Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: chrome/browser/notifications/desktop_notification_service.cc

Issue 247943003: Allow compiling Android with notifications=1, add stubbed UI manager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/prefs/scoped_user_pref_update.h" 8 #include "base/prefs/scoped_user_pref_update.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/chrome_notification_types.h" 12 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/content_settings/content_settings_details.h" 13 #include "chrome/browser/content_settings/content_settings_details.h"
14 #include "chrome/browser/content_settings/content_settings_provider.h" 14 #include "chrome/browser/content_settings/content_settings_provider.h"
15 #include "chrome/browser/content_settings/host_content_settings_map.h" 15 #include "chrome/browser/content_settings/host_content_settings_map.h"
16 #include "chrome/browser/extensions/api/notifications/notifications_api.h"
17 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/infobars/confirm_infobar_delegate.h" 16 #include "chrome/browser/infobars/confirm_infobar_delegate.h"
19 #include "chrome/browser/infobars/infobar_service.h" 17 #include "chrome/browser/infobars/infobar_service.h"
20 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 18 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
21 #include "chrome/browser/notifications/notification.h" 19 #include "chrome/browser/notifications/notification.h"
22 #include "chrome/browser/notifications/notification_object_proxy.h" 20 #include "chrome/browser/notifications/notification_object_proxy.h"
23 #include "chrome/browser/notifications/notification_ui_manager.h" 21 #include "chrome/browser/notifications/notification_ui_manager.h"
24 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" 22 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h"
25 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_fac tory.h" 23 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_fac tory.h"
26 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
27 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
28 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" 26 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
29 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" 27 #include "chrome/browser/ui/website_settings/permission_bubble_request.h"
30 #include "chrome/common/content_settings.h" 28 #include "chrome/common/content_settings.h"
31 #include "chrome/common/content_settings_pattern.h" 29 #include "chrome/common/content_settings_pattern.h"
32 #include "chrome/common/pref_names.h" 30 #include "chrome/common/pref_names.h"
33 #include "chrome/common/url_constants.h" 31 #include "chrome/common/url_constants.h"
34 #include "components/infobars/core/infobar.h" 32 #include "components/infobars/core/infobar.h"
35 #include "components/user_prefs/pref_registry_syncable.h" 33 #include "components/user_prefs/pref_registry_syncable.h"
36 #include "content/public/browser/browser_thread.h" 34 #include "content/public/browser/browser_thread.h"
37 #include "content/public/browser/notification_service.h" 35 #include "content/public/browser/notification_service.h"
38 #include "content/public/browser/render_view_host.h" 36 #include "content/public/browser/render_view_host.h"
39 #include "content/public/browser/web_contents.h" 37 #include "content/public/browser/web_contents.h"
40 #include "content/public/common/show_desktop_notification_params.h" 38 #include "content/public/common/show_desktop_notification_params.h"
41 #include "extensions/browser/event_router.h"
42 #include "extensions/browser/extension_system.h"
43 #include "extensions/browser/info_map.h"
44 #include "extensions/common/constants.h"
45 #include "extensions/common/extension.h"
46 #include "extensions/common/extension_set.h"
47 #include "grit/browser_resources.h" 39 #include "grit/browser_resources.h"
48 #include "grit/chromium_strings.h" 40 #include "grit/chromium_strings.h"
49 #include "grit/generated_resources.h" 41 #include "grit/generated_resources.h"
50 #include "grit/theme_resources.h" 42 #include "grit/theme_resources.h"
51 #include "net/base/escape.h" 43 #include "net/base/escape.h"
52 #include "ui/base/l10n/l10n_util.h" 44 #include "ui/base/l10n/l10n_util.h"
53 #include "ui/base/resource/resource_bundle.h" 45 #include "ui/base/resource/resource_bundle.h"
54 #include "ui/base/webui/web_ui_util.h" 46 #include "ui/base/webui/web_ui_util.h"
55 #include "ui/message_center/message_center_util.h" 47 #include "ui/message_center/message_center_util.h"
56 #include "ui/message_center/notifier_settings.h" 48 #include "ui/message_center/notifier_settings.h"
57 49
50 #if defined(ENABLE_EXTENSIONS)
51 #include "chrome/browser/extensions/api/notifications/notifications_api.h"
52 #include "chrome/browser/extensions/extension_service.h"
53 #include "extensions/browser/event_router.h"
54 #include "extensions/browser/extension_system.h"
55 #include "extensions/browser/info_map.h"
56 #include "extensions/common/constants.h"
57 #include "extensions/common/extension.h"
58 #include "extensions/common/extension_set.h"
59 #endif
60
58 using content::BrowserThread; 61 using content::BrowserThread;
59 using content::RenderViewHost; 62 using content::RenderViewHost;
60 using content::WebContents; 63 using content::WebContents;
61 using message_center::NotifierId; 64 using message_center::NotifierId;
62 using blink::WebTextDirection; 65 using blink::WebTextDirection;
63 66
64 const char kChromeNowExtensionID[] = "pafkbggdmjlpgkdkcbjmhmfcdpncadgh"; 67 const char kChromeNowExtensionID[] = "pafkbggdmjlpgkdkcbjmhmfcdpncadgh";
65 68
66 // NotificationPermissionRequest --------------------------------------- 69 // NotificationPermissionRequest ---------------------------------------
67 70
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 584
582 // The webkit notification doesn't timeout. 585 // The webkit notification doesn't timeout.
583 notification.set_never_timeout(true); 586 notification.set_never_timeout(true);
584 587
585 ShowNotification(notification); 588 ShowNotification(notification);
586 return true; 589 return true;
587 } 590 }
588 591
589 base::string16 DesktopNotificationService::DisplayNameForOriginInProcessId( 592 base::string16 DesktopNotificationService::DisplayNameForOriginInProcessId(
590 const GURL& origin, int process_id) { 593 const GURL& origin, int process_id) {
594 #if defined(ENABLE_EXTENSIONS)
591 // If the source is an extension, lookup the display name. 595 // If the source is an extension, lookup the display name.
592 if (origin.SchemeIs(extensions::kExtensionScheme)) { 596 if (origin.SchemeIs(extensions::kExtensionScheme)) {
593 extensions::InfoMap* extension_info_map = 597 extensions::InfoMap* extension_info_map =
594 extensions::ExtensionSystem::Get(profile_)->info_map(); 598 extensions::ExtensionSystem::Get(profile_)->info_map();
595 if (extension_info_map) { 599 if (extension_info_map) {
596 extensions::ExtensionSet extensions; 600 extensions::ExtensionSet extensions;
597 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin( 601 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
598 origin, process_id, extensions::APIPermission::kNotification, 602 origin, process_id, extensions::APIPermission::kNotification,
599 &extensions); 603 &extensions);
600 for (extensions::ExtensionSet::const_iterator iter = extensions.begin(); 604 for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
601 iter != extensions.end(); ++iter) { 605 iter != extensions.end(); ++iter) {
602 NotifierId notifier_id(NotifierId::APPLICATION, (*iter)->id()); 606 NotifierId notifier_id(NotifierId::APPLICATION, (*iter)->id());
603 if (IsNotifierEnabled(notifier_id)) 607 if (IsNotifierEnabled(notifier_id))
604 return base::UTF8ToUTF16((*iter)->name()); 608 return base::UTF8ToUTF16((*iter)->name());
605 } 609 }
606 } 610 }
607 } 611 }
612 #endif
613
608 return base::UTF8ToUTF16(origin.host()); 614 return base::UTF8ToUTF16(origin.host());
609 } 615 }
610 616
611 void DesktopNotificationService::NotifySettingsChange() { 617 void DesktopNotificationService::NotifySettingsChange() {
612 content::NotificationService::current()->Notify( 618 content::NotificationService::current()->Notify(
613 chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, 619 chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED,
614 content::Source<DesktopNotificationService>(this), 620 content::Source<DesktopNotificationService>(this),
615 content::NotificationService::NoDetails()); 621 content::NotificationService::NoDetails());
616 } 622 }
617 623
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 ids_field->insert(element); 727 ids_field->insert(element);
722 else 728 else
723 LOG(WARNING) << i << "-th element is not a string for " << pref_name; 729 LOG(WARNING) << i << "-th element is not a string for " << pref_name;
724 } 730 }
725 } 731 }
726 732
727 void DesktopNotificationService::Observe( 733 void DesktopNotificationService::Observe(
728 int type, 734 int type,
729 const content::NotificationSource& source, 735 const content::NotificationSource& source,
730 const content::NotificationDetails& details) { 736 const content::NotificationDetails& details) {
737 #if defined(ENABLE_EXTENSIONS)
731 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_UNINSTALLED, type); 738 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_UNINSTALLED, type);
732 739
733 extensions::Extension* extension = 740 extensions::Extension* extension =
734 content::Details<extensions::Extension>(details).ptr(); 741 content::Details<extensions::Extension>(details).ptr();
735 NotifierId notifier_id(NotifierId::APPLICATION, extension->id()); 742 NotifierId notifier_id(NotifierId::APPLICATION, extension->id());
736 if (IsNotifierEnabled(notifier_id)) 743 if (IsNotifierEnabled(notifier_id))
737 return; 744 return;
738 745
739 // The settings for ephemeral apps will be persisted across cache evictions. 746 // The settings for ephemeral apps will be persisted across cache evictions.
740 if (extension->is_ephemeral()) 747 if (extension->is_ephemeral())
741 return; 748 return;
742 749
743 SetNotifierEnabled(notifier_id, true); 750 SetNotifierEnabled(notifier_id, true);
751 #endif
744 } 752 }
745 753
746 void DesktopNotificationService::FirePermissionLevelChangedEvent( 754 void DesktopNotificationService::FirePermissionLevelChangedEvent(
747 const NotifierId& notifier_id, bool enabled) { 755 const NotifierId& notifier_id, bool enabled) {
756 #if defined(ENABLE_EXTENSIONS)
748 DCHECK_EQ(NotifierId::APPLICATION, notifier_id.type); 757 DCHECK_EQ(NotifierId::APPLICATION, notifier_id.type);
749 extensions::api::notifications::PermissionLevel permission = 758 extensions::api::notifications::PermissionLevel permission =
750 enabled ? extensions::api::notifications::PERMISSION_LEVEL_GRANTED 759 enabled ? extensions::api::notifications::PERMISSION_LEVEL_GRANTED
751 : extensions::api::notifications::PERMISSION_LEVEL_DENIED; 760 : extensions::api::notifications::PERMISSION_LEVEL_DENIED;
752 scoped_ptr<base::ListValue> args(new base::ListValue()); 761 scoped_ptr<base::ListValue> args(new base::ListValue());
753 args->Append(new base::StringValue( 762 args->Append(new base::StringValue(
754 extensions::api::notifications::ToString(permission))); 763 extensions::api::notifications::ToString(permission)));
755 scoped_ptr<extensions::Event> event(new extensions::Event( 764 scoped_ptr<extensions::Event> event(new extensions::Event(
756 extensions::api::notifications::OnPermissionLevelChanged::kEventName, 765 extensions::api::notifications::OnPermissionLevelChanged::kEventName,
757 args.Pass())); 766 args.Pass()));
758 extensions::EventRouter::Get(profile_) 767 extensions::EventRouter::Get(profile_)
759 ->DispatchEventToExtension(notifier_id.id, event.Pass()); 768 ->DispatchEventToExtension(notifier_id.id, event.Pass());
760 769
761 // Tell the IO thread that this extension's permission for notifications 770 // Tell the IO thread that this extension's permission for notifications
762 // has changed. 771 // has changed.
763 extensions::InfoMap* extension_info_map = 772 extensions::InfoMap* extension_info_map =
764 extensions::ExtensionSystem::Get(profile_)->info_map(); 773 extensions::ExtensionSystem::Get(profile_)->info_map();
765 BrowserThread::PostTask( 774 BrowserThread::PostTask(
766 BrowserThread::IO, FROM_HERE, 775 BrowserThread::IO, FROM_HERE,
767 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, 776 base::Bind(&extensions::InfoMap::SetNotificationsDisabled,
768 extension_info_map, notifier_id.id, !enabled)); 777 extension_info_map, notifier_id.id, !enabled));
769 778 #endif
770 } 779 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698