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 "chrome/browser/notifications/platform_notification_service_impl.h" | 5 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "components/content_settings/core/common/content_settings.h" | 28 #include "components/content_settings/core/common/content_settings.h" |
29 #include "components/content_settings/core/common/content_settings_types.h" | 29 #include "components/content_settings/core/common/content_settings_types.h" |
30 #include "components/prefs/pref_service.h" | 30 #include "components/prefs/pref_service.h" |
31 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
32 #include "content/public/browser/desktop_notification_delegate.h" | 32 #include "content/public/browser/desktop_notification_delegate.h" |
33 #include "content/public/browser/notification_event_dispatcher.h" | 33 #include "content/public/browser/notification_event_dispatcher.h" |
34 #include "content/public/browser/permission_type.h" | 34 #include "content/public/browser/permission_type.h" |
35 #include "content/public/browser/user_metrics.h" | 35 #include "content/public/browser/user_metrics.h" |
36 #include "content/public/common/notification_resources.h" | 36 #include "content/public/common/notification_resources.h" |
37 #include "content/public/common/platform_notification_data.h" | 37 #include "content/public/common/platform_notification_data.h" |
| 38 #include "extensions/features/features.h" |
38 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
39 #include "ui/base/resource/resource_bundle.h" | 40 #include "ui/base/resource/resource_bundle.h" |
40 #include "ui/message_center/notification.h" | 41 #include "ui/message_center/notification.h" |
41 #include "ui/message_center/notification_types.h" | 42 #include "ui/message_center/notification_types.h" |
42 #include "ui/message_center/notifier_settings.h" | 43 #include "ui/message_center/notifier_settings.h" |
43 #include "url/url_constants.h" | 44 #include "url/url_constants.h" |
44 | 45 |
45 #if BUILDFLAG(ENABLE_BACKGROUND) | 46 #if BUILDFLAG(ENABLE_BACKGROUND) |
46 #include "chrome/browser/lifetime/keep_alive_types.h" | 47 #include "chrome/browser/lifetime/keep_alive_types.h" |
47 #include "chrome/browser/lifetime/scoped_keep_alive.h" | 48 #include "chrome/browser/lifetime/scoped_keep_alive.h" |
48 #endif | 49 #endif |
49 | 50 |
50 #if defined(ENABLE_EXTENSIONS) | 51 #if BUILDFLAG(ENABLE_EXTENSIONS) |
51 #include "chrome/browser/notifications/notifier_state_tracker.h" | 52 #include "chrome/browser/notifications/notifier_state_tracker.h" |
52 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" | 53 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" |
53 #include "extensions/browser/extension_registry.h" | 54 #include "extensions/browser/extension_registry.h" |
54 #include "extensions/browser/info_map.h" | 55 #include "extensions/browser/info_map.h" |
55 #include "extensions/common/constants.h" | 56 #include "extensions/common/constants.h" |
56 #include "extensions/common/permissions/api_permission.h" | 57 #include "extensions/common/permissions/api_permission.h" |
57 #include "extensions/common/permissions/permissions_data.h" | 58 #include "extensions/common/permissions/permissions_data.h" |
58 #endif | 59 #endif |
59 | 60 |
60 using content::BrowserContext; | 61 using content::BrowserContext; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 blink::mojom::PermissionStatus | 177 blink::mojom::PermissionStatus |
177 PlatformNotificationServiceImpl::CheckPermissionOnUIThread( | 178 PlatformNotificationServiceImpl::CheckPermissionOnUIThread( |
178 BrowserContext* browser_context, | 179 BrowserContext* browser_context, |
179 const GURL& origin, | 180 const GURL& origin, |
180 int render_process_id) { | 181 int render_process_id) { |
181 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 182 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
182 | 183 |
183 Profile* profile = Profile::FromBrowserContext(browser_context); | 184 Profile* profile = Profile::FromBrowserContext(browser_context); |
184 DCHECK(profile); | 185 DCHECK(profile); |
185 | 186 |
186 #if defined(ENABLE_EXTENSIONS) | 187 #if BUILDFLAG(ENABLE_EXTENSIONS) |
187 // Extensions support an API permission named "notification". This will grant | 188 // Extensions support an API permission named "notification". This will grant |
188 // not only grant permission for using the Chrome App extension API, but also | 189 // not only grant permission for using the Chrome App extension API, but also |
189 // for the Web Notification API. | 190 // for the Web Notification API. |
190 if (origin.SchemeIs(extensions::kExtensionScheme)) { | 191 if (origin.SchemeIs(extensions::kExtensionScheme)) { |
191 extensions::ExtensionRegistry* registry = | 192 extensions::ExtensionRegistry* registry = |
192 extensions::ExtensionRegistry::Get(browser_context); | 193 extensions::ExtensionRegistry::Get(browser_context); |
193 extensions::ProcessMap* process_map = | 194 extensions::ProcessMap* process_map = |
194 extensions::ProcessMap::Get(browser_context); | 195 extensions::ProcessMap::Get(browser_context); |
195 | 196 |
196 const extensions::Extension* extension = | 197 const extensions::Extension* extension = |
(...skipping 20 matching lines...) Expand all Loading... |
217 } | 218 } |
218 | 219 |
219 blink::mojom::PermissionStatus | 220 blink::mojom::PermissionStatus |
220 PlatformNotificationServiceImpl::CheckPermissionOnIOThread( | 221 PlatformNotificationServiceImpl::CheckPermissionOnIOThread( |
221 content::ResourceContext* resource_context, | 222 content::ResourceContext* resource_context, |
222 const GURL& origin, | 223 const GURL& origin, |
223 int render_process_id) { | 224 int render_process_id) { |
224 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 225 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
225 | 226 |
226 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); | 227 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
227 #if defined(ENABLE_EXTENSIONS) | 228 #if BUILDFLAG(ENABLE_EXTENSIONS) |
228 // Extensions support an API permission named "notification". This will grant | 229 // Extensions support an API permission named "notification". This will grant |
229 // not only grant permission for using the Chrome App extension API, but also | 230 // not only grant permission for using the Chrome App extension API, but also |
230 // for the Web Notification API. | 231 // for the Web Notification API. |
231 if (origin.SchemeIs(extensions::kExtensionScheme)) { | 232 if (origin.SchemeIs(extensions::kExtensionScheme)) { |
232 extensions::InfoMap* extension_info_map = io_data->GetExtensionInfoMap(); | 233 extensions::InfoMap* extension_info_map = io_data->GetExtensionInfoMap(); |
233 const extensions::ProcessMap& process_map = | 234 const extensions::ProcessMap& process_map = |
234 extension_info_map->process_map(); | 235 extension_info_map->process_map(); |
235 | 236 |
236 const extensions::Extension* extension = | 237 const extensions::Extension* extension = |
237 extension_info_map->extensions().GetByID(origin.host()); | 238 extension_info_map->extensions().GetByID(origin.host()); |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 PlatformNotificationServiceImpl::GetNotificationDisplayService( | 478 PlatformNotificationServiceImpl::GetNotificationDisplayService( |
478 Profile* profile) { | 479 Profile* profile) { |
479 return test_display_service_ | 480 return test_display_service_ |
480 ? test_display_service_ | 481 ? test_display_service_ |
481 : NotificationDisplayServiceFactory::GetForProfile(profile); | 482 : NotificationDisplayServiceFactory::GetForProfile(profile); |
482 } | 483 } |
483 | 484 |
484 base::string16 PlatformNotificationServiceImpl::DisplayNameForContextMessage( | 485 base::string16 PlatformNotificationServiceImpl::DisplayNameForContextMessage( |
485 Profile* profile, | 486 Profile* profile, |
486 const GURL& origin) const { | 487 const GURL& origin) const { |
487 #if defined(ENABLE_EXTENSIONS) | 488 #if BUILDFLAG(ENABLE_EXTENSIONS) |
488 // If the source is an extension, lookup the display name. | 489 // If the source is an extension, lookup the display name. |
489 if (origin.SchemeIs(extensions::kExtensionScheme)) { | 490 if (origin.SchemeIs(extensions::kExtensionScheme)) { |
490 const extensions::Extension* extension = | 491 const extensions::Extension* extension = |
491 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( | 492 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( |
492 origin.host(), extensions::ExtensionRegistry::EVERYTHING); | 493 origin.host(), extensions::ExtensionRegistry::EVERYTHING); |
493 DCHECK(extension); | 494 DCHECK(extension); |
494 | 495 |
495 return base::UTF8ToUTF16(extension->name()); | 496 return base::UTF8ToUTF16(extension->name()); |
496 } | 497 } |
497 #endif | 498 #endif |
498 | 499 |
499 return base::string16(); | 500 return base::string16(); |
500 } | 501 } |
501 | 502 |
502 void PlatformNotificationServiceImpl::SetNotificationDisplayServiceForTesting( | 503 void PlatformNotificationServiceImpl::SetNotificationDisplayServiceForTesting( |
503 NotificationDisplayService* display_service) { | 504 NotificationDisplayService* display_service) { |
504 test_display_service_ = display_service; | 505 test_display_service_ = display_service; |
505 } | 506 } |
OLD | NEW |