Chromium Code Reviews| 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 0306d111fe66e95f69e299af9d68056c0989f568..67e261a2fea97d7fac5e18bdd801da2e57f6c7fa 100644 |
| --- a/chrome/browser/services/gcm/push_messaging_service_impl.cc |
| +++ b/chrome/browser/services/gcm/push_messaging_service_impl.cc |
| @@ -10,13 +10,18 @@ |
| #include "base/command_line.h" |
| #include "base/prefs/pref_service.h" |
| #include "base/strings/string_util.h" |
| +#include "chrome/browser/content_settings/permission_request_id.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/services/gcm/gcm_profile_service.h" |
| #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
| +#include "chrome/browser/services/gcm/push_messaging_permission_context.h" |
| +#include "chrome/browser/services/gcm/push_messaging_permission_context_factory.h" |
| +#include "chrome/browser/tab_contents/tab_util.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/pref_names.h" |
| #include "components/gcm_driver/gcm_driver.h" |
| #include "components/pref_registry/pref_registry_syncable.h" |
| +#include "content/public/browser/web_contents.h" |
| namespace gcm { |
| @@ -127,6 +132,8 @@ void PushMessagingServiceImpl::OnSendError( |
| void PushMessagingServiceImpl::Register( |
| const std::string& app_id, |
| const std::string& sender_id, |
| + const int renderer_id, |
| + const int render_view_id, |
| const content::PushMessagingService::RegisterCallback& callback) { |
| if (!gcm_profile_service_->driver()) { |
| NOTREACHED() << "There is no GCMDriver. Has GCMProfileService shut down?"; |
| @@ -134,7 +141,7 @@ void PushMessagingServiceImpl::Register( |
| if (profile_->GetPrefs()->GetInteger( |
| prefs::kPushMessagingRegistrationCount) >= kMaxRegistrations) { |
| - DidRegister(app_id, callback, "", GCMClient::UNKNOWN_ERROR); |
| + DidRegister(app_id, callback, std::string(), GCMClient::UNKNOWN_ERROR); |
| return; |
| } |
| @@ -143,12 +150,36 @@ void PushMessagingServiceImpl::Register( |
| if (gcm_profile_service_->driver()->GetAppHandler(kAppIdPrefix) != this) |
| gcm_profile_service_->driver()->AddAppHandler(kAppIdPrefix, this); |
| - std::vector<std::string> sender_ids(1, sender_id); |
| - gcm_profile_service_->driver()->Register( |
| - app_id, |
| - sender_ids, |
| - base::Bind(&PushMessagingServiceImpl::DidRegister, |
| + content::WebContents* web_contents = |
| + tab_util::GetWebContentsByID(renderer_id, render_view_id); |
| + |
| + // The page doesn't exist any more. |
| + if (!web_contents) |
| + return; |
| + |
| + // TODO(miguelg) need to send this over IPC when bubble support is |
| + // implemented. |
| + int bridge_id = -1; |
| + |
| + const PermissionRequestID id(renderer_id, render_view_id, bridge_id, GURL()); |
| + |
| + GURL embedder = web_contents->GetURL(); |
| + gcm::PushMessagingPermissionContext* permission_context = |
| + gcm::PushMessagingPermissionContextFactory::GetForProfile(profile_); |
| + |
| + if (permission_context == NULL) { |
| + DidRegister(app_id, callback, std::string(), GCMClient::UNKNOWN_ERROR); |
| + return; |
| + } |
| + |
| + permission_context->RequestPermission( |
| + web_contents, |
| + id, |
| + embedder, |
| + false, |
|
Michael van Ouwerkerk
2014/06/23 12:34:10
Nit: What does false stand for? Maybe add a commen
Miguel Garcia
2014/06/23 18:23:14
Done.
|
| + base::Bind(&PushMessagingServiceImpl::DidRequestPermission, |
| weak_factory_.GetWeakPtr(), |
| + sender_id, |
| app_id, |
| callback)); |
| } |
| @@ -170,6 +201,33 @@ void PushMessagingServiceImpl::DidRegister( |
| } |
| } |
| +void PushMessagingServiceImpl::DidRequestPermission( |
| + const std::string& sender_id, |
| + const std::string& app_id, |
| + const content::PushMessagingService::RegisterCallback& register_callback, |
| + bool allow) { |
| + if (!allow) { |
| + // TODO(miguelg) extend the error enum to allow for pemission failure. |
| + DidRegister(app_id, register_callback, std::string(), |
| + GCMClient::UNKNOWN_ERROR); |
| + return; |
| + } |
| + |
| + // The GCMDriver could be NULL if GCMProfileService has been shut down. |
| + if (!gcm_profile_service_->driver()) |
| + return; |
| + |
| + std::vector<std::string> sender_ids(1, sender_id); |
| + |
| + gcm_profile_service_->driver()->Register( |
| + app_id, |
| + sender_ids, |
| + base::Bind(&PushMessagingServiceImpl::DidRegister, |
| + weak_factory_.GetWeakPtr(), |
| + app_id, |
| + register_callback)); |
| +} |
| + |
| // TODO(johnme): Unregister should decrement the pref, and call |
| // RemoveAppHandler if the count drops to zero. |