summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/app/generated_resources.grd3
-rw-r--r--chrome/browser/notifications/desktop_notification_service.h4
-rw-r--r--chrome/browser/notifications/notification_options_menu_model.cc74
-rw-r--r--chrome/browser/notifications/notification_options_menu_model.h4
4 files changed, 74 insertions, 11 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 67b25e9..6e05baa 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -8247,6 +8247,9 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_NOTIFICATION_BALLOON_REVOKE_MESSAGE" desc="Text for the menu option to revoke notification permission.">
Disable notifications from <ph name="site">$1<ex>mail.google.com</ex></ph>
</message>
+ <message name="IDS_NOTIFICATION_BALLOON_ENABLE_MESSAGE" desc="Text for the menu option to enable notification permission.">
+ Enable notifications from <ph name="site">$1<ex>mail.google.com</ex></ph>
+ </message>
<!-- New Tab Page Promotional messages -->
diff --git a/chrome/browser/notifications/desktop_notification_service.h b/chrome/browser/notifications/desktop_notification_service.h
index a6815da..d92d7e6 100644
--- a/chrome/browser/notifications/desktop_notification_service.h
+++ b/chrome/browser/notifications/desktop_notification_service.h
@@ -114,6 +114,8 @@ class DesktopNotificationService : public NotificationObserver {
static void RegisterUserPrefs(PrefService* user_prefs);
+ ContentSetting GetContentSetting(const GURL& origin);
+
private:
void InitPrefs();
void StartObserving();
@@ -130,8 +132,6 @@ class DesktopNotificationService : public NotificationObserver {
// itself when dealing with extensions.
string16 DisplayNameForOrigin(const GURL& origin);
- ContentSetting GetContentSetting(const GURL& origin);
-
// The profile which owns this object.
Profile* profile_;
diff --git a/chrome/browser/notifications/notification_options_menu_model.cc b/chrome/browser/notifications/notification_options_menu_model.cc
index 209a578..60b41869 100644
--- a/chrome/browser/notifications/notification_options_menu_model.cc
+++ b/chrome/browser/notifications/notification_options_menu_model.cc
@@ -10,6 +10,7 @@
#include "chrome/browser/browser_list.h"
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
+#include "chrome/browser/notifications/notifications_prefs_cache.h"
#include "chrome/browser/profile.h"
#include "chrome/common/content_settings_types.h"
#include "chrome/common/extensions/extension.h"
@@ -17,8 +18,8 @@
#include "grit/generated_resources.h"
// Menu commands
-const int kRevokePermissionCommand = 0;
-const int kDisableExtensionCommand = 1;
+const int kTogglePermissionCommand = 0;
+const int kToggleExtensionCommand = 1;
const int kOpenContentSettingsCommand = 2;
NotificationOptionsMenuModel::NotificationOptionsMenuModel(Balloon* balloon)
@@ -31,12 +32,12 @@ NotificationOptionsMenuModel::NotificationOptionsMenuModel(Balloon* balloon)
if (origin.SchemeIs(chrome::kExtensionScheme)) {
const string16 disable_label = l10n_util::GetStringUTF16(
IDS_EXTENSIONS_DISABLE);
- AddItem(kDisableExtensionCommand, disable_label);
+ AddItem(kToggleExtensionCommand, disable_label);
} else {
const string16 disable_label = l10n_util::GetStringFUTF16(
IDS_NOTIFICATION_BALLOON_REVOKE_MESSAGE,
notification.display_source());
- AddItem(kRevokePermissionCommand, disable_label);
+ AddItem(kTogglePermissionCommand, disable_label);
}
const string16 settings_label = l10n_util::GetStringUTF16(
@@ -47,6 +48,52 @@ NotificationOptionsMenuModel::NotificationOptionsMenuModel(Balloon* balloon)
NotificationOptionsMenuModel::~NotificationOptionsMenuModel() {
}
+bool NotificationOptionsMenuModel::IsLabelForCommandIdDynamic(int command_id)
+ const {
+ return command_id == kTogglePermissionCommand ||
+ command_id == kToggleExtensionCommand;
+}
+
+string16 NotificationOptionsMenuModel::GetLabelForCommandId(int command_id)
+ const {
+ // TODO(tfarina,johnnyg): Removed this code if we decide to close
+ // notifications after permissions are revoked.
+ if (command_id == kTogglePermissionCommand ||
+ command_id == kToggleExtensionCommand) {
+ const Notification& notification = balloon_->notification();
+ const GURL& origin = notification.origin_url();
+
+ DesktopNotificationService* service =
+ balloon_->profile()->GetDesktopNotificationService();
+ if (origin.SchemeIs(chrome::kExtensionScheme)) {
+ ExtensionsService* ext_service =
+ balloon_->profile()->GetExtensionsService();
+ Extension* extension = ext_service->GetExtensionByURL(origin);
+ if (extension) {
+ ExtensionPrefs* extension_prefs = ext_service->extension_prefs();
+ const std::string& id = extension->id();
+ if (extension_prefs->GetExtensionState(id) == Extension::ENABLED)
+ return l10n_util::GetStringUTF16(IDS_EXTENSIONS_DISABLE);
+ else
+ return l10n_util::GetStringUTF16(IDS_EXTENSIONS_ENABLE);
+ }
+ } else {
+ if (service->GetContentSetting(origin) == CONTENT_SETTING_ALLOW) {
+ return l10n_util::GetStringFUTF16(
+ IDS_NOTIFICATION_BALLOON_REVOKE_MESSAGE,
+ notification.display_source());
+ } else {
+ return l10n_util::GetStringFUTF16(
+ IDS_NOTIFICATION_BALLOON_ENABLE_MESSAGE,
+ notification.display_source());
+ }
+ }
+ } else if (command_id == kOpenContentSettingsCommand) {
+ return l10n_util::GetStringUTF16(IDS_NOTIFICATIONS_SETTINGS_BUTTON);
+ }
+ return string16();
+}
+
bool NotificationOptionsMenuModel::IsCommandIdChecked(int /* command_id */)
const {
// Nothing in the menu is checked.
@@ -72,13 +119,22 @@ void NotificationOptionsMenuModel::ExecuteCommand(int command_id) {
balloon_->profile()->GetExtensionsService();
const GURL& origin = balloon_->notification().origin_url();
switch (command_id) {
- case kRevokePermissionCommand:
- service->DenyPermission(origin);
+ case kTogglePermissionCommand:
+ if (service->GetContentSetting(origin) == CONTENT_SETTING_ALLOW)
+ service->DenyPermission(origin);
+ else
+ service->GrantPermission(origin);
break;
- case kDisableExtensionCommand: {
+ case kToggleExtensionCommand: {
Extension* extension = ext_service->GetExtensionByURL(origin);
- if (extension)
- ext_service->DisableExtension(extension->id());
+ if (extension) {
+ ExtensionPrefs* extension_prefs = ext_service->extension_prefs();
+ const std::string& id = extension->id();
+ if (extension_prefs->GetExtensionState(id) == Extension::ENABLED)
+ ext_service->DisableExtension(id);
+ else
+ ext_service->EnableExtension(id);
+ }
break;
}
case kOpenContentSettingsCommand: {
diff --git a/chrome/browser/notifications/notification_options_menu_model.h b/chrome/browser/notifications/notification_options_menu_model.h
index 2044da5..b276e11 100644
--- a/chrome/browser/notifications/notification_options_menu_model.h
+++ b/chrome/browser/notifications/notification_options_menu_model.h
@@ -15,6 +15,10 @@ class NotificationOptionsMenuModel : public menus::SimpleMenuModel,
explicit NotificationOptionsMenuModel(Balloon* balloon);
virtual ~NotificationOptionsMenuModel();
+ // Overridden from menus::SimpleMenuModel:
+ virtual bool IsLabelForCommandIdDynamic(int command_id) const;
+ virtual string16 GetLabelForCommandId(int command_id) const;
+
// Overridden from menus::SimpleMenuModel::Delegate:
virtual bool IsCommandIdChecked(int command_id) const;
virtual bool IsCommandIdEnabled(int command_id) const;