| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 #include "core/storage/Storage.h" | 66 #include "core/storage/Storage.h" |
| 67 #include "platform/PlatformScreen.h" | 67 #include "platform/PlatformScreen.h" |
| 68 #include "platform/graphics/media/MediaPlayer.h" | 68 #include "platform/graphics/media/MediaPlayer.h" |
| 69 #include "wtf/ArrayBuffer.h" | 69 #include "wtf/ArrayBuffer.h" |
| 70 #include "wtf/OwnPtr.h" | 70 #include "wtf/OwnPtr.h" |
| 71 | 71 |
| 72 namespace WebCore { | 72 namespace WebCore { |
| 73 | 73 |
| 74 // FIXME: There is a lot of duplication with SetTimeoutOrInterval() in V8WorkerG
lobalScopeCustom.cpp. | 74 // FIXME: There is a lot of duplication with SetTimeoutOrInterval() in V8WorkerG
lobalScopeCustom.cpp. |
| 75 // We should refactor this. | 75 // We should refactor this. |
| 76 void WindowSetTimeoutImpl(const v8::FunctionCallbackInfo<v8::Value>& info, bool
singleShot, ExceptionState& es) | 76 void WindowSetTimeoutImpl(const v8::FunctionCallbackInfo<v8::Value>& info, bool
singleShot, ExceptionState& exceptionState) |
| 77 { | 77 { |
| 78 int argumentCount = info.Length(); | 78 int argumentCount = info.Length(); |
| 79 | 79 |
| 80 if (argumentCount < 1) | 80 if (argumentCount < 1) |
| 81 return; | 81 return; |
| 82 | 82 |
| 83 DOMWindow* imp = V8Window::toNative(info.Holder()); | 83 DOMWindow* imp = V8Window::toNative(info.Holder()); |
| 84 ExecutionContext* scriptContext = static_cast<ExecutionContext*>(imp->docume
nt()); | 84 ExecutionContext* scriptContext = static_cast<ExecutionContext*>(imp->docume
nt()); |
| 85 | 85 |
| 86 if (!scriptContext) { | 86 if (!scriptContext) { |
| 87 es.throwUninformativeAndGenericDOMException(InvalidAccessError); | 87 exceptionState.throwUninformativeAndGenericDOMException(InvalidAccessErr
or); |
| 88 return; | 88 return; |
| 89 } | 89 } |
| 90 | 90 |
| 91 v8::Handle<v8::Value> function = info[0]; | 91 v8::Handle<v8::Value> function = info[0]; |
| 92 String functionString; | 92 String functionString; |
| 93 if (!function->IsFunction()) { | 93 if (!function->IsFunction()) { |
| 94 if (function->IsString()) { | 94 if (function->IsString()) { |
| 95 functionString = toWebCoreString(function.As<v8::String>()); | 95 functionString = toWebCoreString(function.As<v8::String>()); |
| 96 } else { | 96 } else { |
| 97 v8::Handle<v8::Value> v8String = function->ToString(); | 97 v8::Handle<v8::Value> v8String = function->ToString(); |
| 98 | 98 |
| 99 // Bail out if string conversion failed. | 99 // Bail out if string conversion failed. |
| 100 if (v8String.IsEmpty()) | 100 if (v8String.IsEmpty()) |
| 101 return; | 101 return; |
| 102 | 102 |
| 103 functionString = toWebCoreString(v8String); | 103 functionString = toWebCoreString(v8String); |
| 104 } | 104 } |
| 105 | 105 |
| 106 // Don't allow setting timeouts to run empty functions! | 106 // Don't allow setting timeouts to run empty functions! |
| 107 // (Bug 1009597) | 107 // (Bug 1009597) |
| 108 if (!functionString.length()) | 108 if (!functionString.length()) |
| 109 return; | 109 return; |
| 110 } | 110 } |
| 111 | 111 |
| 112 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame(), es)) | 112 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame(), exceptionState)
) |
| 113 return; | 113 return; |
| 114 | 114 |
| 115 OwnPtr<ScheduledAction> action; | 115 OwnPtr<ScheduledAction> action; |
| 116 if (function->IsFunction()) { | 116 if (function->IsFunction()) { |
| 117 int paramCount = argumentCount >= 2 ? argumentCount - 2 : 0; | 117 int paramCount = argumentCount >= 2 ? argumentCount - 2 : 0; |
| 118 OwnPtr<v8::Local<v8::Value>[]> params; | 118 OwnPtr<v8::Local<v8::Value>[]> params; |
| 119 if (paramCount > 0) { | 119 if (paramCount > 0) { |
| 120 params = adoptArrayPtr(new v8::Local<v8::Value>[paramCount]); | 120 params = adoptArrayPtr(new v8::Local<v8::Value>[paramCount]); |
| 121 for (int i = 0; i < paramCount; i++) { | 121 for (int i = 0; i < paramCount; i++) { |
| 122 // parameters must be globalized | 122 // parameters must be globalized |
| (...skipping 30 matching lines...) Expand all Loading... |
| 153 v8SetReturnValue(info, timerId); | 153 v8SetReturnValue(info, timerId); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void V8Window::eventAttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Val
ue>& info) | 156 void V8Window::eventAttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Val
ue>& info) |
| 157 { | 157 { |
| 158 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8
Window::GetTemplate(info.GetIsolate(), worldTypeInMainThread(info.GetIsolate()))
); | 158 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8
Window::GetTemplate(info.GetIsolate(), worldTypeInMainThread(info.GetIsolate()))
); |
| 159 if (holder.IsEmpty()) | 159 if (holder.IsEmpty()) |
| 160 return; | 160 return; |
| 161 | 161 |
| 162 Frame* frame = V8Window::toNative(holder)->frame(); | 162 Frame* frame = V8Window::toNative(holder)->frame(); |
| 163 ExceptionState es(info.GetIsolate()); | 163 ExceptionState exceptionState(info.GetIsolate()); |
| 164 if (!BindingSecurity::shouldAllowAccessToFrame(frame, es)) { | 164 if (!BindingSecurity::shouldAllowAccessToFrame(frame, exceptionState)) { |
| 165 es.throwIfNeeded(); | 165 exceptionState.throwIfNeeded(); |
| 166 return; | 166 return; |
| 167 } | 167 } |
| 168 | 168 |
| 169 ASSERT(frame); | 169 ASSERT(frame); |
| 170 v8::Local<v8::Context> context = frame->script().currentWorldContext(); | 170 v8::Local<v8::Context> context = frame->script().currentWorldContext(); |
| 171 if (context.IsEmpty()) | 171 if (context.IsEmpty()) |
| 172 return; | 172 return; |
| 173 | 173 |
| 174 v8::Handle<v8::String> eventSymbol = V8HiddenPropertyName::event(info.GetIso
late()); | 174 v8::Handle<v8::String> eventSymbol = V8HiddenPropertyName::event(info.GetIso
late()); |
| 175 v8::Handle<v8::Value> jsEvent = context->Global()->GetHiddenValue(eventSymbo
l); | 175 v8::Handle<v8::Value> jsEvent = context->Global()->GetHiddenValue(eventSymbo
l); |
| 176 if (jsEvent.IsEmpty()) | 176 if (jsEvent.IsEmpty()) |
| 177 return; | 177 return; |
| 178 v8SetReturnValue(info, jsEvent); | 178 v8SetReturnValue(info, jsEvent); |
| 179 } | 179 } |
| 180 | 180 |
| 181 void V8Window::eventAttributeSetterCustom(v8::Local<v8::Value> value, const v8::
PropertyCallbackInfo<void>& info) | 181 void V8Window::eventAttributeSetterCustom(v8::Local<v8::Value> value, const v8::
PropertyCallbackInfo<void>& info) |
| 182 { | 182 { |
| 183 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8
Window::GetTemplate(info.GetIsolate(), worldTypeInMainThread(info.GetIsolate()))
); | 183 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8
Window::GetTemplate(info.GetIsolate(), worldTypeInMainThread(info.GetIsolate()))
); |
| 184 if (holder.IsEmpty()) | 184 if (holder.IsEmpty()) |
| 185 return; | 185 return; |
| 186 | 186 |
| 187 Frame* frame = V8Window::toNative(holder)->frame(); | 187 Frame* frame = V8Window::toNative(holder)->frame(); |
| 188 ExceptionState es(info.GetIsolate()); | 188 ExceptionState exceptionState(info.GetIsolate()); |
| 189 if (!BindingSecurity::shouldAllowAccessToFrame(frame, es)) { | 189 if (!BindingSecurity::shouldAllowAccessToFrame(frame, exceptionState)) { |
| 190 es.throwIfNeeded(); | 190 exceptionState.throwIfNeeded(); |
| 191 return; | 191 return; |
| 192 } | 192 } |
| 193 | 193 |
| 194 ASSERT(frame); | 194 ASSERT(frame); |
| 195 v8::Local<v8::Context> context = frame->script().currentWorldContext(); | 195 v8::Local<v8::Context> context = frame->script().currentWorldContext(); |
| 196 if (context.IsEmpty()) | 196 if (context.IsEmpty()) |
| 197 return; | 197 return; |
| 198 | 198 |
| 199 v8::Handle<v8::String> eventSymbol = V8HiddenPropertyName::event(info.GetIso
late()); | 199 v8::Handle<v8::String> eventSymbol = V8HiddenPropertyName::event(info.GetIso
late()); |
| 200 context->Global()->SetHiddenValue(eventSymbol, value); | 200 context->Global()->SetHiddenValue(eventSymbol, value); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void V8Window::openerAttributeSetterCustom(v8::Local<v8::Value> value, const v8:
:PropertyCallbackInfo<void>& info) | 203 void V8Window::openerAttributeSetterCustom(v8::Local<v8::Value> value, const v8:
:PropertyCallbackInfo<void>& info) |
| 204 { | 204 { |
| 205 DOMWindow* imp = V8Window::toNative(info.Holder()); | 205 DOMWindow* imp = V8Window::toNative(info.Holder()); |
| 206 ExceptionState es(info.GetIsolate()); | 206 ExceptionState exceptionState(info.GetIsolate()); |
| 207 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame(), es)) { | 207 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame(), exceptionState)
) { |
| 208 es.throwIfNeeded(); | 208 exceptionState.throwIfNeeded(); |
| 209 return; | 209 return; |
| 210 } | 210 } |
| 211 | 211 |
| 212 // Opener can be shadowed if it is in the same domain. | 212 // Opener can be shadowed if it is in the same domain. |
| 213 // Have a special handling of null value to behave | 213 // Have a special handling of null value to behave |
| 214 // like Firefox. See bug http://b/1224887 & http://b/791706. | 214 // like Firefox. See bug http://b/1224887 & http://b/791706. |
| 215 if (value->IsNull()) { | 215 if (value->IsNull()) { |
| 216 // imp->frame() cannot be null, | 216 // imp->frame() cannot be null, |
| 217 // otherwise, SameOrigin check would have failed. | 217 // otherwise, SameOrigin check would have failed. |
| 218 ASSERT(imp->frame()); | 218 ASSERT(imp->frame()); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 } | 270 } |
| 271 } | 271 } |
| 272 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithUndefinedOrNullChe
ck>, targetOrigin, info[targetOriginArgIndex]); | 272 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithUndefinedOrNullChe
ck>, targetOrigin, info[targetOriginArgIndex]); |
| 273 | 273 |
| 274 bool didThrow = false; | 274 bool didThrow = false; |
| 275 RefPtr<SerializedScriptValue> message = | 275 RefPtr<SerializedScriptValue> message = |
| 276 SerializedScriptValue::create(info[0], &portArray, &arrayBufferArray, di
dThrow, info.GetIsolate()); | 276 SerializedScriptValue::create(info[0], &portArray, &arrayBufferArray, di
dThrow, info.GetIsolate()); |
| 277 if (didThrow) | 277 if (didThrow) |
| 278 return; | 278 return; |
| 279 | 279 |
| 280 ExceptionState es(info.GetIsolate()); | 280 ExceptionState exceptionState(info.GetIsolate()); |
| 281 window->postMessage(message.release(), &portArray, targetOrigin, source, es)
; | 281 window->postMessage(message.release(), &portArray, targetOrigin, source, exc
eptionState); |
| 282 es.throwIfNeeded(); | 282 exceptionState.throwIfNeeded(); |
| 283 } | 283 } |
| 284 | 284 |
| 285 // FIXME(fqian): returning string is cheating, and we should | 285 // FIXME(fqian): returning string is cheating, and we should |
| 286 // fix this by calling toString function on the receiver. | 286 // fix this by calling toString function on the receiver. |
| 287 // However, V8 implements toString in JavaScript, which requires | 287 // However, V8 implements toString in JavaScript, which requires |
| 288 // switching context of receiver. I consider it is dangerous. | 288 // switching context of receiver. I consider it is dangerous. |
| 289 void V8Window::toStringMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& i
nfo) | 289 void V8Window::toStringMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& i
nfo) |
| 290 { | 290 { |
| 291 v8::Handle<v8::Object> domWrapper = info.This()->FindInstanceInPrototypeChai
n(V8Window::GetTemplate(info.GetIsolate(), worldTypeInMainThread(info.GetIsolate
()))); | 291 v8::Handle<v8::Object> domWrapper = info.This()->FindInstanceInPrototypeChai
n(V8Window::GetTemplate(info.GetIsolate(), worldTypeInMainThread(info.GetIsolate
()))); |
| 292 if (domWrapper.IsEmpty()) { | 292 if (domWrapper.IsEmpty()) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 } | 334 } |
| 335 | 335 |
| 336 static void setUpDialog(DOMWindow* dialog, void* handler) | 336 static void setUpDialog(DOMWindow* dialog, void* handler) |
| 337 { | 337 { |
| 338 static_cast<DialogHandler*>(handler)->dialogCreated(dialog); | 338 static_cast<DialogHandler*>(handler)->dialogCreated(dialog); |
| 339 } | 339 } |
| 340 | 340 |
| 341 void V8Window::showModalDialogMethodCustom(const v8::FunctionCallbackInfo<v8::Va
lue>& info) | 341 void V8Window::showModalDialogMethodCustom(const v8::FunctionCallbackInfo<v8::Va
lue>& info) |
| 342 { | 342 { |
| 343 DOMWindow* impl = V8Window::toNative(info.Holder()); | 343 DOMWindow* impl = V8Window::toNative(info.Holder()); |
| 344 ExceptionState es(info.GetIsolate()); | 344 ExceptionState exceptionState(info.GetIsolate()); |
| 345 if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame(), es)) { | 345 if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame(), exceptionState
)) { |
| 346 es.throwIfNeeded(); | 346 exceptionState.throwIfNeeded(); |
| 347 return; | 347 return; |
| 348 } | 348 } |
| 349 | 349 |
| 350 // FIXME: Handle exceptions properly. | 350 // FIXME: Handle exceptions properly. |
| 351 String urlString = toWebCoreStringWithUndefinedOrNullCheck(info[0]); | 351 String urlString = toWebCoreStringWithUndefinedOrNullCheck(info[0]); |
| 352 DialogHandler handler(info[1]); | 352 DialogHandler handler(info[1]); |
| 353 String dialogFeaturesString = toWebCoreStringWithUndefinedOrNullCheck(info[2
]); | 353 String dialogFeaturesString = toWebCoreStringWithUndefinedOrNullCheck(info[2
]); |
| 354 | 354 |
| 355 impl->showModalDialog(urlString, dialogFeaturesString, activeDOMWindow(), fi
rstDOMWindow(), setUpDialog, &handler); | 355 impl->showModalDialog(urlString, dialogFeaturesString, activeDOMWindow(), fi
rstDOMWindow(), setUpDialog, &handler); |
| 356 | 356 |
| 357 v8SetReturnValue(info, handler.returnValue(info.GetIsolate())); | 357 v8SetReturnValue(info, handler.returnValue(info.GetIsolate())); |
| 358 } | 358 } |
| 359 | 359 |
| 360 void V8Window::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) | 360 void V8Window::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 361 { | 361 { |
| 362 DOMWindow* impl = V8Window::toNative(info.Holder()); | 362 DOMWindow* impl = V8Window::toNative(info.Holder()); |
| 363 ExceptionState es(info.GetIsolate()); | 363 ExceptionState exceptionState(info.GetIsolate()); |
| 364 if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame(), es)) { | 364 if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame(), exceptionState
)) { |
| 365 es.throwIfNeeded(); | 365 exceptionState.throwIfNeeded(); |
| 366 return; | 366 return; |
| 367 } | 367 } |
| 368 | 368 |
| 369 // FIXME: Handle exceptions properly. | 369 // FIXME: Handle exceptions properly. |
| 370 String urlString = toWebCoreStringWithUndefinedOrNullCheck(info[0]); | 370 String urlString = toWebCoreStringWithUndefinedOrNullCheck(info[0]); |
| 371 AtomicString frameName = (info[1]->IsUndefined() || info[1]->IsNull()) ? "_b
lank" : toWebCoreAtomicString(info[1]); | 371 AtomicString frameName = (info[1]->IsUndefined() || info[1]->IsNull()) ? "_b
lank" : toWebCoreAtomicString(info[1]); |
| 372 String windowFeaturesString = toWebCoreStringWithUndefinedOrNullCheck(info[2
]); | 372 String windowFeaturesString = toWebCoreStringWithUndefinedOrNullCheck(info[2
]); |
| 373 | 373 |
| 374 RefPtr<DOMWindow> openedWindow = impl->open(urlString, frameName, windowFeat
uresString, activeDOMWindow(), firstDOMWindow()); | 374 RefPtr<DOMWindow> openedWindow = impl->open(urlString, frameName, windowFeat
uresString, activeDOMWindow(), firstDOMWindow()); |
| 375 if (!openedWindow) | 375 if (!openedWindow) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 v8SetReturnValueFast(info, items.release(), window); | 416 v8SetReturnValueFast(info, items.release(), window); |
| 417 return; | 417 return; |
| 418 } | 418 } |
| 419 } | 419 } |
| 420 } | 420 } |
| 421 } | 421 } |
| 422 | 422 |
| 423 | 423 |
| 424 void V8Window::setTimeoutMethodCustom(const v8::FunctionCallbackInfo<v8::Value>&
info) | 424 void V8Window::setTimeoutMethodCustom(const v8::FunctionCallbackInfo<v8::Value>&
info) |
| 425 { | 425 { |
| 426 ExceptionState es(info.GetIsolate()); | 426 ExceptionState exceptionState(info.GetIsolate()); |
| 427 WindowSetTimeoutImpl(info, true, es); | 427 WindowSetTimeoutImpl(info, true, exceptionState); |
| 428 es.throwIfNeeded(); | 428 exceptionState.throwIfNeeded(); |
| 429 } | 429 } |
| 430 | 430 |
| 431 | 431 |
| 432 void V8Window::setIntervalMethodCustom(const v8::FunctionCallbackInfo<v8::Value>
& info) | 432 void V8Window::setIntervalMethodCustom(const v8::FunctionCallbackInfo<v8::Value>
& info) |
| 433 { | 433 { |
| 434 ExceptionState es(info.GetIsolate()); | 434 ExceptionState exceptionState(info.GetIsolate()); |
| 435 WindowSetTimeoutImpl(info, false, es); | 435 WindowSetTimeoutImpl(info, false, exceptionState); |
| 436 es.throwIfNeeded(); | 436 exceptionState.throwIfNeeded(); |
| 437 } | 437 } |
| 438 | 438 |
| 439 bool V8Window::namedSecurityCheckCustom(v8::Local<v8::Object> host, v8::Local<v8
::Value> key, v8::AccessType type, v8::Local<v8::Value>) | 439 bool V8Window::namedSecurityCheckCustom(v8::Local<v8::Object> host, v8::Local<v8
::Value> key, v8::AccessType type, v8::Local<v8::Value>) |
| 440 { | 440 { |
| 441 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 441 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 442 v8::Handle<v8::Object> window = host->FindInstanceInPrototypeChain(V8Window:
:GetTemplate(isolate, worldTypeInMainThread(isolate))); | 442 v8::Handle<v8::Object> window = host->FindInstanceInPrototypeChain(V8Window:
:GetTemplate(isolate, worldTypeInMainThread(isolate))); |
| 443 if (window.IsEmpty()) | 443 if (window.IsEmpty()) |
| 444 return false; // the frame is gone. | 444 return false; // the frame is gone. |
| 445 | 445 |
| 446 DOMWindow* targetWindow = V8Window::toNative(window); | 446 DOMWindow* targetWindow = V8Window::toNative(window); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 v8::Handle<v8::Context> context = frame->script().currentWorldContext(); | 542 v8::Handle<v8::Context> context = frame->script().currentWorldContext(); |
| 543 if (context.IsEmpty()) | 543 if (context.IsEmpty()) |
| 544 return v8Undefined(); | 544 return v8Undefined(); |
| 545 | 545 |
| 546 v8::Handle<v8::Object> global = context->Global(); | 546 v8::Handle<v8::Object> global = context->Global(); |
| 547 ASSERT(!global.IsEmpty()); | 547 ASSERT(!global.IsEmpty()); |
| 548 return global; | 548 return global; |
| 549 } | 549 } |
| 550 | 550 |
| 551 } // namespace WebCore | 551 } // namespace WebCore |
| OLD | NEW |