Chromium Code Reviews| Index: content/renderer/push_messaging/push_messaging_dispatcher.cc |
| diff --git a/content/renderer/push_messaging/push_messaging_dispatcher.cc b/content/renderer/push_messaging/push_messaging_dispatcher.cc |
| index d10704326e5bef8cc6626fbf62476646b96c8eaa..579bcef9e7ee7c9d3efd618fa81ff7e804c7f04e 100644 |
| --- a/content/renderer/push_messaging/push_messaging_dispatcher.cc |
| +++ b/content/renderer/push_messaging/push_messaging_dispatcher.cc |
| @@ -4,9 +4,11 @@ |
| #include "content/renderer/push_messaging/push_messaging_dispatcher.h" |
| +#include "base/command_line.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "content/child/service_worker/web_service_worker_registration_impl.h" |
| #include "content/common/push_messaging_messages.h" |
| +#include "content/public/common/content_switches.h" |
| #include "content/renderer/manifest/manifest_manager.h" |
| #include "content/renderer/render_frame_impl.h" |
| #include "ipc/ipc_message.h" |
| @@ -44,6 +46,8 @@ void PushMessagingDispatcher::subscribe( |
| blink::WebPushSubscriptionCallbacks* callbacks) { |
| DCHECK(service_worker_registration); |
| DCHECK(callbacks); |
| + // TODO(harkness) If the command line flag for push subscriptions is enabled |
| + // and the client provided a public key, don't load the manifest. |
| RenderFrameImpl::FromRoutingID(routing_id()) |
| ->manifest_manager() |
| ->GetManifest(base::Bind( |
| @@ -62,28 +66,41 @@ void PushMessagingDispatcher::DoSubscribe( |
| service_worker_registration) |
| ->registration_id(); |
| - if (manifest.IsEmpty()) { |
| - OnSubscribeFromDocumentError( |
| - request_id, PUSH_REGISTRATION_STATUS_MANIFEST_EMPTY_OR_MISSING); |
| - return; |
| - } |
| - |
| - std::string sender_id = |
| - manifest.gcm_sender_id.is_null() |
| - ? std::string() |
| - : base::UTF16ToUTF8(manifest.gcm_sender_id.string()); |
| - if (sender_id.empty()) { |
| - OnSubscribeFromDocumentError(request_id, |
| - PUSH_REGISTRATION_STATUS_NO_SENDER_ID); |
| - return; |
| + ContentPushSubscriptionOptions content_options; |
| + content_options.user_visible_only = options.userVisibleOnly; |
| + |
| + // If SubscriptionRestrictions aren't enabled or a public key isn't provided |
| + // by the client, fall back to the old sender_id specification. |
| + if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kEnableExperimentalWebPlatformFeatures) || |
|
Peter Beverloo
2016/02/17 16:15:36
No need to check for the command line flag— we can
harkness
2016/02/18 10:45:15
Done.
|
| + options.applicationServerKey.isEmpty()) { |
| + if (manifest.IsEmpty()) { |
| + OnSubscribeFromDocumentError( |
| + request_id, PUSH_REGISTRATION_STATUS_MANIFEST_EMPTY_OR_MISSING); |
| + return; |
| + } |
| + |
| + content_options.using_public_key = false; |
| + content_options.sender_info = |
| + manifest.gcm_sender_id.is_null() |
| + ? std::string() |
| + : base::UTF16ToUTF8(manifest.gcm_sender_id.string()); |
| + if (content_options.sender_info.empty()) { |
| + OnSubscribeFromDocumentError(request_id, |
| + PUSH_REGISTRATION_STATUS_NO_SENDER_ID); |
| + return; |
| + } |
| + } else { |
| + content_options.using_public_key = true; |
| + content_options.sender_info = options.applicationServerKey.utf8(); |
| + |
| + // TODO(harkness) Need to check that appServicePublicKey has a valid |
| + // format and reject with InvalidAccessError if invalid. |
| } |
| Send(new PushMessagingHostMsg_SubscribeFromDocument( |
| - routing_id(), request_id, |
| - manifest.gcm_sender_id.is_null() |
| - ? std::string() |
| - : base::UTF16ToUTF8(manifest.gcm_sender_id.string()), |
| - options.userVisibleOnly, service_worker_registration_id)); |
| + routing_id(), request_id, content_options, |
| + service_worker_registration_id)); |
| } |
| void PushMessagingDispatcher::OnSubscribeFromDocumentSuccess( |