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

Side by Side 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, 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/services/gcm/push_messaging_service_impl.h" 5 #include "chrome/browser/services/gcm/push_messaging_service_impl.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 11 matching lines...) Expand all
22 #include "components/gcm_driver/gcm_driver.h" 22 #include "components/gcm_driver/gcm_driver.h"
23 #include "components/pref_registry/pref_registry_syncable.h" 23 #include "components/pref_registry/pref_registry_syncable.h"
24 #include "content/public/browser/browser_context.h" 24 #include "content/public/browser/browser_context.h"
25 #include "content/public/browser/render_frame_host.h" 25 #include "content/public/browser/render_frame_host.h"
26 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
27 27
28 namespace gcm { 28 namespace gcm {
29 29
30 namespace { 30 namespace {
31 const int kMaxRegistrations = 1000000; 31 const int kMaxRegistrations = 1000000;
32
33 static blink::WebPushPermissionStatus ToPushPermission(
34 ContentSetting setting) {
35 switch (setting) {
36 case CONTENT_SETTING_ALLOW:
37 return blink::WebPushPermissionStatusGranted;
38 case CONTENT_SETTING_BLOCK:
39 return blink::WebPushPermissionStatusDenied;
40 case CONTENT_SETTING_ASK:
41 return blink::WebPushPermissionStatusDefault;
42 default:
43 NOTREACHED();
44 return blink::WebPushPermissionStatusDenied;
45 }
46 }
47
32 } // namespace 48 } // namespace
33 49
34 // static 50 // static
35 void PushMessagingServiceImpl::RegisterProfilePrefs( 51 void PushMessagingServiceImpl::RegisterProfilePrefs(
36 user_prefs::PrefRegistrySyncable* registry) { 52 user_prefs::PrefRegistrySyncable* registry) {
37 registry->RegisterIntegerPref( 53 registry->RegisterIntegerPref(
38 prefs::kPushMessagingRegistrationCount, 54 prefs::kPushMessagingRegistrationCount,
39 0, 55 0,
40 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 56 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
41 } 57 }
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 id, 238 id,
223 embedder, 239 embedder,
224 user_gesture, 240 user_gesture,
225 base::Bind(&PushMessagingServiceImpl::DidRequestPermission, 241 base::Bind(&PushMessagingServiceImpl::DidRequestPermission,
226 weak_factory_.GetWeakPtr(), 242 weak_factory_.GetWeakPtr(),
227 application_id, 243 application_id,
228 sender_id, 244 sender_id,
229 callback)); 245 callback));
230 } 246 }
231 247
248 blink::WebPushPermissionStatus PushMessagingServiceImpl::GetPermissionStatus(
249 const GURL& requesting_origin, int renderer_id, int render_frame_id) {
250 content::RenderFrameHost* render_frame_host =
251 content::RenderFrameHost::FromID(renderer_id, render_frame_id);
252
253 // The frame doesn't exist any more, or we received a bad frame id.
254 if (!render_frame_host)
255 return blink::WebPushPermissionStatusDenied;
256
257 content::WebContents* web_contents =
258 content::WebContents::FromRenderFrameHost(render_frame_host);
259
260 // The page doesn't exist any more or we got a bad render frame host.
261 if (!web_contents)
262 return blink::WebPushPermissionStatusDenied;
263
264 GURL embedder_origin = web_contents->GetLastCommittedURL().GetOrigin();
265 gcm::PushMessagingPermissionContext* permission_context =
266 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_);
267 return ToPushPermission(
268 permission_context->PermissionStatus(requesting_origin, embedder_origin));
269 }
270
232 void PushMessagingServiceImpl::RegisterEnd( 271 void PushMessagingServiceImpl::RegisterEnd(
233 const content::PushMessagingService::RegisterCallback& callback, 272 const content::PushMessagingService::RegisterCallback& callback,
234 const std::string& registration_id, 273 const std::string& registration_id,
235 content::PushRegistrationStatus status) { 274 content::PushRegistrationStatus status) {
236 GURL endpoint = GURL("https://android.googleapis.com/gcm/send"); 275 GURL endpoint = GURL("https://android.googleapis.com/gcm/send");
237 callback.Run(endpoint, registration_id, status); 276 callback.Run(endpoint, registration_id, status);
238 if (status == content::PUSH_REGISTRATION_STATUS_SUCCESS) { 277 if (status == content::PUSH_REGISTRATION_STATUS_SUCCESS) {
239 // TODO(johnme): Make sure the pref doesn't get out of sync after crashes. 278 // TODO(johnme): Make sure the pref doesn't get out of sync after crashes.
240 int registration_count = profile_->GetPrefs()->GetInteger( 279 int registration_count = profile_->GetPrefs()->GetInteger(
241 prefs::kPushMessagingRegistrationCount); 280 prefs::kPushMessagingRegistrationCount);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 sender_ids, 317 sender_ids,
279 base::Bind(&PushMessagingServiceImpl::DidRegister, 318 base::Bind(&PushMessagingServiceImpl::DidRegister,
280 weak_factory_.GetWeakPtr(), 319 weak_factory_.GetWeakPtr(),
281 register_callback)); 320 register_callback));
282 } 321 }
283 322
284 // TODO(johnme): Unregister should decrement the pref, and call 323 // TODO(johnme): Unregister should decrement the pref, and call
285 // RemoveAppHandler if the count drops to zero. 324 // RemoveAppHandler if the count drops to zero.
286 325
287 } // namespace gcm 326 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698