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/user_metrics.h" | 13 #include "content/public/browser/user_metrics.h" |
14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
15 | 15 |
16 #if defined(OS_CHROMEOS) | 16 #if defined(OS_CHROMEOS) |
17 #include <utility> | 17 #include <utility> |
18 | 18 |
19 #include "chrome/browser/chromeos/attestation/platform_verification_dialog.h" | 19 #include "chrome/browser/chromeos/attestation/platform_verification_dialog.h" |
20 #include "chrome/browser/chromeos/settings/cros_settings.h" | 20 #include "chrome/browser/chromeos/settings/cros_settings.h" |
21 #include "chromeos/settings/cros_settings_names.h" | 21 #include "chromeos/settings/cros_settings_names.h" |
22 #include "components/pref_registry/pref_registry_syncable.h" | 22 #include "components/pref_registry/pref_registry_syncable.h" |
23 #include "components/user_prefs/user_prefs.h" | 23 #include "components/user_prefs/user_prefs.h" |
24 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
25 | 25 #elif defined(OS_ANDROID) |
26 using chromeos::attestation::PlatformVerificationDialog; | 26 #include "base/command_line.h" |
27 #include "media/base/media_switches.h" | |
28 #else | |
29 #error This file should only be used on ChromeOS or Android. | |
ddorwin
2015/03/17 00:43:11
"This file currently only supports Chrome OS and A
xhwang
2015/03/17 01:33:28
Done.
| |
27 #endif | 30 #endif |
28 | 31 |
29 ProtectedMediaIdentifierPermissionContext:: | 32 ProtectedMediaIdentifierPermissionContext:: |
30 ProtectedMediaIdentifierPermissionContext(Profile* profile) | 33 ProtectedMediaIdentifierPermissionContext(Profile* profile) |
31 : PermissionContextBase(profile, | 34 : PermissionContextBase(profile, |
32 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) | 35 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) |
33 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
34 , | 37 , |
35 weak_factory_(this) | 38 weak_factory_(this) |
36 #endif | 39 #endif |
37 { | 40 { |
38 } | 41 } |
39 | 42 |
40 ProtectedMediaIdentifierPermissionContext:: | 43 ProtectedMediaIdentifierPermissionContext:: |
41 ~ProtectedMediaIdentifierPermissionContext() { | 44 ~ProtectedMediaIdentifierPermissionContext() { |
42 } | 45 } |
43 | 46 |
44 #if defined(OS_CHROMEOS) | 47 #if defined(OS_CHROMEOS) |
48 using chromeos::attestation::PlatformVerificationDialog; | |
49 | |
45 // static | 50 // static |
46 void ProtectedMediaIdentifierPermissionContext::RegisterProfilePrefs( | 51 void ProtectedMediaIdentifierPermissionContext::RegisterProfilePrefs( |
47 user_prefs::PrefRegistrySyncable* prefs) { | 52 user_prefs::PrefRegistrySyncable* prefs) { |
48 prefs->RegisterBooleanPref(prefs::kRAConsentGranted, | 53 prefs->RegisterBooleanPref(prefs::kRAConsentGranted, |
49 false, // Default value. | 54 false, // Default value. |
50 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 55 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
51 } | 56 } |
52 #endif | 57 #endif |
53 | 58 |
54 void ProtectedMediaIdentifierPermissionContext::RequestPermission( | 59 void ProtectedMediaIdentifierPermissionContext::RequestPermission( |
(...skipping 13 matching lines...) Expand all Loading... | |
68 GetPermissionStatus(requesting_origin, embedding_origin); | 73 GetPermissionStatus(requesting_origin, embedding_origin); |
69 | 74 |
70 if (content_setting == CONTENT_SETTING_ALLOW || | 75 if (content_setting == CONTENT_SETTING_ALLOW || |
71 content_setting == CONTENT_SETTING_BLOCK) { | 76 content_setting == CONTENT_SETTING_BLOCK) { |
72 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 77 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
73 false /* persist */, content_setting); | 78 false /* persist */, content_setting); |
74 return; | 79 return; |
75 } | 80 } |
76 | 81 |
77 DCHECK_EQ(CONTENT_SETTING_ASK, content_setting); | 82 DCHECK_EQ(CONTENT_SETTING_ASK, content_setting); |
78 | 83 |
ddorwin
2015/03/17 00:43:11
Note: Not recording the Allow is important, especi
xhwang
2015/03/17 01:33:28
Added DCHECK.
| |
79 #if defined(OS_CHROMEOS) | 84 #if defined(OS_CHROMEOS) |
80 // Since the dialog is modal, we only support one prompt per |web_contents|. | 85 // Since the dialog is modal, we only support one prompt per |web_contents|. |
81 // Reject the new one if there is already one pending. See | 86 // Reject the new one if there is already one pending. See |
82 // http://crbug.com/447005 | 87 // http://crbug.com/447005 |
83 if (pending_requests_.count(web_contents)) { | 88 if (pending_requests_.count(web_contents)) { |
84 callback.Run(CONTENT_SETTING_ASK); | 89 callback.Run(CONTENT_SETTING_ASK); |
85 return; | 90 return; |
86 } | 91 } |
87 | 92 |
88 // On ChromeOS, we don't use PermissionContextBase::RequestPermission() which | 93 // On ChromeOS, we don't use PermissionContextBase::RequestPermission() which |
(...skipping 25 matching lines...) Expand all Loading... | |
114 return CONTENT_SETTING_BLOCK; | 119 return CONTENT_SETTING_BLOCK; |
115 } | 120 } |
116 | 121 |
117 ContentSetting content_setting = PermissionContextBase::GetPermissionStatus( | 122 ContentSetting content_setting = PermissionContextBase::GetPermissionStatus( |
118 requesting_origin, embedding_origin); | 123 requesting_origin, embedding_origin); |
119 DCHECK(content_setting == CONTENT_SETTING_ALLOW || | 124 DCHECK(content_setting == CONTENT_SETTING_ALLOW || |
120 content_setting == CONTENT_SETTING_BLOCK || | 125 content_setting == CONTENT_SETTING_BLOCK || |
121 content_setting == CONTENT_SETTING_ASK); | 126 content_setting == CONTENT_SETTING_ASK); |
122 | 127 |
123 #if defined(OS_CHROMEOS) | 128 #if defined(OS_CHROMEOS) |
124 if (content_setting == CONTENT_SETTING_ALLOW) { | 129 // Check kRAConsentGranted here because it's possible that user dismissed |
125 // Check kRAConsentGranted here because it's possible that user dismissed | 130 // the dialog triggered by RequestPermission() and the content setting is |
126 // the dialog triggered by RequestPermission() and the content setting is | 131 // set to "allow" by server sync. In this case, we should still "ask". |
127 // set to "allow" by server sync. In this case, we should still "ask". | 132 if (content_setting == CONTENT_SETTING_ALLOW && |
128 if (profile()->GetPrefs()->GetBoolean(prefs::kRAConsentGranted)) | 133 !profile()->GetPrefs()->GetBoolean(prefs::kRAConsentGranted)) { |
129 return CONTENT_SETTING_ALLOW; | 134 content_setting = CONTENT_SETTING_ASK; |
130 else | 135 } |
131 return CONTENT_SETTING_ASK; | 136 #elif defined(OS_ANDROID) |
137 // When kDisableInfobarForProtectedMediaIdentifier is enabled, do not "ask" | |
138 // the user and always "allow". | |
139 if (content_setting == CONTENT_SETTING_ASK && | |
140 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
141 switches::kDisableInfobarForProtectedMediaIdentifier)) { | |
142 content_setting = CONTENT_SETTING_ALLOW; | |
132 } | 143 } |
133 #endif | 144 #endif |
134 | 145 |
135 return content_setting; | 146 return content_setting; |
136 } | 147 } |
137 | 148 |
138 void ProtectedMediaIdentifierPermissionContext::CancelPermissionRequest( | 149 void ProtectedMediaIdentifierPermissionContext::CancelPermissionRequest( |
139 content::WebContents* web_contents, | 150 content::WebContents* web_contents, |
140 const PermissionRequestID& id) { | 151 const PermissionRequestID& id) { |
141 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 152 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 pref_service->SetBoolean(prefs::kRAConsentGranted, true); | 228 pref_service->SetBoolean(prefs::kRAConsentGranted, true); |
218 } | 229 } |
219 | 230 |
220 void ProtectedMediaIdentifierPermissionContext:: | 231 void ProtectedMediaIdentifierPermissionContext:: |
221 OnPlatformVerificationConsentResponse( | 232 OnPlatformVerificationConsentResponse( |
222 content::WebContents* web_contents, | 233 content::WebContents* web_contents, |
223 const PermissionRequestID& id, | 234 const PermissionRequestID& id, |
224 const GURL& requesting_origin, | 235 const GURL& requesting_origin, |
225 const GURL& embedding_origin, | 236 const GURL& embedding_origin, |
226 const BrowserPermissionCallback& callback, | 237 const BrowserPermissionCallback& callback, |
227 chromeos::attestation::PlatformVerificationDialog::ConsentResponse | 238 PlatformVerificationDialog::ConsentResponse response) { |
228 response) { | |
229 // The request may have been canceled. Drop the callback in that case. | 239 // The request may have been canceled. Drop the callback in that case. |
230 PendingRequestMap::iterator request = pending_requests_.find(web_contents); | 240 PendingRequestMap::iterator request = pending_requests_.find(web_contents); |
231 if (request == pending_requests_.end()) | 241 if (request == pending_requests_.end()) |
232 return; | 242 return; |
233 | 243 |
234 DCHECK(request->second.second.Equals(id)); | 244 DCHECK(request->second.second.Equals(id)); |
235 pending_requests_.erase(request); | 245 pending_requests_.erase(request); |
236 | 246 |
237 ContentSetting content_setting = CONTENT_SETTING_ASK; | 247 ContentSetting content_setting = CONTENT_SETTING_ASK; |
238 bool persist = false; // Whether the ContentSetting should be saved. | 248 bool persist = false; // Whether the ContentSetting should be saved. |
(...skipping 17 matching lines...) Expand all Loading... | |
256 content_setting = CONTENT_SETTING_BLOCK; | 266 content_setting = CONTENT_SETTING_BLOCK; |
257 persist = true; | 267 persist = true; |
258 break; | 268 break; |
259 } | 269 } |
260 | 270 |
261 NotifyPermissionSet( | 271 NotifyPermissionSet( |
262 id, requesting_origin, embedding_origin, callback, | 272 id, requesting_origin, embedding_origin, callback, |
263 persist, content_setting); | 273 persist, content_setting); |
264 } | 274 } |
265 #endif | 275 #endif |
OLD | NEW |