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

Unified Diff: chrome/browser/services/gcm/push_messaging_service_impl.cc

Issue 661463002: Implement PushManager#hasPermission (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/services/gcm/push_messaging_service_impl.cc
diff --git a/chrome/browser/services/gcm/push_messaging_service_impl.cc b/chrome/browser/services/gcm/push_messaging_service_impl.cc
index 9d352eb7a0003b0418c788369f825cb161cef3ac..5f2af33c45c7e1fd6f6e5ceeeb13e24d01a53d5e 100644
--- a/chrome/browser/services/gcm/push_messaging_service_impl.cc
+++ b/chrome/browser/services/gcm/push_messaging_service_impl.cc
@@ -30,6 +30,21 @@ namespace gcm {
namespace {
const int kMaxRegistrations = 1000000;
+
+blink::WebPushPermissionStatus ToPushPermission(ContentSetting setting) {
+ switch (setting) {
+ case CONTENT_SETTING_ALLOW:
+ return blink::WebPushPermissionStatusGranted;
+ case CONTENT_SETTING_BLOCK:
+ return blink::WebPushPermissionStatusDenied;
+ case CONTENT_SETTING_ASK:
+ return blink::WebPushPermissionStatusDefault;
+ default:
+ NOTREACHED();
+ return blink::WebPushPermissionStatusDenied;
+ }
+}
+
} // namespace
// static
@@ -234,6 +249,31 @@ void PushMessagingServiceImpl::Register(
callback));
}
+blink::WebPushPermissionStatus PushMessagingServiceImpl::GetPermissionStatus(
+ const GURL& requesting_origin,
+ int renderer_id,
+ int render_frame_id) {
+ content::RenderFrameHost* render_frame_host =
+ content::RenderFrameHost::FromID(renderer_id, render_frame_id);
+
+ // The frame doesn't exist any more, or we received a bad frame id.
+ if (!render_frame_host)
+ return blink::WebPushPermissionStatusDenied;
+
+ content::WebContents* web_contents =
+ content::WebContents::FromRenderFrameHost(render_frame_host);
+
+ // The page doesn't exist any more or we got a bad render frame host.
+ if (!web_contents)
+ return blink::WebPushPermissionStatusDenied;
+
+ GURL embedder_origin = web_contents->GetLastCommittedURL().GetOrigin();
+ gcm::PushMessagingPermissionContext* permission_context =
+ gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_);
+ return ToPushPermission(
+ permission_context->PermissionStatus(requesting_origin, embedder_origin));
+}
+
void PushMessagingServiceImpl::RegisterEnd(
const content::PushMessagingService::RegisterCallback& callback,
const std::string& registration_id,

Powered by Google App Engine
This is Rietveld 408576698