Chromium Code Reviews| Index: content/renderer/render_view_impl.cc |
| diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc |
| index 6a9d750b053b4fee6ff8529bf6b1de8eb3157d0f..bd609207e3069ca810f5d673ef64b14349a082d9 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" |
| #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; |
| @@ -574,7 +580,8 @@ RenderViewImpl::RenderViewImpl( |
| 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()); |
| + if (opener_view) |
| + webview()->mainFrame()->setOpener(opener_view->webview()->mainFrame()); |
| } |
| // If we are initially swapped out, navigate to kSwappedOutURL. |
| @@ -802,6 +809,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) |
| @@ -3520,6 +3528,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_); |
| @@ -4192,6 +4226,41 @@ 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 = static_cast<RenderViewImpl*>( |
| + ChildThread::current()->ResolveRoute(params.source_routing_id)); |
|
Matt Perry
2012/05/11 21:59:34
Maybe move this to a RenderViewImpl::FromRoutingID
Charlie Reis
2012/05/11 22:36:02
Done.
|
| + 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); |