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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 #include "platform/LayoutTestSupport.h" | 63 #include "platform/LayoutTestSupport.h" |
64 #include "wtf/Assertions.h" | 64 #include "wtf/Assertions.h" |
65 | 65 |
66 namespace blink { | 66 namespace blink { |
67 | 67 |
68 void V8Window::eventAttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Val
ue>& info) | 68 void V8Window::eventAttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Val
ue>& info) |
69 { | 69 { |
70 LocalDOMWindow* impl = toLocalDOMWindow(V8Window::toImpl(info.Holder())); | 70 LocalDOMWindow* impl = toLocalDOMWindow(V8Window::toImpl(info.Holder())); |
71 ExceptionState exceptionState(ExceptionState::GetterContext, "event", "Windo
w", info.Holder(), info.GetIsolate()); | 71 ExceptionState exceptionState(ExceptionState::GetterContext, "event", "Windo
w", info.Holder(), info.GetIsolate()); |
72 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()
), impl, exceptionState)) { | 72 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()
), impl, exceptionState)) { |
73 exceptionState.throwIfNeeded(); | |
74 return; | 73 return; |
75 } | 74 } |
76 | 75 |
77 LocalFrame* frame = impl->frame(); | 76 LocalFrame* frame = impl->frame(); |
78 ASSERT(frame); | 77 ASSERT(frame); |
79 // This is a fast path to retrieve info.Holder()->CreationContext(). | 78 // This is a fast path to retrieve info.Holder()->CreationContext(). |
80 v8::Local<v8::Context> context = toV8Context(frame, DOMWrapperWorld::current
(info.GetIsolate())); | 79 v8::Local<v8::Context> context = toV8Context(frame, DOMWrapperWorld::current
(info.GetIsolate())); |
81 if (context.IsEmpty()) | 80 if (context.IsEmpty()) |
82 return; | 81 return; |
83 | 82 |
84 v8::Local<v8::Value> jsEvent = V8HiddenValue::getHiddenValue(ScriptState::cu
rrent(info.GetIsolate()), context->Global(), V8HiddenValue::event(info.GetIsolat
e())); | 83 v8::Local<v8::Value> jsEvent = V8HiddenValue::getHiddenValue(ScriptState::cu
rrent(info.GetIsolate()), context->Global(), V8HiddenValue::event(info.GetIsolat
e())); |
85 if (jsEvent.IsEmpty()) | 84 if (jsEvent.IsEmpty()) |
86 return; | 85 return; |
87 v8SetReturnValue(info, jsEvent); | 86 v8SetReturnValue(info, jsEvent); |
88 } | 87 } |
89 | 88 |
90 void V8Window::eventAttributeSetterCustom(v8::Local<v8::Value> value, const v8::
PropertyCallbackInfo<void>& info) | 89 void V8Window::eventAttributeSetterCustom(v8::Local<v8::Value> value, const v8::
PropertyCallbackInfo<void>& info) |
91 { | 90 { |
92 LocalDOMWindow* impl = toLocalDOMWindow(V8Window::toImpl(info.Holder())); | 91 LocalDOMWindow* impl = toLocalDOMWindow(V8Window::toImpl(info.Holder())); |
93 ExceptionState exceptionState(ExceptionState::SetterContext, "event", "Windo
w", info.Holder(), info.GetIsolate()); | 92 ExceptionState exceptionState(ExceptionState::SetterContext, "event", "Windo
w", info.Holder(), info.GetIsolate()); |
94 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()
), impl, exceptionState)) { | 93 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()
), impl, exceptionState)) { |
95 exceptionState.throwIfNeeded(); | |
96 return; | 94 return; |
97 } | 95 } |
98 | 96 |
99 LocalFrame* frame = impl->frame(); | 97 LocalFrame* frame = impl->frame(); |
100 ASSERT(frame); | 98 ASSERT(frame); |
101 // This is a fast path to retrieve info.Holder()->CreationContext(). | 99 // This is a fast path to retrieve info.Holder()->CreationContext(). |
102 v8::Local<v8::Context> context = toV8Context(frame, DOMWrapperWorld::current
(info.GetIsolate())); | 100 v8::Local<v8::Context> context = toV8Context(frame, DOMWrapperWorld::current
(info.GetIsolate())); |
103 if (context.IsEmpty()) | 101 if (context.IsEmpty()) |
104 return; | 102 return; |
105 | 103 |
(...skipping 16 matching lines...) Expand all Loading... |
122 v8::Local<v8::Value> wrapper = toV8(impl->frameElement(), v8::Local<v8::Obje
ct>::Cast(creationContext), info.GetIsolate()); | 120 v8::Local<v8::Value> wrapper = toV8(impl->frameElement(), v8::Local<v8::Obje
ct>::Cast(creationContext), info.GetIsolate()); |
123 v8SetReturnValue(info, wrapper); | 121 v8SetReturnValue(info, wrapper); |
124 } | 122 } |
125 | 123 |
126 void V8Window::openerAttributeSetterCustom(v8::Local<v8::Value> value, const v8:
:PropertyCallbackInfo<void>& info) | 124 void V8Window::openerAttributeSetterCustom(v8::Local<v8::Value> value, const v8:
:PropertyCallbackInfo<void>& info) |
127 { | 125 { |
128 v8::Isolate* isolate = info.GetIsolate(); | 126 v8::Isolate* isolate = info.GetIsolate(); |
129 DOMWindow* impl = V8Window::toImpl(info.Holder()); | 127 DOMWindow* impl = V8Window::toImpl(info.Holder()); |
130 ExceptionState exceptionState(ExceptionState::SetterContext, "opener", "Wind
ow", info.Holder(), isolate); | 128 ExceptionState exceptionState(ExceptionState::SetterContext, "opener", "Wind
ow", info.Holder(), isolate); |
131 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()
), impl, exceptionState)) { | 129 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()
), impl, exceptionState)) { |
132 exceptionState.throwIfNeeded(); | |
133 return; | 130 return; |
134 } | 131 } |
135 | 132 |
136 // Opener can be shadowed if it is in the same domain. | 133 // Opener can be shadowed if it is in the same domain. |
137 // Have a special handling of null value to behave | 134 // Have a special handling of null value to behave |
138 // like Firefox. See bug http://b/1224887 & http://b/791706. | 135 // like Firefox. See bug http://b/1224887 & http://b/791706. |
139 if (value->IsNull()) { | 136 if (value->IsNull()) { |
140 // impl->frame() has to be a non-null LocalFrame. Otherwise, the | 137 // impl->frame() has to be a non-null LocalFrame. Otherwise, the |
141 // same-origin check would have failed. | 138 // same-origin check would have failed. |
142 ASSERT(impl->frame()); | 139 ASSERT(impl->frame()); |
(...skipping 16 matching lines...) Expand all Loading... |
159 return true; | 156 return true; |
160 return false; | 157 return false; |
161 } | 158 } |
162 | 159 |
163 | 160 |
164 void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value>
& info) | 161 void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value>
& info) |
165 { | 162 { |
166 ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage
", "Window", info.Holder(), info.GetIsolate()); | 163 ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage
", "Window", info.Holder(), info.GetIsolate()); |
167 if (UNLIKELY(info.Length() < 2)) { | 164 if (UNLIKELY(info.Length() < 2)) { |
168 setMinimumArityTypeError(exceptionState, 2, info.Length()); | 165 setMinimumArityTypeError(exceptionState, 2, info.Length()); |
169 exceptionState.throwIfNeeded(); | |
170 return; | 166 return; |
171 } | 167 } |
172 | 168 |
173 // None of these need to be RefPtr because info and context are guaranteed | 169 // None of these need to be RefPtr because info and context are guaranteed |
174 // to hold on to them. | 170 // to hold on to them. |
175 DOMWindow* window = V8Window::toImpl(info.Holder()); | 171 DOMWindow* window = V8Window::toImpl(info.Holder()); |
176 // TODO(yukishiino): The HTML spec specifies that we should use the | 172 // 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 | 173 // Incumbent Realm instead of the Current Realm, but currently we don't have |
178 // a way to retrieve the Incumbent Realm. See also: | 174 // a way to retrieve the Incumbent Realm. See also: |
179 // https://html.spec.whatwg.org/multipage/comms.html#dom-window-postmessage | 175 // https://html.spec.whatwg.org/multipage/comms.html#dom-window-postmessage |
180 LocalDOMWindow* source = currentDOMWindow(info.GetIsolate()); | 176 LocalDOMWindow* source = currentDOMWindow(info.GetIsolate()); |
181 | 177 |
182 ASSERT(window); | 178 ASSERT(window); |
183 UseCounter::countIfNotPrivateScript(info.GetIsolate(), window->frame(), UseC
ounter::WindowPostMessage); | 179 UseCounter::countIfNotPrivateScript(info.GetIsolate(), window->frame(), UseC
ounter::WindowPostMessage); |
184 | 180 |
185 // If called directly by WebCore we don't have a calling context. | 181 // If called directly by WebCore we don't have a calling context. |
186 if (!source) { | 182 if (!source) { |
187 exceptionState.throwTypeError("No active calling context exists."); | 183 exceptionState.throwTypeError("No active calling context exists."); |
188 exceptionState.throwIfNeeded(); | |
189 return; | 184 return; |
190 } | 185 } |
191 | 186 |
192 // This function has variable arguments and can be: | 187 // This function has variable arguments and can be: |
193 // Per current spec: | 188 // Per current spec: |
194 // postMessage(message, targetOrigin) | 189 // postMessage(message, targetOrigin) |
195 // postMessage(message, targetOrigin, {sequence of transferrables}) | 190 // postMessage(message, targetOrigin, {sequence of transferrables}) |
196 // Legacy non-standard implementations in webkit allowed: | 191 // Legacy non-standard implementations in webkit allowed: |
197 // postMessage(message, {sequence of transferrables}, targetOrigin); | 192 // postMessage(message, {sequence of transferrables}, targetOrigin); |
198 Transferables transferables; | 193 Transferables transferables; |
199 int targetOriginArgIndex = 1; | 194 int targetOriginArgIndex = 1; |
200 if (info.Length() > 2) { | 195 if (info.Length() > 2) { |
201 int transferablesArgIndex = 2; | 196 int transferablesArgIndex = 2; |
202 if (isLegacyTargetOriginDesignation(info[2])) { | 197 if (isLegacyTargetOriginDesignation(info[2])) { |
203 Deprecation::countDeprecationIfNotPrivateScript(info.GetIsolate(), w
indow->document(), UseCounter::WindowPostMessageWithLegacyTargetOriginArgument); | 198 Deprecation::countDeprecationIfNotPrivateScript(info.GetIsolate(), w
indow->document(), UseCounter::WindowPostMessageWithLegacyTargetOriginArgument); |
204 targetOriginArgIndex = 2; | 199 targetOriginArgIndex = 2; |
205 transferablesArgIndex = 1; | 200 transferablesArgIndex = 1; |
206 } | 201 } |
207 if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info
[transferablesArgIndex], transferablesArgIndex, transferables, exceptionState))
{ | 202 if (!SerializedScriptValue::extractTransferables(info.GetIsolate(), info
[transferablesArgIndex], transferablesArgIndex, transferables, exceptionState))
{ |
208 exceptionState.throwIfNeeded(); | |
209 return; | 203 return; |
210 } | 204 } |
211 } | 205 } |
212 TOSTRING_VOID(V8StringResource<TreatNullAndUndefinedAsNullString>, targetOri
gin, info[targetOriginArgIndex]); | 206 TOSTRING_VOID(V8StringResource<TreatNullAndUndefinedAsNullString>, targetOri
gin, info[targetOriginArgIndex]); |
213 | 207 |
214 RefPtr<SerializedScriptValue> message = SerializedScriptValue::serialize(inf
o.GetIsolate(), info[0], &transferables, nullptr, exceptionState); | 208 RefPtr<SerializedScriptValue> message = SerializedScriptValue::serialize(inf
o.GetIsolate(), info[0], &transferables, nullptr, exceptionState); |
215 if (exceptionState.throwIfNeeded()) | 209 if (exceptionState.hadException()) |
216 return; | 210 return; |
217 | 211 |
218 window->postMessage(message.release(), transferables.messagePorts, targetOri
gin, source, exceptionState); | 212 window->postMessage(message.release(), transferables.messagePorts, targetOri
gin, source, exceptionState); |
219 exceptionState.throwIfNeeded(); | |
220 } | 213 } |
221 | 214 |
222 void V8Window::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) | 215 void V8Window::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
223 { | 216 { |
224 DOMWindow* impl = V8Window::toImpl(info.Holder()); | 217 DOMWindow* impl = V8Window::toImpl(info.Holder()); |
225 ExceptionState exceptionState(ExceptionState::ExecutionContext, "open", "Win
dow", info.Holder(), info.GetIsolate()); | 218 ExceptionState exceptionState(ExceptionState::ExecutionContext, "open", "Win
dow", info.Holder(), info.GetIsolate()); |
226 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()
), impl, exceptionState)) { | 219 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()
), impl, exceptionState)) { |
227 exceptionState.throwIfNeeded(); | |
228 return; | 220 return; |
229 } | 221 } |
230 | 222 |
231 TOSTRING_VOID(V8StringResource<TreatNullAndUndefinedAsNullString>, urlString
, info[0]); | 223 TOSTRING_VOID(V8StringResource<TreatNullAndUndefinedAsNullString>, urlString
, info[0]); |
232 AtomicString frameName; | 224 AtomicString frameName; |
233 if (info[1]->IsUndefined() || info[1]->IsNull()) { | 225 if (info[1]->IsUndefined() || info[1]->IsNull()) { |
234 frameName = "_blank"; | 226 frameName = "_blank"; |
235 } else { | 227 } else { |
236 TOSTRING_VOID(V8StringResource<>, frameNameResource, info[1]); | 228 TOSTRING_VOID(V8StringResource<>, frameNameResource, info[1]); |
237 frameName = frameNameResource; | 229 frameName = frameNameResource; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 if (items->hasExactlyOneItem()) { | 294 if (items->hasExactlyOneItem()) { |
303 v8SetReturnValueFast(info, items->item(0), window); | 295 v8SetReturnValueFast(info, items->item(0), window); |
304 return; | 296 return; |
305 } | 297 } |
306 v8SetReturnValueFast(info, items, window); | 298 v8SetReturnValueFast(info, items, window); |
307 return; | 299 return; |
308 } | 300 } |
309 } | 301 } |
310 | 302 |
311 } // namespace blink | 303 } // namespace blink |
OLD | NEW |