| OLD | NEW |
| (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/notification_permission_dispatcher.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "content/public/renderer/render_frame.h" | |
| 11 #include "services/shell/public/cpp/interface_provider.h" | |
| 12 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | |
| 13 #include "third_party/WebKit/public/platform/WebString.h" | |
| 14 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" | |
| 15 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | |
| 16 #include "third_party/WebKit/public/web/modules/notifications/WebNotificationPer
missionCallback.h" | |
| 17 | |
| 18 using blink::WebNotificationPermissionCallback; | |
| 19 | |
| 20 namespace content { | |
| 21 | |
| 22 NotificationPermissionDispatcher::NotificationPermissionDispatcher( | |
| 23 RenderFrame* render_frame) | |
| 24 : RenderFrameObserver(render_frame) {} | |
| 25 | |
| 26 NotificationPermissionDispatcher::~NotificationPermissionDispatcher() {} | |
| 27 | |
| 28 void NotificationPermissionDispatcher::RequestPermission( | |
| 29 const blink::WebSecurityOrigin& origin, | |
| 30 WebNotificationPermissionCallback* callback) { | |
| 31 if (!permission_service_.get()) { | |
| 32 render_frame()->GetRemoteInterfaces()->GetInterface(&permission_service_); | |
| 33 } | |
| 34 | |
| 35 std::unique_ptr<WebNotificationPermissionCallback> owned_callback(callback); | |
| 36 | |
| 37 // base::Unretained is safe here because the Mojo channel, with associated | |
| 38 // callbacks, will be deleted before the "this" instance is deleted. | |
| 39 permission_service_->RequestPermission( | |
| 40 blink::mojom::PermissionName::NOTIFICATIONS, origin, | |
| 41 blink::WebUserGestureIndicator::isProcessingUserGesture(), | |
| 42 base::Bind(&NotificationPermissionDispatcher::OnPermissionRequestComplete, | |
| 43 base::Unretained(this), | |
| 44 base::Passed(std::move(owned_callback)))); | |
| 45 } | |
| 46 | |
| 47 void NotificationPermissionDispatcher::OnPermissionRequestComplete( | |
| 48 std::unique_ptr<WebNotificationPermissionCallback> callback, | |
| 49 blink::mojom::PermissionStatus status) { | |
| 50 DCHECK(callback); | |
| 51 | |
| 52 // Blink can't use non-blink bindings so we need to cast to int32. | |
| 53 int32_t blink_status = static_cast<int32_t>(status); | |
| 54 | |
| 55 callback->permissionRequestComplete(blink_status); | |
| 56 } | |
| 57 | |
| 58 void NotificationPermissionDispatcher::OnDestruct() { | |
| 59 delete this; | |
| 60 } | |
| 61 | |
| 62 } // namespace content | |
| OLD | NEW |