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

Side by Side Diff: chrome/browser/media/protected_media_identifier_permission_context.cc

Issue 903873002: media: Support simultaneous permission requests from multiple WebContents in ProtectedMediaIdentifi… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments addressed Created 5 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
« no previous file with comments | « chrome/browser/media/protected_media_identifier_permission_context.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/media/protected_media_identifier_permission_context.h" 5 #include "chrome/browser/media/protected_media_identifier_permission_context.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 8 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/pref_names.h" 10 #include "chrome/common/pref_names.h"
11 #include "components/content_settings/core/common/permission_request_id.h" 11 #include "components/content_settings/core/common/permission_request_id.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
14 14
15 #if defined(OS_CHROMEOS) 15 #if defined(OS_CHROMEOS)
16 #include <utility>
17
16 #include "chrome/browser/chromeos/attestation/platform_verification_dialog.h" 18 #include "chrome/browser/chromeos/attestation/platform_verification_dialog.h"
17 #include "chrome/browser/chromeos/settings/cros_settings.h" 19 #include "chrome/browser/chromeos/settings/cros_settings.h"
18 #include "chromeos/settings/cros_settings_names.h" 20 #include "chromeos/settings/cros_settings_names.h"
19 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
20 22
21 using chromeos::attestation::PlatformVerificationDialog; 23 using chromeos::attestation::PlatformVerificationDialog;
22 using chromeos::attestation::PlatformVerificationFlow; 24 using chromeos::attestation::PlatformVerificationFlow;
23 #endif 25 #endif
24 26
25 #if defined(OS_CHROMEOS)
26 namespace {
27 PermissionRequestID GetInvalidPendingId() {
28 return PermissionRequestID(-1, -1, -1, GURL());
29 }
30 }
31 #endif
32
33 ProtectedMediaIdentifierPermissionContext:: 27 ProtectedMediaIdentifierPermissionContext::
34 ProtectedMediaIdentifierPermissionContext(Profile* profile) 28 ProtectedMediaIdentifierPermissionContext(Profile* profile)
35 : PermissionContextBase(profile, 29 : PermissionContextBase(profile,
36 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) 30 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER)
37 #if defined(OS_CHROMEOS) 31 #if defined(OS_CHROMEOS)
38 , 32 ,
39 pending_id_(GetInvalidPendingId()),
40 widget_(nullptr),
41 weak_factory_(this) 33 weak_factory_(this)
42 #endif 34 #endif
43 { 35 {
44 } 36 }
45 37
46 ProtectedMediaIdentifierPermissionContext:: 38 ProtectedMediaIdentifierPermissionContext::
47 ~ProtectedMediaIdentifierPermissionContext() { 39 ~ProtectedMediaIdentifierPermissionContext() {
48 } 40 }
49 41
50 void ProtectedMediaIdentifierPermissionContext::RequestPermission( 42 void ProtectedMediaIdentifierPermissionContext::RequestPermission(
(...skipping 28 matching lines...) Expand all
79 false /* persist */, false /* granted */); 71 false /* persist */, false /* granted */);
80 return; 72 return;
81 case CONTENT_SETTING_ALLOW: 73 case CONTENT_SETTING_ALLOW:
82 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, 74 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
83 false /* persist */, true /* granted */); 75 false /* persist */, true /* granted */);
84 return; 76 return;
85 default: 77 default:
86 break; 78 break;
87 } 79 }
88 80
89 // We only support one prompt and one pending permission request. 81 // Since the dialog is modal, we only support one prompt per |web_contents|.
90 // Reject the new one if there is already one pending. See 82 // Reject the new one if there is already one pending. See
91 // http://crbug.com/447005 83 // http://crbug.com/447005
92 if (!pending_id_.Equals(GetInvalidPendingId())) { 84 if (pending_requests_.count(web_contents)) {
93 callback.Run(false); 85 callback.Run(false);
94 return; 86 return;
95 } 87 }
96 88
97 pending_id_ = id; 89 views::Widget* widget = PlatformVerificationDialog::ShowDialog(
98 widget_ = PlatformVerificationDialog::ShowDialog(
99 web_contents, requesting_origin, 90 web_contents, requesting_origin,
100 base::Bind(&ProtectedMediaIdentifierPermissionContext:: 91 base::Bind(&ProtectedMediaIdentifierPermissionContext::
101 OnPlatformVerificationResult, 92 OnPlatformVerificationResult,
102 weak_factory_.GetWeakPtr(), id, requesting_origin, 93 weak_factory_.GetWeakPtr(), web_contents, id,
103 embedding_origin, callback)); 94 requesting_origin, embedding_origin, callback));
95 pending_requests_.insert(
96 std::make_pair(web_contents, std::make_pair(widget, id)));
104 #else 97 #else
105 PermissionContextBase::RequestPermission(web_contents, id, requesting_origin, 98 PermissionContextBase::RequestPermission(web_contents, id, requesting_origin,
106 user_gesture, callback); 99 user_gesture, callback);
107 #endif 100 #endif
108 } 101 }
109 102
110 ContentSetting ProtectedMediaIdentifierPermissionContext::GetPermissionStatus( 103 ContentSetting ProtectedMediaIdentifierPermissionContext::GetPermissionStatus(
111 const GURL& requesting_origin, 104 const GURL& requesting_origin,
112 const GURL& embedding_origin) const { 105 const GURL& embedding_origin) const {
113 if (!IsProtectedMediaIdentifierEnabled()) 106 if (!IsProtectedMediaIdentifierEnabled())
114 return CONTENT_SETTING_BLOCK; 107 return CONTENT_SETTING_BLOCK;
115 108
116 return PermissionContextBase::GetPermissionStatus(requesting_origin, 109 return PermissionContextBase::GetPermissionStatus(requesting_origin,
117 embedding_origin); 110 embedding_origin);
118 } 111 }
119 112
120 void ProtectedMediaIdentifierPermissionContext::CancelPermissionRequest( 113 void ProtectedMediaIdentifierPermissionContext::CancelPermissionRequest(
121 content::WebContents* web_contents, 114 content::WebContents* web_contents,
122 const PermissionRequestID& id) { 115 const PermissionRequestID& id) {
123 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 116 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
124 117
125 #if defined(OS_CHROMEOS) 118 #if defined(OS_CHROMEOS)
126 if (!widget_ || !pending_id_.Equals(id)) 119 PendingRequestMap::iterator request = pending_requests_.find(web_contents);
120 if (request == pending_requests_.end() || !request->second.second.Equals(id))
127 return; 121 return;
128 122
129 // Close the |widget_|. OnPlatformVerificationResult() will be fired 123 // Close the |widget_|. OnPlatformVerificationResult() will be fired
130 // during this process, but since |pending_id_| is cleared, the callback will 124 // during this process, but since |web_contents| is removed from
131 // be dropped. 125 // |pending_requests_|, the callback will simply be dropped.
132 pending_id_ = GetInvalidPendingId(); 126 views::Widget* widget = request->second.first;
133 widget_->Close(); 127 pending_requests_.erase(request);
134 return; 128 widget->Close();
135 #else 129 #else
136 PermissionContextBase::CancelPermissionRequest(web_contents, id); 130 PermissionContextBase::CancelPermissionRequest(web_contents, id);
137 #endif 131 #endif
138 } 132 }
139 133
140 void ProtectedMediaIdentifierPermissionContext::UpdateTabContext( 134 void ProtectedMediaIdentifierPermissionContext::UpdateTabContext(
141 const PermissionRequestID& id, 135 const PermissionRequestID& id,
142 const GURL& requesting_frame, 136 const GURL& requesting_frame,
143 bool allowed) { 137 bool allowed) {
144 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 138 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
(...skipping 29 matching lines...) Expand all
174 profile()->GetPrefs()->GetBoolean(prefs::kEnableDRM); 168 profile()->GetPrefs()->GetBoolean(prefs::kEnableDRM);
175 #endif 169 #endif
176 170
177 DVLOG_IF(1, !enabled) 171 DVLOG_IF(1, !enabled)
178 << "Protected media identifier disabled by the user or by device policy."; 172 << "Protected media identifier disabled by the user or by device policy.";
179 return enabled; 173 return enabled;
180 } 174 }
181 175
182 #if defined(OS_CHROMEOS) 176 #if defined(OS_CHROMEOS)
183 void ProtectedMediaIdentifierPermissionContext::OnPlatformVerificationResult( 177 void ProtectedMediaIdentifierPermissionContext::OnPlatformVerificationResult(
178 content::WebContents* web_contents,
184 const PermissionRequestID& id, 179 const PermissionRequestID& id,
185 const GURL& requesting_origin, 180 const GURL& requesting_origin,
186 const GURL& embedding_origin, 181 const GURL& embedding_origin,
187 const BrowserPermissionCallback& callback, 182 const BrowserPermissionCallback& callback,
188 chromeos::attestation::PlatformVerificationFlow::ConsentResponse response) { 183 chromeos::attestation::PlatformVerificationFlow::ConsentResponse response) {
189 DCHECK(widget_); 184 // The request may have been canceled. Drop the callback in that case.
190 widget_ = nullptr; 185 PendingRequestMap::iterator request = pending_requests_.find(web_contents);
191 186 if (request == pending_requests_.end())
192 // The request may have been canceled. Drop the callback here.
193 if (!pending_id_.Equals(id))
194 return; 187 return;
195 188
196 pending_id_ = GetInvalidPendingId(); 189 DCHECK(request->second.second.Equals(id));
190 pending_requests_.erase(request);
197 191
198 if (response == PlatformVerificationFlow::CONSENT_RESPONSE_NONE) { 192 if (response == PlatformVerificationFlow::CONSENT_RESPONSE_NONE) {
199 // Deny request and do not save to content settings. 193 // Deny request and do not save to content settings.
200 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, 194 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
201 false, // Do not save to content settings. 195 false, // Do not save to content settings.
202 false); // Do not allow the permission. 196 false); // Do not allow the permission.
203 return; 197 return;
204 } 198 }
205 199
206 NotifyPermissionSet( 200 NotifyPermissionSet(
207 id, requesting_origin, embedding_origin, callback, 201 id, requesting_origin, embedding_origin, callback,
208 true, // Save to content settings. 202 true, // Save to content settings.
209 response == PlatformVerificationFlow::CONSENT_RESPONSE_ALLOW); 203 response == PlatformVerificationFlow::CONSENT_RESPONSE_ALLOW);
210 } 204 }
211 #endif 205 #endif
OLDNEW
« no previous file with comments | « chrome/browser/media/protected_media_identifier_permission_context.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698