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

Side by Side Diff: content/browser/media/cdm/browser_cdm_manager.cc

Issue 571483002: Refactor content client to include a single Request/CancelPermission method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@geoloc_permission
Patch Set: Created 6 years, 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/browser/media/cdm/browser_cdm_manager.h" 5 #include "content/browser/media/cdm/browser_cdm_manager.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "content/common/media/cdm_messages.h" 8 #include "content/common/media/cdm_messages.h"
9 #include "content/public/browser/content_browser_client.h" 9 #include "content/public/browser/content_browser_client.h"
10 #include "content/public/browser/render_frame_host.h" 10 #include "content/public/browser/render_frame_host.h"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 } 148 }
149 149
150 std::map<int, GURL>::const_iterator iter = 150 std::map<int, GURL>::const_iterator iter =
151 cdm_security_origin_map_.find(cdm_id); 151 cdm_security_origin_map_.find(cdm_id);
152 if (iter == cdm_security_origin_map_.end()) { 152 if (iter == cdm_security_origin_map_.end()) {
153 NOTREACHED(); 153 NOTREACHED();
154 OnSessionError(cdm_id, session_id, MediaKeys::kUnknownError, 0); 154 OnSessionError(cdm_id, session_id, MediaKeys::kUnknownError, 0);
155 return; 155 return;
156 } 156 }
157 157
158 base::Closure cancel_callback; 158 GetContentClient()->browser()->RequestPermission(
159 GetContentClient()->browser()->RequestProtectedMediaIdentifierPermission( 159 content::PERMISSION_PROTECTED_MEDIA,
160 web_contents_, 160 web_contents_,
161 -1,
161 iter->second, 162 iter->second,
163 true,
162 base::Bind(&BrowserCdmManager::CreateSessionIfPermitted, 164 base::Bind(&BrowserCdmManager::CreateSessionIfPermitted,
163 weak_ptr_factory_.GetWeakPtr(), 165 weak_ptr_factory_.GetWeakPtr(),
164 cdm_id, 166 cdm_id,
165 session_id, 167 session_id,
166 mime_type, 168 mime_type,
167 init_data), 169 init_data));
168 &cancel_callback);
169 if (!cancel_callback.is_null())
170 cdm_cancel_permision_map_[cdm_id] = cancel_callback;
171 } 170 }
172 171
173 void BrowserCdmManager::OnUpdateSession( 172 void BrowserCdmManager::OnUpdateSession(
174 int cdm_id, 173 int cdm_id,
175 uint32 session_id, 174 uint32 session_id,
176 const std::vector<uint8>& response) { 175 const std::vector<uint8>& response) {
177 BrowserCdm* cdm = GetCdm(cdm_id); 176 BrowserCdm* cdm = GetCdm(cdm_id);
178 if (!cdm) { 177 if (!cdm) {
179 DLOG(WARNING) << "No CDM for ID " << cdm_id << " found"; 178 DLOG(WARNING) << "No CDM for ID " << cdm_id << " found";
180 OnSessionError(cdm_id, session_id, MediaKeys::kUnknownError, 0); 179 OnSessionError(cdm_id, session_id, MediaKeys::kUnknownError, 0);
(...skipping 24 matching lines...) Expand all
205 void BrowserCdmManager::OnDestroyCdm(int cdm_id) { 204 void BrowserCdmManager::OnDestroyCdm(int cdm_id) {
206 BrowserCdm* cdm = GetCdm(cdm_id); 205 BrowserCdm* cdm = GetCdm(cdm_id);
207 if (!cdm) 206 if (!cdm)
208 return; 207 return;
209 208
210 CancelAllPendingSessionCreations(cdm_id); 209 CancelAllPendingSessionCreations(cdm_id);
211 RemoveCdm(cdm_id); 210 RemoveCdm(cdm_id);
212 } 211 }
213 212
214 void BrowserCdmManager::CancelAllPendingSessionCreations(int cdm_id) { 213 void BrowserCdmManager::CancelAllPendingSessionCreations(int cdm_id) {
215 if (cdm_cancel_permision_map_.count(cdm_id)) { 214 if (cdm_cancel_permision_set_.find(cdm_id)
216 cdm_cancel_permision_map_[cdm_id].Run(); 215 != cdm_cancel_permision_set_.end()) {
217 cdm_cancel_permision_map_.erase(cdm_id); 216 std::map<int, GURL>::const_iterator iter =
217 cdm_security_origin_map_.find(cdm_id);
218 if (iter == cdm_security_origin_map_.end()) {
219 NOTREACHED();
220 return;
221 }
222 GetContentClient()->browser()->CancelPermissionRequest(
223 content::PERMISSION_PROTECTED_MEDIA,
224 web_contents_, -1, iter->second);
225 cdm_cancel_permision_set_.erase(cdm_id);
218 } 226 }
219 } 227 }
220 228
221 void BrowserCdmManager::AddCdm(int cdm_id, 229 void BrowserCdmManager::AddCdm(int cdm_id,
222 const std::string& key_system, 230 const std::string& key_system,
223 const GURL& security_origin) { 231 const GURL& security_origin) {
224 DCHECK(!GetCdm(cdm_id)); 232 DCHECK(!GetCdm(cdm_id));
225 base::WeakPtr<BrowserCdmManager> weak_this = weak_ptr_factory_.GetWeakPtr(); 233 base::WeakPtr<BrowserCdmManager> weak_this = weak_ptr_factory_.GetWeakPtr();
226 scoped_ptr<BrowserCdm> cdm(media::CreateBrowserCdm( 234 scoped_ptr<BrowserCdm> cdm(media::CreateBrowserCdm(
227 key_system, 235 key_system,
(...skipping 14 matching lines...) Expand all
242 cdm_security_origin_map_[cdm_id] = security_origin; 250 cdm_security_origin_map_[cdm_id] = security_origin;
243 } 251 }
244 252
245 void BrowserCdmManager::RemoveCdm(int cdm_id) { 253 void BrowserCdmManager::RemoveCdm(int cdm_id) {
246 // TODO(xhwang): Detach CDM from the player it's set to. In prefixed 254 // TODO(xhwang): Detach CDM from the player it's set to. In prefixed
247 // EME implementation the current code is fine because we always destroy the 255 // EME implementation the current code is fine because we always destroy the
248 // player before we destroy the DrmBridge. This will not always be the case 256 // player before we destroy the DrmBridge. This will not always be the case
249 // in unprefixed EME implementation. 257 // in unprefixed EME implementation.
250 cdm_map_.erase(cdm_id); 258 cdm_map_.erase(cdm_id);
251 cdm_security_origin_map_.erase(cdm_id); 259 cdm_security_origin_map_.erase(cdm_id);
252 cdm_cancel_permision_map_.erase(cdm_id); 260 cdm_cancel_permision_set_.erase(cdm_id);
253 } 261 }
254 262
255 int BrowserCdmManager::RoutingID() { 263 int BrowserCdmManager::RoutingID() {
256 return render_frame_host_->GetRoutingID(); 264 return render_frame_host_->GetRoutingID();
257 } 265 }
258 266
259 bool BrowserCdmManager::Send(IPC::Message* msg) { 267 bool BrowserCdmManager::Send(IPC::Message* msg) {
260 return render_frame_host_->Send(msg); 268 return render_frame_host_->Send(msg);
261 } 269 }
262 270
263 void BrowserCdmManager::CreateSessionIfPermitted( 271 void BrowserCdmManager::CreateSessionIfPermitted(
264 int cdm_id, 272 int cdm_id,
265 uint32 session_id, 273 uint32 session_id,
266 const std::string& content_type, 274 const std::string& content_type,
267 const std::vector<uint8>& init_data, 275 const std::vector<uint8>& init_data,
268 bool permitted) { 276 bool permitted) {
269 cdm_cancel_permision_map_.erase(cdm_id); 277 cdm_cancel_permision_set_.erase(cdm_id);
270 if (!permitted) { 278 if (!permitted) {
271 OnSessionError(cdm_id, session_id, MediaKeys::kUnknownError, 0); 279 OnSessionError(cdm_id, session_id, MediaKeys::kUnknownError, 0);
272 return; 280 return;
273 } 281 }
274 282
275 BrowserCdm* cdm = GetCdm(cdm_id); 283 BrowserCdm* cdm = GetCdm(cdm_id);
276 if (!cdm) { 284 if (!cdm) {
277 DLOG(WARNING) << "No CDM for ID: " << cdm_id << " found"; 285 DLOG(WARNING) << "No CDM for ID: " << cdm_id << " found";
278 OnSessionError(cdm_id, session_id, MediaKeys::kUnknownError, 0); 286 OnSessionError(cdm_id, session_id, MediaKeys::kUnknownError, 0);
279 return; 287 return;
280 } 288 }
281 289
282 // This could fail, in which case a SessionError will be fired. 290 // This could fail, in which case a SessionError will be fired.
283 cdm->CreateSession(session_id, content_type, &init_data[0], init_data.size()); 291 cdm->CreateSession(session_id, content_type, &init_data[0], init_data.size());
284 } 292 }
285 293
286 } // namespace content 294 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/cdm/browser_cdm_manager.h ('k') | content/browser/media/midi_dispatcher_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698