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 @@
#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/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 "third_party/WebKit/public/platform/WebPushError.h"
#include "third_party/WebKit/public/platform/WebPushRegistration.h"
......@@ -36,20 +39,21 @@ bool PushMessagingDispatcher::OnMessageReceived(const IPC::Message& message) {
void PushMessagingDispatcher::registerPushMessaging(
const WebString& sender_id,
blink::WebPushRegistrationCallbacks* callbacks) {
DCHECK(callbacks);
scoped_ptr<blink::WebPushError> error(new blink::WebPushError(
blink::WebPushError::ErrorTypeAbort,
WebString::fromUTF8(PushMessagingStatusToString(
PUSH_MESSAGING_STATUS_REGISTRATION_FAILED_NO_SERVICE_WORKER))));
callbacks->onError(error.release());
delete callbacks;
blink::WebPushRegistrationCallbacks* callbacks,
blink::WebServiceWorkerProvider* service_worker_provider) {
RenderFrameImpl::FromRoutingID(routing_id())->manifest_manager()->GetManifest(
base::Bind(&PushMessagingDispatcher::DoRegister,
base::Unretained(this),
sender_id.utf8(),
callbacks,
service_worker_provider));
}
void PushMessagingDispatcher::registerPushMessaging(
const WebString& sender_id,
void PushMessagingDispatcher::DoRegister(
const std::string& sender_id,
blink::WebPushRegistrationCallbacks* callbacks,
blink::WebServiceWorkerProvider* service_worker_provider) {
blink::WebServiceWorkerProvider* service_worker_provider,
const Manifest& manifest) {
DCHECK(callbacks);
int callbacks_id = registration_callbacks_.Add(callbacks);
int service_worker_provider_id = static_cast<WebServiceWorkerProviderImpl*>(
......@@ -57,7 +61,9 @@ void PushMessagingDispatcher::registerPushMessaging(
Send(new PushMessagingHostMsg_Register(
routing_id(),
callbacks_id,
sender_id.utf8(),
manifest.gcm_sender_id.is_null()
? sender_id
: base::UTF16ToUTF8(manifest.gcm_sender_id.string()),
blink::WebUserGestureIndicator::isProcessingUserGesture(),
service_worker_provider_id));
}
......
......@@ -24,6 +24,9 @@ class WebString;
} // namespace blink
namespace content {
struct Manifest;
class PushMessagingDispatcher : public RenderFrameObserver,
public blink::WebPushClient {
public:
......@@ -35,16 +38,16 @@ class PushMessagingDispatcher : public RenderFrameObserver,
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
// 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(
const blink::WebString& sender_id,
blink::WebPushRegistrationCallbacks* callbacks,
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,
const GURL& endpoint,
const std::string& registration_id);
......
......@@ -1006,6 +1006,10 @@ void RenderFrameImpl::BindServiceRegistry(
service_registry_.BindRemoteServiceProvider(service_provider_handle.Pass());
}
ManifestManager* RenderFrameImpl::manifest_manager() {
return manifest_manager_;
}
void RenderFrameImpl::OnBeforeUnload() {
TRACE_EVENT1("navigation", "RenderFrameImpl::OnBeforeUnload",
"id", routing_id_);
......
......@@ -461,6 +461,8 @@ class CONTENT_EXPORT RenderFrameImpl
void BindServiceRegistry(
mojo::ScopedMessagePipeHandle service_provider_handle);
ManifestManager* manifest_manager();
protected:
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