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/content_settings/content_settings_details.h" | 14 #include "chrome/browser/content_settings/content_settings_details.h" |
15 #include "chrome/browser/content_settings/content_settings_provider.h" | 15 #include "chrome/browser/content_settings/content_settings_provider.h" |
16 #include "chrome/browser/content_settings/host_content_settings_map.h" | 16 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
17 #include "chrome/browser/infobars/infobar_service.h" | |
18 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 17 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
19 #include "chrome/browser/notifications/notification.h" | 18 #include "chrome/browser/notifications/notification.h" |
20 #include "chrome/browser/notifications/notification_object_proxy.h" | 19 #include "chrome/browser/notifications/notification_object_proxy.h" |
21 #include "chrome/browser/notifications/notification_ui_manager.h" | 20 #include "chrome/browser/notifications/notification_ui_manager.h" |
22 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" | 21 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" |
23 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_fac
tory.h" | 22 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_fac
tory.h" |
24 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
26 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | |
27 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | |
28 #include "chrome/common/content_settings.h" | |
29 #include "chrome/common/content_settings_pattern.h" | |
30 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
31 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
32 #include "components/infobars/core/confirm_infobar_delegate.h" | |
33 #include "components/infobars/core/infobar.h" | |
34 #include "components/pref_registry/pref_registry_syncable.h" | 27 #include "components/pref_registry/pref_registry_syncable.h" |
35 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
36 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
37 #include "content/public/browser/render_frame_host.h" | 30 #include "content/public/browser/render_frame_host.h" |
38 #include "content/public/browser/render_process_host.h" | 31 #include "content/public/browser/render_process_host.h" |
39 #include "content/public/browser/render_view_host.h" | 32 #include "content/public/browser/render_view_host.h" |
40 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
41 #include "content/public/common/show_desktop_notification_params.h" | 34 #include "content/public/common/show_desktop_notification_params.h" |
42 #include "grit/browser_resources.h" | 35 #include "grit/browser_resources.h" |
43 #include "grit/chromium_strings.h" | 36 #include "grit/chromium_strings.h" |
(...skipping 20 matching lines...) Expand all Loading... |
64 using blink::WebTextDirection; | 57 using blink::WebTextDirection; |
65 using content::BrowserThread; | 58 using content::BrowserThread; |
66 using content::RenderViewHost; | 59 using content::RenderViewHost; |
67 using content::WebContents; | 60 using content::WebContents; |
68 using message_center::NotifierId; | 61 using message_center::NotifierId; |
69 | 62 |
70 namespace { | 63 namespace { |
71 | 64 |
72 const char kChromeNowExtensionID[] = "pafkbggdmjlpgkdkcbjmhmfcdpncadgh"; | 65 const char kChromeNowExtensionID[] = "pafkbggdmjlpgkdkcbjmhmfcdpncadgh"; |
73 | 66 |
74 // NotificationPermissionRequest --------------------------------------- | |
75 | |
76 class NotificationPermissionRequest : public PermissionBubbleRequest { | |
77 public: | |
78 NotificationPermissionRequest( | |
79 DesktopNotificationService* notification_service, | |
80 const GURL& origin, | |
81 base::string16 display_name, | |
82 const base::Closure& callback); | |
83 virtual ~NotificationPermissionRequest(); | |
84 | |
85 // PermissionBubbleDelegate: | |
86 virtual int GetIconID() const OVERRIDE; | |
87 virtual base::string16 GetMessageText() const OVERRIDE; | |
88 virtual base::string16 GetMessageTextFragment() const OVERRIDE; | |
89 virtual bool HasUserGesture() const OVERRIDE; | |
90 virtual GURL GetRequestingHostname() const OVERRIDE; | |
91 virtual void PermissionGranted() OVERRIDE; | |
92 virtual void PermissionDenied() OVERRIDE; | |
93 virtual void Cancelled() OVERRIDE; | |
94 virtual void RequestFinished() OVERRIDE; | |
95 | |
96 private: | |
97 // The notification service to be used. | |
98 DesktopNotificationService* notification_service_; | |
99 | |
100 // The origin we are asking for permissions on. | |
101 GURL origin_; | |
102 | |
103 // The display name for the origin to be displayed. Will be different from | |
104 // origin_ for extensions. | |
105 base::string16 display_name_; | |
106 | |
107 // The callback information that tells us how to respond to javascript. | |
108 base::Closure callback_; | |
109 | |
110 // Whether the user clicked one of the buttons. | |
111 bool action_taken_; | |
112 | |
113 DISALLOW_COPY_AND_ASSIGN(NotificationPermissionRequest); | |
114 }; | |
115 | |
116 NotificationPermissionRequest::NotificationPermissionRequest( | |
117 DesktopNotificationService* notification_service, | |
118 const GURL& origin, | |
119 base::string16 display_name, | |
120 const base::Closure& callback) | |
121 : notification_service_(notification_service), | |
122 origin_(origin), | |
123 display_name_(display_name), | |
124 callback_(callback), | |
125 action_taken_(false) {} | |
126 | |
127 NotificationPermissionRequest::~NotificationPermissionRequest() {} | |
128 | |
129 int NotificationPermissionRequest::GetIconID() const { | |
130 return IDR_INFOBAR_DESKTOP_NOTIFICATIONS; | |
131 } | |
132 | |
133 base::string16 NotificationPermissionRequest::GetMessageText() const { | |
134 return l10n_util::GetStringFUTF16(IDS_NOTIFICATION_PERMISSIONS, | |
135 display_name_); | |
136 } | |
137 | |
138 base::string16 | |
139 NotificationPermissionRequest::GetMessageTextFragment() const { | |
140 return l10n_util::GetStringUTF16(IDS_NOTIFICATION_PERMISSIONS_FRAGMENT); | |
141 } | |
142 | |
143 bool NotificationPermissionRequest::HasUserGesture() const { | |
144 // Currently notification permission requests are only issued on | |
145 // user gesture. | |
146 return true; | |
147 } | |
148 | |
149 GURL NotificationPermissionRequest::GetRequestingHostname() const { | |
150 return origin_; | |
151 } | |
152 | |
153 void NotificationPermissionRequest::PermissionGranted() { | |
154 action_taken_ = true; | |
155 UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Allowed", 1); | |
156 notification_service_->GrantPermission(origin_); | |
157 } | |
158 | |
159 void NotificationPermissionRequest::PermissionDenied() { | |
160 action_taken_ = true; | |
161 UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Denied", 1); | |
162 notification_service_->DenyPermission(origin_); | |
163 } | |
164 | |
165 void NotificationPermissionRequest::Cancelled() { | |
166 } | |
167 | |
168 void NotificationPermissionRequest::RequestFinished() { | |
169 if (!action_taken_) | |
170 UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Ignored", 1); | |
171 | |
172 callback_.Run(); | |
173 | |
174 delete this; | |
175 } | |
176 | |
177 | |
178 // NotificationPermissionInfoBarDelegate -------------------------------------- | |
179 | |
180 // The delegate for the infobar shown when an origin requests notification | |
181 // permissions. | |
182 class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { | |
183 public: | |
184 // Creates a notification permission infobar and delegate and adds the infobar | |
185 // to |infobar_service|. | |
186 static void Create(InfoBarService* infobar_service, | |
187 DesktopNotificationService* notification_service, | |
188 const GURL& origin, | |
189 const base::string16& display_name, | |
190 const base::Closure& callback); | |
191 | |
192 private: | |
193 NotificationPermissionInfoBarDelegate( | |
194 DesktopNotificationService* notification_service, | |
195 const GURL& origin, | |
196 const base::string16& display_name, | |
197 const base::Closure& callback); | |
198 virtual ~NotificationPermissionInfoBarDelegate(); | |
199 | |
200 // ConfirmInfoBarDelegate: | |
201 virtual int GetIconID() const OVERRIDE; | |
202 virtual Type GetInfoBarType() const OVERRIDE; | |
203 virtual base::string16 GetMessageText() const OVERRIDE; | |
204 virtual base::string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | |
205 virtual bool Accept() OVERRIDE; | |
206 virtual bool Cancel() OVERRIDE; | |
207 | |
208 // The origin we are asking for permissions on. | |
209 GURL origin_; | |
210 | |
211 // The display name for the origin to be displayed. Will be different from | |
212 // origin_ for extensions. | |
213 base::string16 display_name_; | |
214 | |
215 // The notification service to be used. | |
216 DesktopNotificationService* notification_service_; | |
217 | |
218 // The callback information that tells us how to respond to javascript. | |
219 base::Closure callback_; | |
220 | |
221 // Whether the user clicked one of the buttons. | |
222 bool action_taken_; | |
223 | |
224 DISALLOW_COPY_AND_ASSIGN(NotificationPermissionInfoBarDelegate); | |
225 }; | |
226 | |
227 // static | |
228 void NotificationPermissionInfoBarDelegate::Create( | |
229 InfoBarService* infobar_service, | |
230 DesktopNotificationService* notification_service, | |
231 const GURL& origin, | |
232 const base::string16& display_name, | |
233 const base::Closure& callback) { | |
234 infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( | |
235 scoped_ptr<ConfirmInfoBarDelegate>( | |
236 new NotificationPermissionInfoBarDelegate( | |
237 notification_service, origin, display_name, callback)))); | |
238 } | |
239 | |
240 NotificationPermissionInfoBarDelegate::NotificationPermissionInfoBarDelegate( | |
241 DesktopNotificationService* notification_service, | |
242 const GURL& origin, | |
243 const base::string16& display_name, | |
244 const base::Closure& callback) | |
245 : ConfirmInfoBarDelegate(), | |
246 origin_(origin), | |
247 display_name_(display_name), | |
248 notification_service_(notification_service), | |
249 callback_(callback), | |
250 action_taken_(false) { | |
251 } | |
252 | |
253 NotificationPermissionInfoBarDelegate:: | |
254 ~NotificationPermissionInfoBarDelegate() { | |
255 if (!action_taken_) | |
256 UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Ignored", 1); | |
257 | |
258 callback_.Run(); | |
259 } | |
260 | |
261 int NotificationPermissionInfoBarDelegate::GetIconID() const { | |
262 return IDR_INFOBAR_DESKTOP_NOTIFICATIONS; | |
263 } | |
264 | |
265 infobars::InfoBarDelegate::Type | |
266 NotificationPermissionInfoBarDelegate::GetInfoBarType() const { | |
267 return PAGE_ACTION_TYPE; | |
268 } | |
269 | |
270 base::string16 NotificationPermissionInfoBarDelegate::GetMessageText() const { | |
271 return l10n_util::GetStringFUTF16(IDS_NOTIFICATION_PERMISSIONS, | |
272 display_name_); | |
273 } | |
274 | |
275 base::string16 NotificationPermissionInfoBarDelegate::GetButtonLabel( | |
276 InfoBarButton button) const { | |
277 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | |
278 IDS_NOTIFICATION_PERMISSION_YES : IDS_NOTIFICATION_PERMISSION_NO); | |
279 } | |
280 | |
281 bool NotificationPermissionInfoBarDelegate::Accept() { | |
282 UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Allowed", 1); | |
283 notification_service_->GrantPermission(origin_); | |
284 action_taken_ = true; | |
285 return true; | |
286 } | |
287 | |
288 bool NotificationPermissionInfoBarDelegate::Cancel() { | |
289 UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Denied", 1); | |
290 notification_service_->DenyPermission(origin_); | |
291 action_taken_ = true; | |
292 return true; | |
293 } | |
294 | 67 |
295 void CancelNotification(const std::string& id) { | 68 void CancelNotification(const std::string& id) { |
296 g_browser_process->notification_ui_manager()->CancelById(id); | 69 g_browser_process->notification_ui_manager()->CancelById(id); |
297 } | 70 } |
298 | 71 |
299 } // namespace | 72 } // namespace |
300 | 73 |
301 | 74 |
302 // DesktopNotificationService ------------------------------------------------- | 75 // DesktopNotificationService ------------------------------------------------- |
303 | 76 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 Notification notification(origin_url, icon, title, message, | 152 Notification notification(origin_url, icon, title, message, |
380 blink::WebTextDirectionDefault, | 153 blink::WebTextDirectionDefault, |
381 base::string16(), replace_id, delegate); | 154 base::string16(), replace_id, delegate); |
382 g_browser_process->notification_ui_manager()->Add(notification, profile); | 155 g_browser_process->notification_ui_manager()->Add(notification, profile); |
383 return notification.delegate_id(); | 156 return notification.delegate_id(); |
384 } | 157 } |
385 | 158 |
386 DesktopNotificationService::DesktopNotificationService( | 159 DesktopNotificationService::DesktopNotificationService( |
387 Profile* profile, | 160 Profile* profile, |
388 NotificationUIManager* ui_manager) | 161 NotificationUIManager* ui_manager) |
389 : profile_(profile), | 162 : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS), |
| 163 profile_(profile), |
390 ui_manager_(ui_manager) { | 164 ui_manager_(ui_manager) { |
391 OnStringListPrefChanged( | 165 OnStringListPrefChanged( |
392 prefs::kMessageCenterDisabledExtensionIds, &disabled_extension_ids_); | 166 prefs::kMessageCenterDisabledExtensionIds, &disabled_extension_ids_); |
393 OnStringListPrefChanged( | 167 OnStringListPrefChanged( |
394 prefs::kMessageCenterDisabledSystemComponentIds, | 168 prefs::kMessageCenterDisabledSystemComponentIds, |
395 &disabled_system_component_ids_); | 169 &disabled_system_component_ids_); |
396 disabled_extension_id_pref_.Init( | 170 disabled_extension_id_pref_.Init( |
397 prefs::kMessageCenterDisabledExtensionIds, | 171 prefs::kMessageCenterDisabledExtensionIds, |
398 profile_->GetPrefs(), | 172 profile_->GetPrefs(), |
399 base::Bind( | 173 base::Bind( |
(...skipping 10 matching lines...) Expand all Loading... |
410 base::Unretained(prefs::kMessageCenterDisabledSystemComponentIds), | 184 base::Unretained(prefs::kMessageCenterDisabledSystemComponentIds), |
411 base::Unretained(&disabled_system_component_ids_))); | 185 base::Unretained(&disabled_system_component_ids_))); |
412 registrar_.Add(this, | 186 registrar_.Add(this, |
413 chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED, | 187 chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED, |
414 content::Source<Profile>(profile_)); | 188 content::Source<Profile>(profile_)); |
415 } | 189 } |
416 | 190 |
417 DesktopNotificationService::~DesktopNotificationService() { | 191 DesktopNotificationService::~DesktopNotificationService() { |
418 } | 192 } |
419 | 193 |
420 void DesktopNotificationService::GrantPermission(const GURL& origin) { | |
421 ContentSettingsPattern primary_pattern = | |
422 ContentSettingsPattern::FromURLNoWildcard(origin); | |
423 profile_->GetHostContentSettingsMap()->SetContentSetting( | |
424 primary_pattern, | |
425 ContentSettingsPattern::Wildcard(), | |
426 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
427 NO_RESOURCE_IDENTIFIER, | |
428 CONTENT_SETTING_ALLOW); | |
429 } | |
430 | |
431 void DesktopNotificationService::DenyPermission(const GURL& origin) { | |
432 ContentSettingsPattern primary_pattern = | |
433 ContentSettingsPattern::FromURLNoWildcard(origin); | |
434 profile_->GetHostContentSettingsMap()->SetContentSetting( | |
435 primary_pattern, | |
436 ContentSettingsPattern::Wildcard(), | |
437 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
438 NO_RESOURCE_IDENTIFIER, | |
439 CONTENT_SETTING_BLOCK); | |
440 } | |
441 | |
442 ContentSetting DesktopNotificationService::GetDefaultContentSetting( | |
443 std::string* provider_id) { | |
444 return profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( | |
445 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, provider_id); | |
446 } | |
447 | |
448 void DesktopNotificationService::SetDefaultContentSetting( | |
449 ContentSetting setting) { | |
450 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( | |
451 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting); | |
452 } | |
453 | |
454 void DesktopNotificationService::ResetToDefaultContentSetting() { | |
455 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( | |
456 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_DEFAULT); | |
457 } | |
458 | |
459 void DesktopNotificationService::GetNotificationsSettings( | |
460 ContentSettingsForOneType* settings) { | |
461 profile_->GetHostContentSettingsMap()->GetSettingsForOneType( | |
462 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
463 NO_RESOURCE_IDENTIFIER, | |
464 settings); | |
465 } | |
466 | |
467 void DesktopNotificationService::ClearSetting( | |
468 const ContentSettingsPattern& pattern) { | |
469 profile_->GetHostContentSettingsMap()->SetContentSetting( | |
470 pattern, | |
471 ContentSettingsPattern::Wildcard(), | |
472 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
473 NO_RESOURCE_IDENTIFIER, | |
474 CONTENT_SETTING_DEFAULT); | |
475 } | |
476 | |
477 void DesktopNotificationService::ResetAllOrigins() { | |
478 profile_->GetHostContentSettingsMap()->ClearSettingsForOneType( | |
479 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
480 } | |
481 | |
482 ContentSetting DesktopNotificationService::GetContentSetting( | |
483 const GURL& origin) { | |
484 return profile_->GetHostContentSettingsMap()->GetContentSetting( | |
485 origin, | |
486 origin, | |
487 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
488 NO_RESOURCE_IDENTIFIER); | |
489 } | |
490 | |
491 void DesktopNotificationService::RequestPermission( | |
492 const GURL& origin, | |
493 content::RenderFrameHost* render_frame_host, | |
494 const base::Closure& callback) { | |
495 // If |origin| hasn't been seen before and the default content setting for | |
496 // notifications is "ask", show an infobar. | |
497 // The cache can only answer queries on the IO thread once it's initialized, | |
498 // so don't ask the cache. | |
499 WebContents* web_contents = WebContents::FromRenderFrameHost( | |
500 render_frame_host); | |
501 ContentSetting setting = GetContentSetting(origin); | |
502 if (setting == CONTENT_SETTING_ASK) { | |
503 if (PermissionBubbleManager::Enabled()) { | |
504 PermissionBubbleManager* bubble_manager = | |
505 PermissionBubbleManager::FromWebContents(web_contents); | |
506 if (bubble_manager) { | |
507 bubble_manager->AddRequest(new NotificationPermissionRequest( | |
508 this, | |
509 origin, | |
510 DisplayNameForOriginInProcessId( | |
511 origin, render_frame_host->GetProcess()->GetID()), | |
512 callback)); | |
513 } | |
514 return; | |
515 } | |
516 | |
517 // Show an info bar requesting permission. | |
518 InfoBarService* infobar_service = | |
519 InfoBarService::FromWebContents(web_contents); | |
520 // |infobar_service| may be NULL, e.g., if this request originated in a | |
521 // browser action popup, extension background page, or any HTML that runs | |
522 // outside of a tab. | |
523 if (infobar_service) { | |
524 NotificationPermissionInfoBarDelegate::Create( | |
525 infobar_service, this, origin, | |
526 DisplayNameForOriginInProcessId( | |
527 origin, render_frame_host->GetProcess()->GetID()), | |
528 callback); | |
529 return; | |
530 } | |
531 } | |
532 | |
533 // Notify renderer immediately. | |
534 callback.Run(); | |
535 } | |
536 | |
537 void DesktopNotificationService::ShowDesktopNotification( | 194 void DesktopNotificationService::ShowDesktopNotification( |
538 const content::ShowDesktopNotificationHostMsgParams& params, | 195 const content::ShowDesktopNotificationHostMsgParams& params, |
539 content::RenderFrameHost* render_frame_host, | 196 content::RenderFrameHost* render_frame_host, |
540 content::DesktopNotificationDelegate* delegate, | 197 content::DesktopNotificationDelegate* delegate, |
541 base::Closure* cancel_callback) { | 198 base::Closure* cancel_callback) { |
542 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
543 const GURL& origin = params.origin; | 200 const GURL& origin = params.origin; |
544 NotificationObjectProxy* proxy = | 201 NotificationObjectProxy* proxy = |
545 new NotificationObjectProxy(render_frame_host, delegate); | 202 new NotificationObjectProxy(render_frame_host, delegate); |
546 | 203 |
(...skipping 29 matching lines...) Expand all Loading... |
576 if (IsNotifierEnabled(notifier_id)) | 233 if (IsNotifierEnabled(notifier_id)) |
577 return base::UTF8ToUTF16((*iter)->name()); | 234 return base::UTF8ToUTF16((*iter)->name()); |
578 } | 235 } |
579 } | 236 } |
580 } | 237 } |
581 #endif | 238 #endif |
582 | 239 |
583 return base::UTF8ToUTF16(origin.host()); | 240 return base::UTF8ToUTF16(origin.host()); |
584 } | 241 } |
585 | 242 |
586 void DesktopNotificationService::NotifySettingsChange() { | |
587 content::NotificationService::current()->Notify( | |
588 chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, | |
589 content::Source<DesktopNotificationService>(this), | |
590 content::NotificationService::NoDetails()); | |
591 } | |
592 | |
593 NotificationUIManager* DesktopNotificationService::GetUIManager() { | 243 NotificationUIManager* DesktopNotificationService::GetUIManager() { |
594 // We defer setting ui_manager_ to the global singleton until we need it | 244 // We defer setting ui_manager_ to the global singleton until we need it |
595 // in order to avoid UI dependent construction during startup. | 245 // in order to avoid UI dependent construction during startup. |
596 if (!ui_manager_) | 246 if (!ui_manager_) |
597 ui_manager_ = g_browser_process->notification_ui_manager(); | 247 ui_manager_ = g_browser_process->notification_ui_manager(); |
598 return ui_manager_; | 248 return ui_manager_; |
599 } | 249 } |
600 | 250 |
601 bool DesktopNotificationService::IsNotifierEnabled( | 251 bool DesktopNotificationService::IsNotifierEnabled( |
602 const NotifierId& notifier_id) { | 252 const NotifierId& notifier_id) { |
603 switch (notifier_id.type) { | 253 switch (notifier_id.type) { |
604 case NotifierId::APPLICATION: | 254 case NotifierId::APPLICATION: |
605 return disabled_extension_ids_.find(notifier_id.id) == | 255 return disabled_extension_ids_.find(notifier_id.id) == |
606 disabled_extension_ids_.end(); | 256 disabled_extension_ids_.end(); |
607 case NotifierId::WEB_PAGE: | 257 case NotifierId::WEB_PAGE: |
608 return GetContentSetting(notifier_id.url) == CONTENT_SETTING_ALLOW; | 258 return DesktopNotificationProfileUtil::GetContentSetting( |
| 259 profile_, notifier_id.url) == CONTENT_SETTING_ALLOW; |
609 case NotifierId::SYSTEM_COMPONENT: | 260 case NotifierId::SYSTEM_COMPONENT: |
610 #if defined(OS_CHROMEOS) | 261 #if defined(OS_CHROMEOS) |
611 return disabled_system_component_ids_.find(notifier_id.id) == | 262 return disabled_system_component_ids_.find(notifier_id.id) == |
612 disabled_system_component_ids_.end(); | 263 disabled_system_component_ids_.end(); |
613 #else | 264 #else |
614 // We do not disable system component notifications. | 265 // We do not disable system component notifications. |
615 return true; | 266 return true; |
616 #endif | 267 #endif |
617 } | 268 } |
618 | 269 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 // Tell the IO thread that this extension's permission for notifications | 380 // Tell the IO thread that this extension's permission for notifications |
730 // has changed. | 381 // has changed. |
731 extensions::InfoMap* extension_info_map = | 382 extensions::InfoMap* extension_info_map = |
732 extensions::ExtensionSystem::Get(profile_)->info_map(); | 383 extensions::ExtensionSystem::Get(profile_)->info_map(); |
733 BrowserThread::PostTask( | 384 BrowserThread::PostTask( |
734 BrowserThread::IO, FROM_HERE, | 385 BrowserThread::IO, FROM_HERE, |
735 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, | 386 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, |
736 extension_info_map, notifier_id.id, !enabled)); | 387 extension_info_map, notifier_id.id, !enabled)); |
737 #endif | 388 #endif |
738 } | 389 } |
OLD | NEW |