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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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: | 182 // TODO(foolip): Type checking of the arguments should happen in order, so |
192 // postMessage(message, {sequence of transferrables}, targetOrigin); | 183 // that e.g. postMessage({}, { toString: () => { throw Error(); } }, 0) |
| 184 // throws the Error from toString, not the TypeError for argument 3. |
193 Transferables transferables; | 185 Transferables transferables; |
194 int targetOriginArgIndex = 1; | 186 const int targetOriginArgIndex = 1; |
195 if (info.Length() > 2) { | 187 if (info.Length() > 2) { |
196 int transferablesArgIndex = 2; | 188 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))
{ | 189 if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info
[transferablesArgIndex], transferablesArgIndex, transferables, exceptionState))
{ |
203 return; | 190 return; |
204 } | 191 } |
205 } | 192 } |
| 193 // TODO(foolip): targetOrigin should be a USVString in IDL and treated as |
| 194 // such here, without TreatNullAndUndefinedAsNullString. |
206 TOSTRING_VOID(V8StringResource<TreatNullAndUndefinedAsNullString>, targetOri
gin, info[targetOriginArgIndex]); | 195 TOSTRING_VOID(V8StringResource<TreatNullAndUndefinedAsNullString>, targetOri
gin, info[targetOriginArgIndex]); |
207 | 196 |
208 RefPtr<SerializedScriptValue> message = SerializedScriptValue::serialize(inf
o.GetIsolate(), info[0], &transferables, nullptr, exceptionState); | 197 RefPtr<SerializedScriptValue> message = SerializedScriptValue::serialize(inf
o.GetIsolate(), info[0], &transferables, nullptr, exceptionState); |
209 if (exceptionState.hadException()) | 198 if (exceptionState.hadException()) |
210 return; | 199 return; |
211 | 200 |
212 window->postMessage(message.release(), transferables.messagePorts, targetOri
gin, source, exceptionState); | 201 window->postMessage(message.release(), transferables.messagePorts, targetOri
gin, source, exceptionState); |
213 } | 202 } |
214 | 203 |
215 void V8Window::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) | 204 void V8Window::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 if (items->hasExactlyOneItem()) { | 283 if (items->hasExactlyOneItem()) { |
295 v8SetReturnValueFast(info, items->item(0), window); | 284 v8SetReturnValueFast(info, items->item(0), window); |
296 return; | 285 return; |
297 } | 286 } |
298 v8SetReturnValueFast(info, items, window); | 287 v8SetReturnValueFast(info, items, window); |
299 return; | 288 return; |
300 } | 289 } |
301 } | 290 } |
302 | 291 |
303 } // namespace blink | 292 } // namespace blink |
OLD | NEW |