summaryrefslogtreecommitdiffstats
path: root/chrome/browser/automation
diff options
context:
space:
mode:
authornirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-06 08:17:05 +0000
committernirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-06 08:17:05 +0000
commitf7d48015503c80e2f29df6a59b39a179649a6a5f (patch)
tree42e2bebe5b47cb7448c6ee6e4deffa6e2fbcf1c7 /chrome/browser/automation
parent03e32def91b569982af74094c51651924d38e70c (diff)
downloadchromium_src-f7d48015503c80e2f29df6a59b39a179649a6a5f.zip
chromium_src-f7d48015503c80e2f29df6a59b39a179649a6a5f.tar.gz
chromium_src-f7d48015503c80e2f29df6a59b39a179649a6a5f.tar.bz2
Add hooks to fetch about:plugins info for PyAuto.
Also, hooks for to enable/disable a plugin. Add a test which excercises them. Review URL: http://codereview.chromium.org/1935003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46553 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation')
-rw-r--r--chrome/browser/automation/automation_provider.cc105
-rw-r--r--chrome/browser/automation/automation_provider.h12
2 files changed, 116 insertions, 1 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index b43ef22..24cff0f 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -85,6 +85,7 @@
#include "net/url_request/url_request_context.h"
#include "chrome/browser/automation/ui_controls.h"
#include "views/event.h"
+#include "webkit/glue/plugins/plugin_list.h"
#if defined(OS_WIN)
#include "chrome/browser/external_tab_container.h"
@@ -1773,6 +1774,102 @@ void AutomationProvider::SetPrefs(DictionaryValue* args,
Send(reply_message);
}
+// Sample json input: { "command": "GetPluginsInfo" }
+// Refer chrome/test/pyautolib/plugins_info.py for sample json output.
+void AutomationProvider::GetPluginsInfo(DictionaryValue* args,
+ IPC::Message* reply_message) {
+ std::string json_return;
+ bool reply_return = true;
+
+ std::vector<WebPluginInfo> plugins;
+ NPAPI::PluginList::Singleton()->GetPlugins(false, &plugins);
+ ListValue* items = new ListValue;
+ for (std::vector<WebPluginInfo>::const_iterator it = plugins.begin();
+ it != plugins.end();
+ ++it) {
+ DictionaryValue* item = new DictionaryValue;
+ item->SetString(L"name", it->name);
+ item->SetString(L"path", it->path.value());
+ item->SetString(L"version", it->version);
+ item->SetString(L"desc", it->desc);
+ item->SetBoolean(L"enabled", it->enabled);
+ // Add info about mime types.
+ ListValue* mime_types = new ListValue();
+ for (std::vector<WebPluginMimeType>::const_iterator type_it =
+ it->mime_types.begin();
+ type_it != it->mime_types.end();
+ ++type_it) {
+ DictionaryValue* mime_type = new DictionaryValue();
+ mime_type->SetString(L"mimeType", type_it->mime_type);
+ mime_type->SetString(L"description", type_it->description);
+
+ ListValue* file_extensions = new ListValue();
+ for (std::vector<std::string>::const_iterator ext_it =
+ type_it->file_extensions.begin();
+ ext_it != type_it->file_extensions.end();
+ ++ext_it) {
+ file_extensions->Append(new StringValue(*ext_it));
+ }
+ mime_type->Set(L"fileExtensions", file_extensions);
+
+ mime_types->Append(mime_type);
+ }
+ item->Set(L"mimeTypes", mime_types);
+ items->Append(item);
+ }
+ scoped_ptr<DictionaryValue> return_value(new DictionaryValue);
+ return_value->Set(L"plugins", items); // return_value owns items.
+
+ base::JSONWriter::Write(return_value.get(), false, &json_return);
+ AutomationMsg_SendJSONRequest::WriteReplyParams(
+ reply_message, json_return, reply_return);
+ Send(reply_message);
+}
+
+// Sample json input:
+// { "command": "EnablePlugin",
+// "path": "/Library/Internet Plug-Ins/Flash Player.plugin" }
+void AutomationProvider::EnablePlugin(DictionaryValue* args,
+ IPC::Message* reply_message) {
+ std::string json_return = "{}";
+ bool reply_return = true;
+ FilePath::StringType path;
+ if (!args->GetString(L"path", &path)) {
+ json_return = "{\"error\": \"path not specified.\"}";
+ reply_return = false;
+ } else if (!NPAPI::PluginList::Singleton()->EnablePlugin(FilePath(path))) {
+ json_return = StringPrintf("{\"error\": \"Could not enable plugin"
+ " for path %s.\"}", path.c_str());
+ reply_return = false;
+ }
+
+ AutomationMsg_SendJSONRequest::WriteReplyParams(
+ reply_message, json_return, reply_return);
+ Send(reply_message);
+}
+
+// Sample json input:
+// { "command": "DisablePlugin",
+// "path": "/Library/Internet Plug-Ins/Flash Player.plugin" }
+void AutomationProvider::DisablePlugin(DictionaryValue* args,
+ IPC::Message* reply_message) {
+ std::string json_return = "{}";
+ bool reply_return = true;
+ FilePath::StringType path;
+ if (!args->GetString(L"path", &path)) {
+ json_return = "{\"error\": \"path not specified.\"}";
+ reply_return = false;
+ } else if (!NPAPI::PluginList::Singleton()->DisablePlugin(FilePath(path))) {
+ json_return = StringPrintf("{\"error\": \"Could not enable plugin"
+ " for path %s.\"}", path.c_str());
+ reply_return = false;
+ }
+
+ AutomationMsg_SendJSONRequest::WriteReplyParams(
+ reply_message, json_return, reply_return);
+ Send(reply_message);
+}
+
void AutomationProvider::SendJSONRequest(
int handle,
std::string json_request,
@@ -1813,10 +1910,16 @@ void AutomationProvider::SendJSONRequest(
// Map json commands to their handlers.
std::map<std::string, JsonHandler> handler_map;
- handler_map["GetDownloadsInfo"] = &AutomationProvider::GetDownloadsInfo;
+ handler_map["DisablePlugin"] = &AutomationProvider::DisablePlugin;
+ handler_map["EnablePlugin"] = &AutomationProvider::EnablePlugin;
+ handler_map["GetPluginsInfo"] = &AutomationProvider::GetPluginsInfo;
+
handler_map["GetHistoryInfo"] = &AutomationProvider::GetHistoryInfo;
+
handler_map["GetPrefsInfo"] = &AutomationProvider::GetPrefsInfo;
handler_map["SetPrefs"] = &AutomationProvider::SetPrefs;
+
+ handler_map["GetDownloadsInfo"] = &AutomationProvider::GetDownloadsInfo;
handler_map["WaitForAllDownloadsToComplete"] =
&AutomationProvider::WaitForDownloadsToComplete;
diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h
index 518eb8b..83b52e6 100644
--- a/chrome/browser/automation/automation_provider.h
+++ b/chrome/browser/automation/automation_provider.h
@@ -353,6 +353,18 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
// Uses the JSON interface for input/output.
void GetPrefsInfo(DictionaryValue* args, IPC::Message* reply_message);
+ // Get info about plugins.
+ // Uses the JSON interface for input/output.
+ void GetPluginsInfo(DictionaryValue* args, IPC::Message* reply_message);
+
+ // Enable a plugin.
+ // Uses the JSON interface for input/output.
+ void EnablePlugin(DictionaryValue* args, IPC::Message* reply_message);
+
+ // Disable a plugin.
+ // Uses the JSON interface for input/output.
+ void DisablePlugin(DictionaryValue* args, IPC::Message* reply_message);
+
// Set prefs.
// Uses the JSON interface for input/output.
void SetPrefs(DictionaryValue* args, IPC::Message* reply_message);