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 f6043b495bd9650c7b37f2ebd8947aa640847c15..ce8d37747c8d3b955b6fc9a062f925c4e134ddfa 100644 |
--- a/chrome/browser/services/gcm/push_messaging_service_impl.cc |
+++ b/chrome/browser/services/gcm/push_messaging_service_impl.cc |
@@ -7,8 +7,13 @@ |
#include <vector> |
#include "base/bind.h" |
+#include "chrome/browser/content_settings/permission_request_id.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/services/gcm/gcm_permission_context.h" |
#include "chrome/browser/services/gcm/gcm_profile_service.h" |
+#include "chrome/browser/tab_contents/tab_util.h" |
#include "components/gcm_driver/gcm_driver.h" |
+#include "content/public/browser/web_contents.h" |
namespace gcm { |
@@ -22,16 +27,38 @@ PushMessagingServiceImpl::~PushMessagingServiceImpl() {} |
void PushMessagingServiceImpl::Register( |
const std::string& app_id, |
const std::string& sender_id, |
+ const int renderer_id, |
+ const int routing_id, |
const content::PushMessagingService::RegisterCallback& callback) { |
// 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, |
+ content::WebContents* web_contents = |
+ tab_util::GetWebContentsByID(renderer_id, routing_id); |
+ |
+ // The page doesn't exist any more. |
+ if (!web_contents) |
+ return; |
Michael van Ouwerkerk
2014/06/19 10:16:11
We can't only return. We must also send a rejectio
Miguel Garcia
2014/06/19 17:49:28
But if web_contents does not exist, it means the r
|
+ |
+ // TODO(miguelg) need to send this over IPC when bubble support is |
+ // implemented. |
+ int bridge_id = -1; |
+ |
+ const PermissionRequestID id(renderer_id, routing_id, bridge_id, GURL()); |
+ |
+ GURL embedder = web_contents->GetURL(); |
+ gcm::GCMPermissionContext* context = |
Michael van Ouwerkerk
2014/06/19 10:16:11
We have other contexts (ServiceWorkerContextWrappe
Miguel Garcia
2014/06/19 17:49:28
Done.
|
+ gcm_profile_service_->profile()->GetPushMessagingPermissionContext(); |
+ |
+ context->RequestPermission( |
+ web_contents, |
+ id, |
+ embedder, |
+ false, |
+ base::Bind(&PushMessagingServiceImpl::ShouldProceed, |
weak_factory_.GetWeakPtr(), |
+ sender_id, |
+ app_id, |
callback)); |
} |
@@ -43,4 +70,29 @@ void PushMessagingServiceImpl::DidRegister( |
callback.Run(endpoint, registration_id, result == GCMClient::SUCCESS); |
} |
+void PushMessagingServiceImpl::ShouldProceed( |
Michael van Ouwerkerk
2014/06/19 10:16:11
This method name is not very clear. Let's rename t
Miguel Garcia
2014/06/19 17:49:28
Done.
|
+ const std::string& sender_id, |
+ const std::string& app_id, |
+ const content::PushMessagingService::RegisterCallback& callback, |
Michael van Ouwerkerk
2014/06/19 10:16:11
The argument and method names are starting to conf
Miguel Garcia
2014/06/19 17:49:28
Done.
|
+ bool allow) { |
+ if (!allow) { |
+ // NOT_SIGNED_IN is the closest error I can find when not allowed. |
Michael van Ouwerkerk
2014/06/19 10:16:11
We really need to rewire all the error codes so pp
Miguel Garcia
2014/06/19 17:49:28
Agreed
|
+ DidRegister(callback, "", GCMClient::NOT_SIGNED_IN); |
Michael van Ouwerkerk
2014/06/19 10:16:11
The signed-in requirement is going away. Maybe jus
Miguel Garcia
2014/06/19 17:49:28
Done.
|
+ 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(), |
+ callback)); |
+} |
+ |
} // namespace gcm |