Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: content/renderer/push_messaging_dispatcher.cc

Issue 219653002: Push API: send and receive IPC messages for registration. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up includes. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/renderer/push_messaging_dispatcher.h ('k') | content/renderer/render_view_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "ipc/ipc_message.h"
10 #include "third_party/WebKit/public/platform/WebPushError.h"
11 #include "third_party/WebKit/public/platform/WebPushRegistration.h"
12 #include "third_party/WebKit/public/platform/WebString.h"
13 #include "url/gurl.h"
14
15 using blink::WebString;
16
17 namespace content {
18
19 PushMessagingDispatcher::PushMessagingDispatcher(RenderViewImpl* render_view)
20 : RenderViewObserver(render_view) {}
21
22 PushMessagingDispatcher::~PushMessagingDispatcher() {}
23
24 bool PushMessagingDispatcher::OnMessageReceived(const IPC::Message& message) {
25 bool handled = true;
26 IPC_BEGIN_MESSAGE_MAP(PushMessagingDispatcher, message)
27 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterSuccess, OnRegisterSuccess)
28 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterError, OnRegisterError)
29 IPC_MESSAGE_UNHANDLED(handled = false)
30 IPC_END_MESSAGE_MAP()
31 return handled;
32 }
33
34 void PushMessagingDispatcher::registerPushMessaging(
35 const WebString& sender_id,
36 blink::WebPushRegistrationCallbacks* callbacks) {
37 DCHECK(callbacks);
38 int callbacks_id = registration_callbacks_.Add(callbacks);
39 Send(new PushMessagingHostMsg_Register(
40 routing_id(), callbacks_id, sender_id.utf8()));
41 }
42
43 void PushMessagingDispatcher::OnRegisterSuccess(
44 int32 callbacks_id,
45 const GURL& endpoint,
46 const std::string& registration_id) {
47 blink::WebPushRegistrationCallbacks* callbacks =
48 registration_callbacks_.Lookup(callbacks_id);
49 CHECK(callbacks);
50
51 scoped_ptr<blink::WebPushRegistration> registration(
52 new blink::WebPushRegistration(
53 WebString::fromUTF8(endpoint.spec()),
54 WebString::fromUTF8(registration_id)));
55 callbacks->onSuccess(registration.release());
56 registration_callbacks_.Remove(callbacks_id);
57 }
58
59 void PushMessagingDispatcher::OnRegisterError(int32 callbacks_id) {
60 const std::string kAbortErrorReason = "Registration failed.";
61 blink::WebPushRegistrationCallbacks* callbacks =
62 registration_callbacks_.Lookup(callbacks_id);
63 CHECK(callbacks);
64
65 scoped_ptr<blink::WebPushError> error(
66 new blink::WebPushError(
67 blink::WebPushError::ErrorTypeAbort,
68 WebString::fromUTF8(kAbortErrorReason)));
69 callbacks->onError(error.release());
70 registration_callbacks_.Remove(callbacks_id);
71 }
72
73 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/push_messaging_dispatcher.h ('k') | content/renderer/render_view_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698