| 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 |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/plugin_updater.h" | 16 #include "chrome/browser/plugin_prefs.h" |
| 17 #include "chrome/browser/prefs/pref_member.h" | 17 #include "chrome/browser/prefs/pref_member.h" |
| 18 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
| 22 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 22 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 23 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 23 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
| 24 #include "chrome/common/chrome_content_client.h" | 24 #include "chrome/common/chrome_content_client.h" |
| 25 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
| 26 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 115 |
| 116 // Calback for the "getShowDetails" message. | 116 // Calback for the "getShowDetails" message. |
| 117 void HandleGetShowDetails(const ListValue* args); | 117 void HandleGetShowDetails(const ListValue* args); |
| 118 | 118 |
| 119 // NotificationObserver method overrides | 119 // NotificationObserver method overrides |
| 120 virtual void Observe(int type, | 120 virtual void Observe(int type, |
| 121 const NotificationSource& source, | 121 const NotificationSource& source, |
| 122 const NotificationDetails& details) OVERRIDE; | 122 const NotificationDetails& details) OVERRIDE; |
| 123 | 123 |
| 124 private: | 124 private: |
| 125 // This extra wrapper is used to ensure we don't leak the ListValue* pointer | |
| 126 // if the PluginsDOMHandler object goes away before the task on the UI thread | |
| 127 // to give it the plugin list runs. | |
| 128 struct ListWrapper { | |
| 129 ListValue* list; | |
| 130 }; | |
| 131 // Loads the plugins on the FILE thread. | 125 // Loads the plugins on the FILE thread. |
| 132 static void LoadPluginsOnFileThread(ListWrapper* wrapper, Task* task); | 126 static void LoadPluginsOnFileThread( |
| 127 std::vector<webkit::npapi::PluginGroup>* groups, Task* task); |
| 133 | 128 |
| 134 // Used in conjunction with ListWrapper to avoid any memory leaks. | 129 // Used in conjunction with ListWrapper to avoid any memory leaks. |
| 135 static void EnsureListDeleted(ListWrapper* wrapper); | 130 static void EnsurePluginGroupsDeleted( |
| 131 std::vector<webkit::npapi::PluginGroup>* groups); |
| 136 | 132 |
| 137 // Call this to start getting the plugins on the UI thread. | 133 // Call this to start getting the plugins on the UI thread. |
| 138 void LoadPlugins(); | 134 void LoadPlugins(); |
| 139 | 135 |
| 140 // Called on the UI thread when the plugin information is ready. | 136 // Called on the UI thread when the plugin information is ready. |
| 141 void PluginsLoaded(ListWrapper* wrapper); | 137 void PluginsLoaded(const std::vector<webkit::npapi::PluginGroup>* groups); |
| 142 | 138 |
| 143 NotificationRegistrar registrar_; | 139 NotificationRegistrar registrar_; |
| 144 | 140 |
| 145 ScopedRunnableMethodFactory<PluginsDOMHandler> get_plugins_factory_; | 141 ScopedRunnableMethodFactory<PluginsDOMHandler> get_plugins_factory_; |
| 146 | 142 |
| 147 // This pref guards the value whether about:plugins is in the details mode or | 143 // This pref guards the value whether about:plugins is in the details mode or |
| 148 // not. | 144 // not. |
| 149 BooleanPrefMember show_details_; | 145 BooleanPrefMember show_details_; |
| 150 | 146 |
| 151 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler); | 147 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler); |
| 152 }; | 148 }; |
| 153 | 149 |
| 154 PluginsDOMHandler::PluginsDOMHandler() | 150 PluginsDOMHandler::PluginsDOMHandler() |
| 155 : ALLOW_THIS_IN_INITIALIZER_LIST(get_plugins_factory_(this)) { | 151 : ALLOW_THIS_IN_INITIALIZER_LIST(get_plugins_factory_(this)) { |
| 156 registrar_.Add(this, | 152 registrar_.Add(this, |
| 157 content::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, | 153 content::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, |
| 158 NotificationService::AllSources()); | 154 NotificationService::AllSources()); |
| 159 } | 155 } |
| 160 | 156 |
| 161 WebUIMessageHandler* PluginsDOMHandler::Attach(WebUI* web_ui) { | 157 WebUIMessageHandler* PluginsDOMHandler::Attach(WebUI* web_ui) { |
| 162 PrefService* prefs = web_ui->GetProfile()->GetPrefs(); | 158 PrefService* prefs = web_ui->GetProfile()->GetPrefs(); |
| 163 | 159 |
| 164 show_details_.Init(prefs::kPluginsShowDetails, prefs, this); | 160 show_details_.Init(prefs::kPluginsShowDetails, prefs, NULL); |
| 165 | 161 |
| 166 return WebUIMessageHandler::Attach(web_ui); | 162 return WebUIMessageHandler::Attach(web_ui); |
| 167 } | 163 } |
| 168 | 164 |
| 169 void PluginsDOMHandler::RegisterMessages() { | 165 void PluginsDOMHandler::RegisterMessages() { |
| 170 web_ui_->RegisterMessageCallback("requestPluginsData", | 166 web_ui_->RegisterMessageCallback("requestPluginsData", |
| 171 NewCallback(this, &PluginsDOMHandler::HandleRequestPluginsData)); | 167 NewCallback(this, &PluginsDOMHandler::HandleRequestPluginsData)); |
| 172 web_ui_->RegisterMessageCallback("enablePlugin", | 168 web_ui_->RegisterMessageCallback("enablePlugin", |
| 173 NewCallback(this, &PluginsDOMHandler::HandleEnablePluginMessage)); | 169 NewCallback(this, &PluginsDOMHandler::HandleEnablePluginMessage)); |
| 174 web_ui_->RegisterMessageCallback("saveShowDetailsToPrefs", | 170 web_ui_->RegisterMessageCallback("saveShowDetailsToPrefs", |
| (...skipping 18 matching lines...) Expand all Loading... |
| 193 // JavaScript). | 189 // JavaScript). |
| 194 if (args->GetSize() != 3) | 190 if (args->GetSize() != 3) |
| 195 return; | 191 return; |
| 196 | 192 |
| 197 std::string enable_str; | 193 std::string enable_str; |
| 198 std::string is_group_str; | 194 std::string is_group_str; |
| 199 if (!args->GetString(1, &enable_str) || !args->GetString(2, &is_group_str)) | 195 if (!args->GetString(1, &enable_str) || !args->GetString(2, &is_group_str)) |
| 200 return; | 196 return; |
| 201 bool enable = enable_str == "true"; | 197 bool enable = enable_str == "true"; |
| 202 | 198 |
| 203 PluginUpdater* plugin_updater = PluginUpdater::GetInstance(); | 199 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(web_ui_->GetProfile()); |
| 204 if (is_group_str == "true") { | 200 if (is_group_str == "true") { |
| 205 string16 group_name; | 201 string16 group_name; |
| 206 if (!args->GetString(0, &group_name)) | 202 if (!args->GetString(0, &group_name)) |
| 207 return; | 203 return; |
| 208 | 204 |
| 209 plugin_updater->EnablePluginGroup(enable, group_name); | 205 plugin_prefs->EnablePluginGroup(enable, group_name); |
| 210 if (enable) { | 206 if (enable) { |
| 211 // See http://crbug.com/50105 for background. | 207 // See http://crbug.com/50105 for background. |
| 212 string16 adobereader = ASCIIToUTF16( | 208 string16 adobereader = ASCIIToUTF16( |
| 213 webkit::npapi::PluginGroup::kAdobeReaderGroupName); | 209 webkit::npapi::PluginGroup::kAdobeReaderGroupName); |
| 214 string16 internalpdf = | 210 string16 internalpdf = |
| 215 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName); | 211 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName); |
| 216 if (group_name == adobereader) { | 212 if (group_name == adobereader) { |
| 217 plugin_updater->EnablePluginGroup(false, internalpdf); | 213 plugin_prefs->EnablePluginGroup(false, internalpdf); |
| 218 } else if (group_name == internalpdf) { | 214 } else if (group_name == internalpdf) { |
| 219 plugin_updater->EnablePluginGroup(false, adobereader); | 215 plugin_prefs->EnablePluginGroup(false, adobereader); |
| 220 } | 216 } |
| 221 } | 217 } |
| 222 } else { | 218 } else { |
| 223 FilePath::StringType file_path; | 219 FilePath::StringType file_path; |
| 224 if (!args->GetString(0, &file_path)) | 220 if (!args->GetString(0, &file_path)) |
| 225 return; | 221 return; |
| 226 | 222 |
| 227 plugin_updater->EnablePlugin(enable, file_path); | 223 plugin_prefs->EnablePlugin(enable, FilePath(file_path)); |
| 228 } | 224 } |
| 229 | 225 |
| 230 // TODO(viettrungluu): We might also want to ensure that the plugins | 226 // TODO(viettrungluu): We might also want to ensure that the plugins |
| 231 // list is always written to prefs even when the user hasn't disabled a | 227 // list is always written to prefs even when the user hasn't disabled a |
| 232 // plugin. <http://crbug.com/39101> | 228 // plugin. <http://crbug.com/39101> |
| 233 plugin_updater->UpdatePreferences(web_ui_->GetProfile(), 0); | 229 plugin_prefs->UpdatePreferences(0); |
| 234 } | 230 } |
| 235 | 231 |
| 236 void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) { | 232 void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) { |
| 237 std::string details_mode; | 233 std::string details_mode; |
| 238 if (!args->GetString(0, &details_mode)) { | 234 if (!args->GetString(0, &details_mode)) { |
| 239 NOTREACHED(); | 235 NOTREACHED(); |
| 240 return; | 236 return; |
| 241 } | 237 } |
| 242 show_details_.SetValue(details_mode == "true"); | 238 show_details_.SetValue(details_mode == "true"); |
| 243 } | 239 } |
| 244 | 240 |
| 245 void PluginsDOMHandler::HandleGetShowDetails(const ListValue* args) { | 241 void PluginsDOMHandler::HandleGetShowDetails(const ListValue* args) { |
| 246 FundamentalValue show_details(show_details_.GetValue()); | 242 FundamentalValue show_details(show_details_.GetValue()); |
| 247 web_ui_->CallJavascriptFunction("loadShowDetailsFromPrefs", show_details); | 243 web_ui_->CallJavascriptFunction("loadShowDetailsFromPrefs", show_details); |
| 248 } | 244 } |
| 249 | 245 |
| 250 void PluginsDOMHandler::Observe(int type, | 246 void PluginsDOMHandler::Observe(int type, |
| 251 const NotificationSource& source, | 247 const NotificationSource& source, |
| 252 const NotificationDetails& details) { | 248 const NotificationDetails& details) { |
| 253 DCHECK_EQ(content::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); | 249 DCHECK_EQ(content::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); |
| 254 LoadPlugins(); | 250 LoadPlugins(); |
| 255 } | 251 } |
| 256 | 252 |
| 257 void PluginsDOMHandler::LoadPluginsOnFileThread(ListWrapper* wrapper, | 253 void PluginsDOMHandler::LoadPluginsOnFileThread( |
| 258 Task* task) { | 254 std::vector<webkit::npapi::PluginGroup>* groups, |
| 259 wrapper->list = PluginUpdater::GetInstance()->GetPluginGroupsData(); | 255 Task* task) { |
| 256 webkit::npapi::PluginList::Singleton()->GetPluginGroups(true, groups); |
| 257 |
| 260 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, task); | 258 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, task); |
| 261 BrowserThread::PostTask( | 259 BrowserThread::PostTask( |
| 262 BrowserThread::UI, | 260 BrowserThread::UI, |
| 263 FROM_HERE, | 261 FROM_HERE, |
| 264 NewRunnableFunction(&PluginsDOMHandler::EnsureListDeleted, wrapper)); | 262 NewRunnableFunction(&PluginsDOMHandler::EnsurePluginGroupsDeleted, |
| 263 groups)); |
| 265 } | 264 } |
| 266 | 265 |
| 267 void PluginsDOMHandler::EnsureListDeleted(ListWrapper* wrapper) { | 266 void PluginsDOMHandler::EnsurePluginGroupsDeleted( |
| 268 delete wrapper->list; | 267 std::vector<webkit::npapi::PluginGroup>* groups) { |
| 269 delete wrapper; | 268 delete groups; |
| 270 } | 269 } |
| 271 | 270 |
| 272 void PluginsDOMHandler::LoadPlugins() { | 271 void PluginsDOMHandler::LoadPlugins() { |
| 273 if (!get_plugins_factory_.empty()) | 272 if (!get_plugins_factory_.empty()) |
| 274 return; | 273 return; |
| 275 | 274 |
| 276 ListWrapper* wrapper = new ListWrapper; | 275 std::vector<webkit::npapi::PluginGroup>* groups = |
| 277 wrapper->list = NULL; | 276 new std::vector<webkit::npapi::PluginGroup>; |
| 278 Task* task = get_plugins_factory_.NewRunnableMethod( | 277 Task* task = get_plugins_factory_.NewRunnableMethod( |
| 279 &PluginsDOMHandler::PluginsLoaded, wrapper); | 278 &PluginsDOMHandler::PluginsLoaded, groups); |
| 280 | 279 |
| 281 BrowserThread::PostTask( | 280 BrowserThread::PostTask( |
| 282 BrowserThread::FILE, | 281 BrowserThread::FILE, |
| 283 FROM_HERE, | 282 FROM_HERE, |
| 284 NewRunnableFunction( | 283 NewRunnableFunction( |
| 285 &PluginsDOMHandler::LoadPluginsOnFileThread, wrapper, task)); | 284 &PluginsDOMHandler::LoadPluginsOnFileThread, groups, task)); |
| 286 } | 285 } |
| 287 | 286 |
| 288 void PluginsDOMHandler::PluginsLoaded(ListWrapper* wrapper) { | 287 void PluginsDOMHandler::PluginsLoaded( |
| 288 const std::vector<webkit::npapi::PluginGroup>* groups) { |
| 289 // Construct DictionaryValues to return to the UI |
| 290 ListValue* plugin_groups_data = new ListValue(); |
| 291 for (size_t i = 0; i < groups->size(); ++i) { |
| 292 plugin_groups_data->Append((*groups)[i].GetDataForUI()); |
| 293 // TODO(bauerb): Fetch plugin enabled state from PluginPrefs. |
| 294 } |
| 289 DictionaryValue results; | 295 DictionaryValue results; |
| 290 results.Set("plugins", wrapper->list); | 296 results.Set("plugins", plugin_groups_data); |
| 291 wrapper->list = NULL; // So it doesn't get deleted. | |
| 292 web_ui_->CallJavascriptFunction("returnPluginsData", results); | 297 web_ui_->CallJavascriptFunction("returnPluginsData", results); |
| 293 } | 298 } |
| 294 | 299 |
| 295 } // namespace | 300 } // namespace |
| 296 | 301 |
| 297 /////////////////////////////////////////////////////////////////////////////// | 302 /////////////////////////////////////////////////////////////////////////////// |
| 298 // | 303 // |
| 299 // PluginsUI | 304 // PluginsUI |
| 300 // | 305 // |
| 301 /////////////////////////////////////////////////////////////////////////////// | 306 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 25 matching lines...) Expand all Loading... |
| 327 prefs->RegisterBooleanPref(prefs::kPluginsEnabledInternalPDF, | 332 prefs->RegisterBooleanPref(prefs::kPluginsEnabledInternalPDF, |
| 328 false, | 333 false, |
| 329 PrefService::UNSYNCABLE_PREF); | 334 PrefService::UNSYNCABLE_PREF); |
| 330 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, | 335 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, |
| 331 false, | 336 false, |
| 332 PrefService::UNSYNCABLE_PREF); | 337 PrefService::UNSYNCABLE_PREF); |
| 333 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, | 338 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, |
| 334 true, | 339 true, |
| 335 PrefService::UNSYNCABLE_PREF); | 340 PrefService::UNSYNCABLE_PREF); |
| 336 } | 341 } |
| OLD | NEW |