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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/custom/V8WindowCustom.cpp

Issue 2336133002: Remove window.postMessage(message, transferables, targetOrigin) legacy overload (Closed)
Patch Set: Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009, 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2009, 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 // Delete the accessor from the inner object. 146 // Delete the accessor from the inner object.
147 info.Holder()->Delete(isolate->GetCurrentContext(), v8AtomicString(isolate, "opener")); 147 info.Holder()->Delete(isolate->GetCurrentContext(), v8AtomicString(isolate, "opener"));
148 148
149 // Put property on the inner object. 149 // Put property on the inner object.
150 if (info.Holder()->IsObject()) { 150 if (info.Holder()->IsObject()) {
151 v8::Maybe<bool> unused = v8::Local<v8::Object>::Cast(info.Holder())->Set (isolate->GetCurrentContext(), v8AtomicString(isolate, "opener"), value); 151 v8::Maybe<bool> unused = v8::Local<v8::Object>::Cast(info.Holder())->Set (isolate->GetCurrentContext(), v8AtomicString(isolate, "opener"), value);
152 ALLOW_UNUSED_LOCAL(unused); 152 ALLOW_UNUSED_LOCAL(unused);
153 } 153 }
154 } 154 }
155 155
156 static bool isLegacyTargetOriginDesignation(v8::Local<v8::Value> value)
157 {
158 if (value->IsString() || value->IsStringObject())
159 return true;
160 return false;
161 }
162
163
164 void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value> & info) 156 void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value> & info)
165 { 157 {
166 ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage ", "Window", info.Holder(), info.GetIsolate()); 158 ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage ", "Window", info.Holder(), info.GetIsolate());
167 if (UNLIKELY(info.Length() < 2)) { 159 if (UNLIKELY(info.Length() < 2)) {
168 setMinimumArityTypeError(exceptionState, 2, info.Length()); 160 setMinimumArityTypeError(exceptionState, 2, info.Length());
169 exceptionState.throwIfNeeded(); 161 exceptionState.throwIfNeeded();
170 return; 162 return;
171 } 163 }
172 164
173 // None of these need to be RefPtr because info and context are guaranteed 165 // None of these need to be RefPtr because info and context are guaranteed
174 // to hold on to them. 166 // to hold on to them.
175 DOMWindow* window = V8Window::toImpl(info.Holder()); 167 DOMWindow* window = V8Window::toImpl(info.Holder());
176 // TODO(yukishiino): The HTML spec specifies that we should use the 168 // TODO(yukishiino): The HTML spec specifies that we should use the
177 // Incumbent Realm instead of the Current Realm, but currently we don't have 169 // Incumbent Realm instead of the Current Realm, but currently we don't have
178 // a way to retrieve the Incumbent Realm. See also: 170 // a way to retrieve the Incumbent Realm. See also:
179 // https://html.spec.whatwg.org/multipage/comms.html#dom-window-postmessage 171 // https://html.spec.whatwg.org/multipage/comms.html#dom-window-postmessage
180 LocalDOMWindow* source = currentDOMWindow(info.GetIsolate()); 172 LocalDOMWindow* source = currentDOMWindow(info.GetIsolate());
181 173
182 ASSERT(window); 174 ASSERT(window);
183 UseCounter::countIfNotPrivateScript(info.GetIsolate(), window->frame(), UseC ounter::WindowPostMessage); 175 UseCounter::countIfNotPrivateScript(info.GetIsolate(), window->frame(), UseC ounter::WindowPostMessage);
184 176
185 // If called directly by WebCore we don't have a calling context. 177 // If called directly by WebCore we don't have a calling context.
186 if (!source) { 178 if (!source) {
187 exceptionState.throwTypeError("No active calling context exists."); 179 exceptionState.throwTypeError("No active calling context exists.");
188 exceptionState.throwIfNeeded(); 180 exceptionState.throwIfNeeded();
189 return; 181 return;
190 } 182 }
191 183
192 // This function has variable arguments and can be: 184 // This function has variable arguments and can be:
193 // Per current spec:
194 // postMessage(message, targetOrigin) 185 // postMessage(message, targetOrigin)
195 // postMessage(message, targetOrigin, {sequence of transferrables}) 186 // postMessage(message, targetOrigin, {sequence of transferrables})
196 // Legacy non-standard implementations in webkit allowed: 187 // TODO(foolip): Type checking of the arguments should happen in order, so
197 // postMessage(message, {sequence of transferrables}, targetOrigin); 188 // that e.g. postMessage({}, { toString: () => { throw Error(); } }, 0)
189 // throws the Error from toString, not the TypeError for argument 3.
198 Transferables transferables; 190 Transferables transferables;
199 int targetOriginArgIndex = 1; 191 const int targetOriginArgIndex = 1;
200 if (info.Length() > 2) { 192 if (info.Length() > 2) {
201 int transferablesArgIndex = 2; 193 const int transferablesArgIndex = 2;
202 if (isLegacyTargetOriginDesignation(info[2])) {
203 Deprecation::countDeprecationIfNotPrivateScript(info.GetIsolate(), w indow->document(), UseCounter::WindowPostMessageWithLegacyTargetOriginArgument);
204 targetOriginArgIndex = 2;
205 transferablesArgIndex = 1;
206 }
207 if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info [transferablesArgIndex], transferablesArgIndex, transferables, exceptionState)) { 194 if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info [transferablesArgIndex], transferablesArgIndex, transferables, exceptionState)) {
208 exceptionState.throwIfNeeded(); 195 exceptionState.throwIfNeeded();
209 return; 196 return;
210 } 197 }
211 } 198 }
199 // TODO(foolip): targetOrigin should be a USVString in IDL and treated as
200 // such here, without TreatNullAndUndefinedAsNullString.
212 TOSTRING_VOID(V8StringResource<TreatNullAndUndefinedAsNullString>, targetOri gin, info[targetOriginArgIndex]); 201 TOSTRING_VOID(V8StringResource<TreatNullAndUndefinedAsNullString>, targetOri gin, info[targetOriginArgIndex]);
213 202
214 RefPtr<SerializedScriptValue> message = SerializedScriptValue::serialize(inf o.GetIsolate(), info[0], &transferables, nullptr, exceptionState); 203 RefPtr<SerializedScriptValue> message = SerializedScriptValue::serialize(inf o.GetIsolate(), info[0], &transferables, nullptr, exceptionState);
215 if (exceptionState.throwIfNeeded()) 204 if (exceptionState.throwIfNeeded())
216 return; 205 return;
217 206
218 window->postMessage(message.release(), transferables.messagePorts, targetOri gin, source, exceptionState); 207 window->postMessage(message.release(), transferables.messagePorts, targetOri gin, source, exceptionState);
219 exceptionState.throwIfNeeded(); 208 exceptionState.throwIfNeeded();
220 } 209 }
221 210
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 if (items->hasExactlyOneItem()) { 291 if (items->hasExactlyOneItem()) {
303 v8SetReturnValueFast(info, items->item(0), window); 292 v8SetReturnValueFast(info, items->item(0), window);
304 return; 293 return;
305 } 294 }
306 v8SetReturnValueFast(info, items, window); 295 v8SetReturnValueFast(info, items, window);
307 return; 296 return;
308 } 297 }
309 } 298 }
310 299
311 } // namespace blink 300 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698