OLD | NEW |
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 Loading... |
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 |
156 void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value>
& info) | 164 void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value>
& info) |
157 { | 165 { |
158 ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage
", "Window", info.Holder(), info.GetIsolate()); | 166 ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage
", "Window", info.Holder(), info.GetIsolate()); |
159 if (UNLIKELY(info.Length() < 2)) { | 167 if (UNLIKELY(info.Length() < 2)) { |
160 setMinimumArityTypeError(exceptionState, 2, info.Length()); | 168 setMinimumArityTypeError(exceptionState, 2, info.Length()); |
161 exceptionState.throwIfNeeded(); | 169 exceptionState.throwIfNeeded(); |
162 return; | 170 return; |
163 } | 171 } |
164 | 172 |
165 // None of these need to be RefPtr because info and context are guaranteed | 173 // None of these need to be RefPtr because info and context are guaranteed |
166 // to hold on to them. | 174 // to hold on to them. |
167 DOMWindow* window = V8Window::toImpl(info.Holder()); | 175 DOMWindow* window = V8Window::toImpl(info.Holder()); |
168 // TODO(yukishiino): The HTML spec specifies that we should use the | 176 // TODO(yukishiino): The HTML spec specifies that we should use the |
169 // Incumbent Realm instead of the Current Realm, but currently we don't have | 177 // Incumbent Realm instead of the Current Realm, but currently we don't have |
170 // a way to retrieve the Incumbent Realm. See also: | 178 // a way to retrieve the Incumbent Realm. See also: |
171 // https://html.spec.whatwg.org/multipage/comms.html#dom-window-postmessage | 179 // https://html.spec.whatwg.org/multipage/comms.html#dom-window-postmessage |
172 LocalDOMWindow* source = currentDOMWindow(info.GetIsolate()); | 180 LocalDOMWindow* source = currentDOMWindow(info.GetIsolate()); |
173 | 181 |
174 ASSERT(window); | 182 ASSERT(window); |
175 UseCounter::countIfNotPrivateScript(info.GetIsolate(), window->frame(), UseC
ounter::WindowPostMessage); | 183 UseCounter::countIfNotPrivateScript(info.GetIsolate(), window->frame(), UseC
ounter::WindowPostMessage); |
176 | 184 |
177 // If called directly by WebCore we don't have a calling context. | 185 // If called directly by WebCore we don't have a calling context. |
178 if (!source) { | 186 if (!source) { |
179 exceptionState.throwTypeError("No active calling context exists."); | 187 exceptionState.throwTypeError("No active calling context exists."); |
180 exceptionState.throwIfNeeded(); | 188 exceptionState.throwIfNeeded(); |
181 return; | 189 return; |
182 } | 190 } |
183 | 191 |
184 // This function has variable arguments and can be: | 192 // This function has variable arguments and can be: |
| 193 // Per current spec: |
185 // postMessage(message, targetOrigin) | 194 // postMessage(message, targetOrigin) |
186 // postMessage(message, targetOrigin, {sequence of transferrables}) | 195 // postMessage(message, targetOrigin, {sequence of transferrables}) |
187 // TODO(foolip): Type checking of the arguments should happen in order, so | 196 // Legacy non-standard implementations in webkit allowed: |
188 // that e.g. postMessage({}, { toString: () => { throw Error(); } }, 0) | 197 // postMessage(message, {sequence of transferrables}, targetOrigin); |
189 // throws the Error from toString, not the TypeError for argument 3. | |
190 Transferables transferables; | 198 Transferables transferables; |
191 const int targetOriginArgIndex = 1; | 199 int targetOriginArgIndex = 1; |
192 if (info.Length() > 2) { | 200 if (info.Length() > 2) { |
193 const int transferablesArgIndex = 2; | 201 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 } |
194 if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info
[transferablesArgIndex], transferablesArgIndex, transferables, exceptionState))
{ | 207 if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info
[transferablesArgIndex], transferablesArgIndex, transferables, exceptionState))
{ |
195 exceptionState.throwIfNeeded(); | 208 exceptionState.throwIfNeeded(); |
196 return; | 209 return; |
197 } | 210 } |
198 } | 211 } |
199 // TODO(foolip): targetOrigin should be a USVString in IDL and treated as | |
200 // such here, without TreatNullAndUndefinedAsNullString. | |
201 TOSTRING_VOID(V8StringResource<TreatNullAndUndefinedAsNullString>, targetOri
gin, info[targetOriginArgIndex]); | 212 TOSTRING_VOID(V8StringResource<TreatNullAndUndefinedAsNullString>, targetOri
gin, info[targetOriginArgIndex]); |
202 | 213 |
203 RefPtr<SerializedScriptValue> message = SerializedScriptValue::serialize(inf
o.GetIsolate(), info[0], &transferables, nullptr, exceptionState); | 214 RefPtr<SerializedScriptValue> message = SerializedScriptValue::serialize(inf
o.GetIsolate(), info[0], &transferables, nullptr, exceptionState); |
204 if (exceptionState.throwIfNeeded()) | 215 if (exceptionState.throwIfNeeded()) |
205 return; | 216 return; |
206 | 217 |
207 window->postMessage(message.release(), transferables.messagePorts, targetOri
gin, source, exceptionState); | 218 window->postMessage(message.release(), transferables.messagePorts, targetOri
gin, source, exceptionState); |
208 exceptionState.throwIfNeeded(); | 219 exceptionState.throwIfNeeded(); |
209 } | 220 } |
210 | 221 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 if (items->hasExactlyOneItem()) { | 302 if (items->hasExactlyOneItem()) { |
292 v8SetReturnValueFast(info, items->item(0), window); | 303 v8SetReturnValueFast(info, items->item(0), window); |
293 return; | 304 return; |
294 } | 305 } |
295 v8SetReturnValueFast(info, items, window); | 306 v8SetReturnValueFast(info, items, window); |
296 return; | 307 return; |
297 } | 308 } |
298 } | 309 } |
299 | 310 |
300 } // namespace blink | 311 } // namespace blink |
OLD | NEW |