| Index: chrome/browser/media/protected_media_identifier_permission_context.cc
|
| diff --git a/chrome/browser/media/protected_media_identifier_permission_context.cc b/chrome/browser/media/protected_media_identifier_permission_context.cc
|
| index 990be4c913e70ad32e41955653b9c0b37cf8ebbb..ddea1247fc4c5af803bbf0dc32c76bdc04bdb74c 100644
|
| --- a/chrome/browser/media/protected_media_identifier_permission_context.cc
|
| +++ b/chrome/browser/media/protected_media_identifier_permission_context.cc
|
| @@ -13,14 +13,34 @@
|
| #include "content/public/browser/web_contents.h"
|
|
|
| #if defined(OS_CHROMEOS)
|
| +#include "chrome/browser/chromeos/attestation/platform_verification_dialog.h"
|
| #include "chrome/browser/chromeos/settings/cros_settings.h"
|
| #include "chromeos/settings/cros_settings_names.h"
|
| +#include "ui/views/widget/widget.h"
|
| +
|
| +using chromeos::attestation::PlatformVerificationDialog;
|
| +using chromeos::attestation::PlatformVerificationFlow;
|
| +#endif
|
| +
|
| +#if defined(OS_CHROMEOS)
|
| +namespace {
|
| +PermissionRequestID GetInvalidPendingId() {
|
| + return PermissionRequestID(-1, -1, -1, GURL());
|
| +}
|
| +}
|
| #endif
|
|
|
| ProtectedMediaIdentifierPermissionContext::
|
| ProtectedMediaIdentifierPermissionContext(Profile* profile)
|
| : PermissionContextBase(profile,
|
| - CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) {
|
| + CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER)
|
| +#if defined(OS_CHROMEOS)
|
| + ,
|
| + pending_id_(GetInvalidPendingId()),
|
| + widget_(nullptr),
|
| + weak_factory_(this)
|
| +#endif
|
| +{
|
| }
|
|
|
| ProtectedMediaIdentifierPermissionContext::
|
| @@ -30,23 +50,61 @@ ProtectedMediaIdentifierPermissionContext::
|
| void ProtectedMediaIdentifierPermissionContext::RequestPermission(
|
| content::WebContents* web_contents,
|
| const PermissionRequestID& id,
|
| - const GURL& requesting_frame_origin,
|
| + const GURL& requesting_origin,
|
| bool user_gesture,
|
| const BrowserPermissionCallback& callback) {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
|
|
| - if (!IsProtectedMediaIdentifierEnabled()) {
|
| - NotifyPermissionSet(id,
|
| - requesting_frame_origin,
|
| - web_contents->GetLastCommittedURL().GetOrigin(),
|
| - callback, false, false);
|
| + GURL embedding_origin = web_contents->GetLastCommittedURL().GetOrigin();
|
| +
|
| + if (!requesting_origin.is_valid() || !embedding_origin.is_valid() ||
|
| + !IsProtectedMediaIdentifierEnabled()) {
|
| + NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
|
| + false /* persist */, false /* granted */);
|
| return;
|
| }
|
|
|
| - PermissionContextBase::RequestPermission(web_contents, id,
|
| - requesting_frame_origin,
|
| - user_gesture,
|
| - callback);
|
| +#if defined(OS_CHROMEOS)
|
| + // On ChromeOS, we don't use PermissionContextBase::RequestPermission() which
|
| + // uses the standard permission infobar/bubble UI. See http://crbug.com/454847
|
| + // Instead, we check the content setting and show the existing platform
|
| + // verification UI.
|
| + // TODO(xhwang): Remove when http://crbug.com/454847 is fixed.
|
| + ContentSetting content_setting =
|
| + GetPermissionStatus(requesting_origin, embedding_origin);
|
| +
|
| + switch (content_setting) {
|
| + case CONTENT_SETTING_BLOCK:
|
| + NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
|
| + false /* persist */, false /* granted */);
|
| + return;
|
| + case CONTENT_SETTING_ALLOW:
|
| + NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
|
| + false /* persist */, true /* granted */);
|
| + return;
|
| + default:
|
| + break;
|
| + }
|
| +
|
| + // We only support one prompt and one pending permission request.
|
| + // Reject the new one if there is already one pending. See
|
| + // http://crbug.com/447005
|
| + if (!pending_id_.Equals(GetInvalidPendingId())) {
|
| + callback.Run(false);
|
| + return;
|
| + }
|
| +
|
| + pending_id_ = id;
|
| + widget_ = PlatformVerificationDialog::ShowDialog(
|
| + web_contents, requesting_origin,
|
| + base::Bind(&ProtectedMediaIdentifierPermissionContext::
|
| + OnPlatformVerificationResult,
|
| + weak_factory_.GetWeakPtr(), id, requesting_origin,
|
| + embedding_origin, callback));
|
| +#else
|
| + PermissionContextBase::RequestPermission(web_contents, id, requesting_origin,
|
| + user_gesture, callback);
|
| +#endif
|
| }
|
|
|
| ContentSetting ProtectedMediaIdentifierPermissionContext::GetPermissionStatus(
|
| @@ -59,6 +117,26 @@ ContentSetting ProtectedMediaIdentifierPermissionContext::GetPermissionStatus(
|
| embedding_origin);
|
| }
|
|
|
| +void ProtectedMediaIdentifierPermissionContext::CancelPermissionRequest(
|
| + content::WebContents* web_contents,
|
| + const PermissionRequestID& id) {
|
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| +
|
| +#if defined(OS_CHROMEOS)
|
| + if (!widget_ || !pending_id_.Equals(id))
|
| + return;
|
| +
|
| + // Close the |widget_|. OnPlatformVerificationResult() will be fired
|
| + // during this process, but since |pending_id_| is cleared, the callback will
|
| + // be dropped.
|
| + pending_id_ = GetInvalidPendingId();
|
| + widget_->Close();
|
| + return;
|
| +#else
|
| + PermissionContextBase::CancelPermissionRequest(web_contents, id);
|
| +#endif
|
| +}
|
| +
|
| void ProtectedMediaIdentifierPermissionContext::UpdateTabContext(
|
| const PermissionRequestID& id,
|
| const GURL& requesting_frame,
|
| @@ -73,7 +151,6 @@ void ProtectedMediaIdentifierPermissionContext::UpdateTabContext(
|
| content_settings->OnProtectedMediaIdentifierPermissionSet(
|
| requesting_frame.GetOrigin(), allowed);
|
| }
|
| -
|
| }
|
|
|
| // TODO(xhwang): We should consolidate the "protected content" related pref
|
| @@ -101,3 +178,34 @@ bool ProtectedMediaIdentifierPermissionContext::
|
| << "Protected media identifier disabled by the user or by device policy.";
|
| return enabled;
|
| }
|
| +
|
| +#if defined(OS_CHROMEOS)
|
| +void ProtectedMediaIdentifierPermissionContext::OnPlatformVerificationResult(
|
| + const PermissionRequestID& id,
|
| + const GURL& requesting_origin,
|
| + const GURL& embedding_origin,
|
| + const BrowserPermissionCallback& callback,
|
| + chromeos::attestation::PlatformVerificationFlow::ConsentResponse response) {
|
| + DCHECK(widget_);
|
| + widget_ = nullptr;
|
| +
|
| + // The request may have been canceled. Drop the callback here.
|
| + if (!pending_id_.Equals(id))
|
| + return;
|
| +
|
| + pending_id_ = GetInvalidPendingId();
|
| +
|
| + if (response == PlatformVerificationFlow::CONSENT_RESPONSE_NONE) {
|
| + // Deny request and do not save to content settings.
|
| + NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
|
| + false, // Do not save to content settings.
|
| + false); // Do not allow the permission.
|
| + return;
|
| + }
|
| +
|
| + NotifyPermissionSet(
|
| + id, requesting_origin, embedding_origin, callback,
|
| + true, // Save to content settings.
|
| + response == PlatformVerificationFlow::CONSENT_RESPONSE_ALLOW);
|
| +}
|
| +#endif
|
|
|