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

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 12 matching lines...) Expand all
23 #include "components/gcm_driver/gcm_driver.h" 23 #include "components/gcm_driver/gcm_driver.h"
24 #include "components/pref_registry/pref_registry_syncable.h" 24 #include "components/pref_registry/pref_registry_syncable.h"
25 #include "content/public/browser/browser_context.h" 25 #include "content/public/browser/browser_context.h"
26 #include "content/public/browser/render_frame_host.h" 26 #include "content/public/browser/render_frame_host.h"
27 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
28 28
29 namespace gcm { 29 namespace gcm {
30 30
31 namespace { 31 namespace {
32 const int kMaxRegistrations = 1000000; 32 const int kMaxRegistrations = 1000000;
33
34 blink::WebPushPermissionStatus ToPushPermission(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
33 } // namespace 48 } // namespace
34 49
35 // static 50 // static
36 void PushMessagingServiceImpl::RegisterProfilePrefs( 51 void PushMessagingServiceImpl::RegisterProfilePrefs(
37 user_prefs::PrefRegistrySyncable* registry) { 52 user_prefs::PrefRegistrySyncable* registry) {
38 registry->RegisterIntegerPref( 53 registry->RegisterIntegerPref(
39 prefs::kPushMessagingRegistrationCount, 54 prefs::kPushMessagingRegistrationCount,
40 0, 55 0,
41 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 56 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
42 } 57 }
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 id, 242 id,
228 embedder, 243 embedder,
229 user_gesture, 244 user_gesture,
230 base::Bind(&PushMessagingServiceImpl::DidRequestPermission, 245 base::Bind(&PushMessagingServiceImpl::DidRequestPermission,
231 weak_factory_.GetWeakPtr(), 246 weak_factory_.GetWeakPtr(),
232 application_id, 247 application_id,
233 sender_id, 248 sender_id,
234 callback)); 249 callback));
235 } 250 }
236 251
252 blink::WebPushPermissionStatus PushMessagingServiceImpl::GetPermissionStatus(
253 const GURL& requesting_origin,
254 int renderer_id,
255 int render_frame_id) {
256 content::RenderFrameHost* render_frame_host =
257 content::RenderFrameHost::FromID(renderer_id, render_frame_id);
258
259 // The frame doesn't exist any more, or we received a bad frame id.
260 if (!render_frame_host)
261 return blink::WebPushPermissionStatusDenied;
262
263 content::WebContents* web_contents =
264 content::WebContents::FromRenderFrameHost(render_frame_host);
265
266 // The page doesn't exist any more or we got a bad render frame host.
267 if (!web_contents)
268 return blink::WebPushPermissionStatusDenied;
269
270 GURL embedder_origin = web_contents->GetLastCommittedURL().GetOrigin();
271 gcm::PushMessagingPermissionContext* permission_context =
272 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_);
273 return ToPushPermission(
274 permission_context->PermissionStatus(requesting_origin, embedder_origin));
275 }
276
237 void PushMessagingServiceImpl::RegisterEnd( 277 void PushMessagingServiceImpl::RegisterEnd(
238 const content::PushMessagingService::RegisterCallback& callback, 278 const content::PushMessagingService::RegisterCallback& callback,
239 const std::string& registration_id, 279 const std::string& registration_id,
240 content::PushRegistrationStatus status) { 280 content::PushRegistrationStatus status) {
241 GURL endpoint = GURL(std::string(kPushMessagingEndpoint)); 281 GURL endpoint = GURL(std::string(kPushMessagingEndpoint));
242 callback.Run(endpoint, registration_id, status); 282 callback.Run(endpoint, registration_id, status);
243 if (status == content::PUSH_REGISTRATION_STATUS_SUCCESS) { 283 if (status == content::PUSH_REGISTRATION_STATUS_SUCCESS) {
244 // TODO(johnme): Make sure the pref doesn't get out of sync after crashes. 284 // TODO(johnme): Make sure the pref doesn't get out of sync after crashes.
245 int registration_count = profile_->GetPrefs()->GetInteger( 285 int registration_count = profile_->GetPrefs()->GetInteger(
246 prefs::kPushMessagingRegistrationCount); 286 prefs::kPushMessagingRegistrationCount);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 sender_ids, 323 sender_ids,
284 base::Bind(&PushMessagingServiceImpl::DidRegister, 324 base::Bind(&PushMessagingServiceImpl::DidRegister,
285 weak_factory_.GetWeakPtr(), 325 weak_factory_.GetWeakPtr(),
286 register_callback)); 326 register_callback));
287 } 327 }
288 328
289 // TODO(johnme): Unregister should decrement the pref, and call 329 // TODO(johnme): Unregister should decrement the pref, and call
290 // RemoveAppHandler if the count drops to zero. 330 // RemoveAppHandler if the count drops to zero.
291 331
292 } // namespace gcm 332 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698