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

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

Issue 9537014: Merge a bunch of CLs to whitelist the Google Talk plug-in when turning on click-to-play. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1025/src
Patch Set: sync 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
OLDNEW
1 // Copyright (c) 2011 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/plugin_prefs.h" 20 #include "chrome/browser/plugin_prefs.h"
21 #include "chrome/browser/prefs/scoped_user_pref_update.h"
20 #include "chrome/browser/prefs/pref_member.h" 22 #include "chrome/browser/prefs/pref_member.h"
21 #include "chrome/browser/prefs/pref_service.h" 23 #include "chrome/browser/prefs/pref_service.h"
22 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_window.h" 26 #include "chrome/browser/ui/browser_window.h"
25 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 27 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
26 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" 28 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
27 #include "chrome/common/chrome_content_client.h" 29 #include "chrome/common/chrome_content_client.h"
28 #include "chrome/common/chrome_notification_types.h" 30 #include "chrome/common/chrome_notification_types.h"
29 #include "chrome/common/chrome_paths.h" 31 #include "chrome/common/chrome_paths.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 source->AddLocalizedString("pluginType", IDS_PLUGINS_TYPE); 74 source->AddLocalizedString("pluginType", IDS_PLUGINS_TYPE);
73 source->AddLocalizedString("pluginMimeTypes", IDS_PLUGINS_MIME_TYPES); 75 source->AddLocalizedString("pluginMimeTypes", IDS_PLUGINS_MIME_TYPES);
74 source->AddLocalizedString("pluginMimeTypesMimeType", 76 source->AddLocalizedString("pluginMimeTypesMimeType",
75 IDS_PLUGINS_MIME_TYPES_MIME_TYPE); 77 IDS_PLUGINS_MIME_TYPES_MIME_TYPE);
76 source->AddLocalizedString("pluginMimeTypesDescription", 78 source->AddLocalizedString("pluginMimeTypesDescription",
77 IDS_PLUGINS_MIME_TYPES_DESCRIPTION); 79 IDS_PLUGINS_MIME_TYPES_DESCRIPTION);
78 source->AddLocalizedString("pluginMimeTypesFileExtensions", 80 source->AddLocalizedString("pluginMimeTypesFileExtensions",
79 IDS_PLUGINS_MIME_TYPES_FILE_EXTENSIONS); 81 IDS_PLUGINS_MIME_TYPES_FILE_EXTENSIONS);
80 source->AddLocalizedString("disable", IDS_PLUGINS_DISABLE); 82 source->AddLocalizedString("disable", IDS_PLUGINS_DISABLE);
81 source->AddLocalizedString("enable", IDS_PLUGINS_ENABLE); 83 source->AddLocalizedString("enable", IDS_PLUGINS_ENABLE);
84 source->AddLocalizedString("alwaysAllowed", IDS_EXCEPTIONS_ALLOW_BUTTON);
82 source->AddLocalizedString("noPlugins", IDS_PLUGINS_NO_PLUGINS); 85 source->AddLocalizedString("noPlugins", IDS_PLUGINS_NO_PLUGINS);
83 86
84 source->set_json_path("strings.js"); 87 source->set_json_path("strings.js");
85 source->add_resource_path("plugins.js", IDR_PLUGINS_JS); 88 source->add_resource_path("plugins.js", IDR_PLUGINS_JS);
86 source->set_default_resource(IDR_PLUGINS_HTML); 89 source->set_default_resource(IDR_PLUGINS_HTML);
87 return source; 90 return source;
88 } 91 }
89 92
90 string16 PluginTypeToString(int type) { 93 string16 PluginTypeToString(int type) {
91 // The type is stored as an |int|, but doing the switch on the right 94 // The type is stored as an |int|, but doing the switch on the right
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 132
130 // Callback for the "enablePlugin" message. 133 // Callback for the "enablePlugin" message.
131 void HandleEnablePluginMessage(const ListValue* args); 134 void HandleEnablePluginMessage(const ListValue* args);
132 135
133 // Callback for the "saveShowDetailsToPrefs" message. 136 // Callback for the "saveShowDetailsToPrefs" message.
134 void HandleSaveShowDetailsToPrefs(const ListValue* args); 137 void HandleSaveShowDetailsToPrefs(const ListValue* args);
135 138
136 // Calback for the "getShowDetails" message. 139 // Calback for the "getShowDetails" message.
137 void HandleGetShowDetails(const ListValue* args); 140 void HandleGetShowDetails(const ListValue* args);
138 141
142 // Callback for the "setPluginAlwaysAllowed" message.
143 void HandleSetPluginAlwaysAllowed(const ListValue* args);
144
139 // content::NotificationObserver method overrides 145 // content::NotificationObserver method overrides
140 virtual void Observe(int type, 146 virtual void Observe(int type,
141 const content::NotificationSource& source, 147 const content::NotificationSource& source,
142 const content::NotificationDetails& details) OVERRIDE; 148 const content::NotificationDetails& details) OVERRIDE;
143 149
144 private: 150 private:
145 // Call this to start getting the plugins on the UI thread. 151 // Call this to start getting the plugins on the UI thread.
146 void LoadPlugins(); 152 void LoadPlugins();
147 153
148 // Called on the UI thread when the plugin information is ready. 154 // Called on the UI thread when the plugin information is ready.
(...skipping 23 matching lines...) Expand all
172 registrar_.Add(this, 178 registrar_.Add(this,
173 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, 179 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED,
174 content::Source<Profile>(profile)); 180 content::Source<Profile>(profile));
175 181
176 web_ui()->RegisterMessageCallback("requestPluginsData", 182 web_ui()->RegisterMessageCallback("requestPluginsData",
177 base::Bind(&PluginsDOMHandler::HandleRequestPluginsData, 183 base::Bind(&PluginsDOMHandler::HandleRequestPluginsData,
178 base::Unretained(this))); 184 base::Unretained(this)));
179 web_ui()->RegisterMessageCallback("enablePlugin", 185 web_ui()->RegisterMessageCallback("enablePlugin",
180 base::Bind(&PluginsDOMHandler::HandleEnablePluginMessage, 186 base::Bind(&PluginsDOMHandler::HandleEnablePluginMessage,
181 base::Unretained(this))); 187 base::Unretained(this)));
188 web_ui()->RegisterMessageCallback("setPluginAlwaysAllowed",
189 base::Bind(&PluginsDOMHandler::HandleSetPluginAlwaysAllowed,
190 base::Unretained(this)));
182 web_ui()->RegisterMessageCallback("saveShowDetailsToPrefs", 191 web_ui()->RegisterMessageCallback("saveShowDetailsToPrefs",
183 base::Bind(&PluginsDOMHandler::HandleSaveShowDetailsToPrefs, 192 base::Bind(&PluginsDOMHandler::HandleSaveShowDetailsToPrefs,
184 base::Unretained(this))); 193 base::Unretained(this)));
185 web_ui()->RegisterMessageCallback("getShowDetails", 194 web_ui()->RegisterMessageCallback("getShowDetails",
186 base::Bind(&PluginsDOMHandler::HandleGetShowDetails, 195 base::Bind(&PluginsDOMHandler::HandleGetShowDetails,
187 base::Unretained(this))); 196 base::Unretained(this)));
188 } 197 }
189 198
190 void PluginsDOMHandler::HandleRequestPluginsData(const ListValue* args) { 199 void PluginsDOMHandler::HandleRequestPluginsData(const ListValue* args) {
191 LoadPlugins(); 200 LoadPlugins();
192 } 201 }
193 202
194 void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) { 203 void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) {
195 Profile* profile = Profile::FromWebUI(web_ui()); 204 Profile* profile = Profile::FromWebUI(web_ui());
196 205
197 // Be robust in accepting badness since plug-ins display HTML (hence 206 // Be robust in accepting badness since plug-ins display HTML (hence
198 // JavaScript). 207 // JavaScript).
199 if (args->GetSize() != 3) 208 if (args->GetSize() != 3) {
209 NOTREACHED();
200 return; 210 return;
211 }
201 212
202 std::string enable_str; 213 std::string enable_str;
203 std::string is_group_str; 214 std::string is_group_str;
204 if (!args->GetString(1, &enable_str) || !args->GetString(2, &is_group_str)) 215 if (!args->GetString(1, &enable_str) || !args->GetString(2, &is_group_str)) {
216 NOTREACHED();
205 return; 217 return;
218 }
206 bool enable = enable_str == "true"; 219 bool enable = enable_str == "true";
207 220
208 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); 221 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile);
209 if (is_group_str == "true") { 222 if (is_group_str == "true") {
210 string16 group_name; 223 string16 group_name;
211 if (!args->GetString(0, &group_name)) 224 if (!args->GetString(0, &group_name)) {
225 NOTREACHED();
212 return; 226 return;
227 }
213 228
214 plugin_prefs->EnablePluginGroup(enable, group_name); 229 plugin_prefs->EnablePluginGroup(enable, group_name);
215 if (enable) { 230 if (enable) {
216 // See http://crbug.com/50105 for background. 231 // See http://crbug.com/50105 for background.
217 string16 adobereader = ASCIIToUTF16( 232 string16 adobereader = ASCIIToUTF16(
218 PluginGroup::kAdobeReaderGroupName); 233 PluginGroup::kAdobeReaderGroupName);
219 string16 internalpdf = 234 string16 internalpdf =
220 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName); 235 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName);
221 if (group_name == adobereader) 236 if (group_name == adobereader)
222 plugin_prefs->EnablePluginGroup(false, internalpdf); 237 plugin_prefs->EnablePluginGroup(false, internalpdf);
223 else if (group_name == internalpdf) 238 else if (group_name == internalpdf)
224 plugin_prefs->EnablePluginGroup(false, adobereader); 239 plugin_prefs->EnablePluginGroup(false, adobereader);
225 } 240 }
226 } else { 241 } else {
227 FilePath::StringType file_path; 242 FilePath::StringType file_path;
228 if (!args->GetString(0, &file_path)) 243 if (!args->GetString(0, &file_path)) {
244 NOTREACHED();
229 return; 245 return;
246 }
230 bool result = plugin_prefs->EnablePlugin(enable, FilePath(file_path)); 247 bool result = plugin_prefs->EnablePlugin(enable, FilePath(file_path));
231 DCHECK(result); 248 DCHECK(result);
232 } 249 }
233 } 250 }
234 251
235 void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) { 252 void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) {
236 std::string details_mode; 253 std::string details_mode;
237 if (!args->GetString(0, &details_mode)) { 254 if (!args->GetString(0, &details_mode)) {
238 NOTREACHED(); 255 NOTREACHED();
239 return; 256 return;
240 } 257 }
241 show_details_.SetValue(details_mode == "true"); 258 show_details_.SetValue(details_mode == "true");
242 } 259 }
243 260
244 void PluginsDOMHandler::HandleGetShowDetails(const ListValue* args) { 261 void PluginsDOMHandler::HandleGetShowDetails(const ListValue* args) {
245 base::FundamentalValue show_details(show_details_.GetValue()); 262 base::FundamentalValue show_details(show_details_.GetValue());
246 web_ui()->CallJavascriptFunction("loadShowDetailsFromPrefs", show_details); 263 web_ui()->CallJavascriptFunction("loadShowDetailsFromPrefs", show_details);
247 } 264 }
248 265
266 void PluginsDOMHandler::HandleSetPluginAlwaysAllowed(const ListValue* args) {
267 // Be robust in the input parameters, but crash in a Debug build.
268 if (args->GetSize() != 2) {
269 NOTREACHED();
270 return;
271 }
272
273 std::string plugin;
274 bool allowed = false;
275 if (!args->GetString(0, &plugin) || !args->GetBoolean(1, &allowed)) {
276 NOTREACHED();
277 return;
278 }
279 Profile* profile = Profile::FromWebUI(web_ui());
280 profile->GetHostContentSettingsMap()->SetContentSetting(
281 ContentSettingsPattern::Wildcard(),
282 ContentSettingsPattern::Wildcard(),
283 CONTENT_SETTINGS_TYPE_PLUGINS,
284 plugin,
285 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_DEFAULT);
286
287 // Keep track of the whitelist separately, so that we can distinguish plug-ins
288 // whitelisted by the user from automatically whitelisted ones.
289 DictionaryPrefUpdate update(profile->GetPrefs(),
290 prefs::kContentSettingsPluginWhitelist);
291 update->SetBoolean(plugin, allowed);
292 }
293
249 void PluginsDOMHandler::Observe(int type, 294 void PluginsDOMHandler::Observe(int type,
250 const content::NotificationSource& source, 295 const content::NotificationSource& source,
251 const content::NotificationDetails& details) { 296 const content::NotificationDetails& details) {
252 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); 297 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type);
253 LoadPlugins(); 298 LoadPlugins();
254 } 299 }
255 300
256 void PluginsDOMHandler::LoadPlugins() { 301 void PluginsDOMHandler::LoadPlugins() {
257 if (weak_ptr_factory_.HasWeakPtrs()) 302 if (weak_ptr_factory_.HasWeakPtrs())
258 return; 303 return;
259 304
260 PluginService::GetInstance()->GetPluginGroups( 305 PluginService::GetInstance()->GetPluginGroups(
261 base::Bind(&PluginsDOMHandler::PluginsLoaded, 306 base::Bind(&PluginsDOMHandler::PluginsLoaded,
262 weak_ptr_factory_.GetWeakPtr())); 307 weak_ptr_factory_.GetWeakPtr()));
263 } 308 }
264 309
265 void PluginsDOMHandler::PluginsLoaded(const std::vector<PluginGroup>& groups) { 310 void PluginsDOMHandler::PluginsLoaded(const std::vector<PluginGroup>& groups) {
311 Profile* profile = Profile::FromWebUI(web_ui());
266 PluginPrefs* plugin_prefs = 312 PluginPrefs* plugin_prefs =
267 PluginPrefs::GetForProfile(Profile::FromWebUI(web_ui())); 313 PluginPrefs::GetForProfile(profile);
314
315 HostContentSettingsMap* map = profile->GetHostContentSettingsMap();
316 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard();
268 317
269 // Construct DictionaryValues to return to the UI 318 // Construct DictionaryValues to return to the UI
270 ListValue* plugin_groups_data = new ListValue(); 319 ListValue* plugin_groups_data = new ListValue();
271 for (size_t i = 0; i < groups.size(); ++i) { 320 for (size_t i = 0; i < groups.size(); ++i) {
272 const PluginGroup& group = groups[i]; 321 const PluginGroup& group = groups[i];
273 if (group.IsEmpty()) 322 if (group.IsEmpty())
274 continue; 323 continue;
275 ListValue* plugin_files = new ListValue(); 324 ListValue* plugin_files = new ListValue();
276 string16 group_name = group.GetGroupName(); 325 string16 group_name = group.GetGroupName();
277 bool group_enabled = false; 326 bool group_enabled = false;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 } 385 }
337 } 386 }
338 plugin_file->SetString("enabledMode", enabled_mode); 387 plugin_file->SetString("enabledMode", enabled_mode);
339 388
340 plugin_files->Append(plugin_file); 389 plugin_files->Append(plugin_file);
341 } 390 }
342 DictionaryValue* group_data = new DictionaryValue(); 391 DictionaryValue* group_data = new DictionaryValue();
343 392
344 group_data->Set("plugin_files", plugin_files); 393 group_data->Set("plugin_files", plugin_files);
345 group_data->SetString("name", group_name); 394 group_data->SetString("name", group_name);
395 group_data->SetString("id", group.identifier());
346 group_data->SetString("description", active_plugin->desc); 396 group_data->SetString("description", active_plugin->desc);
347 group_data->SetString("version", active_plugin->version); 397 group_data->SetString("version", active_plugin->version);
348 group_data->SetBoolean("critical", group.IsVulnerable(*active_plugin)); 398 group_data->SetBoolean("critical", group.IsVulnerable(*active_plugin));
349 group_data->SetString("update_url", group.GetUpdateURL()); 399 group_data->SetString("update_url", group.GetUpdateURL());
350 400
351 std::string enabled_mode; 401 std::string enabled_mode;
352 if (all_plugins_enabled_by_policy) { 402 if (all_plugins_enabled_by_policy) {
353 enabled_mode = "enabledByPolicy"; 403 enabled_mode = "enabledByPolicy";
354 } else if (all_plugins_disabled_by_policy) { 404 } else if (all_plugins_disabled_by_policy) {
355 enabled_mode = "disabledByPolicy"; 405 enabled_mode = "disabledByPolicy";
356 } else if (group_enabled) { 406 } else if (group_enabled) {
357 enabled_mode = "enabledByUser"; 407 enabled_mode = "enabledByUser";
358 } else { 408 } else {
359 enabled_mode = "disabledByUser"; 409 enabled_mode = "disabledByUser";
360 } 410 }
361 group_data->SetString("enabledMode", enabled_mode); 411 group_data->SetString("enabledMode", enabled_mode);
362 412
413 // TODO(bauerb): We should have a method on HostContentSettinsMap for this.
414 bool always_allowed = false;
415 ContentSettingsForOneType settings;
416 map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_PLUGINS,
417 group.identifier(), &settings);
418 for (ContentSettingsForOneType::const_iterator it = settings.begin();
419 it != settings.end(); ++it) {
420 if (it->primary_pattern == wildcard &&
421 it->secondary_pattern == wildcard &&
422 it->setting == CONTENT_SETTING_ALLOW) {
423 always_allowed = true;
424 break;
425 }
426 }
427 group_data->SetBoolean("alwaysAllowed", always_allowed);
428
363 plugin_groups_data->Append(group_data); 429 plugin_groups_data->Append(group_data);
364 } 430 }
365 DictionaryValue results; 431 DictionaryValue results;
366 results.Set("plugins", plugin_groups_data); 432 results.Set("plugins", plugin_groups_data);
367 web_ui()->CallJavascriptFunction("returnPluginsData", results); 433 web_ui()->CallJavascriptFunction("returnPluginsData", results);
368 } 434 }
369 435
370 } // namespace 436 } // namespace
371 437
372 /////////////////////////////////////////////////////////////////////////////// 438 ///////////////////////////////////////////////////////////////////////////////
373 // 439 //
374 // PluginsUI 440 // PluginsUI
375 // 441 //
376 /////////////////////////////////////////////////////////////////////////////// 442 ///////////////////////////////////////////////////////////////////////////////
377 443
378 PluginsUI::PluginsUI(content::WebUI* web_ui) : WebUIController(web_ui) { 444 PluginsUI::PluginsUI(content::WebUI* web_ui) : WebUIController(web_ui) {
379 web_ui->AddMessageHandler(new PluginsDOMHandler()); 445 web_ui->AddMessageHandler(new PluginsDOMHandler());
380 446
381 // Set up the chrome://plugins/ source. 447 // Set up the chrome://plugins/ source.
382 Profile* profile = Profile::FromWebUI(web_ui); 448 Profile* profile = Profile::FromWebUI(web_ui);
383 profile->GetChromeURLDataManager()->AddDataSource( 449 profile->GetChromeURLDataManager()->AddDataSource(
384 CreatePluginsUIHTMLSource()); 450 CreatePluginsUIHTMLSource());
385 } 451 }
386 452
387
388 // static 453 // static
389 RefCountedMemory* PluginsUI::GetFaviconResourceBytes() { 454 RefCountedMemory* PluginsUI::GetFaviconResourceBytes() {
390 return ResourceBundle::GetSharedInstance(). 455 return ResourceBundle::GetSharedInstance().
391 LoadDataResourceBytes(IDR_PLUGIN); 456 LoadDataResourceBytes(IDR_PLUGIN);
392 } 457 }
393 458
394 // static 459 // static
395 void PluginsUI::RegisterUserPrefs(PrefService* prefs) { 460 void PluginsUI::RegisterUserPrefs(PrefService* prefs) {
396 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, 461 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails,
397 false, 462 false,
398 PrefService::UNSYNCABLE_PREF); 463 PrefService::UNSYNCABLE_PREF);
399 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, 464 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar,
400 true, 465 true,
401 PrefService::UNSYNCABLE_PREF); 466 PrefService::UNSYNCABLE_PREF);
467 prefs->RegisterDictionaryPref(prefs::kContentSettingsPluginWhitelist,
468 PrefService::SYNCABLE_PREF);
402 } 469 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options2/content_settings_handler2.cc ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698