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" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 const GURL& requesting_origin, | 45 const GURL& requesting_origin, |
46 bool user_gesture, | 46 bool user_gesture, |
47 const BrowserPermissionCallback& callback) { | 47 const BrowserPermissionCallback& callback) { |
48 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 48 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
49 | 49 |
50 GURL embedding_origin = web_contents->GetLastCommittedURL().GetOrigin(); | 50 GURL embedding_origin = web_contents->GetLastCommittedURL().GetOrigin(); |
51 | 51 |
52 if (!requesting_origin.is_valid() || !embedding_origin.is_valid() || | 52 if (!requesting_origin.is_valid() || !embedding_origin.is_valid() || |
53 !IsProtectedMediaIdentifierEnabled()) { | 53 !IsProtectedMediaIdentifierEnabled()) { |
54 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 54 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
55 false /* persist */, false /* granted */); | 55 false /* persist */, CONTENT_SETTING_BLOCK); |
56 return; | 56 return; |
57 } | 57 } |
58 | 58 |
59 #if defined(OS_CHROMEOS) | 59 #if defined(OS_CHROMEOS) |
60 // On ChromeOS, we don't use PermissionContextBase::RequestPermission() which | 60 // On ChromeOS, we don't use PermissionContextBase::RequestPermission() which |
61 // uses the standard permission infobar/bubble UI. See http://crbug.com/454847 | 61 // uses the standard permission infobar/bubble UI. See http://crbug.com/454847 |
62 // Instead, we check the content setting and show the existing platform | 62 // Instead, we check the content setting and show the existing platform |
63 // verification UI. | 63 // verification UI. |
64 // TODO(xhwang): Remove when http://crbug.com/454847 is fixed. | 64 // TODO(xhwang): Remove when http://crbug.com/454847 is fixed. |
65 ContentSetting content_setting = | 65 ContentSetting content_setting = |
66 GetPermissionStatus(requesting_origin, embedding_origin); | 66 GetPermissionStatus(requesting_origin, embedding_origin); |
67 | 67 |
68 switch (content_setting) { | 68 if (content_setting == CONTENT_SETTING_ALLOW || |
69 case CONTENT_SETTING_BLOCK: | 69 content_setting == CONTENT_SETTING_BLOCK) { |
70 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 70 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
71 false /* persist */, false /* granted */); | 71 false /* persist */, content_setting); |
72 return; | 72 return; |
73 case CONTENT_SETTING_ALLOW: | |
74 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | |
75 false /* persist */, true /* granted */); | |
76 return; | |
77 default: | |
78 break; | |
79 } | 73 } |
80 | 74 |
81 // Since the dialog is modal, we only support one prompt per |web_contents|. | 75 // Since the dialog is modal, we only support one prompt per |web_contents|. |
82 // Reject the new one if there is already one pending. See | 76 // Reject the new one if there is already one pending. See |
83 // http://crbug.com/447005 | 77 // http://crbug.com/447005 |
84 if (pending_requests_.count(web_contents)) { | 78 if (pending_requests_.count(web_contents)) { |
85 callback.Run(false); | 79 callback.Run(CONTENT_SETTING_DEFAULT); |
86 return; | 80 return; |
87 } | 81 } |
88 | 82 |
89 views::Widget* widget = PlatformVerificationDialog::ShowDialog( | 83 views::Widget* widget = PlatformVerificationDialog::ShowDialog( |
90 web_contents, requesting_origin, | 84 web_contents, requesting_origin, |
91 base::Bind(&ProtectedMediaIdentifierPermissionContext:: | 85 base::Bind(&ProtectedMediaIdentifierPermissionContext:: |
92 OnPlatformVerificationResult, | 86 OnPlatformVerificationResult, |
93 weak_factory_.GetWeakPtr(), web_contents, id, | 87 weak_factory_.GetWeakPtr(), web_contents, id, |
94 requesting_origin, embedding_origin, callback)); | 88 requesting_origin, embedding_origin, callback)); |
95 pending_requests_.insert( | 89 pending_requests_.insert( |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 const BrowserPermissionCallback& callback, | 176 const BrowserPermissionCallback& callback, |
183 chromeos::attestation::PlatformVerificationFlow::ConsentResponse response) { | 177 chromeos::attestation::PlatformVerificationFlow::ConsentResponse response) { |
184 // The request may have been canceled. Drop the callback in that case. | 178 // The request may have been canceled. Drop the callback in that case. |
185 PendingRequestMap::iterator request = pending_requests_.find(web_contents); | 179 PendingRequestMap::iterator request = pending_requests_.find(web_contents); |
186 if (request == pending_requests_.end()) | 180 if (request == pending_requests_.end()) |
187 return; | 181 return; |
188 | 182 |
189 DCHECK(request->second.second.Equals(id)); | 183 DCHECK(request->second.second.Equals(id)); |
190 pending_requests_.erase(request); | 184 pending_requests_.erase(request); |
191 | 185 |
192 if (response == PlatformVerificationFlow::CONSENT_RESPONSE_NONE) { | 186 ContentSetting content_setting; |
193 // Deny request and do not save to content settings. | 187 bool persist; // Whether the ContentSetting should be saved. |
194 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 188 switch (response) { |
195 false, // Do not save to content settings. | 189 case PlatformVerificationFlow::CONSENT_RESPONSE_NONE: |
196 false); // Do not allow the permission. | 190 content_setting = CONTENT_SETTING_DEFAULT; |
197 return; | 191 persist = false; |
| 192 break; |
| 193 case PlatformVerificationFlow::CONSENT_RESPONSE_ALLOW: |
| 194 content_setting = CONTENT_SETTING_ALLOW; |
| 195 persist = true; |
| 196 break; |
| 197 case PlatformVerificationFlow::CONSENT_RESPONSE_DENY: |
| 198 content_setting = CONTENT_SETTING_BLOCK; |
| 199 persist = true; |
| 200 break; |
198 } | 201 } |
199 | 202 |
200 NotifyPermissionSet( | 203 NotifyPermissionSet( |
201 id, requesting_origin, embedding_origin, callback, | 204 id, requesting_origin, embedding_origin, callback, |
202 true, // Save to content settings. | 205 persist, content_setting); |
203 response == PlatformVerificationFlow::CONSENT_RESPONSE_ALLOW); | |
204 } | 206 } |
205 #endif | 207 #endif |
OLD | NEW |