Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Unified Diff: chrome/browser/media/protected_media_identifier_permission_context.cc

Issue 769103002: Refactor ProtectedMediaIdentifierPermissionContext to derive from PermissionContextBase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup and fix compile Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 6f1bc6e115b467d6a50608fb7d7ebc361e3a5382..a4ffade79b947d3f356199b0dc3b3b79da61155d 100644
--- a/chrome/browser/media/protected_media_identifier_permission_context.cc
+++ b/chrome/browser/media/protected_media_identifier_permission_context.cc
@@ -4,10 +4,6 @@
#include "chrome/browser/media/protected_media_identifier_permission_context.h"
-#include <functional>
-#include <string>
-#include <vector>
-
#include "base/bind.h"
#include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h"
@@ -18,8 +14,6 @@
#include "components/content_settings/core/browser/host_content_settings_map.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)
@@ -34,30 +28,29 @@ using extensions::APIPermission;
ProtectedMediaIdentifierPermissionContext::
ProtectedMediaIdentifierPermissionContext(Profile* profile)
- : profile_(profile), shutting_down_(false) {}
+ : PermissionContextBase(profile,
+ CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER),
+ shutting_down_(false) {}
ProtectedMediaIdentifierPermissionContext::
~ProtectedMediaIdentifierPermissionContext() {
// ProtectedMediaIdentifierPermissionContext may be destroyed on either
// the UI thread or the IO thread, but the PermissionQueueController must have
// been destroyed on the UI thread.
- DCHECK(!permission_queue_controller_.get());
+ DCHECK(!GetQueueController());
mlamouri (slow - plz ping) 2014/12/02 22:43:30 I think you can remove that. This dtor must be ru
timvolodine 2014/12/03 16:44:25 Done.
}
-void ProtectedMediaIdentifierPermissionContext::
- RequestProtectedMediaIdentifierPermission(
- content::WebContents* web_contents,
- const GURL& origin,
- base::Callback<void(bool)> result_callback) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+void ProtectedMediaIdentifierPermissionContext::RequestPermission(
+ content::WebContents* web_contents,
+ const PermissionRequestID& id,
+ const GURL& requesting_frame_origin,
+ bool user_gesture,
+ const BrowserPermissionCallback& callback) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (shutting_down_)
return;
- int render_process_id = web_contents->GetRenderProcessHost()->GetID();
- int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID();
-
- const PermissionRequestID id(
- render_process_id, render_view_id, 0, origin);
+ GURL embedder = web_contents->GetLastCommittedURL().GetOrigin();
#if defined(ENABLE_EXTENSIONS)
if (extensions::GetViewType(web_contents) !=
@@ -67,102 +60,56 @@ void ProtectedMediaIdentifierPermissionContext::
<< "Attempt to use protected media identifier in tabless renderer: "
<< id.ToString()
<< " (can't prompt user without a visible tab)";
- NotifyPermissionSet(id, origin, result_callback, false);
+ NotifyPermissionSet(id, origin, embedder, callback, false, false);
return;
}
#endif
- GURL embedder = web_contents->GetLastCommittedURL();
- if (!origin.is_valid() || !embedder.is_valid()) {
+ if (!requesting_frame_origin.is_valid() || !embedder.is_valid()) {
LOG(WARNING)
<< "Attempt to use protected media identifier from an invalid URL: "
- << origin << "," << embedder
+ << requesting_frame_origin << "," << embedder
<< " (proteced media identifier is not supported in popups)";
- NotifyPermissionSet(id, origin, result_callback, false);
+ NotifyPermissionSet(id, requesting_frame_origin, embedder,
+ callback, false, false);
return;
}
- content::RenderViewHost* rvh = web_contents->GetRenderViewHost();
- DecidePermission(id, origin, embedder, rvh, result_callback);
-}
-
-void ProtectedMediaIdentifierPermissionContext::
- CancelProtectedMediaIdentifierPermissionRequests(
- int render_process_id,
- int render_view_id,
- const GURL& origin) {
- CancelPendingInfobarRequests(
- render_process_id, render_view_id, origin);
-}
-
-void ProtectedMediaIdentifierPermissionContext::DecidePermission(
- const PermissionRequestID& id,
- const GURL& origin,
- const GURL& embedder,
- content::RenderViewHost* rvh,
- const base::Callback<void(bool)>& callback) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
-
#if defined(OS_ANDROID)
// Check if the protected media identifier master switch is disabled.
- if (!profile()->GetPrefs()->GetBoolean(
+ if (!GetProfile()->GetPrefs()->GetBoolean(
prefs::kProtectedMediaIdentifierEnabled)) {
- PermissionDecided(id, origin, embedder, callback, false);
+ NotifyPermissionSet(id, requesting_frame_origin, embedder, callback,
+ false, false);
return;
}
#endif
- ContentSetting content_setting =
- profile_->GetHostContentSettingsMap()->GetContentSetting(
- origin,
- embedder,
- CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER,
- std::string());
- switch (content_setting) {
- case CONTENT_SETTING_BLOCK:
- PermissionDecided(id, origin, embedder, callback, false);
- break;
- case CONTENT_SETTING_ALLOW:
- PermissionDecided(id, origin, embedder, callback, true);
- break;
- case CONTENT_SETTING_ASK:
- QueueController()->CreateInfoBarRequest(
- id,
- origin,
- embedder,
- base::Bind(&ProtectedMediaIdentifierPermissionContext::
- NotifyPermissionSet,
- base::Unretained(this),
- id,
- origin,
- callback));
- break;
- default:
- NOTREACHED();
- }
+ PermissionContextBase::RequestPermission(web_contents, id,
+ requesting_frame_origin,
+ user_gesture,
+ callback);
}
-void ProtectedMediaIdentifierPermissionContext::ShutdownOnUIThread() {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
- permission_queue_controller_.reset();
- shutting_down_ = true;
+void ProtectedMediaIdentifierPermissionContext::CancelPermissionRequest(
+ content::WebContents* web_contents,
+ const PermissionRequestID& id) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ if (shutting_down_)
+ return;
+ PermissionContextBase::CancelPermissionRequest(web_contents, id);
}
-void ProtectedMediaIdentifierPermissionContext::PermissionDecided(
- const PermissionRequestID& id,
- const GURL& origin,
- const GURL& embedder,
- const base::Callback<void(bool)>& callback,
- bool allowed) {
- NotifyPermissionSet(id, origin, callback, allowed);
+void ProtectedMediaIdentifierPermissionContext::ShutdownOnUIThread() {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ shutting_down_ = true;
}
-void ProtectedMediaIdentifierPermissionContext::NotifyPermissionSet(
+void ProtectedMediaIdentifierPermissionContext::UpdateTabContext(
const PermissionRequestID& id,
- const GURL& origin,
- const base::Callback<void(bool)>& callback,
+ const GURL& requesting_frame,
bool allowed) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// WebContents may have gone away.
TabSpecificContentSettings* content_settings =
@@ -170,49 +117,7 @@ void ProtectedMediaIdentifierPermissionContext::NotifyPermissionSet(
id.render_view_id());
if (content_settings) {
content_settings->OnProtectedMediaIdentifierPermissionSet(
- origin.GetOrigin(), allowed);
+ requesting_frame.GetOrigin(), allowed);
}
- callback.Run(allowed);
-}
-
-PermissionQueueController*
- ProtectedMediaIdentifierPermissionContext::QueueController() {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
- DCHECK(!shutting_down_);
- if (!permission_queue_controller_)
- permission_queue_controller_.reset(CreateQueueController());
- return permission_queue_controller_.get();
-}
-
-PermissionQueueController*
- ProtectedMediaIdentifierPermissionContext::CreateQueueController() {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
- return new PermissionQueueController(
- profile(), CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER);
-}
-
-void
-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::
- CancelPendingInfobarRequests,
- this,
- render_process_id,
- render_view_id,
- origin));
- return;
- }
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
- if (shutting_down_)
- return;
- QueueController()->CancelInfoBarRequest(
- PermissionRequestID(render_process_id, render_view_id, 0,
- origin));
}

Powered by Google App Engine
This is Rietveld 408576698