OLD | NEW |
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 Loading... |
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 | |
42 namespace { | 39 namespace { |
43 | 40 |
44 ChromeWebUIDataSource* CreatePluginsUIHTMLSource(bool enable_controls) { | 41 ChromeWebUIDataSource* CreatePluginsUIHTMLSource(bool enable_controls) { |
45 ChromeWebUIDataSource* source = | 42 ChromeWebUIDataSource* source = |
46 new ChromeWebUIDataSource(chrome::kChromeUIPluginsHost); | 43 new ChromeWebUIDataSource(chrome::kChromeUIPluginsHost); |
47 | 44 |
48 source->AddLocalizedString("pluginsTitle", IDS_PLUGINS_TITLE); | 45 source->AddLocalizedString("pluginsTitle", IDS_PLUGINS_TITLE); |
49 source->AddLocalizedString("pluginsDetailsModeLink", | 46 source->AddLocalizedString("pluginsDetailsModeLink", |
50 IDS_PLUGINS_DETAILS_MODE_LINK); | 47 IDS_PLUGINS_DETAILS_MODE_LINK); |
51 source->AddLocalizedString("pluginsNoneInstalled", | 48 source->AddLocalizedString("pluginsNoneInstalled", |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 void HandleGetShowDetails(const ListValue* args); | 118 void HandleGetShowDetails(const ListValue* args); |
122 | 119 |
123 // NotificationObserver method overrides | 120 // NotificationObserver method overrides |
124 virtual void Observe(int type, | 121 virtual void Observe(int type, |
125 const NotificationSource& source, | 122 const NotificationSource& source, |
126 const NotificationDetails& details) OVERRIDE; | 123 const NotificationDetails& details) OVERRIDE; |
127 | 124 |
128 private: | 125 private: |
129 // Loads the plugins on the FILE thread. | 126 // Loads the plugins on the FILE thread. |
130 static void LoadPluginsOnFileThread( | 127 static void LoadPluginsOnFileThread( |
131 std::vector<PluginGroup>* groups, Task* task); | 128 std::vector<webkit::npapi::PluginGroup>* groups, Task* task); |
132 | 129 |
133 // Used in conjunction with ListWrapper to avoid any memory leaks. | 130 // Used in conjunction with ListWrapper to avoid any memory leaks. |
134 static void EnsurePluginGroupsDeleted( | 131 static void EnsurePluginGroupsDeleted( |
135 std::vector<PluginGroup>* groups); | 132 std::vector<webkit::npapi::PluginGroup>* groups); |
136 | 133 |
137 // Call this to start getting the plugins on the UI thread. | 134 // Call this to start getting the plugins on the UI thread. |
138 void LoadPlugins(); | 135 void LoadPlugins(); |
139 | 136 |
140 // Called on the UI thread when the plugin information is ready. | 137 // Called on the UI thread when the plugin information is ready. |
141 void PluginsLoaded(const std::vector<PluginGroup>* groups); | 138 void PluginsLoaded(const std::vector<webkit::npapi::PluginGroup>* groups); |
142 | 139 |
143 NotificationRegistrar registrar_; | 140 NotificationRegistrar registrar_; |
144 | 141 |
145 ScopedRunnableMethodFactory<PluginsDOMHandler> get_plugins_factory_; | 142 ScopedRunnableMethodFactory<PluginsDOMHandler> get_plugins_factory_; |
146 | 143 |
147 // This pref guards the value whether about:plugins is in the details mode or | 144 // This pref guards the value whether about:plugins is in the details mode or |
148 // not. | 145 // not. |
149 BooleanPrefMember show_details_; | 146 BooleanPrefMember show_details_; |
150 | 147 |
151 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler); | 148 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler); |
(...skipping 25 matching lines...) Expand all Loading... |
177 NewCallback(this, &PluginsDOMHandler::HandleGetShowDetails)); | 174 NewCallback(this, &PluginsDOMHandler::HandleGetShowDetails)); |
178 } | 175 } |
179 | 176 |
180 void PluginsDOMHandler::HandleRequestPluginsData(const ListValue* args) { | 177 void PluginsDOMHandler::HandleRequestPluginsData(const ListValue* args) { |
181 LoadPlugins(); | 178 LoadPlugins(); |
182 } | 179 } |
183 | 180 |
184 void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) { | 181 void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) { |
185 Profile* profile = Profile::FromWebUI(web_ui_); | 182 Profile* profile = Profile::FromWebUI(web_ui_); |
186 | 183 |
| 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 |
187 // Be robust in accepting badness since plug-ins display HTML (hence | 191 // Be robust in accepting badness since plug-ins display HTML (hence |
188 // JavaScript). | 192 // JavaScript). |
189 if (args->GetSize() != 3) | 193 if (args->GetSize() != 3) |
190 return; | 194 return; |
191 | 195 |
192 std::string enable_str; | 196 std::string enable_str; |
193 std::string is_group_str; | 197 std::string is_group_str; |
194 if (!args->GetString(1, &enable_str) || !args->GetString(2, &is_group_str)) | 198 if (!args->GetString(1, &enable_str) || !args->GetString(2, &is_group_str)) |
195 return; | 199 return; |
196 bool enable = enable_str == "true"; | 200 bool enable = enable_str == "true"; |
197 | 201 |
198 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); | 202 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); |
199 if (is_group_str == "true") { | 203 if (is_group_str == "true") { |
200 string16 group_name; | 204 string16 group_name; |
201 if (!args->GetString(0, &group_name)) | 205 if (!args->GetString(0, &group_name)) |
202 return; | 206 return; |
203 | 207 |
204 plugin_prefs->EnablePluginGroup(enable, group_name); | 208 plugin_prefs->EnablePluginGroup(enable, group_name); |
205 if (enable) { | 209 if (enable) { |
206 // See http://crbug.com/50105 for background. | 210 // See http://crbug.com/50105 for background. |
207 string16 adobereader = ASCIIToUTF16( | 211 string16 adobereader = ASCIIToUTF16( |
208 PluginGroup::kAdobeReaderGroupName); | 212 webkit::npapi::PluginGroup::kAdobeReaderGroupName); |
209 string16 internalpdf = | 213 string16 internalpdf = |
210 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName); | 214 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName); |
211 if (group_name == adobereader) | 215 if (group_name == adobereader) { |
212 plugin_prefs->EnablePluginGroup(false, internalpdf); | 216 plugin_prefs->EnablePluginGroup(false, internalpdf); |
213 else if (group_name == internalpdf) | 217 } else if (group_name == internalpdf) { |
214 plugin_prefs->EnablePluginGroup(false, adobereader); | 218 plugin_prefs->EnablePluginGroup(false, adobereader); |
| 219 } |
215 } | 220 } |
216 } else { | 221 } else { |
217 FilePath::StringType file_path; | 222 FilePath::StringType file_path; |
218 if (!args->GetString(0, &file_path)) | 223 if (!args->GetString(0, &file_path)) |
219 return; | 224 return; |
| 225 |
220 plugin_prefs->EnablePlugin(enable, FilePath(file_path)); | 226 plugin_prefs->EnablePlugin(enable, FilePath(file_path)); |
221 } | 227 } |
| 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); |
222 } | 233 } |
223 | 234 |
224 void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) { | 235 void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) { |
225 std::string details_mode; | 236 std::string details_mode; |
226 if (!args->GetString(0, &details_mode)) { | 237 if (!args->GetString(0, &details_mode)) { |
227 NOTREACHED(); | 238 NOTREACHED(); |
228 return; | 239 return; |
229 } | 240 } |
230 show_details_.SetValue(details_mode == "true"); | 241 show_details_.SetValue(details_mode == "true"); |
231 } | 242 } |
232 | 243 |
233 void PluginsDOMHandler::HandleGetShowDetails(const ListValue* args) { | 244 void PluginsDOMHandler::HandleGetShowDetails(const ListValue* args) { |
234 base::FundamentalValue show_details(show_details_.GetValue()); | 245 base::FundamentalValue show_details(show_details_.GetValue()); |
235 web_ui_->CallJavascriptFunction("loadShowDetailsFromPrefs", show_details); | 246 web_ui_->CallJavascriptFunction("loadShowDetailsFromPrefs", show_details); |
236 } | 247 } |
237 | 248 |
238 void PluginsDOMHandler::Observe(int type, | 249 void PluginsDOMHandler::Observe(int type, |
239 const NotificationSource& source, | 250 const NotificationSource& source, |
240 const NotificationDetails& details) { | 251 const NotificationDetails& details) { |
241 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); | 252 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); |
242 LoadPlugins(); | 253 LoadPlugins(); |
243 } | 254 } |
244 | 255 |
245 void PluginsDOMHandler::LoadPluginsOnFileThread( | 256 void PluginsDOMHandler::LoadPluginsOnFileThread( |
246 std::vector<PluginGroup>* groups, | 257 std::vector<webkit::npapi::PluginGroup>* groups, |
247 Task* task) { | 258 Task* task) { |
248 webkit::npapi::PluginList::Singleton()->GetPluginGroups(true, groups); | 259 webkit::npapi::PluginList::Singleton()->GetPluginGroups(true, groups); |
249 | 260 |
250 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, task); | 261 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, task); |
251 BrowserThread::PostTask( | 262 BrowserThread::PostTask( |
252 BrowserThread::UI, | 263 BrowserThread::UI, |
253 FROM_HERE, | 264 FROM_HERE, |
254 NewRunnableFunction(&PluginsDOMHandler::EnsurePluginGroupsDeleted, | 265 NewRunnableFunction(&PluginsDOMHandler::EnsurePluginGroupsDeleted, |
255 groups)); | 266 groups)); |
256 } | 267 } |
257 | 268 |
258 void PluginsDOMHandler::EnsurePluginGroupsDeleted( | 269 void PluginsDOMHandler::EnsurePluginGroupsDeleted( |
259 std::vector<PluginGroup>* groups) { | 270 std::vector<webkit::npapi::PluginGroup>* groups) { |
260 delete groups; | 271 delete groups; |
261 } | 272 } |
262 | 273 |
263 void PluginsDOMHandler::LoadPlugins() { | 274 void PluginsDOMHandler::LoadPlugins() { |
264 if (!get_plugins_factory_.empty()) | 275 if (!get_plugins_factory_.empty()) |
265 return; | 276 return; |
266 | 277 |
267 std::vector<PluginGroup>* groups = new std::vector<PluginGroup>; | 278 std::vector<webkit::npapi::PluginGroup>* groups = |
| 279 new std::vector<webkit::npapi::PluginGroup>; |
268 Task* task = get_plugins_factory_.NewRunnableMethod( | 280 Task* task = get_plugins_factory_.NewRunnableMethod( |
269 &PluginsDOMHandler::PluginsLoaded, groups); | 281 &PluginsDOMHandler::PluginsLoaded, groups); |
270 | 282 |
271 BrowserThread::PostTask( | 283 BrowserThread::PostTask( |
272 BrowserThread::FILE, | 284 BrowserThread::FILE, |
273 FROM_HERE, | 285 FROM_HERE, |
274 NewRunnableFunction( | 286 NewRunnableFunction( |
275 &PluginsDOMHandler::LoadPluginsOnFileThread, groups, task)); | 287 &PluginsDOMHandler::LoadPluginsOnFileThread, groups, task)); |
276 } | 288 } |
277 | 289 |
278 void PluginsDOMHandler::PluginsLoaded(const std::vector<PluginGroup>* groups) { | 290 void PluginsDOMHandler::PluginsLoaded( |
279 PluginPrefs* plugin_prefs = | 291 const std::vector<webkit::npapi::PluginGroup>* groups) { |
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 | |
285 // Construct DictionaryValues to return to the UI | 292 // Construct DictionaryValues to return to the UI |
286 ListValue* plugin_groups_data = new ListValue(); | 293 ListValue* plugin_groups_data = new ListValue(); |
287 for (size_t i = 0; i < groups->size(); ++i) { | 294 for (size_t i = 0; i < groups->size(); ++i) { |
288 ListValue* plugin_files = new ListValue(); | 295 plugin_groups_data->Append((*groups)[i].GetDataForUI()); |
289 const PluginGroup& group = (*groups)[i]; | 296 // TODO(bauerb): Fetch plugin enabled state from PluginPrefs. |
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); | |
375 } | 297 } |
376 DictionaryValue results; | 298 DictionaryValue results; |
377 results.Set("plugins", plugin_groups_data); | 299 results.Set("plugins", plugin_groups_data); |
378 web_ui_->CallJavascriptFunction("returnPluginsData", results); | 300 web_ui_->CallJavascriptFunction("returnPluginsData", results); |
379 } | 301 } |
380 | 302 |
381 } // namespace | 303 } // namespace |
382 | 304 |
383 /////////////////////////////////////////////////////////////////////////////// | 305 /////////////////////////////////////////////////////////////////////////////// |
384 // | 306 // |
385 // PluginsUI | 307 // PluginsUI |
386 // | 308 // |
387 /////////////////////////////////////////////////////////////////////////////// | 309 /////////////////////////////////////////////////////////////////////////////// |
388 | 310 |
389 PluginsUI::PluginsUI(TabContents* contents) : ChromeWebUI(contents) { | 311 PluginsUI::PluginsUI(TabContents* contents) : ChromeWebUI(contents) { |
390 AddMessageHandler((new PluginsDOMHandler())->Attach(this)); | 312 AddMessageHandler((new PluginsDOMHandler())->Attach(this)); |
391 | 313 |
392 // Set up the chrome://plugins/ source. | 314 // Set up the chrome://plugins/ source. |
393 // TODO(bauerb): Remove |enable_controls| & co. | |
394 bool enable_controls = true; | 315 bool enable_controls = true; |
395 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | 316 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); |
| 317 #if !defined(OS_CHROMEOS) |
| 318 enable_controls = profile->GetOriginalProfile()->first_launched(); |
| 319 #endif |
396 profile->GetChromeURLDataManager()->AddDataSource( | 320 profile->GetChromeURLDataManager()->AddDataSource( |
397 CreatePluginsUIHTMLSource(enable_controls)); | 321 CreatePluginsUIHTMLSource(enable_controls)); |
398 } | 322 } |
399 | 323 |
400 | 324 |
401 // static | 325 // static |
402 RefCountedMemory* PluginsUI::GetFaviconResourceBytes() { | 326 RefCountedMemory* PluginsUI::GetFaviconResourceBytes() { |
403 return ResourceBundle::GetSharedInstance(). | 327 return ResourceBundle::GetSharedInstance(). |
404 LoadDataResourceBytes(IDR_PLUGIN); | 328 LoadDataResourceBytes(IDR_PLUGIN); |
405 } | 329 } |
406 | 330 |
407 // static | 331 // static |
408 void PluginsUI::RegisterUserPrefs(PrefService* prefs) { | 332 void PluginsUI::RegisterUserPrefs(PrefService* prefs) { |
409 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, | 333 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, |
410 false, | 334 false, |
411 PrefService::UNSYNCABLE_PREF); | 335 PrefService::UNSYNCABLE_PREF); |
412 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, | 336 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, |
413 true, | 337 true, |
414 PrefService::UNSYNCABLE_PREF); | 338 PrefService::UNSYNCABLE_PREF); |
415 } | 339 } |
OLD | NEW |