From f961a0fedd9bfae93284d6d0d989f42da3caac7b Mon Sep 17 00:00:00 2001
From: "kkimlabs@chromium.org"
 <kkimlabs@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>
Date: Mon, 23 Sep 2013 04:15:45 +0000
Subject: [Android] EME permission on/off pref and infobar UI.

For protected media identifier access permission,
add global on/off preference setting and infobar permission gate UI.

BUG=281576

Review URL: https://chromiumcodereview.appspot.com/23531021

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224650 0039d316-1c4b-4281-b951-d872f2087c98
---
 .../protected_media_identifier_infobar_delegate.cc | 108 +++++++++++++++++++++
 1 file changed, 108 insertions(+)
 create mode 100644 chrome/browser/media/protected_media_identifier_infobar_delegate.cc

(limited to 'chrome/browser/media/protected_media_identifier_infobar_delegate.cc')

diff --git a/chrome/browser/media/protected_media_identifier_infobar_delegate.cc b/chrome/browser/media/protected_media_identifier_infobar_delegate.cc
new file mode 100644
index 0000000..bde3fbf
--- /dev/null
+++ b/chrome/browser/media/protected_media_identifier_infobar_delegate.cc
@@ -0,0 +1,108 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/media/protected_media_identifier_infobar_delegate.h"
+
+#include "chrome/browser/content_settings/permission_queue_controller.h"
+#include "content/public/browser/navigation_details.h"
+#include "content/public/browser/navigation_entry.h"
+#include "grit/generated_resources.h"
+#include "grit/theme_resources.h"
+#include "net/base/net_util.h"
+#include "ui/base/l10n/l10n_util.h"
+
+// static
+InfoBarDelegate* ProtectedMediaIdentifierInfoBarDelegate::Create(
+    InfoBarService* infobar_service,
+    PermissionQueueController* controller,
+    const PermissionRequestID& id,
+    const GURL& requesting_frame,
+    const std::string& display_languages) {
+  const content::NavigationEntry* committed_entry =
+      infobar_service->web_contents()->GetController().GetLastCommittedEntry();
+  return infobar_service->AddInfoBar(
+      scoped_ptr<InfoBarDelegate>(new ProtectedMediaIdentifierInfoBarDelegate(
+          infobar_service,
+          controller,
+          id,
+          requesting_frame,
+          committed_entry ? committed_entry->GetUniqueID() : 0,
+          display_languages)));
+}
+
+
+ProtectedMediaIdentifierInfoBarDelegate::
+    ProtectedMediaIdentifierInfoBarDelegate(
+        InfoBarService* infobar_service,
+        PermissionQueueController* controller,
+        const PermissionRequestID& id,
+        const GURL& requesting_frame,
+        int contents_unique_id,
+        const std::string& display_languages)
+    : ConfirmInfoBarDelegate(infobar_service),
+      controller_(controller),
+      id_(id),
+      requesting_frame_(requesting_frame),
+      contents_unique_id_(contents_unique_id),
+      display_languages_(display_languages) {}
+
+ProtectedMediaIdentifierInfoBarDelegate::
+    ~ProtectedMediaIdentifierInfoBarDelegate() {}
+
+bool ProtectedMediaIdentifierInfoBarDelegate::Accept() {
+  SetPermission(true, true);
+  return true;
+}
+
+void ProtectedMediaIdentifierInfoBarDelegate::SetPermission(
+    bool update_content_setting,
+    bool allowed) {
+  controller_->OnPermissionSet(id_,
+                               requesting_frame_,
+                               web_contents()->GetLastCommittedURL(),
+                               update_content_setting,
+                               allowed);
+}
+
+void ProtectedMediaIdentifierInfoBarDelegate::InfoBarDismissed() {
+  SetPermission(false, false);
+}
+
+int ProtectedMediaIdentifierInfoBarDelegate::GetIconID() const {
+  return IDR_PROTECTED_MEDIA_IDENTIFIER_INFOBAR_ICON;
+}
+
+InfoBarDelegate::Type ProtectedMediaIdentifierInfoBarDelegate::GetInfoBarType()
+    const {
+  return PAGE_ACTION_TYPE;
+}
+
+bool ProtectedMediaIdentifierInfoBarDelegate::ShouldExpireInternal(
+    const content::LoadCommittedDetails& details) const {
+  // This implementation matches InfoBarDelegate::ShouldExpireInternal(), but
+  // uses the unique ID we set in the constructor instead of that stored in the
+  // base class.
+  return (contents_unique_id_ != details.entry->GetUniqueID()) ||
+      (content::PageTransitionStripQualifier(
+          details.entry->GetTransitionType()) ==
+              content::PAGE_TRANSITION_RELOAD);
+}
+
+string16 ProtectedMediaIdentifierInfoBarDelegate::GetMessageText() const {
+  return l10n_util::GetStringFUTF16(
+      IDS_PROTECTED_MEDIA_IDENTIFIER_INFOBAR_QUESTION,
+      net::FormatUrl(requesting_frame_.GetOrigin(), display_languages_));
+}
+
+string16 ProtectedMediaIdentifierInfoBarDelegate::GetButtonLabel(
+    InfoBarButton button) const {
+  return l10n_util::GetStringUTF16(
+      (button == BUTTON_OK) ? IDS_PROTECTED_MEDIA_IDENTIFIER_ALLOW_BUTTON
+                            : IDS_PROTECTED_MEDIA_IDENTIFIER_DENY_BUTTON);
+}
+
+bool ProtectedMediaIdentifierInfoBarDelegate::Cancel() {
+  SetPermission(true, false);
+  return true;
+}
-- 
cgit v1.1