| 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 <memory> |
| 8 #include <utility> |
| 9 |
| 7 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 9 #include "content/child/push_messaging/push_provider.h" | 12 #include "content/child/push_messaging/push_provider.h" |
| 10 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 13 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
| 11 #include "content/common/push_messaging_messages.h" | 14 #include "content/common/push_messaging_messages.h" |
| 12 #include "content/renderer/manifest/manifest_manager.h" | 15 #include "content/renderer/manifest/manifest_manager.h" |
| 13 #include "content/renderer/render_frame_impl.h" | 16 #include "content/renderer/render_frame_impl.h" |
| 14 #include "ipc/ipc_message.h" | 17 #include "ipc/ipc_message.h" |
| 15 #include "third_party/WebKit/public/platform/WebString.h" | 18 #include "third_party/WebKit/public/platform/WebString.h" |
| 16 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushError
.h" | 19 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushError
.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 40 return handled; | 43 return handled; |
| 41 } | 44 } |
| 42 | 45 |
| 43 void PushMessagingDispatcher::OnDestruct() { | 46 void PushMessagingDispatcher::OnDestruct() { |
| 44 delete this; | 47 delete this; |
| 45 } | 48 } |
| 46 | 49 |
| 47 void PushMessagingDispatcher::subscribe( | 50 void PushMessagingDispatcher::subscribe( |
| 48 blink::WebServiceWorkerRegistration* service_worker_registration, | 51 blink::WebServiceWorkerRegistration* service_worker_registration, |
| 49 const blink::WebPushSubscriptionOptions& options, | 52 const blink::WebPushSubscriptionOptions& options, |
| 50 blink::WebPushSubscriptionCallbacks* callbacks) { | 53 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks) { |
| 51 DCHECK(service_worker_registration); | 54 DCHECK(service_worker_registration); |
| 52 DCHECK(callbacks); | 55 DCHECK(callbacks); |
| 53 // If a developer provided an application server key in |options|, skip | 56 // If a developer provided an application server key in |options|, skip |
| 54 // fetching the manifest. | 57 // fetching the manifest. |
| 55 if (options.applicationServerKey.isEmpty()) { | 58 if (options.applicationServerKey.isEmpty()) { |
| 56 RenderFrameImpl::FromRoutingID(routing_id()) | 59 RenderFrameImpl::FromRoutingID(routing_id()) |
| 57 ->manifest_manager() | 60 ->manifest_manager() |
| 58 ->GetManifest(base::Bind( | 61 ->GetManifest(base::Bind( |
| 59 &PushMessagingDispatcher::DidGetManifest, base::Unretained(this), | 62 &PushMessagingDispatcher::DidGetManifest, base::Unretained(this), |
| 60 service_worker_registration, options, callbacks)); | 63 service_worker_registration, options, base::Passed(&callbacks))); |
| 61 } else { | 64 } else { |
| 62 PushSubscriptionOptions content_options; | 65 PushSubscriptionOptions content_options; |
| 63 content_options.user_visible_only = options.userVisibleOnly; | 66 content_options.user_visible_only = options.userVisibleOnly; |
| 64 // Just treat the server key as a string of bytes and pass it to the push | 67 // Just treat the server key as a string of bytes and pass it to the push |
| 65 // service. | 68 // service. |
| 66 content_options.sender_info = options.applicationServerKey.latin1(); | 69 content_options.sender_info = options.applicationServerKey.latin1(); |
| 67 DoSubscribe(service_worker_registration, content_options, callbacks); | 70 DoSubscribe(service_worker_registration, content_options, |
| 71 std::move(callbacks)); |
| 68 } | 72 } |
| 69 } | 73 } |
| 70 | 74 |
| 71 void PushMessagingDispatcher::DidGetManifest( | 75 void PushMessagingDispatcher::DidGetManifest( |
| 72 blink::WebServiceWorkerRegistration* service_worker_registration, | 76 blink::WebServiceWorkerRegistration* service_worker_registration, |
| 73 const blink::WebPushSubscriptionOptions& options, | 77 const blink::WebPushSubscriptionOptions& options, |
| 74 blink::WebPushSubscriptionCallbacks* callbacks, | 78 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks, |
| 75 const GURL& manifest_url, | 79 const GURL& manifest_url, |
| 76 const Manifest& manifest, | 80 const Manifest& manifest, |
| 77 const ManifestDebugInfo&) { | 81 const ManifestDebugInfo&) { |
| 78 // Get the sender_info from the manifest since it wasn't provided by | 82 // Get the sender_info from the manifest since it wasn't provided by |
| 79 // the caller. | 83 // the caller. |
| 80 if (manifest.IsEmpty()) { | 84 if (manifest.IsEmpty()) { |
| 81 int request_id = subscription_callbacks_.Add(callbacks); | 85 int request_id = subscription_callbacks_.Add(std::move(callbacks)); |
| 82 OnSubscribeFromDocumentError( | 86 OnSubscribeFromDocumentError( |
| 83 request_id, PUSH_REGISTRATION_STATUS_MANIFEST_EMPTY_OR_MISSING); | 87 request_id, PUSH_REGISTRATION_STATUS_MANIFEST_EMPTY_OR_MISSING); |
| 84 return; | 88 return; |
| 85 } | 89 } |
| 86 | 90 |
| 87 PushSubscriptionOptions content_options; | 91 PushSubscriptionOptions content_options; |
| 88 content_options.user_visible_only = options.userVisibleOnly; | 92 content_options.user_visible_only = options.userVisibleOnly; |
| 89 if (!manifest.gcm_sender_id.is_null()) { | 93 if (!manifest.gcm_sender_id.is_null()) { |
| 90 content_options.sender_info = | 94 content_options.sender_info = |
| 91 base::UTF16ToUTF8(manifest.gcm_sender_id.string()); | 95 base::UTF16ToUTF8(manifest.gcm_sender_id.string()); |
| 92 } | 96 } |
| 93 | 97 |
| 94 DoSubscribe(service_worker_registration, content_options, callbacks); | 98 DoSubscribe(service_worker_registration, content_options, |
| 99 std::move(callbacks)); |
| 95 } | 100 } |
| 96 | 101 |
| 97 void PushMessagingDispatcher::DoSubscribe( | 102 void PushMessagingDispatcher::DoSubscribe( |
| 98 blink::WebServiceWorkerRegistration* service_worker_registration, | 103 blink::WebServiceWorkerRegistration* service_worker_registration, |
| 99 const PushSubscriptionOptions& options, | 104 const PushSubscriptionOptions& options, |
| 100 blink::WebPushSubscriptionCallbacks* callbacks) { | 105 std::unique_ptr<blink::WebPushSubscriptionCallbacks> callbacks) { |
| 101 int request_id = subscription_callbacks_.Add(callbacks); | 106 int request_id = subscription_callbacks_.Add(std::move(callbacks)); |
| 102 int64_t service_worker_registration_id = | 107 int64_t service_worker_registration_id = |
| 103 static_cast<WebServiceWorkerRegistrationImpl*>( | 108 static_cast<WebServiceWorkerRegistrationImpl*>( |
| 104 service_worker_registration) | 109 service_worker_registration) |
| 105 ->registrationId(); | 110 ->registrationId(); |
| 106 | 111 |
| 107 if (options.sender_info.empty()) { | 112 if (options.sender_info.empty()) { |
| 108 OnSubscribeFromDocumentError(request_id, | 113 OnSubscribeFromDocumentError(request_id, |
| 109 PUSH_REGISTRATION_STATUS_NO_SENDER_ID); | 114 PUSH_REGISTRATION_STATUS_NO_SENDER_ID); |
| 110 return; | 115 return; |
| 111 } | 116 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 136 blink::WebPushSubscriptionCallbacks* callbacks = | 141 blink::WebPushSubscriptionCallbacks* callbacks = |
| 137 subscription_callbacks_.Lookup(request_id); | 142 subscription_callbacks_.Lookup(request_id); |
| 138 DCHECK(callbacks); | 143 DCHECK(callbacks); |
| 139 | 144 |
| 140 callbacks->onError(PushRegistrationStatusToWebPushError(status)); | 145 callbacks->onError(PushRegistrationStatusToWebPushError(status)); |
| 141 | 146 |
| 142 subscription_callbacks_.Remove(request_id); | 147 subscription_callbacks_.Remove(request_id); |
| 143 } | 148 } |
| 144 | 149 |
| 145 } // namespace content | 150 } // namespace content |
| OLD | NEW |