summaryrefslogtreecommitdiffstats
path: root/chrome/test/automation/automation_proxy.cc
diff options
context:
space:
mode:
authorstoyan@chromium.org <stoyan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-28 19:12:46 +0000
committerstoyan@chromium.org <stoyan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-28 19:12:46 +0000
commit802376eb9aacca5284b76da93face73a9488bdb6 (patch)
tree705226a6750fed9a1429aaf07fe9c0a03303c759 /chrome/test/automation/automation_proxy.cc
parent319d4ae6c8b2236fa7e0acf218c533a5a93af5a6 (diff)
downloadchromium_src-802376eb9aacca5284b76da93face73a9488bdb6.zip
chromium_src-802376eb9aacca5284b76da93face73a9488bdb6.tar.gz
chromium_src-802376eb9aacca5284b76da93face73a9488bdb6.tar.bz2
Make automation proxy objects to ref_counted. That allows to process async notifications directly in channel background thread. Add support for listener-less ChannelProxy.
BUG=none TEST=none Review URL: http://codereview.chromium.org/113722 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17093 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/automation/automation_proxy.cc')
-rw-r--r--chrome/test/automation/automation_proxy.cc117
1 files changed, 91 insertions, 26 deletions
diff --git a/chrome/test/automation/automation_proxy.cc b/chrome/test/automation/automation_proxy.cc
index 9fc8193..13e0957 100644
--- a/chrome/test/automation/automation_proxy.cc
+++ b/chrome/test/automation/automation_proxy.cc
@@ -75,6 +75,62 @@ class AutomationMessageFilter : public IPC::ChannelProxy::MessageFilter {
AutomationProxy* server_;
};
+class TabProxyNotificationMessageFilter
+ : public IPC::ChannelProxy::MessageFilter {
+ public:
+ TabProxyNotificationMessageFilter(AutomationHandleTracker* tracker)
+ : tracker_ (tracker) {
+ }
+
+ virtual bool OnMessageReceived(const IPC::Message& message) {
+ if (message.is_sync())
+ return false;
+
+ if (message.is_reply())
+ return false;
+
+ bool tab_message = IsTabNotifyMessage(message);
+ if (tab_message == false)
+ return false;
+
+ // Read tab handle from the message.
+ int tab_handle = 0;
+ void* iter = NULL;
+ if (!message.ReadInt(&iter, &tab_handle))
+ return false;
+
+ // Get AddRef-ed pointer to corresponding TabProxy object
+ TabProxy* tab = static_cast<TabProxy*>(tracker_->GetResource(tab_handle));
+ if (tab) {
+ tab->OnMessageReceived(message);
+ tab->Release();
+ }
+ return true;
+ }
+
+ static bool IsTabNotifyMessage(const IPC::Message& message) {
+ bool tab_message = true;
+ IPC_BEGIN_MESSAGE_MAP(TabProxyNotificationMessageFilter, message)
+ IPC_MESSAGE_HANDLER_GENERIC(AutomationMsg_NavigationStateChanged, )
+ IPC_MESSAGE_HANDLER_GENERIC(AutomationMsg_UpdateTargetUrl, )
+#if defined(OS_WIN)
+ IPC_MESSAGE_HANDLER_GENERIC(AutomationMsg_HandleAccelerator, )
+#endif
+ IPC_MESSAGE_HANDLER_GENERIC(AutomationMsg_TabbedOut, )
+ IPC_MESSAGE_HANDLER_GENERIC(AutomationMsg_OpenURL, )
+ IPC_MESSAGE_HANDLER_GENERIC(AutomationMsg_DidNavigate, )
+ IPC_MESSAGE_HANDLER_GENERIC(AutomationMsg_NavigationFailed, )
+ IPC_MESSAGE_HANDLER_GENERIC(AutomationMsg_TabLoaded, )
+ IPC_MESSAGE_HANDLER_GENERIC(AutomationMsg_ForwardMessageToExternalHost, )
+
+ IPC_MESSAGE_UNHANDLED(tab_message = false);
+ IPC_END_MESSAGE_MAP()
+ return tab_message;
+ }
+
+ private:
+ AutomationHandleTracker* tracker_;
+};
} // anonymous namespace
@@ -339,8 +395,8 @@ bool AutomationProxy::WaitForURLDisplayed(GURL url, int wait_timeout) {
return false;
for (int i = 0; i < window_count; i++) {
- BrowserProxy* window = GetBrowserWindow(i);
- if (!window)
+ scoped_refptr<BrowserProxy> window = GetBrowserWindow(i);
+ if (!window.get())
break;
int tab_count;
@@ -348,8 +404,8 @@ bool AutomationProxy::WaitForURLDisplayed(GURL url, int wait_timeout) {
continue;
for (int j = 0; j < tab_count; j++) {
- TabProxy* tab = window->GetTab(j);
- if (!tab)
+ scoped_refptr<TabProxy> tab = window->GetTab(j);
+ if (!tab.get())
break;
GURL tab_url;
@@ -388,7 +444,7 @@ void AutomationProxy::OnChannelError() {
DLOG(ERROR) << "Channel error in AutomationProxy.";
}
-WindowProxy* AutomationProxy::GetActiveWindow() {
+scoped_refptr<WindowProxy> AutomationProxy::GetActiveWindow() {
int handle = 0;
if (!SendWithTimeout(new AutomationMsg_ActiveWindow(0, &handle),
@@ -396,10 +452,11 @@ WindowProxy* AutomationProxy::GetActiveWindow() {
return NULL;
}
- return new WindowProxy(this, tracker_.get(), handle);
+ return ProxyObjectFromHandle<WindowProxy>(handle);
}
-BrowserProxy* AutomationProxy::GetBrowserWindow(int window_index) {
+scoped_refptr<BrowserProxy> AutomationProxy::GetBrowserWindow(
+ int window_index) {
int handle = 0;
if (!SendWithTimeout(new AutomationMsg_BrowserWindow(0, window_index,
@@ -409,14 +466,10 @@ BrowserProxy* AutomationProxy::GetBrowserWindow(int window_index) {
return NULL;
}
- if (handle == 0) {
- return NULL;
- }
-
- return new BrowserProxy(this, tracker_.get(), handle);
+ return ProxyObjectFromHandle<BrowserProxy>(handle);
}
-BrowserProxy* AutomationProxy::FindNormalBrowserWindow() {
+scoped_refptr<BrowserProxy> AutomationProxy::FindNormalBrowserWindow() {
int handle = 0;
if (!SendWithTimeout(new AutomationMsg_FindNormalBrowserWindow(0, &handle),
@@ -424,14 +477,10 @@ BrowserProxy* AutomationProxy::FindNormalBrowserWindow() {
return NULL;
}
- if (handle == 0) {
- return NULL;
- }
-
- return new BrowserProxy(this, tracker_.get(), handle);
+ return ProxyObjectFromHandle<BrowserProxy>(handle);
}
-BrowserProxy* AutomationProxy::GetLastActiveBrowserWindow() {
+scoped_refptr<BrowserProxy> AutomationProxy::GetLastActiveBrowserWindow() {
int handle = 0;
if (!SendWithTimeout(new AutomationMsg_LastActiveBrowserWindow(
@@ -441,7 +490,7 @@ BrowserProxy* AutomationProxy::GetLastActiveBrowserWindow() {
return NULL;
}
- return new BrowserProxy(this, tracker_.get(), handle);
+ return ProxyObjectFromHandle<BrowserProxy>(handle);
}
#if defined(OS_POSIX)
@@ -491,11 +540,9 @@ bool AutomationProxy::OpenNewBrowserWindow(bool show) {
#if defined(OS_WIN)
// TODO(port): Replace HWNDs.
-TabProxy* AutomationProxy::CreateExternalTab(HWND parent,
- const gfx::Rect& dimensions,
- unsigned int style,
- bool incognito,
- HWND* external_tab_container) {
+scoped_refptr<TabProxy> AutomationProxy::CreateExternalTab(HWND parent,
+ const gfx::Rect& dimensions, unsigned int style, bool incognito,
+ HWND* external_tab_container) {
IPC::Message* response = NULL;
int handle = 0;
@@ -509,7 +556,25 @@ TabProxy* AutomationProxy::CreateExternalTab(HWND parent,
}
DCHECK(IsWindow(*external_tab_container));
-
+ DCHECK(tracker_->GetResource(handle) == NULL);
return new TabProxy(this, tracker_.get(), handle);
}
#endif // defined(OS_WIN)
+
+template <class T> scoped_refptr<T> AutomationProxy::ProxyObjectFromHandle(
+ int handle) {
+ if (!handle)
+ return NULL;
+
+ // Get AddRef-ed pointer to the object if handle is already seen.
+ T* p = static_cast<T*>(tracker_->GetResource(handle));
+ if (!p) {
+ p = new T(this, tracker_.get(), handle);
+ p->AddRef();
+ }
+
+ // Since there is no scoped_refptr::attach.
+ scoped_refptr<T> result;
+ result.swap(&p);
+ return result;
+}