OLD | NEW |
---|---|
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 Loading... | |
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 if (!pending_requests_.count(web_contents)) |
ddorwin
2015/02/05 23:34:46
Redundant with the first part of line 123?
xhwang
2015/02/06 00:21:47
Done.
| |
120 return; | |
121 | |
122 PendingRequestMap::iterator request = pending_requests_.find(web_contents); | |
123 if (request == pending_requests_.end() || !request->second.second.Equals(id)) | |
ddorwin
2015/02/05 23:34:46
Why would the IDs not be equal?
xhwang
2015/02/06 00:21:47
I don't that'll happen in practice. But it's possi
| |
127 return; | 124 return; |
128 | 125 |
129 // Close the |widget_|. OnPlatformVerificationResult() will be fired | 126 // Close the |widget_|. OnPlatformVerificationResult() will be fired |
130 // during this process, but since |pending_id_| is cleared, the callback will | 127 // during this process, but since |web_contents| is removed from |
131 // be dropped. | 128 // |pending_requests_|, the callback will simply be dropped. |
132 pending_id_ = GetInvalidPendingId(); | 129 views::Widget* widget = request->second.first; |
133 widget_->Close(); | 130 pending_requests_.erase(request); |
134 return; | 131 widget->Close(); |
135 #else | 132 #else |
136 PermissionContextBase::CancelPermissionRequest(web_contents, id); | 133 PermissionContextBase::CancelPermissionRequest(web_contents, id); |
137 #endif | 134 #endif |
138 } | 135 } |
139 | 136 |
140 void ProtectedMediaIdentifierPermissionContext::UpdateTabContext( | 137 void ProtectedMediaIdentifierPermissionContext::UpdateTabContext( |
141 const PermissionRequestID& id, | 138 const PermissionRequestID& id, |
142 const GURL& requesting_frame, | 139 const GURL& requesting_frame, |
143 bool allowed) { | 140 bool allowed) { |
144 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 141 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
(...skipping 29 matching lines...) Expand all Loading... | |
174 profile()->GetPrefs()->GetBoolean(prefs::kEnableDRM); | 171 profile()->GetPrefs()->GetBoolean(prefs::kEnableDRM); |
175 #endif | 172 #endif |
176 | 173 |
177 DVLOG_IF(1, !enabled) | 174 DVLOG_IF(1, !enabled) |
178 << "Protected media identifier disabled by the user or by device policy."; | 175 << "Protected media identifier disabled by the user or by device policy."; |
179 return enabled; | 176 return enabled; |
180 } | 177 } |
181 | 178 |
182 #if defined(OS_CHROMEOS) | 179 #if defined(OS_CHROMEOS) |
183 void ProtectedMediaIdentifierPermissionContext::OnPlatformVerificationResult( | 180 void ProtectedMediaIdentifierPermissionContext::OnPlatformVerificationResult( |
181 content::WebContents* web_contents, | |
184 const PermissionRequestID& id, | 182 const PermissionRequestID& id, |
185 const GURL& requesting_origin, | 183 const GURL& requesting_origin, |
186 const GURL& embedding_origin, | 184 const GURL& embedding_origin, |
187 const BrowserPermissionCallback& callback, | 185 const BrowserPermissionCallback& callback, |
188 chromeos::attestation::PlatformVerificationFlow::ConsentResponse response) { | 186 chromeos::attestation::PlatformVerificationFlow::ConsentResponse response) { |
189 DCHECK(widget_); | 187 // The request may have been canceled. Drop the callback then. |
ddorwin
2015/02/05 23:34:46
nit: s/then/in that case/ or something like that
xhwang
2015/02/06 00:21:47
Done.
| |
190 widget_ = nullptr; | 188 PendingRequestMap::iterator request = pending_requests_.find(web_contents); |
191 | 189 if (request == pending_requests_.end()) |
192 // The request may have been canceled. Drop the callback here. | |
193 if (!pending_id_.Equals(id)) | |
194 return; | 190 return; |
195 | 191 |
196 pending_id_ = GetInvalidPendingId(); | 192 DCHECK(request->second.second.Equals(id)); |
193 pending_requests_.erase(request); | |
197 | 194 |
198 if (response == PlatformVerificationFlow::CONSENT_RESPONSE_NONE) { | 195 if (response == PlatformVerificationFlow::CONSENT_RESPONSE_NONE) { |
199 // Deny request and do not save to content settings. | 196 // Deny request and do not save to content settings. |
200 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 197 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
201 false, // Do not save to content settings. | 198 false, // Do not save to content settings. |
202 false); // Do not allow the permission. | 199 false); // Do not allow the permission. |
203 return; | 200 return; |
204 } | 201 } |
205 | 202 |
206 NotifyPermissionSet( | 203 NotifyPermissionSet( |
207 id, requesting_origin, embedding_origin, callback, | 204 id, requesting_origin, embedding_origin, callback, |
208 true, // Save to content settings. | 205 true, // Save to content settings. |
209 response == PlatformVerificationFlow::CONSENT_RESPONSE_ALLOW); | 206 response == PlatformVerificationFlow::CONSENT_RESPONSE_ALLOW); |
210 } | 207 } |
211 #endif | 208 #endif |
OLD | NEW |