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 "content/common/platform_notification_messages.h" | 7 #include "base/bind.h" |
8 #include "content/public/common/service_registry.h" | |
9 #include "content/public/renderer/render_frame.h" | |
8 #include "third_party/WebKit/public/platform/WebString.h" | 10 #include "third_party/WebKit/public/platform/WebString.h" |
9 #include "third_party/WebKit/public/web/WebNotificationPermissionCallback.h" | 11 #include "third_party/WebKit/public/web/WebNotificationPermissionCallback.h" |
10 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 12 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
11 #include "url/gurl.h" | |
12 | 13 |
13 namespace content { | 14 namespace content { |
14 | 15 |
15 NotificationPermissionDispatcher::NotificationPermissionDispatcher( | 16 NotificationPermissionDispatcher::NotificationPermissionDispatcher( |
16 RenderFrame* render_frame) : RenderFrameObserver(render_frame) { | 17 RenderFrame* render_frame) : RenderFrameObserver(render_frame) { |
17 } | 18 } |
18 | 19 |
19 NotificationPermissionDispatcher::~NotificationPermissionDispatcher() { | 20 NotificationPermissionDispatcher::~NotificationPermissionDispatcher() { |
20 } | 21 } |
21 | 22 |
22 void NotificationPermissionDispatcher::RequestPermission( | 23 void NotificationPermissionDispatcher::RequestPermission( |
23 const blink::WebSecurityOrigin& origin, | 24 const blink::WebSecurityOrigin& origin, |
24 blink::WebNotificationPermissionCallback* callback) { | 25 blink::WebNotificationPermissionCallback* callback) { |
26 if (!permission_service_.get()) { | |
27 render_frame()->GetServiceRegistry()->ConnectToRemoteService( | |
28 &permission_service_); | |
29 } | |
30 | |
25 int request_id = pending_requests_.Add(callback); | 31 int request_id = pending_requests_.Add(callback); |
26 Send(new PlatformNotificationHostMsg_RequestPermission( | |
27 routing_id(), GURL(origin.toString()), request_id)); | |
28 } | |
29 | 32 |
30 bool NotificationPermissionDispatcher::OnMessageReceived( | 33 permission_service_->RequestPermission( |
Peter Beverloo
2014/11/24 18:37:34
Is it possible that the service is not connected h
mlamouri (slow - plz ping)
2014/11/25 12:19:55
permission_service_ is a pipe. It is created when
Peter Beverloo
2014/11/25 13:10:34
Can we add a DCHECK to verify that the service is
mlamouri (slow - plz ping)
2014/11/25 13:30:22
The DCHECK will only check that the pipe is create
| |
31 const IPC::Message& message) { | 34 PERMISSION_NAME_NOTIFICATIONS, |
32 bool handled = true; | 35 origin.toString().utf8(), |
33 IPC_BEGIN_MESSAGE_MAP(NotificationPermissionDispatcher, message) | 36 base::Bind(&NotificationPermissionDispatcher::OnPermissionRequestComplete, |
34 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_PermissionRequestComplete, | 37 base::Unretained(this), |
Peter Beverloo
2014/11/24 18:37:33
Just to confirm: is this safe because |permission_
mlamouri (slow - plz ping)
2014/11/25 12:19:55
Correct.
| |
35 OnPermissionRequestComplete); | 38 request_id)); |
36 IPC_MESSAGE_UNHANDLED(handled = false) | |
37 IPC_END_MESSAGE_MAP() | |
38 | |
39 return handled; | |
40 } | 39 } |
41 | 40 |
42 void NotificationPermissionDispatcher::OnPermissionRequestComplete( | 41 void NotificationPermissionDispatcher::OnPermissionRequestComplete( |
43 int request_id, blink::WebNotificationPermission result) { | 42 int request_id, PermissionStatus status) { |
44 blink::WebNotificationPermissionCallback* callback = | 43 blink::WebNotificationPermissionCallback* callback = |
45 pending_requests_.Lookup(request_id); | 44 pending_requests_.Lookup(request_id); |
46 DCHECK(callback); | 45 DCHECK(callback); |
47 | 46 |
48 callback->permissionRequestComplete(result); | 47 blink::WebNotificationPermission permission; |
48 switch (status) { | |
49 case PERMISSION_STATUS_GRANTED: | |
50 permission = blink::WebNotificationPermissionAllowed; | |
51 break; | |
52 case PERMISSION_STATUS_DENIED: | |
53 permission = blink::WebNotificationPermissionDenied; | |
54 break; | |
55 case PERMISSION_STATUS_ASK: | |
56 permission = blink::WebNotificationPermissionDefault; | |
Peter Beverloo
2014/11/24 18:37:34
\o/
Please add 434547 to the BUG= line of your de
mlamouri (slow - plz ping)
2014/11/25 12:19:55
Done.
| |
57 break; | |
58 } | |
Tom Sepez
2014/11/24 18:58:06
Nit:
default: NOTREACHED(); break; or similar?
mlamouri (slow - plz ping)
2014/11/25 12:19:55
PermissionStatus has three states. There will be a
| |
59 | |
60 callback->permissionRequestComplete(permission); | |
49 pending_requests_.Remove(request_id); | 61 pending_requests_.Remove(request_id); |
50 } | 62 } |
51 | 63 |
52 } // namespace content | 64 } // namespace content |
OLD | NEW |