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

Unified Diff: chrome/browser/automation/automation_provider_observers.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
Index: chrome/browser/automation/automation_provider_observers.cc
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc
index aa0fe0ba01689bded2e9a251ec89759a2463ebdd..c0f69d539ff0f9c9761144b863f13ba350b0310b 100644
--- a/chrome/browser/automation/automation_provider_observers.cc
+++ b/chrome/browser/automation/automation_provider_observers.cc
@@ -574,8 +574,28 @@ ExtensionReadyNotificationObserver::ExtensionReadyNotificationObserver(
service_(service),
automation_(automation->AsWeakPtr()),
id_(id),
+ use_json_(false),
reply_message_(reply_message),
extension_(NULL) {
+ Init();
+}
+
+ExtensionReadyNotificationObserver::ExtensionReadyNotificationObserver(
+ ExtensionProcessManager* manager, ExtensionService* service,
+ AutomationProvider* automation, IPC::Message* reply_message)
+ : manager_(manager),
+ service_(service),
+ automation_(automation->AsWeakPtr()),
+ use_json_(true),
+ reply_message_(reply_message),
+ extension_(NULL) {
+ Init();
+}
+
+ExtensionReadyNotificationObserver::~ExtensionReadyNotificationObserver() {
+}
+
+void ExtensionReadyNotificationObserver::Init() {
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
content::NotificationService::AllSources());
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
@@ -588,9 +608,6 @@ ExtensionReadyNotificationObserver::ExtensionReadyNotificationObserver(
content::NotificationService::AllSources());
}
-ExtensionReadyNotificationObserver::~ExtensionReadyNotificationObserver() {
-}
-
void ExtensionReadyNotificationObserver::Observe(
int type, const content::NotificationSource& source,
const content::NotificationDetails& details) {
@@ -606,8 +623,13 @@ void ExtensionReadyNotificationObserver::Observe(
if (!extension_ || !DidExtensionHostsStopLoading(manager_))
return;
break;
- case chrome::NOTIFICATION_EXTENSION_LOADED:
- extension_ = content::Details<const Extension>(details).ptr();
+ case chrome::NOTIFICATION_EXTENSION_LOADED: {
dennis_jeffrey 2011/11/22 23:32:16 Is there a reason this block is enclosed in braces
kkania 2011/11/23 17:31:23 I need the brace because I am defining a new var i
+ const Extension* loaded_extension =
+ content::Details<const Extension>(details).ptr();
+ // Only track internal extension loads.
+ if (loaded_extension->location() != Extension::INTERNAL)
+ return;
+ extension_ = loaded_extension;
if (!DidExtensionHostsStopLoading(manager_))
return;
// For some reason, the background ExtensionHost is not yet
@@ -617,6 +639,7 @@ void ExtensionReadyNotificationObserver::Observe(
if (!service_->IsBackgroundPageReady(extension_))
return;
break;
+ }
case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR:
case chrome::NOTIFICATION_EXTENSION_LOAD_ERROR:
case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED:
@@ -626,21 +649,27 @@ void ExtensionReadyNotificationObserver::Observe(
break;
}
- if (id_ == AutomationMsg_InstallExtension::ID) {
- // A handle of zero indicates an error.
- int extension_handle = 0;
- if (extension_)
- extension_handle = automation_->AddExtension(extension_);
- AutomationMsg_InstallExtension::WriteReplyParams(
- reply_message_.get(), extension_handle);
- } else if (id_ == AutomationMsg_EnableExtension::ID) {
- AutomationMsg_EnableExtension::WriteReplyParams(reply_message_.get(), true);
+ if (use_json_) {
+ DictionaryValue* dict = new DictionaryValue();
+ dict->SetString("id", extension_->id());
+ AutomationJSONReply(automation_, reply_message_.release())
+ .SendSuccess(dict);
} else {
- NOTREACHED();
- LOG(ERROR) << "Cannot write reply params for unknown message id.";
+ if (id_ == AutomationMsg_InstallExtension::ID) {
+ // A handle of zero indicates an error.
+ int extension_handle = 0;
+ if (extension_)
+ extension_handle = automation_->AddExtension(extension_);
+ AutomationMsg_InstallExtension::WriteReplyParams(
+ reply_message_.get(), extension_handle);
+ } else if (id_ == AutomationMsg_EnableExtension::ID) {
+ AutomationMsg_EnableExtension::WriteReplyParams(
+ reply_message_.get(), true);
+ } else {
+ LOG(ERROR) << "Cannot write reply params for unknown message id.";
+ }
+ automation_->Send(reply_message_.release());
}
-
- automation_->Send(reply_message_.release());
delete this;
}

Powered by Google App Engine
This is Rietveld 408576698