OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/renderer/push_messaging_dispatcher.h" | |
6 | |
7 #include "content/common/push_messaging_messages.h" | |
8 #include "content/renderer/render_view_impl.h" | |
9 #include "third_party/WebKit/public/platform/WebPushRegistration.h" | |
10 #include "third_party/WebKit/public/platform/WebString.h" | |
Peter Beverloo
2014/04/01 14:53:18
WebString.h is already included from the header fi
Michael van Ouwerkerk
2014/04/02 14:25:15
Done.
| |
11 | |
12 namespace content { | |
13 | |
14 PushMessagingDispatcher::PushMessagingDispatcher(RenderViewImpl* render_view) | |
15 : RenderViewObserver(render_view) {} | |
16 | |
17 PushMessagingDispatcher::~PushMessagingDispatcher() {} | |
18 | |
19 bool PushMessagingDispatcher::OnMessageReceived(const IPC::Message& message) { | |
20 bool handled = true; | |
21 IPC_BEGIN_MESSAGE_MAP(PushMessagingDispatcher, message) | |
22 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterSuccess, OnRegisterSuccess) | |
Peter Beverloo
2014/04/01 14:53:18
Please indent the IPC_MESSAGE_HANDLER and IPC_MESS
Michael van Ouwerkerk
2014/04/02 14:25:15
Done.
| |
23 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterError, OnRegisterError) | |
24 IPC_MESSAGE_UNHANDLED(handled = false) | |
25 IPC_END_MESSAGE_MAP() | |
26 return handled; | |
27 } | |
28 | |
29 void PushMessagingDispatcher::registerPushMessaging( | |
30 const blink::WebString& sender_id, | |
31 blink::WebPushRegistrationCallbacks* callbacks) { | |
32 DCHECK(callbacks); | |
33 int callbacks_id = registration_callbacks_.Add(callbacks); | |
34 Send(new PushMessagingHostMsg_Register( | |
35 routing_id(), callbacks_id, sender_id.utf8())); | |
36 } | |
37 | |
38 void PushMessagingDispatcher::OnRegisterSuccess( | |
39 int32 callbacks_id, | |
40 const std::string& endpoint, | |
41 const std::string& registration_id) { | |
42 blink::WebPushRegistrationCallbacks* callbacks = | |
43 registration_callbacks_.Lookup(callbacks_id); | |
44 DCHECK(callbacks); | |
Peter Beverloo
2014/04/01 14:53:18
Can we just use CHECK here? If we receive an IPC w
Michael van Ouwerkerk
2014/04/02 14:25:15
Done.
| |
45 if (!callbacks) | |
46 return; | |
47 | |
48 callbacks->onSuccess(new blink::WebPushRegistration( | |
Peter Beverloo
2014/04/01 14:53:18
We leak the WebPushRegistration object here. Can y
Michael van Ouwerkerk
2014/04/02 14:25:15
Done.
| |
49 blink::WebString::fromUTF8(endpoint), | |
50 blink::WebString::fromUTF8(registration_id))); | |
51 registration_callbacks_.Remove(callbacks_id); | |
52 } | |
53 | |
54 void PushMessagingDispatcher::OnRegisterError(int32 callbacks_id, | |
55 PushMessagingStatus status) { | |
56 blink::WebPushRegistrationCallbacks* callbacks = | |
57 registration_callbacks_.Lookup(callbacks_id); | |
58 DCHECK(callbacks); | |
59 if (!callbacks) | |
60 return; | |
61 | |
62 scoped_ptr<blink::WebPushError> error( | |
63 new blink::WebPushError( | |
64 blink::WebPushError::AbortError, | |
65 blink::WebString::fromUTF8(PushMessagingStatusToString(status)))); | |
66 callbacks->onError(error.release()); | |
67 registration_callbacks_.Remove(callbacks_id); | |
68 } | |
69 | |
70 } // namespace content | |
OLD | NEW |