Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: chrome/browser/notifications/platform_notification_service_impl.cc

Issue 774573003: Start pulling away notification logic from ChromeContentBrowserClient. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/notifications/platform_notification_service_impl.h"
6
7 #include "chrome/browser/notifications/desktop_notification_service.h"
8 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/profiles/profile_io_data.h"
11 #include "components/content_settings/core/browser/host_content_settings_map.h"
12 #include "components/content_settings/core/common/content_settings.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/desktop_notification_delegate.h"
15 #include "content/public/common/show_desktop_notification_params.h"
16
17 #if defined(ENABLE_EXTENSIONS)
18 #include "extensions/browser/info_map.h"
19 #include "extensions/common/extension_set.h"
20 #include "extensions/common/permissions/api_permission.h"
21 #endif
22
23 using content::BrowserThread;
24
25 // static
26 PlatformNotificationServiceImpl*
27 PlatformNotificationServiceImpl::GetInstance() {
28 return Singleton<PlatformNotificationServiceImpl>::get();
29 }
30
31 PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() {}
32
33 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {}
34
35 blink::WebNotificationPermission
36 PlatformNotificationServiceImpl::CheckPermission(
37 content::ResourceContext* resource_context,
38 const GURL& origin,
39 int render_process_id) {
40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
41
42 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
43 #if defined(ENABLE_EXTENSIONS)
44 extensions::InfoMap* extension_info_map = io_data->GetExtensionInfoMap();
45
46 // We want to see if there is an extension that hasn't been manually disabled
47 // that has the notifications permission and applies to this security origin.
48 // First, get the list of extensions with permission for the origin.
49 extensions::ExtensionSet extensions;
50 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
51 origin,
52 render_process_id,
53 extensions::APIPermission::kNotifications,
54 &extensions);
55 for (const auto& extension : extensions) {
56 if (!extension_info_map->AreNotificationsDisabled(extension->id()))
57 return blink::WebNotificationPermissionAllowed;
58 }
59 #endif
60
61 // No enabled extensions exist, so check the normal host content settings.
62 HostContentSettingsMap* host_content_settings_map =
63 io_data->GetHostContentSettingsMap();
64 ContentSetting setting = host_content_settings_map->GetContentSetting(
65 origin,
66 origin,
67 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
68 NO_RESOURCE_IDENTIFIER);
69
70 if (setting == CONTENT_SETTING_ALLOW)
71 return blink::WebNotificationPermissionAllowed;
72 if (setting == CONTENT_SETTING_BLOCK)
73 return blink::WebNotificationPermissionDenied;
74
75 return blink::WebNotificationPermissionDefault;
76 }
77
78 void PlatformNotificationServiceImpl::DisplayNotification(
79 content::BrowserContext* browser_context,
80 const content::ShowDesktopNotificationHostMsgParams& params,
81 scoped_ptr<content::DesktopNotificationDelegate> delegate,
82 int render_process_id,
83 base::Closure* cancel_callback) {
84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
85
86 Profile* profile = Profile::FromBrowserContext(browser_context);
87 DCHECK(profile);
88
89 DesktopNotificationService* service =
90 DesktopNotificationServiceFactory::GetForProfile(profile);
91 DCHECK(service);
92
93 service->ShowDesktopNotification(
94 params, render_process_id, delegate.Pass(), cancel_callback);
95 profile->GetHostContentSettingsMap()->UpdateLastUsage(
96 params.origin, params.origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
97 }
OLDNEW
« no previous file with comments | « chrome/browser/notifications/platform_notification_service_impl.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698