| 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/content_settings/host_content_settings_map.h" |
| 17 #include "chrome/browser/extensions/api/notifications/notifications_api.h" | |
| 18 #include "chrome/browser/extensions/extension_service.h" | |
| 19 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 17 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
| 20 #include "chrome/browser/infobars/infobar_service.h" | 18 #include "chrome/browser/infobars/infobar_service.h" |
| 21 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 19 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 22 #include "chrome/browser/notifications/notification.h" | 20 #include "chrome/browser/notifications/notification.h" |
| 23 #include "chrome/browser/notifications/notification_object_proxy.h" | 21 #include "chrome/browser/notifications/notification_object_proxy.h" |
| 24 #include "chrome/browser/notifications/notification_ui_manager.h" | 22 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 25 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" | 23 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" |
| 26 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_fac
tory.h" | 24 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_fac
tory.h" |
| 27 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/browser/ui/browser.h" | 26 #include "chrome/browser/ui/browser.h" |
| 29 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 27 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
| 30 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | 28 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" |
| 31 #include "chrome/common/content_settings.h" | 29 #include "chrome/common/content_settings.h" |
| 32 #include "chrome/common/content_settings_pattern.h" | 30 #include "chrome/common/content_settings_pattern.h" |
| 33 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 34 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 35 #include "components/infobars/core/infobar.h" | 33 #include "components/infobars/core/infobar.h" |
| 36 #include "components/user_prefs/pref_registry_syncable.h" | 34 #include "components/user_prefs/pref_registry_syncable.h" |
| 37 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
| 38 #include "content/public/browser/notification_service.h" | 36 #include "content/public/browser/notification_service.h" |
| 39 #include "content/public/browser/render_frame_host.h" | 37 #include "content/public/browser/render_frame_host.h" |
| 40 #include "content/public/browser/render_process_host.h" | 38 #include "content/public/browser/render_process_host.h" |
| 41 #include "content/public/browser/render_view_host.h" | 39 #include "content/public/browser/render_view_host.h" |
| 42 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
| 43 #include "content/public/common/show_desktop_notification_params.h" | 41 #include "content/public/common/show_desktop_notification_params.h" |
| 44 #include "extensions/browser/event_router.h" | |
| 45 #include "extensions/browser/extension_system.h" | |
| 46 #include "extensions/browser/info_map.h" | |
| 47 #include "extensions/common/constants.h" | |
| 48 #include "extensions/common/extension.h" | |
| 49 #include "extensions/common/extension_set.h" | |
| 50 #include "grit/browser_resources.h" | 42 #include "grit/browser_resources.h" |
| 51 #include "grit/chromium_strings.h" | 43 #include "grit/chromium_strings.h" |
| 52 #include "grit/generated_resources.h" | 44 #include "grit/generated_resources.h" |
| 53 #include "grit/theme_resources.h" | 45 #include "grit/theme_resources.h" |
| 54 #include "net/base/escape.h" | 46 #include "net/base/escape.h" |
| 55 #include "ui/base/l10n/l10n_util.h" | 47 #include "ui/base/l10n/l10n_util.h" |
| 56 #include "ui/base/resource/resource_bundle.h" | 48 #include "ui/base/resource/resource_bundle.h" |
| 57 #include "ui/base/webui/web_ui_util.h" | 49 #include "ui/base/webui/web_ui_util.h" |
| 58 #include "ui/message_center/notifier_settings.h" | 50 #include "ui/message_center/notifier_settings.h" |
| 59 | 51 |
| 52 #if defined(ENABLE_EXTENSIONS) |
| 53 #include "chrome/browser/extensions/api/notifications/notifications_api.h" |
| 54 #include "chrome/browser/extensions/extension_service.h" |
| 55 #include "extensions/browser/event_router.h" |
| 56 #include "extensions/browser/extension_system.h" |
| 57 #include "extensions/browser/info_map.h" |
| 58 #include "extensions/common/constants.h" |
| 59 #include "extensions/common/extension.h" |
| 60 #include "extensions/common/extension_set.h" |
| 61 #endif |
| 62 |
| 60 using blink::WebTextDirection; | 63 using blink::WebTextDirection; |
| 61 using content::BrowserThread; | 64 using content::BrowserThread; |
| 62 using content::RenderViewHost; | 65 using content::RenderViewHost; |
| 63 using content::WebContents; | 66 using content::WebContents; |
| 64 using message_center::NotifierId; | 67 using message_center::NotifierId; |
| 65 | 68 |
| 66 namespace { | 69 namespace { |
| 67 | 70 |
| 68 const char kChromeNowExtensionID[] = "pafkbggdmjlpgkdkcbjmhmfcdpncadgh"; | 71 const char kChromeNowExtensionID[] = "pafkbggdmjlpgkdkcbjmhmfcdpncadgh"; |
| 69 | 72 |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 // The webkit notification doesn't timeout. | 562 // The webkit notification doesn't timeout. |
| 560 notification.set_never_timeout(true); | 563 notification.set_never_timeout(true); |
| 561 | 564 |
| 562 GetUIManager()->Add(notification, profile_); | 565 GetUIManager()->Add(notification, profile_); |
| 563 if (cancel_callback) | 566 if (cancel_callback) |
| 564 *cancel_callback = base::Bind(&CancelNotification, proxy->id()); | 567 *cancel_callback = base::Bind(&CancelNotification, proxy->id()); |
| 565 } | 568 } |
| 566 | 569 |
| 567 base::string16 DesktopNotificationService::DisplayNameForOriginInProcessId( | 570 base::string16 DesktopNotificationService::DisplayNameForOriginInProcessId( |
| 568 const GURL& origin, int process_id) { | 571 const GURL& origin, int process_id) { |
| 572 #if defined(ENABLE_EXTENSIONS) |
| 569 // If the source is an extension, lookup the display name. | 573 // If the source is an extension, lookup the display name. |
| 570 if (origin.SchemeIs(extensions::kExtensionScheme)) { | 574 if (origin.SchemeIs(extensions::kExtensionScheme)) { |
| 571 extensions::InfoMap* extension_info_map = | 575 extensions::InfoMap* extension_info_map = |
| 572 extensions::ExtensionSystem::Get(profile_)->info_map(); | 576 extensions::ExtensionSystem::Get(profile_)->info_map(); |
| 573 if (extension_info_map) { | 577 if (extension_info_map) { |
| 574 extensions::ExtensionSet extensions; | 578 extensions::ExtensionSet extensions; |
| 575 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin( | 579 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin( |
| 576 origin, process_id, extensions::APIPermission::kNotification, | 580 origin, process_id, extensions::APIPermission::kNotification, |
| 577 &extensions); | 581 &extensions); |
| 578 for (extensions::ExtensionSet::const_iterator iter = extensions.begin(); | 582 for (extensions::ExtensionSet::const_iterator iter = extensions.begin(); |
| 579 iter != extensions.end(); ++iter) { | 583 iter != extensions.end(); ++iter) { |
| 580 NotifierId notifier_id(NotifierId::APPLICATION, (*iter)->id()); | 584 NotifierId notifier_id(NotifierId::APPLICATION, (*iter)->id()); |
| 581 if (IsNotifierEnabled(notifier_id)) | 585 if (IsNotifierEnabled(notifier_id)) |
| 582 return base::UTF8ToUTF16((*iter)->name()); | 586 return base::UTF8ToUTF16((*iter)->name()); |
| 583 } | 587 } |
| 584 } | 588 } |
| 585 } | 589 } |
| 590 #endif |
| 591 |
| 586 return base::UTF8ToUTF16(origin.host()); | 592 return base::UTF8ToUTF16(origin.host()); |
| 587 } | 593 } |
| 588 | 594 |
| 589 void DesktopNotificationService::NotifySettingsChange() { | 595 void DesktopNotificationService::NotifySettingsChange() { |
| 590 content::NotificationService::current()->Notify( | 596 content::NotificationService::current()->Notify( |
| 591 chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, | 597 chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, |
| 592 content::Source<DesktopNotificationService>(this), | 598 content::Source<DesktopNotificationService>(this), |
| 593 content::NotificationService::NoDetails()); | 599 content::NotificationService::NoDetails()); |
| 594 } | 600 } |
| 595 | 601 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 ids_field->insert(element); | 705 ids_field->insert(element); |
| 700 else | 706 else |
| 701 LOG(WARNING) << i << "-th element is not a string for " << pref_name; | 707 LOG(WARNING) << i << "-th element is not a string for " << pref_name; |
| 702 } | 708 } |
| 703 } | 709 } |
| 704 | 710 |
| 705 void DesktopNotificationService::Observe( | 711 void DesktopNotificationService::Observe( |
| 706 int type, | 712 int type, |
| 707 const content::NotificationSource& source, | 713 const content::NotificationSource& source, |
| 708 const content::NotificationDetails& details) { | 714 const content::NotificationDetails& details) { |
| 715 #if defined(ENABLE_EXTENSIONS) |
| 709 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_UNINSTALLED, type); | 716 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_UNINSTALLED, type); |
| 710 | 717 |
| 711 extensions::Extension* extension = | 718 extensions::Extension* extension = |
| 712 content::Details<extensions::Extension>(details).ptr(); | 719 content::Details<extensions::Extension>(details).ptr(); |
| 713 NotifierId notifier_id(NotifierId::APPLICATION, extension->id()); | 720 NotifierId notifier_id(NotifierId::APPLICATION, extension->id()); |
| 714 if (IsNotifierEnabled(notifier_id)) | 721 if (IsNotifierEnabled(notifier_id)) |
| 715 return; | 722 return; |
| 716 | 723 |
| 717 // The settings for ephemeral apps will be persisted across cache evictions. | 724 // The settings for ephemeral apps will be persisted across cache evictions. |
| 718 if (extension->is_ephemeral()) | 725 if (extension->is_ephemeral()) |
| 719 return; | 726 return; |
| 720 | 727 |
| 721 SetNotifierEnabled(notifier_id, true); | 728 SetNotifierEnabled(notifier_id, true); |
| 729 #endif |
| 722 } | 730 } |
| 723 | 731 |
| 724 void DesktopNotificationService::FirePermissionLevelChangedEvent( | 732 void DesktopNotificationService::FirePermissionLevelChangedEvent( |
| 725 const NotifierId& notifier_id, bool enabled) { | 733 const NotifierId& notifier_id, bool enabled) { |
| 734 #if defined(ENABLE_EXTENSIONS) |
| 726 DCHECK_EQ(NotifierId::APPLICATION, notifier_id.type); | 735 DCHECK_EQ(NotifierId::APPLICATION, notifier_id.type); |
| 727 extensions::api::notifications::PermissionLevel permission = | 736 extensions::api::notifications::PermissionLevel permission = |
| 728 enabled ? extensions::api::notifications::PERMISSION_LEVEL_GRANTED | 737 enabled ? extensions::api::notifications::PERMISSION_LEVEL_GRANTED |
| 729 : extensions::api::notifications::PERMISSION_LEVEL_DENIED; | 738 : extensions::api::notifications::PERMISSION_LEVEL_DENIED; |
| 730 scoped_ptr<base::ListValue> args(new base::ListValue()); | 739 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 731 args->Append(new base::StringValue( | 740 args->Append(new base::StringValue( |
| 732 extensions::api::notifications::ToString(permission))); | 741 extensions::api::notifications::ToString(permission))); |
| 733 scoped_ptr<extensions::Event> event(new extensions::Event( | 742 scoped_ptr<extensions::Event> event(new extensions::Event( |
| 734 extensions::api::notifications::OnPermissionLevelChanged::kEventName, | 743 extensions::api::notifications::OnPermissionLevelChanged::kEventName, |
| 735 args.Pass())); | 744 args.Pass())); |
| 736 extensions::EventRouter::Get(profile_) | 745 extensions::EventRouter::Get(profile_) |
| 737 ->DispatchEventToExtension(notifier_id.id, event.Pass()); | 746 ->DispatchEventToExtension(notifier_id.id, event.Pass()); |
| 738 | 747 |
| 739 // Tell the IO thread that this extension's permission for notifications | 748 // Tell the IO thread that this extension's permission for notifications |
| 740 // has changed. | 749 // has changed. |
| 741 extensions::InfoMap* extension_info_map = | 750 extensions::InfoMap* extension_info_map = |
| 742 extensions::ExtensionSystem::Get(profile_)->info_map(); | 751 extensions::ExtensionSystem::Get(profile_)->info_map(); |
| 743 BrowserThread::PostTask( | 752 BrowserThread::PostTask( |
| 744 BrowserThread::IO, FROM_HERE, | 753 BrowserThread::IO, FROM_HERE, |
| 745 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, | 754 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, |
| 746 extension_info_map, notifier_id.id, !enabled)); | 755 extension_info_map, notifier_id.id, !enabled)); |
| 747 | 756 #endif |
| 748 } | 757 } |
| OLD | NEW |