Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: chrome/browser/chromeos/display/output_protection_delegate.cc

Issue 2675743002: PPAPI: Make output protection API work with mus+ash (Closed)
Patch Set: Fix try bot Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/display/output_protection_delegate.h" 5 #include "chrome/browser/chromeos/display/output_protection_delegate.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "content/public/browser/browser_thread.h" 9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/render_frame_host.h" 10 #include "content/public/browser/render_frame_host.h"
11 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents.h"
12 #include "content/public/common/service_manager_connection.h"
13 #include "services/service_manager/public/cpp/connector.h"
14 #include "services/service_manager/runner/common/client_util.h"
15 #include "services/ui/public/interfaces/display/display_controller.mojom.h"
12 #include "ui/display/display.h" 16 #include "ui/display/display.h"
17 #include "ui/display/manager/chromeos/display_configurator.h"
13 #include "ui/display/screen.h" 18 #include "ui/display/screen.h"
14 19
15 namespace chromeos { 20 namespace chromeos {
16 21
17 namespace { 22 namespace {
18 23
24 bool IsRunningInMash() {
25 return service_manager::ServiceManagerIsRemote();
26 }
27
19 bool GetCurrentDisplayId(content::RenderFrameHost* rfh, int64_t* display_id) { 28 bool GetCurrentDisplayId(content::RenderFrameHost* rfh, int64_t* display_id) {
20 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 29 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
21 DCHECK(rfh); 30 DCHECK(rfh);
22 DCHECK(display_id); 31 DCHECK(display_id);
23 32
24 display::Screen* screen = display::Screen::GetScreen(); 33 display::Screen* screen = display::Screen::GetScreen();
25 if (!screen) 34 if (!screen)
26 return false; 35 return false;
27 display::Display display = 36 display::Display display =
28 screen->GetDisplayNearestWindow(rfh->GetNativeView()); 37 screen->GetDisplayNearestWindow(rfh->GetNativeView());
29 *display_id = display.id(); 38 *display_id = display.id();
30 return true; 39 return true;
31 } 40 }
32 41
33 void DoNothing(bool status) { 42 void DoNothing(bool status) {
34 } 43 }
35 44
45 // Display content protection controller for running on Aura.
46 class ControllerAura : public OutputProtectionDelegate::Controller {
47 public:
48 ControllerAura() {}
49
50 ~ControllerAura() override {
51 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
52 if (client_id_ == display::DisplayConfigurator::kInvalidClientId)
53 return;
54 display::DisplayConfigurator* configurator =
55 ash::Shell::GetInstance()->display_configurator();
56 configurator->UnregisterContentProtectionClient(client_id_);
57 }
58
59 bool Init() override {
60 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
61 display::DisplayConfigurator* configurator =
62 ash::Shell::GetInstance()->display_configurator();
63 client_id_ = configurator->RegisterContentProtectionClient();
64 return client_id_ != display::DisplayConfigurator::kInvalidClientId;
65 }
66
67 void QueryStatus(
68 int64_t display_id,
69 const OutputProtectionDelegate::QueryStatusCallback& callback) override {
70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
71 display::DisplayConfigurator* configurator =
72 ash::Shell::GetInstance()->display_configurator();
73 configurator->QueryContentProtectionStatus(client_id_, display_id,
74 callback);
75 }
76
77 void EnableProtection(
78 int64_t display_id,
79 uint32_t desired_method_mask,
80 const OutputProtectionDelegate::EnableProtectionCallback& callback)
81 override {
82 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
83 display::DisplayConfigurator* configurator =
84 ash::Shell::GetInstance()->display_configurator();
85 configurator->EnableContentProtection(client_id_, display_id,
86 desired_method_mask, callback);
87 }
88
89 private:
90 display::DisplayConfigurator::ContentProtectionClientId client_id_ =
91 display::DisplayConfigurator::kInvalidClientId;
92
93 DISALLOW_COPY_AND_ASSIGN(ControllerAura);
94 };
95
96 // Display content protection controller for running with Mus server.
97 class ControllerMus : public OutputProtectionDelegate::Controller {
98 public:
99 ControllerMus() {}
100
101 ~ControllerMus() override {
102 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
103 if (client_id_ == display::DisplayConfigurator::kInvalidClientId)
104 return;
105 display_controller_->UnregisterContentProtectionClient(client_id_);
106 }
107
108 bool Init() override {
109 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
110 content::ServiceManagerConnection::GetForProcess()
111 ->GetConnector()
112 ->BindInterface("ui", &display_controller_);
113 return display_controller_->RegisterContentProtectionClient(&client_id_) &&
114 client_id_ != display::DisplayConfigurator::kInvalidClientId;
115 }
116
117 void QueryStatus(
118 int64_t display_id,
119 const OutputProtectionDelegate::QueryStatusCallback& callback) override {
120 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
121 display_controller_->QueryContentProtectionStatus(client_id_, display_id,
122 callback);
123 }
124
125 void EnableProtection(
126 int64_t display_id,
127 uint32_t desired_method_mask,
128 const OutputProtectionDelegate::EnableProtectionCallback& callback)
129 override {
130 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
131 display_controller_->EnableContentProtection(client_id_, display_id,
132 desired_method_mask, callback);
133 }
134
135 private:
136 display::mojom::DisplayControllerPtr display_controller_;
137 display::DisplayConfigurator::ContentProtectionClientId client_id_ =
138 display::DisplayConfigurator::kInvalidClientId;
139
140 DISALLOW_COPY_AND_ASSIGN(ControllerMus);
141 };
142
36 } // namespace 143 } // namespace
37 144
145 OutputProtectionDelegate::Controller::Controller() {}
146
147 OutputProtectionDelegate::Controller::~Controller() {}
148
38 OutputProtectionDelegate::OutputProtectionDelegate(int render_process_id, 149 OutputProtectionDelegate::OutputProtectionDelegate(int render_process_id,
39 int render_frame_id) 150 int render_frame_id)
40 : render_process_id_(render_process_id), 151 : render_process_id_(render_process_id),
41 render_frame_id_(render_frame_id), 152 render_frame_id_(render_frame_id),
42 window_(nullptr), 153 window_(nullptr),
43 client_id_(display::DisplayConfigurator::kInvalidClientId),
44 display_id_(0), 154 display_id_(0),
oshima 2017/02/06 21:51:23 nit: shouldn't this use kInvalidDisplayId? ditto
Peng 2017/02/07 15:12:59 Done.
45 weak_ptr_factory_(this) { 155 weak_ptr_factory_(this) {
46 // This can be constructed on IO or UI thread. 156 // This can be constructed on IO or UI thread.
47 } 157 }
48 158
49 OutputProtectionDelegate::~OutputProtectionDelegate() { 159 OutputProtectionDelegate::~OutputProtectionDelegate() {
50 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 160 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
51 161 controller_.reset();
52 display::DisplayConfigurator* configurator =
53 ash::Shell::GetInstance()->display_configurator();
54 configurator->UnregisterContentProtectionClient(client_id_);
55
56 if (window_) 162 if (window_)
57 window_->RemoveObserver(this); 163 window_->RemoveObserver(this);
58 } 164 }
59 165
60 display::DisplayConfigurator::ContentProtectionClientId 166 bool OutputProtectionDelegate::InitializeControllerIfNecessary() {
61 OutputProtectionDelegate::GetClientId() {
62 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 167 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
63 if (client_id_ == display::DisplayConfigurator::kInvalidClientId) { 168 if (controller_)
64 content::RenderFrameHost* rfh = 169 return true;
65 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
66 if (!rfh || !GetCurrentDisplayId(rfh, &display_id_))
67 return display::DisplayConfigurator::kInvalidClientId;
68 170
69 aura::Window* window = rfh->GetNativeView(); 171 content::RenderFrameHost* rfh =
70 if (!window) 172 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
71 return display::DisplayConfigurator::kInvalidClientId; 173 if (!rfh || !GetCurrentDisplayId(rfh, &display_id_))
174 return false;
72 175
73 display::DisplayConfigurator* configurator = 176 aura::Window* window = rfh->GetNativeView();
74 ash::Shell::GetInstance()->display_configurator(); 177 if (!window) {
75 client_id_ = configurator->RegisterContentProtectionClient(); 178 display_id_ = 0;
179 return false;
180 }
76 181
77 if (client_id_ != display::DisplayConfigurator::kInvalidClientId) { 182 if (IsRunningInMash())
78 window->AddObserver(this); 183 controller_ = base::MakeUnique<ControllerMus>();
79 window_ = window; 184 else
80 } 185 controller_ = base::MakeUnique<ControllerAura>();
186 if (!controller_->Init()) {
187 display_id_ = 0;
188 controller_.reset();
189 return false;
81 } 190 }
82 return client_id_; 191
192 window->AddObserver(this);
193 window_ = window;
194 return true;
83 } 195 }
84 196
85 void OutputProtectionDelegate::QueryStatus( 197 void OutputProtectionDelegate::QueryStatus(
86 const QueryStatusCallback& callback) { 198 const QueryStatusCallback& callback) {
87 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 199 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
88 200
89 content::RenderFrameHost* rfh = 201 content::RenderFrameHost* rfh =
90 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_); 202 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
91 if (!rfh) { 203 if (!rfh) {
92 LOG(WARNING) << "RenderFrameHost is not alive."; 204 LOG(WARNING) << "RenderFrameHost is not alive.";
93 callback.Run(false, 0, 0); 205 callback.Run(false, 0, 0);
94 return; 206 return;
95 } 207 }
96 208
97 display::DisplayConfigurator* configurator = 209 if (!InitializeControllerIfNecessary()) {
98 ash::Shell::GetInstance()->display_configurator(); 210 callback.Run(false, 0, 0);
99 configurator->QueryContentProtectionStatus( 211 return;
100 GetClientId(), display_id_, 212 }
101 base::Bind(&OutputProtectionDelegate::QueryStatusComplete, 213 controller_->QueryStatus(display_id_, callback);
102 weak_ptr_factory_.GetWeakPtr(), callback));
103 } 214 }
104 215
105 void OutputProtectionDelegate::EnableProtection( 216 void OutputProtectionDelegate::EnableProtection(
106 uint32_t desired_method_mask, 217 uint32_t desired_method_mask,
107 const EnableProtectionCallback& callback) { 218 const EnableProtectionCallback& callback) {
108 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 219 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
109 220 if (!InitializeControllerIfNecessary()) {
110 display::DisplayConfigurator* configurator = 221 callback.Run(false);
111 ash::Shell::GetInstance()->display_configurator(); 222 return;
112 configurator->EnableContentProtection( 223 }
113 GetClientId(), display_id_, desired_method_mask, 224 controller_->EnableProtection(display_id_, desired_method_mask, callback);
114 base::Bind(&OutputProtectionDelegate::EnableProtectionComplete,
115 weak_ptr_factory_.GetWeakPtr(), callback));
116 desired_method_mask_ = desired_method_mask; 225 desired_method_mask_ = desired_method_mask;
117 } 226 }
118 227
119 void OutputProtectionDelegate::QueryStatusComplete( 228 void OutputProtectionDelegate::QueryStatusComplete(
120 const QueryStatusCallback& callback, 229 const QueryStatusCallback& callback,
121 const display::DisplayConfigurator::QueryProtectionResponse& response) { 230 bool success,
231 uint32_t link_mask,
232 uint32_t protection_mask) {
122 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 233 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
123 234
124 content::RenderFrameHost* rfh = 235 content::RenderFrameHost* rfh =
125 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_); 236 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
126 // TODO(xjz): Investigate whether this check (and the other one above) should 237 // TODO(xjz): Investigate whether this check (and the other one above) should
127 // be removed. 238 // be removed.
128 if (!rfh) { 239 if (!rfh) {
129 LOG(WARNING) << "RenderFrameHost is not alive."; 240 LOG(WARNING) << "RenderFrameHost is not alive.";
130 callback.Run(false, 0, 0); 241 callback.Run(false, 0, 0);
131 return; 242 return;
132 } 243 }
133 244 callback.Run(success, link_mask, protection_mask);
134 callback.Run(response.success, response.link_mask, response.protection_mask);
135 } 245 }
136 246
137 void OutputProtectionDelegate::EnableProtectionComplete( 247 void OutputProtectionDelegate::EnableProtectionComplete(
138 const EnableProtectionCallback& callback, 248 const EnableProtectionCallback& callback,
139 bool success) { 249 bool success) {
140 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 250 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
141 251
142 callback.Run(success); 252 callback.Run(success);
143 } 253 }
144 254
145 void OutputProtectionDelegate::OnWindowHierarchyChanged( 255 void OutputProtectionDelegate::OnWindowHierarchyChanged(
146 const aura::WindowObserver::HierarchyChangeParams& params) { 256 const aura::WindowObserver::HierarchyChangeParams& params) {
147 content::RenderFrameHost* rfh = 257 content::RenderFrameHost* rfh =
148 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_); 258 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
149 if (!rfh) { 259 if (!rfh) {
150 LOG(WARNING) << "RenderFrameHost is not alive."; 260 LOG(WARNING) << "RenderFrameHost is not alive.";
151 return; 261 return;
152 } 262 }
153 263
154 int64_t new_display_id = 0; 264 int64_t new_display_id = 0;
155 if (!GetCurrentDisplayId(rfh, &new_display_id)) 265 if (!GetCurrentDisplayId(rfh, &new_display_id))
156 return; 266 return;
157 if (display_id_ == new_display_id) 267 if (display_id_ == new_display_id)
158 return; 268 return;
159 269
160 if (desired_method_mask_ != display::CONTENT_PROTECTION_METHOD_NONE) { 270 if (desired_method_mask_ != display::CONTENT_PROTECTION_METHOD_NONE) {
161 // Display changed and should enable output protections on new display. 271 bool result = InitializeControllerIfNecessary();
162 display::DisplayConfigurator* configurator = 272 DCHECK(result);
163 ash::Shell::GetInstance()->display_configurator(); 273 controller_->EnableProtection(display_id_, desired_method_mask_,
164 configurator->EnableContentProtection(GetClientId(), new_display_id, 274 base::Bind(&DoNothing));
165 desired_method_mask_, 275 controller_->EnableProtection(display_id_,
166 base::Bind(&DoNothing)); 276 display::CONTENT_PROTECTION_METHOD_NONE,
167 configurator->EnableContentProtection( 277 base::Bind(&DoNothing));
168 GetClientId(), display_id_, display::CONTENT_PROTECTION_METHOD_NONE,
169 base::Bind(&DoNothing));
170 } 278 }
171 display_id_ = new_display_id; 279 display_id_ = new_display_id;
172 } 280 }
173 281
174 void OutputProtectionDelegate::OnWindowDestroying(aura::Window* window) { 282 void OutputProtectionDelegate::OnWindowDestroying(aura::Window* window) {
175 DCHECK_EQ(window, window_); 283 DCHECK_EQ(window, window_);
176 window_->RemoveObserver(this); 284 window_->RemoveObserver(this);
177 window_ = nullptr; 285 window_ = nullptr;
178 } 286 }
179 287
180 } // namespace chromeos 288 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698