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

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: copyright 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
« no previous file with comments | « chrome/browser/printing/print_preview_tab_controller.cc ('k') | chrome/chrome_tests.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) 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 plugin_prefs->EnablePluginGroup(enable, group_name);
209 if (enable) { 205 if (enable) {
210 // See http://crbug.com/50105 for background. 206 // See http://crbug.com/50105 for background.
211 string16 adobereader = ASCIIToUTF16( 207 string16 adobereader = ASCIIToUTF16(
212 webkit::npapi::PluginGroup::kAdobeReaderGroupName); 208 PluginGroup::kAdobeReaderGroupName);
213 string16 internalpdf = 209 string16 internalpdf =
214 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName); 210 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName);
215 if (group_name == adobereader) { 211 if (group_name == adobereader)
216 plugin_prefs->EnablePluginGroup(false, internalpdf); 212 plugin_prefs->EnablePluginGroup(false, internalpdf);
217 } else if (group_name == internalpdf) { 213 else if (group_name == internalpdf)
218 plugin_prefs->EnablePluginGroup(false, adobereader); 214 plugin_prefs->EnablePluginGroup(false, adobereader);
219 }
220 } 215 }
221 } else { 216 } else {
222 FilePath::StringType file_path; 217 FilePath::StringType file_path;
223 if (!args->GetString(0, &file_path)) 218 if (!args->GetString(0, &file_path))
224 return; 219 return;
225
226 plugin_prefs->EnablePlugin(enable, FilePath(file_path)); 220 plugin_prefs->EnablePlugin(enable, FilePath(file_path));
227 } 221 }
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 } 222 }
234 223
235 void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) { 224 void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) {
236 std::string details_mode; 225 std::string details_mode;
237 if (!args->GetString(0, &details_mode)) { 226 if (!args->GetString(0, &details_mode)) {
238 NOTREACHED(); 227 NOTREACHED();
239 return; 228 return;
240 } 229 }
241 show_details_.SetValue(details_mode == "true"); 230 show_details_.SetValue(details_mode == "true");
242 } 231 }
243 232
244 void PluginsDOMHandler::HandleGetShowDetails(const ListValue* args) { 233 void PluginsDOMHandler::HandleGetShowDetails(const ListValue* args) {
245 base::FundamentalValue show_details(show_details_.GetValue()); 234 base::FundamentalValue show_details(show_details_.GetValue());
246 web_ui_->CallJavascriptFunction("loadShowDetailsFromPrefs", show_details); 235 web_ui_->CallJavascriptFunction("loadShowDetailsFromPrefs", show_details);
247 } 236 }
248 237
249 void PluginsDOMHandler::Observe(int type, 238 void PluginsDOMHandler::Observe(int type,
250 const NotificationSource& source, 239 const NotificationSource& source,
251 const NotificationDetails& details) { 240 const NotificationDetails& details) {
252 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); 241 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type);
253 LoadPlugins(); 242 LoadPlugins();
254 } 243 }
255 244
256 void PluginsDOMHandler::LoadPluginsOnFileThread( 245 void PluginsDOMHandler::LoadPluginsOnFileThread(
257 std::vector<webkit::npapi::PluginGroup>* groups, 246 std::vector<PluginGroup>* groups,
258 Task* task) { 247 Task* task) {
259 webkit::npapi::PluginList::Singleton()->GetPluginGroups(true, groups); 248 webkit::npapi::PluginList::Singleton()->GetPluginGroups(true, groups);
260 249
261 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, task); 250 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, task);
262 BrowserThread::PostTask( 251 BrowserThread::PostTask(
263 BrowserThread::UI, 252 BrowserThread::UI,
264 FROM_HERE, 253 FROM_HERE,
265 NewRunnableFunction(&PluginsDOMHandler::EnsurePluginGroupsDeleted, 254 NewRunnableFunction(&PluginsDOMHandler::EnsurePluginGroupsDeleted,
266 groups)); 255 groups));
267 } 256 }
268 257
269 void PluginsDOMHandler::EnsurePluginGroupsDeleted( 258 void PluginsDOMHandler::EnsurePluginGroupsDeleted(
270 std::vector<webkit::npapi::PluginGroup>* groups) { 259 std::vector<PluginGroup>* groups) {
271 delete groups; 260 delete groups;
272 } 261 }
273 262
274 void PluginsDOMHandler::LoadPlugins() { 263 void PluginsDOMHandler::LoadPlugins() {
275 if (!get_plugins_factory_.empty()) 264 if (!get_plugins_factory_.empty())
276 return; 265 return;
277 266
278 std::vector<webkit::npapi::PluginGroup>* groups = 267 std::vector<PluginGroup>* groups = new std::vector<PluginGroup>;
279 new std::vector<webkit::npapi::PluginGroup>;
280 Task* task = get_plugins_factory_.NewRunnableMethod( 268 Task* task = get_plugins_factory_.NewRunnableMethod(
281 &PluginsDOMHandler::PluginsLoaded, groups); 269 &PluginsDOMHandler::PluginsLoaded, groups);
282 270
283 BrowserThread::PostTask( 271 BrowserThread::PostTask(
284 BrowserThread::FILE, 272 BrowserThread::FILE,
285 FROM_HERE, 273 FROM_HERE,
286 NewRunnableFunction( 274 NewRunnableFunction(
287 &PluginsDOMHandler::LoadPluginsOnFileThread, groups, task)); 275 &PluginsDOMHandler::LoadPluginsOnFileThread, groups, task));
288 } 276 }
289 277
290 void PluginsDOMHandler::PluginsLoaded( 278 void PluginsDOMHandler::PluginsLoaded(const std::vector<PluginGroup>* groups) {
291 const std::vector<webkit::npapi::PluginGroup>* groups) { 279 PluginPrefs* plugin_prefs =
280 PluginPrefs::GetForProfile(Profile::FromWebUI(web_ui_));
281
282 bool all_plugins_enabled_by_policy = true;
283 bool all_plugins_disabled_by_policy = true;
284
292 // Construct DictionaryValues to return to the UI 285 // Construct DictionaryValues to return to the UI
293 ListValue* plugin_groups_data = new ListValue(); 286 ListValue* plugin_groups_data = new ListValue();
294 for (size_t i = 0; i < groups->size(); ++i) { 287 for (size_t i = 0; i < groups->size(); ++i) {
295 plugin_groups_data->Append((*groups)[i].GetDataForUI()); 288 ListValue* plugin_files = new ListValue();
296 // TODO(bauerb): Fetch plugin enabled state from PluginPrefs. 289 const PluginGroup& group = (*groups)[i];
290 string16 group_name = group.GetGroupName();
291 bool group_enabled = false;
292 const WebPluginInfo* active_plugin = NULL;
293 for (size_t j = 0; j < group.web_plugin_infos().size(); ++j) {
294 const WebPluginInfo& group_plugin = group.web_plugin_infos()[j];
295
296 DictionaryValue* plugin_file = new DictionaryValue();
297 plugin_file->SetString("name", group_plugin.name);
298 plugin_file->SetString("description", group_plugin.desc);
299 plugin_file->SetString("path", group_plugin.path.value());
300 plugin_file->SetString("version", group_plugin.version);
301
302 ListValue* mime_types = new ListValue();
303 const std::vector<webkit::WebPluginMimeType>& plugin_mime_types =
304 group_plugin.mime_types;
305 for (size_t k = 0; k < plugin_mime_types.size(); ++k) {
306 DictionaryValue* mime_type = new DictionaryValue();
307 mime_type->SetString("mimeType", plugin_mime_types[k].mime_type);
308 mime_type->SetString("description", plugin_mime_types[k].description);
309
310 ListValue* file_extensions = new ListValue();
311 const std::vector<std::string>& mime_file_extensions =
312 plugin_mime_types[k].file_extensions;
313 for (size_t l = 0; l < mime_file_extensions.size(); ++l)
314 file_extensions->Append(new StringValue(mime_file_extensions[l]));
315 mime_type->Set("fileExtensions", file_extensions);
316
317 mime_types->Append(mime_type);
318 }
319 plugin_file->Set("mimeTypes", mime_types);
320
321 bool plugin_enabled = plugin_prefs->IsPluginEnabled(group_plugin);
322
323 if (!active_plugin || (plugin_enabled && !group_enabled))
324 active_plugin = &group_plugin;
325 group_enabled = plugin_enabled || group_enabled;
326
327 std::string enabled_mode;
328 PluginPrefs::PolicyStatus plugin_status =
329 plugin_prefs->PolicyStatusForPlugin(group_plugin.name);
330 PluginPrefs::PolicyStatus group_status =
331 plugin_prefs->PolicyStatusForPlugin(group_name);
332 if (plugin_status == PluginPrefs::POLICY_ENABLED ||
333 group_status == PluginPrefs::POLICY_ENABLED) {
334 enabled_mode = "enabledByPolicy";
335 } else {
336 all_plugins_enabled_by_policy = false;
337 if (plugin_status == PluginPrefs::POLICY_DISABLED ||
338 group_status == PluginPrefs::POLICY_DISABLED) {
339 enabled_mode = "disabledByPolicy";
340 } else {
341 all_plugins_disabled_by_policy = false;
342 if (plugin_enabled) {
343 enabled_mode = "enabledByUser";
344 } else {
345 enabled_mode = "disabledByUser";
346 }
347 }
348 }
349 plugin_file->SetString("enabledMode", enabled_mode);
350
351 plugin_files->Append(plugin_file);
352 }
353 DictionaryValue* group_data = new DictionaryValue();
354
355 group_data->Set("plugin_files", plugin_files);
356 group_data->SetString("name", group_name);
357 group_data->SetString("description", active_plugin->desc);
358 group_data->SetString("version", active_plugin->version);
359 group_data->SetBoolean("critical", group.IsVulnerable(*active_plugin));
360 group_data->SetString("update_url", group.GetUpdateURL());
361
362 std::string enabled_mode;
363 if (all_plugins_enabled_by_policy) {
364 enabled_mode = "enabledByPolicy";
365 } else if (all_plugins_disabled_by_policy) {
366 enabled_mode = "disabledByPolicy";
367 } else if (group_enabled) {
368 enabled_mode = "enabledByUser";
369 } else {
370 enabled_mode = "disabledByUser";
371 }
372 group_data->SetString("enabledMode", enabled_mode);
373
374 plugin_groups_data->Append(group_data);
297 } 375 }
298 DictionaryValue results; 376 DictionaryValue results;
299 results.Set("plugins", plugin_groups_data); 377 results.Set("plugins", plugin_groups_data);
300 web_ui_->CallJavascriptFunction("returnPluginsData", results); 378 web_ui_->CallJavascriptFunction("returnPluginsData", results);
301 } 379 }
302 380
303 } // namespace 381 } // namespace
304 382
305 /////////////////////////////////////////////////////////////////////////////// 383 ///////////////////////////////////////////////////////////////////////////////
306 // 384 //
307 // PluginsUI 385 // PluginsUI
308 // 386 //
309 /////////////////////////////////////////////////////////////////////////////// 387 ///////////////////////////////////////////////////////////////////////////////
310 388
311 PluginsUI::PluginsUI(TabContents* contents) : ChromeWebUI(contents) { 389 PluginsUI::PluginsUI(TabContents* contents) : ChromeWebUI(contents) {
312 AddMessageHandler((new PluginsDOMHandler())->Attach(this)); 390 AddMessageHandler((new PluginsDOMHandler())->Attach(this));
313 391
314 // Set up the chrome://plugins/ source. 392 // Set up the chrome://plugins/ source.
393 // TODO(bauerb): Remove |enable_controls| & co.
315 bool enable_controls = true; 394 bool enable_controls = true;
316 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); 395 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( 396 profile->GetChromeURLDataManager()->AddDataSource(
321 CreatePluginsUIHTMLSource(enable_controls)); 397 CreatePluginsUIHTMLSource(enable_controls));
322 } 398 }
323 399
324 400
325 // static 401 // static
326 RefCountedMemory* PluginsUI::GetFaviconResourceBytes() { 402 RefCountedMemory* PluginsUI::GetFaviconResourceBytes() {
327 return ResourceBundle::GetSharedInstance(). 403 return ResourceBundle::GetSharedInstance().
328 LoadDataResourceBytes(IDR_PLUGIN); 404 LoadDataResourceBytes(IDR_PLUGIN);
329 } 405 }
330 406
331 // static 407 // static
332 void PluginsUI::RegisterUserPrefs(PrefService* prefs) { 408 void PluginsUI::RegisterUserPrefs(PrefService* prefs) {
333 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, 409 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails,
334 false, 410 false,
335 PrefService::UNSYNCABLE_PREF); 411 PrefService::UNSYNCABLE_PREF);
336 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, 412 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar,
337 true, 413 true,
338 PrefService::UNSYNCABLE_PREF); 414 PrefService::UNSYNCABLE_PREF);
339 } 415 }
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_preview_tab_controller.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698