summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoriyengar@google.com <iyengar@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-15 21:22:15 +0000
committeriyengar@google.com <iyengar@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-15 21:22:15 +0000
commit3ac14a058599a1381224264784ad4000934f0119 (patch)
treec67e92c258ee19a378be5acfdb5741d2d2085bab
parentb5e3bbf106f2bda83900e526d07dfa10a2164c82 (diff)
downloadchromium_src-3ac14a058599a1381224264784ad4000934f0119.zip
chromium_src-3ac14a058599a1381224264784ad4000934f0119.tar.gz
chromium_src-3ac14a058599a1381224264784ad4000934f0119.tar.bz2
Added support for PostMessage from the automation framework to
the renderer. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@964 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/automation/automation_provider.h4
-rw-r--r--chrome/browser/render_view_host.cc4
-rw-r--r--chrome/common/render_messages_internal.h5
-rw-r--r--chrome/renderer/render_view.cc25
-rw-r--r--chrome/renderer/render_view.h4
-rw-r--r--chrome/test/automation/automation_messages_internal.h6
-rw-r--r--chrome/test/automation/tab_proxy.cc11
-rw-r--r--chrome/test/automation/tab_proxy.h5
8 files changed, 64 insertions, 0 deletions
diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h
index 1bde370..1fac8fa 100644
--- a/chrome/browser/automation/automation_provider.h
+++ b/chrome/browser/automation/automation_provider.h
@@ -311,6 +311,10 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
void AutocompleteEditGetMatches(const IPC::Message& message,
int autocomplete_edit_handle);
+ // Handler for PostMessage sent by the automation client.
+ void OnPostMessage(int handle, const std::string& target,
+ const std::string& message);
+
// Callback for history redirect queries.
virtual void OnRedirectQueryComplete(
HistoryService::Handle request_handle,
diff --git a/chrome/browser/render_view_host.cc b/chrome/browser/render_view_host.cc
index a6b0f9d..4db7793 100644
--- a/chrome/browser/render_view_host.cc
+++ b/chrome/browser/render_view_host.cc
@@ -1220,3 +1220,7 @@ void RenderViewHost::OnDebugDisconnect() {
}
}
+void RenderViewHost::PostMessage(const std::string& target,
+ const std::string& message) {
+ Send(new ViewMsg_PostMessage(routing_id_, target, message));
+}
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index 058dc7b..a8251a0 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -436,6 +436,11 @@ IPC_BEGIN_MESSAGES(View, 1)
IPC_MESSAGE_ROUTED1(ViewMsg_Repaint,
gfx::Size /* The view size to be repainted */)
+ // Posts a message to the renderer.
+ IPC_MESSAGE_ROUTED2(ViewMsg_PostMessage,
+ std::string /* The target for the message */,
+ std::string /* The message */)
+
IPC_END_MESSAGES(View)
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 0257927..22dd829 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -358,6 +358,7 @@ void RenderView::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose)
IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
+ IPC_MESSAGE_HANDLER(ViewMsg_PostMessage, OnPostMessage)
// Have the super handle all other messages.
IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
IPC_END_MESSAGE_MAP()
@@ -2490,6 +2491,30 @@ void RenderView::OnThemeChanged() {
DidInvalidateRect(webwidget_, view_rect);
}
+void RenderView::OnPostMessage(const std::string& target,
+ const std::string& message) {
+ if (message.empty())
+ return;
+
+ WebFrame* main_frame = webview()->GetMainFrame();
+ if (!main_frame)
+ return;
+
+ std::string script = "javascript:";
+ script += target;
+ script += "(";
+ script += "'";
+ script += message;
+ script += "'";
+ script += ");void(0);";
+
+ GURL script_url(script);
+ scoped_ptr<WebRequest> request(WebRequest::Create(script_url));
+ // TODO(iyengar)
+ // Need a mechanism to send results back.
+ main_frame->LoadRequest(request.get());
+}
+
std::string RenderView::GetAltHTMLForTemplate(
const DictionaryValue& error_strings, int template_resource_id) const {
const StringPiece template_html(
diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h
index 1aa945f..f774ff2 100644
--- a/chrome/renderer/render_view.h
+++ b/chrome/renderer/render_view.h
@@ -454,6 +454,10 @@ class RenderView : public RenderWidget, public WebViewDelegate,
// Notification about ui theme changes.
void OnThemeChanged();
+ // Handles messages posted by the browser.
+ void OnPostMessage(const std::string& target,
+ const std::string& message);
+
// Switches the frame's CSS media type to "print" and calculate the number of
// printed pages that are to be expected. |frame| will be used to calculate
// the number of expected pages for this frame only.
diff --git a/chrome/test/automation/automation_messages_internal.h b/chrome/test/automation/automation_messages_internal.h
index 82ae220..9c029c4 100644
--- a/chrome/test/automation/automation_messages_internal.h
+++ b/chrome/test/automation/automation_messages_internal.h
@@ -737,6 +737,12 @@ IPC_BEGIN_MESSAGES(Automation, 0)
IPC_MESSAGE_ROUTED1(AutomationMsg_OpenFindInPageRequest,
int /* tab_handle */)
+ // Posts a message to the chrome renderer.
+ IPC_MESSAGE_ROUTED3(AutomationMsg_PostMessage,
+ int /* automation handle */,
+ std::string /* target */,
+ std::string /* message */ )
+
// A message for an external host.
// |receiver| can be a receiving script and |message| is any
// arbitrary string that makes sense to the receiver.
diff --git a/chrome/test/automation/tab_proxy.cc b/chrome/test/automation/tab_proxy.cc
index c359f34..6171ddb 100644
--- a/chrome/test/automation/tab_proxy.cc
+++ b/chrome/test/automation/tab_proxy.cc
@@ -928,3 +928,14 @@ bool TabProxy::SavePage(const std::wstring& file_name,
return succeeded;
}
+
+void TabProxy::PostMessage(AutomationHandle handle,
+ const std::string& target,
+ const std::string& message) {
+ if (!is_valid())
+ return;
+
+ bool succeeded =
+ sender_->Send(new AutomationMsg_PostMessage(0, handle, target, message));
+ DCHECK(succeeded);
+}
diff --git a/chrome/test/automation/tab_proxy.h b/chrome/test/automation/tab_proxy.h
index 6c2e660..24f2cb3 100644
--- a/chrome/test/automation/tab_proxy.h
+++ b/chrome/test/automation/tab_proxy.h
@@ -265,6 +265,11 @@ class TabProxy : public AutomationResourceProxy {
const std::wstring& dir_path,
SavePackage::SavePackageType type);
+ // Posts a message to the external tab.
+ void PostMessage(AutomationHandle handle,
+ const std::string& target,
+ const std::string& message);
+
private:
DISALLOW_EVIL_CONSTRUCTORS(TabProxy);
};