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/notification_permission_dispatcher.h" 6 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" 11 #include "url/gurl.h" 12 13 namespace content { 14 NotificationPermissionDispatcher(RenderFrame * render_frame)15NotificationPermissionDispatcher::NotificationPermissionDispatcher( 16 RenderFrame* render_frame) : RenderFrameObserver(render_frame) { 17 } 18 ~NotificationPermissionDispatcher()19NotificationPermissionDispatcher::~NotificationPermissionDispatcher() { 20 } 21 RequestPermission(const blink::WebSecurityOrigin & origin,blink::WebNotificationPermissionCallback * callback)22void 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)); 28 } 29 OnMessageReceived(const IPC::Message & message)30bool NotificationPermissionDispatcher::OnMessageReceived( 31 const IPC::Message& message) { 32 bool handled = true; 33 IPC_BEGIN_MESSAGE_MAP(NotificationPermissionDispatcher, message) 34 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_PermissionRequestComplete, 35 OnPermissionRequestComplete); 36 IPC_MESSAGE_UNHANDLED(handled = false) 37 IPC_END_MESSAGE_MAP() 38 39 return handled; 40 } 41 OnPermissionRequestComplete(int request_id,blink::WebNotificationPermission result)42void NotificationPermissionDispatcher::OnPermissionRequestComplete( 43 int request_id, blink::WebNotificationPermission result) { 44 blink::WebNotificationPermissionCallback* callback = 45 pending_requests_.Lookup(request_id); 46 DCHECK(callback); 47 48 callback->permissionRequestComplete(result); 49 pending_requests_.Remove(request_id); 50 } 51 52 } // namespace content 53