Commit 4fff1990 authored by mlamouri's avatar mlamouri Committed by Commit bot

[Push] Use Manifest.gcm_sender_id instead of API sender_id if possible.

PushMessagingDispatcher is now trying to get the Manifest before
asking the registration to happen. If the gcm_sender_id is set, it will
be used. Otherwise, the flow is unchanged.

This is an considered option in order to no longer require an opaque
property bag to be passed when registering. It might or might not stay
as is.

BUG=414873

Review URL: https://codereview.chromium.org/609393002

Cr-Commit-Position: refs/heads/master@{#297403}
parent 45a1583b
...@@ -4,8 +4,11 @@ ...@@ -4,8 +4,11 @@
#include "content/renderer/push_messaging_dispatcher.h" #include "content/renderer/push_messaging_dispatcher.h"
#include "base/strings/utf_string_conversions.h"
#include "content/child/service_worker/web_service_worker_provider_impl.h" #include "content/child/service_worker/web_service_worker_provider_impl.h"
#include "content/common/push_messaging_messages.h" #include "content/common/push_messaging_messages.h"
#include "content/renderer/manifest/manifest_manager.h"
#include "content/renderer/render_frame_impl.h"
#include "ipc/ipc_message.h" #include "ipc/ipc_message.h"
#include "third_party/WebKit/public/platform/WebPushError.h" #include "third_party/WebKit/public/platform/WebPushError.h"
#include "third_party/WebKit/public/platform/WebPushRegistration.h" #include "third_party/WebKit/public/platform/WebPushRegistration.h"
...@@ -36,20 +39,21 @@ bool PushMessagingDispatcher::OnMessageReceived(const IPC::Message& message) { ...@@ -36,20 +39,21 @@ bool PushMessagingDispatcher::OnMessageReceived(const IPC::Message& message) {
void PushMessagingDispatcher::registerPushMessaging( void PushMessagingDispatcher::registerPushMessaging(
const WebString& sender_id, const WebString& sender_id,
blink::WebPushRegistrationCallbacks* callbacks) { blink::WebPushRegistrationCallbacks* callbacks,
DCHECK(callbacks); blink::WebServiceWorkerProvider* service_worker_provider) {
scoped_ptr<blink::WebPushError> error(new blink::WebPushError( RenderFrameImpl::FromRoutingID(routing_id())->manifest_manager()->GetManifest(
blink::WebPushError::ErrorTypeAbort, base::Bind(&PushMessagingDispatcher::DoRegister,
WebString::fromUTF8(PushMessagingStatusToString( base::Unretained(this),
PUSH_MESSAGING_STATUS_REGISTRATION_FAILED_NO_SERVICE_WORKER)))); sender_id.utf8(),
callbacks->onError(error.release()); callbacks,
delete callbacks; service_worker_provider));
} }
void PushMessagingDispatcher::registerPushMessaging( void PushMessagingDispatcher::DoRegister(
const WebString& sender_id, const std::string& sender_id,
blink::WebPushRegistrationCallbacks* callbacks, blink::WebPushRegistrationCallbacks* callbacks,
blink::WebServiceWorkerProvider* service_worker_provider) { blink::WebServiceWorkerProvider* service_worker_provider,
const Manifest& manifest) {
DCHECK(callbacks); DCHECK(callbacks);
int callbacks_id = registration_callbacks_.Add(callbacks); int callbacks_id = registration_callbacks_.Add(callbacks);
int service_worker_provider_id = static_cast<WebServiceWorkerProviderImpl*>( int service_worker_provider_id = static_cast<WebServiceWorkerProviderImpl*>(
...@@ -57,7 +61,9 @@ void PushMessagingDispatcher::registerPushMessaging( ...@@ -57,7 +61,9 @@ void PushMessagingDispatcher::registerPushMessaging(
Send(new PushMessagingHostMsg_Register( Send(new PushMessagingHostMsg_Register(
routing_id(), routing_id(),
callbacks_id, callbacks_id,
sender_id.utf8(), manifest.gcm_sender_id.is_null()
? sender_id
: base::UTF16ToUTF8(manifest.gcm_sender_id.string()),
blink::WebUserGestureIndicator::isProcessingUserGesture(), blink::WebUserGestureIndicator::isProcessingUserGesture(),
service_worker_provider_id)); service_worker_provider_id));
} }
......
...@@ -24,6 +24,9 @@ class WebString; ...@@ -24,6 +24,9 @@ class WebString;
} // namespace blink } // namespace blink
namespace content { namespace content {
struct Manifest;
class PushMessagingDispatcher : public RenderFrameObserver, class PushMessagingDispatcher : public RenderFrameObserver,
public blink::WebPushClient { public blink::WebPushClient {
public: public:
...@@ -35,16 +38,16 @@ class PushMessagingDispatcher : public RenderFrameObserver, ...@@ -35,16 +38,16 @@ class PushMessagingDispatcher : public RenderFrameObserver,
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
// WebPushClient implementation. // WebPushClient implementation.
// TODO(mvanouwerkerk): Delete this method once its callers are gone and
// WebPushClient no longer defines it (as pure virtual).
virtual void registerPushMessaging(
const blink::WebString& sender_id,
blink::WebPushRegistrationCallbacks* callbacks);
virtual void registerPushMessaging( virtual void registerPushMessaging(
const blink::WebString& sender_id, const blink::WebString& sender_id,
blink::WebPushRegistrationCallbacks* callbacks, blink::WebPushRegistrationCallbacks* callbacks,
blink::WebServiceWorkerProvider* service_worker_provider); blink::WebServiceWorkerProvider* service_worker_provider);
void DoRegister(const std::string& sender_id,
blink::WebPushRegistrationCallbacks* callbacks,
blink::WebServiceWorkerProvider* service_worker_provider,
const Manifest& manifest);
void OnRegisterSuccess(int32 callbacks_id, void OnRegisterSuccess(int32 callbacks_id,
const GURL& endpoint, const GURL& endpoint,
const std::string& registration_id); const std::string& registration_id);
......
...@@ -1006,6 +1006,10 @@ void RenderFrameImpl::BindServiceRegistry( ...@@ -1006,6 +1006,10 @@ void RenderFrameImpl::BindServiceRegistry(
service_registry_.BindRemoteServiceProvider(service_provider_handle.Pass()); service_registry_.BindRemoteServiceProvider(service_provider_handle.Pass());
} }
ManifestManager* RenderFrameImpl::manifest_manager() {
return manifest_manager_;
}
void RenderFrameImpl::OnBeforeUnload() { void RenderFrameImpl::OnBeforeUnload() {
TRACE_EVENT1("navigation", "RenderFrameImpl::OnBeforeUnload", TRACE_EVENT1("navigation", "RenderFrameImpl::OnBeforeUnload",
"id", routing_id_); "id", routing_id_);
......
...@@ -461,6 +461,8 @@ class CONTENT_EXPORT RenderFrameImpl ...@@ -461,6 +461,8 @@ class CONTENT_EXPORT RenderFrameImpl
void BindServiceRegistry( void BindServiceRegistry(
mojo::ScopedMessagePipeHandle service_provider_handle); mojo::ScopedMessagePipeHandle service_provider_handle);
ManifestManager* manifest_manager();
protected: protected:
RenderFrameImpl(RenderViewImpl* render_view, int32 routing_id); RenderFrameImpl(RenderViewImpl* render_view, int32 routing_id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment