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 13 matching lines...) Expand all Loading... | |
58 Send(new PushMessagingHostMsg_Register( | 63 Send(new PushMessagingHostMsg_Register( |
59 routing_id(), | 64 routing_id(), |
60 callbacks_id, | 65 callbacks_id, |
61 manifest.gcm_sender_id.is_null() | 66 manifest.gcm_sender_id.is_null() |
62 ? std::string() | 67 ? std::string() |
63 : base::UTF16ToUTF8(manifest.gcm_sender_id.string()), | 68 : base::UTF16ToUTF8(manifest.gcm_sender_id.string()), |
64 blink::WebUserGestureIndicator::isProcessingUserGesture(), | 69 blink::WebUserGestureIndicator::isProcessingUserGesture(), |
65 service_worker_provider_id)); | 70 service_worker_provider_id)); |
66 } | 71 } |
67 | 72 |
73 void PushMessagingDispatcher::getPermissionStatus( | |
74 blink::WebPushPermissionCallback* callback, | |
75 blink::WebServiceWorkerProvider* service_worker_provider) { | |
76 int permission_callback_id = permission_check_callbacks_.Add(callback); | |
77 int service_worker_provider_id = static_cast<WebServiceWorkerProviderImpl*>( | |
78 service_worker_provider)->provider_id(); | |
79 Send(new PushMessagingHostMsg_PermissionStatus( | |
80 routing_id(), service_worker_provider_id, permission_callback_id)); | |
81 } | |
82 | |
68 void PushMessagingDispatcher::OnRegisterSuccess( | 83 void PushMessagingDispatcher::OnRegisterSuccess( |
69 int32 callbacks_id, | 84 int32 callbacks_id, |
70 const GURL& endpoint, | 85 const GURL& endpoint, |
71 const std::string& registration_id) { | 86 const std::string& registration_id) { |
72 blink::WebPushRegistrationCallbacks* callbacks = | 87 blink::WebPushRegistrationCallbacks* callbacks = |
73 registration_callbacks_.Lookup(callbacks_id); | 88 registration_callbacks_.Lookup(callbacks_id); |
74 CHECK(callbacks); | 89 CHECK(callbacks); |
75 | 90 |
76 scoped_ptr<blink::WebPushRegistration> registration( | 91 scoped_ptr<blink::WebPushRegistration> registration( |
77 new blink::WebPushRegistration( | 92 new blink::WebPushRegistration( |
78 WebString::fromUTF8(endpoint.spec()), | 93 WebString::fromUTF8(endpoint.spec()), |
79 WebString::fromUTF8(registration_id))); | 94 WebString::fromUTF8(registration_id))); |
80 callbacks->onSuccess(registration.release()); | 95 callbacks->onSuccess(registration.release()); |
81 registration_callbacks_.Remove(callbacks_id); | 96 registration_callbacks_.Remove(callbacks_id); |
82 } | 97 } |
83 | 98 |
84 void PushMessagingDispatcher::OnRegisterError(int32 callbacks_id, | 99 void PushMessagingDispatcher::OnRegisterError(int32 callbacks_id, |
85 PushRegistrationStatus status) { | 100 PushRegistrationStatus status) { |
86 blink::WebPushRegistrationCallbacks* callbacks = | 101 blink::WebPushRegistrationCallbacks* callbacks = |
87 registration_callbacks_.Lookup(callbacks_id); | 102 registration_callbacks_.Lookup(callbacks_id); |
88 CHECK(callbacks); | 103 CHECK(callbacks); |
89 | 104 |
90 scoped_ptr<blink::WebPushError> error(new blink::WebPushError( | 105 scoped_ptr<blink::WebPushError> error(new blink::WebPushError( |
91 blink::WebPushError::ErrorTypeAbort, | 106 blink::WebPushError::ErrorTypeAbort, |
92 WebString::fromUTF8(PushRegistrationStatusToString(status)))); | 107 WebString::fromUTF8(PushRegistrationStatusToString(status)))); |
93 callbacks->onError(error.release()); | 108 callbacks->onError(error.release()); |
94 registration_callbacks_.Remove(callbacks_id); | 109 registration_callbacks_.Remove(callbacks_id); |
95 } | 110 } |
96 | 111 |
112 void PushMessagingDispatcher::OnPermissionStatus( | |
113 int32 callback_id, | |
114 blink::WebPushPermissionStatus status) { | |
115 blink::WebPushPermissionCallback* callback = | |
116 permission_check_callbacks_.Lookup(callback_id); | |
117 DCHECK(callback); | |
jam
2014/10/29 20:08:58
here and below, this doesn't do much. in release,
Miguel Garcia
2014/10/30 12:27:15
It's kind of a nice way of saying. Hey I am callba
| |
118 callback->onSuccess(&status); | |
119 permission_check_callbacks_.Remove(callback_id); | |
120 } | |
121 | |
122 void PushMessagingDispatcher::OnPermissionStatusFailure(int32 callback_id) { | |
123 blink::WebPushPermissionCallback* callback = | |
124 permission_check_callbacks_.Lookup(callback_id); | |
125 DCHECK(callback); | |
126 callback->onError(); | |
127 permission_check_callbacks_.Remove(callback_id); | |
128 } | |
129 | |
97 } // namespace content | 130 } // namespace content |
OLD | NEW |