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

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

Issue 2295863002: 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // Delete the accessor from the inner object. 143 // Delete the accessor from the inner object.
144 info.Holder()->Delete(isolate->GetCurrentContext(), v8AtomicString(isolate, "opener")); 144 info.Holder()->Delete(isolate->GetCurrentContext(), v8AtomicString(isolate, "opener"));
145 145
146 // Put property on the inner object. 146 // Put property on the inner object.
147 if (info.Holder()->IsObject()) { 147 if (info.Holder()->IsObject()) {
148 v8::Maybe<bool> unused = v8::Local<v8::Object>::Cast(info.Holder())->Set (isolate->GetCurrentContext(), v8AtomicString(isolate, "opener"), value); 148 v8::Maybe<bool> unused = v8::Local<v8::Object>::Cast(info.Holder())->Set (isolate->GetCurrentContext(), v8AtomicString(isolate, "opener"), value);
149 ALLOW_UNUSED_LOCAL(unused); 149 ALLOW_UNUSED_LOCAL(unused);
150 } 150 }
151 } 151 }
152 152
153 static bool isLegacyTargetOriginDesignation(v8::Local<v8::Value> value)
154 {
155 if (value->IsString() || value->IsStringObject())
156 return true;
157 return false;
158 }
159
160
161 void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value> & info) 153 void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value> & info)
162 { 154 {
163 ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage ", "Window", info.Holder(), info.GetIsolate()); 155 ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage ", "Window", info.Holder(), info.GetIsolate());
164 if (UNLIKELY(info.Length() < 2)) { 156 if (UNLIKELY(info.Length() < 2)) {
165 setMinimumArityTypeError(exceptionState, 2, info.Length()); 157 setMinimumArityTypeError(exceptionState, 2, info.Length());
166 return; 158 return;
167 } 159 }
168 160
169 // None of these need to be RefPtr because info and context are guaranteed 161 // None of these need to be RefPtr because info and context are guaranteed
170 // to hold on to them. 162 // to hold on to them.
171 DOMWindow* window = V8Window::toImpl(info.Holder()); 163 DOMWindow* window = V8Window::toImpl(info.Holder());
172 // TODO(yukishiino): The HTML spec specifies that we should use the 164 // TODO(yukishiino): The HTML spec specifies that we should use the
173 // Incumbent Realm instead of the Current Realm, but currently we don't have 165 // Incumbent Realm instead of the Current Realm, but currently we don't have
174 // a way to retrieve the Incumbent Realm. See also: 166 // a way to retrieve the Incumbent Realm. See also:
175 // https://html.spec.whatwg.org/multipage/comms.html#dom-window-postmessage 167 // https://html.spec.whatwg.org/multipage/comms.html#dom-window-postmessage
176 LocalDOMWindow* source = currentDOMWindow(info.GetIsolate()); 168 LocalDOMWindow* source = currentDOMWindow(info.GetIsolate());
177 169
178 ASSERT(window); 170 ASSERT(window);
179 UseCounter::countIfNotPrivateScript(info.GetIsolate(), window->frame(), UseC ounter::WindowPostMessage); 171 UseCounter::countIfNotPrivateScript(info.GetIsolate(), window->frame(), UseC ounter::WindowPostMessage);
180 172
181 // If called directly by WebCore we don't have a calling context. 173 // If called directly by WebCore we don't have a calling context.
182 if (!source) { 174 if (!source) {
183 exceptionState.throwTypeError("No active calling context exists."); 175 exceptionState.throwTypeError("No active calling context exists.");
184 return; 176 return;
185 } 177 }
186 178
187 // This function has variable arguments and can be: 179 // This function has variable arguments and can be:
188 // Per current spec:
189 // postMessage(message, targetOrigin) 180 // postMessage(message, targetOrigin)
190 // postMessage(message, targetOrigin, {sequence of transferrables}) 181 // postMessage(message, targetOrigin, {sequence of transferrables})
191 // Legacy non-standard implementations in webkit allowed:
192 // postMessage(message, {sequence of transferrables}, targetOrigin);
193 Transferables transferables; 182 Transferables transferables;
194 int targetOriginArgIndex = 1; 183 const int targetOriginArgIndex = 1;
195 if (info.Length() > 2) { 184 if (info.Length() > 2) {
196 int transferablesArgIndex = 2; 185 const int transferablesArgIndex = 2;
197 if (isLegacyTargetOriginDesignation(info[2])) {
198 Deprecation::countDeprecationIfNotPrivateScript(info.GetIsolate(), w indow->document(), UseCounter::WindowPostMessageWithLegacyTargetOriginArgument);
199 targetOriginArgIndex = 2;
200 transferablesArgIndex = 1;
201 }
202 if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info [transferablesArgIndex], transferablesArgIndex, transferables, exceptionState)) { 186 if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info [transferablesArgIndex], transferablesArgIndex, transferables, exceptionState)) {
203 return; 187 return;
204 } 188 }
205 } 189 }
206 TOSTRING_VOID(V8StringResource<TreatNullAndUndefinedAsNullString>, targetOri gin, info[targetOriginArgIndex]); 190 TOSTRING_VOID(V8StringResource<TreatNullAndUndefinedAsNullString>, targetOri gin, info[targetOriginArgIndex]);
jsbell 2016/08/30 17:01:36 We process the arguments out of order: 3rd, 2nd, 1
foolip 2016/09/01 10:21:40 Looks like transferables are processed first becau
207 191
208 RefPtr<SerializedScriptValue> message = SerializedScriptValue::serialize(inf o.GetIsolate(), info[0], &transferables, nullptr, exceptionState); 192 RefPtr<SerializedScriptValue> message = SerializedScriptValue::serialize(inf o.GetIsolate(), info[0], &transferables, nullptr, exceptionState);
209 if (exceptionState.hadException()) 193 if (exceptionState.hadException())
210 return; 194 return;
211 195
212 window->postMessage(message.release(), transferables.messagePorts, targetOri gin, source, exceptionState); 196 window->postMessage(message.release(), transferables.messagePorts, targetOri gin, source, exceptionState);
213 } 197 }
214 198
215 void V8Window::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) 199 void V8Window::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
216 { 200 {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 if (items->hasExactlyOneItem()) { 278 if (items->hasExactlyOneItem()) {
295 v8SetReturnValueFast(info, items->item(0), window); 279 v8SetReturnValueFast(info, items->item(0), window);
296 return; 280 return;
297 } 281 }
298 v8SetReturnValueFast(info, items, window); 282 v8SetReturnValueFast(info, items, window);
299 return; 283 return;
300 } 284 }
301 } 285 }
302 286
303 } // namespace blink 287 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698