Commit 8d7587e4 authored by sgurun@chromium.org's avatar sgurun@chromium.org

Start changing WebDOMMessageEvent for using target execution context.

Message ports were using the source frame's execution context
rather than the targets when ports were transferred from a frame
to another. This seems to be leaky and also creates difficulties
when implementing message port support for android webview
and OOPIF. Use the target instead.

This is patch 1 of 3. The next CL will move chromium code to
use newly introduced method and the third CL will delete
the old methods.

BUG=473258

Review URL: https://codereview.chromium.org/1289033003

git-svn-id: svn://svn.chromium.org/blink/trunk@200735 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 1e7bf7d4
......@@ -37,24 +37,25 @@
#include "core/events/MessageEvent.h"
#include "core/frame/LocalDOMWindow.h"
#include "public/platform/WebString.h"
#include "public/web/WebDocument.h"
#include "public/web/WebFrame.h"
#include "public/web/WebSerializedScriptValue.h"
#include "web/WebLocalFrameImpl.h"
namespace blink {
void WebDOMMessageEvent::initMessageEvent(const WebString& type, bool canBubble, bool cancelable, const WebSerializedScriptValue& messageData, const WebString& origin, const WebFrame* sourceFrame, const WebString& lastEventId, const WebMessagePortChannelArray& webChannels)
void WebDOMMessageEvent::initMessageEvent(const WebString& type, bool canBubble, bool cancelable, const WebSerializedScriptValue& messageData, const WebString& origin, const WebFrame* sourceFrame, const WebDocument& targetDocument, const WebString& lastEventId, const WebMessagePortChannelArray& webChannels)
{
ASSERT(m_private.get());
ASSERT(isMessageEvent());
DOMWindow* window = nullptr;
// TODO(alexmos): Figure out if this is the right thing to do.
if (sourceFrame)
window = toCoreFrame(sourceFrame)->domWindow();
MessagePortArray* ports = nullptr;
// TODO(alexmos): make ports work properly with OOPIF.
if (sourceFrame && sourceFrame->isWebLocalFrame())
ports = MessagePort::toMessagePortArray(toLocalDOMWindow(window)->document(), webChannels);
if (!targetDocument.isNull()) {
RefPtrWillBeRawPtr<Document> coreDocument = PassRefPtrWillBeRawPtr<Document>(targetDocument);
ports = MessagePort::toMessagePortArray(coreDocument.get(), webChannels);
}
// Use an empty array for |ports| when it is null because this function
// is used to implement postMessage().
if (!ports)
......@@ -62,6 +63,16 @@ void WebDOMMessageEvent::initMessageEvent(const WebString& type, bool canBubble,
unwrap<MessageEvent>()->initMessageEvent(type, canBubble, cancelable, messageData, origin, lastEventId, window, ports);
}
void WebDOMMessageEvent::initMessageEvent(const WebString& type, bool canBubble, bool cancelable, const WebSerializedScriptValue& messageData, const WebString& origin, const WebFrame* sourceFrame, const WebString& lastEventId, const WebMessagePortChannelArray& webChannels)
{
WebDocument document;
if (sourceFrame && sourceFrame->isWebLocalFrame()) {
DOMWindow* window = toCoreFrame(sourceFrame)->domWindow();
document = toLocalDOMWindow(window)->document();
}
initMessageEvent(type, canBubble, cancelable, messageData, origin, sourceFrame, document, lastEventId, webChannels);
}
WebSerializedScriptValue WebDOMMessageEvent::data() const
{
return WebSerializedScriptValue(constUnwrap<MessageEvent>()->dataAsSerializedScriptValue());
......
......@@ -810,10 +810,11 @@ TEST_P(ParameterizedWebFrameTest, DispatchMessageEventWithOriginCheck)
// Send a message with the correct origin.
WebSecurityOrigin correctOrigin(WebSecurityOrigin::create(toKURL(m_baseURL)));
WebDOMEvent event = webViewHelper.webView()->mainFrame()->document().createEvent("MessageEvent");
WebDocument document = webViewHelper.webView()->mainFrame()->document();
WebDOMEvent event = document.createEvent("MessageEvent");
WebDOMMessageEvent message = event.to<WebDOMMessageEvent>();
WebSerializedScriptValue data(WebSerializedScriptValue::fromString("foo"));
message.initMessageEvent("message", false, false, data, "http://origin.com", 0, "");
message.initMessageEvent("message", false, false, data, "http://origin.com", 0, document, "");
webViewHelper.webView()->mainFrame()->dispatchMessageEventWithOriginCheck(correctOrigin, message);
// Send another message with incorrect origin.
......
......@@ -47,6 +47,8 @@ class WebString;
class WebDOMMessageEvent : public WebDOMEvent {
public:
WebDOMMessageEvent() { }
BLINK_EXPORT void initMessageEvent(const WebString& type, bool canBubble, bool cancelable, const WebSerializedScriptValue& messageData, const WebString& origin, const WebFrame* sourceFrame, const WebDocument& targetDocument, const WebString& lastEventId, const WebMessagePortChannelArray& channels = WebMessagePortChannelArray());
// DEPRECATED: Use the initMessageEvent method above. This method will be removed.
BLINK_EXPORT void initMessageEvent(const WebString& type, bool canBubble, bool cancelable, const WebSerializedScriptValue& messageData, const WebString& origin, const WebFrame* sourceFrame, const WebString& lastEventId, const WebMessagePortChannelArray& channels = WebMessagePortChannelArray());
BLINK_EXPORT WebSerializedScriptValue data() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment