Chromium Code Reviews| 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 id, | 224 id, |
| 225 embedder, | 225 embedder, |
| 226 user_gesture, | 226 user_gesture, |
| 227 base::Bind(&PushMessagingServiceImpl::DidRequestPermission, | 227 base::Bind(&PushMessagingServiceImpl::DidRequestPermission, |
| 228 weak_factory_.GetWeakPtr(), | 228 weak_factory_.GetWeakPtr(), |
| 229 application_id, | 229 application_id, |
| 230 sender_id, | 230 sender_id, |
| 231 callback)); | 231 callback)); |
| 232 } | 232 } |
| 233 | 233 |
| 234 static PushPermissionStatus ToPushPermission( | |
|
Michael van Ouwerkerk
2014/10/20 16:30:07
This should be in the anonymous namespace at the t
Miguel Garcia
2014/10/22 16:35:27
Done.
| |
| 235 ContentSetting setting) { | |
| 236 switch (setting) { | |
| 237 case CONTENT_SETTING_ALLOW: | |
| 238 return PushPermissionStatus::PushPermissionGranted; | |
| 239 case CONTENT_SETTING_BLOCK: | |
| 240 return PushPermissionStatus::PushPermissionDenied; | |
| 241 case CONTENT_SETTING_ASK: | |
| 242 return PushPermissionStatus::PushPermissionDefault; | |
| 243 default: | |
| 244 NOTREACHED(); | |
| 245 return PushPermissionStatus::PushPermissionDenied; | |
| 246 } | |
| 247 } | |
| 248 | |
| 249 PushPermissionStatus PushMessagingServiceImpl::PermissionStatus( | |
| 250 const GURL& requesting_origin, int renderer_id, int render_frame_id) { | |
| 251 content::RenderFrameHost* render_frame_host = | |
| 252 content::RenderFrameHost::FromID(renderer_id, render_frame_id); | |
| 253 | |
| 254 // The frame doesn't exist any more, or we received a bad frame id. | |
| 255 if (!render_frame_host) | |
| 256 return PushPermissionStatus::PushPermissionDenied; | |
| 257 | |
| 258 content::WebContents* web_contents = | |
| 259 content::WebContents::FromRenderFrameHost(render_frame_host); | |
| 260 | |
| 261 // The page doesn't exist any more or we got a bad render frame host. | |
| 262 if (!web_contents) | |
| 263 return PushPermissionStatus::PushPermissionDenied; | |
| 264 | |
| 265 GURL embedder_origin = web_contents->GetLastCommittedURL().GetOrigin(); | |
| 266 gcm::PushMessagingPermissionContext* permission_context = | |
| 267 gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_); | |
| 268 return ToPushPermission( | |
| 269 permission_context->PermissionStatus(requesting_origin, embedder_origin)); | |
| 270 } | |
| 271 | |
| 234 void PushMessagingServiceImpl::RegisterEnd( | 272 void PushMessagingServiceImpl::RegisterEnd( |
| 235 const content::PushMessagingService::RegisterCallback& callback, | 273 const content::PushMessagingService::RegisterCallback& callback, |
| 236 const std::string& registration_id, | 274 const std::string& registration_id, |
| 237 content::PushMessagingStatus status) { | 275 content::PushMessagingStatus status) { |
| 238 GURL endpoint = GURL("https://android.googleapis.com/gcm/send"); | 276 GURL endpoint = GURL("https://android.googleapis.com/gcm/send"); |
| 239 callback.Run(endpoint, registration_id, status); | 277 callback.Run(endpoint, registration_id, status); |
| 240 if (status == content::PUSH_MESSAGING_STATUS_OK) { | 278 if (status == content::PUSH_MESSAGING_STATUS_OK) { |
| 241 // TODO(johnme): Make sure the pref doesn't get out of sync after crashes. | 279 // TODO(johnme): Make sure the pref doesn't get out of sync after crashes. |
| 242 int registration_count = profile_->GetPrefs()->GetInteger( | 280 int registration_count = profile_->GetPrefs()->GetInteger( |
| 243 prefs::kPushMessagingRegistrationCount); | 281 prefs::kPushMessagingRegistrationCount); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 sender_ids, | 319 sender_ids, |
| 282 base::Bind(&PushMessagingServiceImpl::DidRegister, | 320 base::Bind(&PushMessagingServiceImpl::DidRegister, |
| 283 weak_factory_.GetWeakPtr(), | 321 weak_factory_.GetWeakPtr(), |
| 284 register_callback)); | 322 register_callback)); |
| 285 } | 323 } |
| 286 | 324 |
| 287 // TODO(johnme): Unregister should decrement the pref, and call | 325 // TODO(johnme): Unregister should decrement the pref, and call |
| 288 // RemoveAppHandler if the count drops to zero. | 326 // RemoveAppHandler if the count drops to zero. |
| 289 | 327 |
| 290 } // namespace gcm | 328 } // namespace gcm |
| OLD | NEW |