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 "config.h" 6 #include "web/NotificationPermissionClientImpl.h" 7 8 #include "core/dom/Document.h" 9 #include "core/dom/ExecutionContext.h" 10 #include "modules/notifications/Notification.h" 11 #include "public/web/WebFrameClient.h" 12 #include "public/web/WebNotificationPermissionCallback.h" 13 #include "web/WebLocalFrameImpl.h" 14 15 namespace blink { 16 17 namespace { 18 19 class WebNotificationPermissionCallbackImpl : public WebNotificationPermissionCallback { 20 public: 21 WebNotificationPermissionCallbackImpl(NotificationPermissionCallback* callback) 22 : m_callback(callback) 23 { 24 } 25 26 virtual ~WebNotificationPermissionCallbackImpl() { } 27 28 virtual void permissionRequestComplete(WebNotificationPermission permission) OVERRIDE 29 { 30 if (m_callback) 31 m_callback->handleEvent(Notification::permissionString(static_cast<NotificationClient::Permission>(permission))); 32 } 33 34 private: 35 Persistent<NotificationPermissionCallback> m_callback; 36 }; 37 38 } // namespace 39 40 PassOwnPtrWillBeRawPtr<NotificationPermissionClientImpl> NotificationPermissionClientImpl::create() 41 { 42 return adoptPtrWillBeNoop(new NotificationPermissionClientImpl()); 43 } 44 45 NotificationPermissionClientImpl::NotificationPermissionClientImpl() 46 { 47 } 48 49 NotificationPermissionClientImpl::~NotificationPermissionClientImpl() 50 { 51 } 52 53 void NotificationPermissionClientImpl::requestPermission(ExecutionContext* context, NotificationPermissionCallback* callback) 54 { 55 ASSERT(context && context->isDocument()); 56 57 Document* document = toDocument(context); 58 WebLocalFrameImpl* webFrame = WebLocalFrameImpl::fromFrame(document->frame()); 59 60 webFrame->client()->requestNotificationPermission(WebSecurityOrigin(context->securityOrigin()), new WebNotificationPermissionCallbackImpl(callback)); 61 } 62 63 } // namespace blink 64