Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Side by Side Diff: chrome/browser/ui/webui/plugins_ui.cc

Issue 7980011: Convert the PluginService interface to be an async wrapper around PluginList. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ready for review Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/bind.h"
11 #include "base/memory/singleton.h" 12 #include "base/memory/singleton.h"
13 #include "base/memory/weak_ptr.h"
12 #include "base/message_loop.h" 14 #include "base/message_loop.h"
13 #include "base/path_service.h" 15 #include "base/path_service.h"
14 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
15 #include "base/values.h" 17 #include "base/values.h"
16 #include "chrome/browser/plugin_prefs.h" 18 #include "chrome/browser/plugin_prefs.h"
17 #include "chrome/browser/prefs/pref_member.h" 19 #include "chrome/browser/prefs/pref_member.h"
18 #include "chrome/browser/prefs/pref_service.h" 20 #include "chrome/browser/prefs/pref_service.h"
19 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_window.h" 23 #include "chrome/browser/ui/browser_window.h"
22 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 24 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
23 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" 25 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
24 #include "chrome/common/chrome_content_client.h" 26 #include "chrome/common/chrome_content_client.h"
25 #include "chrome/common/chrome_notification_types.h" 27 #include "chrome/common/chrome_notification_types.h"
26 #include "chrome/common/chrome_paths.h" 28 #include "chrome/common/chrome_paths.h"
27 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
28 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
29 #include "content/browser/browser_thread.h" 31 #include "content/browser/browser_thread.h"
32 #include "content/browser/plugin_service.h"
30 #include "content/browser/tab_contents/tab_contents.h" 33 #include "content/browser/tab_contents/tab_contents.h"
31 #include "content/common/notification_service.h" 34 #include "content/common/notification_service.h"
32 #include "grit/browser_resources.h" 35 #include "grit/browser_resources.h"
33 #include "grit/generated_resources.h" 36 #include "grit/generated_resources.h"
34 #include "grit/theme_resources.h" 37 #include "grit/theme_resources.h"
35 #include "grit/theme_resources_standard.h" 38 #include "grit/theme_resources_standard.h"
36 #include "ui/base/resource/resource_bundle.h" 39 #include "ui/base/resource/resource_bundle.h"
37 #include "webkit/plugins/npapi/plugin_list.h"
38 40
39 using webkit::npapi::PluginGroup; 41 using webkit::npapi::PluginGroup;
40 using webkit::WebPluginInfo; 42 using webkit::WebPluginInfo;
41 43
42 namespace { 44 namespace {
43 45
44 ChromeWebUIDataSource* CreatePluginsUIHTMLSource() { 46 ChromeWebUIDataSource* CreatePluginsUIHTMLSource() {
45 ChromeWebUIDataSource* source = 47 ChromeWebUIDataSource* source =
46 new ChromeWebUIDataSource(chrome::kChromeUIPluginsHost); 48 new ChromeWebUIDataSource(chrome::kChromeUIPluginsHost);
47 49
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 114
113 // Calback for the "getShowDetails" message. 115 // Calback for the "getShowDetails" message.
114 void HandleGetShowDetails(const ListValue* args); 116 void HandleGetShowDetails(const ListValue* args);
115 117
116 // NotificationObserver method overrides 118 // NotificationObserver method overrides
117 virtual void Observe(int type, 119 virtual void Observe(int type,
118 const NotificationSource& source, 120 const NotificationSource& source,
119 const NotificationDetails& details) OVERRIDE; 121 const NotificationDetails& details) OVERRIDE;
120 122
121 private: 123 private:
122 // Loads the plugins on the FILE thread.
123 static void LoadPluginsOnFileThread(
124 std::vector<PluginGroup>* groups, Task* task);
125
126 // Used in conjunction with ListWrapper to avoid any memory leaks.
127 static void EnsurePluginGroupsDeleted(
128 std::vector<PluginGroup>* groups);
129
130 // Call this to start getting the plugins on the UI thread. 124 // Call this to start getting the plugins on the UI thread.
131 void LoadPlugins(); 125 void LoadPlugins();
132 126
133 // Called on the UI thread when the plugin information is ready. 127 // Called on the UI thread when the plugin information is ready.
134 void PluginsLoaded(const std::vector<PluginGroup>* groups); 128 void PluginsLoaded(const std::vector<PluginGroup> groups);
135 129
136 NotificationRegistrar registrar_; 130 NotificationRegistrar registrar_;
137 131
138 ScopedRunnableMethodFactory<PluginsDOMHandler> get_plugins_factory_; 132 base::WeakPtrFactory<PluginsDOMHandler> weak_ptr_factory_;
139 133
140 // This pref guards the value whether about:plugins is in the details mode or 134 // This pref guards the value whether about:plugins is in the details mode or
141 // not. 135 // not.
142 BooleanPrefMember show_details_; 136 BooleanPrefMember show_details_;
143 137
144 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler); 138 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler);
145 }; 139 };
146 140
147 PluginsDOMHandler::PluginsDOMHandler() 141 PluginsDOMHandler::PluginsDOMHandler()
148 : ALLOW_THIS_IN_INITIALIZER_LIST(get_plugins_factory_(this)) { 142 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
149 registrar_.Add(this, 143 registrar_.Add(this,
150 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, 144 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED,
151 NotificationService::AllSources()); 145 NotificationService::AllSources());
152 } 146 }
153 147
154 WebUIMessageHandler* PluginsDOMHandler::Attach(WebUI* web_ui) { 148 WebUIMessageHandler* PluginsDOMHandler::Attach(WebUI* web_ui) {
155 PrefService* prefs = Profile::FromWebUI(web_ui)->GetPrefs(); 149 PrefService* prefs = Profile::FromWebUI(web_ui)->GetPrefs();
156 150
157 show_details_.Init(prefs::kPluginsShowDetails, prefs, NULL); 151 show_details_.Init(prefs::kPluginsShowDetails, prefs, NULL);
158 152
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 web_ui_->CallJavascriptFunction("loadShowDetailsFromPrefs", show_details); 222 web_ui_->CallJavascriptFunction("loadShowDetailsFromPrefs", show_details);
229 } 223 }
230 224
231 void PluginsDOMHandler::Observe(int type, 225 void PluginsDOMHandler::Observe(int type,
232 const NotificationSource& source, 226 const NotificationSource& source,
233 const NotificationDetails& details) { 227 const NotificationDetails& details) {
234 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type); 228 DCHECK_EQ(chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, type);
235 LoadPlugins(); 229 LoadPlugins();
236 } 230 }
237 231
238 void PluginsDOMHandler::LoadPluginsOnFileThread( 232 void PluginsDOMHandler::LoadPlugins() {
239 std::vector<PluginGroup>* groups, 233 if (weak_ptr_factory_.HasWeakPtrs())
240 Task* task) { 234 return;
241 webkit::npapi::PluginList::Singleton()->GetPluginGroups(true, groups);
242 235
243 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, task); 236 PluginService::GetInstance()->GetPluginGroups(
244 BrowserThread::PostTask( 237 base::Bind(&PluginsDOMHandler::PluginsLoaded,
245 BrowserThread::UI, 238 weak_ptr_factory_.GetWeakPtr()));
246 FROM_HERE,
247 NewRunnableFunction(&PluginsDOMHandler::EnsurePluginGroupsDeleted,
248 groups));
249 } 239 }
250 240
251 void PluginsDOMHandler::EnsurePluginGroupsDeleted( 241 void PluginsDOMHandler::PluginsLoaded(const std::vector<PluginGroup> groups) {
jam 2011/09/21 00:04:51 reference
252 std::vector<PluginGroup>* groups) {
253 delete groups;
254 }
255
256 void PluginsDOMHandler::LoadPlugins() {
257 if (!get_plugins_factory_.empty())
258 return;
259
260 std::vector<PluginGroup>* groups = new std::vector<PluginGroup>;
261 Task* task = get_plugins_factory_.NewRunnableMethod(
262 &PluginsDOMHandler::PluginsLoaded, groups);
263
264 BrowserThread::PostTask(
265 BrowserThread::FILE,
266 FROM_HERE,
267 NewRunnableFunction(
268 &PluginsDOMHandler::LoadPluginsOnFileThread, groups, task));
269 }
270
271 void PluginsDOMHandler::PluginsLoaded(const std::vector<PluginGroup>* groups) {
272 PluginPrefs* plugin_prefs = 242 PluginPrefs* plugin_prefs =
273 PluginPrefs::GetForProfile(Profile::FromWebUI(web_ui_)); 243 PluginPrefs::GetForProfile(Profile::FromWebUI(web_ui_));
274 244
275 bool all_plugins_enabled_by_policy = true; 245 bool all_plugins_enabled_by_policy = true;
276 bool all_plugins_disabled_by_policy = true; 246 bool all_plugins_disabled_by_policy = true;
277 247
278 // Construct DictionaryValues to return to the UI 248 // Construct DictionaryValues to return to the UI
279 ListValue* plugin_groups_data = new ListValue(); 249 ListValue* plugin_groups_data = new ListValue();
280 for (size_t i = 0; i < groups->size(); ++i) { 250 for (size_t i = 0; i < groups.size(); ++i) {
281 ListValue* plugin_files = new ListValue(); 251 ListValue* plugin_files = new ListValue();
282 const PluginGroup& group = (*groups)[i]; 252 const PluginGroup& group = groups[i];
283 string16 group_name = group.GetGroupName(); 253 string16 group_name = group.GetGroupName();
284 bool group_enabled = false; 254 bool group_enabled = false;
285 const WebPluginInfo* active_plugin = NULL; 255 const WebPluginInfo* active_plugin = NULL;
286 for (size_t j = 0; j < group.web_plugin_infos().size(); ++j) { 256 for (size_t j = 0; j < group.web_plugin_infos().size(); ++j) {
287 const WebPluginInfo& group_plugin = group.web_plugin_infos()[j]; 257 const WebPluginInfo& group_plugin = group.web_plugin_infos()[j];
288 258
289 DictionaryValue* plugin_file = new DictionaryValue(); 259 DictionaryValue* plugin_file = new DictionaryValue();
290 plugin_file->SetString("name", group_plugin.name); 260 plugin_file->SetString("name", group_plugin.name);
291 plugin_file->SetString("description", group_plugin.desc); 261 plugin_file->SetString("description", group_plugin.desc);
292 plugin_file->SetString("path", group_plugin.path.value()); 262 plugin_file->SetString("path", group_plugin.path.value());
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 367
398 // static 368 // static
399 void PluginsUI::RegisterUserPrefs(PrefService* prefs) { 369 void PluginsUI::RegisterUserPrefs(PrefService* prefs) {
400 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails, 370 prefs->RegisterBooleanPref(prefs::kPluginsShowDetails,
401 false, 371 false,
402 PrefService::UNSYNCABLE_PREF); 372 PrefService::UNSYNCABLE_PREF);
403 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar, 373 prefs->RegisterBooleanPref(prefs::kPluginsShowSetReaderDefaultInfobar,
404 true, 374 true,
405 PrefService::UNSYNCABLE_PREF); 375 PrefService::UNSYNCABLE_PREF);
406 } 376 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698