| 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" | 10 #include "chrome/browser/content_settings/content_settings_details.h" |
| 11 #include "chrome/browser/content_settings/content_settings_pattern.h" | 11 #include "chrome/browser/content_settings/content_settings_pattern.h" |
| 12 #include "chrome/browser/content_settings/content_settings_provider.h" | 12 #include "chrome/browser/content_settings/content_settings_provider.h" |
| 13 #include "chrome/browser/content_settings/host_content_settings_map.h" | 13 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 15 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 16 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 16 #include "chrome/browser/notifications/notification.h" | 17 #include "chrome/browser/notifications/notification.h" |
| 17 #include "chrome/browser/notifications/notification_object_proxy.h" | 18 #include "chrome/browser/notifications/notification_object_proxy.h" |
| 18 #include "chrome/browser/notifications/notification_ui_manager.h" | 19 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 19 #include "chrome/browser/prefs/pref_service.h" | 20 #include "chrome/browser/prefs/pref_service.h" |
| 20 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 21 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 23 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 23 #include "chrome/browser/ui/browser_list.h" | 24 #include "chrome/browser/ui/browser_list.h" |
| 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 331 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 331 if (!tab) { | 332 if (!tab) { |
| 332 Browser* browser = BrowserList::GetLastActive(); | 333 Browser* browser = BrowserList::GetLastActive(); |
| 333 if (browser) | 334 if (browser) |
| 334 tab = browser->GetSelectedTabContents(); | 335 tab = browser->GetSelectedTabContents(); |
| 335 } | 336 } |
| 336 | 337 |
| 337 if (!tab) | 338 if (!tab) |
| 338 return; | 339 return; |
| 339 | 340 |
| 340 TabContentsWrapper* wrapper = | |
| 341 TabContentsWrapper::GetCurrentWrapperForContents(tab); | |
| 342 | |
| 343 // If |origin| hasn't been seen before and the default content setting for | 341 // If |origin| hasn't been seen before and the default content setting for |
| 344 // notifications is "ask", show an infobar. | 342 // notifications is "ask", show an infobar. |
| 345 // The cache can only answer queries on the IO thread once it's initialized, | 343 // The cache can only answer queries on the IO thread once it's initialized, |
| 346 // so don't ask the cache. | 344 // so don't ask the cache. |
| 347 ContentSetting setting = GetContentSetting(origin); | 345 ContentSetting setting = GetContentSetting(origin); |
| 348 if (setting == CONTENT_SETTING_ASK) { | 346 if (setting == CONTENT_SETTING_ASK) { |
| 349 // Show an info bar requesting permission. | 347 // Show an info bar requesting permission. |
| 350 wrapper->AddInfoBar( | 348 TabContentsWrapper* wrapper = |
| 349 TabContentsWrapper::GetCurrentWrapperForContents(tab); |
| 350 wrapper->infobar_tab_helper()->AddInfoBar( |
| 351 new NotificationPermissionInfoBarDelegate( | 351 new NotificationPermissionInfoBarDelegate( |
| 352 tab, origin, DisplayNameForOrigin(origin), process_id, | 352 tab, origin, DisplayNameForOrigin(origin), process_id, |
| 353 route_id, callback_context)); | 353 route_id, callback_context)); |
| 354 } else { | 354 } else { |
| 355 // Notify renderer immediately. | 355 // Notify renderer immediately. |
| 356 RenderViewHost* host = RenderViewHost::FromID(process_id, route_id); | 356 RenderViewHost* host = RenderViewHost::FromID(process_id, route_id); |
| 357 if (host) | 357 if (host) |
| 358 host->DesktopNotificationPermissionRequestDone(callback_context); | 358 host->DesktopNotificationPermissionRequestDone(callback_context); |
| 359 } | 359 } |
| 360 } | 360 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 | 431 |
| 432 if (setting == CONTENT_SETTING_ALLOW) | 432 if (setting == CONTENT_SETTING_ALLOW) |
| 433 return WebKit::WebNotificationPresenter::PermissionAllowed; | 433 return WebKit::WebNotificationPresenter::PermissionAllowed; |
| 434 if (setting == CONTENT_SETTING_BLOCK) | 434 if (setting == CONTENT_SETTING_BLOCK) |
| 435 return WebKit::WebNotificationPresenter::PermissionDenied; | 435 return WebKit::WebNotificationPresenter::PermissionDenied; |
| 436 if (setting == CONTENT_SETTING_ASK) | 436 if (setting == CONTENT_SETTING_ASK) |
| 437 return WebKit::WebNotificationPresenter::PermissionNotAllowed; | 437 return WebKit::WebNotificationPresenter::PermissionNotAllowed; |
| 438 NOTREACHED() << "Invalid notifications settings value: " << setting; | 438 NOTREACHED() << "Invalid notifications settings value: " << setting; |
| 439 return WebKit::WebNotificationPresenter::PermissionNotAllowed; | 439 return WebKit::WebNotificationPresenter::PermissionNotAllowed; |
| 440 } | 440 } |
| OLD | NEW |