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