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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 exceptionState.throwIfNeeded(); | 72 exceptionState.throwIfNeeded(); |
73 return; | 73 return; |
74 } | 74 } |
75 | 75 |
76 ASSERT(frame); | 76 ASSERT(frame); |
77 // This is a fast path to retrieve info.Holder()->CreationContext(). | 77 // This is a fast path to retrieve info.Holder()->CreationContext(). |
78 v8::Local<v8::Context> context = toV8Context(frame, DOMWrapperWorld::current
(info.GetIsolate())); | 78 v8::Local<v8::Context> context = toV8Context(frame, DOMWrapperWorld::current
(info.GetIsolate())); |
79 if (context.IsEmpty()) | 79 if (context.IsEmpty()) |
80 return; | 80 return; |
81 | 81 |
82 v8::Handle<v8::Value> jsEvent = V8HiddenValue::getHiddenValue(info.GetIsolat
e(), context->Global(), V8HiddenValue::event(info.GetIsolate())); | 82 v8::Local<v8::Value> jsEvent = V8HiddenValue::getHiddenValue(info.GetIsolate
(), context->Global(), V8HiddenValue::event(info.GetIsolate())); |
83 if (jsEvent.IsEmpty()) | 83 if (jsEvent.IsEmpty()) |
84 return; | 84 return; |
85 v8SetReturnValue(info, jsEvent); | 85 v8SetReturnValue(info, jsEvent); |
86 } | 86 } |
87 | 87 |
88 void V8Window::eventAttributeSetterCustom(v8::Local<v8::Value> value, const v8::
PropertyCallbackInfo<void>& info) | 88 void V8Window::eventAttributeSetterCustom(v8::Local<v8::Value> value, const v8::
PropertyCallbackInfo<void>& info) |
89 { | 89 { |
90 LocalFrame* frame = toLocalDOMWindow(V8Window::toImpl(info.Holder()))->frame
(); | 90 LocalFrame* frame = toLocalDOMWindow(V8Window::toImpl(info.Holder()))->frame
(); |
91 ExceptionState exceptionState(ExceptionState::SetterContext, "event", "Windo
w", info.Holder(), info.GetIsolate()); | 91 ExceptionState exceptionState(ExceptionState::SetterContext, "event", "Windo
w", info.Holder(), info.GetIsolate()); |
92 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), frame, exc
eptionState)) { | 92 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), frame, exc
eptionState)) { |
(...skipping 15 matching lines...) Expand all Loading... |
108 LocalDOMWindow* impl = toLocalDOMWindow(V8Window::toImpl(info.Holder())); | 108 LocalDOMWindow* impl = toLocalDOMWindow(V8Window::toImpl(info.Holder())); |
109 ExceptionState exceptionState(ExceptionState::GetterContext, "frame", "Windo
w", info.Holder(), info.GetIsolate()); | 109 ExceptionState exceptionState(ExceptionState::GetterContext, "frame", "Windo
w", info.Holder(), info.GetIsolate()); |
110 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), impl->frame
Element(), exceptionState)) { | 110 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), impl->frame
Element(), exceptionState)) { |
111 v8SetReturnValueNull(info); | 111 v8SetReturnValueNull(info); |
112 exceptionState.throwIfNeeded(); | 112 exceptionState.throwIfNeeded(); |
113 return; | 113 return; |
114 } | 114 } |
115 | 115 |
116 // The wrapper for an <iframe> should get its prototype from the context of
the frame it's in, rather than its own frame. | 116 // The wrapper for an <iframe> should get its prototype from the context of
the frame it's in, rather than its own frame. |
117 // So, use its containing document as the creation context when wrapping. | 117 // So, use its containing document as the creation context when wrapping. |
118 v8::Handle<v8::Value> creationContext = toV8(&impl->frameElement()->document
(), info.Holder(), info.GetIsolate()); | 118 v8::Local<v8::Value> creationContext = toV8(&impl->frameElement()->document(
), info.Holder(), info.GetIsolate()); |
119 RELEASE_ASSERT(!creationContext.IsEmpty()); | 119 RELEASE_ASSERT(!creationContext.IsEmpty()); |
120 v8::Handle<v8::Value> wrapper = toV8(impl->frameElement(), v8::Handle<v8::Ob
ject>::Cast(creationContext), info.GetIsolate()); | 120 v8::Local<v8::Value> wrapper = toV8(impl->frameElement(), v8::Local<v8::Obje
ct>::Cast(creationContext), info.GetIsolate()); |
121 v8SetReturnValue(info, wrapper); | 121 v8SetReturnValue(info, wrapper); |
122 } | 122 } |
123 | 123 |
124 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) |
125 { | 125 { |
126 v8::Isolate* isolate = info.GetIsolate(); | 126 v8::Isolate* isolate = info.GetIsolate(); |
127 LocalDOMWindow* impl = toLocalDOMWindow(V8Window::toImpl(info.Holder())); | 127 LocalDOMWindow* impl = toLocalDOMWindow(V8Window::toImpl(info.Holder())); |
128 ExceptionState exceptionState(ExceptionState::SetterContext, "opener", "Wind
ow", info.Holder(), isolate); | 128 ExceptionState exceptionState(ExceptionState::SetterContext, "opener", "Wind
ow", info.Holder(), isolate); |
129 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->fram
e(), exceptionState)) { | 129 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->fram
e(), exceptionState)) { |
130 exceptionState.throwIfNeeded(); | 130 exceptionState.throwIfNeeded(); |
131 return; | 131 return; |
132 } | 132 } |
133 | 133 |
134 // Opener can be shadowed if it is in the same domain. | 134 // Opener can be shadowed if it is in the same domain. |
135 // Have a special handling of null value to behave | 135 // Have a special handling of null value to behave |
136 // like Firefox. See bug http://b/1224887 & http://b/791706. | 136 // like Firefox. See bug http://b/1224887 & http://b/791706. |
137 if (value->IsNull()) { | 137 if (value->IsNull()) { |
138 // impl->frame() cannot be null, | 138 // impl->frame() cannot be null, |
139 // otherwise, SameOrigin check would have failed. | 139 // otherwise, SameOrigin check would have failed. |
140 ASSERT(impl->frame()); | 140 ASSERT(impl->frame()); |
141 impl->frame()->loader().setOpener(0); | 141 impl->frame()->loader().setOpener(0); |
142 } | 142 } |
143 | 143 |
144 // Delete the accessor from this object. | 144 // Delete the accessor from this object. |
145 info.Holder()->Delete(isolate->GetCurrentContext(), v8AtomicString(isolate,
"opener")); | 145 info.Holder()->Delete(isolate->GetCurrentContext(), v8AtomicString(isolate,
"opener")); |
146 | 146 |
147 // Put property on the front (this) object. | 147 // Put property on the front (this) object. |
148 if (info.This()->IsObject()) | 148 if (info.This()->IsObject()) |
149 v8::Handle<v8::Object>::Cast(info.This())->Set(v8AtomicString(isolate, "
opener"), value); | 149 v8::Local<v8::Object>::Cast(info.This())->Set(v8AtomicString(isolate, "o
pener"), value); |
150 } | 150 } |
151 | 151 |
152 static bool isLegacyTargetOriginDesignation(v8::Handle<v8::Value> value) | 152 static bool isLegacyTargetOriginDesignation(v8::Local<v8::Value> value) |
153 { | 153 { |
154 if (value->IsString() || value->IsStringObject()) | 154 if (value->IsString() || value->IsStringObject()) |
155 return true; | 155 return true; |
156 return false; | 156 return false; |
157 } | 157 } |
158 | 158 |
159 | 159 |
160 void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value>
& info) | 160 void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value>
& info) |
161 { | 161 { |
162 ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage
", "Window", info.Holder(), info.GetIsolate()); | 162 ExceptionState exceptionState(ExceptionState::ExecutionContext, "postMessage
", "Window", info.Holder(), info.GetIsolate()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 window->postMessage(message.release(), &portArray, targetOrigin, source, exc
eptionState); | 211 window->postMessage(message.release(), &portArray, targetOrigin, source, exc
eptionState); |
212 exceptionState.throwIfNeeded(); | 212 exceptionState.throwIfNeeded(); |
213 } | 213 } |
214 | 214 |
215 // FIXME(fqian): returning string is cheating, and we should | 215 // FIXME(fqian): returning string is cheating, and we should |
216 // fix this by calling toString function on the receiver. | 216 // fix this by calling toString function on the receiver. |
217 // However, V8 implements toString in JavaScript, which requires | 217 // However, V8 implements toString in JavaScript, which requires |
218 // switching context of receiver. I consider it is dangerous. | 218 // switching context of receiver. I consider it is dangerous. |
219 void V8Window::toStringMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& i
nfo) | 219 void V8Window::toStringMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& i
nfo) |
220 { | 220 { |
221 v8::Handle<v8::Object> domWrapper = V8Window::findInstanceInPrototypeChain(i
nfo.This(), info.GetIsolate()); | 221 v8::Local<v8::Object> domWrapper = V8Window::findInstanceInPrototypeChain(in
fo.This(), info.GetIsolate()); |
222 v8::Local<v8::Object> target = domWrapper.IsEmpty() ? info.This() : domWrapp
er; | 222 v8::Local<v8::Object> target = domWrapper.IsEmpty() ? info.This() : domWrapp
er; |
223 v8::Local<v8::String> value; | 223 v8::Local<v8::String> value; |
224 if (target->ObjectProtoToString(info.GetIsolate()->GetCurrentContext()).ToLo
cal(&value)) | 224 if (target->ObjectProtoToString(info.GetIsolate()->GetCurrentContext()).ToLo
cal(&value)) |
225 v8SetReturnValue(info, value); | 225 v8SetReturnValue(info, value); |
226 } | 226 } |
227 | 227 |
228 void V8Window::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) | 228 void V8Window::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
229 { | 229 { |
230 LocalDOMWindow* impl = toLocalDOMWindow(V8Window::toImpl(info.Holder())); | 230 LocalDOMWindow* impl = toLocalDOMWindow(V8Window::toImpl(info.Holder())); |
231 ExceptionState exceptionState(ExceptionState::ExecutionContext, "open", "Win
dow", info.Holder(), info.GetIsolate()); | 231 ExceptionState exceptionState(ExceptionState::ExecutionContext, "open", "Win
dow", info.Holder(), info.GetIsolate()); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 } | 308 } |
309 v8SetReturnValueFast(info, items.release(), window); | 309 v8SetReturnValueFast(info, items.release(), window); |
310 return; | 310 return; |
311 } | 311 } |
312 } | 312 } |
313 } | 313 } |
314 | 314 |
315 static bool securityCheck(v8::Local<v8::Object> host) | 315 static bool securityCheck(v8::Local<v8::Object> host) |
316 { | 316 { |
317 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 317 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
318 v8::Handle<v8::Object> window = V8Window::findInstanceInPrototypeChain(host,
isolate); | 318 v8::Local<v8::Object> window = V8Window::findInstanceInPrototypeChain(host,
isolate); |
319 if (window.IsEmpty()) | 319 if (window.IsEmpty()) |
320 return false; // the frame is gone. | 320 return false; // the frame is gone. |
321 | 321 |
322 DOMWindow* targetWindow = V8Window::toImpl(window); | 322 DOMWindow* targetWindow = V8Window::toImpl(window); |
323 ASSERT(targetWindow); | 323 ASSERT(targetWindow); |
324 if (!targetWindow->isLocalDOMWindow()) | 324 if (!targetWindow->isLocalDOMWindow()) |
325 return false; | 325 return false; |
326 | 326 |
327 LocalFrame* target = toLocalDOMWindow(targetWindow)->frame(); | 327 LocalFrame* target = toLocalDOMWindow(targetWindow)->frame(); |
328 if (!target) | 328 if (!target) |
(...skipping 21 matching lines...) Expand all Loading... |
350 // Notice that we explicitly ignore creationContext because the LocalDOMWind
ow is its own creationContext. | 350 // Notice that we explicitly ignore creationContext because the LocalDOMWind
ow is its own creationContext. |
351 | 351 |
352 if (!window) | 352 if (!window) |
353 return v8::Null(isolate); | 353 return v8::Null(isolate); |
354 // Initializes environment of a frame, and return the global object | 354 // Initializes environment of a frame, and return the global object |
355 // of the frame. | 355 // of the frame. |
356 Frame * frame = window->frame(); | 356 Frame * frame = window->frame(); |
357 if (!frame) | 357 if (!frame) |
358 return v8Undefined(); | 358 return v8Undefined(); |
359 | 359 |
360 v8::Handle<v8::Context> context = toV8Context(frame, DOMWrapperWorld::curren
t(isolate)); | 360 v8::Local<v8::Context> context = toV8Context(frame, DOMWrapperWorld::current
(isolate)); |
361 if (context.IsEmpty()) | 361 if (context.IsEmpty()) |
362 return v8Undefined(); | 362 return v8Undefined(); |
363 | 363 |
364 v8::Handle<v8::Object> global = context->Global(); | 364 v8::Local<v8::Object> global = context->Global(); |
365 ASSERT(!global.IsEmpty()); | 365 ASSERT(!global.IsEmpty()); |
366 return global; | 366 return global; |
367 } | 367 } |
368 | 368 |
369 } // namespace blink | 369 } // namespace blink |
OLD | NEW |