| 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/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" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 #include "ui/message_center/notifier_settings.h" | 51 #include "ui/message_center/notifier_settings.h" |
| 52 | 52 |
| 53 #if defined(OS_CHROMEOS) | 53 #if defined(OS_CHROMEOS) |
| 54 #include "ash/system/system_notifier.h" | 54 #include "ash/system/system_notifier.h" |
| 55 #endif | 55 #endif |
| 56 | 56 |
| 57 using content::BrowserThread; | 57 using content::BrowserThread; |
| 58 using content::RenderViewHost; | 58 using content::RenderViewHost; |
| 59 using content::WebContents; | 59 using content::WebContents; |
| 60 using message_center::NotifierId; | 60 using message_center::NotifierId; |
| 61 using WebKit::WebNotificationPresenter; | |
| 62 using WebKit::WebTextDirection; | 61 using WebKit::WebTextDirection; |
| 63 | 62 |
| 64 | 63 |
| 65 // NotificationPermissionInfoBarDelegate -------------------------------------- | 64 // NotificationPermissionInfoBarDelegate -------------------------------------- |
| 66 | 65 |
| 67 // The delegate for the infobar shown when an origin requests notification | 66 // The delegate for the infobar shown when an origin requests notification |
| 68 // permissions. | 67 // permissions. |
| 69 class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { | 68 class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 70 public: | 69 public: |
| 71 // Creates a notification permission infobar delegate and adds it to | 70 // Creates a notification permission infobar delegate and adds it to |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 const base::ListValue* pref_list = profile_->GetPrefs()->GetList(pref_name); | 642 const base::ListValue* pref_list = profile_->GetPrefs()->GetList(pref_name); |
| 644 for (size_t i = 0; i < pref_list->GetSize(); ++i) { | 643 for (size_t i = 0; i < pref_list->GetSize(); ++i) { |
| 645 std::string element; | 644 std::string element; |
| 646 if (pref_list->GetString(i, &element) && !element.empty()) | 645 if (pref_list->GetString(i, &element) && !element.empty()) |
| 647 ids_field->insert(element); | 646 ids_field->insert(element); |
| 648 else | 647 else |
| 649 LOG(WARNING) << i << "-th element is not a string for " << pref_name; | 648 LOG(WARNING) << i << "-th element is not a string for " << pref_name; |
| 650 } | 649 } |
| 651 } | 650 } |
| 652 | 651 |
| 653 WebKit::WebNotificationPresenter::Permission | |
| 654 DesktopNotificationService::HasPermission(const GURL& origin) { | |
| 655 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 656 HostContentSettingsMap* host_content_settings_map = | |
| 657 profile_->GetHostContentSettingsMap(); | |
| 658 ContentSetting setting = host_content_settings_map->GetContentSetting( | |
| 659 origin, | |
| 660 origin, | |
| 661 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
| 662 NO_RESOURCE_IDENTIFIER); | |
| 663 | |
| 664 if (setting == CONTENT_SETTING_ALLOW) | |
| 665 return WebKit::WebNotificationPresenter::PermissionAllowed; | |
| 666 if (setting == CONTENT_SETTING_BLOCK) | |
| 667 return WebKit::WebNotificationPresenter::PermissionDenied; | |
| 668 if (setting == CONTENT_SETTING_ASK) | |
| 669 return WebKit::WebNotificationPresenter::PermissionNotAllowed; | |
| 670 NOTREACHED() << "Invalid notifications settings value: " << setting; | |
| 671 return WebKit::WebNotificationPresenter::PermissionNotAllowed; | |
| 672 } | |
| 673 | |
| 674 void DesktopNotificationService::Observe( | 652 void DesktopNotificationService::Observe( |
| 675 int type, | 653 int type, |
| 676 const content::NotificationSource& source, | 654 const content::NotificationSource& source, |
| 677 const content::NotificationDetails& details) { | 655 const content::NotificationDetails& details) { |
| 678 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_UNINSTALLED, type); | 656 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_UNINSTALLED, type); |
| 679 | 657 |
| 680 extensions::Extension* extension = | 658 extensions::Extension* extension = |
| 681 content::Details<extensions::Extension>(details).ptr(); | 659 content::Details<extensions::Extension>(details).ptr(); |
| 682 NotifierId notifier_id(NotifierId::APPLICATION, extension->id()); | 660 NotifierId notifier_id(NotifierId::APPLICATION, extension->id()); |
| 683 if (IsNotifierEnabled(notifier_id)) | 661 if (IsNotifierEnabled(notifier_id)) |
| 684 return; | 662 return; |
| 685 | 663 |
| 686 SetNotifierEnabled(notifier_id, true); | 664 SetNotifierEnabled(notifier_id, true); |
| 687 } | 665 } |
| 688 | 666 |
| 689 void DesktopNotificationService::FirePermissionLevelChangedEvent( | 667 void DesktopNotificationService::FirePermissionLevelChangedEvent( |
| 690 const NotifierId& notifier_id, bool enabled) { | 668 const NotifierId& notifier_id, bool enabled) { |
| 691 DCHECK_EQ(NotifierId::APPLICATION, notifier_id.type); | 669 DCHECK_EQ(NotifierId::APPLICATION, notifier_id.type); |
| 692 extensions::api::notifications::PermissionLevel permission = | 670 extensions::api::notifications::PermissionLevel permission = |
| 693 enabled ? extensions::api::notifications::PERMISSION_LEVEL_GRANTED | 671 enabled ? extensions::api::notifications::PERMISSION_LEVEL_GRANTED |
| 694 : extensions::api::notifications::PERMISSION_LEVEL_DENIED; | 672 : extensions::api::notifications::PERMISSION_LEVEL_DENIED; |
| 695 scoped_ptr<base::ListValue> args(new base::ListValue()); | 673 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 696 args->Append(new base::StringValue( | 674 args->Append(new base::StringValue( |
| 697 extensions::api::notifications::ToString(permission))); | 675 extensions::api::notifications::ToString(permission))); |
| 698 scoped_ptr<extensions::Event> event(new extensions::Event( | 676 scoped_ptr<extensions::Event> event(new extensions::Event( |
| 699 extensions::api::notifications::OnPermissionLevelChanged::kEventName, | 677 extensions::api::notifications::OnPermissionLevelChanged::kEventName, |
| 700 args.Pass())); | 678 args.Pass())); |
| 701 extensions::ExtensionSystem::Get(profile_)->event_router()-> | 679 extensions::ExtensionSystem::Get(profile_)->event_router()-> |
| 702 DispatchEventToExtension(notifier_id.id, event.Pass()); | 680 DispatchEventToExtension(notifier_id.id, event.Pass()); |
| 681 |
| 682 // Tell the IO thread that this extension's permission for notifications |
| 683 // has changed. |
| 684 ExtensionInfoMap* extension_info_map = |
| 685 extensions::ExtensionSystem::Get(profile_)->info_map(); |
| 686 BrowserThread::PostTask( |
| 687 BrowserThread::IO, FROM_HERE, |
| 688 base::Bind(&ExtensionInfoMap::SetNotificationsDisabled, |
| 689 extension_info_map, notifier_id.id, !enabled)); |
| 690 |
| 703 } | 691 } |
| OLD | NEW |