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 = base::hash_map<std::string, |
| 38 std::vector<const content::WebPluginInfo*>>; | 39 std::vector<const content::WebPluginInfo*>>; |
| 39 | 40 |
| 40 namespace { | 41 namespace { |
| 41 | 42 |
| (...skipping 39 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> GetPluginMimeTypes(const WebPluginInfo& plugin) { |
| 92 scoped_ptr<base::ListValue> mime_types(new base::ListValue()); | 93 mojo::Array<MimeTypePtr> mime_types; |
|
sky
2016/01/20 19:23:08
If plugin.mime_types is empty, then mime_types is
dpapad
2016/01/26 18:39:26
Done. I supplied "0u" as the size and kept using p
| |
| 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 // TODO(dpapad): vector<std::string> to mojo::Array<mojo::String> |
| 99 for (const auto& mime_file_extension : plugin_mime_type.file_extensions) { | 99 // conversion. Is there a better way? If not, should it be added to Mojo? |
| 100 file_extensions->Append(new base::StringValue(mime_file_extension)); | 100 mojo::Array<mojo::String> file_extensions; |
| 101 for (const auto& file_extension: plugin_mime_type.file_extensions) { | |
| 102 file_extensions.push_back(mojo::String::From(file_extension)); | |
| 101 } | 103 } |
| 102 mime_type->Set("fileExtensions", file_extensions); | 104 mime_type->mime_type = mojo::String::From(plugin_mime_type.mime_type); |
| 103 mime_types->Append(mime_type); | 105 mime_type->fileExtensions = std::move(file_extensions); |
|
sky
2016/01/20 19:23:08
You can nuke 100-103 and use:
mime_type->fileE
dpapad
2016/01/26 18:39:26
Done!
| |
| 106 mime_types.push_back(std::move(mime_type)); | |
| 104 } | 107 } |
| 108 | |
| 105 return mime_types; | 109 return mime_types; |
| 106 } | 110 } |
| 107 | 111 |
| 108 } // namespace | 112 } // namespace |
| 109 | 113 |
| 110 | 114 |
| 111 PluginsHandler::PluginsHandler() : weak_ptr_factory_(this) { | 115 PluginsHandler::PluginsHandler( |
| 112 } | 116 content::WebUI* web_ui, |
| 113 | 117 mojo::InterfaceRequest<PluginsHandlerMojo> request) |
| 114 PluginsHandler::~PluginsHandler() { | 118 : web_ui_(web_ui), binding_(this, std::move(request)), |
| 115 } | 119 weak_ptr_factory_(this) { |
| 116 | 120 Profile* profile = Profile::FromWebUI(web_ui_); |
| 117 void PluginsHandler::RegisterMessages() { | |
| 118 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 119 | |
| 120 PrefService* prefs = profile->GetPrefs(); | 121 PrefService* prefs = profile->GetPrefs(); |
| 121 show_details_.Init(prefs::kPluginsShowDetails, prefs); | 122 show_details_.Init(prefs::kPluginsShowDetails, prefs); |
| 122 | 123 |
| 123 registrar_.Add(this, | 124 registrar_.Add(this, |
| 124 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, | 125 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, |
| 125 content::Source<Profile>(profile)); | 126 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 } | 127 } |
| 143 | 128 |
| 144 void PluginsHandler::HandleRequestPluginsData(const base::ListValue* args) { | 129 PluginsHandler::~PluginsHandler() { |
| 145 LoadPlugins(); | |
| 146 } | 130 } |
| 147 | 131 |
| 148 void PluginsHandler::HandleEnablePluginMessage(const base::ListValue* args) { | 132 void PluginsHandler::SetPluginEnabled( |
| 149 Profile* profile = Profile::FromWebUI(web_ui()); | 133 const mojo::String& plugin_path, bool enable) { |
| 134 Profile* profile = Profile::FromWebUI(web_ui_); | |
| 135 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); | |
| 136 plugin_prefs->EnablePlugin( | |
| 137 enable, base::FilePath(plugin_path.To<base::StringPiece>()), | |
|
sky
2016/01/20 19:23:08
I think you want:
base::FilePath(plugin_path
dpapad
2016/01/26 18:39:26
Done.
| |
| 138 base::Bind(&AssertPluginEnabled)); | |
| 139 } | |
| 150 | 140 |
| 151 // Be robust in accepting badness since plugins display HTML (hence | 141 void PluginsHandler::SetPluginGroupEnabled( |
| 152 // JavaScript). | 142 const mojo::String& group_name, bool enable) { |
| 153 if (args->GetSize() != 3) { | 143 Profile* profile = Profile::FromWebUI(web_ui_); |
| 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(); | 144 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); |
| 167 if (is_group_str == "true") { | 145 base::string16 group_name_as_string16 = group_name.To<base::string16>(); |
| 168 base::string16 group_name; | 146 plugin_prefs->EnablePluginGroup(enable, group_name_as_string16); |
| 169 if (!args->GetString(0, &group_name)) { | 147 if (enable) { |
| 170 NOTREACHED(); | 148 // See http://crbug.com/50105 for background. |
| 171 return; | 149 base::string16 adobereader = base::ASCIIToUTF16( |
| 172 } | 150 PluginMetadata::kAdobeReaderGroupName); |
| 173 | 151 base::string16 internalpdf = |
| 174 plugin_prefs->EnablePluginGroup(enable, group_name); | 152 base::ASCIIToUTF16(ChromeContentClient::kPDFPluginName); |
| 175 if (enable) { | 153 if (group_name_as_string16 == adobereader) |
| 176 // See http://crbug.com/50105 for background. | 154 plugin_prefs->EnablePluginGroup(false, internalpdf); |
| 177 base::string16 adobereader = base::ASCIIToUTF16( | 155 else if (group_name_as_string16 == internalpdf) |
| 178 PluginMetadata::kAdobeReaderGroupName); | 156 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 } | 157 } |
| 196 } | 158 } |
| 197 | 159 |
| 198 void PluginsHandler::HandleSaveShowDetailsToPrefs( | 160 void PluginsHandler::GetShowDetails(const GetShowDetailsCallback& callback) { |
| 199 const base::ListValue* args) { | 161 // TODO(dpapad): Figure out why it comes back as a 0/1 number. |
| 200 std::string details_mode; | 162 callback.Run(show_details_.GetValue()); |
| 201 if (!args->GetString(0, &details_mode)) { | |
| 202 NOTREACHED(); | |
| 203 return; | |
| 204 } | |
| 205 show_details_.SetValue(details_mode == "true"); | |
| 206 } | 163 } |
| 207 | 164 |
| 208 void PluginsHandler::HandleGetShowDetails(const base::ListValue* args) { | 165 void PluginsHandler::SaveShowDetailsToPrefs(bool details_mode) { |
| 209 base::FundamentalValue show_details(show_details_.GetValue()); | 166 show_details_.SetValue(details_mode); |
| 210 web_ui()->CallJavascriptFunction("loadShowDetailsFromPrefs", show_details); | |
| 211 } | 167 } |
| 212 | 168 |
| 213 void PluginsHandler::HandleSetPluginAlwaysAllowed( | 169 void PluginsHandler::SetPluginAlwaysAllowed( |
| 214 const base::ListValue* args) { | 170 const mojo::String& plugin, bool allowed) { |
| 215 // Be robust in the input parameters, but crash in a Debug build. | 171 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( | 172 HostContentSettingsMapFactory::GetForProfile(profile)->SetContentSetting( |
| 229 ContentSettingsPattern::Wildcard(), | 173 ContentSettingsPattern::Wildcard(), |
| 230 ContentSettingsPattern::Wildcard(), | 174 ContentSettingsPattern::Wildcard(), |
| 231 CONTENT_SETTINGS_TYPE_PLUGINS, | 175 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 232 plugin, | 176 plugin.get(), |
| 233 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_DEFAULT); | 177 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_DEFAULT); |
| 234 | 178 |
| 235 // Keep track of the whitelist separately, so that we can distinguish plugins | 179 // Keep track of the whitelist separately, so that we can distinguish plugins |
| 236 // whitelisted by the user from automatically whitelisted ones. | 180 // whitelisted by the user from automatically whitelisted ones. |
| 237 DictionaryPrefUpdate update(profile->GetPrefs(), | 181 DictionaryPrefUpdate update(profile->GetPrefs(), |
| 238 prefs::kContentSettingsPluginWhitelist); | 182 prefs::kContentSettingsPluginWhitelist); |
| 239 update->SetBoolean(plugin, allowed); | 183 update->SetBoolean(plugin, allowed); |
| 240 } | 184 } |
| 241 | 185 |
| 186 void PluginsHandler::GetPluginsData(const GetPluginsDataCallback& callback) { | |
| 187 if (weak_ptr_factory_.HasWeakPtrs()) | |
| 188 return; | |
| 189 | |
| 190 content::PluginService::GetInstance()->GetPlugins( | |
| 191 base::Bind(&PluginsHandler::PluginsLoaded, | |
| 192 weak_ptr_factory_.GetWeakPtr(), | |
| 193 callback)); | |
| 194 } | |
| 195 | |
| 242 void PluginsHandler::Observe(int type, | 196 void PluginsHandler::Observe(int type, |
| 243 const content::NotificationSource& source, | 197 const content::NotificationSource& source, |
| 244 const content::NotificationDetails& details) { | 198 const content::NotificationDetails& details) { |
| 245 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); | 199 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); |
| 246 LoadPlugins(); | 200 LOG(ERROR) << "Observer fired"; |
| 201 // TODO(dpapad): Figure out how to reshare the code, when it is invoked as a | |
| 202 // result of this observer method being called. | |
| 203 //LoadPlugins(); | |
| 247 } | 204 } |
| 248 | 205 |
| 249 void PluginsHandler::LoadPlugins() { | 206 void PluginsHandler::LoadPlugins() { |
| 250 if (weak_ptr_factory_.HasWeakPtrs()) | 207 /*if (weak_ptr_factory_.HasWeakPtrs()) |
| 251 return; | 208 return; |
| 252 | 209 |
| 253 content::PluginService::GetInstance()->GetPlugins( | 210 content::PluginService::GetInstance()->GetPlugins( |
| 254 base::Bind(&PluginsHandler::PluginsLoaded, | 211 base::Bind(&PluginsHandler::PluginsLoaded, |
| 255 weak_ptr_factory_.GetWeakPtr())); | 212 weak_ptr_factory_.GetWeakPtr()));*/ |
| 256 } | 213 } |
| 257 | 214 |
| 258 void PluginsHandler::PluginsLoaded( | 215 void PluginsHandler::PluginsLoaded( |
| 216 const GetPluginsDataCallback& callback, | |
| 259 const std::vector<WebPluginInfo>& plugins) { | 217 const std::vector<WebPluginInfo>& plugins) { |
| 260 Profile* profile = Profile::FromWebUI(web_ui()); | 218 Profile* profile = Profile::FromWebUI(web_ui_); |
| 261 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); | 219 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); |
| 262 | 220 //ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); |
| 263 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); | |
| 264 | 221 |
| 265 PluginFinder* plugin_finder = PluginFinder::GetInstance(); | 222 PluginFinder* plugin_finder = PluginFinder::GetInstance(); |
| 266 // Group plugins by identifier. This is done to be able to display | 223 // Group plugins by identifier. This is done to be able to display |
| 267 // the plugins in UI in a grouped fashion. | 224 // the plugins in UI in a grouped fashion. |
| 268 PluginGroups groups; | 225 PluginGroups groups; |
| 269 for (size_t i = 0; i < plugins.size(); ++i) { | 226 for (size_t i = 0; i < plugins.size(); ++i) { |
| 270 scoped_ptr<PluginMetadata> plugin( | 227 scoped_ptr<PluginMetadata> plugin( |
| 271 plugin_finder->GetPluginMetadata(plugins[i])); | 228 plugin_finder->GetPluginMetadata(plugins[i])); |
| 272 groups[plugin->identifier()].push_back(&plugins[i]); | 229 groups[plugin->identifier()].push_back(&plugins[i]); |
| 273 } | 230 } |
| 274 | 231 |
| 275 // Construct DictionaryValues to return to UI. | 232 mojo::Array<PluginDataPtr> plugins_data; |
|
sky
2016/01/20 19:23:08
This is another place where you end up with a null
dpapad
2016/01/26 18:39:26
Fixed.
| |
| 276 base::ListValue* plugin_groups_data = new base::ListValue(); | 233 |
| 277 for (PluginGroups::const_iterator it = groups.begin(); | 234 for (PluginGroups::const_iterator it = groups.begin(); |
| 278 it != groups.end(); ++it) { | 235 it != groups.end(); ++it) { |
| 236 PluginDataPtr plugin_data(PluginData::New()); | |
| 279 const std::vector<const WebPluginInfo*>& group_plugins = it->second; | 237 const std::vector<const WebPluginInfo*>& group_plugins = it->second; |
| 280 base::ListValue* plugin_files = new base::ListValue(); | 238 |
| 281 scoped_ptr<PluginMetadata> plugin_metadata( | 239 scoped_ptr<PluginMetadata> plugin_metadata( |
| 282 plugin_finder->GetPluginMetadata(*group_plugins[0])); | 240 plugin_finder->GetPluginMetadata(*group_plugins[0])); |
| 283 base::string16 group_name = plugin_metadata->name(); | |
| 284 std::string group_identifier = plugin_metadata->identifier(); | 241 std::string group_identifier = plugin_metadata->identifier(); |
| 242 plugin_data->id = mojo::String::From(group_identifier); | |
| 243 | |
| 244 const WebPluginInfo* active_plugin = nullptr; | |
| 285 bool group_enabled = false; | 245 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 | 246 |
| 290 base::DictionaryValue* plugin_file = new base::DictionaryValue(); | 247 mojo::Array<PluginFilePtr> plugin_files; |
|
sky
2016/01/20 19:23:08
And this one too.
dpapad
2016/01/26 18:39:26
Fixed too.
| |
| 291 plugin_file->SetString("name", group_plugin.name); | 248 for (const auto& group_plugin: group_plugins) { |
| 292 plugin_file->SetString("description", GetPluginDescription(group_plugin)); | 249 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 | 250 |
| 298 bool plugin_enabled = plugin_prefs->IsPluginEnabled(group_plugin); | 251 plugin_files.push_back(GetPluginFile( |
| 299 plugin_file->SetString( | 252 *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 | 253 |
| 254 // Update |active_plugin| and |group_enabled|. | |
| 304 if (!active_plugin || (plugin_enabled && !group_enabled)) | 255 if (!active_plugin || (plugin_enabled && !group_enabled)) |
| 305 active_plugin = &group_plugin; | 256 active_plugin = group_plugin; |
| 306 group_enabled = plugin_enabled || group_enabled; | 257 group_enabled = plugin_enabled || group_enabled; |
| 307 } | 258 } |
| 308 | 259 |
| 309 base::DictionaryValue* group_data = new base::DictionaryValue(); | 260 plugin_data->enabled_mode = mojo::String::From( |
| 310 group_data->Set("plugin_files", plugin_files); | 261 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 | 262 |
| 316 #if defined(ENABLE_PLUGIN_INSTALLATION) | 263 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) { | 264 if (group_enabled) { |
| 328 const base::DictionaryValue* whitelist = | 265 const base::DictionaryValue* whitelist = |
| 329 profile->GetPrefs()->GetDictionary( | 266 profile->GetPrefs()->GetDictionary( |
| 330 prefs::kContentSettingsPluginWhitelist); | 267 prefs::kContentSettingsPluginWhitelist); |
| 331 whitelist->GetBoolean(group_identifier, &always_allowed); | 268 whitelist->GetBoolean(group_identifier, &plugin_data->always_allowed); |
| 332 } | 269 } |
| 333 group_data->SetBoolean("alwaysAllowed", always_allowed); | |
| 334 | 270 |
| 335 plugin_groups_data->Append(group_data); | 271 plugin_data->description = mojo::String::From(active_plugin->desc); |
| 272 plugin_data->name = plugin_files[0]->name; | |
| 273 plugin_data->plugin_files = std::move(plugin_files); | |
| 274 plugin_data->version = mojo::String::From(active_plugin->version); | |
| 275 plugins_data.push_back(std::move(plugin_data)); | |
| 336 } | 276 } |
| 337 base::DictionaryValue results; | 277 |
| 338 results.Set("plugins", plugin_groups_data); | 278 callback.Run(std::move(plugins_data)); |
| 339 web_ui()->CallJavascriptFunction("returnPluginsData", results); | 279 //callback.Run(mojo::Array<PluginDataPtr>(0)); |
| 280 } | |
| 281 | |
| 282 PluginFilePtr PluginsHandler::GetPluginFile( | |
| 283 const WebPluginInfo& plugin, | |
| 284 const base::string16& group_name, | |
| 285 bool plugin_enabled) const { | |
| 286 PluginFilePtr plugin_file(PluginFile::New()); | |
| 287 plugin_file->description = mojo::String::From( | |
| 288 GetPluginDescription(plugin)); | |
| 289 plugin_file->enabled_mode = mojo::String::From( | |
| 290 GetPluginEnabledMode(plugin.name, group_name, plugin_enabled)); | |
| 291 plugin_file->name = mojo::String::From(plugin.name); | |
| 292 plugin_file->path = mojo::String::From(plugin.path.value()); | |
| 293 plugin_file->type = mojo::String::From( | |
| 294 PluginTypeToString(plugin.type)); | |
| 295 plugin_file->version = mojo::String::From(plugin.version); | |
| 296 plugin_file->mime_types = GetPluginMimeTypes(plugin); | |
| 297 | |
| 298 return plugin_file; | |
| 340 } | 299 } |
| 341 | 300 |
| 342 std::string PluginsHandler::GetPluginEnabledMode( | 301 std::string PluginsHandler::GetPluginEnabledMode( |
| 343 const base::string16& plugin_name, | 302 const base::string16& plugin_name, |
| 344 const base::string16& group_name, | 303 const base::string16& group_name, |
| 345 bool plugin_enabled) const { | 304 bool plugin_enabled) const { |
| 346 Profile* profile = Profile::FromWebUI(web_ui()); | 305 Profile* profile = Profile::FromWebUI(web_ui_); |
| 347 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); | 306 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); |
| 348 PluginPrefs::PolicyStatus plugin_status = | 307 PluginPrefs::PolicyStatus plugin_status = |
| 349 plugin_prefs->PolicyStatusForPlugin(plugin_name); | 308 plugin_prefs->PolicyStatusForPlugin(plugin_name); |
| 350 PluginPrefs::PolicyStatus group_status = | 309 PluginPrefs::PolicyStatus group_status = |
| 351 plugin_prefs->PolicyStatusForPlugin(group_name); | 310 plugin_prefs->PolicyStatusForPlugin(group_name); |
| 352 | 311 |
| 353 if (plugin_status == PluginPrefs::POLICY_ENABLED || | 312 if (plugin_status == PluginPrefs::POLICY_ENABLED || |
| 354 group_status == PluginPrefs::POLICY_ENABLED) { | 313 group_status == PluginPrefs::POLICY_ENABLED) { |
| 355 return "enabledByPolicy"; | 314 return "enabledByPolicy"; |
| 356 } | 315 } |
| 357 if (plugin_status == PluginPrefs::POLICY_DISABLED || | 316 if (plugin_status == PluginPrefs::POLICY_DISABLED || |
| 358 group_status == PluginPrefs::POLICY_DISABLED) { | 317 group_status == PluginPrefs::POLICY_DISABLED) { |
| 359 return "disabledByPolicy"; | 318 return "disabledByPolicy"; |
| 360 } | 319 } |
| 361 return plugin_enabled ? "enabledByUser" : "disabledByUser"; | 320 return plugin_enabled ? "enabledByUser" : "disabledByUser"; |
| 362 } | 321 } |
| 363 | 322 |
| 364 std::string PluginsHandler::GetPluginGroupEnabledMode( | 323 std::string PluginsHandler::GetPluginGroupEnabledMode( |
| 365 const base::ListValue& plugin_files, bool group_enabled) const { | 324 const mojo::Array<PluginFilePtr>& plugin_files, |
| 325 bool group_enabled) const { | |
| 366 bool plugins_enabled_by_policy = true; | 326 bool plugins_enabled_by_policy = true; |
| 367 bool plugins_disabled_by_policy = true; | 327 bool plugins_disabled_by_policy = true; |
| 368 bool plugins_managed_by_policy = true; | 328 bool plugins_managed_by_policy = true; |
| 369 | 329 |
| 370 for (base::ListValue::const_iterator it = plugin_files.begin(); | 330 for (size_t i = 0; i < plugin_files.size(); i++) { |
| 371 it != plugin_files.end(); ++it) { | 331 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 | 332 |
| 377 plugins_enabled_by_policy = plugins_enabled_by_policy && | 333 plugins_enabled_by_policy = plugins_enabled_by_policy && |
| 378 plugin_enabled_mode == "enabledByPolicy"; | 334 plugin_enabled_mode == "enabledByPolicy"; |
| 379 plugins_disabled_by_policy = plugins_disabled_by_policy && | 335 plugins_disabled_by_policy = plugins_disabled_by_policy && |
| 380 plugin_enabled_mode == "disabledByPolicy"; | 336 plugin_enabled_mode == "disabledByPolicy"; |
| 381 plugins_managed_by_policy = plugins_managed_by_policy && | 337 plugins_managed_by_policy = plugins_managed_by_policy && |
| 382 (plugin_enabled_mode == "enabledByPolicy" || | 338 (plugin_enabled_mode == "enabledByPolicy" || |
| 383 plugin_enabled_mode == "disabledByPolicy"); | 339 plugin_enabled_mode == "disabledByPolicy"); |
| 384 } | 340 } |
| 385 | 341 |
| 386 if (plugins_enabled_by_policy) | 342 if (plugins_enabled_by_policy) |
| 387 return "enabledByPolicy"; | 343 return "enabledByPolicy"; |
| 388 if (plugins_disabled_by_policy) | 344 if (plugins_disabled_by_policy) |
| 389 return "disabledByPolicy"; | 345 return "disabledByPolicy"; |
| 390 if (plugins_managed_by_policy) | 346 if (plugins_managed_by_policy) |
| 391 return "managedByPolicy"; | 347 return "managedByPolicy"; |
| 392 return group_enabled ? "enabledByUser" : "disabledByUser"; | 348 return group_enabled ? "enabledByUser" : "disabledByUser"; |
| 393 } | 349 } |
| OLD | NEW |