| 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/page_info/permission_menu_model.h" | 5 #include "chrome/browser/ui/page_info/permission_menu_model.h" |
| 6 | 6 |
| 7 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 7 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 8 #include "chrome/browser/plugins/plugin_utils.h" | 8 #include "chrome/browser/plugins/plugin_utils.h" |
| 9 #include "chrome/browser/plugins/plugins_field_trial.h" | 9 #include "chrome/browser/plugins/plugins_field_trial.h" |
| 10 #include "chrome/common/chrome_features.h" | 10 #include "chrome/common/chrome_features.h" |
| 11 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
| 12 #include "content/public/common/origin_util.h" | 12 #include "content/public/common/origin_util.h" |
| 13 #include "ppapi/features/features.h" | 13 #include "ppapi/features/features.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/base/material_design/material_design_controller.h" | 15 #include "ui/base/material_design/material_design_controller.h" |
| 16 | 16 |
| 17 PermissionMenuModel::PermissionMenuModel( | 17 PermissionMenuModel::PermissionMenuModel(Profile* profile, |
| 18 Profile* profile, | 18 const GURL& url, |
| 19 const GURL& url, | 19 const PageInfoUI::PermissionInfo& info, |
| 20 const WebsiteSettingsUI::PermissionInfo& info, | 20 const ChangeCallback& callback) |
| 21 const ChangeCallback& callback) | |
| 22 : ui::SimpleMenuModel(this), | 21 : ui::SimpleMenuModel(this), |
| 23 host_content_settings_map_( | 22 host_content_settings_map_( |
| 24 HostContentSettingsMapFactory::GetForProfile(profile)), | 23 HostContentSettingsMapFactory::GetForProfile(profile)), |
| 25 permission_(info), | 24 permission_(info), |
| 26 callback_(callback) { | 25 callback_(callback) { |
| 27 DCHECK(!callback_.is_null()); | 26 DCHECK(!callback_.is_null()); |
| 28 base::string16 label; | 27 base::string16 label; |
| 29 | 28 |
| 30 // Retrieve the string to show for the default setting for this permission. | 29 // Retrieve the string to show for the default setting for this permission. |
| 31 ContentSetting effective_default_setting = permission_.default_setting; | 30 ContentSetting effective_default_setting = permission_.default_setting; |
| 32 | 31 |
| 33 #if BUILDFLAG(ENABLE_PLUGINS) | 32 #if BUILDFLAG(ENABLE_PLUGINS) |
| 34 effective_default_setting = PluginsFieldTrial::EffectiveContentSetting( | 33 effective_default_setting = PluginsFieldTrial::EffectiveContentSetting( |
| 35 host_content_settings_map_, permission_.type, | 34 host_content_settings_map_, permission_.type, |
| 36 permission_.default_setting); | 35 permission_.default_setting); |
| 37 #endif // BUILDFLAG(ENABLE_PLUGINS) | 36 #endif // BUILDFLAG(ENABLE_PLUGINS) |
| 38 | 37 |
| 39 switch (effective_default_setting) { | 38 switch (effective_default_setting) { |
| 40 case CONTENT_SETTING_ALLOW: | 39 case CONTENT_SETTING_ALLOW: |
| 41 label = l10n_util::GetStringUTF16( | 40 label = l10n_util::GetStringUTF16(IDS_PAGE_INFO_MENU_ITEM_DEFAULT_ALLOW); |
| 42 IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_ALLOW); | |
| 43 break; | 41 break; |
| 44 case CONTENT_SETTING_BLOCK: | 42 case CONTENT_SETTING_BLOCK: |
| 45 label = l10n_util::GetStringUTF16( | 43 label = l10n_util::GetStringUTF16(IDS_PAGE_INFO_MENU_ITEM_DEFAULT_BLOCK); |
| 46 IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_BLOCK); | |
| 47 break; | 44 break; |
| 48 case CONTENT_SETTING_ASK: | 45 case CONTENT_SETTING_ASK: |
| 49 label = | 46 label = l10n_util::GetStringUTF16(IDS_PAGE_INFO_MENU_ITEM_DEFAULT_ASK); |
| 50 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_ASK); | |
| 51 break; | 47 break; |
| 52 case CONTENT_SETTING_DETECT_IMPORTANT_CONTENT: | 48 case CONTENT_SETTING_DETECT_IMPORTANT_CONTENT: |
| 53 // TODO(tommycli): We display the ASK string for DETECT because with | 49 // TODO(tommycli): We display the ASK string for DETECT because with |
| 54 // HTML5 by Default, Chrome will ask before running Flash on most sites. | 50 // HTML5 by Default, Chrome will ask before running Flash on most sites. |
| 55 // Once the feature flag is gone, migrate the actual setting to ASK. | 51 // Once the feature flag is gone, migrate the actual setting to ASK. |
| 56 label = l10n_util::GetStringUTF16( | 52 label = l10n_util::GetStringUTF16( |
| 57 PluginUtils::ShouldPreferHtmlOverPlugins(host_content_settings_map_) | 53 PluginUtils::ShouldPreferHtmlOverPlugins(host_content_settings_map_) |
| 58 ? IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_ASK | 54 ? IDS_PAGE_INFO_MENU_ITEM_DEFAULT_ASK |
| 59 : IDS_WEBSITE_SETTINGS_MENU_ITEM_DEFAULT_DETECT_IMPORTANT_CONTENT)
; | 55 : IDS_PAGE_INFO_MENU_ITEM_DEFAULT_DETECT_IMPORTANT_CONTENT); |
| 60 break; | 56 break; |
| 61 case CONTENT_SETTING_NUM_SETTINGS: | 57 case CONTENT_SETTING_NUM_SETTINGS: |
| 62 NOTREACHED(); | 58 NOTREACHED(); |
| 63 default: | 59 default: |
| 64 break; | 60 break; |
| 65 } | 61 } |
| 66 | 62 |
| 67 // The Material UI for site settings uses comboboxes instead of menubuttons, | 63 // The Material UI for site settings uses comboboxes instead of menubuttons, |
| 68 // which means the elements of the menu themselves have to be shorter, instead | 64 // which means the elements of the menu themselves have to be shorter, instead |
| 69 // of simply setting a shorter label on the menubutton. | 65 // of simply setting a shorter label on the menubutton. |
| 70 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { | 66 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
| 71 label = WebsiteSettingsUI::PermissionActionToUIString( | 67 label = PageInfoUI::PermissionActionToUIString( |
| 72 profile, permission_.type, CONTENT_SETTING_DEFAULT, | 68 profile, permission_.type, CONTENT_SETTING_DEFAULT, |
| 73 effective_default_setting, permission_.source); | 69 effective_default_setting, permission_.source); |
| 74 } | 70 } |
| 75 | 71 |
| 76 AddCheckItem(CONTENT_SETTING_DEFAULT, label); | 72 AddCheckItem(CONTENT_SETTING_DEFAULT, label); |
| 77 | 73 |
| 78 // Retrieve the string to show for allowing the permission. | 74 // Retrieve the string to show for allowing the permission. |
| 79 // Notifications does not support CONTENT_SETTING_ALLOW in incognito. | 75 // Notifications does not support CONTENT_SETTING_ALLOW in incognito. |
| 80 bool allow_disabled_for_notifications = | 76 bool allow_disabled_for_notifications = |
| 81 permission_.is_incognito && | 77 permission_.is_incognito && |
| 82 permission_.type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS; | 78 permission_.type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS; |
| 83 // Media only supports CONTENT_SETTTING_ALLOW for secure origins. | 79 // Media only supports CONTENT_SETTTING_ALLOW for secure origins. |
| 84 bool is_media_permission = | 80 bool is_media_permission = |
| 85 permission_.type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || | 81 permission_.type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || |
| 86 permission_.type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA; | 82 permission_.type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA; |
| 87 if (!allow_disabled_for_notifications && | 83 if (!allow_disabled_for_notifications && |
| 88 (!is_media_permission || content::IsOriginSecure(url))) { | 84 (!is_media_permission || content::IsOriginSecure(url))) { |
| 89 label = l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_MENU_ITEM_ALLOW); | 85 label = l10n_util::GetStringUTF16(IDS_PAGE_INFO_MENU_ITEM_ALLOW); |
| 90 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { | 86 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
| 91 label = WebsiteSettingsUI::PermissionActionToUIString( | 87 label = PageInfoUI::PermissionActionToUIString( |
| 92 profile, permission_.type, CONTENT_SETTING_ALLOW, | 88 profile, permission_.type, CONTENT_SETTING_ALLOW, |
| 93 effective_default_setting, permission_.source); | 89 effective_default_setting, permission_.source); |
| 94 } | 90 } |
| 95 AddCheckItem(CONTENT_SETTING_ALLOW, label); | 91 AddCheckItem(CONTENT_SETTING_ALLOW, label); |
| 96 } | 92 } |
| 97 | 93 |
| 98 // TODO(tommycli): With the HTML5 by Default feature, Flash is treated the | 94 // TODO(tommycli): With the HTML5 by Default feature, Flash is treated the |
| 99 // same as any other permission with ASK, i.e. there is no ASK exception. | 95 // same as any other permission with ASK, i.e. there is no ASK exception. |
| 100 // Once the feature flag is gone, remove this block of code entirely. | 96 // Once the feature flag is gone, remove this block of code entirely. |
| 101 if (permission_.type == CONTENT_SETTINGS_TYPE_PLUGINS && | 97 if (permission_.type == CONTENT_SETTINGS_TYPE_PLUGINS && |
| 102 !PluginUtils::ShouldPreferHtmlOverPlugins(host_content_settings_map_)) { | 98 !PluginUtils::ShouldPreferHtmlOverPlugins(host_content_settings_map_)) { |
| 103 label = l10n_util::GetStringUTF16( | 99 label = l10n_util::GetStringUTF16( |
| 104 IDS_WEBSITE_SETTINGS_MENU_ITEM_DETECT_IMPORTANT_CONTENT); | 100 IDS_PAGE_INFO_MENU_ITEM_DETECT_IMPORTANT_CONTENT); |
| 105 AddCheckItem(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, label); | 101 AddCheckItem(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, label); |
| 106 } | 102 } |
| 107 | 103 |
| 108 // Retrieve the string to show for blocking the permission. | 104 // Retrieve the string to show for blocking the permission. |
| 109 label = l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_MENU_ITEM_BLOCK); | 105 label = l10n_util::GetStringUTF16(IDS_PAGE_INFO_MENU_ITEM_BLOCK); |
| 110 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { | 106 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
| 111 label = WebsiteSettingsUI::PermissionActionToUIString( | 107 label = PageInfoUI::PermissionActionToUIString( |
| 112 profile, info.type, CONTENT_SETTING_BLOCK, effective_default_setting, | 108 profile, info.type, CONTENT_SETTING_BLOCK, effective_default_setting, |
| 113 info.source); | 109 info.source); |
| 114 } | 110 } |
| 115 AddCheckItem(CONTENT_SETTING_BLOCK, label); | 111 AddCheckItem(CONTENT_SETTING_BLOCK, label); |
| 116 } | 112 } |
| 117 | 113 |
| 118 PermissionMenuModel::PermissionMenuModel(Profile* profile, | 114 PermissionMenuModel::PermissionMenuModel(Profile* profile, |
| 119 const GURL& url, | 115 const GURL& url, |
| 120 ContentSetting setting, | 116 ContentSetting setting, |
| 121 const ChangeCallback& callback) | 117 const ChangeCallback& callback) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 147 } | 143 } |
| 148 | 144 |
| 149 bool PermissionMenuModel::IsCommandIdEnabled(int command_id) const { | 145 bool PermissionMenuModel::IsCommandIdEnabled(int command_id) const { |
| 150 return true; | 146 return true; |
| 151 } | 147 } |
| 152 | 148 |
| 153 void PermissionMenuModel::ExecuteCommand(int command_id, int event_flags) { | 149 void PermissionMenuModel::ExecuteCommand(int command_id, int event_flags) { |
| 154 permission_.setting = static_cast<ContentSetting>(command_id); | 150 permission_.setting = static_cast<ContentSetting>(command_id); |
| 155 callback_.Run(permission_); | 151 callback_.Run(permission_); |
| 156 } | 152 } |
| OLD | NEW |