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/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 8 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
9 #include "content/common/push_messaging_messages.h" | 9 #include "content/common/push_messaging_messages.h" |
10 #include "content/renderer/manifest/manifest_manager.h" | 10 #include "content/renderer/manifest/manifest_manager.h" |
11 #include "content/renderer/render_frame_impl.h" | 11 #include "content/renderer/render_frame_impl.h" |
12 #include "ipc/ipc_message.h" | 12 #include "ipc/ipc_message.h" |
13 #include "third_party/WebKit/public/platform/WebServiceWorkerRegistration.h" | 13 #include "third_party/WebKit/public/platform/WebServiceWorkerRegistration.h" |
14 #include "third_party/WebKit/public/platform/WebString.h" | 14 #include "third_party/WebKit/public/platform/WebString.h" |
15 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushError
.h" | 15 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushError
.h" |
16 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc
ription.h" | 16 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc
ription.h" |
17 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc
riptionOptions.h" | 17 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc
riptionOptions.h" |
18 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 18 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
19 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 19 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
20 #include "url/gurl.h" | 20 #include "url/gurl.h" |
21 | 21 |
22 using blink::WebString; | |
23 | |
24 namespace content { | 22 namespace content { |
25 | 23 |
26 PushMessagingDispatcher::PushMessagingDispatcher(RenderFrame* render_frame) | 24 PushMessagingDispatcher::PushMessagingDispatcher(RenderFrame* render_frame) |
27 : RenderFrameObserver(render_frame) { | 25 : RenderFrameObserver(render_frame) { |
28 } | 26 } |
29 | 27 |
30 PushMessagingDispatcher::~PushMessagingDispatcher() {} | 28 PushMessagingDispatcher::~PushMessagingDispatcher() {} |
31 | 29 |
32 bool PushMessagingDispatcher::OnMessageReceived(const IPC::Message& message) { | 30 bool PushMessagingDispatcher::OnMessageReceived(const IPC::Message& message) { |
33 bool handled = true; | 31 bool handled = true; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 Send(new PushMessagingHostMsg_SubscribeFromDocument( | 77 Send(new PushMessagingHostMsg_SubscribeFromDocument( |
80 routing_id(), request_id, | 78 routing_id(), request_id, |
81 manifest.gcm_sender_id.is_null() | 79 manifest.gcm_sender_id.is_null() |
82 ? std::string() | 80 ? std::string() |
83 : base::UTF16ToUTF8(manifest.gcm_sender_id.string()), | 81 : base::UTF16ToUTF8(manifest.gcm_sender_id.string()), |
84 options.userVisibleOnly, service_worker_registration_id)); | 82 options.userVisibleOnly, service_worker_registration_id)); |
85 } | 83 } |
86 | 84 |
87 void PushMessagingDispatcher::OnSubscribeFromDocumentSuccess( | 85 void PushMessagingDispatcher::OnSubscribeFromDocumentSuccess( |
88 int32_t request_id, | 86 int32_t request_id, |
89 const GURL& endpoint, | 87 const GURL& endpoint) { |
90 const std::string& subscription_id) { | |
91 blink::WebPushSubscriptionCallbacks* callbacks = | 88 blink::WebPushSubscriptionCallbacks* callbacks = |
92 subscription_callbacks_.Lookup(request_id); | 89 subscription_callbacks_.Lookup(request_id); |
93 | 90 |
94 // TODO(peter): Change this back to a DCHECK before M45 branches. | 91 // TODO(peter): Change this back to a DCHECK before M45 branches. |
95 CHECK(callbacks) << "Invalid request id received: " << request_id; | 92 CHECK(callbacks) << "Invalid request id received: " << request_id; |
96 | 93 |
97 scoped_ptr<blink::WebPushSubscription> subscription( | 94 scoped_ptr<blink::WebPushSubscription> subscription( |
98 new blink::WebPushSubscription( | 95 new blink::WebPushSubscription(endpoint)); |
99 WebString::fromUTF8(endpoint.spec()), | |
100 WebString::fromUTF8(subscription_id))); | |
101 callbacks->onSuccess(subscription.release()); | 96 callbacks->onSuccess(subscription.release()); |
102 | 97 |
103 subscription_callbacks_.Remove(request_id); | 98 subscription_callbacks_.Remove(request_id); |
104 } | 99 } |
105 | 100 |
106 void PushMessagingDispatcher::OnSubscribeFromDocumentError( | 101 void PushMessagingDispatcher::OnSubscribeFromDocumentError( |
107 int32_t request_id, | 102 int32_t request_id, |
108 PushRegistrationStatus status) { | 103 PushRegistrationStatus status) { |
109 blink::WebPushSubscriptionCallbacks* callbacks = | 104 blink::WebPushSubscriptionCallbacks* callbacks = |
110 subscription_callbacks_.Lookup(request_id); | 105 subscription_callbacks_.Lookup(request_id); |
111 | 106 |
112 // TODO(peter): Change this back to a DCHECK before M45 branches. | 107 // TODO(peter): Change this back to a DCHECK before M45 branches. |
113 CHECK(callbacks) << "Invalid request id received: " << request_id; | 108 CHECK(callbacks) << "Invalid request id received: " << request_id; |
114 | 109 |
115 scoped_ptr<blink::WebPushError> error(new blink::WebPushError( | 110 scoped_ptr<blink::WebPushError> error(new blink::WebPushError( |
116 blink::WebPushError::ErrorTypeAbort, | 111 blink::WebPushError::ErrorTypeAbort, |
117 WebString::fromUTF8(PushRegistrationStatusToString(status)))); | 112 blink::WebString::fromUTF8(PushRegistrationStatusToString(status)))); |
118 callbacks->onError(error.release()); | 113 callbacks->onError(error.release()); |
119 | 114 |
120 subscription_callbacks_.Remove(request_id); | 115 subscription_callbacks_.Remove(request_id); |
121 } | 116 } |
122 | 117 |
123 } // namespace content | 118 } // namespace content |
OLD | NEW |