 Chromium Code Reviews
 Chromium Code Reviews Issue 1701313002:
  Partial implementation of subscription restrictions.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1701313002:
  Partial implementation of subscription restrictions.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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..28db707bca53f39f255f6ae72b69d8008fe655ae 100644 | 
| --- a/content/renderer/push_messaging/push_messaging_dispatcher.cc | 
| +++ b/content/renderer/push_messaging/push_messaging_dispatcher.cc | 
| @@ -44,46 +44,63 @@ void PushMessagingDispatcher::subscribe( | 
| blink::WebPushSubscriptionCallbacks* callbacks) { | 
| DCHECK(service_worker_registration); | 
| DCHECK(callbacks); | 
| - RenderFrameImpl::FromRoutingID(routing_id()) | 
| - ->manifest_manager() | 
| - ->GetManifest(base::Bind( | 
| - &PushMessagingDispatcher::DoSubscribe, base::Unretained(this), | 
| - service_worker_registration, options, callbacks)); | 
| + // If a developer provided an application server key in |options|, skip | 
| + // fetching the manifest. | 
| + if (options.applicationServerKey.isEmpty()) { | 
| + RenderFrameImpl::FromRoutingID(routing_id()) | 
| + ->manifest_manager() | 
| + ->GetManifest(base::Bind( | 
| + &PushMessagingDispatcher::DidGetManifest, base::Unretained(this), | 
| + service_worker_registration, options, callbacks)); | 
| + } else { | 
| 
Peter Beverloo
2016/02/23 14:28:29
nit: Chrome prefers early returns, so you could re
 
harkness
2016/02/26 11:44:26
Actually, in this case, I feel like the different
 
Peter Beverloo
2016/02/26 16:02:32
No :-)
 | 
| + PushSubscriptionOptions content_options; | 
| + content_options.user_visible_only = options.userVisibleOnly; | 
| + content_options.sender_info = options.applicationServerKey.utf8(); | 
| + DoSubscribe(service_worker_registration, content_options, callbacks); | 
| + } | 
| } | 
| -void PushMessagingDispatcher::DoSubscribe( | 
| +void PushMessagingDispatcher::DidGetManifest( | 
| blink::WebServiceWorkerRegistration* service_worker_registration, | 
| const blink::WebPushSubscriptionOptions& options, | 
| blink::WebPushSubscriptionCallbacks* callbacks, | 
| const Manifest& manifest) { | 
| int request_id = subscription_callbacks_.Add(callbacks); | 
| - int64_t service_worker_registration_id = | 
| - static_cast<WebServiceWorkerRegistrationImpl*>( | 
| - service_worker_registration) | 
| - ->registration_id(); | 
| - | 
| + // Get the sender_info from the manifest since it wasn't provided by | 
| + // the caller. | 
| if (manifest.IsEmpty()) { | 
| OnSubscribeFromDocumentError( | 
| request_id, PUSH_REGISTRATION_STATUS_MANIFEST_EMPTY_OR_MISSING); | 
| return; | 
| } | 
| - std::string sender_id = | 
| + PushSubscriptionOptions content_options; | 
| + content_options.user_visible_only = options.userVisibleOnly; | 
| + content_options.sender_info = | 
| 
Peter Beverloo
2016/02/23 14:28:29
nit: Since this has got a default value of empty a
 
harkness
2016/02/26 11:44:26
Done.
 | 
| manifest.gcm_sender_id.is_null() | 
| ? std::string() | 
| : base::UTF16ToUTF8(manifest.gcm_sender_id.string()); | 
| - if (sender_id.empty()) { | 
| + | 
| + DoSubscribe(service_worker_registration, content_options, callbacks); | 
| +} | 
| + | 
| +void PushMessagingDispatcher::DoSubscribe( | 
| + blink::WebServiceWorkerRegistration* service_worker_registration, | 
| + const PushSubscriptionOptions& options, | 
| + blink::WebPushSubscriptionCallbacks* callbacks) { | 
| + int request_id = subscription_callbacks_.Add(callbacks); | 
| + int64_t service_worker_registration_id = | 
| + static_cast<WebServiceWorkerRegistrationImpl*>( | 
| + service_worker_registration) | 
| + ->registration_id(); | 
| + | 
| + if (options.sender_info.empty()) { | 
| OnSubscribeFromDocumentError(request_id, | 
| PUSH_REGISTRATION_STATUS_NO_SENDER_ID); | 
| return; | 
| } | 
| - | 
| 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, options, service_worker_registration_id)); | 
| } | 
| void PushMessagingDispatcher::OnSubscribeFromDocumentSuccess( |