| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/user_metrics.h" | 8 #include "base/metrics/user_metrics.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 11 #include "chrome/browser/permissions/permission_util.h" | 11 #include "chrome/browser/permissions/permission_util.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 14 #include "components/prefs/pref_service.h" | 14 #include "components/prefs/pref_service.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/render_frame_host.h" | 16 #include "content/public/browser/render_frame_host.h" |
| 17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 18 #if defined(OS_CHROMEOS) | 18 #if defined(OS_CHROMEOS) |
| 19 #include <utility> | 19 #include <utility> |
| 20 | 20 |
| 21 #include "base/metrics/histogram_macros.h" |
| 21 #include "chrome/browser/chromeos/attestation/platform_verification_dialog.h" | 22 #include "chrome/browser/chromeos/attestation/platform_verification_dialog.h" |
| 22 #include "chrome/browser/chromeos/settings/cros_settings.h" | 23 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 23 #include "chromeos/chromeos_switches.h" | 24 #include "chromeos/chromeos_switches.h" |
| 24 #include "chromeos/settings/cros_settings_names.h" | 25 #include "chromeos/settings/cros_settings_names.h" |
| 25 #include "components/pref_registry/pref_registry_syncable.h" | 26 #include "components/pref_registry/pref_registry_syncable.h" |
| 26 #include "components/user_prefs/user_prefs.h" | 27 #include "components/user_prefs/user_prefs.h" |
| 27 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
| 28 #elif !defined(OS_ANDROID) | 29 #elif !defined(OS_ANDROID) |
| 29 #error This file currently only supports Chrome OS and Android. | 30 #error This file currently only supports Chrome OS and Android. |
| 30 #endif | 31 #endif |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 DVLOG(1) << "Protected media identifier disabled by the user or by device " | 180 DVLOG(1) << "Protected media identifier disabled by the user or by device " |
| 180 "policy."; | 181 "policy."; |
| 181 return false; | 182 return false; |
| 182 } | 183 } |
| 183 #endif | 184 #endif |
| 184 | 185 |
| 185 return true; | 186 return true; |
| 186 } | 187 } |
| 187 | 188 |
| 188 #if defined(OS_CHROMEOS) | 189 #if defined(OS_CHROMEOS) |
| 190 |
| 191 static void ReportPermissionActionUMA(PermissionAction action) { |
| 192 UMA_HISTOGRAM_ENUMERATION("Permissions.Action.ProtectedMedia", action, |
| 193 PermissionAction::NUM); |
| 194 } |
| 195 |
| 189 void ProtectedMediaIdentifierPermissionContext:: | 196 void ProtectedMediaIdentifierPermissionContext:: |
| 190 OnPlatformVerificationConsentResponse( | 197 OnPlatformVerificationConsentResponse( |
| 191 content::WebContents* web_contents, | 198 content::WebContents* web_contents, |
| 192 const PermissionRequestID& id, | 199 const PermissionRequestID& id, |
| 193 const GURL& requesting_origin, | 200 const GURL& requesting_origin, |
| 194 const GURL& embedding_origin, | 201 const GURL& embedding_origin, |
| 195 const BrowserPermissionCallback& callback, | 202 const BrowserPermissionCallback& callback, |
| 196 PlatformVerificationDialog::ConsentResponse response) { | 203 PlatformVerificationDialog::ConsentResponse response) { |
| 197 // The request may have been canceled. Drop the callback in that case. | 204 // The request may have been canceled. Drop the callback in that case. |
| 205 // This can happen if the tab is closed. |
| 198 PendingRequestMap::iterator request = pending_requests_.find(web_contents); | 206 PendingRequestMap::iterator request = pending_requests_.find(web_contents); |
| 199 if (request == pending_requests_.end()) | 207 if (request == pending_requests_.end()) { |
| 208 VLOG(1) << "Platform verification ignored by user."; |
| 209 ReportPermissionActionUMA(PermissionAction::IGNORED); |
| 200 return; | 210 return; |
| 211 } |
| 201 | 212 |
| 202 DCHECK(request->second.second == id); | 213 DCHECK(request->second.second == id); |
| 203 pending_requests_.erase(request); | 214 pending_requests_.erase(request); |
| 204 | 215 |
| 205 ContentSetting content_setting = CONTENT_SETTING_ASK; | 216 ContentSetting content_setting = CONTENT_SETTING_ASK; |
| 206 bool persist = false; // Whether the ContentSetting should be saved. | 217 bool persist = false; // Whether the ContentSetting should be saved. |
| 207 switch (response) { | 218 switch (response) { |
| 208 case PlatformVerificationDialog::CONSENT_RESPONSE_NONE: | 219 case PlatformVerificationDialog::CONSENT_RESPONSE_NONE: |
| 220 // This can happen if user clicked "x", or pressed "Esc", or navigated |
| 221 // away without closing the tab. |
| 209 VLOG(1) << "Platform verification dismissed by user."; | 222 VLOG(1) << "Platform verification dismissed by user."; |
| 223 ReportPermissionActionUMA(PermissionAction::DISMISSED); |
| 210 content_setting = CONTENT_SETTING_ASK; | 224 content_setting = CONTENT_SETTING_ASK; |
| 211 persist = false; | 225 persist = false; |
| 212 break; | 226 break; |
| 213 case PlatformVerificationDialog::CONSENT_RESPONSE_ALLOW: | 227 case PlatformVerificationDialog::CONSENT_RESPONSE_ALLOW: |
| 214 VLOG(1) << "Platform verification accepted by user."; | 228 VLOG(1) << "Platform verification accepted by user."; |
| 215 base::RecordAction( | 229 base::RecordAction( |
| 216 base::UserMetricsAction("PlatformVerificationAccepted")); | 230 base::UserMetricsAction("PlatformVerificationAccepted")); |
| 231 ReportPermissionActionUMA(PermissionAction::GRANTED); |
| 217 content_setting = CONTENT_SETTING_ALLOW; | 232 content_setting = CONTENT_SETTING_ALLOW; |
| 218 persist = true; | 233 persist = true; |
| 219 break; | 234 break; |
| 220 case PlatformVerificationDialog::CONSENT_RESPONSE_DENY: | 235 case PlatformVerificationDialog::CONSENT_RESPONSE_DENY: |
| 221 VLOG(1) << "Platform verification denied by user."; | 236 VLOG(1) << "Platform verification denied by user."; |
| 222 base::RecordAction( | 237 base::RecordAction( |
| 223 base::UserMetricsAction("PlatformVerificationRejected")); | 238 base::UserMetricsAction("PlatformVerificationRejected")); |
| 239 ReportPermissionActionUMA(PermissionAction::DENIED); |
| 224 content_setting = CONTENT_SETTING_BLOCK; | 240 content_setting = CONTENT_SETTING_BLOCK; |
| 225 persist = true; | 241 persist = true; |
| 226 break; | 242 break; |
| 227 } | 243 } |
| 228 | 244 |
| 229 NotifyPermissionSet( | 245 NotifyPermissionSet( |
| 230 id, requesting_origin, embedding_origin, callback, | 246 id, requesting_origin, embedding_origin, callback, |
| 231 persist, content_setting); | 247 persist, content_setting); |
| 232 } | 248 } |
| 233 #endif | 249 #endif |
| OLD | NEW |