Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / content / renderer / push_permission_dispatcher.cc
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_permission_dispatcher.h"
6
7 #include "content/common/push_messaging_messages.h"
8 #include "content/renderer/render_frame_impl.h"
9 #include "ipc/ipc_message.h"
10 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
11
12 namespace content {
13
14 PushPermissionDispatcher::PushPermissionDispatcher(RenderFrame* render_frame)
15     : RenderFrameObserver(render_frame) {
16 }
17
18 PushPermissionDispatcher::~PushPermissionDispatcher() {
19 }
20
21 void PushPermissionDispatcher::RequestPermission(blink::WebCallback* callback) {
22   DCHECK(callback);
23   int request_id = callbacks_.Add(callback);
24   Send(new PushMessagingHostMsg_RequestPermission(
25       routing_id(),
26       request_id,
27       blink::WebUserGestureIndicator::isProcessingUserGesture()));
28 }
29
30 bool PushPermissionDispatcher::OnMessageReceived(const IPC::Message& message) {
31   bool handled = true;
32   IPC_BEGIN_MESSAGE_MAP(PushPermissionDispatcher, message)
33   IPC_MESSAGE_HANDLER(PushMessagingMsg_RequestPermissionResponse,
34                       OnRequestPermissionResponse)
35   IPC_MESSAGE_UNHANDLED(handled = false)
36   IPC_END_MESSAGE_MAP()
37   return handled;
38 }
39
40 void PushPermissionDispatcher::OnRequestPermissionResponse(int32 request_id) {
41   blink::WebCallback* callback = callbacks_.Lookup(request_id);
42   CHECK(callback);
43
44   callback->run();
45   callbacks_.Remove(request_id);
46 }
47
48 }  // namespace content