Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/push_messaging/push_messaging_dispatcher.h" | 5 #include "content/renderer/push_messaging/push_messaging_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | |
|
Peter Beverloo
2016/02/18 11:39:43
nit: unused
harkness
2016/02/22 15:40:43
Done.
| |
| 7 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 9 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
| 9 #include "content/common/push_messaging_messages.h" | 10 #include "content/common/push_messaging_messages.h" |
| 11 #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.
| |
| 10 #include "content/renderer/manifest/manifest_manager.h" | 12 #include "content/renderer/manifest/manifest_manager.h" |
| 11 #include "content/renderer/render_frame_impl.h" | 13 #include "content/renderer/render_frame_impl.h" |
| 12 #include "ipc/ipc_message.h" | 14 #include "ipc/ipc_message.h" |
| 13 #include "third_party/WebKit/public/platform/WebString.h" | 15 #include "third_party/WebKit/public/platform/WebString.h" |
| 14 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushError .h" | 16 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushError .h" |
| 15 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc ription.h" | 17 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc ription.h" |
| 16 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc riptionOptions.h" | 18 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc riptionOptions.h" |
| 17 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerRegistration.h" | 19 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerRegistration.h" |
| 18 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 20 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
| 19 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 21 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 37 IPC_END_MESSAGE_MAP() | 39 IPC_END_MESSAGE_MAP() |
| 38 return handled; | 40 return handled; |
| 39 } | 41 } |
| 40 | 42 |
| 41 void PushMessagingDispatcher::subscribe( | 43 void PushMessagingDispatcher::subscribe( |
| 42 blink::WebServiceWorkerRegistration* service_worker_registration, | 44 blink::WebServiceWorkerRegistration* service_worker_registration, |
| 43 const blink::WebPushSubscriptionOptions& options, | 45 const blink::WebPushSubscriptionOptions& options, |
| 44 blink::WebPushSubscriptionCallbacks* callbacks) { | 46 blink::WebPushSubscriptionCallbacks* callbacks) { |
| 45 DCHECK(service_worker_registration); | 47 DCHECK(service_worker_registration); |
| 46 DCHECK(callbacks); | 48 DCHECK(callbacks); |
| 49 // TODO(harkness) If the command line flag for push subscriptions is enabled | |
| 50 // 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
| |
| 47 RenderFrameImpl::FromRoutingID(routing_id()) | 51 RenderFrameImpl::FromRoutingID(routing_id()) |
| 48 ->manifest_manager() | 52 ->manifest_manager() |
| 49 ->GetManifest(base::Bind( | 53 ->GetManifest(base::Bind( |
| 50 &PushMessagingDispatcher::DoSubscribe, base::Unretained(this), | 54 &PushMessagingDispatcher::DoSubscribe, base::Unretained(this), |
| 51 service_worker_registration, options, callbacks)); | 55 service_worker_registration, options, callbacks)); |
| 52 } | 56 } |
| 53 | 57 |
| 54 void PushMessagingDispatcher::DoSubscribe( | 58 void PushMessagingDispatcher::DoSubscribe( |
| 55 blink::WebServiceWorkerRegistration* service_worker_registration, | 59 blink::WebServiceWorkerRegistration* service_worker_registration, |
| 56 const blink::WebPushSubscriptionOptions& options, | 60 const blink::WebPushSubscriptionOptions& options, |
| 57 blink::WebPushSubscriptionCallbacks* callbacks, | 61 blink::WebPushSubscriptionCallbacks* callbacks, |
| 58 const Manifest& manifest) { | 62 const Manifest& manifest) { |
| 59 int request_id = subscription_callbacks_.Add(callbacks); | 63 int request_id = subscription_callbacks_.Add(callbacks); |
| 60 int64_t service_worker_registration_id = | 64 int64_t service_worker_registration_id = |
| 61 static_cast<WebServiceWorkerRegistrationImpl*>( | 65 static_cast<WebServiceWorkerRegistrationImpl*>( |
| 62 service_worker_registration) | 66 service_worker_registration) |
| 63 ->registration_id(); | 67 ->registration_id(); |
| 64 | 68 |
| 65 if (manifest.IsEmpty()) { | 69 PushSubscriptionOptions content_options; |
| 66 OnSubscribeFromDocumentError( | 70 content_options.user_visible_only = options.userVisibleOnly; |
| 67 request_id, PUSH_REGISTRATION_STATUS_MANIFEST_EMPTY_OR_MISSING); | |
| 68 return; | |
| 69 } | |
| 70 | 71 |
| 71 std::string sender_id = | 72 // If a public key isn't provided by the client, fall back to the |
| 72 manifest.gcm_sender_id.is_null() | 73 // sender_id specification. |
| 73 ? std::string() | 74 if (options.applicationServerKey.isEmpty()) { |
| 74 : base::UTF16ToUTF8(manifest.gcm_sender_id.string()); | 75 if (manifest.IsEmpty()) { |
| 75 if (sender_id.empty()) { | 76 OnSubscribeFromDocumentError( |
| 76 OnSubscribeFromDocumentError(request_id, | 77 request_id, PUSH_REGISTRATION_STATUS_MANIFEST_EMPTY_OR_MISSING); |
| 77 PUSH_REGISTRATION_STATUS_NO_SENDER_ID); | 78 return; |
| 78 return; | 79 } |
| 80 | |
| 81 content_options.using_public_key = false; | |
| 82 content_options.sender_info = | |
| 83 manifest.gcm_sender_id.is_null() | |
| 84 ? std::string() | |
| 85 : base::UTF16ToUTF8(manifest.gcm_sender_id.string()); | |
| 86 if (content_options.sender_info.empty()) { | |
| 87 OnSubscribeFromDocumentError(request_id, | |
| 88 PUSH_REGISTRATION_STATUS_NO_SENDER_ID); | |
| 89 return; | |
| 90 } | |
| 91 } else { | |
| 92 content_options.using_public_key = true; | |
| 93 content_options.sender_info = options.applicationServerKey.utf8(); | |
| 94 | |
| 95 // 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.
| |
| 96 // format and reject with InvalidAccessError if invalid. | |
| 79 } | 97 } |
| 80 | 98 |
| 81 Send(new PushMessagingHostMsg_SubscribeFromDocument( | 99 Send(new PushMessagingHostMsg_SubscribeFromDocument( |
| 82 routing_id(), request_id, | 100 routing_id(), request_id, content_options, |
| 83 manifest.gcm_sender_id.is_null() | 101 service_worker_registration_id)); |
| 84 ? std::string() | |
| 85 : base::UTF16ToUTF8(manifest.gcm_sender_id.string()), | |
| 86 options.userVisibleOnly, service_worker_registration_id)); | |
| 87 } | 102 } |
| 88 | 103 |
| 89 void PushMessagingDispatcher::OnSubscribeFromDocumentSuccess( | 104 void PushMessagingDispatcher::OnSubscribeFromDocumentSuccess( |
| 90 int32_t request_id, | 105 int32_t request_id, |
| 91 const GURL& endpoint, | 106 const GURL& endpoint, |
| 92 const std::vector<uint8_t>& p256dh, | 107 const std::vector<uint8_t>& p256dh, |
| 93 const std::vector<uint8_t>& auth) { | 108 const std::vector<uint8_t>& auth) { |
| 94 blink::WebPushSubscriptionCallbacks* callbacks = | 109 blink::WebPushSubscriptionCallbacks* callbacks = |
| 95 subscription_callbacks_.Lookup(request_id); | 110 subscription_callbacks_.Lookup(request_id); |
| 96 DCHECK(callbacks); | 111 DCHECK(callbacks); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 114 : blink::WebPushError::ErrorTypeAbort; | 129 : blink::WebPushError::ErrorTypeAbort; |
| 115 | 130 |
| 116 callbacks->onError(blink::WebPushError( | 131 callbacks->onError(blink::WebPushError( |
| 117 error_type, | 132 error_type, |
| 118 blink::WebString::fromUTF8(PushRegistrationStatusToString(status)))); | 133 blink::WebString::fromUTF8(PushRegistrationStatusToString(status)))); |
| 119 | 134 |
| 120 subscription_callbacks_.Remove(request_id); | 135 subscription_callbacks_.Remove(request_id); |
| 121 } | 136 } |
| 122 | 137 |
| 123 } // namespace content | 138 } // namespace content |
| OLD | NEW |