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/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/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/content_settings/content_settings_details.h" | 11 #include "chrome/browser/content_settings/content_settings_details.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/infobars/infobar_tab_helper.h" |
16 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 16 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
17 #include "chrome/browser/notifications/notification.h" | 17 #include "chrome/browser/notifications/notification.h" |
18 #include "chrome/browser/notifications/notification_object_proxy.h" | 18 #include "chrome/browser/notifications/notification_object_proxy.h" |
19 #include "chrome/browser/notifications/notification_ui_manager.h" | 19 #include "chrome/browser/notifications/notification_ui_manager.h" |
20 #include "chrome/browser/prefs/pref_service.h" | 20 #include "chrome/browser/prefs/pref_service.h" |
21 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 21 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 23 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
24 #include "chrome/browser/ui/browser_list.h" | 24 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/browser/ui/browser_finder.h" |
25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
26 #include "chrome/common/chrome_notification_types.h" | 27 #include "chrome/common/chrome_notification_types.h" |
27 #include "chrome/common/content_settings.h" | 28 #include "chrome/common/content_settings.h" |
28 #include "chrome/common/content_settings_pattern.h" | 29 #include "chrome/common/content_settings_pattern.h" |
29 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
30 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
31 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
32 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
33 #include "content/public/browser/render_view_host.h" | 34 #include "content/public/browser/render_view_host.h" |
34 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 origin, | 326 origin, |
326 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 327 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
327 NO_RESOURCE_IDENTIFIER); | 328 NO_RESOURCE_IDENTIFIER); |
328 } | 329 } |
329 | 330 |
330 void DesktopNotificationService::RequestPermission( | 331 void DesktopNotificationService::RequestPermission( |
331 const GURL& origin, int process_id, int route_id, int callback_context, | 332 const GURL& origin, int process_id, int route_id, int callback_context, |
332 WebContents* tab) { | 333 WebContents* tab) { |
333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
334 if (!tab) { | 335 if (!tab) { |
335 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); | 336 Browser* browser = browser::FindLastActiveWithProfile(profile_); |
336 if (browser) | 337 if (browser) |
337 tab = browser->GetSelectedWebContents(); | 338 tab = browser->GetSelectedWebContents(); |
338 } | 339 } |
339 | 340 |
340 if (!tab) | 341 if (!tab) |
341 return; | 342 return; |
342 | 343 |
343 // If |origin| hasn't been seen before and the default content setting for | 344 // If |origin| hasn't been seen before and the default content setting for |
344 // notifications is "ask", show an infobar. | 345 // notifications is "ask", show an infobar. |
345 // The cache can only answer queries on the IO thread once it's initialized, | 346 // The cache can only answer queries on the IO thread once it's initialized, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 | 449 |
449 if (setting == CONTENT_SETTING_ALLOW) | 450 if (setting == CONTENT_SETTING_ALLOW) |
450 return WebKit::WebNotificationPresenter::PermissionAllowed; | 451 return WebKit::WebNotificationPresenter::PermissionAllowed; |
451 if (setting == CONTENT_SETTING_BLOCK) | 452 if (setting == CONTENT_SETTING_BLOCK) |
452 return WebKit::WebNotificationPresenter::PermissionDenied; | 453 return WebKit::WebNotificationPresenter::PermissionDenied; |
453 if (setting == CONTENT_SETTING_ASK) | 454 if (setting == CONTENT_SETTING_ASK) |
454 return WebKit::WebNotificationPresenter::PermissionNotAllowed; | 455 return WebKit::WebNotificationPresenter::PermissionNotAllowed; |
455 NOTREACHED() << "Invalid notifications settings value: " << setting; | 456 NOTREACHED() << "Invalid notifications settings value: " << setting; |
456 return WebKit::WebNotificationPresenter::PermissionNotAllowed; | 457 return WebKit::WebNotificationPresenter::PermissionNotAllowed; |
457 } | 458 } |
OLD | NEW |