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

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 bug in chromeos loading the plugins page 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
« no previous file with comments | « chrome/browser/ui/pdf/pdf_unsupported_feature.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/memory/ref_counted_memory.h" 13 #include "base/memory/ref_counted_memory.h"
14 #include "base/memory/singleton.h" 14 #include "base/memory/singleton.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/message_loop.h" 16 #include "base/message_loop.h"
17 #include "base/path_service.h" 17 #include "base/path_service.h"
18 #include "base/utf_string_conversions.h" 18 #include "base/utf_string_conversions.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "chrome/browser/api/prefs/pref_member.h" 20 #include "chrome/browser/api/prefs/pref_member.h"
21 #include "chrome/browser/content_settings/host_content_settings_map.h" 21 #include "chrome/browser/content_settings/host_content_settings_map.h"
22 #include "chrome/browser/plugin_finder.h"
23 #include "chrome/browser/plugin_installer.h"
22 #include "chrome/browser/plugin_prefs.h" 24 #include "chrome/browser/plugin_prefs.h"
23 #include "chrome/browser/prefs/pref_service.h" 25 #include "chrome/browser/prefs/pref_service.h"
24 #include "chrome/browser/prefs/scoped_user_pref_update.h" 26 #include "chrome/browser/prefs/scoped_user_pref_update.h"
25 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/ui/browser.h" 28 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/browser_window.h" 29 #include "chrome/browser/ui/browser_window.h"
28 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 30 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
29 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" 31 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
30 #include "chrome/common/chrome_content_client.h" 32 #include "chrome/common/chrome_content_client.h"
31 #include "chrome/common/chrome_notification_types.h" 33 #include "chrome/common/chrome_notification_types.h"
(...skipping 10 matching lines...) Expand all
42 #include "grit/theme_resources.h" 44 #include "grit/theme_resources.h"
43 #include "ui/base/l10n/l10n_util.h" 45 #include "ui/base/l10n/l10n_util.h"
44 #include "ui/base/layout.h" 46 #include "ui/base/layout.h"
45 #include "ui/base/resource/resource_bundle.h" 47 #include "ui/base/resource/resource_bundle.h"
46 #include "webkit/plugins/npapi/plugin_group.h" 48 #include "webkit/plugins/npapi/plugin_group.h"
47 49
48 #if defined(OS_CHROMEOS) 50 #if defined(OS_CHROMEOS)
49 #include "chrome/browser/ui/webui/chromeos/ui_account_tweaks.h" 51 #include "chrome/browser/ui/webui/chromeos/ui_account_tweaks.h"
50 #endif 52 #endif
51 53
52 #if defined(ENABLE_PLUGIN_INSTALLATION)
53 #include "chrome/browser/plugin_finder.h"
54 #include "chrome/browser/plugin_installer.h"
55 #else
56 // Forward-declare PluginFinder. It's never actually used, but we pass a NULL
57 // pointer instead.
58 class PluginFinder;
59 #endif
60
61 using content::PluginService; 54 using content::PluginService;
62 using content::WebContents; 55 using content::WebContents;
63 using content::WebUIMessageHandler; 56 using content::WebUIMessageHandler;
64 using webkit::npapi::PluginGroup; 57 using webkit::npapi::PluginGroup;
65 using webkit::WebPluginInfo; 58 using webkit::WebPluginInfo;
66 59
67 namespace { 60 namespace {
68 61
62 // Callback function to process result of EnablePlugin method.
63 void AssertPluginEnabled(bool did_enable) {
64 DCHECK(did_enable);
65 }
66
69 ChromeWebUIDataSource* CreatePluginsUIHTMLSource() { 67 ChromeWebUIDataSource* CreatePluginsUIHTMLSource() {
70 ChromeWebUIDataSource* source = 68 ChromeWebUIDataSource* source =
71 new ChromeWebUIDataSource(chrome::kChromeUIPluginsHost); 69 new ChromeWebUIDataSource(chrome::kChromeUIPluginsHost);
72 source->set_use_json_js_format_v2(); 70 source->set_use_json_js_format_v2();
73 71
74 source->AddLocalizedString("pluginsTitle", IDS_PLUGINS_TITLE); 72 source->AddLocalizedString("pluginsTitle", IDS_PLUGINS_TITLE);
75 source->AddLocalizedString("pluginsDetailsModeLink", 73 source->AddLocalizedString("pluginsDetailsModeLink",
76 IDS_PLUGINS_DETAILS_MODE_LINK); 74 IDS_PLUGINS_DETAILS_MODE_LINK);
77 source->AddLocalizedString("pluginsNoneInstalled", 75 source->AddLocalizedString("pluginsNoneInstalled",
78 IDS_PLUGINS_NONE_INSTALLED); 76 IDS_PLUGINS_NONE_INSTALLED);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 165
168 private: 166 private:
169 // Call this to start getting the plugins on the UI thread. 167 // Call this to start getting the plugins on the UI thread.
170 void GetPluginFinder(); 168 void GetPluginFinder();
171 169
172 // Called when we have a PluginFinder and need to load the list of plug-ins. 170 // Called when we have a PluginFinder and need to load the list of plug-ins.
173 void LoadPlugins(PluginFinder* plugin_finder); 171 void LoadPlugins(PluginFinder* plugin_finder);
174 172
175 // Called on the UI thread when the plugin information is ready. 173 // Called on the UI thread when the plugin information is ready.
176 void PluginsLoaded(PluginFinder* plugin_finder, 174 void PluginsLoaded(PluginFinder* plugin_finder,
177 const std::vector<PluginGroup>& groups); 175 const std::vector<webkit::WebPluginInfo>& plugins);
178 176
179 content::NotificationRegistrar registrar_; 177 content::NotificationRegistrar registrar_;
180 178
181 base::WeakPtrFactory<PluginsDOMHandler> weak_ptr_factory_; 179 base::WeakPtrFactory<PluginsDOMHandler> weak_ptr_factory_;
182 180
181 // Holds grouped plug-ins. The key is the group identifier and
182 // the value is the list of plug-ins belonging to the group.
183 typedef base::hash_map<std::string, std::vector<const WebPluginInfo*> >
184 PluginGroups;
185
183 // This pref guards the value whether about:plugins is in the details mode or 186 // This pref guards the value whether about:plugins is in the details mode or
184 // not. 187 // not.
185 BooleanPrefMember show_details_; 188 BooleanPrefMember show_details_;
186 189
187 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler); 190 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler);
188 }; 191 };
189 192
190 PluginsDOMHandler::PluginsDOMHandler() 193 PluginsDOMHandler::PluginsDOMHandler()
191 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 194 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
192 } 195 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 plugin_prefs->EnablePluginGroup(false, internalpdf); 262 plugin_prefs->EnablePluginGroup(false, internalpdf);
260 else if (group_name == internalpdf) 263 else if (group_name == internalpdf)
261 plugin_prefs->EnablePluginGroup(false, adobereader); 264 plugin_prefs->EnablePluginGroup(false, adobereader);
262 } 265 }
263 } else { 266 } else {
264 FilePath::StringType file_path; 267 FilePath::StringType file_path;
265 if (!args->GetString(0, &file_path)) { 268 if (!args->GetString(0, &file_path)) {
266 NOTREACHED(); 269 NOTREACHED();
267 return; 270 return;
268 } 271 }
269 DCHECK(plugin_prefs->CanEnablePlugin(enable, FilePath(file_path))); 272
270 plugin_prefs->EnablePlugin(enable, FilePath(file_path), 273 plugin_prefs->EnablePlugin(enable, FilePath(file_path),
271 base::Bind(&base::DoNothing)); 274 base::Bind(&AssertPluginEnabled));
272 } 275 }
273 } 276 }
274 277
275 void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) { 278 void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) {
276 std::string details_mode; 279 std::string details_mode;
277 if (!args->GetString(0, &details_mode)) { 280 if (!args->GetString(0, &details_mode)) {
278 NOTREACHED(); 281 NOTREACHED();
279 return; 282 return;
280 } 283 }
281 show_details_.SetValue(details_mode == "true"); 284 show_details_.SetValue(details_mode == "true");
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 const content::NotificationSource& source, 321 const content::NotificationSource& source,
319 const content::NotificationDetails& details) { 322 const content::NotificationDetails& details) {
320 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); 323 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type);
321 GetPluginFinder(); 324 GetPluginFinder();
322 } 325 }
323 326
324 void PluginsDOMHandler::GetPluginFinder() { 327 void PluginsDOMHandler::GetPluginFinder() {
325 if (weak_ptr_factory_.HasWeakPtrs()) 328 if (weak_ptr_factory_.HasWeakPtrs())
326 return; 329 return;
327 330
328 #if defined(ENABLE_PLUGIN_INSTALLATION)
329 PluginFinder::Get(base::Bind(&PluginsDOMHandler::LoadPlugins, 331 PluginFinder::Get(base::Bind(&PluginsDOMHandler::LoadPlugins,
330 weak_ptr_factory_.GetWeakPtr())); 332 weak_ptr_factory_.GetWeakPtr()));
331 #else
332 LoadPlugins(NULL);
333 #endif
334 } 333 }
335 334
336 void PluginsDOMHandler::LoadPlugins(PluginFinder* plugin_finder) { 335 void PluginsDOMHandler::LoadPlugins(PluginFinder* plugin_finder) {
337 PluginService::GetInstance()->GetPluginGroups( 336 PluginService::GetInstance()->GetPlugins(
338 base::Bind(&PluginsDOMHandler::PluginsLoaded, 337 base::Bind(&PluginsDOMHandler::PluginsLoaded,
339 weak_ptr_factory_.GetWeakPtr(), plugin_finder)); 338 weak_ptr_factory_.GetWeakPtr(), plugin_finder));
340 } 339 }
341 340
342 void PluginsDOMHandler::PluginsLoaded(PluginFinder* plugin_finder, 341 void PluginsDOMHandler::PluginsLoaded(
343 const std::vector<PluginGroup>& groups) { 342 PluginFinder* plugin_finder,
343 const std::vector<webkit::WebPluginInfo>& plugins) {
344 Profile* profile = Profile::FromWebUI(web_ui()); 344 Profile* profile = Profile::FromWebUI(web_ui());
345 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); 345 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile);
346 346
347 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); 347 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard();
348 348
349 // Construct DictionaryValues to return to the UI 349 // Group plug-ins by identifier. This is done to be able to display
350 // the plug-ins in UI in a grouped fashion.
351 PluginGroups groups;
352 for (size_t i = 0; i < plugins.size(); ++i) {
353 PluginInstaller* installer = plugin_finder->GetPluginInstaller(plugins[i]);
354 groups[installer->identifier()].push_back(&plugins[i]);
355 }
356
357 // Construct DictionaryValues to return to UI.
350 ListValue* plugin_groups_data = new ListValue(); 358 ListValue* plugin_groups_data = new ListValue();
351 for (size_t i = 0; i < groups.size(); ++i) { 359 for (PluginGroups::const_iterator it = groups.begin();
352 const PluginGroup& group = groups[i]; 360 it != groups.end(); ++it) {
353 if (group.IsEmpty()) 361 const std::vector<const WebPluginInfo*>& group_plugins = it->second;
354 continue;
355 ListValue* plugin_files = new ListValue(); 362 ListValue* plugin_files = new ListValue();
356 string16 group_name = group.GetGroupName(); 363 PluginInstaller* plugin_installer =
364 plugin_finder->GetPluginInstaller(*group_plugins[0]);
365 string16 group_name = plugin_installer->name();
366 std::string group_identifier = plugin_installer->identifier();
357 bool group_enabled = false; 367 bool group_enabled = false;
358 bool all_plugins_enabled_by_policy = true; 368 bool all_plugins_enabled_by_policy = true;
359 bool all_plugins_disabled_by_policy = true; 369 bool all_plugins_disabled_by_policy = true;
360 const WebPluginInfo* active_plugin = NULL; 370 const WebPluginInfo* active_plugin = NULL;
361 for (size_t j = 0; j < group.web_plugin_infos().size(); ++j) { 371 for (size_t j = 0; j < group_plugins.size(); ++j) {
362 const WebPluginInfo& group_plugin = group.web_plugin_infos()[j]; 372 const WebPluginInfo& group_plugin = *group_plugins[j];
363 373
364 DictionaryValue* plugin_file = new DictionaryValue(); 374 DictionaryValue* plugin_file = new DictionaryValue();
365 plugin_file->SetString("name", group_plugin.name); 375 plugin_file->SetString("name", group_plugin.name);
366 plugin_file->SetString("description", group_plugin.desc); 376 plugin_file->SetString("description", group_plugin.desc);
367 plugin_file->SetString("path", group_plugin.path.value()); 377 plugin_file->SetString("path", group_plugin.path.value());
368 plugin_file->SetString("version", group_plugin.version); 378 plugin_file->SetString("version", group_plugin.version);
369 plugin_file->SetString("type", PluginTypeToString(group_plugin.type)); 379 plugin_file->SetString("type", PluginTypeToString(group_plugin.type));
370 380
371 ListValue* mime_types = new ListValue(); 381 ListValue* mime_types = new ListValue();
372 const std::vector<webkit::WebPluginMimeType>& plugin_mime_types = 382 const std::vector<webkit::WebPluginMimeType>& plugin_mime_types =
(...skipping 24 matching lines...) Expand all
397 PluginPrefs::PolicyStatus plugin_status = 407 PluginPrefs::PolicyStatus plugin_status =
398 plugin_prefs->PolicyStatusForPlugin(group_plugin.name); 408 plugin_prefs->PolicyStatusForPlugin(group_plugin.name);
399 PluginPrefs::PolicyStatus group_status = 409 PluginPrefs::PolicyStatus group_status =
400 plugin_prefs->PolicyStatusForPlugin(group_name); 410 plugin_prefs->PolicyStatusForPlugin(group_name);
401 if (plugin_status == PluginPrefs::POLICY_ENABLED || 411 if (plugin_status == PluginPrefs::POLICY_ENABLED ||
402 group_status == PluginPrefs::POLICY_ENABLED) { 412 group_status == PluginPrefs::POLICY_ENABLED) {
403 enabled_mode = "enabledByPolicy"; 413 enabled_mode = "enabledByPolicy";
404 } else { 414 } else {
405 all_plugins_enabled_by_policy = false; 415 all_plugins_enabled_by_policy = false;
406 if (plugin_status == PluginPrefs::POLICY_DISABLED || 416 if (plugin_status == PluginPrefs::POLICY_DISABLED ||
407 group_status == PluginPrefs::POLICY_DISABLED) { 417 group_status == PluginPrefs::POLICY_DISABLED) {
408 enabled_mode = "disabledByPolicy"; 418 enabled_mode = "disabledByPolicy";
409 } else { 419 } else {
410 all_plugins_disabled_by_policy = false; 420 all_plugins_disabled_by_policy = false;
411 if (plugin_enabled) { 421 if (plugin_enabled) {
412 enabled_mode = "enabledByUser"; 422 enabled_mode = "enabledByUser";
413 } else { 423 } else {
414 enabled_mode = "disabledByUser"; 424 enabled_mode = "disabledByUser";
415 } 425 }
416 } 426 }
417 } 427 }
418 plugin_file->SetString("enabledMode", enabled_mode); 428 plugin_file->SetString("enabledMode", enabled_mode);
419 429
420 plugin_files->Append(plugin_file); 430 plugin_files->Append(plugin_file);
421 } 431 }
422 DictionaryValue* group_data = new DictionaryValue(); 432 DictionaryValue* group_data = new DictionaryValue();
423 433
424 group_data->Set("plugin_files", plugin_files); 434 group_data->Set("plugin_files", plugin_files);
425 group_data->SetString("name", group_name); 435 group_data->SetString("name", group_name);
426 group_data->SetString("id", group.identifier()); 436 group_data->SetString("id", group_identifier);
427 group_data->SetString("description", active_plugin->desc); 437 group_data->SetString("description", active_plugin->desc);
428 group_data->SetString("version", active_plugin->version); 438 group_data->SetString("version", active_plugin->version);
429 439
430 #if defined(ENABLE_PLUGIN_INSTALLATION) 440 #if defined(ENABLE_PLUGIN_INSTALLATION)
431 PluginInstaller* installer = 441 PluginInstaller* installer =
432 plugin_finder->FindPluginWithIdentifier(group.identifier()); 442 plugin_finder->FindPluginWithIdentifier(group_identifier);
433 if (installer) { 443 if (installer) {
434 bool out_of_date = installer->GetSecurityStatus(*active_plugin) == 444 bool out_of_date = installer->GetSecurityStatus(*active_plugin) ==
435 PluginInstaller::SECURITY_STATUS_OUT_OF_DATE; 445 PluginInstaller::SECURITY_STATUS_OUT_OF_DATE;
436 group_data->SetBoolean("critical", out_of_date); 446 group_data->SetBoolean("critical", out_of_date);
437 group_data->SetString("update_url", installer->plugin_url().spec()); 447 group_data->SetString("update_url", installer->plugin_url().spec());
438 } 448 }
439 #endif 449 #endif
440 450
441 std::string enabled_mode; 451 std::string enabled_mode;
442 if (all_plugins_enabled_by_policy) { 452 if (all_plugins_enabled_by_policy) {
443 enabled_mode = "enabledByPolicy"; 453 enabled_mode = "enabledByPolicy";
444 } else if (all_plugins_disabled_by_policy) { 454 } else if (all_plugins_disabled_by_policy) {
445 enabled_mode = "disabledByPolicy"; 455 enabled_mode = "disabledByPolicy";
446 } else if (group_enabled) { 456 } else if (group_enabled) {
447 enabled_mode = "enabledByUser"; 457 enabled_mode = "enabledByUser";
448 } else { 458 } else {
449 enabled_mode = "disabledByUser"; 459 enabled_mode = "disabledByUser";
450 } 460 }
451 group_data->SetString("enabledMode", enabled_mode); 461 group_data->SetString("enabledMode", enabled_mode);
452 462
453 bool always_allowed = false; 463 bool always_allowed = false;
454 if (group_enabled) { 464 if (group_enabled) {
455 const DictionaryValue* whitelist = profile->GetPrefs()->GetDictionary( 465 const DictionaryValue* whitelist = profile->GetPrefs()->GetDictionary(
456 prefs::kContentSettingsPluginWhitelist); 466 prefs::kContentSettingsPluginWhitelist);
457 whitelist->GetBoolean(group.identifier(), &always_allowed); 467 whitelist->GetBoolean(group_identifier, &always_allowed);
458 } 468 }
459 group_data->SetBoolean("alwaysAllowed", always_allowed); 469 group_data->SetBoolean("alwaysAllowed", always_allowed);
460 470
461 plugin_groups_data->Append(group_data); 471 plugin_groups_data->Append(group_data);
462 } 472 }
463 DictionaryValue results; 473 DictionaryValue results;
464 results.Set("plugins", plugin_groups_data); 474 results.Set("plugins", plugin_groups_data);
465 web_ui()->CallJavascriptFunction("returnPluginsData", results); 475 web_ui()->CallJavascriptFunction("returnPluginsData", results);
466 } 476 }
467 477
(...skipping 23 matching lines...) Expand all
491 void PluginsUI::RegisterUserPrefs(PrefService* prefs) { 501 void PluginsUI::RegisterUserPrefs(PrefService* prefs) {
492 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, 502 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails,
493 false, 503 false,
494 PrefService::UNSYNCABLE_PREF); 504 PrefService::UNSYNCABLE_PREF);
495 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, 505 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar,
496 true, 506 true,
497 PrefService::UNSYNCABLE_PREF); 507 PrefService::UNSYNCABLE_PREF);
498 prefs->RegisterDictionaryPref(prefs::kContentSettingsPluginWhitelist, 508 prefs->RegisterDictionaryPref(prefs::kContentSettingsPluginWhitelist,
499 PrefService::SYNCABLE_PREF); 509 PrefService::SYNCABLE_PREF);
500 } 510 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/pdf/pdf_unsupported_feature.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698