Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: chrome/browser/ui/webui/plugins_ui.cc

Issue 10872034: Changing PluginPrefs to use PluginFinder's async interface. (Closed) Base URL: http://git.chromium.org/chromium/src.git@test_async
Patch Set: Fixed bauerb's More Nits Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/webui/plugins_ui.h" 5 #include "chrome/browser/ui/webui/plugins_ui.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 #endif 59 #endif
60 60
61 using content::PluginService; 61 using content::PluginService;
62 using content::WebContents; 62 using content::WebContents;
63 using content::WebUIMessageHandler; 63 using content::WebUIMessageHandler;
64 using webkit::npapi::PluginGroup; 64 using webkit::npapi::PluginGroup;
65 using webkit::WebPluginInfo; 65 using webkit::WebPluginInfo;
66 66
67 namespace { 67 namespace {
68 68
69 // Helper callback method to process result of CanEnablePlugin method.
70 void CheckCanEnablePluginCallback(bool can_enable) {
71 DCHECK(can_enable);
72 }
73
69 ChromeWebUIDataSource* CreatePluginsUIHTMLSource() { 74 ChromeWebUIDataSource* CreatePluginsUIHTMLSource() {
70 ChromeWebUIDataSource* source = 75 ChromeWebUIDataSource* source =
71 new ChromeWebUIDataSource(chrome::kChromeUIPluginsHost); 76 new ChromeWebUIDataSource(chrome::kChromeUIPluginsHost);
72 source->set_use_json_js_format_v2(); 77 source->set_use_json_js_format_v2();
73 78
74 source->AddLocalizedString("pluginsTitle", IDS_PLUGINS_TITLE); 79 source->AddLocalizedString("pluginsTitle", IDS_PLUGINS_TITLE);
75 source->AddLocalizedString("pluginsDetailsModeLink", 80 source->AddLocalizedString("pluginsDetailsModeLink",
76 IDS_PLUGINS_DETAILS_MODE_LINK); 81 IDS_PLUGINS_DETAILS_MODE_LINK);
77 source->AddLocalizedString("pluginsNoneInstalled", 82 source->AddLocalizedString("pluginsNoneInstalled",
78 IDS_PLUGINS_NONE_INSTALLED); 83 IDS_PLUGINS_NONE_INSTALLED);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 172
168 private: 173 private:
169 // Call this to start getting the plugins on the UI thread. 174 // Call this to start getting the plugins on the UI thread.
170 void GetPluginFinder(); 175 void GetPluginFinder();
171 176
172 // Called when we have a PluginFinder and need to load the list of plug-ins. 177 // Called when we have a PluginFinder and need to load the list of plug-ins.
173 void LoadPlugins(PluginFinder* plugin_finder); 178 void LoadPlugins(PluginFinder* plugin_finder);
174 179
175 // Called on the UI thread when the plugin information is ready. 180 // Called on the UI thread when the plugin information is ready.
176 void PluginsLoaded(PluginFinder* plugin_finder, 181 void PluginsLoaded(PluginFinder* plugin_finder,
177 const std::vector<PluginGroup>& groups); 182 const std::vector<webkit::WebPluginInfo>& plugins);
178 183
179 content::NotificationRegistrar registrar_; 184 content::NotificationRegistrar registrar_;
180 185
181 base::WeakPtrFactory<PluginsDOMHandler> weak_ptr_factory_; 186 base::WeakPtrFactory<PluginsDOMHandler> weak_ptr_factory_;
182 187
188 typedef base::hash_map<std::string, std::vector<const WebPluginInfo*> >
189 PluginGroups;
Bernhard Bauer 2012/09/03 08:57:12 Nit: Indent by four spaces.
ibraaaa 2012/09/03 09:10:28 Done.
190
183 // This pref guards the value whether about:plugins is in the details mode or 191 // This pref guards the value whether about:plugins is in the details mode or
184 // not. 192 // not.
185 BooleanPrefMember show_details_; 193 BooleanPrefMember show_details_;
186 194
187 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler); 195 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler);
188 }; 196 };
189 197
190 PluginsDOMHandler::PluginsDOMHandler() 198 PluginsDOMHandler::PluginsDOMHandler()
191 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 199 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
192 } 200 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 } 241 }
234 242
235 std::string enable_str; 243 std::string enable_str;
236 std::string is_group_str; 244 std::string is_group_str;
237 if (!args->GetString(1, &enable_str) || !args->GetString(2, &is_group_str)) { 245 if (!args->GetString(1, &enable_str) || !args->GetString(2, &is_group_str)) {
238 NOTREACHED(); 246 NOTREACHED();
239 return; 247 return;
240 } 248 }
241 bool enable = enable_str == "true"; 249 bool enable = enable_str == "true";
242 250
243 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); 251 scoped_refptr<PluginPrefs> plugin_prefs(PluginPrefs::GetForProfile(profile));
ibraaaa 2012/09/03 09:10:28 there is no need to use scoped_refptr now, will re
244 if (is_group_str == "true") { 252 if (is_group_str == "true") {
245 string16 group_name; 253 string16 group_name;
246 if (!args->GetString(0, &group_name)) { 254 if (!args->GetString(0, &group_name)) {
247 NOTREACHED(); 255 NOTREACHED();
248 return; 256 return;
249 } 257 }
250 258
251 plugin_prefs->EnablePluginGroup(enable, group_name); 259 plugin_prefs->EnablePluginGroup(enable, group_name);
252 if (enable) { 260 if (enable) {
253 // See http://crbug.com/50105 for background. 261 // See http://crbug.com/50105 for background.
254 string16 adobereader = ASCIIToUTF16( 262 string16 adobereader = ASCIIToUTF16(
255 PluginGroup::kAdobeReaderGroupName); 263 PluginGroup::kAdobeReaderGroupName);
256 string16 internalpdf = 264 string16 internalpdf =
257 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName); 265 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName);
258 if (group_name == adobereader) 266 if (group_name == adobereader)
259 plugin_prefs->EnablePluginGroup(false, internalpdf); 267 plugin_prefs->EnablePluginGroup(false, internalpdf);
260 else if (group_name == internalpdf) 268 else if (group_name == internalpdf)
261 plugin_prefs->EnablePluginGroup(false, adobereader); 269 plugin_prefs->EnablePluginGroup(false, adobereader);
262 } 270 }
263 } else { 271 } else {
264 FilePath::StringType file_path; 272 FilePath::StringType file_path;
265 if (!args->GetString(0, &file_path)) { 273 if (!args->GetString(0, &file_path)) {
266 NOTREACHED(); 274 NOTREACHED();
267 return; 275 return;
268 } 276 }
269 DCHECK(plugin_prefs->CanEnablePlugin(enable, FilePath(file_path))); 277
270 plugin_prefs->EnablePlugin(enable, FilePath(file_path), 278 plugin_prefs->EnablePlugin(enable, FilePath(file_path),
271 base::Bind(&base::DoNothing)); 279 base::Bind(&CheckCanEnablePluginCallback));
272 } 280 }
273 } 281 }
274 282
275 void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) { 283 void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) {
276 std::string details_mode; 284 std::string details_mode;
277 if (!args->GetString(0, &details_mode)) { 285 if (!args->GetString(0, &details_mode)) {
278 NOTREACHED(); 286 NOTREACHED();
279 return; 287 return;
280 } 288 }
281 show_details_.SetValue(details_mode == "true"); 289 show_details_.SetValue(details_mode == "true");
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 335
328 #if defined(ENABLE_PLUGIN_INSTALLATION) 336 #if defined(ENABLE_PLUGIN_INSTALLATION)
329 PluginFinder::Get(base::Bind(&PluginsDOMHandler::LoadPlugins, 337 PluginFinder::Get(base::Bind(&PluginsDOMHandler::LoadPlugins,
330 weak_ptr_factory_.GetWeakPtr())); 338 weak_ptr_factory_.GetWeakPtr()));
331 #else 339 #else
332 LoadPlugins(NULL); 340 LoadPlugins(NULL);
333 #endif 341 #endif
334 } 342 }
335 343
336 void PluginsDOMHandler::LoadPlugins(PluginFinder* plugin_finder) { 344 void PluginsDOMHandler::LoadPlugins(PluginFinder* plugin_finder) {
337 PluginService::GetInstance()->GetPluginGroups( 345 PluginService::GetInstance()->GetPlugins(
338 base::Bind(&PluginsDOMHandler::PluginsLoaded, 346 base::Bind(&PluginsDOMHandler::PluginsLoaded,
339 weak_ptr_factory_.GetWeakPtr(), plugin_finder)); 347 weak_ptr_factory_.GetWeakPtr(), plugin_finder));
340 } 348 }
341 349
342 void PluginsDOMHandler::PluginsLoaded(PluginFinder* plugin_finder, 350 void PluginsDOMHandler::PluginsLoaded(
343 const std::vector<PluginGroup>& groups) { 351 PluginFinder* plugin_finder,
352 const std::vector<webkit::WebPluginInfo>& plugins) {
344 Profile* profile = Profile::FromWebUI(web_ui()); 353 Profile* profile = Profile::FromWebUI(web_ui());
345 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); 354 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile);
346 355
347 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); 356 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard();
348 357
349 // Construct DictionaryValues to return to the UI 358 // Group plug-ins by identifier. This is done to be able to display
359 // the plug-ins in UI in a grouped fashion.
360 PluginGroups groups;
361 for (size_t i = 0; i < plugins.size(); ++i) {
362 PluginInstaller* installer = plugin_finder->GetPluginInstaller(plugins[i]);
363 groups[installer->identifier()].push_back(&plugins[i]);
364 }
365
366 // Construct DictionaryValues to return to UI.
350 ListValue* plugin_groups_data = new ListValue(); 367 ListValue* plugin_groups_data = new ListValue();
351 for (size_t i = 0; i < groups.size(); ++i) { 368 for (PluginGroups::const_iterator it = groups.begin();
352 const PluginGroup& group = groups[i]; 369 it != groups.end(); ++it) {
353 if (group.IsEmpty()) 370 const std::vector<const WebPluginInfo*>& group_plugins = it->second;
354 continue;
355 ListValue* plugin_files = new ListValue(); 371 ListValue* plugin_files = new ListValue();
356 string16 group_name = group.GetGroupName(); 372 PluginInstaller* plugin_installer =
373 plugin_finder->GetPluginInstaller(*group_plugins[0]);
374 string16 group_name = plugin_installer->name();
375 std::string group_identifier = plugin_installer->identifier();
357 bool group_enabled = false; 376 bool group_enabled = false;
358 bool all_plugins_enabled_by_policy = true; 377 bool all_plugins_enabled_by_policy = true;
359 bool all_plugins_disabled_by_policy = true; 378 bool all_plugins_disabled_by_policy = true;
360 const WebPluginInfo* active_plugin = NULL; 379 const WebPluginInfo* active_plugin = NULL;
361 for (size_t j = 0; j < group.web_plugin_infos().size(); ++j) { 380 for (size_t j = 0; j < group_plugins.size(); ++j) {
362 const WebPluginInfo& group_plugin = group.web_plugin_infos()[j]; 381 const WebPluginInfo& group_plugin = *group_plugins[j];
363 382
364 DictionaryValue* plugin_file = new DictionaryValue(); 383 DictionaryValue* plugin_file = new DictionaryValue();
365 plugin_file->SetString("name", group_plugin.name); 384 plugin_file->SetString("name", group_plugin.name);
366 plugin_file->SetString("description", group_plugin.desc); 385 plugin_file->SetString("description", group_plugin.desc);
367 plugin_file->SetString("path", group_plugin.path.value()); 386 plugin_file->SetString("path", group_plugin.path.value());
368 plugin_file->SetString("version", group_plugin.version); 387 plugin_file->SetString("version", group_plugin.version);
369 plugin_file->SetString("type", PluginTypeToString(group_plugin.type)); 388 plugin_file->SetString("type", PluginTypeToString(group_plugin.type));
370 389
371 ListValue* mime_types = new ListValue(); 390 ListValue* mime_types = new ListValue();
372 const std::vector<webkit::WebPluginMimeType>& plugin_mime_types = 391 const std::vector<webkit::WebPluginMimeType>& plugin_mime_types =
(...skipping 24 matching lines...) Expand all
397 PluginPrefs::PolicyStatus plugin_status = 416 PluginPrefs::PolicyStatus plugin_status =
398 plugin_prefs->PolicyStatusForPlugin(group_plugin.name); 417 plugin_prefs->PolicyStatusForPlugin(group_plugin.name);
399 PluginPrefs::PolicyStatus group_status = 418 PluginPrefs::PolicyStatus group_status =
400 plugin_prefs->PolicyStatusForPlugin(group_name); 419 plugin_prefs->PolicyStatusForPlugin(group_name);
401 if (plugin_status == PluginPrefs::POLICY_ENABLED || 420 if (plugin_status == PluginPrefs::POLICY_ENABLED ||
402 group_status == PluginPrefs::POLICY_ENABLED) { 421 group_status == PluginPrefs::POLICY_ENABLED) {
403 enabled_mode = "enabledByPolicy"; 422 enabled_mode = "enabledByPolicy";
404 } else { 423 } else {
405 all_plugins_enabled_by_policy = false; 424 all_plugins_enabled_by_policy = false;
406 if (plugin_status == PluginPrefs::POLICY_DISABLED || 425 if (plugin_status == PluginPrefs::POLICY_DISABLED ||
407 group_status == PluginPrefs::POLICY_DISABLED) { 426 group_status == PluginPrefs::POLICY_DISABLED) {
408 enabled_mode = "disabledByPolicy"; 427 enabled_mode = "disabledByPolicy";
409 } else { 428 } else {
410 all_plugins_disabled_by_policy = false; 429 all_plugins_disabled_by_policy = false;
411 if (plugin_enabled) { 430 if (plugin_enabled) {
412 enabled_mode = "enabledByUser"; 431 enabled_mode = "enabledByUser";
413 } else { 432 } else {
414 enabled_mode = "disabledByUser"; 433 enabled_mode = "disabledByUser";
415 } 434 }
416 } 435 }
417 } 436 }
418 plugin_file->SetString("enabledMode", enabled_mode); 437 plugin_file->SetString("enabledMode", enabled_mode);
419 438
420 plugin_files->Append(plugin_file); 439 plugin_files->Append(plugin_file);
421 } 440 }
422 DictionaryValue* group_data = new DictionaryValue(); 441 DictionaryValue* group_data = new DictionaryValue();
423 442
424 group_data->Set("plugin_files", plugin_files); 443 group_data->Set("plugin_files", plugin_files);
425 group_data->SetString("name", group_name); 444 group_data->SetString("name", group_name);
426 group_data->SetString("id", group.identifier()); 445 group_data->SetString("id", group_identifier);
427 group_data->SetString("description", active_plugin->desc); 446 group_data->SetString("description", active_plugin->desc);
428 group_data->SetString("version", active_plugin->version); 447 group_data->SetString("version", active_plugin->version);
429 448
430 #if defined(ENABLE_PLUGIN_INSTALLATION) 449 #if defined(ENABLE_PLUGIN_INSTALLATION)
431 PluginInstaller* installer = 450 PluginInstaller* installer =
432 plugin_finder->FindPluginWithIdentifier(group.identifier()); 451 plugin_finder->FindPluginWithIdentifier(group_identifier);
433 if (installer) { 452 if (installer) {
434 bool out_of_date = installer->GetSecurityStatus(*active_plugin) == 453 bool out_of_date = installer->GetSecurityStatus(*active_plugin) ==
435 PluginInstaller::SECURITY_STATUS_OUT_OF_DATE; 454 PluginInstaller::SECURITY_STATUS_OUT_OF_DATE;
436 group_data->SetBoolean("critical", out_of_date); 455 group_data->SetBoolean("critical", out_of_date);
437 group_data->SetString("update_url", installer->plugin_url().spec()); 456 group_data->SetString("update_url", installer->plugin_url().spec());
438 } 457 }
439 #endif 458 #endif
440 459
441 std::string enabled_mode; 460 std::string enabled_mode;
442 if (all_plugins_enabled_by_policy) { 461 if (all_plugins_enabled_by_policy) {
443 enabled_mode = "enabledByPolicy"; 462 enabled_mode = "enabledByPolicy";
444 } else if (all_plugins_disabled_by_policy) { 463 } else if (all_plugins_disabled_by_policy) {
445 enabled_mode = "disabledByPolicy"; 464 enabled_mode = "disabledByPolicy";
446 } else if (group_enabled) { 465 } else if (group_enabled) {
447 enabled_mode = "enabledByUser"; 466 enabled_mode = "enabledByUser";
448 } else { 467 } else {
449 enabled_mode = "disabledByUser"; 468 enabled_mode = "disabledByUser";
450 } 469 }
451 group_data->SetString("enabledMode", enabled_mode); 470 group_data->SetString("enabledMode", enabled_mode);
452 471
453 bool always_allowed = false; 472 bool always_allowed = false;
454 if (group_enabled) { 473 if (group_enabled) {
455 const DictionaryValue* whitelist = profile->GetPrefs()->GetDictionary( 474 const DictionaryValue* whitelist = profile->GetPrefs()->GetDictionary(
456 prefs::kContentSettingsPluginWhitelist); 475 prefs::kContentSettingsPluginWhitelist);
457 whitelist->GetBoolean(group.identifier(), &always_allowed); 476 whitelist->GetBoolean(group_identifier, &always_allowed);
458 } 477 }
459 group_data->SetBoolean("alwaysAllowed", always_allowed); 478 group_data->SetBoolean("alwaysAllowed", always_allowed);
460 479
461 plugin_groups_data->Append(group_data); 480 plugin_groups_data->Append(group_data);
462 } 481 }
482
463 DictionaryValue results; 483 DictionaryValue results;
464 results.Set("plugins", plugin_groups_data); 484 results.Set("plugins", plugin_groups_data);
465 web_ui()->CallJavascriptFunction("returnPluginsData", results); 485 web_ui()->CallJavascriptFunction("returnPluginsData", results);
466 } 486 }
467 487
468 } // namespace 488 } // namespace
469 489
470 /////////////////////////////////////////////////////////////////////////////// 490 ///////////////////////////////////////////////////////////////////////////////
471 // 491 //
472 // PluginsUI 492 // PluginsUI
(...skipping 18 matching lines...) Expand all
491 void PluginsUI::RegisterUserPrefs(PrefService* prefs) { 511 void PluginsUI::RegisterUserPrefs(PrefService* prefs) {
492 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, 512 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails,
493 false, 513 false,
494 PrefService::UNSYNCABLE_PREF); 514 PrefService::UNSYNCABLE_PREF);
495 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, 515 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar,
496 true, 516 true,
497 PrefService::UNSYNCABLE_PREF); 517 PrefService::UNSYNCABLE_PREF);
498 prefs->RegisterDictionaryPref(prefs::kContentSettingsPluginWhitelist, 518 prefs->RegisterDictionaryPref(prefs::kContentSettingsPluginWhitelist,
499 PrefService::SYNCABLE_PREF); 519 PrefService::SYNCABLE_PREF);
500 } 520 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698