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" |
11 #include "base/metrics/user_metrics.h" | 11 #include "base/metrics/user_metrics.h" |
12 #include "base/metrics/user_metrics_action.h" | 12 #include "base/metrics/user_metrics_action.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/time/time.h" |
14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 17 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
17 #include "chrome/browser/engagement/site_engagement_service.h" | 18 #include "chrome/browser/engagement/site_engagement_service.h" |
18 #include "chrome/browser/notifications/notification_display_service_factory.h" | 19 #include "chrome/browser/notifications/notification_display_service_factory.h" |
19 #include "chrome/browser/notifications/notification_object_proxy.h" | 20 #include "chrome/browser/notifications/notification_object_proxy.h" |
20 #include "chrome/browser/notifications/persistent_notification_delegate.h" | 21 #include "chrome/browser/notifications/persistent_notification_delegate.h" |
| 22 #include "chrome/browser/permissions/permission_decision_auto_blocker.h" |
21 #include "chrome/browser/permissions/permission_manager.h" | 23 #include "chrome/browser/permissions/permission_manager.h" |
22 #include "chrome/browser/permissions/permission_result.h" | 24 #include "chrome/browser/permissions/permission_result.h" |
23 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/profiles/profile_attributes_storage.h" | 26 #include "chrome/browser/profiles/profile_attributes_storage.h" |
25 #include "chrome/browser/profiles/profile_io_data.h" | 27 #include "chrome/browser/profiles/profile_io_data.h" |
26 #include "chrome/browser/profiles/profile_manager.h" | 28 #include "chrome/browser/profiles/profile_manager.h" |
27 #include "chrome/browser/safe_browsing/ping_manager.h" | 29 #include "chrome/browser/safe_browsing/ping_manager.h" |
28 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 30 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
29 #include "chrome/browser/ui/browser.h" | 31 #include "chrome/browser/ui/browser.h" |
30 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 origin, | 282 origin, |
281 origin, | 283 origin, |
282 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 284 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
283 content_settings::ResourceIdentifier()); | 285 content_settings::ResourceIdentifier()); |
284 | 286 |
285 if (setting == CONTENT_SETTING_ALLOW) | 287 if (setting == CONTENT_SETTING_ALLOW) |
286 return blink::mojom::PermissionStatus::GRANTED; | 288 return blink::mojom::PermissionStatus::GRANTED; |
287 if (setting == CONTENT_SETTING_BLOCK) | 289 if (setting == CONTENT_SETTING_BLOCK) |
288 return blink::mojom::PermissionStatus::DENIED; | 290 return blink::mojom::PermissionStatus::DENIED; |
289 | 291 |
290 return blink::mojom::PermissionStatus::ASK; | 292 // Check whether the permission has been embargoed (automatically blocked). |
| 293 // TODO(crbug.com/658020): make PermissionManager::GetPermissionStatus thread |
| 294 // safe so it isn't necessary to do this HostContentSettingsMap and embargo |
| 295 // check outside of the permissions code. |
| 296 PermissionResult result = PermissionDecisionAutoBlocker::GetEmbargoResult( |
| 297 host_content_settings_map, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 298 base::Time::Now()); |
| 299 DCHECK(result.content_setting == CONTENT_SETTING_ASK || |
| 300 result.content_setting == CONTENT_SETTING_BLOCK); |
| 301 return result.content_setting == CONTENT_SETTING_ASK |
| 302 ? blink::mojom::PermissionStatus::ASK |
| 303 : blink::mojom::PermissionStatus::DENIED; |
291 } | 304 } |
292 | 305 |
293 void PlatformNotificationServiceImpl::DisplayNotification( | 306 void PlatformNotificationServiceImpl::DisplayNotification( |
294 BrowserContext* browser_context, | 307 BrowserContext* browser_context, |
295 const std::string& notification_id, | 308 const std::string& notification_id, |
296 const GURL& origin, | 309 const GURL& origin, |
297 const content::PlatformNotificationData& notification_data, | 310 const content::PlatformNotificationData& notification_data, |
298 const content::NotificationResources& notification_resources, | 311 const content::NotificationResources& notification_resources, |
299 std::unique_ptr<content::DesktopNotificationDelegate> delegate, | 312 std::unique_ptr<content::DesktopNotificationDelegate> delegate, |
300 base::Closure* cancel_callback) { | 313 base::Closure* cancel_callback) { |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 | 548 |
536 void PlatformNotificationServiceImpl::RecordSiteEngagement( | 549 void PlatformNotificationServiceImpl::RecordSiteEngagement( |
537 BrowserContext* browser_context, | 550 BrowserContext* browser_context, |
538 const GURL& origin) { | 551 const GURL& origin) { |
539 // TODO(dominickn, peter): This would be better if the site engagement service | 552 // TODO(dominickn, peter): This would be better if the site engagement service |
540 // could directly observe each notification. | 553 // could directly observe each notification. |
541 SiteEngagementService* engagement_service = | 554 SiteEngagementService* engagement_service = |
542 SiteEngagementService::Get(Profile::FromBrowserContext(browser_context)); | 555 SiteEngagementService::Get(Profile::FromBrowserContext(browser_context)); |
543 engagement_service->HandleNotificationInteraction(origin); | 556 engagement_service->HandleNotificationInteraction(origin); |
544 } | 557 } |
OLD | NEW |