Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/notification_permission_dispatcher.h" | 5 #include "content/renderer/notification_permission_dispatcher.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "content/public/renderer/render_frame.h" | 10 #include "content/public/renderer/render_frame.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 | 27 |
| 28 void NotificationPermissionDispatcher::RequestPermission( | 28 void NotificationPermissionDispatcher::RequestPermission( |
| 29 const blink::WebSecurityOrigin& origin, | 29 const blink::WebSecurityOrigin& origin, |
| 30 WebNotificationPermissionCallback* callback) { | 30 WebNotificationPermissionCallback* callback) { |
| 31 if (!permission_service_.get()) { | 31 if (!permission_service_.get()) { |
| 32 render_frame()->GetRemoteInterfaces()->GetInterface(&permission_service_); | 32 render_frame()->GetRemoteInterfaces()->GetInterface(&permission_service_); |
| 33 } | 33 } |
| 34 | 34 |
| 35 std::unique_ptr<WebNotificationPermissionCallback> owned_callback(callback); | 35 std::unique_ptr<WebNotificationPermissionCallback> owned_callback(callback); |
| 36 | 36 |
| 37 auto descriptor = blink::mojom::PermissionDescriptor::New(); | |
| 38 descriptor->name = blink::mojom::PermissionName::NOTIFICATIONS; | |
|
ddorwin
2016/08/24 02:43:55
This pattern occurs frequently. ISTM, the construc
| |
| 39 | |
| 37 // base::Unretained is safe here because the Mojo channel, with associated | 40 // base::Unretained is safe here because the Mojo channel, with associated |
| 38 // callbacks, will be deleted before the "this" instance is deleted. | 41 // callbacks, will be deleted before the "this" instance is deleted. |
| 39 permission_service_->RequestPermission( | 42 permission_service_->RequestPermission( |
| 40 blink::mojom::PermissionName::NOTIFICATIONS, origin, | 43 std::move(descriptor), origin, |
| 41 blink::WebUserGestureIndicator::isProcessingUserGesture(), | 44 blink::WebUserGestureIndicator::isProcessingUserGesture(), |
| 42 base::Bind(&NotificationPermissionDispatcher::OnPermissionRequestComplete, | 45 base::Bind(&NotificationPermissionDispatcher::OnPermissionRequestComplete, |
| 43 base::Unretained(this), | 46 base::Unretained(this), |
| 44 base::Passed(std::move(owned_callback)))); | 47 base::Passed(std::move(owned_callback)))); |
| 45 } | 48 } |
| 46 | 49 |
| 47 void NotificationPermissionDispatcher::OnPermissionRequestComplete( | 50 void NotificationPermissionDispatcher::OnPermissionRequestComplete( |
| 48 std::unique_ptr<WebNotificationPermissionCallback> callback, | 51 std::unique_ptr<WebNotificationPermissionCallback> callback, |
| 49 blink::mojom::PermissionStatus status) { | 52 blink::mojom::PermissionStatus status) { |
| 50 DCHECK(callback); | 53 DCHECK(callback); |
| 51 | 54 |
| 52 // Blink can't use non-blink bindings so we need to cast to int32. | 55 // Blink can't use non-blink bindings so we need to cast to int32. |
| 53 int32_t blink_status = static_cast<int32_t>(status); | 56 int32_t blink_status = static_cast<int32_t>(status); |
| 54 | 57 |
| 55 callback->permissionRequestComplete(blink_status); | 58 callback->permissionRequestComplete(blink_status); |
| 56 } | 59 } |
| 57 | 60 |
| 58 void NotificationPermissionDispatcher::OnDestruct() { | 61 void NotificationPermissionDispatcher::OnDestruct() { |
| 59 delete this; | 62 delete this; |
| 60 } | 63 } |
| 61 | 64 |
| 62 } // namespace content | 65 } // namespace content |
| OLD | NEW |