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_dispatcher.h" | 5 #include "content/renderer/push_messaging_dispatcher.h" |
6 | 6 |
7 #include "content/child/service_worker/web_service_worker_provider_impl.h" | 7 #include "content/child/service_worker/web_service_worker_provider_impl.h" |
8 #include "content/common/push_messaging_messages.h" | 8 #include "content/common/push_messaging_messages.h" |
9 #include "ipc/ipc_message.h" | 9 #include "ipc/ipc_message.h" |
10 #include "third_party/WebKit/public/platform/WebPushError.h" | 10 #include "third_party/WebKit/public/platform/WebPushError.h" |
11 #include "third_party/WebKit/public/platform/WebPushRegistration.h" | 11 #include "third_party/WebKit/public/platform/WebPushRegistration.h" |
12 #include "third_party/WebKit/public/platform/WebServiceWorkerProvider.h" | 12 #include "third_party/WebKit/public/platform/WebServiceWorkerProvider.h" |
13 #include "third_party/WebKit/public/platform/WebString.h" | 13 #include "third_party/WebKit/public/platform/WebString.h" |
14 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 14 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
16 | 16 |
17 using blink::WebString; | 17 using blink::WebString; |
18 | 18 |
19 namespace { | |
20 const char kAbortErrorReason[] = "Registration failed."; | |
21 } | |
22 | |
23 namespace content { | 19 namespace content { |
24 | 20 |
25 PushMessagingDispatcher::PushMessagingDispatcher(RenderFrame* render_frame) | 21 PushMessagingDispatcher::PushMessagingDispatcher(RenderFrame* render_frame) |
26 : RenderFrameObserver(render_frame) { | 22 : RenderFrameObserver(render_frame) { |
27 } | 23 } |
28 | 24 |
29 PushMessagingDispatcher::~PushMessagingDispatcher() {} | 25 PushMessagingDispatcher::~PushMessagingDispatcher() {} |
30 | 26 |
31 bool PushMessagingDispatcher::OnMessageReceived(const IPC::Message& message) { | 27 bool PushMessagingDispatcher::OnMessageReceived(const IPC::Message& message) { |
32 bool handled = true; | 28 bool handled = true; |
33 IPC_BEGIN_MESSAGE_MAP(PushMessagingDispatcher, message) | 29 IPC_BEGIN_MESSAGE_MAP(PushMessagingDispatcher, message) |
34 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterSuccess, OnRegisterSuccess) | 30 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterSuccess, OnRegisterSuccess) |
35 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterError, OnRegisterError) | 31 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterError, OnRegisterError) |
36 IPC_MESSAGE_UNHANDLED(handled = false) | 32 IPC_MESSAGE_UNHANDLED(handled = false) |
37 IPC_END_MESSAGE_MAP() | 33 IPC_END_MESSAGE_MAP() |
38 return handled; | 34 return handled; |
39 } | 35 } |
40 | 36 |
41 void PushMessagingDispatcher::registerPushMessaging( | 37 void PushMessagingDispatcher::registerPushMessaging( |
42 const WebString& sender_id, | 38 const WebString& sender_id, |
43 blink::WebPushRegistrationCallbacks* callbacks) { | 39 blink::WebPushRegistrationCallbacks* callbacks) { |
44 DCHECK(callbacks); | 40 DCHECK(callbacks); |
45 scoped_ptr<blink::WebPushError> error( | 41 scoped_ptr<blink::WebPushError> error(new blink::WebPushError( |
46 new blink::WebPushError(blink::WebPushError::ErrorTypeAbort, | 42 blink::WebPushError::ErrorTypeAbort, |
47 WebString::fromUTF8(kAbortErrorReason))); | 43 WebString::fromUTF8(PushMessagingStatusToString( |
| 44 PUSH_MESSAGING_STATUS_REGISTRATION_FAILED_NO_SERVICE_WORKER)))); |
48 callbacks->onError(error.release()); | 45 callbacks->onError(error.release()); |
49 delete callbacks; | 46 delete callbacks; |
50 } | 47 } |
51 | 48 |
52 void PushMessagingDispatcher::registerPushMessaging( | 49 void PushMessagingDispatcher::registerPushMessaging( |
53 const WebString& sender_id, | 50 const WebString& sender_id, |
54 blink::WebPushRegistrationCallbacks* callbacks, | 51 blink::WebPushRegistrationCallbacks* callbacks, |
55 blink::WebServiceWorkerProvider* service_worker_provider) { | 52 blink::WebServiceWorkerProvider* service_worker_provider) { |
56 DCHECK(callbacks); | 53 DCHECK(callbacks); |
57 int callbacks_id = registration_callbacks_.Add(callbacks); | 54 int callbacks_id = registration_callbacks_.Add(callbacks); |
(...skipping 16 matching lines...) Expand all Loading... |
74 CHECK(callbacks); | 71 CHECK(callbacks); |
75 | 72 |
76 scoped_ptr<blink::WebPushRegistration> registration( | 73 scoped_ptr<blink::WebPushRegistration> registration( |
77 new blink::WebPushRegistration( | 74 new blink::WebPushRegistration( |
78 WebString::fromUTF8(endpoint.spec()), | 75 WebString::fromUTF8(endpoint.spec()), |
79 WebString::fromUTF8(registration_id))); | 76 WebString::fromUTF8(registration_id))); |
80 callbacks->onSuccess(registration.release()); | 77 callbacks->onSuccess(registration.release()); |
81 registration_callbacks_.Remove(callbacks_id); | 78 registration_callbacks_.Remove(callbacks_id); |
82 } | 79 } |
83 | 80 |
84 void PushMessagingDispatcher::OnRegisterError(int32 callbacks_id) { | 81 void PushMessagingDispatcher::OnRegisterError(int32 callbacks_id, |
| 82 PushMessagingStatus status) { |
85 blink::WebPushRegistrationCallbacks* callbacks = | 83 blink::WebPushRegistrationCallbacks* callbacks = |
86 registration_callbacks_.Lookup(callbacks_id); | 84 registration_callbacks_.Lookup(callbacks_id); |
87 CHECK(callbacks); | 85 CHECK(callbacks); |
88 | 86 |
89 scoped_ptr<blink::WebPushError> error( | 87 scoped_ptr<blink::WebPushError> error(new blink::WebPushError( |
90 new blink::WebPushError( | 88 blink::WebPushError::ErrorTypeAbort, |
91 blink::WebPushError::ErrorTypeAbort, | 89 WebString::fromUTF8(PushMessagingStatusToString(status)))); |
92 WebString::fromUTF8(kAbortErrorReason))); | |
93 callbacks->onError(error.release()); | 90 callbacks->onError(error.release()); |
94 registration_callbacks_.Remove(callbacks_id); | 91 registration_callbacks_.Remove(callbacks_id); |
95 } | 92 } |
96 | 93 |
97 } // namespace content | 94 } // namespace content |
OLD | NEW |