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

Unified Diff: content/renderer/render_view_impl.cc

Issue 9108001: Adds support for calling postMessage on a frame living in a different renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use FromRoutingID Created 8 years, 7 months 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
« content/renderer/render_view_impl.h ('K') | « content/renderer/render_view_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/render_view_impl.cc
diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc
index 821fe0b78137a2915d462179ad40c697d8781717..5c2098edb0eea8a9d1ec630a8b93193e39c0522c 100644
--- a/content/renderer/render_view_impl.cc
+++ b/content/renderer/render_view_impl.cc
@@ -102,6 +102,8 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMEvent.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
@@ -128,6 +130,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerializedScriptValue.h"
jam 2012/05/14 06:41:45 nit: order
Charlie Reis 2012/05/14 17:38:43 Done.
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h"
@@ -204,6 +207,8 @@ using WebKit::WebCookieJar;
using WebKit::WebData;
using WebKit::WebDataSource;
using WebKit::WebDocument;
+using WebKit::WebDOMEvent;
+using WebKit::WebDOMMessageEvent;
using WebKit::WebDragData;
using WebKit::WebDragOperation;
using WebKit::WebDragOperationsMask;
@@ -252,6 +257,7 @@ using WebKit::WebScriptSource;
using WebKit::WebSearchableFormData;
using WebKit::WebSecurityOrigin;
using WebKit::WebSecurityPolicy;
+using WebKit::WebSerializedScriptValue;
using WebKit::WebSettings;
using WebKit::WebSharedWorker;
using WebKit::WebSize;
@@ -573,9 +579,9 @@ RenderViewImpl::RenderViewImpl(
// it's the browser asking us to set our opener to another RenderView.
// TODO(creis): This doesn't yet handle openers that are subframes.
if (opener_id != MSG_ROUTING_NONE && !is_renderer_created) {
- RenderViewImpl* opener_view = static_cast<RenderViewImpl*>(
- ChildThread::current()->ResolveRoute(opener_id));
- webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame());
+ RenderViewImpl* opener_view = FromRoutingID(opener_id);
+ if (opener_view)
+ webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame());
}
// If we are initially swapped out, navigate to kSwappedOutURL.
@@ -634,6 +640,12 @@ content::RenderView*
}
/*static*/
+RenderViewImpl* RenderViewImpl::FromRoutingID(int32 routing_id) {
+ return static_cast<RenderViewImpl*>(
+ ChildThread::current()->ResolveRoute(routing_id));
+}
+
+/*static*/
void content::RenderView::ForEach(content::RenderViewVisitor* visitor) {
ViewMap* views = g_view_map.Pointer();
for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
@@ -803,6 +815,7 @@ bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
OnResetPageEncodingToDefault)
IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
+ IPC_MESSAGE_HANDLER(ViewMsg_PostMessageEvent, OnPostMessageEvent)
IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
@@ -3525,6 +3538,32 @@ void RenderViewImpl::dispatchIntent(
routing_id_, intent_data, id));
}
+bool RenderViewImpl::willCheckAndDispatchMessageEvent(
+ WebKit::WebFrame* source,
+ WebKit::WebSecurityOrigin target_origin,
+ WebKit::WebDOMMessageEvent event) {
+ if (!is_swapped_out_)
+ return false;
+
+ ViewHostMsg_PostMessage_Params params;
+ params.data = event.data().toString();
+ params.source_origin = event.origin();
+ if (!target_origin.isNull())
+ params.target_origin = target_origin.toString();
+
+ // Include the routing ID for the source frame, which the browser process
+ // will translate into the routing ID for the equivalent frame in the target
+ // process.
+ // TODO(creis): Support source subframes.
+ params.source_routing_id = MSG_ROUTING_NONE;
+ RenderViewImpl* source_view = FromWebView(source->view());
+ if (source_view)
+ params.source_routing_id = source_view->routing_id();
+
+ Send(new ViewHostMsg_RouteMessageEvent(routing_id_, params));
+ return true;
+}
+
void RenderViewImpl::willOpenSocketStream(
WebSocketStreamHandle* handle) {
SocketStreamHandleData::AddToHandle(handle, routing_id_);
@@ -4197,6 +4236,40 @@ void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
EvaluateScript(frame_xpath, jscript, id, notify_result);
}
+void RenderViewImpl::OnPostMessageEvent(
+ const ViewHostMsg_PostMessage_Params& params) {
+ // TODO(creis): Support sending to subframes.
+ WebFrame *frame = webview()->mainFrame();
+
+ // Find the source frame if it exists.
+ // TODO(creis): Support source subframes.
+ WebFrame* source_frame = NULL;
+ if (params.source_routing_id != MSG_ROUTING_NONE) {
+ RenderViewImpl* source_view = FromRoutingID(params.source_routing_id);
+ if (source_view)
+ source_frame = source_view->webview()->mainFrame();
+ }
+
+ // Create an event with the message. The final parameter to initMessageEvent
+ // is the last event ID, which is not used with postMessage.
+ WebDOMEvent event = frame->document().createEvent("MessageEvent");
+ WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>();
+ msg_event.initMessageEvent("message",
+ // |canBubble| and |cancellable| are always false
+ false, false,
+ WebSerializedScriptValue::fromString(params.data),
+ params.source_origin, source_frame, "");
+
+ // We must pass in the target_origin to do the security check on this side,
+ // since it may have changed since the original postMessage call was made.
+ WebSecurityOrigin target_origin;
+ if (!params.target_origin.empty()) {
+ target_origin =
+ WebSecurityOrigin::createFromString(WebString(params.target_origin));
+ }
+ frame->dispatchMessageEventWithOriginCheck(target_origin, msg_event);
+}
+
void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
const std::string& css) {
WebFrame* frame = GetChildFrame(frame_xpath);
« content/renderer/render_view_impl.h ('K') | « content/renderer/render_view_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698