Chromium Code Reviews| 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_provider.h" | 10 #include "chrome/browser/content_settings/content_settings_provider.h" |
| 11 #include "chrome/browser/content_settings/host_content_settings_map.h" | 11 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/infobars/infobar_tab_helper.h" | |
| 13 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 14 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 14 #include "chrome/browser/notifications/notification.h" | 15 #include "chrome/browser/notifications/notification.h" |
| 15 #include "chrome/browser/notifications/notification_object_proxy.h" | 16 #include "chrome/browser/notifications/notification_object_proxy.h" |
| 16 #include "chrome/browser/notifications/notification_ui_manager.h" | 17 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 17 #include "chrome/browser/notifications/notifications_prefs_cache.h" | 18 #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" |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 497 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 498 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 498 if (!tab) { | 499 if (!tab) { |
| 499 Browser* browser = BrowserList::GetLastActive(); | 500 Browser* browser = BrowserList::GetLastActive(); |
| 500 if (browser) | 501 if (browser) |
| 501 tab = browser->GetSelectedTabContents(); | 502 tab = browser->GetSelectedTabContents(); |
| 502 } | 503 } |
| 503 | 504 |
| 504 if (!tab) | 505 if (!tab) |
| 505 return; | 506 return; |
| 506 | 507 |
| 507 TabContentsWrapper* wrapper = | 508 TabContentsWrapper* wrapper = |
|
Peter Kasting
2011/08/31 18:47:32
Nit: Move this into the conditional and combine wi
| |
| 508 TabContentsWrapper::GetCurrentWrapperForContents(tab); | 509 TabContentsWrapper::GetCurrentWrapperForContents(tab); |
| 509 | 510 |
| 510 // If |origin| hasn't been seen before and the default content setting for | 511 // If |origin| hasn't been seen before and the default content setting for |
| 511 // notifications is "ask", show an infobar. | 512 // notifications is "ask", show an infobar. |
| 512 // The cache can only answer queries on the IO thread once it's initialized, | 513 // The cache can only answer queries on the IO thread once it's initialized, |
| 513 // so don't ask the cache. | 514 // so don't ask the cache. |
| 514 ContentSetting setting = GetContentSetting(origin); | 515 ContentSetting setting = GetContentSetting(origin); |
| 515 if (setting == CONTENT_SETTING_ASK) { | 516 if (setting == CONTENT_SETTING_ASK) { |
| 516 // Show an info bar requesting permission. | 517 // Show an info bar requesting permission. |
| 517 wrapper->AddInfoBar( | 518 wrapper->infobar_tab_helper()->AddInfoBar( |
| 518 new NotificationPermissionInfoBarDelegate( | 519 new NotificationPermissionInfoBarDelegate( |
| 519 tab, origin, DisplayNameForOrigin(origin), process_id, | 520 tab, origin, DisplayNameForOrigin(origin), process_id, |
| 520 route_id, callback_context)); | 521 route_id, callback_context)); |
| 521 } else { | 522 } else { |
| 522 // Notify renderer immediately. | 523 // Notify renderer immediately. |
| 523 RenderViewHost* host = RenderViewHost::FromID(process_id, route_id); | 524 RenderViewHost* host = RenderViewHost::FromID(process_id, route_id); |
| 524 if (host) | 525 if (host) |
| 525 host->DesktopNotificationPermissionRequestDone(callback_context); | 526 host->DesktopNotificationPermissionRequestDone(callback_context); |
| 526 } | 527 } |
| 527 } | 528 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 584 chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, | 585 chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, |
| 585 Source<DesktopNotificationService>(this), | 586 Source<DesktopNotificationService>(this), |
| 586 NotificationService::NoDetails()); | 587 NotificationService::NoDetails()); |
| 587 } | 588 } |
| 588 | 589 |
| 589 WebKit::WebNotificationPresenter::Permission | 590 WebKit::WebNotificationPresenter::Permission |
| 590 DesktopNotificationService::HasPermission(const GURL& origin) { | 591 DesktopNotificationService::HasPermission(const GURL& origin) { |
| 591 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 592 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 592 return prefs_cache()->HasPermission(origin.GetOrigin()); | 593 return prefs_cache()->HasPermission(origin.GetOrigin()); |
| 593 } | 594 } |
| OLD | NEW |