Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / media / protected_media_identifier_permission_context.cc
index 258d817..cfe4f03 100644 (file)
@@ -9,23 +9,28 @@
 #include <vector>
 
 #include "base/bind.h"
+#include "base/prefs/pref_service.h"
 #include "base/strings/utf_string_conversions.h"
 #include "chrome/browser/content_settings/host_content_settings_map.h"
-#include "chrome/browser/content_settings/permission_request_id.h"
 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
-#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/extensions/extension_system.h"
-#include "chrome/browser/extensions/suggest_permission_util.h"
 #include "chrome/browser/profiles/profile.h"
 #include "chrome/browser/tab_contents/tab_util.h"
-#include "chrome/common/extensions/extension.h"
 #include "chrome/common/pref_names.h"
+#include "components/content_settings/core/common/permission_request_id.h"
 #include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_process_host.h"
 #include "content/public/browser/render_view_host.h"
 #include "content/public/browser/web_contents.h"
+
+#if defined(ENABLE_EXTENSIONS)
+#include "chrome/browser/extensions/extension_service.h"
+#include "extensions/browser/extension_system.h"
+#include "extensions/browser/suggest_permission_util.h"
 #include "extensions/browser/view_type_utils.h"
+#include "extensions/common/extension.h"
 
 using extensions::APIPermission;
+#endif
 
 ProtectedMediaIdentifierPermissionContext::
     ProtectedMediaIdentifierPermissionContext(Profile* profile)
@@ -41,18 +46,27 @@ ProtectedMediaIdentifierPermissionContext::
 
 void ProtectedMediaIdentifierPermissionContext::
     RequestProtectedMediaIdentifierPermission(
-        int render_process_id,
-        int render_view_id,
-        const GURL& requesting_frame,
-        const base::Callback<void(bool)>& callback) {
+        content::WebContents* web_contents,
+        const GURL& origin,
+        base::Callback<void(bool)> result_callback,
+        base::Closure* cancel_callback) {
   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
   if (shutting_down_)
     return;
 
-  content::WebContents* web_contents =
-      tab_util::GetWebContentsByID(render_process_id, render_view_id);
-  const PermissionRequestID id(render_process_id, render_view_id, 0);
+  int render_process_id = web_contents->GetRenderProcessHost()->GetID();
+  int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID();
+  if (cancel_callback) {
+    *cancel_callback = base::Bind(
+        &ProtectedMediaIdentifierPermissionContext::
+            CancelProtectedMediaIdentifierPermissionRequests,
+        this, render_process_id, render_view_id, origin);
+  }
+
+  const PermissionRequestID id(
+      render_process_id, render_view_id, 0, origin);
 
+#if defined(ENABLE_EXTENSIONS)
   if (extensions::GetViewType(web_contents) !=
       extensions::VIEW_TYPE_TAB_CONTENTS) {
     // The tab may have gone away, or the request may not be from a tab at all.
@@ -60,36 +74,37 @@ void ProtectedMediaIdentifierPermissionContext::
         << "Attempt to use protected media identifier in tabless renderer: "
         << id.ToString()
         << " (can't prompt user without a visible tab)";
-    NotifyPermissionSet(id, requesting_frame, callback, false);
+    NotifyPermissionSet(id, origin, result_callback, false);
     return;
   }
+#endif
 
   GURL embedder = web_contents->GetLastCommittedURL();
-  if (!requesting_frame.is_valid() || !embedder.is_valid()) {
+  if (!origin.is_valid() || !embedder.is_valid()) {
     LOG(WARNING)
         << "Attempt to use protected media identifier from an invalid URL: "
-        << requesting_frame << "," << embedder
+        << origin << "," << embedder
         << " (proteced media identifier is not supported in popups)";
-    NotifyPermissionSet(id, requesting_frame, callback, false);
+    NotifyPermissionSet(id, origin, result_callback, false);
     return;
   }
 
   content::RenderViewHost* rvh = web_contents->GetRenderViewHost();
-  DecidePermission(id, requesting_frame, embedder, rvh, callback);
+  DecidePermission(id, origin, embedder, rvh, result_callback);
 }
 
 void ProtectedMediaIdentifierPermissionContext::
-    CancelProtectedMediaIdentifierPermissionRequest(
+    CancelProtectedMediaIdentifierPermissionRequests(
         int render_process_id,
         int render_view_id,
-        const GURL& requesting_frame) {
-  CancelPendingInfoBarRequest(
-      PermissionRequestID(render_process_id, render_view_id, 0));
+        const GURL& origin) {
+  CancelPendingInfobarRequests(
+      render_process_id, render_view_id, origin);
 }
 
 void ProtectedMediaIdentifierPermissionContext::DecidePermission(
     const PermissionRequestID& id,
-    const GURL& requesting_frame,
+    const GURL& origin,
     const GURL& embedder,
     content::RenderViewHost* rvh,
     const base::Callback<void(bool)>& callback) {
@@ -99,36 +114,35 @@ void ProtectedMediaIdentifierPermissionContext::DecidePermission(
   // Check if the protected media identifier master switch is disabled.
   if (!profile()->GetPrefs()->GetBoolean(
         prefs::kProtectedMediaIdentifierEnabled)) {
-    PermissionDecided(id, requesting_frame, embedder, callback, false);
+    PermissionDecided(id, origin, embedder, callback, false);
     return;
   }
 #endif
 
   ContentSetting content_setting =
      profile_->GetHostContentSettingsMap()->GetContentSetting(
-          requesting_frame,
+          origin,
           embedder,
           CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER,
           std::string());
   switch (content_setting) {
     case CONTENT_SETTING_BLOCK:
-      PermissionDecided(id, requesting_frame, embedder, callback, false);
+      PermissionDecided(id, origin, embedder, callback, false);
       break;
     case CONTENT_SETTING_ALLOW:
-      PermissionDecided(id, requesting_frame, embedder, callback, true);
+      PermissionDecided(id, origin, embedder, callback, true);
       break;
     case CONTENT_SETTING_ASK:
       QueueController()->CreateInfoBarRequest(
           id,
-          requesting_frame,
+          origin,
           embedder,
           base::Bind(&ProtectedMediaIdentifierPermissionContext::
                           NotifyPermissionSet,
                      base::Unretained(this),
                      id,
-                     requesting_frame,
+                     origin,
                      callback));
-      rvh->DisableFullscreenEncryptedMediaPlayback();
       break;
     default:
       NOTREACHED();
@@ -143,16 +157,16 @@ void ProtectedMediaIdentifierPermissionContext::ShutdownOnUIThread() {
 
 void ProtectedMediaIdentifierPermissionContext::PermissionDecided(
     const PermissionRequestID& id,
-    const GURL& requesting_frame,
+    const GURL& origin,
     const GURL& embedder,
     const base::Callback<void(bool)>& callback,
     bool allowed) {
-  NotifyPermissionSet(id, requesting_frame, callback, allowed);
+  NotifyPermissionSet(id, origin, callback, allowed);
 }
 
 void ProtectedMediaIdentifierPermissionContext::NotifyPermissionSet(
     const PermissionRequestID& id,
-    const GURL& requesting_frame,
+    const GURL& origin,
     const base::Callback<void(bool)>& callback,
     bool allowed) {
   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
@@ -163,7 +177,7 @@ void ProtectedMediaIdentifierPermissionContext::NotifyPermissionSet(
                                       id.render_view_id());
   if (content_settings) {
     content_settings->OnProtectedMediaIdentifierPermissionSet(
-        requesting_frame.GetOrigin(), allowed);
+        origin.GetOrigin(), allowed);
   }
 
   callback.Run(allowed);
@@ -186,20 +200,26 @@ PermissionQueueController*
 }
 
 void
-ProtectedMediaIdentifierPermissionContext::CancelPendingInfoBarRequest(
-    const PermissionRequestID& id) {
+ProtectedMediaIdentifierPermissionContext::CancelPendingInfobarRequests(
+    int render_process_id,
+    int render_view_id,
+    const GURL& origin) {
   if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
     content::BrowserThread::PostTask(
         content::BrowserThread::UI,
         FROM_HERE,
         base::Bind(&ProtectedMediaIdentifierPermissionContext::
-                        CancelPendingInfoBarRequest,
+                        CancelPendingInfobarRequests,
                    this,
-                   id));
+                   render_process_id,
+                   render_view_id,
+                   origin));
     return;
   }
   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
   if (shutting_down_)
     return;
-  QueueController()->CancelInfoBarRequest(id);
+  QueueController()->CancelInfoBarRequest(
+      PermissionRequestID(render_process_id, render_view_id, 0,
+                          origin));
 }