OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/content_settings/content_settings_details.h" |
| 11 #include "chrome/browser/content_settings/content_settings_pattern.h" |
10 #include "chrome/browser/content_settings/content_settings_provider.h" | 12 #include "chrome/browser/content_settings/content_settings_provider.h" |
11 #include "chrome/browser/content_settings/host_content_settings_map.h" | 13 #include "chrome/browser/content_settings/host_content_settings_map.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
13 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 15 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
14 #include "chrome/browser/notifications/notification.h" | 16 #include "chrome/browser/notifications/notification.h" |
15 #include "chrome/browser/notifications/notification_object_proxy.h" | 17 #include "chrome/browser/notifications/notification_object_proxy.h" |
16 #include "chrome/browser/notifications/notification_ui_manager.h" | 18 #include "chrome/browser/notifications/notification_ui_manager.h" |
17 #include "chrome/browser/notifications/notifications_prefs_cache.h" | |
18 #include "chrome/browser/prefs/pref_service.h" | 19 #include "chrome/browser/prefs/pref_service.h" |
19 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 20 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 22 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
22 #include "chrome/browser/ui/browser_list.h" | 23 #include "chrome/browser/ui/browser_list.h" |
23 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
24 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
25 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
26 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
27 #include "content/browser/browser_child_process_host.h" | 28 #include "content/browser/browser_child_process_host.h" |
(...skipping 10 matching lines...) Expand all Loading... |
38 #include "grit/theme_resources.h" | 39 #include "grit/theme_resources.h" |
39 #include "net/base/escape.h" | 40 #include "net/base/escape.h" |
40 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
41 #include "ui/base/resource/resource_bundle.h" | 42 #include "ui/base/resource/resource_bundle.h" |
42 | 43 |
43 using WebKit::WebNotificationPresenter; | 44 using WebKit::WebNotificationPresenter; |
44 using WebKit::WebTextDirection; | 45 using WebKit::WebTextDirection; |
45 | 46 |
46 const ContentSetting kDefaultSetting = CONTENT_SETTING_ASK; | 47 const ContentSetting kDefaultSetting = CONTENT_SETTING_ASK; |
47 | 48 |
48 namespace { | |
49 | |
50 typedef content_settings::ProviderInterface::Rules Rules; | |
51 | |
52 void GetOriginsWithSettingFromContentSettingsRules( | |
53 const Rules& content_setting_rules, | |
54 ContentSetting setting, | |
55 std::vector<GURL>* origins) { | |
56 origins->clear(); | |
57 | |
58 for (Rules::const_iterator rule = content_setting_rules.begin(); | |
59 rule != content_setting_rules.end(); | |
60 ++rule) { | |
61 if (setting == rule->content_setting) { | |
62 std::string url_str = rule->primary_pattern.ToString(); | |
63 if (!rule->primary_pattern.IsValid()) { | |
64 // TODO(markusheintz): This will be removed in one of the next | |
65 // refactoring steps as this entire function will disapear. | |
66 LOG(DFATAL) << "Ignoring invalid content settings pattern: " | |
67 << url_str; | |
68 } else if (url_str.find(ContentSettingsPattern::kDomainWildcard) == 0) { | |
69 // TODO(markusheintz): This must be changed once the UI code is | |
70 // refactored and content_settings patterns are fully supported for | |
71 // notifications settings. | |
72 LOG(DFATAL) << "Ignoring unsupported content settings pattern: " | |
73 << url_str << ". Content settings patterns other than " | |
74 << "hostnames (e.g. wildcard patterns) are not supported " | |
75 << "for notification content settings yet."; | |
76 } else { | |
77 origins->push_back( | |
78 content_settings::NotificationProvider::ToGURL( | |
79 rule->primary_pattern)); | |
80 } | |
81 } | |
82 } | |
83 } | |
84 | |
85 } // namespace | |
86 | |
87 // NotificationPermissionInfoBarDelegate -------------------------------------- | 49 // NotificationPermissionInfoBarDelegate -------------------------------------- |
88 | 50 |
89 // The delegate for the infobar shown when an origin requests notification | 51 // The delegate for the infobar shown when an origin requests notification |
90 // permissions. | 52 // permissions. |
91 class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { | 53 class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { |
92 public: | 54 public: |
93 NotificationPermissionInfoBarDelegate(TabContents* contents, | 55 NotificationPermissionInfoBarDelegate(TabContents* contents, |
94 const GURL& origin, | 56 const GURL& origin, |
95 const string16& display_name, | 57 const string16& display_name, |
96 int process_id, | 58 int process_id, |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 207 |
246 std::string data = ReplaceStringPlaceholders(template_html, subst, NULL); | 208 std::string data = ReplaceStringPlaceholders(template_html, subst, NULL); |
247 return UTF8ToUTF16("data:text/html;charset=utf-8," + | 209 return UTF8ToUTF16("data:text/html;charset=utf-8," + |
248 EscapeQueryParamValue(data, false)); | 210 EscapeQueryParamValue(data, false)); |
249 } | 211 } |
250 | 212 |
251 DesktopNotificationService::DesktopNotificationService(Profile* profile, | 213 DesktopNotificationService::DesktopNotificationService(Profile* profile, |
252 NotificationUIManager* ui_manager) | 214 NotificationUIManager* ui_manager) |
253 : profile_(profile), | 215 : profile_(profile), |
254 ui_manager_(ui_manager) { | 216 ui_manager_(ui_manager) { |
255 prefs_registrar_.Init(profile_->GetPrefs()); | |
256 InitPrefs(); | |
257 StartObserving(); | 217 StartObserving(); |
258 } | 218 } |
259 | 219 |
260 DesktopNotificationService::~DesktopNotificationService() { | 220 DesktopNotificationService::~DesktopNotificationService() { |
261 StopObserving(); | 221 StopObserving(); |
262 } | 222 } |
263 | 223 |
264 void DesktopNotificationService::RegisterUserPrefs(PrefService* user_prefs) { | |
265 content_settings::NotificationProvider::RegisterUserPrefs(user_prefs); | |
266 } | |
267 | |
268 // Initialize the cache with the allowed and denied origins, or | |
269 // create the preferences if they don't exist yet. | |
270 void DesktopNotificationService::InitPrefs() { | |
271 provider_.reset(new content_settings::NotificationProvider(profile_)); | |
272 | |
273 std::vector<GURL> allowed_origins; | |
274 std::vector<GURL> denied_origins; | |
275 ContentSetting default_content_setting = CONTENT_SETTING_DEFAULT; | |
276 | |
277 if (!profile_->IsOffTheRecord()) { | |
278 default_content_setting = | |
279 profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( | |
280 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
281 allowed_origins = GetAllowedOrigins(); | |
282 denied_origins = GetBlockedOrigins(); | |
283 } | |
284 | |
285 prefs_cache_ = new NotificationsPrefsCache(); | |
286 prefs_cache_->SetCacheDefaultContentSetting(default_content_setting); | |
287 prefs_cache_->SetCacheAllowedOrigins(allowed_origins); | |
288 prefs_cache_->SetCacheDeniedOrigins(denied_origins); | |
289 prefs_cache_->set_is_initialized(true); | |
290 } | |
291 | |
292 void DesktopNotificationService::StartObserving() { | 224 void DesktopNotificationService::StartObserving() { |
293 if (!profile_->IsOffTheRecord()) { | 225 if (!profile_->IsOffTheRecord()) { |
294 prefs_registrar_.Add(prefs::kDesktopNotificationAllowedOrigins, this); | |
295 prefs_registrar_.Add(prefs::kDesktopNotificationDeniedOrigins, this); | |
296 notification_registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 226 notification_registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
297 NotificationService::AllSources()); | 227 NotificationService::AllSources()); |
298 notification_registrar_.Add( | |
299 this, | |
300 chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED, | |
301 Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap())); | |
302 } | 228 } |
303 notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 229 notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
304 Source<Profile>(profile_)); | 230 Source<Profile>(profile_)); |
305 } | 231 } |
306 | 232 |
307 void DesktopNotificationService::StopObserving() { | 233 void DesktopNotificationService::StopObserving() { |
308 if (!profile_->IsOffTheRecord()) { | |
309 prefs_registrar_.RemoveAll(); | |
310 } | |
311 notification_registrar_.RemoveAll(); | 234 notification_registrar_.RemoveAll(); |
312 } | 235 } |
313 | 236 |
314 void DesktopNotificationService::GrantPermission(const GURL& origin) { | 237 void DesktopNotificationService::GrantPermission(const GURL& origin) { |
315 ContentSettingsPattern pattern = | 238 ContentSettingsPattern primary_pattern = |
316 content_settings::NotificationProvider::ToContentSettingsPattern(origin); | 239 ContentSettingsPattern::FromURLNoWildcard(origin); |
317 provider_->SetContentSetting( | 240 profile_->GetHostContentSettingsMap()->SetContentSetting( |
318 pattern, | 241 primary_pattern, |
319 pattern, | 242 ContentSettingsPattern::Wildcard(), |
320 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 243 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
321 NO_RESOURCE_IDENTIFIER, | 244 NO_RESOURCE_IDENTIFIER, |
322 CONTENT_SETTING_ALLOW); | 245 CONTENT_SETTING_ALLOW); |
323 | |
324 // Schedule a cache update on the IO thread. | |
325 BrowserThread::PostTask( | |
326 BrowserThread::IO, FROM_HERE, | |
327 NewRunnableMethod( | |
328 prefs_cache_.get(), | |
329 &NotificationsPrefsCache::CacheAllowedOrigin, | |
330 origin)); | |
331 } | 246 } |
332 | 247 |
333 void DesktopNotificationService::DenyPermission(const GURL& origin) { | 248 void DesktopNotificationService::DenyPermission(const GURL& origin) { |
334 // Update content settings | 249 ContentSettingsPattern primary_pattern = |
335 ContentSettingsPattern pattern = | 250 ContentSettingsPattern::FromURLNoWildcard(origin); |
336 content_settings::NotificationProvider::ToContentSettingsPattern(origin); | 251 profile_->GetHostContentSettingsMap()->SetContentSetting( |
337 provider_->SetContentSetting( | 252 primary_pattern, |
338 pattern, | 253 ContentSettingsPattern::Wildcard(), |
339 pattern, | |
340 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 254 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
341 NO_RESOURCE_IDENTIFIER, | 255 NO_RESOURCE_IDENTIFIER, |
342 CONTENT_SETTING_BLOCK); | 256 CONTENT_SETTING_BLOCK); |
343 | |
344 // Schedule a cache update on the IO thread. | |
345 BrowserThread::PostTask( | |
346 BrowserThread::IO, FROM_HERE, | |
347 NewRunnableMethod( | |
348 prefs_cache_.get(), | |
349 &NotificationsPrefsCache::CacheDeniedOrigin, | |
350 origin)); | |
351 } | 257 } |
352 | 258 |
353 void DesktopNotificationService::Observe(int type, | 259 void DesktopNotificationService::Observe(int type, |
354 const NotificationSource& source, | 260 const NotificationSource& source, |
355 const NotificationDetails& details) { | 261 const NotificationDetails& details) { |
356 if (chrome::NOTIFICATION_PREF_CHANGED == type) { | 262 if (chrome::NOTIFICATION_EXTENSION_UNLOADED == type) { |
357 const std::string& name = *Details<std::string>(details).ptr(); | |
358 OnPrefsChanged(name); | |
359 } else if (chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED == type) { | |
360 // TODO(markusheintz): Check if content settings type default was changed; | |
361 const ContentSetting default_content_setting = | |
362 profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( | |
363 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
364 // Schedule a cache update on the IO thread. | |
365 BrowserThread::PostTask( | |
366 BrowserThread::IO, FROM_HERE, | |
367 NewRunnableMethod( | |
368 prefs_cache_.get(), | |
369 &NotificationsPrefsCache::SetCacheDefaultContentSetting, | |
370 default_content_setting)); | |
371 } else if (chrome::NOTIFICATION_EXTENSION_UNLOADED == type) { | |
372 // Remove all notifications currently shown or queued by the extension | 263 // Remove all notifications currently shown or queued by the extension |
373 // which was unloaded. | 264 // which was unloaded. |
374 const Extension* extension = | 265 const Extension* extension = |
375 Details<UnloadedExtensionInfo>(details)->extension; | 266 Details<UnloadedExtensionInfo>(details)->extension; |
376 if (extension) | 267 if (extension) |
377 ui_manager_->CancelAllBySourceOrigin(extension->url()); | 268 ui_manager_->CancelAllBySourceOrigin(extension->url()); |
378 } else if (chrome::NOTIFICATION_PROFILE_DESTROYED == type) { | 269 } else if (chrome::NOTIFICATION_PROFILE_DESTROYED == type) { |
379 StopObserving(); | 270 StopObserving(); |
380 } | 271 } |
381 } | 272 } |
382 | 273 |
383 void DesktopNotificationService::OnPrefsChanged(const std::string& pref_name) { | |
384 if (pref_name == prefs::kDesktopNotificationAllowedOrigins) { | |
385 // Schedule a cache update on the IO thread. | |
386 std::vector<GURL> allowed_origins(GetAllowedOrigins()); | |
387 BrowserThread::PostTask( | |
388 BrowserThread::IO, FROM_HERE, | |
389 NewRunnableMethod( | |
390 prefs_cache_.get(), | |
391 &NotificationsPrefsCache::SetCacheAllowedOrigins, | |
392 allowed_origins)); | |
393 } else if (pref_name == prefs::kDesktopNotificationDeniedOrigins) { | |
394 // Schedule a cache update on the IO thread. | |
395 std::vector<GURL> denied_origins(GetBlockedOrigins()); | |
396 BrowserThread::PostTask( | |
397 BrowserThread::IO, FROM_HERE, | |
398 NewRunnableMethod( | |
399 prefs_cache_.get(), | |
400 &NotificationsPrefsCache::SetCacheDeniedOrigins, | |
401 denied_origins)); | |
402 } else { | |
403 NOTREACHED(); | |
404 } | |
405 } | |
406 | |
407 ContentSetting DesktopNotificationService::GetDefaultContentSetting() { | 274 ContentSetting DesktopNotificationService::GetDefaultContentSetting() { |
408 return profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( | 275 return profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( |
409 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 276 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
410 } | 277 } |
411 | 278 |
412 void DesktopNotificationService::SetDefaultContentSetting( | 279 void DesktopNotificationService::SetDefaultContentSetting( |
413 ContentSetting setting) { | 280 ContentSetting setting) { |
414 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( | 281 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( |
415 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting); | 282 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting); |
416 } | 283 } |
417 | 284 |
418 bool DesktopNotificationService::IsDefaultContentSettingManaged() const { | 285 bool DesktopNotificationService::IsDefaultContentSettingManaged() const { |
419 return profile_->GetHostContentSettingsMap()->IsDefaultContentSettingManaged( | 286 return profile_->GetHostContentSettingsMap()->IsDefaultContentSettingManaged( |
420 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 287 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
421 } | 288 } |
422 | 289 |
423 void DesktopNotificationService::ResetToDefaultContentSetting() { | 290 void DesktopNotificationService::ResetToDefaultContentSetting() { |
424 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( | 291 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( |
425 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_DEFAULT); | 292 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_DEFAULT); |
426 } | 293 } |
427 | 294 |
428 std::vector<GURL> DesktopNotificationService::GetAllowedOrigins() { | 295 void DesktopNotificationService::GetNotificationsSettings( |
429 content_settings::ProviderInterface::Rules content_setting_rules; | 296 HostContentSettingsMap::SettingsForOneType* settings) { |
430 provider_->GetAllContentSettingsRules( | 297 profile_->GetHostContentSettingsMap()->GetSettingsForOneType( |
431 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 298 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
432 NO_RESOURCE_IDENTIFIER, | 299 NO_RESOURCE_IDENTIFIER, |
433 &content_setting_rules); | 300 settings); |
434 std::vector<GURL> allowed_origins; | |
435 | |
436 GetOriginsWithSettingFromContentSettingsRules( | |
437 content_setting_rules, CONTENT_SETTING_ALLOW, &allowed_origins); | |
438 | |
439 return allowed_origins; | |
440 } | 301 } |
441 | 302 |
442 std::vector<GURL> DesktopNotificationService::GetBlockedOrigins() { | 303 void DesktopNotificationService::ClearSetting( |
443 content_settings::ProviderInterface::Rules content_settings_rules; | 304 const ContentSettingsPattern& pattern) { |
444 provider_->GetAllContentSettingsRules( | 305 profile_->GetHostContentSettingsMap()->SetContentSetting( |
445 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
446 NO_RESOURCE_IDENTIFIER, | |
447 &content_settings_rules); | |
448 std::vector<GURL> denied_origins; | |
449 | |
450 GetOriginsWithSettingFromContentSettingsRules( | |
451 content_settings_rules, CONTENT_SETTING_BLOCK, &denied_origins); | |
452 | |
453 return denied_origins; | |
454 } | |
455 | |
456 void DesktopNotificationService::ResetAllowedOrigin(const GURL& origin) { | |
457 ContentSettingsPattern pattern = | |
458 ContentSettingsPattern::FromURLNoWildcard(origin); | |
459 provider_->SetContentSetting( | |
460 pattern, | 306 pattern, |
461 pattern, | 307 ContentSettingsPattern::Wildcard(), |
462 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
463 NO_RESOURCE_IDENTIFIER, | |
464 CONTENT_SETTING_DEFAULT); | |
465 } | |
466 | |
467 void DesktopNotificationService::ResetBlockedOrigin(const GURL& origin) { | |
468 ContentSettingsPattern pattern = | |
469 ContentSettingsPattern::FromURLNoWildcard(origin); | |
470 provider_->SetContentSetting( | |
471 pattern, | |
472 pattern, | |
473 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 308 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
474 NO_RESOURCE_IDENTIFIER, | 309 NO_RESOURCE_IDENTIFIER, |
475 CONTENT_SETTING_DEFAULT); | 310 CONTENT_SETTING_DEFAULT); |
476 } | 311 } |
477 | 312 |
478 void DesktopNotificationService::ResetAllOrigins() { | 313 void DesktopNotificationService::ResetAllOrigins() { |
479 provider_->ClearAllContentSettingsRules(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 314 profile_->GetHostContentSettingsMap()->ClearSettingsForOneType( |
| 315 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
480 } | 316 } |
481 | 317 |
482 ContentSetting DesktopNotificationService::GetContentSetting( | 318 ContentSetting DesktopNotificationService::GetContentSetting( |
483 const GURL& origin) { | 319 const GURL& origin) { |
484 ContentSetting provided_setting = provider_->GetContentSetting( | 320 return profile_->GetHostContentSettingsMap()->GetContentSetting( |
485 origin, | 321 origin, |
486 origin, | 322 origin, |
487 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 323 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
488 NO_RESOURCE_IDENTIFIER); | 324 NO_RESOURCE_IDENTIFIER); |
489 if (CONTENT_SETTING_DEFAULT == provided_setting) | |
490 return GetDefaultContentSetting(); | |
491 return provided_setting; | |
492 } | 325 } |
493 | 326 |
494 void DesktopNotificationService::RequestPermission( | 327 void DesktopNotificationService::RequestPermission( |
495 const GURL& origin, int process_id, int route_id, int callback_context, | 328 const GURL& origin, int process_id, int route_id, int callback_context, |
496 TabContents* tab) { | 329 TabContents* tab) { |
497 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
498 if (!tab) { | 331 if (!tab) { |
499 Browser* browser = BrowserList::GetLastActive(); | 332 Browser* browser = BrowserList::GetLastActive(); |
500 if (browser) | 333 if (browser) |
501 tab = browser->GetSelectedTabContents(); | 334 tab = browser->GetSelectedTabContents(); |
(...skipping 30 matching lines...) Expand all Loading... |
532 } | 365 } |
533 | 366 |
534 bool DesktopNotificationService::CancelDesktopNotification( | 367 bool DesktopNotificationService::CancelDesktopNotification( |
535 int process_id, int route_id, int notification_id) { | 368 int process_id, int route_id, int notification_id) { |
536 scoped_refptr<NotificationObjectProxy> proxy( | 369 scoped_refptr<NotificationObjectProxy> proxy( |
537 new NotificationObjectProxy(process_id, route_id, notification_id, | 370 new NotificationObjectProxy(process_id, route_id, notification_id, |
538 false)); | 371 false)); |
539 return ui_manager_->CancelById(proxy->id()); | 372 return ui_manager_->CancelById(proxy->id()); |
540 } | 373 } |
541 | 374 |
542 | |
543 bool DesktopNotificationService::ShowDesktopNotification( | 375 bool DesktopNotificationService::ShowDesktopNotification( |
544 const DesktopNotificationHostMsg_Show_Params& params, | 376 const DesktopNotificationHostMsg_Show_Params& params, |
545 int process_id, int route_id, DesktopNotificationSource source) { | 377 int process_id, int route_id, DesktopNotificationSource source) { |
546 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
547 const GURL& origin = params.origin; | 379 const GURL& origin = params.origin; |
548 NotificationObjectProxy* proxy = | 380 NotificationObjectProxy* proxy = |
549 new NotificationObjectProxy(process_id, route_id, | 381 new NotificationObjectProxy(process_id, route_id, |
550 params.notification_id, | 382 params.notification_id, |
551 source == WorkerNotification); | 383 source == WorkerNotification); |
552 GURL contents; | 384 GURL contents; |
(...skipping 29 matching lines...) Expand all Loading... |
582 void DesktopNotificationService::NotifySettingsChange() { | 414 void DesktopNotificationService::NotifySettingsChange() { |
583 NotificationService::current()->Notify( | 415 NotificationService::current()->Notify( |
584 chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, | 416 chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, |
585 Source<DesktopNotificationService>(this), | 417 Source<DesktopNotificationService>(this), |
586 NotificationService::NoDetails()); | 418 NotificationService::NoDetails()); |
587 } | 419 } |
588 | 420 |
589 WebKit::WebNotificationPresenter::Permission | 421 WebKit::WebNotificationPresenter::Permission |
590 DesktopNotificationService::HasPermission(const GURL& origin) { | 422 DesktopNotificationService::HasPermission(const GURL& origin) { |
591 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 423 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
592 return prefs_cache()->HasPermission(origin.GetOrigin()); | 424 HostContentSettingsMap* host_content_settings_map = |
| 425 profile_->GetHostContentSettingsMap(); |
| 426 ContentSetting setting = host_content_settings_map->GetContentSetting( |
| 427 origin, |
| 428 origin, |
| 429 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 430 NO_RESOURCE_IDENTIFIER); |
| 431 |
| 432 if (setting == CONTENT_SETTING_ALLOW) |
| 433 return WebKit::WebNotificationPresenter::PermissionAllowed; |
| 434 if (setting == CONTENT_SETTING_BLOCK) |
| 435 return WebKit::WebNotificationPresenter::PermissionDenied; |
| 436 if (setting == CONTENT_SETTING_ASK) |
| 437 return WebKit::WebNotificationPresenter::PermissionNotAllowed; |
| 438 NOTREACHED() << "Invalid notifications settings value: " << setting; |
| 439 return WebKit::WebNotificationPresenter::PermissionNotAllowed; |
593 } | 440 } |
OLD | NEW |