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.
5 #include "content/renderer/notification_permission_dispatcher.h"
7 #include "content/common/platform_notification_messages.h"
8 #include "third_party/WebKit/public/platform/WebString.h"
9 #include "third_party/WebKit/public/web/WebNotificationPermissionCallback.h"
10 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
15 NotificationPermissionDispatcher::NotificationPermissionDispatcher(
16 RenderFrame
* render_frame
) : RenderFrameObserver(render_frame
) {
19 NotificationPermissionDispatcher::~NotificationPermissionDispatcher() {
22 void NotificationPermissionDispatcher::RequestPermission(
23 const blink::WebSecurityOrigin
& origin
,
24 blink::WebNotificationPermissionCallback
* callback
) {
25 int request_id
= pending_requests_
.Add(callback
);
26 Send(new PlatformNotificationHostMsg_RequestPermission(
27 routing_id(), GURL(origin
.toString()), request_id
));
30 bool NotificationPermissionDispatcher::OnMessageReceived(
31 const IPC::Message
& message
) {
33 IPC_BEGIN_MESSAGE_MAP(NotificationPermissionDispatcher
, message
)
34 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_PermissionRequestComplete
,
35 OnPermissionRequestComplete
);
36 IPC_MESSAGE_UNHANDLED(handled
= false)
42 void NotificationPermissionDispatcher::OnPermissionRequestComplete(
43 int request_id
, blink::WebNotificationPermission result
) {
44 blink::WebNotificationPermissionCallback
* callback
=
45 pending_requests_
.Lookup(request_id
);
48 callback
->permissionRequestComplete(result
);
49 pending_requests_
.Remove(request_id
);
52 } // namespace content