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

Unified Diff: chrome/browser/chrome_content_browser_client.cc

Issue 622793002: Group the different permission related methods in the content api. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months 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/chrome_content_browser_client.cc
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index f57d75c04f098c77d5fe3bdf545caba967341b31..aa606d5a4c1d83155eabaf4358bac7b077fda21c 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -1816,39 +1816,6 @@ content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
return MediaCaptureDevicesDispatcher::GetInstance();
}
-void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
- const GURL& source_origin,
- content::RenderFrameHost* render_frame_host,
- const base::Callback<void(blink::WebNotificationPermission)>& callback) {
-#if defined(ENABLE_NOTIFICATIONS)
- // Skip showing the infobar if the request comes from an extension, and that
- // extension has the 'notify' permission. (If the extension does not have the
- // permission, the user will still be prompted.)
- Profile* profile = Profile::FromBrowserContext(
- render_frame_host->GetSiteInstance()->GetBrowserContext());
- DesktopNotificationService* notification_service =
- DesktopNotificationServiceFactory::GetForProfile(profile);
- WebContents* web_contents = WebContents::FromRenderFrameHost(
- render_frame_host);
- int render_process_id = render_frame_host->GetProcess()->GetID();
- const PermissionRequestID request_id(render_process_id,
- web_contents->GetRoutingID(),
- -1 /* bridge id */,
- GURL());
-
- notification_service->RequestNotificationPermission(
- web_contents,
- request_id,
- source_origin,
- // TODO(peter): plumb user_gesture over IPC
- true,
- callback);
-
-#else
- NOTIMPLEMENTED();
-#endif
-}
-
blink::WebNotificationPermission
ChromeContentBrowserClient::CheckDesktopNotificationPermission(
const GURL& source_origin,
@@ -1917,7 +1884,8 @@ void ChromeContentBrowserClient::ShowDesktopNotification(
#endif
}
-void ChromeContentBrowserClient::RequestGeolocationPermission(
+void ChromeContentBrowserClient::RequestPermission(
+ content::PermissionType permission,
content::WebContents* web_contents,
int bridge_id,
const GURL& requesting_frame,
@@ -1925,19 +1893,55 @@ void ChromeContentBrowserClient::RequestGeolocationPermission(
const base::Callback<void(bool)>& result_callback) {
int render_process_id = web_contents->GetRenderProcessHost()->GetID();
int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID();
+ Profile* profile = Profile::FromBrowserContext(
+ web_contents->GetBrowserContext());
Peter Beverloo 2014/10/20 17:32:16 Profile* profile = Profile::FromBrowserConte
Miguel Garcia 2014/10/21 17:17:12 Done.
const PermissionRequestID request_id(render_process_id,
render_view_id,
bridge_id,
requesting_frame);
- GeolocationPermissionContextFactory::GetForProfile(
- Profile::FromBrowserContext(web_contents->GetBrowserContext()))->
- RequestPermission(web_contents, request_id,
- requesting_frame.GetOrigin(), user_gesture,
- result_callback);
+
+ switch (permission) {
+ case content::PERMISSION_MIDI_SYSEX:
+ MidiPermissionContextFactory::GetForProfile(profile)->RequestPermission(
+ web_contents, request_id, requesting_frame,
+ user_gesture, result_callback);
+ break;
+ case content::PERMISSION_NOTIFICATIONS:
+#if defined(ENABLE_NOTIFICATIONS)
+ DesktopNotificationServiceFactory::GetForProfile(profile)
+ ->RequestNotificationPermission(
Bernhard Bauer 2014/10/20 14:57:24 At the very least, indent this four more spaces, a
Miguel Garcia 2014/10/21 17:17:11 Done.
+ web_contents,
+ request_id,
+ requesting_frame,
+ user_gesture,
+ result_callback);
+#else
+ NOTIMPLEMENTED();
Bernhard Bauer 2014/10/20 14:57:24 Fix alignment.
Miguel Garcia 2014/10/21 17:17:12 Done.
+#endif
+ break;
+ case content::PERMISSION_GEOLOCATION:
+ GeolocationPermissionContextFactory::GetForProfile(profile)
+ ->RequestPermission(web_contents, request_id,
+ requesting_frame.GetOrigin(), user_gesture,
+ result_callback);
+ break;
+#if defined(OS_ANDROID)
Peter Beverloo 2014/10/20 17:32:16 Either place the #if inside of the case-statement,
Miguel Garcia 2014/10/21 17:17:12 Done.
+ case content::PERMISSION_PROTECTED_MEDIA:
+ ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(profile)
+ ->RequestProtectedMediaIdentifierPermission(web_contents,
+ requesting_frame,
+ result_callback);
+ break;
+#endif
+ default:
+ LOG(WARNING) << "Permission not available " << permission;
Peter Beverloo 2014/10/20 17:32:16 nit: break for consistency.
Miguel Garcia 2014/10/21 17:17:12 Not sure where do you want to see the break
+ }
+
}
-void ChromeContentBrowserClient::CancelGeolocationPermissionRequest(
+void ChromeContentBrowserClient::CancelPermissionRequest(
+ content::PermissionType permission,
content::WebContents* web_contents,
int bridge_id,
const GURL& requesting_frame) {
@@ -1948,56 +1952,70 @@ void ChromeContentBrowserClient::CancelGeolocationPermissionRequest(
render_view_id,
bridge_id,
requesting_frame);
- GeolocationPermissionContextFactory::GetForProfile(
- Profile::FromBrowserContext(web_contents->GetBrowserContext()))->
- CancelPermissionRequest(web_contents, request_id);
+ Profile* profile = Profile::FromBrowserContext(
+ web_contents->GetBrowserContext());
+ switch (permission) {
+ case content::PERMISSION_MIDI_SYSEX:
+ MidiPermissionContextFactory::GetForProfile(profile)
Peter Beverloo 2014/10/20 17:32:16 Fix indentation.
Miguel Garcia 2014/10/21 17:17:12 Done.
+ ->CancelPermissionRequest(web_contents, request_id);
+ break;
+ case content::PERMISSION_NOTIFICATIONS:
+#if defined(ENABLE_NOTIFICATIONS)
+ DesktopNotificationServiceFactory::GetForProfile(profile)
+ ->CancelPermissionRequest(web_contents, request_id);
+#else
+ NOTIMPLEMENTED();
+#endif
+
+ break;
+ case content::PERMISSION_GEOLOCATION:
+ GeolocationPermissionContextFactory::GetForProfile(profile)
+ ->CancelPermissionRequest(web_contents, request_id);
+ break;
+ #if defined(OS_ANDROID)
+ case content::PERMISSION_PROTECTED_MEDIA:
+ ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(
+ profile)->CancelProtectedMediaIdentifierPermissionRequests(
+ render_process_id,
+ render_view_id,
+ requesting_frame);
+ break;
+ #endif
+ default:
+ LOG(WARNING) << "Permission not available " << permission;
+ }
}
-void ChromeContentBrowserClient::RequestMidiSysExPermission(
- content::WebContents* web_contents,
- int bridge_id,
- const GURL& requesting_frame,
- bool user_gesture,
- base::Callback<void(bool)> result_callback,
- base::Closure* cancel_callback) {
- MidiPermissionContext* context =
- MidiPermissionContextFactory::GetForProfile(
- Profile::FromBrowserContext(web_contents->GetBrowserContext()));
- int renderer_id = web_contents->GetRenderProcessHost()->GetID();
- int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID();
- const PermissionRequestID id(renderer_id, render_view_id, bridge_id, GURL());
+// Helper method to translate from Permissions to ContentSettings
+static ContentSettingsType PermissionToContentSetting(
+ content::PermissionType permission) {
+ switch (permission) {
+ case content::PERMISSION_MIDI_SYSEX:
Peter Beverloo 2014/10/20 17:32:16 Fix indentation.
Miguel Garcia 2014/10/21 17:17:11 Done.
+ return CONTENT_SETTINGS_TYPE_MIDI_SYSEX;
+ case content::PERMISSION_NOTIFICATIONS:
+ return CONTENT_SETTINGS_TYPE_NOTIFICATIONS;
+ case content::PERMISSION_GEOLOCATION:
+ return CONTENT_SETTINGS_TYPE_GEOLOCATION;
+#if defined(OS_ANDROID)
+ case content::PERMISSION_PROTECTED_MEDIA:
+ return CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER;
+#endif
- context->RequestPermission(web_contents, id, requesting_frame,
- user_gesture, result_callback);
+ default:
+ NOTREACHED() << "Unknown content setting for permission " << permission;
+ return CONTENT_SETTINGS_TYPE_DEFAULT;
+ }
}
-void ChromeContentBrowserClient::DidUseGeolocationPermission(
+void ChromeContentBrowserClient::RegisterPermissionUsage(
+ content::PermissionType permission,
content::WebContents* web_contents,
const GURL& frame_url,
const GURL& main_frame_url) {
Profile::FromBrowserContext(web_contents->GetBrowserContext())
->GetHostContentSettingsMap()
->UpdateLastUsage(
- frame_url, main_frame_url, CONTENT_SETTINGS_TYPE_GEOLOCATION);
-}
-
-void ChromeContentBrowserClient::RequestProtectedMediaIdentifierPermission(
- content::WebContents* web_contents,
- const GURL& origin,
- base::Callback<void(bool)> result_callback,
- base::Closure* cancel_callback) {
-#if defined(OS_ANDROID)
- ProtectedMediaIdentifierPermissionContext* context =
- ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(
- Profile::FromBrowserContext(web_contents->GetBrowserContext()));
- context->RequestProtectedMediaIdentifierPermission(web_contents,
- origin,
- result_callback,
- cancel_callback);
-#else
- NOTIMPLEMENTED();
- result_callback.Run(false);
-#endif // defined(OS_ANDROID)
+ frame_url, main_frame_url, PermissionToContentSetting(permission));
}
bool ChromeContentBrowserClient::CanCreateWindow(

Powered by Google App Engine
This is Rietveld 408576698