| 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/browser/content_settings/host_content_settings_map_factory.h" |
| 8 #include "chrome/browser/plugins/plugin_utils.h" |
| 7 #include "chrome/browser/plugins/plugins_field_trial.h" | 9 #include "chrome/browser/plugins/plugins_field_trial.h" |
| 8 #include "chrome/common/chrome_features.h" | 10 #include "chrome/common/chrome_features.h" |
| 9 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
| 10 #include "content/public/common/origin_util.h" | 12 #include "content/public/common/origin_util.h" |
| 11 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
| 12 | 14 |
| 13 PermissionMenuModel::PermissionMenuModel( | 15 PermissionMenuModel::PermissionMenuModel( |
| 16 Profile* profile, |
| 14 const GURL& url, | 17 const GURL& url, |
| 15 const WebsiteSettingsUI::PermissionInfo& info, | 18 const WebsiteSettingsUI::PermissionInfo& info, |
| 16 const ChangeCallback& callback) | 19 const ChangeCallback& callback) |
| 17 : ui::SimpleMenuModel(this), permission_(info), callback_(callback) { | 20 : ui::SimpleMenuModel(this), |
| 21 host_content_settings_map_( |
| 22 HostContentSettingsMapFactory::GetForProfile(profile)), |
| 23 permission_(info), |
| 24 callback_(callback) { |
| 18 DCHECK(!callback_.is_null()); | 25 DCHECK(!callback_.is_null()); |
| 19 base::string16 label; | 26 base::string16 label; |
| 20 | 27 |
| 21 ContentSetting effective_default_setting = permission_.default_setting; | 28 ContentSetting effective_default_setting = permission_.default_setting; |
| 22 | 29 |
| 23 #if defined(ENABLE_PLUGINS) | 30 #if defined(ENABLE_PLUGINS) |
| 24 effective_default_setting = PluginsFieldTrial::EffectiveContentSetting( | 31 effective_default_setting = PluginsFieldTrial::EffectiveContentSetting( |
| 25 permission_.type, permission_.default_setting); | 32 host_content_settings_map_, permission_.type, |
| 33 permission_.default_setting); |
| 26 #endif // defined(ENABLE_PLUGINS) | 34 #endif // defined(ENABLE_PLUGINS) |
| 27 | 35 |
| 28 switch (effective_default_setting) { | 36 switch (effective_default_setting) { |
| 29 case CONTENT_SETTING_ALLOW: | 37 case CONTENT_SETTING_ALLOW: |
| 30 label = l10n_util::GetStringUTF16( | 38 label = l10n_util::GetStringUTF16( |
| 31 IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_ALLOW); | 39 IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_ALLOW); |
| 32 break; | 40 break; |
| 33 case CONTENT_SETTING_BLOCK: | 41 case CONTENT_SETTING_BLOCK: |
| 34 label = l10n_util::GetStringUTF16( | 42 label = l10n_util::GetStringUTF16( |
| 35 IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_BLOCK); | 43 IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_BLOCK); |
| 36 break; | 44 break; |
| 37 case CONTENT_SETTING_ASK: | 45 case CONTENT_SETTING_ASK: |
| 38 label = | 46 label = |
| 39 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_ASK); | 47 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_ASK); |
| 40 break; | 48 break; |
| 41 case CONTENT_SETTING_DETECT_IMPORTANT_CONTENT: | 49 case CONTENT_SETTING_DETECT_IMPORTANT_CONTENT: |
| 42 // TODO(tommycli): We display the ASK string for DETECT because with | 50 // TODO(tommycli): We display the ASK string for DETECT because with |
| 43 // HTML5 by Default, Chrome will ask before running Flash on most sites. | 51 // HTML5 by Default, Chrome will ask before running Flash on most sites. |
| 44 // Once the feature flag is gone, migrate the actual setting to ASK. | 52 // Once the feature flag is gone, migrate the actual setting to ASK. |
| 45 label = l10n_util::GetStringUTF16( | 53 label = l10n_util::GetStringUTF16( |
| 46 base::FeatureList::IsEnabled(features::kPreferHtmlOverPlugins) | 54 PluginUtils::ShouldPreferHtmlOverPlugins(host_content_settings_map_) |
| 47 ? IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_ASK | 55 ? IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_ASK |
| 48 : IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_DETECT_IMPORTANT_CONTENT)
; | 56 : IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_DETECT_IMPORTANT_CONTENT)
; |
| 49 break; | 57 break; |
| 50 case CONTENT_SETTING_NUM_SETTINGS: | 58 case CONTENT_SETTING_NUM_SETTINGS: |
| 51 NOTREACHED(); | 59 NOTREACHED(); |
| 52 default: | 60 default: |
| 53 break; | 61 break; |
| 54 } | 62 } |
| 55 AddCheckItem(CONTENT_SETTING_DEFAULT, label); | 63 AddCheckItem(CONTENT_SETTING_DEFAULT, label); |
| 56 | 64 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 76 !is_exclusive_access_on_file) { | 84 !is_exclusive_access_on_file) { |
| 77 label = l10n_util::GetStringUTF16( | 85 label = l10n_util::GetStringUTF16( |
| 78 IDS_WEBSITE_SETTINGS_MENU_ITEM_ALLOW); | 86 IDS_WEBSITE_SETTINGS_MENU_ITEM_ALLOW); |
| 79 AddCheckItem(CONTENT_SETTING_ALLOW, label); | 87 AddCheckItem(CONTENT_SETTING_ALLOW, label); |
| 80 } | 88 } |
| 81 | 89 |
| 82 // TODO(tommycli): With the HTML5 by Default feature, Flash is treated the | 90 // TODO(tommycli): With the HTML5 by Default feature, Flash is treated the |
| 83 // same as any other permission with ASK, i.e. there is no ASK exception. | 91 // same as any other permission with ASK, i.e. there is no ASK exception. |
| 84 // Once the feature flag is gone, remove this block of code entirely. | 92 // Once the feature flag is gone, remove this block of code entirely. |
| 85 if (permission_.type == CONTENT_SETTINGS_TYPE_PLUGINS && | 93 if (permission_.type == CONTENT_SETTINGS_TYPE_PLUGINS && |
| 86 !base::FeatureList::IsEnabled(features::kPreferHtmlOverPlugins)) { | 94 !PluginUtils::ShouldPreferHtmlOverPlugins(host_content_settings_map_)) { |
| 87 label = l10n_util::GetStringUTF16( | 95 label = l10n_util::GetStringUTF16( |
| 88 IDS_WEBSITE_SETTINGS_MENU_ITEM_DETECT_IMPORTANT_CONTENT); | 96 IDS_WEBSITE_SETTINGS_MENU_ITEM_DETECT_IMPORTANT_CONTENT); |
| 89 AddCheckItem(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, label); | 97 AddCheckItem(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, label); |
| 90 } | 98 } |
| 91 | 99 |
| 92 if (permission_.type != CONTENT_SETTINGS_TYPE_FULLSCREEN && | 100 if (permission_.type != CONTENT_SETTINGS_TYPE_FULLSCREEN && |
| 93 !is_exclusive_access_on_file) { | 101 !is_exclusive_access_on_file) { |
| 94 label = l10n_util::GetStringUTF16( | 102 label = l10n_util::GetStringUTF16( |
| 95 IDS_WEBSITE_SETTINGS_MENU_ITEM_BLOCK); | 103 IDS_WEBSITE_SETTINGS_MENU_ITEM_BLOCK); |
| 96 AddCheckItem(CONTENT_SETTING_BLOCK, label); | 104 AddCheckItem(CONTENT_SETTING_BLOCK, label); |
| 97 } | 105 } |
| 98 } | 106 } |
| 99 | 107 |
| 100 PermissionMenuModel::PermissionMenuModel(const GURL& url, | 108 PermissionMenuModel::PermissionMenuModel(Profile* profile, |
| 109 const GURL& url, |
| 101 ContentSetting setting, | 110 ContentSetting setting, |
| 102 const ChangeCallback& callback) | 111 const ChangeCallback& callback) |
| 103 : ui::SimpleMenuModel(this), callback_(callback) { | 112 : ui::SimpleMenuModel(this), |
| 113 host_content_settings_map_( |
| 114 HostContentSettingsMapFactory::GetForProfile(profile)), |
| 115 callback_(callback) { |
| 104 DCHECK(setting == CONTENT_SETTING_ALLOW || setting == CONTENT_SETTING_BLOCK); | 116 DCHECK(setting == CONTENT_SETTING_ALLOW || setting == CONTENT_SETTING_BLOCK); |
| 105 permission_.type = CONTENT_SETTINGS_TYPE_DEFAULT; | 117 permission_.type = CONTENT_SETTINGS_TYPE_DEFAULT; |
| 106 permission_.setting = setting; | 118 permission_.setting = setting; |
| 107 permission_.default_setting = CONTENT_SETTING_NUM_SETTINGS; | 119 permission_.default_setting = CONTENT_SETTING_NUM_SETTINGS; |
| 108 AddCheckItem(CONTENT_SETTING_ALLOW, | 120 AddCheckItem(CONTENT_SETTING_ALLOW, |
| 109 l10n_util::GetStringUTF16(IDS_PERMISSION_ALLOW)); | 121 l10n_util::GetStringUTF16(IDS_PERMISSION_ALLOW)); |
| 110 AddCheckItem(CONTENT_SETTING_BLOCK, | 122 AddCheckItem(CONTENT_SETTING_BLOCK, |
| 111 l10n_util::GetStringUTF16(IDS_PERMISSION_DENY)); | 123 l10n_util::GetStringUTF16(IDS_PERMISSION_DENY)); |
| 112 } | 124 } |
| 113 | 125 |
| 114 PermissionMenuModel::~PermissionMenuModel() {} | 126 PermissionMenuModel::~PermissionMenuModel() {} |
| 115 | 127 |
| 116 bool PermissionMenuModel::IsCommandIdChecked(int command_id) const { | 128 bool PermissionMenuModel::IsCommandIdChecked(int command_id) const { |
| 117 ContentSetting setting = permission_.setting; | 129 ContentSetting setting = permission_.setting; |
| 118 | 130 |
| 119 #if defined(ENABLE_PLUGINS) | 131 #if defined(ENABLE_PLUGINS) |
| 120 setting = PluginsFieldTrial::EffectiveContentSetting(permission_.type, | 132 setting = PluginsFieldTrial::EffectiveContentSetting( |
| 121 permission_.setting); | 133 host_content_settings_map_, permission_.type, permission_.setting); |
| 122 #endif // defined(ENABLE_PLUGINS) | 134 #endif // defined(ENABLE_PLUGINS) |
| 123 | 135 |
| 124 return setting == command_id; | 136 return setting == command_id; |
| 125 } | 137 } |
| 126 | 138 |
| 127 bool PermissionMenuModel::IsCommandIdEnabled(int command_id) const { | 139 bool PermissionMenuModel::IsCommandIdEnabled(int command_id) const { |
| 128 return true; | 140 return true; |
| 129 } | 141 } |
| 130 | 142 |
| 131 void PermissionMenuModel::ExecuteCommand(int command_id, int event_flags) { | 143 void PermissionMenuModel::ExecuteCommand(int command_id, int event_flags) { |
| 132 permission_.setting = static_cast<ContentSetting>(command_id); | 144 permission_.setting = static_cast<ContentSetting>(command_id); |
| 133 callback_.Run(permission_); | 145 callback_.Run(permission_); |
| 134 } | 146 } |
| OLD | NEW |