Commit 77a58a92 authored by foolip's avatar foolip Committed by Commit bot

Remove window.postMessage(message, transferables, targetOrigin) legacy overload

Intent to Deprecate and Remove:
https://groups.google.com/a/chromium.org/d/msg/blink-dev/h4ooaB_Y9JE/nh7vXshGBwAJ

BUG=425896,640825
R=sigbjornf@opera.com,haraken@chromium.org
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2295863002
Cr-Commit-Position: refs/heads/master@{#417066}
parent 41481c71
...@@ -80,7 +80,7 @@ if (typeof(goog) != 'undefined' && goog.require) { ...@@ -80,7 +80,7 @@ if (typeof(goog) != 'undefined' && goog.require) {
} }
channel = new MessageChannel(); channel = new MessageChannel();
window.postMessage(PORT_SETUP_MSG, [channel.port2], '*'); window.postMessage(PORT_SETUP_MSG, '*', [channel.port2]);
channel.port1.onmessage = function(event) { channel.port1.onmessage = function(event) {
if (event.data == DISCONNECT_MSG) { if (event.data == DISCONNECT_MSG) {
channel = null; channel = null;
......
...@@ -38,7 +38,7 @@ if (typeof(goog) != 'undefined' && goog.require) { ...@@ -38,7 +38,7 @@ if (typeof(goog) != 'undefined' && goog.require) {
channel_.port1.onmessage = function(evt) { channel_.port1.onmessage = function(evt) {
cvox.MathJax.execMessage(evt.data); cvox.MathJax.execMessage(evt.data);
}; };
window.postMessage('cvox.MathJaxPortSetup', [channel_.port2], '*'); window.postMessage('cvox.MathJaxPortSetup', '*', [channel_.port2]);
}; };
......
CONSOLE WARNING: line 31: 'window.postMessage(message, transferables, targetOrigin)' is deprecated and will be removed in M54, around October 2016. Please use 'window.postMessage(message, targetOrigin, transferables)' instead. See https://www.chromestatus.com/features/5719033043222528 for more details.
Test that the second argument of window.postMessage is ignored or triggers an error if it is not a message port. You should see PASS message '1' through '7', followed by 'done', with messages 4-7 received below. Test that the second argument of window.postMessage is ignored or triggers an error if it is not a message port. You should see PASS message '1' through '7', followed by 'done', with messages 4-7 received below.
PASS Posting message ('1', 1): threw exception TypeError: Failed to execute 'postMessage' on 'Window': The 3rd argument is neither an array, nor does it have indexed properties. PASS Posting message ('1', 1): threw exception TypeError: Failed to execute 'postMessage' on 'Window': The 3rd argument is neither an array, nor does it have indexed properties.
PASS Posting message ('2', c): threw exception TypeError: Failed to execute 'postMessage' on 'Window': The 2nd argument is neither an array, nor does it have indexed properties. PASS Posting message ('2', c): threw exception TypeError: Failed to execute 'postMessage' on 'Window': The 3rd argument is neither an array, nor does it have indexed properties.
PASS Posting message ('3', [object Object]): threw exception TypeError: Failed to execute 'postMessage' on 'Window': The 3rd argument is neither an array, nor does it have indexed properties. PASS Posting message ('3', [object Object]): threw exception TypeError: Failed to execute 'postMessage' on 'Window': The 3rd argument is neither an array, nor does it have indexed properties.
PASS Posting message ('3a', *): threw exception TypeError: Failed to execute 'postMessage' on 'Window': The 2nd argument is neither an array, nor does it have indexed properties.
PASS Posting message ('4', [object Window]) did not throw an exception PASS Posting message ('4', [object Window]) did not throw an exception
PASS Posting message ('4a', *) did not throw an exception
PASS Posting message ('5', undefined) did not throw an exception PASS Posting message ('5', undefined) did not throw an exception
PASS Posting message ('5a', null): threw exception TypeError: Failed to execute 'postMessage' on 'Window': The 3rd argument is neither an array, nor does it have indexed properties. PASS Posting message ('5a', null): threw exception TypeError: Failed to execute 'postMessage' on 'Window': The 3rd argument is neither an array, nor does it have indexed properties.
PASS Posting message ('6', undefined) did not throw an exception PASS Posting message ('6', undefined) did not throw an exception
PASS Posting message ('7', [object MessagePort],[object MessagePort]) did not throw an exception PASS Posting message ('7', [object MessagePort],[object MessagePort]) did not throw an exception
PASS Posting message ('7a', *) did not throw an exception
PASS Posting message ('7', [object MessagePort],[object MessagePort]) did not throw an exception PASS Posting message ('7', [object MessagePort],[object MessagePort]) did not throw an exception
PASS Posting message ('2147483648', undefined) did not throw an exception PASS Posting message ('2147483648', undefined) did not throw an exception
PASS Posting message ('2147483648', null): threw exception TypeError: Failed to execute 'postMessage' on 'Window': The 3rd argument is neither an array, nor does it have indexed properties. PASS Posting message ('2147483648', null): threw exception TypeError: Failed to execute 'postMessage' on 'Window': The 3rd argument is neither an array, nor does it have indexed properties.
...@@ -35,11 +31,9 @@ PASS window.postMessage() threw exception TypeError: Failed to execute 'postMess ...@@ -35,11 +31,9 @@ PASS window.postMessage() threw exception TypeError: Failed to execute 'postMess
PASS window.postMessage('a') threw exception TypeError: Failed to execute 'postMessage' on 'Window': 2 arguments required, but only 1 present.. PASS window.postMessage('a') threw exception TypeError: Failed to execute 'postMessage' on 'Window': 2 arguments required, but only 1 present..
PASS Posting message ('done', undefined) did not throw an exception PASS Posting message ('done', undefined) did not throw an exception
Received message '4' with 0 ports. Received message '4' with 0 ports.
Received message '4a' with 0 ports.
Received message '5' with 0 ports. Received message '5' with 0 ports.
Received message '6' with 0 ports. Received message '6' with 0 ports.
Received message '7' with 2 ports. Received message '7' with 2 ports.
Received message '7a' with 2 ports.
Received message '7' with 2 ports. Received message '7' with 2 ports.
Received message '2147483648' with 0 ports. Received message '2147483648' with 0 ports.
Received message '[object MessagePort]' with 2 ports. Received message '[object MessagePort]' with 2 ports.
......
...@@ -48,18 +48,14 @@ function tryPostMessage(first, second, third, shouldFail) { ...@@ -48,18 +48,14 @@ function tryPostMessage(first, second, third, shouldFail) {
document.getElementById("description").innerHTML = "Test that the second argument of window.postMessage is ignored or triggers an error if it is not a message port. You should see PASS message '1' through '7', followed by 'done', with messages 4-7 received below.<br><br>"; document.getElementById("description").innerHTML = "Test that the second argument of window.postMessage is ignored or triggers an error if it is not a message port. You should see PASS message '1' through '7', followed by 'done', with messages 4-7 received below.<br><br>";
tryPostMessage('1', '*', 1, true); tryPostMessage('1', '*', 1, true);
tryPostMessage('2', '*', 'c', true); // Legacy overload resolution will consider 3rd argument to be the (string) origin. tryPostMessage('2', '*', 'c', true);
tryPostMessage('3', '*', { x: 1 }, true); tryPostMessage('3', '*', { x: 1 }, true);
tryPostMessage('3a', { x: 1 }, '*', true); // Legacy argument order.
tryPostMessage('4', '*', window); // Passes because window has a "length" attribute of value '0', so it looks like an array tryPostMessage('4', '*', window); // Passes because window has a "length" attribute of value '0', so it looks like an array
tryPostMessage('4a', window, '*'); // Legacy argument order.
tryPostMessage('5', '*', undefined); tryPostMessage('5', '*', undefined);
tryPostMessage('5a', '*', null, true); tryPostMessage('5a', '*', null, true);
tryPostMessage('6', '*', void 0); tryPostMessage('6', '*', void 0);
var channel1 = new MessageChannel; var channel1 = new MessageChannel;
tryPostMessageFunction(window.postMessage, '7', '*', [channel1.port1, channel1.port2]); tryPostMessageFunction(window.postMessage, '7', '*', [channel1.port1, channel1.port2]);
var channel1a = new MessageChannel;
tryPostMessageFunction(window.postMessage, '7a', [channel1a.port1, channel1a.port2], '*');
var channel2 = new MessageChannel; var channel2 = new MessageChannel;
tryPostMessageFunction(window.postMessage, '7', '*', [channel2.port1, channel2.port2]); tryPostMessageFunction(window.postMessage, '7', '*', [channel2.port1, channel2.port2]);
var channel3 = new MessageChannel; var channel3 = new MessageChannel;
......
...@@ -150,14 +150,6 @@ void V8Window::openerAttributeSetterCustom(v8::Local<v8::Value> value, const v8: ...@@ -150,14 +150,6 @@ void V8Window::openerAttributeSetterCustom(v8::Local<v8::Value> value, const v8:
} }
} }
static bool isLegacyTargetOriginDesignation(v8::Local<v8::Value> value)
{
if (value->IsString() || value->IsStringObject())
return true;
return false;
}
void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{ {
ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage", "Window", info.Holder(), info.GetIsolate()); ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage", "Window", info.Holder(), info.GetIsolate());
...@@ -185,24 +177,21 @@ void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value> ...@@ -185,24 +177,21 @@ void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value>
} }
// This function has variable arguments and can be: // This function has variable arguments and can be:
// Per current spec:
// postMessage(message, targetOrigin) // postMessage(message, targetOrigin)
// postMessage(message, targetOrigin, {sequence of transferrables}) // postMessage(message, targetOrigin, {sequence of transferrables})
// Legacy non-standard implementations in webkit allowed: // TODO(foolip): Type checking of the arguments should happen in order, so
// postMessage(message, {sequence of transferrables}, targetOrigin); // that e.g. postMessage({}, { toString: () => { throw Error(); } }, 0)
// throws the Error from toString, not the TypeError for argument 3.
Transferables transferables; Transferables transferables;
int targetOriginArgIndex = 1; const int targetOriginArgIndex = 1;
if (info.Length() > 2) { if (info.Length() > 2) {
int transferablesArgIndex = 2; const int transferablesArgIndex = 2;
if (isLegacyTargetOriginDesignation(info[2])) {
Deprecation::countDeprecationIfNotPrivateScript(info.GetIsolate(), window->document(), UseCounter::WindowPostMessageWithLegacyTargetOriginArgument);
targetOriginArgIndex = 2;
transferablesArgIndex = 1;
}
if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info[transferablesArgIndex], transferablesArgIndex, transferables, exceptionState)) { if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info[transferablesArgIndex], transferablesArgIndex, transferables, exceptionState)) {
return; return;
} }
} }
// TODO(foolip): targetOrigin should be a USVString in IDL and treated as
// such here, without TreatNullAndUndefinedAsNullString.
TOSTRING_VOID(V8StringResource<TreatNullAndUndefinedAsNullString>, targetOrigin, info[targetOriginArgIndex]); TOSTRING_VOID(V8StringResource<TreatNullAndUndefinedAsNullString>, targetOrigin, info[targetOriginArgIndex]);
RefPtr<SerializedScriptValue> message = SerializedScriptValue::serialize(info.GetIsolate(), info[0], &transferables, nullptr, exceptionState); RefPtr<SerializedScriptValue> message = SerializedScriptValue::serialize(info.GetIsolate(), info[0], &transferables, nullptr, exceptionState);
......
...@@ -55,11 +55,6 @@ String dopplerWillBeRemoved(const char* feature, int milestone, const char* deta ...@@ -55,11 +55,6 @@ String dopplerWillBeRemoved(const char* feature, int milestone, const char* deta
return String::format("%s is deprecated and will be removed in %s. It has no effect as the Web Audio doppler effects have already been removed internally. See https://www.chromestatus.com/features/%s for more details.", feature, milestoneString(milestone), details); return String::format("%s is deprecated and will be removed in %s. It has no effect as the Web Audio doppler effects have already been removed internally. See https://www.chromestatus.com/features/%s for more details.", feature, milestoneString(milestone), details);
} }
String replacedWillBeRemoved(const char* feature, const char* replacement, int milestone, const char* details)
{
return String::format("%s is deprecated and will be removed in %s. Please use %s instead. See https://www.chromestatus.com/features/%s for more details.", feature, milestoneString(milestone), replacement, details);
}
} // anonymous namespace } // anonymous namespace
namespace blink { namespace blink {
...@@ -348,9 +343,6 @@ String Deprecation::deprecationMessage(UseCounter::Feature feature) ...@@ -348,9 +343,6 @@ String Deprecation::deprecationMessage(UseCounter::Feature feature)
case UseCounter::HTMLKeygenElement: case UseCounter::HTMLKeygenElement:
return willBeRemoved("The <keygen> element", 56, "5716060992962560"); return willBeRemoved("The <keygen> element", 56, "5716060992962560");
case UseCounter::WindowPostMessageWithLegacyTargetOriginArgument:
return replacedWillBeRemoved("'window.postMessage(message, transferables, targetOrigin)'", "'window.postMessage(message, targetOrigin, transferables)'", 54, "5719033043222528");
case UseCounter::EncryptedMediaAllSelectedContentTypesMissingCodecs: case UseCounter::EncryptedMediaAllSelectedContentTypesMissingCodecs:
return String::format("EME requires that contentType strings accepted by requestMediaKeySystemAccess() include codecs. Non-standard support for contentType strings without codecs will be removed in %s. Please specify the desired codec(s) as part of the contentType.", milestoneString(56)); return String::format("EME requires that contentType strings accepted by requestMediaKeySystemAccess() include codecs. Non-standard support for contentType strings without codecs will be removed in %s. Please specify the desired codec(s) as part of the contentType.", milestoneString(56));
......
...@@ -445,7 +445,6 @@ public: ...@@ -445,7 +445,6 @@ public:
QuotedKeyframesRule = 572, QuotedKeyframesRule = 572,
SrcsetDroppedCandidate = 573, SrcsetDroppedCandidate = 573,
WindowPostMessage = 574, WindowPostMessage = 574,
WindowPostMessageWithLegacyTargetOriginArgument = 575,
RenderRuby = 576, RenderRuby = 576,
ScriptElementWithInvalidTypeHasSrc = 578, ScriptElementWithInvalidTypeHasSrc = 578,
XMLHttpRequestSynchronousInNonWorkerOutsideBeforeUnload = 581, XMLHttpRequestSynchronousInNonWorkerOutsideBeforeUnload = 581,
......
...@@ -856,7 +856,7 @@ function ExtensionServerClient() ...@@ -856,7 +856,7 @@ function ExtensionServerClient()
this._port.addEventListener("message", this._onMessage.bind(this), false); this._port.addEventListener("message", this._onMessage.bind(this), false);
this._port.start(); this._port.start();
window.parent.postMessage("registerExtension", [ channel.port2 ], "*"); window.parent.postMessage("registerExtension", "*", [ channel.port2 ]);
} }
ExtensionServerClient.prototype = { ExtensionServerClient.prototype = {
......
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