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

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

Issue 7848025: Store plug-in enabled/disabled state in PluginPrefs instead of WebPluginInfo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: indent Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 18 matching lines...) Expand all
29 #include "content/browser/browser_thread.h" 29 #include "content/browser/browser_thread.h"
30 #include "content/browser/tab_contents/tab_contents.h" 30 #include "content/browser/tab_contents/tab_contents.h"
31 #include "content/common/notification_service.h" 31 #include "content/common/notification_service.h"
32 #include "grit/browser_resources.h" 32 #include "grit/browser_resources.h"
33 #include "grit/generated_resources.h" 33 #include "grit/generated_resources.h"
34 #include "grit/theme_resources.h" 34 #include "grit/theme_resources.h"
35 #include "grit/theme_resources_standard.h" 35 #include "grit/theme_resources_standard.h"
36 #include "ui/base/resource/resource_bundle.h" 36 #include "ui/base/resource/resource_bundle.h"
37 #include "webkit/plugins/npapi/plugin_list.h" 37 #include "webkit/plugins/npapi/plugin_list.h"
38 38
39 using webkit::npapi::PluginGroup;
40 using webkit::WebPluginInfo;
41
39 namespace { 42 namespace {
40 43
41 ChromeWebUIDataSource* CreatePluginsUIHTMLSource(bool enable_controls) { 44 ChromeWebUIDataSource* CreatePluginsUIHTMLSource(bool enable_controls) {
42 ChromeWebUIDataSource* source = 45 ChromeWebUIDataSource* source =
43 new ChromeWebUIDataSource(chrome::kChromeUIPluginsHost); 46 new ChromeWebUIDataSource(chrome::kChromeUIPluginsHost);
44 47
45 source->AddLocalizedString("pluginsTitle", IDS_PLUGINS_TITLE); 48 source->AddLocalizedString("pluginsTitle", IDS_PLUGINS_TITLE);
46 source->AddLocalizedString("pluginsDetailsModeLink", 49 source->AddLocalizedString("pluginsDetailsModeLink",
47 IDS_PLUGINS_DETAILS_MODE_LINK); 50 IDS_PLUGINS_DETAILS_MODE_LINK);
48 source->AddLocalizedString("pluginsNoneInstalled", 51 source->AddLocalizedString("pluginsNoneInstalled",
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 void HandleGetShowDetails(const ListValue* args); 121 void HandleGetShowDetails(const ListValue* args);
119 122
120 // NotificationObserver method overrides 123 // NotificationObserver method overrides
121 virtual void Observe(int type, 124 virtual void Observe(int type,
122 const NotificationSource& source, 125 const NotificationSource& source,
123 const NotificationDetails& details) OVERRIDE; 126 const NotificationDetails& details) OVERRIDE;
124 127
125 private: 128 private:
126 // Loads the plugins on the FILE thread. 129 // Loads the plugins on the FILE thread.
127 static void LoadPluginsOnFileThread( 130 static void LoadPluginsOnFileThread(
128 std::vector<webkit::npapi::PluginGroup>* groups, Task* task); 131 std::vector<PluginGroup>* groups, Task* task);
129 132
130 // Used in conjunction with ListWrapper to avoid any memory leaks. 133 // Used in conjunction with ListWrapper to avoid any memory leaks.
131 static void EnsurePluginGroupsDeleted( 134 static void EnsurePluginGroupsDeleted(
132 std::vector<webkit::npapi::PluginGroup>* groups); 135 std::vector<PluginGroup>* groups);
133 136
134 // Call this to start getting the plugins on the UI thread. 137 // Call this to start getting the plugins on the UI thread.
135 void LoadPlugins(); 138 void LoadPlugins();
136 139
137 // Called on the UI thread when the plugin information is ready. 140 // Called on the UI thread when the plugin information is ready.
138 void PluginsLoaded(const std::vector<webkit::npapi::PluginGroup>* groups); 141 void PluginsLoaded(const std::vector<PluginGroup>* groups);
139 142
140 NotificationRegistrar registrar_; 143 NotificationRegistrar registrar_;
141 144
142 ScopedRunnableMethodFactory<PluginsDOMHandler> get_plugins_factory_; 145 ScopedRunnableMethodFactory<PluginsDOMHandler> get_plugins_factory_;
143 146
144 // This pref guards the value whether about:plugins is in the details mode or 147 // This pref guards the value whether about:plugins is in the details mode or
145 // not. 148 // not.
146 BooleanPrefMember show_details_; 149 BooleanPrefMember show_details_;
147 150
148 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler); 151 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler);
(...skipping 25 matching lines...) Expand all
174 NewCallback(this, &PluginsDOMHandler::HandleGetShowDetails)); 177 NewCallback(this, &PluginsDOMHandler::HandleGetShowDetails));
175 } 178 }
176 179
177 void PluginsDOMHandler::HandleRequestPluginsData(const ListValue* args) { 180 void PluginsDOMHandler::HandleRequestPluginsData(const ListValue* args) {
178 LoadPlugins(); 181 LoadPlugins();
179 } 182 }
180 183
181 void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) { 184 void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) {
182 Profile* profile = Profile::FromWebUI(web_ui_); 185 Profile* profile = Profile::FromWebUI(web_ui_);
183 186
184 // If a non-first-profile user tries to trigger these methods sneakily,
185 // forbid it.
186 #if !defined(OS_CHROMEOS)
187 if (!profile->GetOriginalProfile()->first_launched())
188 return;
189 #endif
190
191 // Be robust in accepting badness since plug-ins display HTML (hence 187 // Be robust in accepting badness since plug-ins display HTML (hence
192 // JavaScript). 188 // JavaScript).
193 if (args->GetSize() != 3) 189 if (args->GetSize() != 3)
194 return; 190 return;
195 191
196 std::string enable_str; 192 std::string enable_str;
197 std::string is_group_str; 193 std::string is_group_str;
198 if (!args->GetString(1, &enable_str) || !args->GetString(2, &is_group_str)) 194 if (!args->GetString(1, &enable_str) || !args->GetString(2, &is_group_str))
199 return; 195 return;
200 bool enable = enable_str == "true"; 196 bool enable = enable_str == "true";
201 197
202 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); 198 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile);
203 if (is_group_str == "true") { 199 if (is_group_str == "true") {
204 string16 group_name; 200 string16 group_name;
205 if (!args->GetString(0, &group_name)) 201 if (!args->GetString(0, &group_name))
206 return; 202 return;
207 203
208 plugin_prefs->EnablePluginGroup(enable, group_name); 204 BrowserThread::PostTask(
205 BrowserThread::FILE, FROM_HERE,
206 NewRunnableMethod(plugin_prefs, &PluginPrefs::EnablePluginGroup,
207 enable, group_name));
209 if (enable) { 208 if (enable) {
210 // See http://crbug.com/50105 for background. 209 // See http://crbug.com/50105 for background.
211 string16 adobereader = ASCIIToUTF16( 210 string16 adobereader = ASCIIToUTF16(
212 webkit::npapi::PluginGroup::kAdobeReaderGroupName); 211 PluginGroup::kAdobeReaderGroupName);
213 string16 internalpdf = 212 string16 internalpdf =
214 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName); 213 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName);
215 if (group_name == adobereader) { 214 if (group_name == adobereader) {
216 plugin_prefs->EnablePluginGroup(false, internalpdf); 215 BrowserThread::PostTask(
216 BrowserThread::FILE, FROM_HERE,
217 NewRunnableMethod(plugin_prefs, &PluginPrefs::EnablePluginGroup,
218 false, internalpdf));
217 } else if (group_name == internalpdf) { 219 } else if (group_name == internalpdf) {
218 plugin_prefs->EnablePluginGroup(false, adobereader); 220 BrowserThread::PostTask(
221 BrowserThread::FILE, FROM_HERE,
222 NewRunnableMethod(plugin_prefs, &PluginPrefs::EnablePluginGroup,
223 false, adobereader));
219 } 224 }
220 } 225 }
221 } else { 226 } else {
222 FilePath::StringType file_path; 227 FilePath::StringType file_path;
223 if (!args->GetString(0, &file_path)) 228 if (!args->GetString(0, &file_path))
224 return; 229 return;
225 230
226 plugin_prefs->EnablePlugin(enable, FilePath(file_path)); 231 BrowserThread::PostTask(
232 BrowserThread::FILE, FROM_HERE,
233 NewRunnableMethod(plugin_prefs, &PluginPrefs::EnablePlugin,
234 enable, FilePath(file_path)));
227 } 235 }
228
229 // TODO(viettrungluu): We might also want to ensure that the plugins
230 // list is always written to prefs even when the user hasn't disabled a
231 // plugin. <http://crbug.com/39101>
232 plugin_prefs->UpdatePreferences(0);
233 } 236 }
234 237
235 void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) { 238 void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) {
236 std::string details_mode; 239 std::string details_mode;
237 if (!args->GetString(0, &details_mode)) { 240 if (!args->GetString(0, &details_mode)) {
238 NOTREACHED(); 241 NOTREACHED();
239 return; 242 return;
240 } 243 }
241 show_details_.SetValue(details_mode == "true"); 244 show_details_.SetValue(details_mode == "true");
242 } 245 }
243 246
244 void PluginsDOMHandler::HandleGetShowDetails(const ListValue* args) { 247 void PluginsDOMHandler::HandleGetShowDetails(const ListValue* args) {
245 base::FundamentalValue show_details(show_details_.GetValue()); 248 base::FundamentalValue show_details(show_details_.GetValue());
246 web_ui_->CallJavascriptFunction("loadShowDetailsFromPrefs", show_details); 249 web_ui_->CallJavascriptFunction("loadShowDetailsFromPrefs", show_details);
247 } 250 }
248 251
249 void PluginsDOMHandler::Observe(int type, 252 void PluginsDOMHandler::Observe(int type,
250 const NotificationSource& source, 253 const NotificationSource& source,
251 const NotificationDetails& details) { 254 const NotificationDetails& details) {
252 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); 255 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type);
253 LoadPlugins(); 256 LoadPlugins();
254 } 257 }
255 258
256 void PluginsDOMHandler::LoadPluginsOnFileThread( 259 void PluginsDOMHandler::LoadPluginsOnFileThread(
257 std::vector<webkit::npapi::PluginGroup>* groups, 260 std::vector<PluginGroup>* groups,
258 Task* task) { 261 Task* task) {
259 webkit::npapi::PluginList::Singleton()->GetPluginGroups(true, groups); 262 webkit::npapi::PluginList::Singleton()->GetPluginGroups(true, groups);
260 263
261 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, task); 264 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, task);
262 BrowserThread::PostTask( 265 BrowserThread::PostTask(
263 BrowserThread::UI, 266 BrowserThread::UI,
264 FROM_HERE, 267 FROM_HERE,
265 NewRunnableFunction(&PluginsDOMHandler::EnsurePluginGroupsDeleted, 268 NewRunnableFunction(&PluginsDOMHandler::EnsurePluginGroupsDeleted,
266 groups)); 269 groups));
267 } 270 }
268 271
269 void PluginsDOMHandler::EnsurePluginGroupsDeleted( 272 void PluginsDOMHandler::EnsurePluginGroupsDeleted(
270 std::vector<webkit::npapi::PluginGroup>* groups) { 273 std::vector<PluginGroup>* groups) {
271 delete groups; 274 delete groups;
272 } 275 }
273 276
274 void PluginsDOMHandler::LoadPlugins() { 277 void PluginsDOMHandler::LoadPlugins() {
275 if (!get_plugins_factory_.empty()) 278 if (!get_plugins_factory_.empty())
276 return; 279 return;
277 280
278 std::vector<webkit::npapi::PluginGroup>* groups = 281 std::vector<PluginGroup>* groups = new std::vector<PluginGroup>;
279 new std::vector<webkit::npapi::PluginGroup>;
280 Task* task = get_plugins_factory_.NewRunnableMethod( 282 Task* task = get_plugins_factory_.NewRunnableMethod(
281 &PluginsDOMHandler::PluginsLoaded, groups); 283 &PluginsDOMHandler::PluginsLoaded, groups);
282 284
283 BrowserThread::PostTask( 285 BrowserThread::PostTask(
284 BrowserThread::FILE, 286 BrowserThread::FILE,
285 FROM_HERE, 287 FROM_HERE,
286 NewRunnableFunction( 288 NewRunnableFunction(
287 &PluginsDOMHandler::LoadPluginsOnFileThread, groups, task)); 289 &PluginsDOMHandler::LoadPluginsOnFileThread, groups, task));
288 } 290 }
289 291
290 void PluginsDOMHandler::PluginsLoaded( 292 void PluginsDOMHandler::PluginsLoaded(const std::vector<PluginGroup>* groups) {
291 const std::vector<webkit::npapi::PluginGroup>* groups) { 293 PluginPrefs* plugin_prefs =
294 PluginPrefs::GetForProfile(Profile::FromWebUI(web_ui_));
295
296 bool all_plugins_enabled_by_policy = true;
297 bool all_plugins_disabled_by_policy = true;
298
292 // Construct DictionaryValues to return to the UI 299 // Construct DictionaryValues to return to the UI
293 ListValue* plugin_groups_data = new ListValue(); 300 ListValue* plugin_groups_data = new ListValue();
294 for (size_t i = 0; i < groups->size(); ++i) { 301 for (size_t i = 0; i < groups->size(); ++i) {
295 plugin_groups_data->Append((*groups)[i].GetDataForUI()); 302 ListValue* plugin_files = new ListValue();
296 // TODO(bauerb): Fetch plugin enabled state from PluginPrefs. 303 const PluginGroup& group = (*groups)[i];
304 string16 group_name = group.GetGroupName();
305 bool group_enabled = false;
306 const WebPluginInfo* active_plugin = NULL;
307 for (size_t j = 0; j < group.web_plugin_infos().size(); ++j) {
308 const WebPluginInfo& group_plugin = group.web_plugin_infos()[j];
309
310 DictionaryValue* plugin_file = new DictionaryValue();
311 plugin_file->SetString("name", group_plugin.name);
312 plugin_file->SetString("description", group_plugin.desc);
313 plugin_file->SetString("path", group_plugin.path.value());
314 plugin_file->SetString("version", group_plugin.version);
315
316 ListValue* mime_types = new ListValue();
317 const std::vector<webkit::WebPluginMimeType>& plugin_mime_types =
318 group_plugin.mime_types;
319 for (size_t k = 0; k < plugin_mime_types.size(); ++k) {
320 DictionaryValue* mime_type = new DictionaryValue();
321 mime_type->SetString("mimeType", plugin_mime_types[k].mime_type);
322 mime_type->SetString("description", plugin_mime_types[k].description);
323
324 ListValue* file_extensions = new ListValue();
325 const std::vector<std::string>& mime_file_extensions =
326 plugin_mime_types[k].file_extensions;
327 for (size_t l = 0; l < mime_file_extensions.size(); ++l)
328 file_extensions->Append(new StringValue(mime_file_extensions[l]));
329 mime_type->Set("fileExtensions", file_extensions);
330
331 mime_types->Append(mime_type);
332 }
333 plugin_file->Set("mimeTypes", mime_types);
334
335 bool plugin_enabled = plugin_prefs->IsPluginEnabled(group_plugin);
336
337 if (!active_plugin || (plugin_enabled && !group_enabled))
338 active_plugin = &group_plugin;
339 group_enabled = plugin_enabled || group_enabled;
340
341 std::string enabled_mode;
342 PluginPrefs::PolicyStatus plugin_status =
343 plugin_prefs->PolicyStatusForPlugin(group_plugin.name);
344 PluginPrefs::PolicyStatus group_status =
345 plugin_prefs->PolicyStatusForPlugin(group_name);
346 if (plugin_status == PluginPrefs::POLICY_ENABLED ||
347 group_status == PluginPrefs::POLICY_ENABLED) {
348 enabled_mode = "enabledByPolicy";
349 } else {
350 all_plugins_enabled_by_policy = false;
351 if (plugin_status == PluginPrefs::POLICY_DISABLED ||
352 group_status == PluginPrefs::POLICY_DISABLED) {
353 enabled_mode = "disabledByPolicy";
354 } else {
355 all_plugins_disabled_by_policy = false;
356 if (plugin_enabled) {
357 enabled_mode = "enabledByUser";
358 } else {
359 enabled_mode = "disabledByUser";
360 }
361 }
362 }
363 plugin_file->SetString("enabledMode", enabled_mode);
364
365 plugin_files->Append(plugin_file);
366 }
367 DictionaryValue* group_data = new DictionaryValue();
368
369 group_data->Set("plugin_files", plugin_files);
370 group_data->SetString("name", group_name);
371 group_data->SetString("description", active_plugin->desc);
372 group_data->SetString("version", active_plugin->version);
373 group_data->SetBoolean("critical", group.IsVulnerable(*active_plugin));
374 group_data->SetString("update_url", group.GetUpdateURL());
375
376 std::string enabled_mode;
377 if (all_plugins_enabled_by_policy) {
378 enabled_mode = "enabledByPolicy";
379 } else if (all_plugins_disabled_by_policy) {
380 enabled_mode = "disabledByPolicy";
381 } else if (group_enabled) {
382 enabled_mode = "enabledByUser";
383 } else {
384 enabled_mode = "disabledByUser";
385 }
386 group_data->SetString("enabledMode", enabled_mode);
387
388 plugin_groups_data->Append(group_data);
297 } 389 }
298 DictionaryValue results; 390 DictionaryValue results;
299 results.Set("plugins", plugin_groups_data); 391 results.Set("plugins", plugin_groups_data);
300 web_ui_->CallJavascriptFunction("returnPluginsData", results); 392 web_ui_->CallJavascriptFunction("returnPluginsData", results);
301 } 393 }
302 394
303 } // namespace 395 } // namespace
304 396
305 /////////////////////////////////////////////////////////////////////////////// 397 ///////////////////////////////////////////////////////////////////////////////
306 // 398 //
307 // PluginsUI 399 // PluginsUI
308 // 400 //
309 /////////////////////////////////////////////////////////////////////////////// 401 ///////////////////////////////////////////////////////////////////////////////
310 402
311 PluginsUI::PluginsUI(TabContents* contents) : ChromeWebUI(contents) { 403 PluginsUI::PluginsUI(TabContents* contents) : ChromeWebUI(contents) {
312 AddMessageHandler((new PluginsDOMHandler())->Attach(this)); 404 AddMessageHandler((new PluginsDOMHandler())->Attach(this));
313 405
314 // Set up the chrome://plugins/ source. 406 // Set up the chrome://plugins/ source.
407 // TODO(bauerb): Remove |enabled_controls| & co.
Joao da Silva 2011/09/13 09:30:48 Nit: |enable_controls|
Bernhard Bauer 2011/09/13 12:13:01 Done.
315 bool enable_controls = true; 408 bool enable_controls = true;
316 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); 409 Profile* profile = Profile::FromBrowserContext(contents->browser_context());
317 #if !defined(OS_CHROMEOS)
318 enable_controls = profile->GetOriginalProfile()->first_launched();
319 #endif
320 profile->GetChromeURLDataManager()->AddDataSource( 410 profile->GetChromeURLDataManager()->AddDataSource(
321 CreatePluginsUIHTMLSource(enable_controls)); 411 CreatePluginsUIHTMLSource(enable_controls));
322 } 412 }
323 413
324 414
325 // static 415 // static
326 RefCountedMemory* PluginsUI::GetFaviconResourceBytes() { 416 RefCountedMemory* PluginsUI::GetFaviconResourceBytes() {
327 return ResourceBundle::GetSharedInstance(). 417 return ResourceBundle::GetSharedInstance().
328 LoadDataResourceBytes(IDR_PLUGIN); 418 LoadDataResourceBytes(IDR_PLUGIN);
329 } 419 }
330 420
331 // static 421 // static
332 void PluginsUI::RegisterUserPrefs(PrefService* prefs) { 422 void PluginsUI::RegisterUserPrefs(PrefService* prefs) {
333 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, 423 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails,
334 false, 424 false,
335 PrefService::UNSYNCABLE_PREF); 425 PrefService::UNSYNCABLE_PREF);
336 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, 426 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar,
337 true, 427 true,
338 PrefService::UNSYNCABLE_PREF); 428 PrefService::UNSYNCABLE_PREF);
339 } 429 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698