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 "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "content/child/service_worker/web_service_worker_provider_impl.h" | 8 #include "content/child/service_worker/web_service_worker_provider_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" |
(...skipping 14 matching lines...) Expand all Loading... |
25 : RenderFrameObserver(render_frame) { | 25 : RenderFrameObserver(render_frame) { |
26 } | 26 } |
27 | 27 |
28 PushMessagingDispatcher::~PushMessagingDispatcher() {} | 28 PushMessagingDispatcher::~PushMessagingDispatcher() {} |
29 | 29 |
30 bool PushMessagingDispatcher::OnMessageReceived(const IPC::Message& message) { | 30 bool PushMessagingDispatcher::OnMessageReceived(const IPC::Message& message) { |
31 bool handled = true; | 31 bool handled = true; |
32 IPC_BEGIN_MESSAGE_MAP(PushMessagingDispatcher, message) | 32 IPC_BEGIN_MESSAGE_MAP(PushMessagingDispatcher, message) |
33 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterSuccess, OnRegisterSuccess) | 33 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterSuccess, OnRegisterSuccess) |
34 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterError, OnRegisterError) | 34 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterError, OnRegisterError) |
| 35 IPC_MESSAGE_HANDLER(PushMessagingMsg_PermissionStatusResult, |
| 36 OnPermissionStatus) |
| 37 IPC_MESSAGE_HANDLER(PushMessagingMsg_PermissionStatusFailure, |
| 38 OnPermissionStatusFailure) |
| 39 |
35 IPC_MESSAGE_UNHANDLED(handled = false) | 40 IPC_MESSAGE_UNHANDLED(handled = false) |
36 IPC_END_MESSAGE_MAP() | 41 IPC_END_MESSAGE_MAP() |
37 return handled; | 42 return handled; |
38 } | 43 } |
39 | 44 |
40 void PushMessagingDispatcher::registerPushMessaging( | 45 void PushMessagingDispatcher::registerPushMessaging( |
41 blink::WebPushRegistrationCallbacks* callbacks, | 46 blink::WebPushRegistrationCallbacks* callbacks, |
42 blink::WebServiceWorkerProvider* service_worker_provider) { | 47 blink::WebServiceWorkerProvider* service_worker_provider) { |
43 RenderFrameImpl::FromRoutingID(routing_id())->manifest_manager()->GetManifest( | 48 RenderFrameImpl::FromRoutingID(routing_id())->manifest_manager()->GetManifest( |
44 base::Bind(&PushMessagingDispatcher::DoRegister, | 49 base::Bind(&PushMessagingDispatcher::DoRegister, |
(...skipping 14 matching lines...) Expand all Loading... |
59 std::string sender_id = manifest.gcm_sender_id.is_null() | 64 std::string sender_id = manifest.gcm_sender_id.is_null() |
60 ? std::string() : base::UTF16ToUTF8(manifest.gcm_sender_id.string()); | 65 ? std::string() : base::UTF16ToUTF8(manifest.gcm_sender_id.string()); |
61 if (sender_id.empty()) { | 66 if (sender_id.empty()) { |
62 OnRegisterError(callbacks_id, PUSH_REGISTRATION_STATUS_NO_SENDER_ID); | 67 OnRegisterError(callbacks_id, PUSH_REGISTRATION_STATUS_NO_SENDER_ID); |
63 return; | 68 return; |
64 } | 69 } |
65 | 70 |
66 Send(new PushMessagingHostMsg_Register( | 71 Send(new PushMessagingHostMsg_Register( |
67 routing_id(), | 72 routing_id(), |
68 callbacks_id, | 73 callbacks_id, |
69 sender_id, | 74 manifest.gcm_sender_id.is_null() |
| 75 ? std::string() |
| 76 : base::UTF16ToUTF8(manifest.gcm_sender_id.string()), |
70 blink::WebUserGestureIndicator::isProcessingUserGesture(), | 77 blink::WebUserGestureIndicator::isProcessingUserGesture(), |
71 service_worker_provider_id)); | 78 service_worker_provider_id)); |
72 } | 79 } |
73 | 80 |
| 81 void PushMessagingDispatcher::getPermissionStatus( |
| 82 blink::WebPushPermissionCallback* callback, |
| 83 blink::WebServiceWorkerProvider* service_worker_provider) { |
| 84 int permission_callback_id = permission_check_callbacks_.Add(callback); |
| 85 int service_worker_provider_id = static_cast<WebServiceWorkerProviderImpl*>( |
| 86 service_worker_provider)->provider_id(); |
| 87 Send(new PushMessagingHostMsg_PermissionStatus( |
| 88 routing_id(), service_worker_provider_id, permission_callback_id)); |
| 89 } |
| 90 |
74 void PushMessagingDispatcher::OnRegisterSuccess( | 91 void PushMessagingDispatcher::OnRegisterSuccess( |
75 int32 callbacks_id, | 92 int32 callbacks_id, |
76 const GURL& endpoint, | 93 const GURL& endpoint, |
77 const std::string& registration_id) { | 94 const std::string& registration_id) { |
78 blink::WebPushRegistrationCallbacks* callbacks = | 95 blink::WebPushRegistrationCallbacks* callbacks = |
79 registration_callbacks_.Lookup(callbacks_id); | 96 registration_callbacks_.Lookup(callbacks_id); |
80 CHECK(callbacks); | 97 CHECK(callbacks); |
81 | 98 |
82 scoped_ptr<blink::WebPushRegistration> registration( | 99 scoped_ptr<blink::WebPushRegistration> registration( |
83 new blink::WebPushRegistration( | 100 new blink::WebPushRegistration( |
84 WebString::fromUTF8(endpoint.spec()), | 101 WebString::fromUTF8(endpoint.spec()), |
85 WebString::fromUTF8(registration_id))); | 102 WebString::fromUTF8(registration_id))); |
86 callbacks->onSuccess(registration.release()); | 103 callbacks->onSuccess(registration.release()); |
87 registration_callbacks_.Remove(callbacks_id); | 104 registration_callbacks_.Remove(callbacks_id); |
88 } | 105 } |
89 | 106 |
90 void PushMessagingDispatcher::OnRegisterError(int32 callbacks_id, | 107 void PushMessagingDispatcher::OnRegisterError(int32 callbacks_id, |
91 PushRegistrationStatus status) { | 108 PushRegistrationStatus status) { |
92 blink::WebPushRegistrationCallbacks* callbacks = | 109 blink::WebPushRegistrationCallbacks* callbacks = |
93 registration_callbacks_.Lookup(callbacks_id); | 110 registration_callbacks_.Lookup(callbacks_id); |
94 CHECK(callbacks); | 111 CHECK(callbacks); |
95 | 112 |
96 scoped_ptr<blink::WebPushError> error(new blink::WebPushError( | 113 scoped_ptr<blink::WebPushError> error(new blink::WebPushError( |
97 blink::WebPushError::ErrorTypeAbort, | 114 blink::WebPushError::ErrorTypeAbort, |
98 WebString::fromUTF8(PushRegistrationStatusToString(status)))); | 115 WebString::fromUTF8(PushRegistrationStatusToString(status)))); |
99 callbacks->onError(error.release()); | 116 callbacks->onError(error.release()); |
100 registration_callbacks_.Remove(callbacks_id); | 117 registration_callbacks_.Remove(callbacks_id); |
101 } | 118 } |
102 | 119 |
| 120 void PushMessagingDispatcher::OnPermissionStatus( |
| 121 int32 callback_id, |
| 122 blink::WebPushPermissionStatus status) { |
| 123 blink::WebPushPermissionCallback* callback = |
| 124 permission_check_callbacks_.Lookup(callback_id); |
| 125 callback->onSuccess(&status); |
| 126 permission_check_callbacks_.Remove(callback_id); |
| 127 } |
| 128 |
| 129 void PushMessagingDispatcher::OnPermissionStatusFailure(int32 callback_id) { |
| 130 blink::WebPushPermissionCallback* callback = |
| 131 permission_check_callbacks_.Lookup(callback_id); |
| 132 callback->onError(); |
| 133 permission_check_callbacks_.Remove(callback_id); |
| 134 } |
| 135 |
103 } // namespace content | 136 } // namespace content |
OLD | NEW |