| 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 |
| 35 IPC_MESSAGE_UNHANDLED(handled = false) | 38 IPC_MESSAGE_UNHANDLED(handled = false) |
| 36 IPC_END_MESSAGE_MAP() | 39 IPC_END_MESSAGE_MAP() |
| 37 return handled; | 40 return handled; |
| 38 } | 41 } |
| 39 | 42 |
| 40 void PushMessagingDispatcher::registerPushMessaging( | 43 void PushMessagingDispatcher::registerPushMessaging( |
| 41 const WebString& sender_id, | 44 const WebString& sender_id, |
| 42 blink::WebPushRegistrationCallbacks* callbacks, | 45 blink::WebPushRegistrationCallbacks* callbacks, |
| 43 blink::WebServiceWorkerProvider* service_worker_provider) { | 46 blink::WebServiceWorkerProvider* service_worker_provider) { |
| 44 RenderFrameImpl::FromRoutingID(routing_id())->manifest_manager()->GetManifest( | 47 RenderFrameImpl::FromRoutingID(routing_id())->manifest_manager()->GetManifest( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 61 Send(new PushMessagingHostMsg_Register( | 64 Send(new PushMessagingHostMsg_Register( |
| 62 routing_id(), | 65 routing_id(), |
| 63 callbacks_id, | 66 callbacks_id, |
| 64 manifest.gcm_sender_id.is_null() | 67 manifest.gcm_sender_id.is_null() |
| 65 ? sender_id | 68 ? sender_id |
| 66 : base::UTF16ToUTF8(manifest.gcm_sender_id.string()), | 69 : base::UTF16ToUTF8(manifest.gcm_sender_id.string()), |
| 67 blink::WebUserGestureIndicator::isProcessingUserGesture(), | 70 blink::WebUserGestureIndicator::isProcessingUserGesture(), |
| 68 service_worker_provider_id)); | 71 service_worker_provider_id)); |
| 69 } | 72 } |
| 70 | 73 |
| 74 void PushMessagingDispatcher::permissionStatus( |
| 75 blink::WebPushPermissionCallback* callback, |
| 76 blink::WebServiceWorkerProvider* service_worker_provider) { |
| 77 int permission_callback_id = permission_check_callbacks_.Add(callback); |
| 78 int service_worker_provider_id = static_cast<WebServiceWorkerProviderImpl*>( |
| 79 service_worker_provider)->provider_id(); |
| 80 Send(new PushMessagingHostMsg_PermissionStatus( |
| 81 routing_id(), |
| 82 service_worker_provider_id, |
| 83 permission_callback_id)); |
| 84 } |
| 85 |
| 71 void PushMessagingDispatcher::OnRegisterSuccess( | 86 void PushMessagingDispatcher::OnRegisterSuccess( |
| 72 int32 callbacks_id, | 87 int32 callbacks_id, |
| 73 const GURL& endpoint, | 88 const GURL& endpoint, |
| 74 const std::string& registration_id) { | 89 const std::string& registration_id) { |
| 75 blink::WebPushRegistrationCallbacks* callbacks = | 90 blink::WebPushRegistrationCallbacks* callbacks = |
| 76 registration_callbacks_.Lookup(callbacks_id); | 91 registration_callbacks_.Lookup(callbacks_id); |
| 77 CHECK(callbacks); | 92 CHECK(callbacks); |
| 78 | 93 |
| 79 scoped_ptr<blink::WebPushRegistration> registration( | 94 scoped_ptr<blink::WebPushRegistration> registration( |
| 80 new blink::WebPushRegistration( | 95 new blink::WebPushRegistration( |
| 81 WebString::fromUTF8(endpoint.spec()), | 96 WebString::fromUTF8(endpoint.spec()), |
| 82 WebString::fromUTF8(registration_id))); | 97 WebString::fromUTF8(registration_id))); |
| 83 callbacks->onSuccess(registration.release()); | 98 callbacks->onSuccess(registration.release()); |
| 84 registration_callbacks_.Remove(callbacks_id); | 99 registration_callbacks_.Remove(callbacks_id); |
| 85 } | 100 } |
| 86 | 101 |
| 87 void PushMessagingDispatcher::OnRegisterError(int32 callbacks_id, | 102 void PushMessagingDispatcher::OnRegisterError(int32 callbacks_id, |
| 88 PushMessagingStatus status) { | 103 PushMessagingStatus status) { |
| 89 blink::WebPushRegistrationCallbacks* callbacks = | 104 blink::WebPushRegistrationCallbacks* callbacks = |
| 90 registration_callbacks_.Lookup(callbacks_id); | 105 registration_callbacks_.Lookup(callbacks_id); |
| 91 CHECK(callbacks); | 106 CHECK(callbacks); |
| 92 | 107 |
| 93 scoped_ptr<blink::WebPushError> error(new blink::WebPushError( | 108 scoped_ptr<blink::WebPushError> error(new blink::WebPushError( |
| 94 blink::WebPushError::ErrorTypeAbort, | 109 blink::WebPushError::ErrorTypeAbort, |
| 95 WebString::fromUTF8(PushMessagingStatusToString(status)))); | 110 WebString::fromUTF8(PushMessagingStatusToString(status)))); |
| 96 callbacks->onError(error.release()); | 111 callbacks->onError(error.release()); |
| 97 registration_callbacks_.Remove(callbacks_id); | 112 registration_callbacks_.Remove(callbacks_id); |
| 98 } | 113 } |
| 99 | 114 |
| 115 void PushMessagingDispatcher::OnPermissionStatus( |
| 116 int32 callback_id, |
| 117 blink::WebPushPermissionCallback::PushPermissionStatus type) { |
| 118 blink::WebPushPermissionCallback* callback = |
| 119 permission_check_callbacks_.Lookup(callback_id); |
| 120 callback->onSuccess(type); |
| 121 permission_check_callbacks_.Remove(callback_id); |
| 122 } |
| 123 |
| 100 } // namespace content | 124 } // namespace content |
| OLD | NEW |