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

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

Issue 8790003: Allow the automation provider to accept an ID for performing render-view (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years 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
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..2d3848d8d2b4d6705f0ce75d35bdbf74ee854c35 100644
--- a/chrome/browser/automation/automation_provider_json.cc
+++ b/chrome/browser/automation/automation_provider_json.cc
@@ -10,6 +10,7 @@
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/automation/automation_provider.h"
#include "chrome/browser/automation/automation_util.h"
+#include "chrome/common/automation_id.h"
#include "chrome/common/automation_messages.h"
namespace {
@@ -61,15 +62,32 @@ bool GetBrowserFromJSONArgs(
DictionaryValue* args,
Browser** browser,
std::string* error) {
- int browser_index;
- if (!args->GetInteger("windex", &browser_index)) {
- *error = "'windex' missing or invalid";
- return false;
- }
- *browser = automation_util::GetBrowserAt(browser_index);
- if (!*browser) {
- *error = "Cannot locate browser from given index";
- return false;
+ if (args->HasKey("tab_id")) {
+ AutomationId id;
+ if (!GetAutomationIdFromJSONArgs(args, "tab_id", &id, error))
+ return false;
+ TabContents* tab;
+ if (!automation_util::GetTabForId(id, &tab)) {
+ *error = "'tab_id' does not refer to an open tab";
+ return false;
+ }
+ Browser* container = automation_util::GetBrowserForTab(tab);
+ if (!container) {
+ *error = "tab does not belong to an open browser";
+ return false;
+ }
+ *browser = container;
+ } else {
+ int browser_index;
+ if (!args->GetInteger("windex", &browser_index)) {
+ *error = "'windex' missing or invalid";
+ return false;
+ }
+ *browser = automation_util::GetBrowserAt(browser_index);
+ if (!*browser) {
+ *error = "Cannot locate browser from given index";
+ return false;
+ }
}
return true;
}
@@ -78,19 +96,29 @@ bool GetTabFromJSONArgs(
DictionaryValue* args,
TabContents** tab,
std::string* error) {
- int browser_index, tab_index;
- if (!args->GetInteger("windex", &browser_index)) {
- *error = "'windex' missing or invalid";
- return false;
- }
- if (!args->GetInteger("tab_index", &tab_index)) {
- *error = "'tab_index' missing or invalid";
- return false;
- }
- *tab = automation_util::GetTabContentsAt(browser_index, tab_index);
- if (!*tab) {
- *error = "Cannot locate tab from given indices";
- return false;
+ if (args->HasKey("tab_id")) {
+ AutomationId id;
+ if (!GetAutomationIdFromJSONArgs(args, "tab_id", &id, error))
+ return false;
+ if (!automation_util::GetTabForId(id, tab)) {
+ *error = "'tab_id' does not refer to an open tab";
+ return false;
+ }
+ } else {
+ int browser_index, tab_index;
+ if (!args->GetInteger("windex", &browser_index)) {
+ *error = "'windex' missing or invalid";
+ return false;
+ }
+ if (!args->GetInteger("tab_index", &tab_index)) {
+ *error = "'tab_index' missing or invalid";
+ return false;
+ }
+ *tab = automation_util::GetTabContentsAt(browser_index, tab_index);
+ if (!*tab) {
+ *error = "Cannot locate tab from given indices";
+ return false;
+ }
}
return true;
}
@@ -103,3 +131,40 @@ bool GetBrowserAndTabFromJSONArgs(
return GetBrowserFromJSONArgs(args, browser, error) &&
GetTabFromJSONArgs(args, tab, error);
}
+
+bool GetAutomationIdFromJSONArgs(
+ DictionaryValue* args,
+ const std::string& key_name,
+ AutomationId* id,
+ std::string* error) {
+ Value* id_value;
+ if (!args->Get(key_name, &id_value)) {
+ *error = base::StringPrintf("Missing or invalid '%s'", key_name.c_str());
+ 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;
+}

Powered by Google App Engine
This is Rietveld 408576698