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/browser/notifications/notification_message_filter.h" | 5 #include "content/browser/notifications/notification_message_filter.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "content/browser/notifications/page_notification_delegate.h" | 8 #include "content/browser/notifications/page_notification_delegate.h" |
9 #include "content/common/platform_notification_messages.h" | 9 #include "content/common/platform_notification_messages.h" |
10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
12 #include "content/public/browser/content_browser_client.h" | 12 #include "content/public/browser/content_browser_client.h" |
13 #include "content/public/browser/desktop_notification_delegate.h" | 13 #include "content/public/browser/desktop_notification_delegate.h" |
| 14 #include "content/public/browser/platform_notification_service.h" |
14 #include "content/public/common/content_client.h" | 15 #include "content/public/common/content_client.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
18 NotificationMessageFilter::NotificationMessageFilter( | 19 NotificationMessageFilter::NotificationMessageFilter( |
19 int process_id, | 20 int process_id, |
20 ResourceContext* resource_context, | 21 ResourceContext* resource_context, |
21 BrowserContext* browser_context) | 22 BrowserContext* browser_context) |
22 : BrowserMessageFilter(PlatformNotificationMsgStart), | 23 : BrowserMessageFilter(PlatformNotificationMsgStart), |
23 process_id_(process_id), | 24 process_id_(process_id), |
(...skipping 29 matching lines...) Expand all Loading... |
53 const IPC::Message& message, content::BrowserThread::ID* thread) { | 54 const IPC::Message& message, content::BrowserThread::ID* thread) { |
54 if (message.type() == PlatformNotificationHostMsg_Show::ID || | 55 if (message.type() == PlatformNotificationHostMsg_Show::ID || |
55 message.type() == PlatformNotificationHostMsg_ShowPersistent::ID || | 56 message.type() == PlatformNotificationHostMsg_ShowPersistent::ID || |
56 message.type() == PlatformNotificationHostMsg_Close::ID || | 57 message.type() == PlatformNotificationHostMsg_Close::ID || |
57 message.type() == PlatformNotificationHostMsg_ClosePersistent::ID) | 58 message.type() == PlatformNotificationHostMsg_ClosePersistent::ID) |
58 *thread = BrowserThread::UI; | 59 *thread = BrowserThread::UI; |
59 } | 60 } |
60 | 61 |
61 void NotificationMessageFilter::OnCheckNotificationPermission( | 62 void NotificationMessageFilter::OnCheckNotificationPermission( |
62 const GURL& origin, blink::WebNotificationPermission* permission) { | 63 const GURL& origin, blink::WebNotificationPermission* permission) { |
63 *permission = | 64 PlatformNotificationService* service = |
64 GetContentClient()->browser()->CheckDesktopNotificationPermission( | 65 GetContentClient()->browser()->GetPlatformNotificationService(); |
65 origin, | 66 if (service) { |
66 resource_context_, | 67 *permission = service->CheckPermission(resource_context_, |
67 process_id_); | 68 origin, |
| 69 process_id_); |
| 70 } else { |
| 71 *permission = blink::WebNotificationPermissionDenied; |
| 72 } |
68 } | 73 } |
69 | 74 |
70 void NotificationMessageFilter::OnShowPlatformNotification( | 75 void NotificationMessageFilter::OnShowPlatformNotification( |
71 int notification_id, const ShowDesktopNotificationHostMsgParams& params) { | 76 int notification_id, const ShowDesktopNotificationHostMsgParams& params) { |
72 scoped_ptr<DesktopNotificationDelegate> delegate( | 77 scoped_ptr<DesktopNotificationDelegate> delegate( |
73 new PageNotificationDelegate(process_id_, notification_id)); | 78 new PageNotificationDelegate(process_id_, notification_id)); |
74 | 79 |
75 base::Closure close_closure; | 80 base::Closure close_closure; |
76 GetContentClient()->browser()->ShowDesktopNotification(params, | 81 PlatformNotificationService* service = |
77 browser_context_, | 82 GetContentClient()->browser()->GetPlatformNotificationService(); |
78 process_id_, | 83 DCHECK(service); |
79 delegate.Pass(), | 84 |
80 &close_closure); | 85 service->DisplayNotification(browser_context_, |
| 86 params, |
| 87 delegate.Pass(), |
| 88 process_id_, |
| 89 &close_closure); |
81 | 90 |
82 if (!close_closure.is_null()) | 91 if (!close_closure.is_null()) |
83 close_closures_[notification_id] = close_closure; | 92 close_closures_[notification_id] = close_closure; |
84 } | 93 } |
85 | 94 |
86 void NotificationMessageFilter::OnShowPersistentNotification( | 95 void NotificationMessageFilter::OnShowPersistentNotification( |
87 int request_id, | 96 int request_id, |
88 int64 service_worker_registration_id, | 97 int64 service_worker_registration_id, |
89 const ShowDesktopNotificationHostMsgParams& params) { | 98 const ShowDesktopNotificationHostMsgParams& params) { |
90 NOTIMPLEMENTED(); | 99 NOTIMPLEMENTED(); |
(...skipping 11 matching lines...) Expand all Loading... |
102 close_closures_[notification_id].Run(); | 111 close_closures_[notification_id].Run(); |
103 close_closures_.erase(notification_id); | 112 close_closures_.erase(notification_id); |
104 } | 113 } |
105 | 114 |
106 void NotificationMessageFilter::OnClosePersistentNotification( | 115 void NotificationMessageFilter::OnClosePersistentNotification( |
107 const std::string& persistent_notification_id) { | 116 const std::string& persistent_notification_id) { |
108 NOTIMPLEMENTED(); | 117 NOTIMPLEMENTED(); |
109 } | 118 } |
110 | 119 |
111 } // namespace content | 120 } // namespace content |
OLD | NEW |