Chromium Code Reviews| 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" | 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( |
| 18 Profile* profile, | 18 Profile* profile, |
| 19 const GURL& url, | 19 const GURL& url, |
| 20 const WebsiteSettingsUI::PermissionInfo& info, | 20 const WebsiteSettingsUI::PermissionInfo& info, |
| 21 const ChangeCallback& callback) | 21 const ChangeCallback& callback) |
| 22 : ui::SimpleMenuModel(this), | 22 : ui::SimpleMenuModel(this), |
| 23 host_content_settings_map_( | 23 host_content_settings_map_( |
| 24 HostContentSettingsMapFactory::GetForProfile(profile)), | 24 HostContentSettingsMapFactory::GetForProfile(profile)), |
| 25 permission_(info), | 25 permission_(info), |
| 26 callback_(callback) { | 26 callback_(callback) { |
| 27 DCHECK(!callback_.is_null()); | 27 DCHECK(!callback_.is_null()); |
| 28 base::string16 label; | 28 base::string16 label; |
| 29 | 29 |
| 30 // Retrieve the string to show for the default setting for this permission. | |
| 30 ContentSetting effective_default_setting = permission_.default_setting; | 31 ContentSetting effective_default_setting = permission_.default_setting; |
| 31 | 32 |
| 32 #if BUILDFLAG(ENABLE_PLUGINS) | 33 #if BUILDFLAG(ENABLE_PLUGINS) |
| 33 effective_default_setting = PluginsFieldTrial::EffectiveContentSetting( | 34 effective_default_setting = PluginsFieldTrial::EffectiveContentSetting( |
| 34 host_content_settings_map_, permission_.type, | 35 host_content_settings_map_, permission_.type, |
| 35 permission_.default_setting); | 36 permission_.default_setting); |
| 36 #endif // BUILDFLAG(ENABLE_PLUGINS) | 37 #endif // BUILDFLAG(ENABLE_PLUGINS) |
| 37 | 38 |
| 38 switch (effective_default_setting) { | 39 switch (effective_default_setting) { |
| 39 case CONTENT_SETTING_ALLOW: | 40 case CONTENT_SETTING_ALLOW: |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 61 NOTREACHED(); | 62 NOTREACHED(); |
| 62 default: | 63 default: |
| 63 break; | 64 break; |
| 64 } | 65 } |
| 65 | 66 |
| 66 // The Material UI for site settings uses comboboxes instead of menubuttons, | 67 // The Material UI for site settings uses comboboxes instead of menubuttons, |
| 67 // which means the elements of the menu themselves have to be shorter, instead | 68 // which means the elements of the menu themselves have to be shorter, instead |
| 68 // of simply setting a shorter label on the menubutton. | 69 // of simply setting a shorter label on the menubutton. |
| 69 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { | 70 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
| 70 label = WebsiteSettingsUI::PermissionActionToUIString( | 71 label = WebsiteSettingsUI::PermissionActionToUIString( |
| 71 profile, info.type, info.setting, effective_default_setting, | 72 profile, info.type, CONTENT_SETTING_DEFAULT, effective_default_setting, |
| 72 info.source); | 73 info.source); |
| 73 } | 74 } |
| 74 | 75 |
| 75 AddCheckItem(CONTENT_SETTING_DEFAULT, label); | 76 AddCheckItem(CONTENT_SETTING_DEFAULT, label); |
| 76 | 77 |
| 78 // Retrieve the string to show for allowing the permission. | |
| 77 // Notifications does not support CONTENT_SETTING_ALLOW in incognito. | 79 // Notifications does not support CONTENT_SETTING_ALLOW in incognito. |
| 78 bool allow_disabled_for_notifications = | 80 bool allow_disabled_for_notifications = |
| 79 permission_.is_incognito && | 81 permission_.is_incognito && |
| 80 permission_.type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS; | 82 permission_.type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS; |
| 81 // Media only supports CONTENT_SETTTING_ALLOW for secure origins. | 83 // Media only supports CONTENT_SETTTING_ALLOW for secure origins. |
| 82 bool is_media_permission = | 84 bool is_media_permission = |
| 83 permission_.type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || | 85 permission_.type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || |
| 84 permission_.type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA; | 86 permission_.type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA; |
| 85 if (!allow_disabled_for_notifications && | 87 if (!allow_disabled_for_notifications && |
| 86 (!is_media_permission || content::IsOriginSecure(url))) { | 88 (!is_media_permission || content::IsOriginSecure(url))) { |
| 87 label = l10n_util::GetStringUTF16( | 89 label = l10n_util::GetStringUTF16( |
| 88 IDS_WEBSITE_SETTINGS_MENU_ITEM_ALLOW); | 90 IDS_WEBSITE_SETTINGS_MENU_ITEM_ALLOW); |
| 91 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { | |
| 92 label = WebsiteSettingsUI::PermissionActionToUIString( | |
| 93 profile, info.type, CONTENT_SETTING_ALLOW, effective_default_setting, | |
| 94 info.source); | |
| 95 } | |
| 89 AddCheckItem(CONTENT_SETTING_ALLOW, label); | 96 AddCheckItem(CONTENT_SETTING_ALLOW, label); |
| 90 } | 97 } |
| 91 | 98 |
| 92 // TODO(tommycli): With the HTML5 by Default feature, Flash is treated the | 99 // TODO(tommycli): With the HTML5 by Default feature, Flash is treated the |
| 93 // same as any other permission with ASK, i.e. there is no ASK exception. | 100 // same as any other permission with ASK, i.e. there is no ASK exception. |
| 94 // Once the feature flag is gone, remove this block of code entirely. | 101 // Once the feature flag is gone, remove this block of code entirely. |
| 95 if (permission_.type == CONTENT_SETTINGS_TYPE_PLUGINS && | 102 if (permission_.type == CONTENT_SETTINGS_TYPE_PLUGINS && |
| 96 !PluginUtils::ShouldPreferHtmlOverPlugins(host_content_settings_map_)) { | 103 !PluginUtils::ShouldPreferHtmlOverPlugins(host_content_settings_map_)) { |
| 97 label = l10n_util::GetStringUTF16( | 104 label = l10n_util::GetStringUTF16( |
| 98 IDS_WEBSITE_SETTINGS_MENU_ITEM_DETECT_IMPORTANT_CONTENT); | 105 IDS_WEBSITE_SETTINGS_MENU_ITEM_DETECT_IMPORTANT_CONTENT); |
| 99 AddCheckItem(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, label); | 106 AddCheckItem(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, label); |
| 100 } | 107 } |
| 101 | 108 |
| 109 // Retrieve the string to show for blocking the permission. | |
|
palmer
2017/03/07 23:39:46
Nit: These comments suggest that moving this code
Patti Lor
2017/03/08 06:58:41
Yeah, I did consider this - it's pretty simple for
| |
| 102 label = l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_MENU_ITEM_BLOCK); | 110 label = l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_MENU_ITEM_BLOCK); |
| 111 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { | |
| 112 label = WebsiteSettingsUI::PermissionActionToUIString( | |
| 113 profile, info.type, CONTENT_SETTING_BLOCK, effective_default_setting, | |
| 114 info.source); | |
| 115 } | |
| 103 AddCheckItem(CONTENT_SETTING_BLOCK, label); | 116 AddCheckItem(CONTENT_SETTING_BLOCK, label); |
| 104 } | 117 } |
| 105 | 118 |
| 106 PermissionMenuModel::PermissionMenuModel(Profile* profile, | 119 PermissionMenuModel::PermissionMenuModel(Profile* profile, |
| 107 const GURL& url, | 120 const GURL& url, |
| 108 ContentSetting setting, | 121 ContentSetting setting, |
| 109 const ChangeCallback& callback) | 122 const ChangeCallback& callback) |
| 110 : ui::SimpleMenuModel(this), | 123 : ui::SimpleMenuModel(this), |
| 111 host_content_settings_map_( | 124 host_content_settings_map_( |
| 112 HostContentSettingsMapFactory::GetForProfile(profile)), | 125 HostContentSettingsMapFactory::GetForProfile(profile)), |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 135 } | 148 } |
| 136 | 149 |
| 137 bool PermissionMenuModel::IsCommandIdEnabled(int command_id) const { | 150 bool PermissionMenuModel::IsCommandIdEnabled(int command_id) const { |
| 138 return true; | 151 return true; |
| 139 } | 152 } |
| 140 | 153 |
| 141 void PermissionMenuModel::ExecuteCommand(int command_id, int event_flags) { | 154 void PermissionMenuModel::ExecuteCommand(int command_id, int event_flags) { |
| 142 permission_.setting = static_cast<ContentSetting>(command_id); | 155 permission_.setting = static_cast<ContentSetting>(command_id); |
| 143 callback_.Run(permission_); | 156 callback_.Run(permission_); |
| 144 } | 157 } |
| OLD | NEW |