OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/notifications/desktop_notification_service.h" | 5 #include "chrome/browser/notifications/desktop_notification_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/prefs/scoped_user_pref_update.h" | 9 #include "base/prefs/scoped_user_pref_update.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
14 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 14 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
15 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 15 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
16 #include "chrome/browser/notifications/notification.h" | 16 #include "chrome/browser/notifications/notification.h" |
17 #include "chrome/browser/notifications/notification_object_proxy.h" | 17 #include "chrome/browser/notifications/notification_object_proxy.h" |
18 #include "chrome/browser/notifications/notification_ui_manager.h" | 18 #include "chrome/browser/notifications/notification_ui_manager.h" |
19 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" | 19 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" |
20 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_fac tory.h" | 20 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_fac tory.h" |
21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
24 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
25 #include "components/content_settings/core/common/permission_request_id.h" | |
25 #include "components/pref_registry/pref_registry_syncable.h" | 26 #include "components/pref_registry/pref_registry_syncable.h" |
26 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/browser/desktop_notification_delegate.h" | 28 #include "content/public/browser/desktop_notification_delegate.h" |
28 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
29 #include "content/public/browser/render_frame_host.h" | 30 #include "content/public/browser/render_frame_host.h" |
30 #include "content/public/browser/render_process_host.h" | 31 #include "content/public/browser/render_process_host.h" |
31 #include "content/public/browser/render_view_host.h" | 32 #include "content/public/browser/render_view_host.h" |
32 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
33 #include "content/public/common/show_desktop_notification_params.h" | 34 #include "content/public/common/show_desktop_notification_params.h" |
34 #include "ui/base/webui/web_ui_util.h" | 35 #include "ui/base/webui/web_ui_util.h" |
35 #include "ui/message_center/notifier_settings.h" | 36 #include "ui/message_center/notifier_settings.h" |
36 | 37 |
37 #if defined(ENABLE_EXTENSIONS) | 38 #if defined(ENABLE_EXTENSIONS) |
38 #include "chrome/browser/extensions/api/notifications/notifications_api.h" | 39 #include "chrome/browser/extensions/api/notifications/notifications_api.h" |
39 #include "chrome/browser/extensions/extension_service.h" | 40 #include "chrome/browser/extensions/extension_service.h" |
40 #include "extensions/browser/event_router.h" | 41 #include "extensions/browser/event_router.h" |
41 #include "extensions/browser/extension_registry.h" | 42 #include "extensions/browser/extension_registry.h" |
42 #include "extensions/browser/extension_system.h" | 43 #include "extensions/browser/extension_system.h" |
43 #include "extensions/browser/extension_util.h" | 44 #include "extensions/browser/extension_util.h" |
44 #include "extensions/browser/info_map.h" | 45 #include "extensions/browser/info_map.h" |
46 #include "extensions/browser/suggest_permission_util.h" | |
45 #include "extensions/common/constants.h" | 47 #include "extensions/common/constants.h" |
46 #include "extensions/common/extension.h" | 48 #include "extensions/common/extension.h" |
47 #include "extensions/common/extension_set.h" | 49 #include "extensions/common/extension_set.h" |
48 #endif | 50 #endif |
49 | 51 |
50 using blink::WebTextDirection; | 52 using blink::WebTextDirection; |
51 using content::BrowserThread; | 53 using content::BrowserThread; |
52 using content::RenderViewHost; | 54 using content::RenderViewHost; |
53 using content::WebContents; | 55 using content::WebContents; |
54 using message_center::NotifierId; | 56 using message_center::NotifierId; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 extensions::ExtensionRegistry::Get(profile_)); | 133 extensions::ExtensionRegistry::Get(profile_)); |
132 #endif | 134 #endif |
133 } | 135 } |
134 | 136 |
135 DesktopNotificationService::~DesktopNotificationService() { | 137 DesktopNotificationService::~DesktopNotificationService() { |
136 } | 138 } |
137 | 139 |
138 void DesktopNotificationService::RequestNotificationPermission( | 140 void DesktopNotificationService::RequestNotificationPermission( |
139 content::WebContents* web_contents, | 141 content::WebContents* web_contents, |
140 const PermissionRequestID& request_id, | 142 const PermissionRequestID& request_id, |
141 const GURL& requesting_frame, | 143 const GURL& requesting_origin, |
142 bool user_gesture, | 144 bool user_gesture, |
143 const NotificationPermissionCallback& callback) { | 145 const NotificationPermissionCallback& callback) { |
144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
147 | |
148 #if defined(ENABLE_EXTENSIONS) | |
149 extensions::InfoMap* extension_info_map = | |
150 extensions::ExtensionSystem::Get(profile_)->info_map(); | |
151 const extensions::Extension* extension = NULL; | |
152 if (extension_info_map) { | |
153 extensions::ExtensionSet extensions; | |
154 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin( | |
155 requesting_origin, | |
156 request_id.render_process_id(), | |
157 extensions::APIPermission::kNotifications, | |
158 &extensions); | |
159 for (extensions::ExtensionSet::const_iterator iter = extensions.begin(); | |
160 iter != extensions.end(); ++iter) { | |
161 if (IsNotifierEnabled(NotifierId( | |
162 NotifierId::APPLICATION, (*iter)->id()))) { | |
163 extension = iter->get(); | |
164 break; | |
165 } | |
166 } | |
167 } | |
168 if (IsExtensionWithPermissionOrSuggestInConsole( | |
169 extensions::APIPermission::kNotifications, | |
170 extension, | |
171 web_contents->GetRenderViewHost())) { | |
172 callback.Run(blink::WebNotificationPermissionAllowed); | |
173 return; | |
174 } | |
175 #endif | |
176 | |
177 | |
Peter Beverloo
2014/10/17 15:29:31
nit: double white line
Miguel Garcia
2014/10/17 16:21:41
Done.
| |
145 RequestPermission( | 178 RequestPermission( |
146 web_contents, | 179 web_contents, |
147 request_id, | 180 request_id, |
148 requesting_frame, | 181 requesting_origin, |
149 user_gesture, | 182 user_gesture, |
150 base::Bind(&DesktopNotificationService::OnNotificationPermissionRequested, | 183 base::Bind(&DesktopNotificationService::OnNotificationPermissionRequested, |
151 weak_factory_.GetWeakPtr(), | 184 weak_factory_.GetWeakPtr(), |
152 callback)); | 185 callback)); |
153 } | 186 } |
154 | 187 |
155 void DesktopNotificationService::ShowDesktopNotification( | 188 void DesktopNotificationService::ShowDesktopNotification( |
156 const content::ShowDesktopNotificationHostMsgParams& params, | 189 const content::ShowDesktopNotificationHostMsgParams& params, |
157 content::RenderFrameHost* render_frame_host, | 190 content::RenderFrameHost* render_frame_host, |
158 scoped_ptr<content::DesktopNotificationDelegate> delegate, | 191 scoped_ptr<content::DesktopNotificationDelegate> delegate, |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
353 // Tell the IO thread that this extension's permission for notifications | 386 // Tell the IO thread that this extension's permission for notifications |
354 // has changed. | 387 // has changed. |
355 extensions::InfoMap* extension_info_map = | 388 extensions::InfoMap* extension_info_map = |
356 extensions::ExtensionSystem::Get(profile_)->info_map(); | 389 extensions::ExtensionSystem::Get(profile_)->info_map(); |
357 BrowserThread::PostTask( | 390 BrowserThread::PostTask( |
358 BrowserThread::IO, FROM_HERE, | 391 BrowserThread::IO, FROM_HERE, |
359 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, | 392 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, |
360 extension_info_map, notifier_id.id, !enabled)); | 393 extension_info_map, notifier_id.id, !enabled)); |
361 #endif | 394 #endif |
362 } | 395 } |
OLD | NEW |