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

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: Remove exclusion of plugin_installer and plugin_finder from build when enable_plugin_installation i… 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 // Helper callback method to process result of CanEnablePlugin method.
James Hawkins 2012/09/04 14:13:17 nit: No need to specify that this is a helper call
ibraaaa 2012/09/04 14:52:09 Done.
63 void CheckCanEnablePluginCallback(bool can_enable) {
James Hawkins 2012/09/04 14:13:17 What is the purpose of this function?
ibraaaa 2012/09/04 14:52:09 We merged EnablePlugin and CanEnablePlugin into on
James Hawkins 2012/09/04 14:55:50 OK. The function name seems a bit misleading as i
ibraaaa 2012/09/04 15:09:08 Ahh, ok. Actually, the name is a left over from mu
64 DCHECK(can_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 typedef base::hash_map<std::string, std::vector<const WebPluginInfo*> >
James Hawkins 2012/09/04 14:13:17 nit: Document the map.
ibraaaa 2012/09/04 14:52:09 Done.
182 PluginGroups;
183
183 // This pref guards the value whether about:plugins is in the details mode or 184 // This pref guards the value whether about:plugins is in the details mode or
184 // not. 185 // not.
185 BooleanPrefMember show_details_; 186 BooleanPrefMember show_details_;
186 187
187 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler); 188 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler);
188 }; 189 };
189 190
190 PluginsDOMHandler::PluginsDOMHandler() 191 PluginsDOMHandler::PluginsDOMHandler()
191 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 192 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
192 } 193 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 plugin_prefs->EnablePluginGroup(false, internalpdf); 260 plugin_prefs->EnablePluginGroup(false, internalpdf);
260 else if (group_name == internalpdf) 261 else if (group_name == internalpdf)
261 plugin_prefs->EnablePluginGroup(false, adobereader); 262 plugin_prefs->EnablePluginGroup(false, adobereader);
262 } 263 }
263 } else { 264 } else {
264 FilePath::StringType file_path; 265 FilePath::StringType file_path;
265 if (!args->GetString(0, &file_path)) { 266 if (!args->GetString(0, &file_path)) {
266 NOTREACHED(); 267 NOTREACHED();
267 return; 268 return;
268 } 269 }
269 DCHECK(plugin_prefs->CanEnablePlugin(enable, FilePath(file_path))); 270
270 plugin_prefs->EnablePlugin(enable, FilePath(file_path), 271 plugin_prefs->EnablePlugin(enable, FilePath(file_path),
271 base::Bind(&base::DoNothing)); 272 base::Bind(&CheckCanEnablePluginCallback));
272 } 273 }
273 } 274 }
274 275
275 void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) { 276 void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) {
276 std::string details_mode; 277 std::string details_mode;
277 if (!args->GetString(0, &details_mode)) { 278 if (!args->GetString(0, &details_mode)) {
278 NOTREACHED(); 279 NOTREACHED();
279 return; 280 return;
280 } 281 }
281 show_details_.SetValue(details_mode == "true"); 282 show_details_.SetValue(details_mode == "true");
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 328
328 #if defined(ENABLE_PLUGIN_INSTALLATION) 329 #if defined(ENABLE_PLUGIN_INSTALLATION)
329 PluginFinder::Get(base::Bind(&PluginsDOMHandler::LoadPlugins, 330 PluginFinder::Get(base::Bind(&PluginsDOMHandler::LoadPlugins,
330 weak_ptr_factory_.GetWeakPtr())); 331 weak_ptr_factory_.GetWeakPtr()));
331 #else 332 #else
332 LoadPlugins(NULL); 333 LoadPlugins(NULL);
333 #endif 334 #endif
334 } 335 }
335 336
336 void PluginsDOMHandler::LoadPlugins(PluginFinder* plugin_finder) { 337 void PluginsDOMHandler::LoadPlugins(PluginFinder* plugin_finder) {
337 PluginService::GetInstance()->GetPluginGroups( 338 PluginService::GetInstance()->GetPlugins(
338 base::Bind(&PluginsDOMHandler::PluginsLoaded, 339 base::Bind(&PluginsDOMHandler::PluginsLoaded,
339 weak_ptr_factory_.GetWeakPtr(), plugin_finder)); 340 weak_ptr_factory_.GetWeakPtr(), plugin_finder));
340 } 341 }
341 342
342 void PluginsDOMHandler::PluginsLoaded(PluginFinder* plugin_finder, 343 void PluginsDOMHandler::PluginsLoaded(
343 const std::vector<PluginGroup>& groups) { 344 PluginFinder* plugin_finder,
345 const std::vector<webkit::WebPluginInfo>& plugins) {
344 Profile* profile = Profile::FromWebUI(web_ui()); 346 Profile* profile = Profile::FromWebUI(web_ui());
345 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); 347 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile);
346 348
347 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); 349 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard();
348 350
349 // Construct DictionaryValues to return to the UI 351 // Group plug-ins by identifier. This is done to be able to display
352 // the plug-ins in UI in a grouped fashion.
353 PluginGroups groups;
354 for (size_t i = 0; i < plugins.size(); ++i) {
355 PluginInstaller* installer = plugin_finder->GetPluginInstaller(plugins[i]);
356 groups[installer->identifier()].push_back(&plugins[i]);
357 }
358
359 // Construct DictionaryValues to return to UI.
350 ListValue* plugin_groups_data = new ListValue(); 360 ListValue* plugin_groups_data = new ListValue();
351 for (size_t i = 0; i < groups.size(); ++i) { 361 for (PluginGroups::const_iterator it = groups.begin();
352 const PluginGroup& group = groups[i]; 362 it != groups.end(); ++it) {
353 if (group.IsEmpty()) 363 const std::vector<const WebPluginInfo*>& group_plugins = it->second;
354 continue;
355 ListValue* plugin_files = new ListValue(); 364 ListValue* plugin_files = new ListValue();
356 string16 group_name = group.GetGroupName(); 365 PluginInstaller* plugin_installer =
366 plugin_finder->GetPluginInstaller(*group_plugins[0]);
367 string16 group_name = plugin_installer->name();
368 std::string group_identifier = plugin_installer->identifier();
357 bool group_enabled = false; 369 bool group_enabled = false;
358 bool all_plugins_enabled_by_policy = true; 370 bool all_plugins_enabled_by_policy = true;
359 bool all_plugins_disabled_by_policy = true; 371 bool all_plugins_disabled_by_policy = true;
360 const WebPluginInfo* active_plugin = NULL; 372 const WebPluginInfo* active_plugin = NULL;
361 for (size_t j = 0; j < group.web_plugin_infos().size(); ++j) { 373 for (size_t j = 0; j < group_plugins.size(); ++j) {
362 const WebPluginInfo& group_plugin = group.web_plugin_infos()[j]; 374 const WebPluginInfo& group_plugin = *group_plugins[j];
363 375
364 DictionaryValue* plugin_file = new DictionaryValue(); 376 DictionaryValue* plugin_file = new DictionaryValue();
365 plugin_file->SetString("name", group_plugin.name); 377 plugin_file->SetString("name", group_plugin.name);
366 plugin_file->SetString("description", group_plugin.desc); 378 plugin_file->SetString("description", group_plugin.desc);
367 plugin_file->SetString("path", group_plugin.path.value()); 379 plugin_file->SetString("path", group_plugin.path.value());
368 plugin_file->SetString("version", group_plugin.version); 380 plugin_file->SetString("version", group_plugin.version);
369 plugin_file->SetString("type", PluginTypeToString(group_plugin.type)); 381 plugin_file->SetString("type", PluginTypeToString(group_plugin.type));
370 382
371 ListValue* mime_types = new ListValue(); 383 ListValue* mime_types = new ListValue();
372 const std::vector<webkit::WebPluginMimeType>& plugin_mime_types = 384 const std::vector<webkit::WebPluginMimeType>& plugin_mime_types =
(...skipping 24 matching lines...) Expand all
397 PluginPrefs::PolicyStatus plugin_status = 409 PluginPrefs::PolicyStatus plugin_status =
398 plugin_prefs->PolicyStatusForPlugin(group_plugin.name); 410 plugin_prefs->PolicyStatusForPlugin(group_plugin.name);
399 PluginPrefs::PolicyStatus group_status = 411 PluginPrefs::PolicyStatus group_status =
400 plugin_prefs->PolicyStatusForPlugin(group_name); 412 plugin_prefs->PolicyStatusForPlugin(group_name);
401 if (plugin_status == PluginPrefs::POLICY_ENABLED || 413 if (plugin_status == PluginPrefs::POLICY_ENABLED ||
402 group_status == PluginPrefs::POLICY_ENABLED) { 414 group_status == PluginPrefs::POLICY_ENABLED) {
403 enabled_mode = "enabledByPolicy"; 415 enabled_mode = "enabledByPolicy";
404 } else { 416 } else {
405 all_plugins_enabled_by_policy = false; 417 all_plugins_enabled_by_policy = false;
406 if (plugin_status == PluginPrefs::POLICY_DISABLED || 418 if (plugin_status == PluginPrefs::POLICY_DISABLED ||
407 group_status == PluginPrefs::POLICY_DISABLED) { 419 group_status == PluginPrefs::POLICY_DISABLED) {
408 enabled_mode = "disabledByPolicy"; 420 enabled_mode = "disabledByPolicy";
409 } else { 421 } else {
410 all_plugins_disabled_by_policy = false; 422 all_plugins_disabled_by_policy = false;
411 if (plugin_enabled) { 423 if (plugin_enabled) {
412 enabled_mode = "enabledByUser"; 424 enabled_mode = "enabledByUser";
413 } else { 425 } else {
414 enabled_mode = "disabledByUser"; 426 enabled_mode = "disabledByUser";
415 } 427 }
416 } 428 }
417 } 429 }
418 plugin_file->SetString("enabledMode", enabled_mode); 430 plugin_file->SetString("enabledMode", enabled_mode);
419 431
420 plugin_files->Append(plugin_file); 432 plugin_files->Append(plugin_file);
421 } 433 }
422 DictionaryValue* group_data = new DictionaryValue(); 434 DictionaryValue* group_data = new DictionaryValue();
423 435
424 group_data->Set("plugin_files", plugin_files); 436 group_data->Set("plugin_files", plugin_files);
425 group_data->SetString("name", group_name); 437 group_data->SetString("name", group_name);
426 group_data->SetString("id", group.identifier()); 438 group_data->SetString("id", group_identifier);
427 group_data->SetString("description", active_plugin->desc); 439 group_data->SetString("description", active_plugin->desc);
428 group_data->SetString("version", active_plugin->version); 440 group_data->SetString("version", active_plugin->version);
429 441
430 #if defined(ENABLE_PLUGIN_INSTALLATION) 442 #if defined(ENABLE_PLUGIN_INSTALLATION)
431 PluginInstaller* installer = 443 PluginInstaller* installer =
432 plugin_finder->FindPluginWithIdentifier(group.identifier()); 444 plugin_finder->FindPluginWithIdentifier(group_identifier);
433 if (installer) { 445 if (installer) {
434 bool out_of_date = installer->GetSecurityStatus(*active_plugin) == 446 bool out_of_date = installer->GetSecurityStatus(*active_plugin) ==
435 PluginInstaller::SECURITY_STATUS_OUT_OF_DATE; 447 PluginInstaller::SECURITY_STATUS_OUT_OF_DATE;
436 group_data->SetBoolean("critical", out_of_date); 448 group_data->SetBoolean("critical", out_of_date);
437 group_data->SetString("update_url", installer->plugin_url().spec()); 449 group_data->SetString("update_url", installer->plugin_url().spec());
438 } 450 }
439 #endif 451 #endif
440 452
441 std::string enabled_mode; 453 std::string enabled_mode;
442 if (all_plugins_enabled_by_policy) { 454 if (all_plugins_enabled_by_policy) {
443 enabled_mode = "enabledByPolicy"; 455 enabled_mode = "enabledByPolicy";
444 } else if (all_plugins_disabled_by_policy) { 456 } else if (all_plugins_disabled_by_policy) {
445 enabled_mode = "disabledByPolicy"; 457 enabled_mode = "disabledByPolicy";
446 } else if (group_enabled) { 458 } else if (group_enabled) {
447 enabled_mode = "enabledByUser"; 459 enabled_mode = "enabledByUser";
448 } else { 460 } else {
449 enabled_mode = "disabledByUser"; 461 enabled_mode = "disabledByUser";
450 } 462 }
451 group_data->SetString("enabledMode", enabled_mode); 463 group_data->SetString("enabledMode", enabled_mode);
452 464
453 bool always_allowed = false; 465 bool always_allowed = false;
454 if (group_enabled) { 466 if (group_enabled) {
455 const DictionaryValue* whitelist = profile->GetPrefs()->GetDictionary( 467 const DictionaryValue* whitelist = profile->GetPrefs()->GetDictionary(
456 prefs::kContentSettingsPluginWhitelist); 468 prefs::kContentSettingsPluginWhitelist);
457 whitelist->GetBoolean(group.identifier(), &always_allowed); 469 whitelist->GetBoolean(group_identifier, &always_allowed);
458 } 470 }
459 group_data->SetBoolean("alwaysAllowed", always_allowed); 471 group_data->SetBoolean("alwaysAllowed", always_allowed);
460 472
461 plugin_groups_data->Append(group_data); 473 plugin_groups_data->Append(group_data);
462 } 474 }
463 DictionaryValue results; 475 DictionaryValue results;
464 results.Set("plugins", plugin_groups_data); 476 results.Set("plugins", plugin_groups_data);
465 web_ui()->CallJavascriptFunction("returnPluginsData", results); 477 web_ui()->CallJavascriptFunction("returnPluginsData", results);
466 } 478 }
467 479
(...skipping 23 matching lines...) Expand all
491 void PluginsUI::RegisterUserPrefs(PrefService* prefs) { 503 void PluginsUI::RegisterUserPrefs(PrefService* prefs) {
492 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, 504 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails,
493 false, 505 false,
494 PrefService::UNSYNCABLE_PREF); 506 PrefService::UNSYNCABLE_PREF);
495 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, 507 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar,
496 true, 508 true,
497 PrefService::UNSYNCABLE_PREF); 509 PrefService::UNSYNCABLE_PREF);
498 prefs->RegisterDictionaryPref(prefs::kContentSettingsPluginWhitelist, 510 prefs->RegisterDictionaryPref(prefs::kContentSettingsPluginWhitelist,
499 PrefService::SYNCABLE_PREF); 511 PrefService::SYNCABLE_PREF);
500 } 512 }
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