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 16 matching lines...) Expand all Loading... |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "bindings/core/v8/V8Window.h" | 32 #include "bindings/core/v8/V8Window.h" |
33 | 33 |
34 #include "bindings/core/v8/BindingSecurity.h" | 34 #include "bindings/core/v8/BindingSecurity.h" |
35 #include "bindings/core/v8/ExceptionMessages.h" | 35 #include "bindings/core/v8/ExceptionMessages.h" |
36 #include "bindings/core/v8/ExceptionState.h" | 36 #include "bindings/core/v8/ExceptionState.h" |
37 #include "bindings/core/v8/ScheduledAction.h" | |
38 #include "bindings/core/v8/ScriptController.h" | 37 #include "bindings/core/v8/ScriptController.h" |
39 #include "bindings/core/v8/ScriptSourceCode.h" | 38 #include "bindings/core/v8/ScriptSourceCode.h" |
40 #include "bindings/core/v8/SerializedScriptValue.h" | 39 #include "bindings/core/v8/SerializedScriptValue.h" |
41 #include "bindings/core/v8/V8Binding.h" | 40 #include "bindings/core/v8/V8Binding.h" |
42 #include "bindings/core/v8/V8EventListener.h" | 41 #include "bindings/core/v8/V8EventListener.h" |
43 #include "bindings/core/v8/V8EventListenerList.h" | 42 #include "bindings/core/v8/V8EventListenerList.h" |
44 #include "bindings/core/v8/V8GCForContextDispose.h" | |
45 #include "bindings/core/v8/V8HTMLCollection.h" | 43 #include "bindings/core/v8/V8HTMLCollection.h" |
46 #include "bindings/core/v8/V8HiddenValue.h" | 44 #include "bindings/core/v8/V8HiddenValue.h" |
47 #include "bindings/core/v8/V8Node.h" | 45 #include "bindings/core/v8/V8Node.h" |
48 #include "core/dom/DOMArrayBuffer.h" | 46 #include "core/dom/DOMArrayBuffer.h" |
49 #include "core/dom/ExceptionCode.h" | 47 #include "core/dom/ExceptionCode.h" |
50 #include "core/dom/MessagePort.h" | 48 #include "core/dom/MessagePort.h" |
51 #include "core/frame/DOMTimer.h" | |
52 #include "core/frame/DOMWindowTimers.h" | |
53 #include "core/frame/FrameView.h" | 49 #include "core/frame/FrameView.h" |
54 #include "core/frame/LocalDOMWindow.h" | 50 #include "core/frame/LocalDOMWindow.h" |
55 #include "core/frame/LocalFrame.h" | 51 #include "core/frame/LocalFrame.h" |
56 #include "core/frame/Settings.h" | 52 #include "core/frame/Settings.h" |
57 #include "core/frame/UseCounter.h" | 53 #include "core/frame/UseCounter.h" |
58 #include "core/frame/csp/ContentSecurityPolicy.h" | 54 #include "core/frame/csp/ContentSecurityPolicy.h" |
59 #include "core/html/HTMLCollection.h" | 55 #include "core/html/HTMLCollection.h" |
60 #include "core/html/HTMLDocument.h" | 56 #include "core/html/HTMLDocument.h" |
61 #include "core/inspector/ScriptCallStack.h" | 57 #include "core/inspector/ScriptCallStack.h" |
62 #include "core/loader/FrameLoadRequest.h" | 58 #include "core/loader/FrameLoadRequest.h" |
63 #include "core/loader/FrameLoader.h" | 59 #include "core/loader/FrameLoader.h" |
64 #include "core/storage/Storage.h" | 60 #include "core/storage/Storage.h" |
65 #include "platform/PlatformScreen.h" | 61 #include "platform/PlatformScreen.h" |
66 #include "platform/graphics/media/MediaPlayer.h" | 62 #include "platform/graphics/media/MediaPlayer.h" |
67 #include "wtf/Assertions.h" | 63 #include "wtf/Assertions.h" |
68 #include "wtf/OwnPtr.h" | 64 #include "wtf/OwnPtr.h" |
69 | 65 |
70 namespace blink { | 66 namespace blink { |
71 | 67 |
72 // FIXME: There is a lot of duplication with SetTimeoutOrInterval() in V8WorkerG
lobalScopeCustom.cpp. | |
73 // We should refactor this. | |
74 static void windowSetTimeoutImpl(const v8::FunctionCallbackInfo<v8::Value>& info
, bool singleShot, ExceptionState& exceptionState) | |
75 { | |
76 int argumentCount = info.Length(); | |
77 | |
78 if (argumentCount < 1) | |
79 return; | |
80 | |
81 LocalDOMWindow* impl = toLocalDOMWindow(V8Window::toImpl(info.Holder())); | |
82 if (!impl->frame() || !impl->document()) { | |
83 exceptionState.throwDOMException(InvalidAccessError, "No script context
is available in which to execute the script."); | |
84 return; | |
85 } | |
86 ScriptState* scriptState = ScriptState::current(info.GetIsolate()); | |
87 v8::Handle<v8::Value> function = info[0]; | |
88 String functionString; | |
89 if (!function->IsFunction()) { | |
90 if (function->IsString()) { | |
91 functionString = toCoreString(function.As<v8::String>()); | |
92 } else { | |
93 v8::Handle<v8::String> v8String = function->ToString(); | |
94 | |
95 // Bail out if string conversion failed. | |
96 if (v8String.IsEmpty()) | |
97 return; | |
98 | |
99 functionString = toCoreString(v8String); | |
100 } | |
101 | |
102 // Don't allow setting timeouts to run empty functions! | |
103 // (Bug 1009597) | |
104 if (!functionString.length()) | |
105 return; | |
106 } | |
107 | |
108 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->fram
e(), exceptionState)) | |
109 return; | |
110 | |
111 OwnPtr<ScheduledAction> action; | |
112 if (function->IsFunction()) { | |
113 int paramCount = argumentCount >= 2 ? argumentCount - 2 : 0; | |
114 OwnPtr<v8::Local<v8::Value>[]> params; | |
115 if (paramCount > 0) { | |
116 params = adoptArrayPtr(new v8::Local<v8::Value>[paramCount]); | |
117 for (int i = 0; i < paramCount; i++) { | |
118 // parameters must be globalized | |
119 params[i] = info[i+2]; | |
120 } | |
121 } | |
122 | |
123 // params is passed to action, and released in action's destructor | |
124 ASSERT(impl->frame()); | |
125 action = adoptPtr(new ScheduledAction(scriptState, v8::Handle<v8::Functi
on>::Cast(function), paramCount, params.get(), info.GetIsolate())); | |
126 } else { | |
127 if (impl->document() && !impl->document()->contentSecurityPolicy()->allo
wEval()) { | |
128 v8SetReturnValue(info, 0); | |
129 return; | |
130 } | |
131 ASSERT(impl->frame()); | |
132 action = adoptPtr(new ScheduledAction(scriptState, functionString, KURL(
), info.GetIsolate())); | |
133 } | |
134 | |
135 int32_t timeout = argumentCount >= 2 ? info[1]->Int32Value() : 0; | |
136 int timerId; | |
137 if (singleShot) | |
138 timerId = DOMWindowTimers::setTimeout(*impl, action.release(), timeout); | |
139 else | |
140 timerId = DOMWindowTimers::setInterval(*impl, action.release(), timeout)
; | |
141 | |
142 // FIXME: Crude hack that attempts to pass idle time to V8. This should be | |
143 // done using the scheduler instead. | |
144 if (timeout >= 0) | |
145 V8GCForContextDispose::instance().notifyIdle(); | |
146 | |
147 v8SetReturnValue(info, timerId); | |
148 } | |
149 | |
150 void V8Window::eventAttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Val
ue>& info) | 68 void V8Window::eventAttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Val
ue>& info) |
151 { | 69 { |
152 LocalFrame* frame = toLocalDOMWindow(V8Window::toImpl(info.Holder()))->frame
(); | 70 LocalFrame* frame = toLocalDOMWindow(V8Window::toImpl(info.Holder()))->frame
(); |
153 ExceptionState exceptionState(ExceptionState::GetterContext, "event", "Windo
w", info.Holder(), info.GetIsolate()); | 71 ExceptionState exceptionState(ExceptionState::GetterContext, "event", "Windo
w", info.Holder(), info.GetIsolate()); |
154 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), frame, exc
eptionState)) { | 72 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), frame, exc
eptionState)) { |
155 exceptionState.throwIfNeeded(); | 73 exceptionState.throwIfNeeded(); |
156 return; | 74 return; |
157 } | 75 } |
158 | 76 |
159 ASSERT(frame); | 77 ASSERT(frame); |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 v8SetReturnValueFast(info, items->item(0), window); | 349 v8SetReturnValueFast(info, items->item(0), window); |
432 return; | 350 return; |
433 } | 351 } |
434 v8SetReturnValueFast(info, items.release(), window); | 352 v8SetReturnValueFast(info, items.release(), window); |
435 return; | 353 return; |
436 } | 354 } |
437 } | 355 } |
438 } | 356 } |
439 } | 357 } |
440 | 358 |
441 | |
442 void V8Window::setTimeoutMethodCustom(const v8::FunctionCallbackInfo<v8::Value>&
info) | |
443 { | |
444 ExceptionState exceptionState(ExceptionState::ExecutionContext, "setTimeout"
, "Window", info.Holder(), info.GetIsolate()); | |
445 windowSetTimeoutImpl(info, true, exceptionState); | |
446 exceptionState.throwIfNeeded(); | |
447 } | |
448 | |
449 | |
450 void V8Window::setIntervalMethodCustom(const v8::FunctionCallbackInfo<v8::Value>
& info) | |
451 { | |
452 ExceptionState exceptionState(ExceptionState::ExecutionContext, "setInterval
", "Window", info.Holder(), info.GetIsolate()); | |
453 windowSetTimeoutImpl(info, false, exceptionState); | |
454 exceptionState.throwIfNeeded(); | |
455 } | |
456 | |
457 bool V8Window::namedSecurityCheckCustom(v8::Local<v8::Object> host, v8::Local<v8
::Value> key, v8::AccessType type, v8::Local<v8::Value>) | 359 bool V8Window::namedSecurityCheckCustom(v8::Local<v8::Object> host, v8::Local<v8
::Value> key, v8::AccessType type, v8::Local<v8::Value>) |
458 { | 360 { |
459 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 361 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
460 v8::Handle<v8::Object> window = V8Window::findInstanceInPrototypeChain(host,
isolate); | 362 v8::Handle<v8::Object> window = V8Window::findInstanceInPrototypeChain(host,
isolate); |
461 if (window.IsEmpty()) | 363 if (window.IsEmpty()) |
462 return false; // the frame is gone. | 364 return false; // the frame is gone. |
463 | 365 |
464 DOMWindow* targetWindow = V8Window::toImpl(window); | 366 DOMWindow* targetWindow = V8Window::toImpl(window); |
465 ASSERT(targetWindow); | 367 ASSERT(targetWindow); |
466 if (!targetWindow->isLocalDOMWindow()) | 368 if (!targetWindow->isLocalDOMWindow()) |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 v8::Handle<v8::Context> context = toV8Context(frame, DOMWrapperWorld::curren
t(isolate)); | 452 v8::Handle<v8::Context> context = toV8Context(frame, DOMWrapperWorld::curren
t(isolate)); |
551 if (context.IsEmpty()) | 453 if (context.IsEmpty()) |
552 return v8Undefined(); | 454 return v8Undefined(); |
553 | 455 |
554 v8::Handle<v8::Object> global = context->Global(); | 456 v8::Handle<v8::Object> global = context->Global(); |
555 ASSERT(!global.IsEmpty()); | 457 ASSERT(!global.IsEmpty()); |
556 return global; | 458 return global; |
557 } | 459 } |
558 | 460 |
559 } // namespace blink | 461 } // namespace blink |
OLD | NEW |