OLD | NEW |
---|---|
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 Loading... | |
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 static blink::WebPushPermissionStatus ToPushPermission(ContentSetting setting) { | |
fgorski
2014/10/29 20:52:44
why static?
Miguel Garcia
2014/10/30 12:27:15
Ok, I removed it. I actually don't know if there i
| |
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 Loading... | |
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); |
247 profile_->GetPrefs()->SetInteger(prefs::kPushMessagingRegistrationCount, | 287 profile_->GetPrefs()->SetInteger(prefs::kPushMessagingRegistrationCount, |
248 registration_count + 1); | 288 registration_count + 1); |
249 } | 289 } |
250 } | 290 } |
251 | 291 |
252 void PushMessagingServiceImpl::DidRegister( | 292 void PushMessagingServiceImpl::DidRegister( |
253 const content::PushMessagingService::RegisterCallback& callback, | 293 const content::PushMessagingService::RegisterCallback& callback, |
254 const std::string& registration_id, | 294 const std::string& registration_id, |
255 GCMClient::Result result) { | 295 GCMClient::Result result) { |
296 LOG(WARNING) << "GCM RETURNED " << result; | |
mlamouri (slow - plz ping)
2014/10/29 20:13:33
nit: leftover debugging code?
Miguel Garcia
2014/10/30 12:27:15
Indeed, sorry about that.
| |
297 | |
256 content::PushRegistrationStatus status = | 298 content::PushRegistrationStatus status = |
257 result == GCMClient::SUCCESS | 299 result == GCMClient::SUCCESS |
258 ? content::PUSH_REGISTRATION_STATUS_SUCCESS | 300 ? content::PUSH_REGISTRATION_STATUS_SUCCESS |
259 : content::PUSH_REGISTRATION_STATUS_SERVICE_ERROR; | 301 : content::PUSH_REGISTRATION_STATUS_SERVICE_ERROR; |
260 RegisterEnd(callback, registration_id, status); | 302 RegisterEnd(callback, registration_id, status); |
261 } | 303 } |
262 | 304 |
263 void PushMessagingServiceImpl::DidRequestPermission( | 305 void PushMessagingServiceImpl::DidRequestPermission( |
264 const PushMessagingApplicationId& application_id, | 306 const PushMessagingApplicationId& application_id, |
265 const std::string& sender_id, | 307 const std::string& sender_id, |
(...skipping 17 matching lines...) Expand all Loading... | |
283 sender_ids, | 325 sender_ids, |
284 base::Bind(&PushMessagingServiceImpl::DidRegister, | 326 base::Bind(&PushMessagingServiceImpl::DidRegister, |
285 weak_factory_.GetWeakPtr(), | 327 weak_factory_.GetWeakPtr(), |
286 register_callback)); | 328 register_callback)); |
287 } | 329 } |
288 | 330 |
289 // TODO(johnme): Unregister should decrement the pref, and call | 331 // TODO(johnme): Unregister should decrement the pref, and call |
290 // RemoveAppHandler if the count drops to zero. | 332 // RemoveAppHandler if the count drops to zero. |
291 | 333 |
292 } // namespace gcm | 334 } // namespace gcm |
OLD | NEW |