| 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 |
| 7 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 9 #include "content/child/push_messaging/push_provider.h" | 11 #include "content/child/push_messaging/push_provider.h" |
| 10 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 12 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
| 11 #include "content/common/push_messaging_messages.h" | 13 #include "content/common/push_messaging_messages.h" |
| 12 #include "content/renderer/manifest/manifest_manager.h" | 14 #include "content/renderer/manifest/manifest_manager.h" |
| 13 #include "content/renderer/render_frame_impl.h" | 15 #include "content/renderer/render_frame_impl.h" |
| 14 #include "ipc/ipc_message.h" | 16 #include "ipc/ipc_message.h" |
| 15 #include "third_party/WebKit/public/platform/WebString.h" | 17 #include "third_party/WebKit/public/platform/WebString.h" |
| 16 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushError
.h" | 18 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushError
.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 void PushMessagingDispatcher::DidGetManifest( | 73 void PushMessagingDispatcher::DidGetManifest( |
| 72 blink::WebServiceWorkerRegistration* service_worker_registration, | 74 blink::WebServiceWorkerRegistration* service_worker_registration, |
| 73 const blink::WebPushSubscriptionOptions& options, | 75 const blink::WebPushSubscriptionOptions& options, |
| 74 blink::WebPushSubscriptionCallbacks* callbacks, | 76 blink::WebPushSubscriptionCallbacks* callbacks, |
| 75 const GURL& manifest_url, | 77 const GURL& manifest_url, |
| 76 const Manifest& manifest, | 78 const Manifest& manifest, |
| 77 const ManifestDebugInfo&) { | 79 const ManifestDebugInfo&) { |
| 78 // Get the sender_info from the manifest since it wasn't provided by | 80 // Get the sender_info from the manifest since it wasn't provided by |
| 79 // the caller. | 81 // the caller. |
| 80 if (manifest.IsEmpty()) { | 82 if (manifest.IsEmpty()) { |
| 81 int request_id = subscription_callbacks_.Add(callbacks); | 83 int request_id = subscription_callbacks_.Add( |
| 84 std::unique_ptr<blink::WebPushSubscriptionCallbacks>(callbacks)); |
| 82 OnSubscribeFromDocumentError( | 85 OnSubscribeFromDocumentError( |
| 83 request_id, PUSH_REGISTRATION_STATUS_MANIFEST_EMPTY_OR_MISSING); | 86 request_id, PUSH_REGISTRATION_STATUS_MANIFEST_EMPTY_OR_MISSING); |
| 84 return; | 87 return; |
| 85 } | 88 } |
| 86 | 89 |
| 87 PushSubscriptionOptions content_options; | 90 PushSubscriptionOptions content_options; |
| 88 content_options.user_visible_only = options.userVisibleOnly; | 91 content_options.user_visible_only = options.userVisibleOnly; |
| 89 if (!manifest.gcm_sender_id.is_null()) { | 92 if (!manifest.gcm_sender_id.is_null()) { |
| 90 content_options.sender_info = | 93 content_options.sender_info = |
| 91 base::UTF16ToUTF8(manifest.gcm_sender_id.string()); | 94 base::UTF16ToUTF8(manifest.gcm_sender_id.string()); |
| 92 } | 95 } |
| 93 | 96 |
| 94 DoSubscribe(service_worker_registration, content_options, callbacks); | 97 DoSubscribe(service_worker_registration, content_options, callbacks); |
| 95 } | 98 } |
| 96 | 99 |
| 97 void PushMessagingDispatcher::DoSubscribe( | 100 void PushMessagingDispatcher::DoSubscribe( |
| 98 blink::WebServiceWorkerRegistration* service_worker_registration, | 101 blink::WebServiceWorkerRegistration* service_worker_registration, |
| 99 const PushSubscriptionOptions& options, | 102 const PushSubscriptionOptions& options, |
| 100 blink::WebPushSubscriptionCallbacks* callbacks) { | 103 blink::WebPushSubscriptionCallbacks* callbacks) { |
| 101 int request_id = subscription_callbacks_.Add(callbacks); | 104 int request_id = subscription_callbacks_.Add( |
| 105 std::unique_ptr<blink::WebPushSubscriptionCallbacks>(callbacks)); |
| 102 int64_t service_worker_registration_id = | 106 int64_t service_worker_registration_id = |
| 103 static_cast<WebServiceWorkerRegistrationImpl*>( | 107 static_cast<WebServiceWorkerRegistrationImpl*>( |
| 104 service_worker_registration) | 108 service_worker_registration) |
| 105 ->registration_id(); | 109 ->registration_id(); |
| 106 | 110 |
| 107 if (options.sender_info.empty()) { | 111 if (options.sender_info.empty()) { |
| 108 OnSubscribeFromDocumentError(request_id, | 112 OnSubscribeFromDocumentError(request_id, |
| 109 PUSH_REGISTRATION_STATUS_NO_SENDER_ID); | 113 PUSH_REGISTRATION_STATUS_NO_SENDER_ID); |
| 110 return; | 114 return; |
| 111 } | 115 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 136 blink::WebPushSubscriptionCallbacks* callbacks = | 140 blink::WebPushSubscriptionCallbacks* callbacks = |
| 137 subscription_callbacks_.Lookup(request_id); | 141 subscription_callbacks_.Lookup(request_id); |
| 138 DCHECK(callbacks); | 142 DCHECK(callbacks); |
| 139 | 143 |
| 140 callbacks->onError(PushRegistrationStatusToWebPushError(status)); | 144 callbacks->onError(PushRegistrationStatusToWebPushError(status)); |
| 141 | 145 |
| 142 subscription_callbacks_.Remove(request_id); | 146 subscription_callbacks_.Remove(request_id); |
| 143 } | 147 } |
| 144 | 148 |
| 145 } // namespace content | 149 } // namespace content |
| OLD | NEW |