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

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

Issue 8804011: WebDriver extension support in TestingAutomationProvider. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fix comments and minor issues 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 9cc328ea9e3886fba9c64116b15274b773ba3740..27c8474a3072690a4d459f7c77b4d16e31392728 100644
--- a/chrome/browser/automation/automation_provider_json.cc
+++ b/chrome/browser/automation/automation_provider_json.cc
@@ -10,6 +10,8 @@
#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_service.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/common/automation_id.h"
#include "chrome/common/automation_messages.h"
#include "content/browser/tab_contents/tab_contents.h"
@@ -135,12 +137,12 @@ bool GetBrowserAndTabFromJSONArgs(
bool GetAutomationIdFromJSONArgs(
DictionaryValue* args,
- const std::string& key_name,
+ const std::string& key,
AutomationId* id,
std::string* error) {
Value* id_value;
- if (!args->Get(key_name, &id_value)) {
- *error = base::StringPrintf("Missing parameter '%s'", key_name.c_str());
+ if (!args->Get(key, &id_value)) {
+ *error = base::StringPrintf("Missing parameter '%s'", key.c_str());
return false;
}
return AutomationId::FromValue(id_value, id, error);
@@ -169,3 +171,61 @@ bool GetRenderViewFromJSONArgs(
}
return true;
}
+
+namespace {
+
+bool GetExtensionFromJSONArgsHelper(
+ base::DictionaryValue* args,
+ const std::string& key,
+ Profile* profile,
+ bool include_disabled,
+ const Extension** extension,
+ std::string* error) {
+ std::string id;
+ if (!args->GetString(key, &id)) {
+ *error = base::StringPrintf("Missing or invalid key: %s", key.c_str());
+ return false;
+ }
+ ExtensionService* service = profile->GetExtensionService();
+ if (!service) {
+ *error = "No extensions service.";
+ return false;
+ }
+ if (!service->GetInstalledExtension(id)) {
+ // The extension ID does not correspond to any extension, whether crashed
+ // or not.
+ *error = base::StringPrintf("Extension %s is not installed.",
+ id.c_str());
+ return false;
+ }
+ const Extension* installed_extension =
+ service->GetExtensionById(id, include_disabled);
+ if (!installed_extension) {
+ *error = "Extension is disabled or has crashed.";
+ return false;
+ }
+ *extension = installed_extension;
+ return true;
+}
+
+} // namespace
+
+bool GetExtensionFromJSONArgs(
+ base::DictionaryValue* args,
+ const std::string& key,
+ Profile* profile,
+ const Extension** extension,
+ std::string* error) {
+ return GetExtensionFromJSONArgsHelper(
+ args, key, profile, true /* include_disabled */, extension, error);
+}
+
+bool GetEnabledExtensionFromJSONArgs(
+ base::DictionaryValue* args,
+ const std::string& key,
+ Profile* profile,
+ const Extension** extension,
+ std::string* error) {
+ return GetExtensionFromJSONArgsHelper(
+ args, key, profile, false /* include_disabled */, extension, error);
+}
« no previous file with comments | « chrome/browser/automation/automation_provider_json.h ('k') | chrome/browser/automation/automation_provider_observers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698