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

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

Issue 9874001: revert 128949 (and dependent 129252) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/plugins_win.json ('k') | content/utility/utility_thread_impl.cc » ('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
(...skipping 26 matching lines...) Expand all
37 #include "content/public/browser/web_ui.h" 37 #include "content/public/browser/web_ui.h"
38 #include "content/public/browser/web_ui_message_handler.h" 38 #include "content/public/browser/web_ui_message_handler.h"
39 #include "grit/browser_resources.h" 39 #include "grit/browser_resources.h"
40 #include "grit/generated_resources.h" 40 #include "grit/generated_resources.h"
41 #include "grit/theme_resources.h" 41 #include "grit/theme_resources.h"
42 #include "grit/theme_resources_standard.h" 42 #include "grit/theme_resources_standard.h"
43 #include "ui/base/l10n/l10n_util.h" 43 #include "ui/base/l10n/l10n_util.h"
44 #include "ui/base/resource/resource_bundle.h" 44 #include "ui/base/resource/resource_bundle.h"
45 #include "webkit/plugins/npapi/plugin_group.h" 45 #include "webkit/plugins/npapi/plugin_group.h"
46 46
47 #if defined(ENABLE_PLUGIN_INSTALLATION)
48 #include "chrome/browser/plugin_finder.h"
49 #include "chrome/browser/plugin_installer.h"
50 #else
51 // Forward-declare PluginFinder. It's never actually used, but we pass a NULL
52 // pointer instead.
53 class PluginFinder;
54 #endif
55
56 using content::PluginService; 47 using content::PluginService;
57 using content::WebContents; 48 using content::WebContents;
58 using content::WebUIMessageHandler; 49 using content::WebUIMessageHandler;
59 using webkit::npapi::PluginGroup; 50 using webkit::npapi::PluginGroup;
60 using webkit::WebPluginInfo; 51 using webkit::WebPluginInfo;
61 52
62 namespace { 53 namespace {
63 54
64 ChromeWebUIDataSource* CreatePluginsUIHTMLSource() { 55 ChromeWebUIDataSource* CreatePluginsUIHTMLSource() {
65 ChromeWebUIDataSource* source = 56 ChromeWebUIDataSource* source =
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // Callback for the "setPluginAlwaysAllowed" message. 142 // Callback for the "setPluginAlwaysAllowed" message.
152 void HandleSetPluginAlwaysAllowed(const ListValue* args); 143 void HandleSetPluginAlwaysAllowed(const ListValue* args);
153 144
154 // content::NotificationObserver method overrides 145 // content::NotificationObserver method overrides
155 virtual void Observe(int type, 146 virtual void Observe(int type,
156 const content::NotificationSource& source, 147 const content::NotificationSource& source,
157 const content::NotificationDetails& details) OVERRIDE; 148 const content::NotificationDetails& details) OVERRIDE;
158 149
159 private: 150 private:
160 // Call this to start getting the plugins on the UI thread. 151 // Call this to start getting the plugins on the UI thread.
161 void GetPluginFinder(); 152 void LoadPlugins();
162
163 // Called when we have a PluginFinder and need to load the list of plug-ins.
164 void LoadPlugins(PluginFinder* plugin_finder);
165 153
166 // Called on the UI thread when the plugin information is ready. 154 // Called on the UI thread when the plugin information is ready.
167 void PluginsLoaded(PluginFinder* plugin_finder, 155 void PluginsLoaded(const std::vector<PluginGroup>& groups);
168 const std::vector<PluginGroup>& groups);
169 156
170 content::NotificationRegistrar registrar_; 157 content::NotificationRegistrar registrar_;
171 158
172 base::WeakPtrFactory<PluginsDOMHandler> weak_ptr_factory_; 159 base::WeakPtrFactory<PluginsDOMHandler> weak_ptr_factory_;
173 160
174 // This pref guards the value whether about:plugins is in the details mode or 161 // This pref guards the value whether about:plugins is in the details mode or
175 // not. 162 // not.
176 BooleanPrefMember show_details_; 163 BooleanPrefMember show_details_;
177 164
178 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler); 165 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler);
(...skipping 24 matching lines...) Expand all
203 base::Unretained(this))); 190 base::Unretained(this)));
204 web_ui()->RegisterMessageCallback("saveShowDetailsToPrefs", 191 web_ui()->RegisterMessageCallback("saveShowDetailsToPrefs",
205 base::Bind(&PluginsDOMHandler::HandleSaveShowDetailsToPrefs, 192 base::Bind(&PluginsDOMHandler::HandleSaveShowDetailsToPrefs,
206 base::Unretained(this))); 193 base::Unretained(this)));
207 web_ui()->RegisterMessageCallback("getShowDetails", 194 web_ui()->RegisterMessageCallback("getShowDetails",
208 base::Bind(&PluginsDOMHandler::HandleGetShowDetails, 195 base::Bind(&PluginsDOMHandler::HandleGetShowDetails,
209 base::Unretained(this))); 196 base::Unretained(this)));
210 } 197 }
211 198
212 void PluginsDOMHandler::HandleRequestPluginsData(const ListValue* args) { 199 void PluginsDOMHandler::HandleRequestPluginsData(const ListValue* args) {
213 GetPluginFinder(); 200 LoadPlugins();
214 } 201 }
215 202
216 void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) { 203 void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) {
217 Profile* profile = Profile::FromWebUI(web_ui()); 204 Profile* profile = Profile::FromWebUI(web_ui());
218 205
219 // Be robust in accepting badness since plug-ins display HTML (hence 206 // Be robust in accepting badness since plug-ins display HTML (hence
220 // JavaScript). 207 // JavaScript).
221 if (args->GetSize() != 3) { 208 if (args->GetSize() != 3) {
222 NOTREACHED(); 209 NOTREACHED();
223 return; 210 return;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 // whitelisted by the user from automatically whitelisted ones. 288 // whitelisted by the user from automatically whitelisted ones.
302 DictionaryPrefUpdate update(profile->GetPrefs(), 289 DictionaryPrefUpdate update(profile->GetPrefs(),
303 prefs::kContentSettingsPluginWhitelist); 290 prefs::kContentSettingsPluginWhitelist);
304 update->SetBoolean(plugin, allowed); 291 update->SetBoolean(plugin, allowed);
305 } 292 }
306 293
307 void PluginsDOMHandler::Observe(int type, 294 void PluginsDOMHandler::Observe(int type,
308 const content::NotificationSource& source, 295 const content::NotificationSource& source,
309 const content::NotificationDetails& details) { 296 const content::NotificationDetails& details) {
310 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); 297 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type);
311 GetPluginFinder(); 298 LoadPlugins();
312 } 299 }
313 300
314 void PluginsDOMHandler::GetPluginFinder() { 301 void PluginsDOMHandler::LoadPlugins() {
315 if (weak_ptr_factory_.HasWeakPtrs()) 302 if (weak_ptr_factory_.HasWeakPtrs())
316 return; 303 return;
317 304
318 #if defined(ENABLE_PLUGIN_INSTALLATION) 305 PluginService::GetInstance()->GetPluginGroups(
319 PluginFinder::Get(base::Bind(&PluginsDOMHandler::LoadPlugins, 306 base::Bind(&PluginsDOMHandler::PluginsLoaded,
320 weak_ptr_factory_.GetWeakPtr())); 307 weak_ptr_factory_.GetWeakPtr()));
321 #else
322 LoadPlugins(NULL);
323 #endif
324 } 308 }
325 309
326 void PluginsDOMHandler::LoadPlugins(PluginFinder* plugin_finder) { 310 void PluginsDOMHandler::PluginsLoaded(const std::vector<PluginGroup>& groups) {
327 PluginService::GetInstance()->GetPluginGroups(
328 base::Bind(&PluginsDOMHandler::PluginsLoaded,
329 weak_ptr_factory_.GetWeakPtr(), plugin_finder));
330 }
331
332 void PluginsDOMHandler::PluginsLoaded(PluginFinder* plugin_finder,
333 const std::vector<PluginGroup>& groups) {
334 Profile* profile = Profile::FromWebUI(web_ui()); 311 Profile* profile = Profile::FromWebUI(web_ui());
335 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); 312 PluginPrefs* plugin_prefs =
313 PluginPrefs::GetForProfile(profile);
336 314
337 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); 315 HostContentSettingsMap* map = profile->GetHostContentSettingsMap();
338 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); 316 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard();
339 317
340 // Construct DictionaryValues to return to the UI 318 // Construct DictionaryValues to return to the UI
341 ListValue* plugin_groups_data = new ListValue(); 319 ListValue* plugin_groups_data = new ListValue();
342 for (size_t i = 0; i < groups.size(); ++i) { 320 for (size_t i = 0; i < groups.size(); ++i) {
343 const PluginGroup& group = groups[i]; 321 const PluginGroup& group = groups[i];
344 if (group.IsEmpty()) 322 if (group.IsEmpty())
345 continue; 323 continue;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 plugin_files->Append(plugin_file); 389 plugin_files->Append(plugin_file);
412 } 390 }
413 DictionaryValue* group_data = new DictionaryValue(); 391 DictionaryValue* group_data = new DictionaryValue();
414 392
415 group_data->Set("plugin_files", plugin_files); 393 group_data->Set("plugin_files", plugin_files);
416 group_data->SetString("name", group_name); 394 group_data->SetString("name", group_name);
417 group_data->SetString("id", group.identifier()); 395 group_data->SetString("id", group.identifier());
418 group_data->SetString("description", active_plugin->desc); 396 group_data->SetString("description", active_plugin->desc);
419 group_data->SetString("version", active_plugin->version); 397 group_data->SetString("version", active_plugin->version);
420 group_data->SetBoolean("critical", group.IsVulnerable(*active_plugin)); 398 group_data->SetBoolean("critical", group.IsVulnerable(*active_plugin));
421 399 group_data->SetString("update_url", group.GetUpdateURL());
422 std::string update_url;
423 #if defined(ENABLE_PLUGIN_INSTALLATION)
424 PluginInstaller* installer =
425 plugin_finder->FindPluginWithIdentifier(group.identifier());
426 if (installer)
427 update_url = installer->plugin_url().spec();
428 #endif
429 group_data->SetString("update_url", update_url);
430 400
431 std::string enabled_mode; 401 std::string enabled_mode;
432 if (all_plugins_enabled_by_policy) { 402 if (all_plugins_enabled_by_policy) {
433 enabled_mode = "enabledByPolicy"; 403 enabled_mode = "enabledByPolicy";
434 } else if (all_plugins_disabled_by_policy) { 404 } else if (all_plugins_disabled_by_policy) {
435 enabled_mode = "disabledByPolicy"; 405 enabled_mode = "disabledByPolicy";
436 } else if (group_enabled) { 406 } else if (group_enabled) {
437 enabled_mode = "enabledByUser"; 407 enabled_mode = "enabledByUser";
438 } else { 408 } else {
439 enabled_mode = "disabledByUser"; 409 enabled_mode = "disabledByUser";
440 } 410 }
441 group_data->SetString("enabledMode", enabled_mode); 411 group_data->SetString("enabledMode", enabled_mode);
442 412
443 // TODO(bauerb): We should have a method on HostContentSettingsMap for this. 413 // TODO(bauerb): We should have a method on HostContentSettinsMap for this.
444 bool always_allowed = false; 414 bool always_allowed = false;
445 ContentSettingsForOneType settings; 415 ContentSettingsForOneType settings;
446 map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_PLUGINS, 416 map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_PLUGINS,
447 group.identifier(), &settings); 417 group.identifier(), &settings);
448 for (ContentSettingsForOneType::const_iterator it = settings.begin(); 418 for (ContentSettingsForOneType::const_iterator it = settings.begin();
449 it != settings.end(); ++it) { 419 it != settings.end(); ++it) {
450 if (it->primary_pattern == wildcard && 420 if (it->primary_pattern == wildcard &&
451 it->secondary_pattern == wildcard && 421 it->secondary_pattern == wildcard &&
452 it->setting == CONTENT_SETTING_ALLOW) { 422 it->setting == CONTENT_SETTING_ALLOW) {
453 always_allowed = true; 423 always_allowed = true;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 void PluginsUI::RegisterUserPrefs(PrefService* prefs) { 460 void PluginsUI::RegisterUserPrefs(PrefService* prefs) {
491 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, 461 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails,
492 false, 462 false,
493 PrefService::UNSYNCABLE_PREF); 463 PrefService::UNSYNCABLE_PREF);
494 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, 464 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar,
495 true, 465 true,
496 PrefService::UNSYNCABLE_PREF); 466 PrefService::UNSYNCABLE_PREF);
497 prefs->RegisterDictionaryPref(prefs::kContentSettingsPluginWhitelist, 467 prefs->RegisterDictionaryPref(prefs::kContentSettingsPluginWhitelist,
498 PrefService::SYNCABLE_PREF); 468 PrefService::SYNCABLE_PREF);
499 } 469 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/plugins_win.json ('k') | content/utility/utility_thread_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698