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

Unified Diff: chrome/browser/automation/automation_provider_json.cc

Issue 8649004: Allow chromedriver to install an extension and get all installed extension IDs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/automation/automation_provider_json.h ('k') | chrome/browser/automation/automation_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/automation/automation_provider_json.cc
diff --git a/chrome/browser/automation/automation_provider_json.cc b/chrome/browser/automation/automation_provider_json.cc
index 0f0918dc40b9ba4b53485bd6dcbc5bb6ba39b963..e7acc408634c1f922002e8937b5f95f77cd94474 100644
--- a/chrome/browser/automation/automation_provider_json.cc
+++ b/chrome/browser/automation/automation_provider_json.cc
@@ -10,7 +10,18 @@
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/automation/automation_provider.h"
#include "chrome/browser/automation/automation_util.h"
+#include "chrome/browser/extensions/extension_host.h"
+#include "chrome/browser/extensions/extension_process_manager.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/sessions/restore_tab_helper.h"
+#include "chrome/browser/sessions/session_id.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/common/automation_messages.h"
+#include "chrome/common/chrome_view_types.h"
+#include "chrome/common/extensions/extension.h"
+#include "content/browser/tab_contents/tab_contents.h"
namespace {
@@ -57,6 +68,52 @@ void AutomationJSONReply::SendError(const std::string& error_message) {
message_ = NULL;
}
+// static
+bool AutomationId::FromValue(
+ Value* value, AutomationId* id, std::string* error) {
+ DictionaryValue* dict;
+ if (!value->GetAsDictionary(&dict)) {
+ *error = "automation ID must be a dictionary";
+ return false;
+ }
+ int type;
+ if (!dict->GetInteger("type", &type)) {
+ *error = "automation ID 'type' missing or invalid";
+ return false;
+ }
+ std::string type_id;
+ if (!dict->GetString("id", &type_id)) {
+ *error = "automation ID 'type_id' missing or invalid";
+ return false;
+ }
+ *id = AutomationId(static_cast<Type>(type), type_id);
+ return true;
+}
+
+AutomationId::AutomationId() : type_(kInvalidType) { }
+
+AutomationId::AutomationId(Type type, const std::string& id)
+ : type_(type), id_(id) { }
+
+Value* AutomationId::ToValue() const {
+ DictionaryValue* dict = new DictionaryValue();
+ dict->SetInteger("type", type_);
+ dict->SetString("id", id_);
+ return dict;
+}
+
+bool AutomationId::is_valid() const {
+ return type_ != kInvalidType;
+}
+
+AutomationId::Type AutomationId::type() const {
+ return type_;
+}
+
+const std::string& AutomationId::id() const {
+ return id_;
+}
+
bool GetBrowserFromJSONArgs(
DictionaryValue* args,
Browser** browser,
@@ -103,3 +160,39 @@ bool GetBrowserAndTabFromJSONArgs(
return GetBrowserFromJSONArgs(args, browser, error) &&
GetTabFromJSONArgs(args, tab, error);
}
+
+bool GetAutomationIdFromJSONArgs(
+ DictionaryValue* args,
+ AutomationId* id,
+ std::string* error) {
+ Value* id_value;
+ if (!args->Get("view_id", &id_value)) {
+ *error = "Missing or invalid 'view_id'";
+ return false;
+ }
+ return AutomationId::FromValue(id_value, id, error);
+}
+
+bool GetRenderViewFromJSONArgs(
+ DictionaryValue* args,
+ Profile* profile,
+ RenderViewHost** rvh,
+ std::string* error) {
+ Value* id_value;
+ if (args->Get("view_id", &id_value)) {
+ AutomationId id;
+ if (!AutomationId::FromValue(id_value, &id, error))
+ return false;
+ if (!automation_util::GetRenderViewForId(id, profile, rvh)) {
+ *error = "ID does not correspond to an open view";
+ return false;
+ }
+ } else {
+ // If the render view id is not specified, check for browser/tab indices.
+ TabContents* tab = NULL;
+ if (!GetTabFromJSONArgs(args, &tab, error))
+ return false;
+ *rvh = tab->render_view_host();
+ }
+ return true;
+}
« no previous file with comments | « chrome/browser/automation/automation_provider_json.h ('k') | chrome/browser/automation/automation_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698