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

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

Issue 9536013: Move |requires_authorization| flag for plug-ins out of webkit/ (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') | webkit/plugins/npapi/plugin_group.h » ('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/singleton.h" 13 #include "base/memory/singleton.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/message_loop.h" 15 #include "base/message_loop.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chrome/browser/content_settings/host_content_settings_map.h" 19 #include "chrome/browser/content_settings/host_content_settings_map.h"
20 #include "chrome/browser/plugin_finder.h"
21 #include "chrome/browser/plugin_installer.h"
20 #include "chrome/browser/plugin_prefs.h" 22 #include "chrome/browser/plugin_prefs.h"
21 #include "chrome/browser/prefs/scoped_user_pref_update.h" 23 #include "chrome/browser/prefs/scoped_user_pref_update.h"
22 #include "chrome/browser/prefs/pref_member.h" 24 #include "chrome/browser/prefs/pref_member.h"
23 #include "chrome/browser/prefs/pref_service.h" 25 #include "chrome/browser/prefs/pref_service.h"
24 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/ui/browser.h" 27 #include "chrome/browser/ui/browser.h"
26 #include "chrome/browser/ui/browser_window.h" 28 #include "chrome/browser/ui/browser_window.h"
27 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 29 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
28 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" 30 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
29 #include "chrome/common/chrome_content_client.h" 31 #include "chrome/common/chrome_content_client.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 // Callback for the "setPluginAlwaysAllowed" message. 144 // Callback for the "setPluginAlwaysAllowed" message.
143 void HandleSetPluginAlwaysAllowed(const ListValue* args); 145 void HandleSetPluginAlwaysAllowed(const ListValue* args);
144 146
145 // content::NotificationObserver method overrides 147 // content::NotificationObserver method overrides
146 virtual void Observe(int type, 148 virtual void Observe(int type,
147 const content::NotificationSource& source, 149 const content::NotificationSource& source,
148 const content::NotificationDetails& details) OVERRIDE; 150 const content::NotificationDetails& details) OVERRIDE;
149 151
150 private: 152 private:
151 // Call this to start getting the plugins on the UI thread. 153 // Call this to start getting the plugins on the UI thread.
152 void LoadPlugins(); 154 void GetPluginFinder();
155
156 // XXX
jam 2012/03/09 19:10:08 ?
Bernhard Bauer 2012/03/09 20:28:12 Forgot a comment :)
157 void LoadPlugins(PluginFinder* plugin_finder);
153 158
154 // Called on the UI thread when the plugin information is ready. 159 // Called on the UI thread when the plugin information is ready.
155 void PluginsLoaded(const std::vector<PluginGroup>& groups); 160 void PluginsLoaded(PluginFinder* plugin_finder,
161 const std::vector<PluginGroup>& groups);
156 162
157 content::NotificationRegistrar registrar_; 163 content::NotificationRegistrar registrar_;
158 164
159 base::WeakPtrFactory<PluginsDOMHandler> weak_ptr_factory_; 165 base::WeakPtrFactory<PluginsDOMHandler> weak_ptr_factory_;
160 166
161 // This pref guards the value whether about:plugins is in the details mode or 167 // This pref guards the value whether about:plugins is in the details mode or
162 // not. 168 // not.
163 BooleanPrefMember show_details_; 169 BooleanPrefMember show_details_;
164 170
165 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler); 171 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler);
(...skipping 24 matching lines...) Expand all
190 base::Unretained(this))); 196 base::Unretained(this)));
191 web_ui()->RegisterMessageCallback("saveShowDetailsToPrefs", 197 web_ui()->RegisterMessageCallback("saveShowDetailsToPrefs",
192 base::Bind(&PluginsDOMHandler::HandleSaveShowDetailsToPrefs, 198 base::Bind(&PluginsDOMHandler::HandleSaveShowDetailsToPrefs,
193 base::Unretained(this))); 199 base::Unretained(this)));
194 web_ui()->RegisterMessageCallback("getShowDetails", 200 web_ui()->RegisterMessageCallback("getShowDetails",
195 base::Bind(&PluginsDOMHandler::HandleGetShowDetails, 201 base::Bind(&PluginsDOMHandler::HandleGetShowDetails,
196 base::Unretained(this))); 202 base::Unretained(this)));
197 } 203 }
198 204
199 void PluginsDOMHandler::HandleRequestPluginsData(const ListValue* args) { 205 void PluginsDOMHandler::HandleRequestPluginsData(const ListValue* args) {
200 LoadPlugins(); 206 GetPluginFinder();
201 } 207 }
202 208
203 void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) { 209 void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) {
204 Profile* profile = Profile::FromWebUI(web_ui()); 210 Profile* profile = Profile::FromWebUI(web_ui());
205 211
206 // Be robust in accepting badness since plug-ins display HTML (hence 212 // Be robust in accepting badness since plug-ins display HTML (hence
207 // JavaScript). 213 // JavaScript).
208 if (args->GetSize() != 3) { 214 if (args->GetSize() != 3) {
209 NOTREACHED(); 215 NOTREACHED();
210 return; 216 return;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 // whitelisted by the user from automatically whitelisted ones. 294 // whitelisted by the user from automatically whitelisted ones.
289 DictionaryPrefUpdate update(profile->GetPrefs(), 295 DictionaryPrefUpdate update(profile->GetPrefs(),
290 prefs::kContentSettingsPluginWhitelist); 296 prefs::kContentSettingsPluginWhitelist);
291 update->SetBoolean(plugin, allowed); 297 update->SetBoolean(plugin, allowed);
292 } 298 }
293 299
294 void PluginsDOMHandler::Observe(int type, 300 void PluginsDOMHandler::Observe(int type,
295 const content::NotificationSource& source, 301 const content::NotificationSource& source,
296 const content::NotificationDetails& details) { 302 const content::NotificationDetails& details) {
297 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); 303 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type);
298 LoadPlugins(); 304 GetPluginFinder();
299 } 305 }
300 306
301 void PluginsDOMHandler::LoadPlugins() { 307 void PluginsDOMHandler::GetPluginFinder() {
308 PluginFinder::Get(base::Bind(&PluginsDOMHandler::LoadPlugins,
309 weak_ptr_factory_.GetWeakPtr()));
310 }
311
312 void PluginsDOMHandler::LoadPlugins(PluginFinder* plugin_finder) {
302 if (weak_ptr_factory_.HasWeakPtrs()) 313 if (weak_ptr_factory_.HasWeakPtrs())
303 return; 314 return;
304 315
305 PluginService::GetInstance()->GetPluginGroups( 316 PluginService::GetInstance()->GetPluginGroups(
306 base::Bind(&PluginsDOMHandler::PluginsLoaded, 317 base::Bind(&PluginsDOMHandler::PluginsLoaded,
307 weak_ptr_factory_.GetWeakPtr())); 318 weak_ptr_factory_.GetWeakPtr(), plugin_finder));
308 } 319 }
309 320
310 void PluginsDOMHandler::PluginsLoaded(const std::vector<PluginGroup>& groups) { 321 void PluginsDOMHandler::PluginsLoaded(PluginFinder* plugin_finder,
322 const std::vector<PluginGroup>& groups) {
311 Profile* profile = Profile::FromWebUI(web_ui()); 323 Profile* profile = Profile::FromWebUI(web_ui());
312 PluginPrefs* plugin_prefs = 324 PluginPrefs* plugin_prefs =
313 PluginPrefs::GetForProfile(profile); 325 PluginPrefs::GetForProfile(profile);
314 326
315 HostContentSettingsMap* map = profile->GetHostContentSettingsMap(); 327 HostContentSettingsMap* map = profile->GetHostContentSettingsMap();
316 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); 328 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard();
317 329
318 // Construct DictionaryValues to return to the UI 330 // Construct DictionaryValues to return to the UI
319 ListValue* plugin_groups_data = new ListValue(); 331 ListValue* plugin_groups_data = new ListValue();
320 for (size_t i = 0; i < groups.size(); ++i) { 332 for (size_t i = 0; i < groups.size(); ++i) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 plugin_files->Append(plugin_file); 401 plugin_files->Append(plugin_file);
390 } 402 }
391 DictionaryValue* group_data = new DictionaryValue(); 403 DictionaryValue* group_data = new DictionaryValue();
392 404
393 group_data->Set("plugin_files", plugin_files); 405 group_data->Set("plugin_files", plugin_files);
394 group_data->SetString("name", group_name); 406 group_data->SetString("name", group_name);
395 group_data->SetString("id", group.identifier()); 407 group_data->SetString("id", group.identifier());
396 group_data->SetString("description", active_plugin->desc); 408 group_data->SetString("description", active_plugin->desc);
397 group_data->SetString("version", active_plugin->version); 409 group_data->SetString("version", active_plugin->version);
398 group_data->SetBoolean("critical", group.IsVulnerable(*active_plugin)); 410 group_data->SetBoolean("critical", group.IsVulnerable(*active_plugin));
399 group_data->SetString("update_url", group.GetUpdateURL()); 411
412 std::string update_url;
413 PluginInstaller* installer =
414 plugin_finder->FindPluginWithIdentifier(group.identifier());
415 if (installer)
416 update_url = installer->plugin_url().spec();
417 group_data->SetString("update_url", update_url);
400 418
401 std::string enabled_mode; 419 std::string enabled_mode;
402 if (all_plugins_enabled_by_policy) { 420 if (all_plugins_enabled_by_policy) {
403 enabled_mode = "enabledByPolicy"; 421 enabled_mode = "enabledByPolicy";
404 } else if (all_plugins_disabled_by_policy) { 422 } else if (all_plugins_disabled_by_policy) {
405 enabled_mode = "disabledByPolicy"; 423 enabled_mode = "disabledByPolicy";
406 } else if (group_enabled) { 424 } else if (group_enabled) {
407 enabled_mode = "enabledByUser"; 425 enabled_mode = "enabledByUser";
408 } else { 426 } else {
409 enabled_mode = "disabledByUser"; 427 enabled_mode = "disabledByUser";
410 } 428 }
411 group_data->SetString("enabledMode", enabled_mode); 429 group_data->SetString("enabledMode", enabled_mode);
412 430
413 // TODO(bauerb): We should have a method on HostContentSettinsMap for this. 431 // TODO(bauerb): We should have a method on HostContentSettingsMap for this.
414 bool always_allowed = false; 432 bool always_allowed = false;
415 ContentSettingsForOneType settings; 433 ContentSettingsForOneType settings;
416 map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_PLUGINS, 434 map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_PLUGINS,
417 group.identifier(), &settings); 435 group.identifier(), &settings);
418 for (ContentSettingsForOneType::const_iterator it = settings.begin(); 436 for (ContentSettingsForOneType::const_iterator it = settings.begin();
419 it != settings.end(); ++it) { 437 it != settings.end(); ++it) {
420 if (it->primary_pattern == wildcard && 438 if (it->primary_pattern == wildcard &&
421 it->secondary_pattern == wildcard && 439 it->secondary_pattern == wildcard &&
422 it->setting == CONTENT_SETTING_ALLOW) { 440 it->setting == CONTENT_SETTING_ALLOW) {
423 always_allowed = true; 441 always_allowed = true;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 void PluginsUI::RegisterUserPrefs(PrefService* prefs) { 478 void PluginsUI::RegisterUserPrefs(PrefService* prefs) {
461 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, 479 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails,
462 false, 480 false,
463 PrefService::UNSYNCABLE_PREF); 481 PrefService::UNSYNCABLE_PREF);
464 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, 482 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar,
465 true, 483 true,
466 PrefService::UNSYNCABLE_PREF); 484 PrefService::UNSYNCABLE_PREF);
467 prefs->RegisterDictionaryPref(prefs::kContentSettingsPluginWhitelist, 485 prefs->RegisterDictionaryPref(prefs::kContentSettingsPluginWhitelist,
468 PrefService::SYNCABLE_PREF); 486 PrefService::SYNCABLE_PREF);
469 } 487 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/plugins_win.json ('k') | webkit/plugins/npapi/plugin_group.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698