Chromium Code Reviews| 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" |
| 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/WebPushError.h" | 13 #include "third_party/WebKit/public/platform/WebPushError.h" |
| 14 #include "third_party/WebKit/public/platform/WebPushPermissionCallback.h" | |
| 14 #include "third_party/WebKit/public/platform/WebPushRegistration.h" | 15 #include "third_party/WebKit/public/platform/WebPushRegistration.h" |
| 15 #include "third_party/WebKit/public/platform/WebServiceWorkerProvider.h" | 16 #include "third_party/WebKit/public/platform/WebServiceWorkerProvider.h" |
| 16 #include "third_party/WebKit/public/platform/WebString.h" | 17 #include "third_party/WebKit/public/platform/WebString.h" |
| 17 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 18 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| 18 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 19 | 20 |
| 20 using blink::WebString; | 21 using blink::WebString; |
| 21 | 22 |
| 22 namespace content { | 23 namespace content { |
| 23 | 24 |
| 24 PushMessagingDispatcher::PushMessagingDispatcher(RenderFrame* render_frame) | 25 PushMessagingDispatcher::PushMessagingDispatcher(RenderFrame* render_frame) |
| 25 : RenderFrameObserver(render_frame) { | 26 : RenderFrameObserver(render_frame) { |
| 26 } | 27 } |
| 27 | 28 |
| 28 PushMessagingDispatcher::~PushMessagingDispatcher() {} | 29 PushMessagingDispatcher::~PushMessagingDispatcher() {} |
| 29 | 30 |
| 30 bool PushMessagingDispatcher::OnMessageReceived(const IPC::Message& message) { | 31 bool PushMessagingDispatcher::OnMessageReceived(const IPC::Message& message) { |
| 31 bool handled = true; | 32 bool handled = true; |
| 32 IPC_BEGIN_MESSAGE_MAP(PushMessagingDispatcher, message) | 33 IPC_BEGIN_MESSAGE_MAP(PushMessagingDispatcher, message) |
| 33 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterSuccess, OnRegisterSuccess) | 34 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterSuccess, OnRegisterSuccess) |
| 34 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterError, OnRegisterError) | 35 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterError, OnRegisterError) |
| 36 IPC_MESSAGE_HANDLER(PushMessagingMsg_PermissionStatusResult, | |
| 37 OnPermissionStatus) | |
| 38 | |
| 35 IPC_MESSAGE_UNHANDLED(handled = false) | 39 IPC_MESSAGE_UNHANDLED(handled = false) |
| 36 IPC_END_MESSAGE_MAP() | 40 IPC_END_MESSAGE_MAP() |
| 37 return handled; | 41 return handled; |
| 38 } | 42 } |
| 39 | 43 |
| 40 void PushMessagingDispatcher::registerPushMessaging( | 44 void PushMessagingDispatcher::registerPushMessaging( |
| 41 const WebString& sender_id, | 45 const WebString& sender_id, |
| 42 blink::WebPushRegistrationCallbacks* callbacks, | 46 blink::WebPushRegistrationCallbacks* callbacks, |
| 43 blink::WebServiceWorkerProvider* service_worker_provider) { | 47 blink::WebServiceWorkerProvider* service_worker_provider) { |
| 44 RenderFrameImpl::FromRoutingID(routing_id())->manifest_manager()->GetManifest( | 48 RenderFrameImpl::FromRoutingID(routing_id())->manifest_manager()->GetManifest( |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 61 Send(new PushMessagingHostMsg_Register( | 65 Send(new PushMessagingHostMsg_Register( |
| 62 routing_id(), | 66 routing_id(), |
| 63 callbacks_id, | 67 callbacks_id, |
| 64 manifest.gcm_sender_id.is_null() | 68 manifest.gcm_sender_id.is_null() |
| 65 ? sender_id | 69 ? sender_id |
| 66 : base::UTF16ToUTF8(manifest.gcm_sender_id.string()), | 70 : base::UTF16ToUTF8(manifest.gcm_sender_id.string()), |
| 67 blink::WebUserGestureIndicator::isProcessingUserGesture(), | 71 blink::WebUserGestureIndicator::isProcessingUserGesture(), |
| 68 service_worker_provider_id)); | 72 service_worker_provider_id)); |
| 69 } | 73 } |
| 70 | 74 |
| 75 void PushMessagingDispatcher::getPermissionStatus( | |
| 76 blink::WebPushPermissionCallback* callback, | |
| 77 blink::WebServiceWorkerProvider* service_worker_provider) { | |
| 78 int permission_callback_id = permission_check_callbacks_.Add(callback); | |
| 79 int service_worker_provider_id = static_cast<WebServiceWorkerProviderImpl*>( | |
| 80 service_worker_provider)->provider_id(); | |
| 81 Send(new PushMessagingHostMsg_PermissionStatus( | |
| 82 routing_id(), | |
| 83 service_worker_provider_id, | |
| 84 permission_callback_id)); | |
| 85 } | |
| 86 | |
| 71 void PushMessagingDispatcher::OnRegisterSuccess( | 87 void PushMessagingDispatcher::OnRegisterSuccess( |
| 72 int32 callbacks_id, | 88 int32 callbacks_id, |
| 73 const GURL& endpoint, | 89 const GURL& endpoint, |
| 74 const std::string& registration_id) { | 90 const std::string& registration_id) { |
| 75 blink::WebPushRegistrationCallbacks* callbacks = | 91 blink::WebPushRegistrationCallbacks* callbacks = |
| 76 registration_callbacks_.Lookup(callbacks_id); | 92 registration_callbacks_.Lookup(callbacks_id); |
| 77 CHECK(callbacks); | 93 CHECK(callbacks); |
| 78 | 94 |
| 79 scoped_ptr<blink::WebPushRegistration> registration( | 95 scoped_ptr<blink::WebPushRegistration> registration( |
| 80 new blink::WebPushRegistration( | 96 new blink::WebPushRegistration( |
| 81 WebString::fromUTF8(endpoint.spec()), | 97 WebString::fromUTF8(endpoint.spec()), |
| 82 WebString::fromUTF8(registration_id))); | 98 WebString::fromUTF8(registration_id))); |
| 83 callbacks->onSuccess(registration.release()); | 99 callbacks->onSuccess(registration.release()); |
| 84 registration_callbacks_.Remove(callbacks_id); | 100 registration_callbacks_.Remove(callbacks_id); |
| 85 } | 101 } |
| 86 | 102 |
| 87 void PushMessagingDispatcher::OnRegisterError(int32 callbacks_id, | 103 void PushMessagingDispatcher::OnRegisterError(int32 callbacks_id, |
| 88 PushRegistrationStatus status) { | 104 PushRegistrationStatus status) { |
| 89 blink::WebPushRegistrationCallbacks* callbacks = | 105 blink::WebPushRegistrationCallbacks* callbacks = |
| 90 registration_callbacks_.Lookup(callbacks_id); | 106 registration_callbacks_.Lookup(callbacks_id); |
| 91 CHECK(callbacks); | 107 CHECK(callbacks); |
| 92 | 108 |
| 93 scoped_ptr<blink::WebPushError> error(new blink::WebPushError( | 109 scoped_ptr<blink::WebPushError> error(new blink::WebPushError( |
| 94 blink::WebPushError::ErrorTypeAbort, | 110 blink::WebPushError::ErrorTypeAbort, |
| 95 WebString::fromUTF8(PushRegistrationStatusToString(status)))); | 111 WebString::fromUTF8(PushRegistrationStatusToString(status)))); |
| 96 callbacks->onError(error.release()); | 112 callbacks->onError(error.release()); |
| 97 registration_callbacks_.Remove(callbacks_id); | 113 registration_callbacks_.Remove(callbacks_id); |
| 98 } | 114 } |
| 99 | 115 |
| 116 void PushMessagingDispatcher::OnPermissionStatus( | |
| 117 int32 callback_id, | |
| 118 blink::WebPushPermissionStatus type) { | |
|
Michael van Ouwerkerk
2014/10/24 12:36:08
tiny nit: I'd prefer status over type
Miguel Garcia
2014/10/29 18:32:03
Done.
| |
| 119 blink::WebPushPermissionCallback* callback = | |
| 120 permission_check_callbacks_.Lookup(callback_id); | |
| 121 callback->onSuccess(type); | |
| 122 permission_check_callbacks_.Remove(callback_id); | |
| 123 } | |
| 124 | |
| 100 } // namespace content | 125 } // namespace content |
| OLD | NEW |