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..cbf902468c808753b704807d0e56309c0ffeb1e1 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" |
|
Peter Beverloo
2016/02/18 11:39:43
nit: unused
harkness
2016/02/22 15:40:43
Done.
|
| #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" |
|
Peter Beverloo
2016/02/18 11:39:43
nit: unused
harkness
2016/02/22 15:40:43
Done.
|
| #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. |
|
Peter Beverloo
2016/02/18 11:39:43
Perhaps phrase this like "If the developer provide
harkness
2016/02/22 15:40:43
Updated the comment, and I went ahead and refactor
|
| RenderFrameImpl::FromRoutingID(routing_id()) |
| ->manifest_manager() |
| ->GetManifest(base::Bind( |
| @@ -62,28 +66,39 @@ 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; |
| + PushSubscriptionOptions content_options; |
| + content_options.user_visible_only = options.userVisibleOnly; |
| + |
| + // If a public key isn't provided by the client, fall back to the |
| + // sender_id specification. |
| + if (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 |
|
Peter Beverloo
2016/02/18 11:39:43
nit: applicationServerKey
Would you want to do th
harkness
2016/02/22 15:40:43
Done.
|
| + // 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( |