| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 }; | 152 }; |
| 153 | 153 |
| 154 PluginsDOMHandler::PluginsDOMHandler() | 154 PluginsDOMHandler::PluginsDOMHandler() |
| 155 : ALLOW_THIS_IN_INITIALIZER_LIST(get_plugins_factory_(this)) { | 155 : ALLOW_THIS_IN_INITIALIZER_LIST(get_plugins_factory_(this)) { |
| 156 registrar_.Add(this, | 156 registrar_.Add(this, |
| 157 content::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, | 157 content::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, |
| 158 NotificationService::AllSources()); | 158 NotificationService::AllSources()); |
| 159 } | 159 } |
| 160 | 160 |
| 161 WebUIMessageHandler* PluginsDOMHandler::Attach(WebUI* web_ui) { | 161 WebUIMessageHandler* PluginsDOMHandler::Attach(WebUI* web_ui) { |
| 162 PrefService* prefs = web_ui->GetProfile()->GetPrefs(); | 162 PrefService* prefs = Profile::FromWebUI(web_ui)->GetPrefs(); |
| 163 | 163 |
| 164 show_details_.Init(prefs::kPluginsShowDetails, prefs, this); | 164 show_details_.Init(prefs::kPluginsShowDetails, prefs, this); |
| 165 | 165 |
| 166 return WebUIMessageHandler::Attach(web_ui); | 166 return WebUIMessageHandler::Attach(web_ui); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void PluginsDOMHandler::RegisterMessages() { | 169 void PluginsDOMHandler::RegisterMessages() { |
| 170 web_ui_->RegisterMessageCallback("requestPluginsData", | 170 web_ui_->RegisterMessageCallback("requestPluginsData", |
| 171 NewCallback(this, &PluginsDOMHandler::HandleRequestPluginsData)); | 171 NewCallback(this, &PluginsDOMHandler::HandleRequestPluginsData)); |
| 172 web_ui_->RegisterMessageCallback("enablePlugin", | 172 web_ui_->RegisterMessageCallback("enablePlugin", |
| 173 NewCallback(this, &PluginsDOMHandler::HandleEnablePluginMessage)); | 173 NewCallback(this, &PluginsDOMHandler::HandleEnablePluginMessage)); |
| 174 web_ui_->RegisterMessageCallback("saveShowDetailsToPrefs", | 174 web_ui_->RegisterMessageCallback("saveShowDetailsToPrefs", |
| 175 NewCallback(this, &PluginsDOMHandler::HandleSaveShowDetailsToPrefs)); | 175 NewCallback(this, &PluginsDOMHandler::HandleSaveShowDetailsToPrefs)); |
| 176 web_ui_->RegisterMessageCallback("getShowDetails", | 176 web_ui_->RegisterMessageCallback("getShowDetails", |
| 177 NewCallback(this, &PluginsDOMHandler::HandleGetShowDetails)); | 177 NewCallback(this, &PluginsDOMHandler::HandleGetShowDetails)); |
| 178 } | 178 } |
| 179 | 179 |
| 180 void PluginsDOMHandler::HandleRequestPluginsData(const ListValue* args) { | 180 void PluginsDOMHandler::HandleRequestPluginsData(const ListValue* args) { |
| 181 LoadPlugins(); | 181 LoadPlugins(); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) { | 184 void PluginsDOMHandler::HandleEnablePluginMessage(const ListValue* args) { |
| 185 Profile* profile = Profile::FromWebUI(web_ui_); |
| 186 |
| 185 // If a non-first-profile user tries to trigger these methods sneakily, | 187 // If a non-first-profile user tries to trigger these methods sneakily, |
| 186 // forbid it. | 188 // forbid it. |
| 187 #if !defined(OS_CHROMEOS) | 189 #if !defined(OS_CHROMEOS) |
| 188 if (!web_ui_->GetProfile()->GetOriginalProfile()->first_launched()) | 190 if (!profile->GetOriginalProfile()->first_launched()) |
| 189 return; | 191 return; |
| 190 #endif | 192 #endif |
| 191 | 193 |
| 192 // Be robust in accepting badness since plug-ins display HTML (hence | 194 // Be robust in accepting badness since plug-ins display HTML (hence |
| 193 // JavaScript). | 195 // JavaScript). |
| 194 if (args->GetSize() != 3) | 196 if (args->GetSize() != 3) |
| 195 return; | 197 return; |
| 196 | 198 |
| 197 std::string enable_str; | 199 std::string enable_str; |
| 198 std::string is_group_str; | 200 std::string is_group_str; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 223 FilePath::StringType file_path; | 225 FilePath::StringType file_path; |
| 224 if (!args->GetString(0, &file_path)) | 226 if (!args->GetString(0, &file_path)) |
| 225 return; | 227 return; |
| 226 | 228 |
| 227 plugin_updater->EnablePlugin(enable, file_path); | 229 plugin_updater->EnablePlugin(enable, file_path); |
| 228 } | 230 } |
| 229 | 231 |
| 230 // TODO(viettrungluu): We might also want to ensure that the plugins | 232 // 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 | 233 // list is always written to prefs even when the user hasn't disabled a |
| 232 // plugin. <http://crbug.com/39101> | 234 // plugin. <http://crbug.com/39101> |
| 233 plugin_updater->UpdatePreferences(web_ui_->GetProfile(), 0); | 235 plugin_updater->UpdatePreferences(profile, 0); |
| 234 } | 236 } |
| 235 | 237 |
| 236 void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) { | 238 void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) { |
| 237 std::string details_mode; | 239 std::string details_mode; |
| 238 if (!args->GetString(0, &details_mode)) { | 240 if (!args->GetString(0, &details_mode)) { |
| 239 NOTREACHED(); | 241 NOTREACHED(); |
| 240 return; | 242 return; |
| 241 } | 243 } |
| 242 show_details_.SetValue(details_mode == "true"); | 244 show_details_.SetValue(details_mode == "true"); |
| 243 } | 245 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 prefs->RegisterBooleanPref(prefs::kPluginsEnabledInternalPDF, | 329 prefs->RegisterBooleanPref(prefs::kPluginsEnabledInternalPDF, |
| 328 false, | 330 false, |
| 329 PrefService::UNSYNCABLE_PREF); | 331 PrefService::UNSYNCABLE_PREF); |
| 330 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, | 332 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, |
| 331 false, | 333 false, |
| 332 PrefService::UNSYNCABLE_PREF); | 334 PrefService::UNSYNCABLE_PREF); |
| 333 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, | 335 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, |
| 334 true, | 336 true, |
| 335 PrefService::UNSYNCABLE_PREF); | 337 PrefService::UNSYNCABLE_PREF); |
| 336 } | 338 } |
| OLD | NEW |