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

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: Addressed review issues 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 "chrome/browser/chromeos/display/output_protection_controller_ash.h"
8 #include "build/build_config.h" 8 #include "chrome/browser/chromeos/display/output_protection_controller_mus.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 "services/service_manager/runner/common/client_util.h"
12 #include "ui/display/display.h" 12 #include "ui/display/display.h"
13 #include "ui/display/screen.h" 13 #include "ui/display/screen.h"
14 #include "ui/display/types/display_constants.h"
14 15
15 namespace chromeos { 16 namespace chromeos {
16 17
17 namespace { 18 namespace {
18 19
20 bool IsRunningInMash() {
21 return service_manager::ServiceManagerIsRemote();
22 }
23
19 bool GetCurrentDisplayId(content::RenderFrameHost* rfh, int64_t* display_id) { 24 bool GetCurrentDisplayId(content::RenderFrameHost* rfh, int64_t* display_id) {
20 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 25 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
21 DCHECK(rfh); 26 DCHECK(rfh);
22 DCHECK(display_id); 27 DCHECK(display_id);
23 28
24 display::Screen* screen = display::Screen::GetScreen(); 29 display::Screen* screen = display::Screen::GetScreen();
25 if (!screen) 30 if (!screen)
26 return false; 31 return false;
27 display::Display display = 32 display::Display display =
28 screen->GetDisplayNearestWindow(rfh->GetNativeView()); 33 screen->GetDisplayNearestWindow(rfh->GetNativeView());
29 *display_id = display.id(); 34 *display_id = display.id();
30 return true; 35 return true;
31 } 36 }
32 37
33 void DoNothing(bool status) { 38 void DoNothing(bool status) {
34 } 39 }
35 40
36 } // namespace 41 } // namespace
37 42
43 OutputProtectionDelegate::Controller::Controller() {}
44
45 OutputProtectionDelegate::Controller::~Controller() {}
46
38 OutputProtectionDelegate::OutputProtectionDelegate(int render_process_id, 47 OutputProtectionDelegate::OutputProtectionDelegate(int render_process_id,
39 int render_frame_id) 48 int render_frame_id)
40 : render_process_id_(render_process_id), 49 : render_process_id_(render_process_id),
41 render_frame_id_(render_frame_id), 50 render_frame_id_(render_frame_id),
42 window_(nullptr), 51 window_(nullptr),
43 client_id_(display::DisplayConfigurator::kInvalidClientId), 52 display_id_(display::kInvalidDisplayId),
44 display_id_(0),
45 weak_ptr_factory_(this) { 53 weak_ptr_factory_(this) {
46 // This can be constructed on IO or UI thread. 54 // This can be constructed on IO or UI thread.
47 } 55 }
48 56
49 OutputProtectionDelegate::~OutputProtectionDelegate() { 57 OutputProtectionDelegate::~OutputProtectionDelegate() {
50 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 58 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
51
52 display::DisplayConfigurator* configurator =
53 ash::Shell::GetInstance()->display_configurator();
54 configurator->UnregisterContentProtectionClient(client_id_);
55
56 if (window_) 59 if (window_)
57 window_->RemoveObserver(this); 60 window_->RemoveObserver(this);
58 } 61 }
59 62
60 display::DisplayConfigurator::ContentProtectionClientId
61 OutputProtectionDelegate::GetClientId() {
62 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
63 if (client_id_ == display::DisplayConfigurator::kInvalidClientId) {
64 content::RenderFrameHost* rfh =
65 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
66 if (!rfh || !GetCurrentDisplayId(rfh, &display_id_))
67 return display::DisplayConfigurator::kInvalidClientId;
68
69 aura::Window* window = rfh->GetNativeView();
70 if (!window)
71 return display::DisplayConfigurator::kInvalidClientId;
72
73 display::DisplayConfigurator* configurator =
74 ash::Shell::GetInstance()->display_configurator();
75 client_id_ = configurator->RegisterContentProtectionClient();
76
77 if (client_id_ != display::DisplayConfigurator::kInvalidClientId) {
78 window->AddObserver(this);
79 window_ = window;
80 }
81 }
82 return client_id_;
83 }
84
85 void OutputProtectionDelegate::QueryStatus( 63 void OutputProtectionDelegate::QueryStatus(
86 const QueryStatusCallback& callback) { 64 const QueryStatusCallback& callback) {
87 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 65 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
88 66
89 content::RenderFrameHost* rfh = 67 if (!InitializeControllerIfNecessary()) {
90 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
91 if (!rfh) {
92 LOG(WARNING) << "RenderFrameHost is not alive.";
93 callback.Run(false, 0, 0); 68 callback.Run(false, 0, 0);
94 return; 69 return;
95 } 70 }
96 71
97 display::DisplayConfigurator* configurator = 72 controller_->QueryStatus(display_id_, callback);
98 ash::Shell::GetInstance()->display_configurator();
99 configurator->QueryContentProtectionStatus(
100 GetClientId(), display_id_,
101 base::Bind(&OutputProtectionDelegate::QueryStatusComplete,
102 weak_ptr_factory_.GetWeakPtr(), callback));
103 } 73 }
104 74
105 void OutputProtectionDelegate::EnableProtection( 75 void OutputProtectionDelegate::SetProtection(
106 uint32_t desired_method_mask, 76 uint32_t desired_method_mask,
107 const EnableProtectionCallback& callback) { 77 const SetProtectionCallback& callback) {
108 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 78 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
109 79
110 display::DisplayConfigurator* configurator = 80 if (!InitializeControllerIfNecessary()) {
111 ash::Shell::GetInstance()->display_configurator(); 81 callback.Run(false);
112 configurator->EnableContentProtection( 82 return;
113 GetClientId(), display_id_, desired_method_mask, 83 }
114 base::Bind(&OutputProtectionDelegate::EnableProtectionComplete, 84 controller_->SetProtection(display_id_, desired_method_mask, callback);
115 weak_ptr_factory_.GetWeakPtr(), callback));
116 desired_method_mask_ = desired_method_mask; 85 desired_method_mask_ = desired_method_mask;
117 } 86 }
118 87
119 void OutputProtectionDelegate::QueryStatusComplete( 88 bool OutputProtectionDelegate::InitializeControllerIfNecessary() {
120 const QueryStatusCallback& callback,
121 const display::DisplayConfigurator::QueryProtectionResponse& response) {
122 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 89 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
123 90
91 if (controller_)
92 return true;
93
124 content::RenderFrameHost* rfh = 94 content::RenderFrameHost* rfh =
125 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_); 95 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
126 // TODO(xjz): Investigate whether this check (and the other one above) should
127 // be removed.
128 if (!rfh) { 96 if (!rfh) {
129 LOG(WARNING) << "RenderFrameHost is not alive."; 97 DLOG(WARNING) << "RenderFrameHost is not alive.";
130 callback.Run(false, 0, 0); 98 return false;
131 return;
132 } 99 }
133 100
134 callback.Run(response.success, response.link_mask, response.protection_mask); 101 int64_t display_id = display::kInvalidDisplayId;
135 } 102 if (!GetCurrentDisplayId(rfh, &display_id))
103 return false;
136 104
137 void OutputProtectionDelegate::EnableProtectionComplete( 105 aura::Window* window = rfh->GetNativeView();
138 const EnableProtectionCallback& callback, 106 if (!window)
139 bool success) { 107 return false;
140 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
141 108
142 callback.Run(success); 109 if (IsRunningInMash())
110 controller_ = base::MakeUnique<OutputProtectionControllerMus>();
111 else
112 controller_ = base::MakeUnique<OutputProtectionControllerAsh>();
113
114 display_id_ = display_id;
115 window_ = window;
116 window_->AddObserver(this);
117 return true;
143 } 118 }
144 119
145 void OutputProtectionDelegate::OnWindowHierarchyChanged( 120 void OutputProtectionDelegate::OnWindowHierarchyChanged(
146 const aura::WindowObserver::HierarchyChangeParams& params) { 121 const aura::WindowObserver::HierarchyChangeParams& params) {
147 content::RenderFrameHost* rfh = 122 content::RenderFrameHost* rfh =
148 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_); 123 content::RenderFrameHost::FromID(render_process_id_, render_frame_id_);
149 if (!rfh) { 124 if (!rfh) {
150 LOG(WARNING) << "RenderFrameHost is not alive."; 125 DLOG(WARNING) << "RenderFrameHost is not alive.";
151 return; 126 return;
152 } 127 }
153 128
154 int64_t new_display_id = 0; 129 int64_t new_display_id = display::kInvalidDisplayId;
155 if (!GetCurrentDisplayId(rfh, &new_display_id)) 130 if (!GetCurrentDisplayId(rfh, &new_display_id))
156 return; 131 return;
132
157 if (display_id_ == new_display_id) 133 if (display_id_ == new_display_id)
158 return; 134 return;
159 135
160 if (desired_method_mask_ != display::CONTENT_PROTECTION_METHOD_NONE) { 136 if (desired_method_mask_ != display::CONTENT_PROTECTION_METHOD_NONE) {
161 // Display changed and should enable output protections on new display. 137 DCHECK(controller_);
162 display::DisplayConfigurator* configurator = 138 controller_->SetProtection(new_display_id, desired_method_mask_,
163 ash::Shell::GetInstance()->display_configurator(); 139 base::Bind(&DoNothing));
164 configurator->EnableContentProtection(GetClientId(), new_display_id, 140 controller_->SetProtection(display_id_,
165 desired_method_mask_, 141 display::CONTENT_PROTECTION_METHOD_NONE,
166 base::Bind(&DoNothing)); 142 base::Bind(&DoNothing));
167 configurator->EnableContentProtection(
168 GetClientId(), display_id_, display::CONTENT_PROTECTION_METHOD_NONE,
169 base::Bind(&DoNothing));
170 } 143 }
171 display_id_ = new_display_id; 144 display_id_ = new_display_id;
172 } 145 }
173 146
174 void OutputProtectionDelegate::OnWindowDestroying(aura::Window* window) { 147 void OutputProtectionDelegate::OnWindowDestroying(aura::Window* window) {
175 DCHECK_EQ(window, window_); 148 DCHECK_EQ(window, window_);
176 window_->RemoveObserver(this); 149 window_->RemoveObserver(this);
177 window_ = nullptr; 150 window_ = nullptr;
178 } 151 }
179 152
180 } // namespace chromeos 153 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/display/output_protection_delegate.h ('k') | chrome/browser/media/output_protection_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698