Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/webui/plugins/plugins_handler.h" | 5 #include "chrome/browser/ui/webui/plugins/plugins_handler.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/common/chrome_content_client.h" | 23 #include "chrome/common/chrome_content_client.h" |
| 24 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
| 25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 26 #include "chrome/grit/generated_resources.h" | 26 #include "chrome/grit/generated_resources.h" |
| 27 #include "components/content_settings/core/browser/host_content_settings_map.h" | 27 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 28 #include "content/public/browser/notification_observer.h" | 28 #include "content/public/browser/notification_observer.h" |
| 29 #include "content/public/browser/plugin_service.h" | 29 #include "content/public/browser/plugin_service.h" |
| 30 #include "content/public/browser/web_ui.h" | 30 #include "content/public/browser/web_ui.h" |
| 31 #include "content/public/common/content_constants.h" | 31 #include "content/public/common/content_constants.h" |
| 32 #include "mojo/common/common_type_converters.h" | |
| 32 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 33 | 34 |
| 34 using content::WebPluginInfo; | 35 using content::WebPluginInfo; |
| 35 // Holds grouped plugins. The key is the group identifier and | 36 // Holds grouped plugins. The key is the group identifier and |
| 36 // the value is the list of plugins belonging to the group. | 37 // the value is the list of plugins belonging to the group. |
| 37 using PluginGroups = base::hash_map<std::string, | 38 using PluginGroups = |
| 38 std::vector<const content::WebPluginInfo*>>; | 39 base::hash_map<std::string, std::vector<const content::WebPluginInfo*>>; |
| 39 | 40 |
| 40 namespace { | 41 namespace { |
| 41 | 42 |
| 42 // Callback function to process result of EnablePlugin method. | 43 // Callback function to process result of EnablePlugin method. |
| 43 void AssertPluginEnabled(bool did_enable) { | 44 void AssertPluginEnabled(bool did_enable) { |
| 44 DCHECK(did_enable); | 45 DCHECK(did_enable); |
| 45 } | 46 } |
| 46 | 47 |
| 47 base::string16 PluginTypeToString(int type) { | 48 base::string16 PluginTypeToString(int type) { |
| 48 // The type is stored as an |int|, but doing the switch on the right | 49 // The type is stored as an |int|, but doing the switch on the right |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 desc += base::ASCIIToUTF16(" Debug"); | 82 desc += base::ASCIIToUTF16(" Debug"); |
| 82 #else | 83 #else |
| 83 // On Chromium, we can name it what it really is; the system plugin. | 84 // On Chromium, we can name it what it really is; the system plugin. |
| 84 desc += base::ASCIIToUTF16(" System"); | 85 desc += base::ASCIIToUTF16(" System"); |
| 85 #endif | 86 #endif |
| 86 } | 87 } |
| 87 } | 88 } |
| 88 return desc; | 89 return desc; |
| 89 } | 90 } |
| 90 | 91 |
| 91 scoped_ptr<base::ListValue> GetPluginMimeTypes(const WebPluginInfo& plugin) { | 92 mojo::Array<MimeTypePtr> GeneratePluginMimeTypes(const WebPluginInfo& plugin) { |
| 92 scoped_ptr<base::ListValue> mime_types(new base::ListValue()); | 93 mojo::Array<MimeTypePtr> mime_types(0u); |
| 93 for (const auto& plugin_mime_type: plugin.mime_types) { | 94 for (const auto& plugin_mime_type : plugin.mime_types) { |
| 94 base::DictionaryValue* mime_type = new base::DictionaryValue(); | 95 MimeTypePtr mime_type(MimeType::New()); |
| 95 mime_type->SetString("mimeType", plugin_mime_type.mime_type); | 96 mime_type->description = mojo::String::From(plugin_mime_type.description); |
| 96 mime_type->SetString("description", plugin_mime_type.description); | |
| 97 | 97 |
| 98 base::ListValue* file_extensions = new base::ListValue(); | 98 mime_type->mime_type = mojo::String::From(plugin_mime_type.mime_type); |
| 99 for (const auto& mime_file_extension : plugin_mime_type.file_extensions) { | 99 mime_type->file_extensions = |
| 100 file_extensions->Append(new base::StringValue(mime_file_extension)); | 100 mojo::Array<mojo::String>::From(plugin_mime_type.file_extensions); |
| 101 } | 101 mime_types.push_back(std::move(mime_type)); |
| 102 mime_type->Set("fileExtensions", file_extensions); | |
| 103 mime_types->Append(mime_type); | |
| 104 } | 102 } |
| 103 | |
| 105 return mime_types; | 104 return mime_types; |
| 106 } | 105 } |
| 107 | 106 |
| 108 } // namespace | 107 } // namespace |
| 109 | 108 |
| 110 | 109 PluginsHandler::PluginsHandler( |
| 111 PluginsHandler::PluginsHandler() : weak_ptr_factory_(this) { | 110 content::WebUI* web_ui, |
| 112 } | 111 mojo::InterfaceRequest<PluginsHandlerMojo> request) |
| 113 | 112 : web_ui_(web_ui), |
| 114 PluginsHandler::~PluginsHandler() { | 113 binding_(this, std::move(request)), |
| 115 } | 114 weak_ptr_factory_(this) { |
| 116 | 115 Profile* profile = Profile::FromWebUI(web_ui_); |
| 117 void PluginsHandler::RegisterMessages() { | |
| 118 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 119 | |
| 120 PrefService* prefs = profile->GetPrefs(); | 116 PrefService* prefs = profile->GetPrefs(); |
| 121 show_details_.Init(prefs::kPluginsShowDetails, prefs); | 117 show_details_.Init(prefs::kPluginsShowDetails, prefs); |
| 122 | 118 |
| 123 registrar_.Add(this, | 119 registrar_.Add(this, chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, |
| 124 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, | |
| 125 content::Source<Profile>(profile)); | 120 content::Source<Profile>(profile)); |
| 126 | |
| 127 web_ui()->RegisterMessageCallback("requestPluginsData", | |
| 128 base::Bind(&PluginsHandler::HandleRequestPluginsData, | |
| 129 base::Unretained(this))); | |
| 130 web_ui()->RegisterMessageCallback("enablePlugin", | |
| 131 base::Bind(&PluginsHandler::HandleEnablePluginMessage, | |
| 132 base::Unretained(this))); | |
| 133 web_ui()->RegisterMessageCallback("setPluginAlwaysAllowed", | |
| 134 base::Bind(&PluginsHandler::HandleSetPluginAlwaysAllowed, | |
| 135 base::Unretained(this))); | |
| 136 web_ui()->RegisterMessageCallback("saveShowDetailsToPrefs", | |
| 137 base::Bind(&PluginsHandler::HandleSaveShowDetailsToPrefs, | |
| 138 base::Unretained(this))); | |
| 139 web_ui()->RegisterMessageCallback("getShowDetails", | |
| 140 base::Bind(&PluginsHandler::HandleGetShowDetails, | |
| 141 base::Unretained(this))); | |
| 142 } | 121 } |
| 143 | 122 |
| 144 void PluginsHandler::HandleRequestPluginsData(const base::ListValue* args) { | 123 PluginsHandler::~PluginsHandler() {} |
| 145 LoadPlugins(); | 124 |
| 125 void PluginsHandler::SetPluginEnabled(const mojo::String& plugin_path, | |
| 126 bool enable) { | |
| 127 Profile* profile = Profile::FromWebUI(web_ui_); | |
| 128 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); | |
| 129 plugin_prefs->EnablePlugin( | |
| 130 enable, base::FilePath(plugin_path.To<base::FilePath::StringType>()), | |
| 131 base::Bind(&AssertPluginEnabled)); | |
| 146 } | 132 } |
| 147 | 133 |
| 148 void PluginsHandler::HandleEnablePluginMessage(const base::ListValue* args) { | 134 void PluginsHandler::SetPluginGroupEnabled(const mojo::String& group_name, |
| 149 Profile* profile = Profile::FromWebUI(web_ui()); | 135 bool enable) { |
| 150 | 136 Profile* profile = Profile::FromWebUI(web_ui_); |
| 151 // Be robust in accepting badness since plugins display HTML (hence | |
| 152 // JavaScript). | |
| 153 if (args->GetSize() != 3) { | |
| 154 NOTREACHED(); | |
| 155 return; | |
| 156 } | |
| 157 | |
| 158 std::string enable_str; | |
| 159 std::string is_group_str; | |
| 160 if (!args->GetString(1, &enable_str) || !args->GetString(2, &is_group_str)) { | |
| 161 NOTREACHED(); | |
| 162 return; | |
| 163 } | |
| 164 bool enable = enable_str == "true"; | |
| 165 | |
| 166 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); | 137 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); |
| 167 if (is_group_str == "true") { | 138 base::string16 group_name_as_string16 = group_name.To<base::string16>(); |
| 168 base::string16 group_name; | 139 plugin_prefs->EnablePluginGroup(enable, group_name_as_string16); |
| 169 if (!args->GetString(0, &group_name)) { | 140 if (enable) { |
|
Dan Beam
2016/01/28 04:25:08
optional nit:
if (!enable)
return;
... l
dpapad
2016/01/28 18:32:54
Done.
| |
| 170 NOTREACHED(); | 141 // See http://crbug.com/50105 for background. |
| 171 return; | 142 base::string16 adobereader = |
| 172 } | 143 base::ASCIIToUTF16(PluginMetadata::kAdobeReaderGroupName); |
| 173 | 144 base::string16 internalpdf = |
| 174 plugin_prefs->EnablePluginGroup(enable, group_name); | 145 base::ASCIIToUTF16(ChromeContentClient::kPDFPluginName); |
| 175 if (enable) { | 146 if (group_name_as_string16 == adobereader) |
| 176 // See http://crbug.com/50105 for background. | 147 plugin_prefs->EnablePluginGroup(false, internalpdf); |
| 177 base::string16 adobereader = base::ASCIIToUTF16( | 148 else if (group_name_as_string16 == internalpdf) |
| 178 PluginMetadata::kAdobeReaderGroupName); | 149 plugin_prefs->EnablePluginGroup(false, adobereader); |
| 179 base::string16 internalpdf = | |
| 180 base::ASCIIToUTF16(ChromeContentClient::kPDFPluginName); | |
| 181 if (group_name == adobereader) | |
| 182 plugin_prefs->EnablePluginGroup(false, internalpdf); | |
| 183 else if (group_name == internalpdf) | |
| 184 plugin_prefs->EnablePluginGroup(false, adobereader); | |
| 185 } | |
| 186 } else { | |
| 187 base::FilePath::StringType file_path; | |
| 188 if (!args->GetString(0, &file_path)) { | |
| 189 NOTREACHED(); | |
| 190 return; | |
| 191 } | |
| 192 | |
| 193 plugin_prefs->EnablePlugin(enable, base::FilePath(file_path), | |
| 194 base::Bind(&AssertPluginEnabled)); | |
| 195 } | 150 } |
| 196 } | 151 } |
| 197 | 152 |
| 198 void PluginsHandler::HandleSaveShowDetailsToPrefs( | 153 void PluginsHandler::GetShowDetails(const GetShowDetailsCallback& callback) { |
| 199 const base::ListValue* args) { | 154 callback.Run(show_details_.GetValue()); |
| 200 std::string details_mode; | |
| 201 if (!args->GetString(0, &details_mode)) { | |
| 202 NOTREACHED(); | |
| 203 return; | |
| 204 } | |
| 205 show_details_.SetValue(details_mode == "true"); | |
| 206 } | 155 } |
| 207 | 156 |
| 208 void PluginsHandler::HandleGetShowDetails(const base::ListValue* args) { | 157 void PluginsHandler::SaveShowDetailsToPrefs(bool details_mode) { |
| 209 base::FundamentalValue show_details(show_details_.GetValue()); | 158 show_details_.SetValue(details_mode); |
| 210 web_ui()->CallJavascriptFunction("loadShowDetailsFromPrefs", show_details); | |
| 211 } | 159 } |
| 212 | 160 |
| 213 void PluginsHandler::HandleSetPluginAlwaysAllowed( | 161 void PluginsHandler::SetPluginAlwaysAllowed(const mojo::String& plugin, |
| 214 const base::ListValue* args) { | 162 bool allowed) { |
| 215 // Be robust in the input parameters, but crash in a Debug build. | 163 Profile* profile = Profile::FromWebUI(web_ui_); |
| 216 if (args->GetSize() != 2) { | |
| 217 NOTREACHED(); | |
| 218 return; | |
| 219 } | |
| 220 | |
| 221 std::string plugin; | |
| 222 bool allowed = false; | |
| 223 if (!args->GetString(0, &plugin) || !args->GetBoolean(1, &allowed)) { | |
| 224 NOTREACHED(); | |
| 225 return; | |
| 226 } | |
| 227 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 228 HostContentSettingsMapFactory::GetForProfile(profile)->SetContentSetting( | 164 HostContentSettingsMapFactory::GetForProfile(profile)->SetContentSetting( |
| 229 ContentSettingsPattern::Wildcard(), | 165 ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(), |
| 230 ContentSettingsPattern::Wildcard(), | 166 CONTENT_SETTINGS_TYPE_PLUGINS, plugin.get(), |
| 231 CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 232 plugin, | |
| 233 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_DEFAULT); | 167 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_DEFAULT); |
| 234 | 168 |
| 235 // Keep track of the whitelist separately, so that we can distinguish plugins | 169 // Keep track of the whitelist separately, so that we can distinguish plugins |
| 236 // whitelisted by the user from automatically whitelisted ones. | 170 // whitelisted by the user from automatically whitelisted ones. |
| 237 DictionaryPrefUpdate update(profile->GetPrefs(), | 171 DictionaryPrefUpdate update(profile->GetPrefs(), |
| 238 prefs::kContentSettingsPluginWhitelist); | 172 prefs::kContentSettingsPluginWhitelist); |
| 239 update->SetBoolean(plugin, allowed); | 173 update->SetBoolean(plugin, allowed); |
| 240 } | 174 } |
| 241 | 175 |
| 176 void PluginsHandler::GetPluginsData(const GetPluginsDataCallback& callback) { | |
| 177 if (weak_ptr_factory_.HasWeakPtrs()) | |
| 178 return; | |
| 179 | |
| 180 content::PluginService::GetInstance()->GetPlugins( | |
| 181 base::Bind(&PluginsHandler::RespondWithPluginsData, | |
| 182 weak_ptr_factory_.GetWeakPtr(), callback)); | |
| 183 } | |
| 184 | |
| 185 void PluginsHandler::SetClientPage(PluginsPageMojoPtr page) { | |
| 186 page_ = std::move(page); | |
| 187 } | |
| 188 | |
| 242 void PluginsHandler::Observe(int type, | 189 void PluginsHandler::Observe(int type, |
| 243 const content::NotificationSource& source, | 190 const content::NotificationSource& source, |
| 244 const content::NotificationDetails& details) { | 191 const content::NotificationDetails& details) { |
| 245 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); | 192 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); |
| 246 LoadPlugins(); | |
| 247 } | |
| 248 | 193 |
| 249 void PluginsHandler::LoadPlugins() { | |
| 250 if (weak_ptr_factory_.HasWeakPtrs()) | 194 if (weak_ptr_factory_.HasWeakPtrs()) |
| 251 return; | 195 return; |
| 252 | 196 |
| 253 content::PluginService::GetInstance()->GetPlugins( | 197 content::PluginService::GetInstance()->GetPlugins(base::Bind( |
| 254 base::Bind(&PluginsHandler::PluginsLoaded, | 198 &PluginsHandler::NotifyWithPluginsData, weak_ptr_factory_.GetWeakPtr())); |
| 255 weak_ptr_factory_.GetWeakPtr())); | |
| 256 } | 199 } |
| 257 | 200 |
| 258 void PluginsHandler::PluginsLoaded( | 201 void PluginsHandler::RespondWithPluginsData( |
| 202 const GetPluginsDataCallback& callback, | |
| 259 const std::vector<WebPluginInfo>& plugins) { | 203 const std::vector<WebPluginInfo>& plugins) { |
| 260 Profile* profile = Profile::FromWebUI(web_ui()); | 204 callback.Run(GeneratePluginsData(plugins)); |
| 205 } | |
| 206 | |
| 207 void PluginsHandler::NotifyWithPluginsData( | |
| 208 const std::vector<WebPluginInfo>& plugins) { | |
| 209 page_->OnPluginsUpdated(GeneratePluginsData(plugins)); | |
|
sky
2016/01/28 16:45:27
As page_ is not immediately set you need an if (pa
dpapad
2016/01/28 18:32:54
Done.
| |
| 210 } | |
| 211 | |
| 212 mojo::Array<PluginDataPtr> PluginsHandler::GeneratePluginsData( | |
| 213 const std::vector<WebPluginInfo>& plugins) { | |
| 214 Profile* profile = Profile::FromWebUI(web_ui_); | |
| 261 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); | 215 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); |
| 262 | 216 |
| 263 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); | |
| 264 | |
| 265 PluginFinder* plugin_finder = PluginFinder::GetInstance(); | 217 PluginFinder* plugin_finder = PluginFinder::GetInstance(); |
| 266 // Group plugins by identifier. This is done to be able to display | 218 // Group plugins by identifier. This is done to be able to display |
| 267 // the plugins in UI in a grouped fashion. | 219 // the plugins in UI in a grouped fashion. |
| 268 PluginGroups groups; | 220 PluginGroups groups; |
| 269 for (size_t i = 0; i < plugins.size(); ++i) { | 221 for (size_t i = 0; i < plugins.size(); ++i) { |
| 270 scoped_ptr<PluginMetadata> plugin( | 222 scoped_ptr<PluginMetadata> plugin( |
| 271 plugin_finder->GetPluginMetadata(plugins[i])); | 223 plugin_finder->GetPluginMetadata(plugins[i])); |
| 272 groups[plugin->identifier()].push_back(&plugins[i]); | 224 groups[plugin->identifier()].push_back(&plugins[i]); |
| 273 } | 225 } |
| 274 | 226 |
| 275 // Construct DictionaryValues to return to UI. | 227 mojo::Array<PluginDataPtr> plugins_data(0u); |
| 276 base::ListValue* plugin_groups_data = new base::ListValue(); | 228 |
| 277 for (PluginGroups::const_iterator it = groups.begin(); | 229 for (PluginGroups::const_iterator it = groups.begin(); it != groups.end(); |
| 278 it != groups.end(); ++it) { | 230 ++it) { |
| 231 PluginDataPtr plugin_data(PluginData::New()); | |
| 279 const std::vector<const WebPluginInfo*>& group_plugins = it->second; | 232 const std::vector<const WebPluginInfo*>& group_plugins = it->second; |
| 280 base::ListValue* plugin_files = new base::ListValue(); | 233 |
| 281 scoped_ptr<PluginMetadata> plugin_metadata( | 234 scoped_ptr<PluginMetadata> plugin_metadata( |
| 282 plugin_finder->GetPluginMetadata(*group_plugins[0])); | 235 plugin_finder->GetPluginMetadata(*group_plugins[0])); |
| 283 base::string16 group_name = plugin_metadata->name(); | |
| 284 std::string group_identifier = plugin_metadata->identifier(); | 236 std::string group_identifier = plugin_metadata->identifier(); |
| 237 plugin_data->id = mojo::String::From(group_identifier); | |
| 238 | |
| 239 const WebPluginInfo* active_plugin = nullptr; | |
| 285 bool group_enabled = false; | 240 bool group_enabled = false; |
| 286 const WebPluginInfo* active_plugin = NULL; | |
| 287 for (size_t j = 0; j < group_plugins.size(); ++j) { | |
| 288 const WebPluginInfo& group_plugin = *group_plugins[j]; | |
| 289 | 241 |
| 290 base::DictionaryValue* plugin_file = new base::DictionaryValue(); | 242 mojo::Array<PluginFilePtr> plugin_files(0u); |
| 291 plugin_file->SetString("name", group_plugin.name); | 243 for (const auto& group_plugin : group_plugins) { |
| 292 plugin_file->SetString("description", GetPluginDescription(group_plugin)); | 244 bool plugin_enabled = plugin_prefs->IsPluginEnabled(*group_plugin); |
| 293 plugin_file->SetString("path", group_plugin.path.value()); | |
| 294 plugin_file->SetString("version", group_plugin.version); | |
| 295 plugin_file->SetString("type", PluginTypeToString(group_plugin.type)); | |
| 296 plugin_file->Set("mimeTypes", GetPluginMimeTypes(group_plugin)); | |
| 297 | 245 |
| 298 bool plugin_enabled = plugin_prefs->IsPluginEnabled(group_plugin); | 246 plugin_files.push_back(GeneratePluginFile( |
| 299 plugin_file->SetString( | 247 *group_plugin, plugin_metadata->name(), plugin_enabled)); |
| 300 "enabledMode", | |
| 301 GetPluginEnabledMode(group_plugin.name, group_name, plugin_enabled)); | |
| 302 plugin_files->Append(plugin_file); | |
| 303 | 248 |
| 249 // Update |active_plugin| and |group_enabled|. | |
| 304 if (!active_plugin || (plugin_enabled && !group_enabled)) | 250 if (!active_plugin || (plugin_enabled && !group_enabled)) |
| 305 active_plugin = &group_plugin; | 251 active_plugin = group_plugin; |
| 306 group_enabled = plugin_enabled || group_enabled; | 252 group_enabled = plugin_enabled || group_enabled; |
| 307 } | 253 } |
| 308 | 254 |
| 309 base::DictionaryValue* group_data = new base::DictionaryValue(); | 255 plugin_data->enabled_mode = mojo::String::From( |
| 310 group_data->Set("plugin_files", plugin_files); | 256 GetPluginGroupEnabledMode(plugin_files, group_enabled)); |
| 311 group_data->SetString("name", group_name); | |
| 312 group_data->SetString("id", group_identifier); | |
| 313 group_data->SetString("description", active_plugin->desc); | |
| 314 group_data->SetString("version", active_plugin->version); | |
| 315 | 257 |
| 316 #if defined(ENABLE_PLUGIN_INSTALLATION) | 258 plugin_data->always_allowed = false; |
| 317 bool out_of_date = plugin_metadata->GetSecurityStatus(*active_plugin) == | |
| 318 PluginMetadata::SECURITY_STATUS_OUT_OF_DATE; | |
| 319 group_data->SetBoolean("critical", out_of_date); | |
| 320 group_data->SetString("update_url", plugin_metadata->plugin_url().spec()); | |
| 321 #endif | |
| 322 | |
| 323 group_data->SetString( | |
| 324 "enabledMode", GetPluginGroupEnabledMode(*plugin_files, group_enabled)); | |
| 325 | |
| 326 bool always_allowed = false; | |
| 327 if (group_enabled) { | 259 if (group_enabled) { |
| 328 const base::DictionaryValue* whitelist = | 260 const base::DictionaryValue* whitelist = |
| 329 profile->GetPrefs()->GetDictionary( | 261 profile->GetPrefs()->GetDictionary( |
| 330 prefs::kContentSettingsPluginWhitelist); | 262 prefs::kContentSettingsPluginWhitelist); |
| 331 whitelist->GetBoolean(group_identifier, &always_allowed); | 263 whitelist->GetBoolean(group_identifier, &plugin_data->always_allowed); |
| 332 } | 264 } |
| 333 group_data->SetBoolean("alwaysAllowed", always_allowed); | |
| 334 | 265 |
| 335 plugin_groups_data->Append(group_data); | 266 plugin_data->critical = false; |
| 267 plugin_data->update_url = ""; | |
| 268 #if defined(ENABLE_PLUGIN_INSTALLATION) | |
| 269 bool out_of_date = plugin_metadata->GetSecurityStatus(*active_plugin) == | |
| 270 PluginMetadata::SECURITY_STATUS_OUT_OF_DATE; | |
| 271 plugin_data->critical = out_of_date; | |
| 272 plugin_data->update_url = plugin_metadata->plugin_url().spec(); | |
| 273 #endif | |
| 274 | |
| 275 plugin_data->description = mojo::String::From(active_plugin->desc); | |
| 276 plugin_data->name = plugin_files[0]->name; | |
| 277 plugin_data->plugin_files = std::move(plugin_files); | |
| 278 plugin_data->version = mojo::String::From(active_plugin->version); | |
| 279 plugins_data.push_back(std::move(plugin_data)); | |
| 336 } | 280 } |
| 337 base::DictionaryValue results; | 281 |
| 338 results.Set("plugins", plugin_groups_data); | 282 return plugins_data; |
| 339 web_ui()->CallJavascriptFunction("returnPluginsData", results); | 283 } |
| 284 | |
| 285 PluginFilePtr PluginsHandler::GeneratePluginFile( | |
| 286 const WebPluginInfo& plugin, | |
| 287 const base::string16& group_name, | |
| 288 bool plugin_enabled) const { | |
| 289 PluginFilePtr plugin_file(PluginFile::New()); | |
| 290 plugin_file->description = mojo::String::From(GetPluginDescription(plugin)); | |
| 291 plugin_file->enabled_mode = mojo::String::From( | |
| 292 GetPluginEnabledMode(plugin.name, group_name, plugin_enabled)); | |
| 293 plugin_file->name = mojo::String::From(plugin.name); | |
| 294 plugin_file->path = mojo::String::From(plugin.path.value()); | |
| 295 plugin_file->type = mojo::String::From(PluginTypeToString(plugin.type)); | |
| 296 plugin_file->version = mojo::String::From(plugin.version); | |
| 297 plugin_file->mime_types = GeneratePluginMimeTypes(plugin); | |
| 298 | |
| 299 return plugin_file; | |
| 340 } | 300 } |
| 341 | 301 |
| 342 std::string PluginsHandler::GetPluginEnabledMode( | 302 std::string PluginsHandler::GetPluginEnabledMode( |
| 343 const base::string16& plugin_name, | 303 const base::string16& plugin_name, |
| 344 const base::string16& group_name, | 304 const base::string16& group_name, |
| 345 bool plugin_enabled) const { | 305 bool plugin_enabled) const { |
| 346 Profile* profile = Profile::FromWebUI(web_ui()); | 306 Profile* profile = Profile::FromWebUI(web_ui_); |
| 347 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); | 307 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); |
| 348 PluginPrefs::PolicyStatus plugin_status = | 308 PluginPrefs::PolicyStatus plugin_status = |
| 349 plugin_prefs->PolicyStatusForPlugin(plugin_name); | 309 plugin_prefs->PolicyStatusForPlugin(plugin_name); |
| 350 PluginPrefs::PolicyStatus group_status = | 310 PluginPrefs::PolicyStatus group_status = |
| 351 plugin_prefs->PolicyStatusForPlugin(group_name); | 311 plugin_prefs->PolicyStatusForPlugin(group_name); |
| 352 | 312 |
| 353 if (plugin_status == PluginPrefs::POLICY_ENABLED || | 313 if (plugin_status == PluginPrefs::POLICY_ENABLED || |
| 354 group_status == PluginPrefs::POLICY_ENABLED) { | 314 group_status == PluginPrefs::POLICY_ENABLED) { |
| 355 return "enabledByPolicy"; | 315 return "enabledByPolicy"; |
| 356 } | 316 } |
| 357 if (plugin_status == PluginPrefs::POLICY_DISABLED || | 317 if (plugin_status == PluginPrefs::POLICY_DISABLED || |
| 358 group_status == PluginPrefs::POLICY_DISABLED) { | 318 group_status == PluginPrefs::POLICY_DISABLED) { |
| 359 return "disabledByPolicy"; | 319 return "disabledByPolicy"; |
| 360 } | 320 } |
| 361 return plugin_enabled ? "enabledByUser" : "disabledByUser"; | 321 return plugin_enabled ? "enabledByUser" : "disabledByUser"; |
| 362 } | 322 } |
| 363 | 323 |
| 364 std::string PluginsHandler::GetPluginGroupEnabledMode( | 324 std::string PluginsHandler::GetPluginGroupEnabledMode( |
| 365 const base::ListValue& plugin_files, bool group_enabled) const { | 325 const mojo::Array<PluginFilePtr>& plugin_files, |
| 326 bool group_enabled) const { | |
| 366 bool plugins_enabled_by_policy = true; | 327 bool plugins_enabled_by_policy = true; |
| 367 bool plugins_disabled_by_policy = true; | 328 bool plugins_disabled_by_policy = true; |
| 368 bool plugins_managed_by_policy = true; | 329 bool plugins_managed_by_policy = true; |
| 369 | 330 |
| 370 for (base::ListValue::const_iterator it = plugin_files.begin(); | 331 for (size_t i = 0; i < plugin_files.size(); i++) { |
| 371 it != plugin_files.end(); ++it) { | 332 std::string plugin_enabled_mode = plugin_files[i]->enabled_mode; |
| 372 base::DictionaryValue* plugin_dict; | |
| 373 CHECK((*it)->GetAsDictionary(&plugin_dict)); | |
| 374 std::string plugin_enabled_mode; | |
| 375 CHECK(plugin_dict->GetString("enabledMode", &plugin_enabled_mode)); | |
| 376 | 333 |
| 377 plugins_enabled_by_policy = plugins_enabled_by_policy && | 334 plugins_enabled_by_policy = |
| 378 plugin_enabled_mode == "enabledByPolicy"; | 335 plugins_enabled_by_policy && plugin_enabled_mode == "enabledByPolicy"; |
| 379 plugins_disabled_by_policy = plugins_disabled_by_policy && | 336 plugins_disabled_by_policy = |
| 380 plugin_enabled_mode == "disabledByPolicy"; | 337 plugins_disabled_by_policy && plugin_enabled_mode == "disabledByPolicy"; |
| 381 plugins_managed_by_policy = plugins_managed_by_policy && | 338 plugins_managed_by_policy = plugins_managed_by_policy && |
| 382 (plugin_enabled_mode == "enabledByPolicy" || | 339 (plugin_enabled_mode == "enabledByPolicy" || |
| 383 plugin_enabled_mode == "disabledByPolicy"); | 340 plugin_enabled_mode == "disabledByPolicy"); |
| 384 } | 341 } |
| 385 | 342 |
| 386 if (plugins_enabled_by_policy) | 343 if (plugins_enabled_by_policy) |
| 387 return "enabledByPolicy"; | 344 return "enabledByPolicy"; |
| 388 if (plugins_disabled_by_policy) | 345 if (plugins_disabled_by_policy) |
| 389 return "disabledByPolicy"; | 346 return "disabledByPolicy"; |
| 390 if (plugins_managed_by_policy) | 347 if (plugins_managed_by_policy) |
| 391 return "managedByPolicy"; | 348 return "managedByPolicy"; |
| 392 return group_enabled ? "enabledByUser" : "disabledByUser"; | 349 return group_enabled ? "enabledByUser" : "disabledByUser"; |
| 393 } | 350 } |
| OLD | NEW |