summaryrefslogtreecommitdiffstats
path: root/chrome_frame/chrome_frame_automation.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome_frame/chrome_frame_automation.cc')
-rw-r--r--chrome_frame/chrome_frame_automation.cc220
1 files changed, 92 insertions, 128 deletions
diff --git a/chrome_frame/chrome_frame_automation.cc b/chrome_frame/chrome_frame_automation.cc
index bccdcc8..8d89cbd 100644
--- a/chrome_frame/chrome_frame_automation.cc
+++ b/chrome_frame/chrome_frame_automation.cc
@@ -24,6 +24,7 @@
#include "chrome/test/automation/tab_proxy.h"
#include "chrome_frame/chrome_launcher.h"
#include "chrome_frame/utils.h"
+#include "chrome_frame/sync_msg_reply_dispatcher.h"
#ifdef NDEBUG
int64 kAutomationServerReasonableLaunchDelay = 1000; // in milliseconds
@@ -91,135 +92,33 @@ class ChromeFrameAutomationProxyImpl::TabProxyNotificationMessageFilter
std::list<AutomationHandle> tabs_list_;
};
-// Class that maintains context during the async load/install extension
-// operation. When done, InstallExtensionComplete is posted back to the UI
-// thread so that the users of ChromeFrameAutomationClient can be notified.
-class InstallExtensionContext
- : public SyncMessageReplyDispatcher::SyncMessageCallContext {
- public:
- typedef Tuple1<AutomationMsg_ExtensionResponseValues> output_type;
-
- InstallExtensionContext(ChromeFrameAutomationClient* client,
- const FilePath& crx_path, void* user_data) : client_(client),
- crx_path_(crx_path), user_data_(user_data) {
- }
-
- ~InstallExtensionContext() {
- }
-
- void Completed(AutomationMsg_ExtensionResponseValues res) {
- client_->PostTask(FROM_HERE, NewRunnableMethod(client_.get(),
- &ChromeFrameAutomationClient::InstallExtensionComplete, crx_path_,
- user_data_, res));
- }
-
- private:
- scoped_refptr<ChromeFrameAutomationClient> client_;
- FilePath crx_path_;
- void* user_data_;
-};
-
-// Class that maintains context during the async retrieval of fetching the
-// list of enabled extensions. When done, GetEnabledExtensionsComplete is
-// posted back to the UI thread so that the users of
-// ChromeFrameAutomationClient can be notified.
-class GetEnabledExtensionsContext
- : public SyncMessageReplyDispatcher::SyncMessageCallContext {
- public:
- typedef Tuple1<std::vector<FilePath> > output_type;
-
- GetEnabledExtensionsContext(
- ChromeFrameAutomationClient* client, void* user_data) : client_(client),
- user_data_(user_data) {
- extension_directories_ = new std::vector<FilePath>();
- }
-
- ~GetEnabledExtensionsContext() {
- // ChromeFrameAutomationClient::GetEnabledExtensionsComplete takes
- // ownership of extension_directories_.
- }
-
- std::vector<FilePath>* extension_directories() {
- return extension_directories_;
- }
-
- void Completed(
- std::vector<FilePath> result) {
- (*extension_directories_) = result;
- client_->PostTask(FROM_HERE, NewRunnableMethod(client_.get(),
- &ChromeFrameAutomationClient::GetEnabledExtensionsComplete,
- user_data_, extension_directories_));
- }
-
- private:
- scoped_refptr<ChromeFrameAutomationClient> client_;
- std::vector<FilePath>* extension_directories_;
- void* user_data_;
-};
-
-// Class that maintains contextual information for the create and connect
-// external tab operations.
-class CreateExternalTabContext
- : public SyncMessageReplyDispatcher::SyncMessageCallContext {
- public:
- typedef Tuple3<HWND, HWND, int> output_type;
- explicit CreateExternalTabContext(ChromeFrameAutomationClient* client)
- : client_(client) {
- }
-
- void Completed(HWND chrome_window, HWND tab_window, int tab_handle) {
- client_->PostTask(FROM_HERE,
- NewRunnableMethod(client_.get(),
- &ChromeFrameAutomationClient::CreateExternalTabComplete,
- chrome_window, tab_window, tab_handle));
- }
-
- private:
- scoped_refptr<ChromeFrameAutomationClient> client_;
-};
-
-// This class maintains context information for the BeginNavigate operations
-// pertaining to the external tab.
-class BeginNavigateContext
- : public SyncMessageReplyDispatcher::SyncMessageCallContext {
- public:
- explicit BeginNavigateContext(ChromeFrameAutomationClient* client)
- : client_(client) {}
-
- typedef Tuple1<AutomationMsg_NavigationResponseValues> output_type;
-
- void Completed(AutomationMsg_NavigationResponseValues response) {
- client_->BeginNavigateCompleted(response);
- }
-
- private:
- scoped_refptr<ChromeFrameAutomationClient> client_;
-};
-
class ChromeFrameAutomationProxyImpl::CFMsgDispatcher
: public SyncMessageReplyDispatcher {
public:
CFMsgDispatcher() : SyncMessageReplyDispatcher() {}
protected:
virtual bool HandleMessageType(const IPC::Message& msg,
- SyncMessageCallContext* context) {
- switch (context->message_type()) {
+ const MessageSent& origin) {
+ switch (origin.type) {
case AutomationMsg_CreateExternalTab::ID:
case AutomationMsg_ConnectExternalTab::ID:
- InvokeCallback<CreateExternalTabContext>(msg, context);
+ InvokeCallback<Tuple3<HWND, HWND, int> >(msg, origin);
break;
case AutomationMsg_NavigateExternalTabAtIndex::ID:
case AutomationMsg_NavigateInExternalTab::ID:
- InvokeCallback<BeginNavigateContext>(msg, context);
+ InvokeCallback<Tuple1<AutomationMsg_NavigationResponseValues> >(msg,
+ origin);
break;
case AutomationMsg_InstallExtension::ID:
- InvokeCallback<InstallExtensionContext>(msg, context);
+ InvokeCallback<Tuple1<AutomationMsg_ExtensionResponseValues> >(msg,
+ origin);
break;
case AutomationMsg_LoadExpandedExtension::ID:
- InvokeCallback<InstallExtensionContext>(msg, context);
+ InvokeCallback<Tuple1<AutomationMsg_ExtensionResponseValues> >(msg,
+ origin);
break;
case AutomationMsg_GetEnabledExtensions::ID:
- InvokeCallback<GetEnabledExtensionsContext>(msg, context);
+ InvokeCallback<Tuple1<std::vector<FilePath> > >(msg, origin);
break;
default:
NOTREACHED();
@@ -244,10 +143,9 @@ ChromeFrameAutomationProxyImpl::~ChromeFrameAutomationProxyImpl() {
TRACE_EVENT_END("chromeframe.automationproxy", this, "");
}
-void ChromeFrameAutomationProxyImpl::SendAsAsync(
- IPC::SyncMessage* msg,
- SyncMessageReplyDispatcher::SyncMessageCallContext* context, void* key) {
- sync_->Push(msg, context, key);
+void ChromeFrameAutomationProxyImpl::SendAsAsync(IPC::SyncMessage* msg,
+ void* callback, void* key) {
+ sync_->Push(msg, callback, key);
channel_->ChannelProxy::Send(msg);
}
@@ -715,8 +613,8 @@ bool ChromeFrameAutomationClient::NavigateToIndex(int index) {
IPC::SyncMessage* msg = new AutomationMsg_NavigateExternalTabAtIndex(
0, tab_->handle(), index, NULL);
- automation_server_->SendAsAsync(msg, new BeginNavigateContext(this),
- this);
+ automation_server_->SendAsAsync(msg, NewCallback(this,
+ &ChromeFrameAutomationClient::BeginNavigateCompleted), this);
return true;
}
@@ -758,7 +656,8 @@ void ChromeFrameAutomationClient::BeginNavigate(const GURL& url,
IPC::SyncMessage* msg =
new AutomationMsg_NavigateInExternalTab(0, tab_->handle(), url,
referrer, NULL);
- automation_server_->SendAsAsync(msg, new BeginNavigateContext(this), this);
+ automation_server_->SendAsAsync(msg, NewCallback(this,
+ &ChromeFrameAutomationClient::BeginNavigateCompleted), this);
RECT client_rect = {0};
chrome_frame_delegate_->GetBounds(&client_rect);
@@ -794,6 +693,32 @@ void ChromeFrameAutomationClient::FindInPage(const std::wstring& search_string,
automation_server_->SendAsAsync(msg, NULL, this);
}
+// Class that maintains context during the async load/install extension
+// operation. When done, InstallExtensionComplete is posted back to the UI
+// thread so that the users of ChromeFrameAutomationClient can be notified.
+class InstallExtensionContext {
+ public:
+ InstallExtensionContext(ChromeFrameAutomationClient* client,
+ const FilePath& crx_path, void* user_data) : client_(client),
+ crx_path_(crx_path), user_data_(user_data) {
+ }
+
+ ~InstallExtensionContext() {
+ }
+
+ void InstallExtensionComplete(AutomationMsg_ExtensionResponseValues res) {
+ client_->PostTask(FROM_HERE, NewRunnableMethod(client_.get(),
+ &ChromeFrameAutomationClient::InstallExtensionComplete, crx_path_,
+ user_data_, res));
+ delete this;
+ }
+
+ private:
+ scoped_refptr<ChromeFrameAutomationClient> client_;
+ FilePath crx_path_;
+ void* user_data_;
+};
+
void ChromeFrameAutomationClient::InstallExtension(
const FilePath& crx_path,
void* user_data) {
@@ -811,7 +736,8 @@ void ChromeFrameAutomationClient::InstallExtension(
new AutomationMsg_InstallExtension(0, crx_path, NULL);
// The context will delete itself after it is called.
- automation_server_->SendAsAsync(msg, ctx, this);
+ automation_server_->SendAsAsync(msg, NewCallback(ctx,
+ &InstallExtensionContext::InstallExtensionComplete), this);
}
void ChromeFrameAutomationClient::InstallExtensionComplete(
@@ -825,6 +751,42 @@ void ChromeFrameAutomationClient::InstallExtensionComplete(
}
}
+// Class that maintains context during the async retrieval of fetching the
+// list of enabled extensions. When done, GetEnabledExtensionsComplete is
+// posted back to the UI thread so that the users of
+// ChromeFrameAutomationClient can be notified.
+class GetEnabledExtensionsContext {
+ public:
+ GetEnabledExtensionsContext(
+ ChromeFrameAutomationClient* client, void* user_data) : client_(client),
+ user_data_(user_data) {
+ extension_directories_ = new std::vector<FilePath>();
+ }
+
+ ~GetEnabledExtensionsContext() {
+ // ChromeFrameAutomationClient::GetEnabledExtensionsComplete takes
+ // ownership of extension_directories_.
+ }
+
+ std::vector<FilePath>* extension_directories() {
+ return extension_directories_;
+ }
+
+ void GetEnabledExtensionsComplete(
+ std::vector<FilePath> result) {
+ (*extension_directories_) = result;
+ client_->PostTask(FROM_HERE, NewRunnableMethod(client_.get(),
+ &ChromeFrameAutomationClient::GetEnabledExtensionsComplete,
+ user_data_, extension_directories_));
+ delete this;
+ }
+
+ private:
+ scoped_refptr<ChromeFrameAutomationClient> client_;
+ std::vector<FilePath>* extension_directories_;
+ void* user_data_;
+};
+
void ChromeFrameAutomationClient::GetEnabledExtensions(void* user_data) {
if (automation_server_ == NULL) {
GetEnabledExtensionsComplete(user_data, &std::vector<FilePath>());
@@ -838,7 +800,8 @@ void ChromeFrameAutomationClient::GetEnabledExtensions(void* user_data) {
0, ctx->extension_directories());
// The context will delete itself after it is called.
- automation_server_->SendAsAsync(msg, ctx, this);
+ automation_server_->SendAsAsync(msg, NewCallback(ctx,
+ &GetEnabledExtensionsContext::GetEnabledExtensionsComplete), this);
}
void ChromeFrameAutomationClient::GetEnabledExtensionsComplete(
@@ -882,7 +845,8 @@ void ChromeFrameAutomationClient::LoadExpandedExtension(
new AutomationMsg_LoadExpandedExtension(0, path, NULL);
// The context will delete itself after it is called.
- automation_server_->SendAsAsync(msg, ctx, this);
+ automation_server_->SendAsAsync(msg, NewCallback(ctx,
+ &InstallExtensionContext::InstallExtensionComplete), this);
}
void ChromeFrameAutomationClient::CreateExternalTab() {
@@ -913,8 +877,8 @@ void ChromeFrameAutomationClient::CreateExternalTab() {
IPC::SyncMessage* message =
new AutomationMsg_CreateExternalTab(0, settings, NULL, NULL, NULL);
- automation_server_->SendAsAsync(message, new CreateExternalTabContext(this),
- this);
+ automation_server_->SendAsAsync(message, NewCallback(this,
+ &ChromeFrameAutomationClient::CreateExternalTabComplete), this);
}
void ChromeFrameAutomationClient::CreateExternalTabComplete(HWND chrome_window,
@@ -937,7 +901,8 @@ void ChromeFrameAutomationClient::CreateExternalTabComplete(HWND chrome_window,
tab_handle_ = tab_handle;
}
- InitializeComplete(launch_result);
+ PostTask(FROM_HERE, NewRunnableMethod(this,
+ &ChromeFrameAutomationClient::InitializeComplete, launch_result));
}
void ChromeFrameAutomationClient::SetEnableExtensionAutomation(
@@ -983,9 +948,8 @@ void ChromeFrameAutomationClient::LaunchComplete(
IPC::SyncMessage* message =
new AutomationMsg_ConnectExternalTab(0, external_tab_cookie_, true,
NULL, NULL, NULL);
- automation_server_->SendAsAsync(message,
- new CreateExternalTabContext(this),
- this);
+ automation_server_->SendAsAsync(message, NewCallback(this,
+ &ChromeFrameAutomationClient::CreateExternalTabComplete), this);
DLOG(INFO) << __FUNCTION__ << ": sending CreateExternalTabComplete";
}
}