| 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/ui/website_settings/permission_menu_model.h" | 5 #include "chrome/browser/ui/website_settings/permission_menu_model.h" |
| 6 | 6 |
| 7 #include "chrome/grit/generated_resources.h" | 7 #include "chrome/grit/generated_resources.h" |
| 8 #include "components/plugins/common/plugins_field_trial.h" |
| 8 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
| 9 | 10 |
| 10 PermissionMenuModel::PermissionMenuModel( | 11 PermissionMenuModel::PermissionMenuModel( |
| 11 const GURL& url, | 12 const GURL& url, |
| 12 const WebsiteSettingsUI::PermissionInfo& info, | 13 const WebsiteSettingsUI::PermissionInfo& info, |
| 13 const ChangeCallback& callback) | 14 const ChangeCallback& callback) |
| 14 : ui::SimpleMenuModel(this), permission_(info), callback_(callback) { | 15 : ui::SimpleMenuModel(this), permission_(info), callback_(callback) { |
| 15 DCHECK(!callback_.is_null()); | 16 DCHECK(!callback_.is_null()); |
| 16 base::string16 label; | 17 base::string16 label; |
| 17 switch (permission_.default_setting) { | 18 switch (permission_.default_setting) { |
| 18 case CONTENT_SETTING_ALLOW: | 19 case CONTENT_SETTING_ALLOW: |
| 19 label = l10n_util::GetStringUTF16( | 20 // For Plugins, allow flag to override displayed content setting. |
| 20 IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_ALLOW); | 21 if (permission_.type == CONTENT_SETTINGS_TYPE_PLUGINS && |
| 22 PluginsFieldTrial::EnableForcePluginPowerSaver()) { |
| 23 label = l10n_util::GetStringUTF16( |
| 24 IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_DETECT_IMPORTANT_CONTENT); |
| 25 } else { |
| 26 label = l10n_util::GetStringUTF16( |
| 27 IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_ALLOW); |
| 28 } |
| 21 break; | 29 break; |
| 22 case CONTENT_SETTING_BLOCK: | 30 case CONTENT_SETTING_BLOCK: |
| 23 label = l10n_util::GetStringUTF16( | 31 label = l10n_util::GetStringUTF16( |
| 24 IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_BLOCK); | 32 IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_BLOCK); |
| 25 break; | 33 break; |
| 26 case CONTENT_SETTING_ASK: | 34 case CONTENT_SETTING_ASK: |
| 27 // For Plugins, ASK is obsolete. Show as BLOCK to reflect actual behavior. | 35 // For Plugins, ASK is obsolete. Show as BLOCK to reflect actual behavior. |
| 28 label = l10n_util::GetStringUTF16( | 36 label = l10n_util::GetStringUTF16( |
| 29 permission_.type == CONTENT_SETTINGS_TYPE_PLUGINS | 37 permission_.type == CONTENT_SETTINGS_TYPE_PLUGINS |
| 30 ? IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_BLOCK | 38 ? IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_BLOCK |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 permission_.default_setting = CONTENT_SETTING_NUM_SETTINGS; | 91 permission_.default_setting = CONTENT_SETTING_NUM_SETTINGS; |
| 84 AddCheckItem(CONTENT_SETTING_ALLOW, | 92 AddCheckItem(CONTENT_SETTING_ALLOW, |
| 85 l10n_util::GetStringUTF16(IDS_PERMISSION_ALLOW)); | 93 l10n_util::GetStringUTF16(IDS_PERMISSION_ALLOW)); |
| 86 AddCheckItem(CONTENT_SETTING_BLOCK, | 94 AddCheckItem(CONTENT_SETTING_BLOCK, |
| 87 l10n_util::GetStringUTF16(IDS_PERMISSION_DENY)); | 95 l10n_util::GetStringUTF16(IDS_PERMISSION_DENY)); |
| 88 } | 96 } |
| 89 | 97 |
| 90 PermissionMenuModel::~PermissionMenuModel() {} | 98 PermissionMenuModel::~PermissionMenuModel() {} |
| 91 | 99 |
| 92 bool PermissionMenuModel::IsCommandIdChecked(int command_id) const { | 100 bool PermissionMenuModel::IsCommandIdChecked(int command_id) const { |
| 93 // For Plugins, ASK is obsolete. Show as BLOCK to reflect actual behavior. | 101 if (permission_.type == CONTENT_SETTINGS_TYPE_PLUGINS) { |
| 94 if (permission_.type == CONTENT_SETTINGS_TYPE_PLUGINS && | 102 // For Plugins, allow flag to override displayed content setting. |
| 95 permission_.setting == CONTENT_SETTING_ASK && | 103 if (permission_.setting == CONTENT_SETTING_ALLOW && |
| 96 command_id == CONTENT_SETTING_BLOCK) { | 104 PluginsFieldTrial::EnableForcePluginPowerSaver()) { |
| 97 return true; | 105 return command_id == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT; |
| 106 } |
| 107 |
| 108 // For Plugins, ASK is obsolete. Show as BLOCK to reflect actual behavior. |
| 109 if (permission_.setting == CONTENT_SETTING_ASK && |
| 110 command_id == CONTENT_SETTING_BLOCK) { |
| 111 return true; |
| 112 } |
| 98 } | 113 } |
| 114 |
| 99 return permission_.setting == command_id; | 115 return permission_.setting == command_id; |
| 100 } | 116 } |
| 101 | 117 |
| 102 bool PermissionMenuModel::IsCommandIdEnabled(int command_id) const { | 118 bool PermissionMenuModel::IsCommandIdEnabled(int command_id) const { |
| 103 return true; | 119 return true; |
| 104 } | 120 } |
| 105 | 121 |
| 106 bool PermissionMenuModel::GetAcceleratorForCommandId( | 122 bool PermissionMenuModel::GetAcceleratorForCommandId( |
| 107 int command_id, | 123 int command_id, |
| 108 ui::Accelerator* accelerator) { | 124 ui::Accelerator* accelerator) { |
| 109 // Accelerators are not supported. | 125 // Accelerators are not supported. |
| 110 return false; | 126 return false; |
| 111 } | 127 } |
| 112 | 128 |
| 113 void PermissionMenuModel::ExecuteCommand(int command_id, int event_flags) { | 129 void PermissionMenuModel::ExecuteCommand(int command_id, int event_flags) { |
| 114 permission_.setting = static_cast<ContentSetting>(command_id); | 130 permission_.setting = static_cast<ContentSetting>(command_id); |
| 115 callback_.Run(permission_); | 131 callback_.Run(permission_); |
| 116 } | 132 } |
| OLD | NEW |