Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: content/renderer/notification_permission_dispatcher.cc

Issue 1471833002: Stop using base::IDMap in the NotificationPermissionDispatcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/renderer/notification_permission_dispatcher.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "content/public/common/service_registry.h" 8 #include "content/public/common/service_registry.h"
9 #include "content/public/renderer/render_frame.h" 9 #include "content/public/renderer/render_frame.h"
10 #include "third_party/WebKit/public/platform/WebString.h" 10 #include "third_party/WebKit/public/platform/WebString.h"
11 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" 11 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
12 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" 12 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
13 #include "third_party/WebKit/public/web/modules/notifications/WebNotificationPer missionCallback.h" 13 #include "third_party/WebKit/public/web/modules/notifications/WebNotificationPer missionCallback.h"
14 14
15 using blink::WebNotificationPermissionCallback;
16
15 namespace content { 17 namespace content {
16 18
17 NotificationPermissionDispatcher::NotificationPermissionDispatcher( 19 NotificationPermissionDispatcher::NotificationPermissionDispatcher(
18 RenderFrame* render_frame) : RenderFrameObserver(render_frame) { 20 RenderFrame* render_frame)
19 } 21 : RenderFrameObserver(render_frame) {}
20 22
21 NotificationPermissionDispatcher::~NotificationPermissionDispatcher() { 23 NotificationPermissionDispatcher::~NotificationPermissionDispatcher() {}
22 }
23 24
24 void NotificationPermissionDispatcher::RequestPermission( 25 void NotificationPermissionDispatcher::RequestPermission(
25 const blink::WebSecurityOrigin& origin, 26 const blink::WebSecurityOrigin& origin,
26 blink::WebNotificationPermissionCallback* callback) { 27 WebNotificationPermissionCallback* callback) {
27 if (!permission_service_.get()) { 28 if (!permission_service_.get()) {
28 render_frame()->GetServiceRegistry()->ConnectToRemoteService( 29 render_frame()->GetServiceRegistry()->ConnectToRemoteService(
29 mojo::GetProxy(&permission_service_)); 30 mojo::GetProxy(&permission_service_));
30 } 31 }
31 32
32 int request_id = pending_requests_.Add(callback); 33 scoped_ptr<WebNotificationPermissionCallback> owned_callback(callback);
33 34
35 // base::Unretained is safe here because the Mojo channel, with associated
36 // callbacks, will be deleted before the "this" instance is deleted.
34 permission_service_->RequestPermission( 37 permission_service_->RequestPermission(
35 PERMISSION_NAME_NOTIFICATIONS, 38 PERMISSION_NAME_NOTIFICATIONS, origin.toString().utf8(),
36 origin.toString().utf8(),
37 blink::WebUserGestureIndicator::isProcessingUserGesture(), 39 blink::WebUserGestureIndicator::isProcessingUserGesture(),
38 base::Bind(&NotificationPermissionDispatcher::OnPermissionRequestComplete, 40 base::Bind(&NotificationPermissionDispatcher::OnPermissionRequestComplete,
39 base::Unretained(this), 41 base::Unretained(this), base::Passed(owned_callback.Pass())));
40 request_id));
41 } 42 }
42 43
43 void NotificationPermissionDispatcher::OnPermissionRequestComplete( 44 void NotificationPermissionDispatcher::OnPermissionRequestComplete(
44 int request_id, PermissionStatus status) { 45 scoped_ptr<WebNotificationPermissionCallback> callback,
45 blink::WebNotificationPermissionCallback* callback = 46 PermissionStatus status) {
46 pending_requests_.Lookup(request_id);
47 DCHECK(callback); 47 DCHECK(callback);
48 48
49 blink::WebNotificationPermission permission = 49 blink::WebNotificationPermission permission =
50 blink::WebNotificationPermissionDefault; 50 blink::WebNotificationPermissionDefault;
51 switch (status) { 51 switch (status) {
52 case PERMISSION_STATUS_GRANTED: 52 case PERMISSION_STATUS_GRANTED:
53 permission = blink::WebNotificationPermissionAllowed; 53 permission = blink::WebNotificationPermissionAllowed;
54 break; 54 break;
55 case PERMISSION_STATUS_DENIED: 55 case PERMISSION_STATUS_DENIED:
56 permission = blink::WebNotificationPermissionDenied; 56 permission = blink::WebNotificationPermissionDenied;
57 break; 57 break;
58 case PERMISSION_STATUS_ASK: 58 case PERMISSION_STATUS_ASK:
59 permission = blink::WebNotificationPermissionDefault; 59 permission = blink::WebNotificationPermissionDefault;
60 break; 60 break;
61 } 61 }
62 62
63 callback->permissionRequestComplete(permission); 63 callback->permissionRequestComplete(permission);
64 pending_requests_.Remove(request_id);
65 } 64 }
66 65
67 } // namespace content 66 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/notification_permission_dispatcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698