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

Side by Side Diff: chrome/browser/dom_ui/plugins_ui.cc

Issue 1991005: (1) Group plugins with the same name together. (2) Show a download link for p... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 10 years, 6 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
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/plugin_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/dom_ui/plugins_ui.h" 5 #include "chrome/browser/dom_ui/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 "app/l10n_util.h" 11 #include "app/l10n_util.h"
12 #include "app/resource_bundle.h" 12 #include "app/resource_bundle.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/singleton.h" 15 #include "base/singleton.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/browser.h" 17 #include "chrome/browser/browser.h"
18 #include "chrome/browser/browser_window.h" 18 #include "chrome/browser/browser_window.h"
19 #include "chrome/browser/chrome_thread.h" 19 #include "chrome/browser/chrome_thread.h"
20 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" 20 #include "chrome/browser/dom_ui/chrome_url_data_manager.h"
21 #include "chrome/browser/plugin_updater.h"
21 #include "chrome/browser/pref_service.h" 22 #include "chrome/browser/pref_service.h"
22 #include "chrome/browser/profile.h" 23 #include "chrome/browser/profile.h"
23 #include "chrome/common/chrome_paths.h" 24 #include "chrome/common/chrome_paths.h"
24 #include "chrome/common/jstemplate_builder.h" 25 #include "chrome/common/jstemplate_builder.h"
25 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
26 #include "chrome/common/url_constants.h" 27 #include "chrome/common/url_constants.h"
27 #include "grit/browser_resources.h" 28 #include "grit/browser_resources.h"
28 #include "grit/generated_resources.h" 29 #include "grit/generated_resources.h"
29 #include "grit/theme_resources.h" 30 #include "grit/theme_resources.h"
30 #include "webkit/glue/plugins/plugin_list.h" 31 #include "webkit/glue/plugins/plugin_list.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // Strings used in the JsTemplate file. 64 // Strings used in the JsTemplate file.
64 DictionaryValue localized_strings; 65 DictionaryValue localized_strings;
65 localized_strings.SetString(L"pluginsTitle", 66 localized_strings.SetString(L"pluginsTitle",
66 l10n_util::GetString(IDS_PLUGINS_TITLE)); 67 l10n_util::GetString(IDS_PLUGINS_TITLE));
67 localized_strings.SetString(L"pluginsDetailsModeLink", 68 localized_strings.SetString(L"pluginsDetailsModeLink",
68 l10n_util::GetString(IDS_PLUGINS_DETAILS_MODE_LINK)); 69 l10n_util::GetString(IDS_PLUGINS_DETAILS_MODE_LINK));
69 localized_strings.SetString(L"pluginsNoneInstalled", 70 localized_strings.SetString(L"pluginsNoneInstalled",
70 l10n_util::GetString(IDS_PLUGINS_NONE_INSTALLED)); 71 l10n_util::GetString(IDS_PLUGINS_NONE_INSTALLED));
71 localized_strings.SetString(L"pluginDisabled", 72 localized_strings.SetString(L"pluginDisabled",
72 l10n_util::GetString(IDS_PLUGINS_DISABLED_PLUGIN)); 73 l10n_util::GetString(IDS_PLUGINS_DISABLED_PLUGIN));
74 localized_strings.SetString(L"pluginDownload",
75 l10n_util::GetString(IDS_PLUGINS_DOWNLOAD));
76 localized_strings.SetString(L"pluginName",
77 l10n_util::GetString(IDS_PLUGINS_NAME));
78 localized_strings.SetString(L"pluginPriority",
79 l10n_util::GetString(IDS_PLUGINS_PRIORITY));
73 localized_strings.SetString(L"pluginVersion", 80 localized_strings.SetString(L"pluginVersion",
74 l10n_util::GetString(IDS_PLUGINS_VERSION)); 81 l10n_util::GetString(IDS_PLUGINS_VERSION));
75 localized_strings.SetString(L"pluginDescription", 82 localized_strings.SetString(L"pluginDescription",
76 l10n_util::GetString(IDS_PLUGINS_DESCRIPTION)); 83 l10n_util::GetString(IDS_PLUGINS_DESCRIPTION));
77 localized_strings.SetString(L"pluginPath", 84 localized_strings.SetString(L"pluginPath",
78 l10n_util::GetString(IDS_PLUGINS_PATH)); 85 l10n_util::GetString(IDS_PLUGINS_PATH));
79 localized_strings.SetString(L"pluginMimeTypes", 86 localized_strings.SetString(L"pluginMimeTypes",
80 l10n_util::GetString(IDS_PLUGINS_MIME_TYPES)); 87 l10n_util::GetString(IDS_PLUGINS_MIME_TYPES));
81 localized_strings.SetString(L"pluginMimeTypesMimeType", 88 localized_strings.SetString(L"pluginMimeTypesMimeType",
82 l10n_util::GetString(IDS_PLUGINS_MIME_TYPES_MIME_TYPE)); 89 l10n_util::GetString(IDS_PLUGINS_MIME_TYPES_MIME_TYPE));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 136
130 // Callback for the "enablePlugin" message. 137 // Callback for the "enablePlugin" message.
131 void HandleEnablePluginMessage(const Value* value); 138 void HandleEnablePluginMessage(const Value* value);
132 139
133 // Callback for the "showTermsOfService" message. This really just opens a new 140 // Callback for the "showTermsOfService" message. This really just opens a new
134 // window with about:terms. Flash can't link directly to about:terms due to 141 // window with about:terms. Flash can't link directly to about:terms due to
135 // the security model. 142 // the security model.
136 void HandleShowTermsOfServiceMessage(const Value* value); 143 void HandleShowTermsOfServiceMessage(const Value* value);
137 144
138 private: 145 private:
139 // Creates a dictionary containing all the information about the given plugin;
140 // this is put into the list to "return" for the "requestPluginsData" message.
141 DictionaryValue* CreatePluginDetailValue(const WebPluginInfo& plugin);
142
143 // Creates a dictionary containing the important parts of the information 146 // Creates a dictionary containing the important parts of the information
144 // about the given plugin; this is put into a list and saved in prefs. 147 // about the given plugin; this is put into a list and saved in prefs.
145 DictionaryValue* CreatePluginSummaryValue(const WebPluginInfo& plugin); 148 DictionaryValue* CreatePluginSummaryValue(const WebPluginInfo& plugin);
146 149
147 // Update the user preferences to reflect the current (user-selected) state of 150 // Update the user preferences to reflect the current (user-selected) state of
148 // plugins. 151 // plugins.
149 void UpdatePreferences(); 152 void UpdatePreferences();
150 153
151 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler); 154 DISALLOW_COPY_AND_ASSIGN(PluginsDOMHandler);
152 }; 155 };
153 156
154 void PluginsDOMHandler::RegisterMessages() { 157 void PluginsDOMHandler::RegisterMessages() {
155 dom_ui_->RegisterMessageCallback("requestPluginsData", 158 dom_ui_->RegisterMessageCallback("requestPluginsData",
156 NewCallback(this, &PluginsDOMHandler::HandleRequestPluginsData)); 159 NewCallback(this, &PluginsDOMHandler::HandleRequestPluginsData));
157 dom_ui_->RegisterMessageCallback("enablePlugin", 160 dom_ui_->RegisterMessageCallback("enablePlugin",
158 NewCallback(this, &PluginsDOMHandler::HandleEnablePluginMessage)); 161 NewCallback(this, &PluginsDOMHandler::HandleEnablePluginMessage));
159 dom_ui_->RegisterMessageCallback("showTermsOfService", 162 dom_ui_->RegisterMessageCallback("showTermsOfService",
160 NewCallback(this, &PluginsDOMHandler::HandleShowTermsOfServiceMessage)); 163 NewCallback(this, &PluginsDOMHandler::HandleShowTermsOfServiceMessage));
161 } 164 }
162 165
163 void PluginsDOMHandler::HandleRequestPluginsData(const Value* value) { 166 void PluginsDOMHandler::HandleRequestPluginsData(const Value* value) {
164 DictionaryValue* results = new DictionaryValue(); 167 DictionaryValue* results = new DictionaryValue();
165 168
166 // Add plugins to the results structure. 169 // Grouped plugins.
167 ListValue* plugins_list = new ListValue(); 170 results->Set(L"plugins", PluginUpdater::GetInstance()->GetPluginGroupsData());
168
169 std::vector<WebPluginInfo> plugins;
170 NPAPI::PluginList::Singleton()->GetPlugins(false, &plugins);
171
172 for (std::vector<WebPluginInfo>::const_iterator it = plugins.begin();
173 it != plugins.end();
174 ++it) {
175 plugins_list->Append(CreatePluginDetailValue(*it));
176 }
177 results->Set(L"plugins", plugins_list);
178 171
179 dom_ui_->CallJavascriptFunction(L"returnPluginsData", *results); 172 dom_ui_->CallJavascriptFunction(L"returnPluginsData", *results);
180 } 173 }
181 174
182 void PluginsDOMHandler::HandleEnablePluginMessage(const Value* value) { 175 void PluginsDOMHandler::HandleEnablePluginMessage(const Value* value) {
183 // Be robust in accepting badness since plug-ins display HTML (hence 176 // Be robust in accepting badness since plug-ins display HTML (hence
184 // JavaScript). 177 // JavaScript).
185 if (!value->IsType(Value::TYPE_LIST)) 178 if (!value->IsType(Value::TYPE_LIST))
186 return; 179 return;
187 180
188 const ListValue* list = static_cast<const ListValue*>(value); 181 const ListValue* list = static_cast<const ListValue*>(value);
189 if (list->GetSize() != 2) 182 if (list->GetSize() != 3)
190 return; 183 return;
191 184
192 FilePath::StringType plugin_path;
193 std::string enable_str; 185 std::string enable_str;
194 if (!list->GetString(0, &plugin_path) || 186 std::string is_group_str;
195 !list->GetString(1, &enable_str)) 187 if (!list->GetString(1, &enable_str) ||
188 !list->GetString(2, &is_group_str))
196 return; 189 return;
197 190
198 if (enable_str == "true") 191 if (is_group_str == "true") {
199 NPAPI::PluginList::Singleton()->EnablePlugin(FilePath(plugin_path)); 192 std::wstring group_name;
200 else 193 if (!list->GetString(0, &group_name))
201 NPAPI::PluginList::Singleton()->DisablePlugin(FilePath(plugin_path)); 194 return;
202 195
203 // TODO(viettrungluu): It's morally wrong to do this here (it should be done 196 PluginUpdater::GetInstance()->EnablePluginGroup(enable_str == "true",
204 // by the plugins service), and we might also want to ensure that the plugins 197 WideToUTF16(group_name));
198 } else {
199 FilePath::StringType file_path;
200 if (!list->GetString(0, &file_path))
201 return;
202
203 PluginUpdater::GetInstance()->EnablePluginFile(enable_str == "true",
204 file_path);
205 }
206
207 // TODO(viettrungluu): We might also want to ensure that the plugins
205 // list is always written to prefs even when the user hasn't disabled a 208 // list is always written to prefs even when the user hasn't disabled a
206 // plugin. This will require refactoring the plugin list and service. 209 // plugin. <http://crbug.com/39101>
207 // <http://crbug.com/39101> 210 PluginUpdater::GetInstance()->UpdatePreferences(dom_ui_->GetProfile());
208 UpdatePreferences();
209 } 211 }
210 212
211 void PluginsDOMHandler::HandleShowTermsOfServiceMessage(const Value* value) { 213 void PluginsDOMHandler::HandleShowTermsOfServiceMessage(const Value* value) {
212 // Show it in a new browser window.... 214 // Show it in a new browser window....
213 Browser* browser = Browser::Create(dom_ui_->GetProfile()); 215 Browser* browser = Browser::Create(dom_ui_->GetProfile());
214 browser->OpenURL(GURL(chrome::kAboutTermsURL), 216 browser->OpenURL(GURL(chrome::kAboutTermsURL),
215 GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); 217 GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK);
216 browser->window()->Show(); 218 browser->window()->Show();
217 } 219 }
218 220
219 DictionaryValue* PluginsDOMHandler::CreatePluginDetailValue(
220 const WebPluginInfo& plugin) {
221 DictionaryValue* plugin_data = new DictionaryValue();
222 plugin_data->SetString(L"path", plugin.path.value());
223 plugin_data->SetString(L"name", plugin.name);
224 plugin_data->SetString(L"version", plugin.version);
225 plugin_data->SetString(L"description", plugin.desc);
226 plugin_data->SetBoolean(L"enabled", plugin.enabled);
227
228 ListValue* mime_types = new ListValue();
229 for (std::vector<WebPluginMimeType>::const_iterator type_it =
230 plugin.mime_types.begin();
231 type_it != plugin.mime_types.end();
232 ++type_it) {
233 DictionaryValue* mime_type = new DictionaryValue();
234 mime_type->SetString(L"mimeType", type_it->mime_type);
235 mime_type->SetString(L"description", type_it->description);
236
237 ListValue* file_extensions = new ListValue();
238 for (std::vector<std::string>::const_iterator ext_it =
239 type_it->file_extensions.begin();
240 ext_it != type_it->file_extensions.end();
241 ++ext_it) {
242 file_extensions->Append(new StringValue(*ext_it));
243 }
244 mime_type->Set(L"fileExtensions", file_extensions);
245
246 mime_types->Append(mime_type);
247 }
248 plugin_data->Set(L"mimeTypes", mime_types);
249
250 return plugin_data;
251 }
252
253 DictionaryValue* PluginsDOMHandler::CreatePluginSummaryValue(
254 const WebPluginInfo& plugin) {
255 DictionaryValue* plugin_data = new DictionaryValue();
256 plugin_data->SetString(L"path", plugin.path.value());
257 plugin_data->SetString(L"name", plugin.name);
258 plugin_data->SetString(L"version", plugin.version);
259 plugin_data->SetBoolean(L"enabled", plugin.enabled);
260 return plugin_data;
261 }
262
263 // TODO(viettrungluu): move this (and the registration of the prefs into the
264 // plugins service.
265 void PluginsDOMHandler::UpdatePreferences() {
266 PrefService* prefs = dom_ui_->GetProfile()->GetPrefs();
267
268 FilePath internal_dir;
269 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir))
270 prefs->SetFilePath(prefs::kPluginsLastInternalDirectory, internal_dir);
271
272 ListValue* plugins_list = prefs->GetMutableList(prefs::kPluginsPluginsList);
273 plugins_list->Clear();
274
275 std::vector<WebPluginInfo> plugins;
276 NPAPI::PluginList::Singleton()->GetPlugins(false, &plugins);
277
278 for (std::vector<WebPluginInfo>::const_iterator it = plugins.begin();
279 it != plugins.end();
280 ++it) {
281 plugins_list->Append(CreatePluginSummaryValue(*it));
282 }
283 }
284
285 } // namespace 221 } // namespace
286 222
287 /////////////////////////////////////////////////////////////////////////////// 223 ///////////////////////////////////////////////////////////////////////////////
288 // 224 //
289 // PluginsUI 225 // PluginsUI
290 // 226 //
291 /////////////////////////////////////////////////////////////////////////////// 227 ///////////////////////////////////////////////////////////////////////////////
292 228
293 PluginsUI::PluginsUI(TabContents* contents) : DOMUI(contents) { 229 PluginsUI::PluginsUI(TabContents* contents) : DOMUI(contents) {
294 AddMessageHandler((new PluginsDOMHandler())->Attach(this)); 230 AddMessageHandler((new PluginsDOMHandler())->Attach(this));
(...skipping 17 matching lines...) Expand all
312 248
313 // static 249 // static
314 void PluginsUI::RegisterUserPrefs(PrefService* prefs) { 250 void PluginsUI::RegisterUserPrefs(PrefService* prefs) {
315 FilePath internal_dir; 251 FilePath internal_dir;
316 PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir); 252 PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir);
317 prefs->RegisterFilePathPref(prefs::kPluginsLastInternalDirectory, 253 prefs->RegisterFilePathPref(prefs::kPluginsLastInternalDirectory,
318 internal_dir); 254 internal_dir);
319 255
320 prefs->RegisterListPref(prefs::kPluginsPluginsList); 256 prefs->RegisterListPref(prefs::kPluginsPluginsList);
321 } 257 }
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/plugin_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698