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 = Profile::FromWebUI(web_ui)->GetPrefs(); | 158 PrefService* prefs = Profile::FromWebUI(web_ui)->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 20 matching lines...) Expand all Loading... |
195 // JavaScript). | 191 // JavaScript). |
196 if (args->GetSize() != 3) | 192 if (args->GetSize() != 3) |
197 return; | 193 return; |
198 | 194 |
199 std::string enable_str; | 195 std::string enable_str; |
200 std::string is_group_str; | 196 std::string is_group_str; |
201 if (!args->GetString(1, &enable_str) || !args->GetString(2, &is_group_str)) | 197 if (!args->GetString(1, &enable_str) || !args->GetString(2, &is_group_str)) |
202 return; | 198 return; |
203 bool enable = enable_str == "true"; | 199 bool enable = enable_str == "true"; |
204 | 200 |
205 PluginUpdater* plugin_updater = PluginUpdater::GetInstance(); | 201 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); |
206 if (is_group_str == "true") { | 202 if (is_group_str == "true") { |
207 string16 group_name; | 203 string16 group_name; |
208 if (!args->GetString(0, &group_name)) | 204 if (!args->GetString(0, &group_name)) |
209 return; | 205 return; |
210 | 206 |
211 plugin_updater->EnablePluginGroup(enable, group_name); | 207 plugin_prefs->EnablePluginGroup(enable, group_name); |
212 if (enable) { | 208 if (enable) { |
213 // See http://crbug.com/50105 for background. | 209 // See http://crbug.com/50105 for background. |
214 string16 adobereader = ASCIIToUTF16( | 210 string16 adobereader = ASCIIToUTF16( |
215 webkit::npapi::PluginGroup::kAdobeReaderGroupName); | 211 webkit::npapi::PluginGroup::kAdobeReaderGroupName); |
216 string16 internalpdf = | 212 string16 internalpdf = |
217 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName); | 213 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName); |
218 if (group_name == adobereader) { | 214 if (group_name == adobereader) { |
219 plugin_updater->EnablePluginGroup(false, internalpdf); | 215 plugin_prefs->EnablePluginGroup(false, internalpdf); |
220 } else if (group_name == internalpdf) { | 216 } else if (group_name == internalpdf) { |
221 plugin_updater->EnablePluginGroup(false, adobereader); | 217 plugin_prefs->EnablePluginGroup(false, adobereader); |
222 } | 218 } |
223 } | 219 } |
224 } else { | 220 } else { |
225 FilePath::StringType file_path; | 221 FilePath::StringType file_path; |
226 if (!args->GetString(0, &file_path)) | 222 if (!args->GetString(0, &file_path)) |
227 return; | 223 return; |
228 | 224 |
229 plugin_updater->EnablePlugin(enable, file_path); | 225 plugin_prefs->EnablePlugin(enable, FilePath(file_path)); |
230 } | 226 } |
231 | 227 |
232 // TODO(viettrungluu): We might also want to ensure that the plugins | 228 // TODO(viettrungluu): We might also want to ensure that the plugins |
233 // list is always written to prefs even when the user hasn't disabled a | 229 // list is always written to prefs even when the user hasn't disabled a |
234 // plugin. <http://crbug.com/39101> | 230 // plugin. <http://crbug.com/39101> |
235 plugin_updater->UpdatePreferences(Profile::FromWebUI(web_ui_), 0); | 231 plugin_prefs->UpdatePreferences(0); |
236 } | 232 } |
237 | 233 |
238 void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) { | 234 void PluginsDOMHandler::HandleSaveShowDetailsToPrefs(const ListValue* args) { |
239 std::string details_mode; | 235 std::string details_mode; |
240 if (!args->GetString(0, &details_mode)) { | 236 if (!args->GetString(0, &details_mode)) { |
241 NOTREACHED(); | 237 NOTREACHED(); |
242 return; | 238 return; |
243 } | 239 } |
244 show_details_.SetValue(details_mode == "true"); | 240 show_details_.SetValue(details_mode == "true"); |
245 } | 241 } |
246 | 242 |
247 void PluginsDOMHandler::HandleGetShowDetails(const ListValue* args) { | 243 void PluginsDOMHandler::HandleGetShowDetails(const ListValue* args) { |
248 base::FundamentalValue show_details(show_details_.GetValue()); | 244 base::FundamentalValue show_details(show_details_.GetValue()); |
249 web_ui_->CallJavascriptFunction("loadShowDetailsFromPrefs", show_details); | 245 web_ui_->CallJavascriptFunction("loadShowDetailsFromPrefs", show_details); |
250 } | 246 } |
251 | 247 |
252 void PluginsDOMHandler::Observe(int type, | 248 void PluginsDOMHandler::Observe(int type, |
253 const NotificationSource& source, | 249 const NotificationSource& source, |
254 const NotificationDetails& details) { | 250 const NotificationDetails& details) { |
255 DCHECK_EQ(content::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); | 251 DCHECK_EQ(content::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); |
256 LoadPlugins(); | 252 LoadPlugins(); |
257 } | 253 } |
258 | 254 |
259 void PluginsDOMHandler::LoadPluginsOnFileThread(ListWrapper* wrapper, | 255 void PluginsDOMHandler::LoadPluginsOnFileThread( |
260 Task* task) { | 256 std::vector<webkit::npapi::PluginGroup>* groups, |
261 wrapper->list = PluginUpdater::GetInstance()->GetPluginGroupsData(); | 257 Task* task) { |
| 258 webkit::npapi::PluginList::Singleton()->GetPluginGroups(true, groups); |
| 259 |
262 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, task); | 260 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, task); |
263 BrowserThread::PostTask( | 261 BrowserThread::PostTask( |
264 BrowserThread::UI, | 262 BrowserThread::UI, |
265 FROM_HERE, | 263 FROM_HERE, |
266 NewRunnableFunction(&PluginsDOMHandler::EnsureListDeleted, wrapper)); | 264 NewRunnableFunction(&PluginsDOMHandler::EnsurePluginGroupsDeleted, |
| 265 groups)); |
267 } | 266 } |
268 | 267 |
269 void PluginsDOMHandler::EnsureListDeleted(ListWrapper* wrapper) { | 268 void PluginsDOMHandler::EnsurePluginGroupsDeleted( |
270 delete wrapper->list; | 269 std::vector<webkit::npapi::PluginGroup>* groups) { |
271 delete wrapper; | 270 delete groups; |
272 } | 271 } |
273 | 272 |
274 void PluginsDOMHandler::LoadPlugins() { | 273 void PluginsDOMHandler::LoadPlugins() { |
275 if (!get_plugins_factory_.empty()) | 274 if (!get_plugins_factory_.empty()) |
276 return; | 275 return; |
277 | 276 |
278 ListWrapper* wrapper = new ListWrapper; | 277 std::vector<webkit::npapi::PluginGroup>* groups = |
279 wrapper->list = NULL; | 278 new std::vector<webkit::npapi::PluginGroup>; |
280 Task* task = get_plugins_factory_.NewRunnableMethod( | 279 Task* task = get_plugins_factory_.NewRunnableMethod( |
281 &PluginsDOMHandler::PluginsLoaded, wrapper); | 280 &PluginsDOMHandler::PluginsLoaded, groups); |
282 | 281 |
283 BrowserThread::PostTask( | 282 BrowserThread::PostTask( |
284 BrowserThread::FILE, | 283 BrowserThread::FILE, |
285 FROM_HERE, | 284 FROM_HERE, |
286 NewRunnableFunction( | 285 NewRunnableFunction( |
287 &PluginsDOMHandler::LoadPluginsOnFileThread, wrapper, task)); | 286 &PluginsDOMHandler::LoadPluginsOnFileThread, groups, task)); |
288 } | 287 } |
289 | 288 |
290 void PluginsDOMHandler::PluginsLoaded(ListWrapper* wrapper) { | 289 void PluginsDOMHandler::PluginsLoaded( |
| 290 const std::vector<webkit::npapi::PluginGroup>* groups) { |
| 291 // Construct DictionaryValues to return to the UI |
| 292 ListValue* plugin_groups_data = new ListValue(); |
| 293 for (size_t i = 0; i < groups->size(); ++i) { |
| 294 plugin_groups_data->Append((*groups)[i].GetDataForUI()); |
| 295 // TODO(bauerb): Fetch plugin enabled state from PluginPrefs. |
| 296 } |
291 DictionaryValue results; | 297 DictionaryValue results; |
292 results.Set("plugins", wrapper->list); | 298 results.Set("plugins", plugin_groups_data); |
293 wrapper->list = NULL; // So it doesn't get deleted. | |
294 web_ui_->CallJavascriptFunction("returnPluginsData", results); | 299 web_ui_->CallJavascriptFunction("returnPluginsData", results); |
295 } | 300 } |
296 | 301 |
297 } // namespace | 302 } // namespace |
298 | 303 |
299 /////////////////////////////////////////////////////////////////////////////// | 304 /////////////////////////////////////////////////////////////////////////////// |
300 // | 305 // |
301 // PluginsUI | 306 // PluginsUI |
302 // | 307 // |
303 /////////////////////////////////////////////////////////////////////////////// | 308 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 25 matching lines...) Expand all Loading... |
329 prefs->RegisterBooleanPref(prefs::kPluginsEnabledInternalPDF, | 334 prefs->RegisterBooleanPref(prefs::kPluginsEnabledInternalPDF, |
330 false, | 335 false, |
331 PrefService::UNSYNCABLE_PREF); | 336 PrefService::UNSYNCABLE_PREF); |
332 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, | 337 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, |
333 false, | 338 false, |
334 PrefService::UNSYNCABLE_PREF); | 339 PrefService::UNSYNCABLE_PREF); |
335 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, | 340 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, |
336 true, | 341 true, |
337 PrefService::UNSYNCABLE_PREF); | 342 PrefService::UNSYNCABLE_PREF); |
338 } | 343 } |
OLD | NEW |