| 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/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 14 | 15 |
| 15 #if defined(OS_CHROMEOS) | 16 #if defined(OS_CHROMEOS) |
| 16 #include <utility> | 17 #include <utility> |
| 17 | 18 |
| 18 #include "chrome/browser/chromeos/attestation/platform_verification_dialog.h" | 19 #include "chrome/browser/chromeos/attestation/platform_verification_dialog.h" |
| 19 #include "chrome/browser/chromeos/settings/cros_settings.h" | 20 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 20 #include "chromeos/settings/cros_settings_names.h" | 21 #include "chromeos/settings/cros_settings_names.h" |
| 22 #include "components/user_prefs/user_prefs.h" |
| 21 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
| 22 | 24 |
| 23 using chromeos::attestation::PlatformVerificationDialog; | 25 using chromeos::attestation::PlatformVerificationDialog; |
| 24 using chromeos::attestation::PlatformVerificationFlow; | 26 using chromeos::attestation::PlatformVerificationFlow; |
| 25 #endif | 27 #endif |
| 26 | 28 |
| 27 ProtectedMediaIdentifierPermissionContext:: | 29 ProtectedMediaIdentifierPermissionContext:: |
| 28 ProtectedMediaIdentifierPermissionContext(Profile* profile) | 30 ProtectedMediaIdentifierPermissionContext(Profile* profile) |
| 29 : PermissionContextBase(profile, | 31 : PermissionContextBase(profile, |
| 30 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) | 32 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 42 void ProtectedMediaIdentifierPermissionContext::RequestPermission( | 44 void ProtectedMediaIdentifierPermissionContext::RequestPermission( |
| 43 content::WebContents* web_contents, | 45 content::WebContents* web_contents, |
| 44 const PermissionRequestID& id, | 46 const PermissionRequestID& id, |
| 45 const GURL& requesting_origin, | 47 const GURL& requesting_origin, |
| 46 bool user_gesture, | 48 bool user_gesture, |
| 47 const BrowserPermissionCallback& callback) { | 49 const BrowserPermissionCallback& callback) { |
| 48 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 50 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 49 | 51 |
| 50 GURL embedding_origin = web_contents->GetLastCommittedURL().GetOrigin(); | 52 GURL embedding_origin = web_contents->GetLastCommittedURL().GetOrigin(); |
| 51 | 53 |
| 54 DVLOG(1) << __FUNCTION__ << ": (" << requesting_origin.spec() << ", " |
| 55 << embedding_origin.spec() << ")"; |
| 56 |
| 52 if (!requesting_origin.is_valid() || !embedding_origin.is_valid() || | 57 if (!requesting_origin.is_valid() || !embedding_origin.is_valid() || |
| 53 !IsProtectedMediaIdentifierEnabled()) { | 58 !IsProtectedMediaIdentifierEnabled()) { |
| 54 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 59 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 55 false /* persist */, CONTENT_SETTING_BLOCK); | 60 false /* persist */, CONTENT_SETTING_BLOCK); |
| 56 return; | 61 return; |
| 57 } | 62 } |
| 58 | 63 |
| 59 #if defined(OS_CHROMEOS) | 64 #if defined(OS_CHROMEOS) |
| 60 // On ChromeOS, we don't use PermissionContextBase::RequestPermission() which | 65 ContentSetting content_setting = PermissionContextBase::GetPermissionStatus( |
| 61 // uses the standard permission infobar/bubble UI. See http://crbug.com/454847 | 66 requesting_origin, embedding_origin); |
| 62 // Instead, we check the content setting and show the existing platform | 67 if (content_setting == CONTENT_SETTING_BLOCK) { |
| 63 // verification UI. | |
| 64 // TODO(xhwang): Remove when http://crbug.com/454847 is fixed. | |
| 65 ContentSetting content_setting = | |
| 66 GetPermissionStatus(requesting_origin, embedding_origin); | |
| 67 | |
| 68 if (content_setting == CONTENT_SETTING_ALLOW || | |
| 69 content_setting == CONTENT_SETTING_BLOCK) { | |
| 70 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 68 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 71 false /* persist */, content_setting); | 69 false /* persist */, CONTENT_SETTING_BLOCK); |
| 72 return; | 70 return; |
| 73 } | 71 } |
| 74 | 72 |
| 73 // Consent required if user has never given consent for this origin, or if |
| 74 // user has never given consent to attestation for content protection on this |
| 75 // device. |
| 76 bool consent_required = |
| 77 content_setting != CONTENT_SETTING_ALLOW || |
| 78 !profile()->GetPrefs()->GetBoolean(prefs::kRAConsentGranted); |
| 79 |
| 80 if (!consent_required) { |
| 81 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 82 false /* persist */, CONTENT_SETTING_ALLOW); |
| 83 return; |
| 84 } |
| 85 |
| 75 // Since the dialog is modal, we only support one prompt per |web_contents|. | 86 // Since the dialog is modal, we only support one prompt per |web_contents|. |
| 76 // Reject the new one if there is already one pending. See | 87 // Reject the new one if there is already one pending. See |
| 77 // http://crbug.com/447005 | 88 // http://crbug.com/447005 |
| 78 if (pending_requests_.count(web_contents)) { | 89 if (pending_requests_.count(web_contents)) { |
| 79 callback.Run(CONTENT_SETTING_DEFAULT); | 90 callback.Run(CONTENT_SETTING_DEFAULT); |
| 80 return; | 91 return; |
| 81 } | 92 } |
| 82 | 93 |
| 94 // On ChromeOS, we don't use PermissionContextBase::RequestPermission() which |
| 95 // uses the standard permission infobar/bubble UI. See http://crbug.com/454847 |
| 96 // Instead, we check the content setting and show the existing platform |
| 97 // verification UI. |
| 98 // TODO(xhwang): Remove when http://crbug.com/454847 is fixed. |
| 83 views::Widget* widget = PlatformVerificationDialog::ShowDialog( | 99 views::Widget* widget = PlatformVerificationDialog::ShowDialog( |
| 84 web_contents, requesting_origin, | 100 web_contents, requesting_origin, |
| 85 base::Bind(&ProtectedMediaIdentifierPermissionContext:: | 101 base::Bind(&ProtectedMediaIdentifierPermissionContext:: |
| 86 OnPlatformVerificationResult, | 102 OnPlatformVerificationConsentResponse, |
| 87 weak_factory_.GetWeakPtr(), web_contents, id, | 103 weak_factory_.GetWeakPtr(), web_contents, id, |
| 88 requesting_origin, embedding_origin, callback)); | 104 requesting_origin, embedding_origin, callback)); |
| 89 pending_requests_.insert( | 105 pending_requests_.insert( |
| 90 std::make_pair(web_contents, std::make_pair(widget, id))); | 106 std::make_pair(web_contents, std::make_pair(widget, id))); |
| 91 #else | 107 #else |
| 92 PermissionContextBase::RequestPermission(web_contents, id, requesting_origin, | 108 PermissionContextBase::RequestPermission(web_contents, id, requesting_origin, |
| 93 user_gesture, callback); | 109 user_gesture, callback); |
| 94 #endif | 110 #endif |
| 95 } | 111 } |
| 96 | 112 |
| 97 ContentSetting ProtectedMediaIdentifierPermissionContext::GetPermissionStatus( | 113 ContentSetting ProtectedMediaIdentifierPermissionContext::GetPermissionStatus( |
| 98 const GURL& requesting_origin, | 114 const GURL& requesting_origin, |
| 99 const GURL& embedding_origin) const { | 115 const GURL& embedding_origin) const { |
| 116 DVLOG(1) << __FUNCTION__ << ": (" << requesting_origin.spec() << ", " |
| 117 << embedding_origin.spec() << ")"; |
| 118 |
| 100 if (!IsProtectedMediaIdentifierEnabled()) | 119 if (!IsProtectedMediaIdentifierEnabled()) |
| 101 return CONTENT_SETTING_BLOCK; | 120 return CONTENT_SETTING_BLOCK; |
| 102 | 121 |
| 122 #if defined(OS_CHROMEOS) |
| 123 // Block if user never granted RA consent on this device. It's possible that |
| 124 // user dismissed the dialog triggered by RequestPermission() and the content |
| 125 // setting is set to "allow" by server sync. In this case, we should block. |
| 126 if (!profile()->GetPrefs()->GetBoolean(prefs::kRAConsentGranted)) { |
| 127 DVLOG(1) << "RA consent never granted on this device."; |
| 128 return CONTENT_SETTING_BLOCK; |
| 129 } |
| 130 #endif |
| 131 |
| 103 return PermissionContextBase::GetPermissionStatus(requesting_origin, | 132 return PermissionContextBase::GetPermissionStatus(requesting_origin, |
| 104 embedding_origin); | 133 embedding_origin); |
| 105 } | 134 } |
| 106 | 135 |
| 107 void ProtectedMediaIdentifierPermissionContext::CancelPermissionRequest( | 136 void ProtectedMediaIdentifierPermissionContext::CancelPermissionRequest( |
| 108 content::WebContents* web_contents, | 137 content::WebContents* web_contents, |
| 109 const PermissionRequestID& id) { | 138 const PermissionRequestID& id) { |
| 110 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 139 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 111 | 140 |
| 112 #if defined(OS_CHROMEOS) | 141 #if defined(OS_CHROMEOS) |
| 113 PendingRequestMap::iterator request = pending_requests_.find(web_contents); | 142 PendingRequestMap::iterator request = pending_requests_.find(web_contents); |
| 114 if (request == pending_requests_.end() || !request->second.second.Equals(id)) | 143 if (request == pending_requests_.end() || !request->second.second.Equals(id)) |
| 115 return; | 144 return; |
| 116 | 145 |
| 117 // Close the |widget_|. OnPlatformVerificationResult() will be fired | 146 // Close the |widget_|. OnPlatformVerificationConsentResponse() will be fired |
| 118 // during this process, but since |web_contents| is removed from | 147 // during this process, but since |web_contents| is removed from |
| 119 // |pending_requests_|, the callback will simply be dropped. | 148 // |pending_requests_|, the callback will simply be dropped. |
| 120 views::Widget* widget = request->second.first; | 149 views::Widget* widget = request->second.first; |
| 121 pending_requests_.erase(request); | 150 pending_requests_.erase(request); |
| 122 widget->Close(); | 151 widget->Close(); |
| 123 #else | 152 #else |
| 124 PermissionContextBase::CancelPermissionRequest(web_contents, id); | 153 PermissionContextBase::CancelPermissionRequest(web_contents, id); |
| 125 #endif | 154 #endif |
| 126 } | 155 } |
| 127 | 156 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 138 if (content_settings) { | 167 if (content_settings) { |
| 139 content_settings->OnProtectedMediaIdentifierPermissionSet( | 168 content_settings->OnProtectedMediaIdentifierPermissionSet( |
| 140 requesting_frame.GetOrigin(), allowed); | 169 requesting_frame.GetOrigin(), allowed); |
| 141 } | 170 } |
| 142 } | 171 } |
| 143 | 172 |
| 144 // TODO(xhwang): We should consolidate the "protected content" related pref | 173 // TODO(xhwang): We should consolidate the "protected content" related pref |
| 145 // across platforms. | 174 // across platforms. |
| 146 bool ProtectedMediaIdentifierPermissionContext:: | 175 bool ProtectedMediaIdentifierPermissionContext:: |
| 147 IsProtectedMediaIdentifierEnabled() const { | 176 IsProtectedMediaIdentifierEnabled() const { |
| 148 bool enabled = false; | |
| 149 | |
| 150 #if defined(OS_ANDROID) | 177 #if defined(OS_ANDROID) |
| 151 enabled = profile()->GetPrefs()->GetBoolean( | 178 if (!profile()->GetPrefs()->GetBoolean( |
| 152 prefs::kProtectedMediaIdentifierEnabled); | 179 prefs::kProtectedMediaIdentifierEnabled)) { |
| 180 DVLOG(1) << "Protected media identifier disabled by a user master switch."; |
| 181 return false; |
| 182 } |
| 153 #endif | 183 #endif |
| 154 | 184 |
| 155 #if defined(OS_CHROMEOS) | 185 #if defined(OS_CHROMEOS) |
| 156 // This could be disabled by the device policy. | 186 // Platform verification is not allowed in incognito or guest mode. |
| 187 if (profile()->IsOffTheRecord() || profile()->IsGuestSession()) { |
| 188 DVLOG(1) << "Protected media identifier disabled in incognito or guest " |
| 189 "mode."; |
| 190 return false; |
| 191 } |
| 192 |
| 193 // This could be disabled by user's master switch or by the device policy. |
| 157 bool enabled_for_device = false; | 194 bool enabled_for_device = false; |
| 158 enabled = chromeos::CrosSettings::Get()->GetBoolean( | 195 if (!chromeos::CrosSettings::Get()->GetBoolean( |
| 159 chromeos::kAttestationForContentProtectionEnabled, | 196 chromeos::kAttestationForContentProtectionEnabled, |
| 160 &enabled_for_device) && | 197 &enabled_for_device) || |
| 161 enabled_for_device && | 198 !enabled_for_device || |
| 162 profile()->GetPrefs()->GetBoolean(prefs::kEnableDRM); | 199 !profile()->GetPrefs()->GetBoolean(prefs::kEnableDRM)) { |
| 200 DVLOG(1) << "Protected media identifier disabled by the user or by device " |
| 201 "policy."; |
| 202 return false; |
| 203 } |
| 163 #endif | 204 #endif |
| 164 | 205 |
| 165 DVLOG_IF(1, !enabled) | 206 return true; |
| 166 << "Protected media identifier disabled by the user or by device policy."; | |
| 167 return enabled; | |
| 168 } | 207 } |
| 169 | 208 |
| 170 #if defined(OS_CHROMEOS) | 209 #if defined(OS_CHROMEOS) |
| 171 void ProtectedMediaIdentifierPermissionContext::OnPlatformVerificationResult( | 210 static void RecordRAConsentGranted(content::WebContents* web_contents) { |
| 172 content::WebContents* web_contents, | 211 PrefService* pref_service = |
| 173 const PermissionRequestID& id, | 212 user_prefs::UserPrefs::Get(web_contents->GetBrowserContext()); |
| 174 const GURL& requesting_origin, | 213 if (!pref_service) { |
| 175 const GURL& embedding_origin, | 214 LOG(ERROR) << "Failed to get user prefs."; |
| 176 const BrowserPermissionCallback& callback, | 215 return; |
| 177 chromeos::attestation::PlatformVerificationFlow::ConsentResponse response) { | 216 } |
| 217 pref_service->SetBoolean(prefs::kRAConsentGranted, true); |
| 218 } |
| 219 |
| 220 void ProtectedMediaIdentifierPermissionContext:: |
| 221 OnPlatformVerificationConsentResponse( |
| 222 content::WebContents* web_contents, |
| 223 const PermissionRequestID& id, |
| 224 const GURL& requesting_origin, |
| 225 const GURL& embedding_origin, |
| 226 const BrowserPermissionCallback& callback, |
| 227 chromeos::attestation::PlatformVerificationDialog::ConsentResponse |
| 228 response) { |
| 178 // The request may have been canceled. Drop the callback in that case. | 229 // The request may have been canceled. Drop the callback in that case. |
| 179 PendingRequestMap::iterator request = pending_requests_.find(web_contents); | 230 PendingRequestMap::iterator request = pending_requests_.find(web_contents); |
| 180 if (request == pending_requests_.end()) | 231 if (request == pending_requests_.end()) |
| 181 return; | 232 return; |
| 182 | 233 |
| 183 DCHECK(request->second.second.Equals(id)); | 234 DCHECK(request->second.second.Equals(id)); |
| 184 pending_requests_.erase(request); | 235 pending_requests_.erase(request); |
| 185 | 236 |
| 186 ContentSetting content_setting = CONTENT_SETTING_DEFAULT; | 237 ContentSetting content_setting = CONTENT_SETTING_DEFAULT; |
| 187 bool persist = false; // Whether the ContentSetting should be saved. | 238 bool persist = false; // Whether the ContentSetting should be saved. |
| 188 switch (response) { | 239 switch (response) { |
| 189 case PlatformVerificationFlow::CONSENT_RESPONSE_NONE: | 240 case PlatformVerificationDialog::CONSENT_RESPONSE_NONE: |
| 190 content_setting = CONTENT_SETTING_DEFAULT; | 241 content_setting = CONTENT_SETTING_DEFAULT; |
| 191 persist = false; | 242 persist = false; |
| 192 break; | 243 break; |
| 193 case PlatformVerificationFlow::CONSENT_RESPONSE_ALLOW: | 244 case PlatformVerificationDialog::CONSENT_RESPONSE_ALLOW: |
| 245 VLOG(1) << "Platform verification accepted by user."; |
| 246 content::RecordAction( |
| 247 base::UserMetricsAction("PlatformVerificationAccepted")); |
| 248 RecordRAConsentGranted(web_contents); |
| 194 content_setting = CONTENT_SETTING_ALLOW; | 249 content_setting = CONTENT_SETTING_ALLOW; |
| 195 persist = true; | 250 persist = true; |
| 196 break; | 251 break; |
| 197 case PlatformVerificationFlow::CONSENT_RESPONSE_DENY: | 252 case PlatformVerificationDialog::CONSENT_RESPONSE_DENY: |
| 253 VLOG(1) << "Platform verification denied by user."; |
| 254 content::RecordAction( |
| 255 base::UserMetricsAction("PlatformVerificationRejected")); |
| 198 content_setting = CONTENT_SETTING_BLOCK; | 256 content_setting = CONTENT_SETTING_BLOCK; |
| 199 persist = true; | 257 persist = true; |
| 200 break; | 258 break; |
| 201 } | 259 } |
| 202 | 260 |
| 203 NotifyPermissionSet( | 261 NotifyPermissionSet( |
| 204 id, requesting_origin, embedding_origin, callback, | 262 id, requesting_origin, embedding_origin, callback, |
| 205 persist, content_setting); | 263 persist, content_setting); |
| 206 } | 264 } |
| 207 #endif | 265 #endif |
| OLD | NEW |