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

Unified Diff: chrome/browser/chrome_content_browser_client.cc

Issue 750633003: Implement HasPermission() method in PermissionService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed comments, switched to use BrowserContext, passing PermissionStatus in callback Created 6 years, 1 month 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 a872ec6c9b027869d158c6dc1934f05be88253a9..00267bdcd22ad09bf5a0b2a11df99ed5f6bcfce8 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -594,6 +594,20 @@ void GetGuestViewDefaultContentSettingRules(
}
#endif // defined(ENALBE_EXTENSIONS)
+content::PermissionStatus
+ContentSettingToPermissionStatus(ContentSetting setting) {
+ switch (setting) {
+ case CONTENT_SETTING_ALLOW:
+ return content::PERMISSION_STATUS_GRANTED;
mlamouri (slow - plz ping) 2014/11/24 19:06:01 nit: CONTENT_SETTING_SESSION_ONLY should also link
timvolodine 2014/11/27 17:53:42 Done.
+ case CONTENT_SETTING_BLOCK:
+ return content::PERMISSION_STATUS_DENIED;
+ case CONTENT_SETTING_ASK:
+ return content::PERMISSION_STATUS_ASK;
+ default:
+ return content::PERMISSION_STATUS_ASK;
mlamouri (slow - plz ping) 2014/11/24 19:06:01 I think it would be better to not have a |default|
timvolodine 2014/11/27 17:53:42 Done.
+ }
+}
+
} // namespace
namespace chrome {
@@ -1971,6 +1985,50 @@ void ChromeContentBrowserClient::RequestPermission(
}
}
+void ChromeContentBrowserClient::HasPermission(
+ content::PermissionType permission,
+ content::BrowserContext* browser_context,
+ const GURL& requesting_origin,
+ const GURL& embedding_origin,
+ const content::PermissionStatusCallback& result_callback) {
+ DCHECK(browser_context);
+ Profile* profile = Profile::FromBrowserContext(browser_context);
+
+ PermissionContextBase* context = nullptr;
+ switch (permission) {
+ case content::PERMISSION_MIDI_SYSEX:
+ context = MidiPermissionContextFactory::GetForProfile(profile);
+ break;
+ case content::PERMISSION_NOTIFICATIONS:
+#if defined(ENABLE_NOTIFICATIONS)
+ context = DesktopNotificationServiceFactory::GetForProfile(profile);
+#else
+ NOTIMPLEMENTED();
+#endif
+ break;
+ case content::PERMISSION_GEOLOCATION:
+ context = GeolocationPermissionContextFactory::GetForProfile(profile);
+ break;
+ case content::PERMISSION_PROTECTED_MEDIA:
+ NOTIMPLEMENTED();
+ break;
+ case content::PERMISSION_PUSH_MESSAGING:
+ context = gcm::PushMessagingPermissionContextFactory::GetForProfile(
+ profile);
+ break;
+ case content::PERMISSION_NUM:
+ NOTREACHED() << "Invalid RequestPermission for " << permission;
+ break;
+ }
+
+ ContentSetting result = context
+ ? context->GetPermissionStatus(requesting_origin.GetOrigin(),
+ embedding_origin.GetOrigin())
+ : CONTENT_SETTING_DEFAULT;
+
+ result_callback.Run(ContentSettingToPermissionStatus(result));
mlamouri (slow - plz ping) 2014/11/24 19:06:01 Why do you use a callback instead of returning dir
timvolodine 2014/11/27 17:53:42 Done.
+}
+
void ChromeContentBrowserClient::CancelPermissionRequest(
content::PermissionType permission,
content::WebContents* web_contents,

Powered by Google App Engine
This is Rietveld 408576698