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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 #include "core/dom/MessagePort.h" | 48 #include "core/dom/MessagePort.h" |
49 #include "core/html/HTMLCollection.h" | 49 #include "core/html/HTMLCollection.h" |
50 #include "core/html/HTMLDocument.h" | 50 #include "core/html/HTMLDocument.h" |
51 #include "core/inspector/ScriptCallStack.h" | 51 #include "core/inspector/ScriptCallStack.h" |
52 #include "core/loader/FrameLoadRequest.h" | 52 #include "core/loader/FrameLoadRequest.h" |
53 #include "core/loader/FrameLoader.h" | 53 #include "core/loader/FrameLoader.h" |
54 #include "core/page/Chrome.h" | 54 #include "core/page/Chrome.h" |
55 #include "core/page/ContentSecurityPolicy.h" | 55 #include "core/page/ContentSecurityPolicy.h" |
56 #include "core/page/DOMTimer.h" | 56 #include "core/page/DOMTimer.h" |
57 #include "core/page/DOMWindow.h" | 57 #include "core/page/DOMWindow.h" |
| 58 #include "core/page/DOMWindowTimers.h" |
58 #include "core/page/Frame.h" | 59 #include "core/page/Frame.h" |
59 #include "core/page/FrameView.h" | 60 #include "core/page/FrameView.h" |
60 #include "core/page/Location.h" | 61 #include "core/page/Location.h" |
61 #include "core/page/Page.h" | 62 #include "core/page/Page.h" |
62 #include "core/page/Settings.h" | 63 #include "core/page/Settings.h" |
63 #include "core/page/WindowFeatures.h" | 64 #include "core/page/WindowFeatures.h" |
64 #include "core/platform/PlatformScreen.h" | 65 #include "core/platform/PlatformScreen.h" |
65 #include "core/platform/graphics/MediaPlayer.h" | 66 #include "core/platform/graphics/MediaPlayer.h" |
66 #include "core/storage/Storage.h" | 67 #include "core/storage/Storage.h" |
67 #include "core/workers/SharedWorkerRepository.h" | 68 #include "core/workers/SharedWorkerRepository.h" |
68 #include "wtf/ArrayBuffer.h" | 69 #include "wtf/ArrayBuffer.h" |
| 70 #include "wtf/OwnArrayPtr.h" |
69 | 71 |
70 namespace WebCore { | 72 namespace WebCore { |
71 | 73 |
| 74 // FIXME: There is a lot of duplication with SetTimeoutOrInterval() in V8WorkerG
lobalScopeCustom.cpp. |
| 75 // We should refactor this. |
72 void WindowSetTimeoutImpl(const v8::FunctionCallbackInfo<v8::Value>& args, bool
singleShot) | 76 void WindowSetTimeoutImpl(const v8::FunctionCallbackInfo<v8::Value>& args, bool
singleShot) |
73 { | 77 { |
74 int argumentCount = args.Length(); | 78 int argumentCount = args.Length(); |
75 | 79 |
76 if (argumentCount < 1) | 80 if (argumentCount < 1) |
77 return; | 81 return; |
78 | 82 |
79 DOMWindow* imp = V8Window::toNative(args.Holder()); | 83 DOMWindow* imp = V8Window::toNative(args.Holder()); |
80 ScriptExecutionContext* scriptContext = static_cast<ScriptExecutionContext*>
(imp->document()); | 84 ScriptExecutionContext* scriptContext = static_cast<ScriptExecutionContext*>
(imp->document()); |
81 | 85 |
82 if (!scriptContext) { | 86 if (!scriptContext) { |
83 setDOMException(InvalidAccessError, args.GetIsolate()); | 87 setDOMException(InvalidAccessError, args.GetIsolate()); |
84 return; | 88 return; |
85 } | 89 } |
86 | 90 |
87 v8::Handle<v8::Value> function = args[0]; | 91 v8::Handle<v8::Value> function = args[0]; |
88 WTF::String functionString; | 92 String functionString; |
89 if (!function->IsFunction()) { | 93 if (!function->IsFunction()) { |
90 if (function->IsString()) { | 94 if (function->IsString()) { |
91 functionString = toWebCoreString(function); | 95 functionString = toWebCoreString(function); |
92 } else { | 96 } else { |
93 v8::Handle<v8::Value> v8String = function->ToString(); | 97 v8::Handle<v8::Value> v8String = function->ToString(); |
94 | 98 |
95 // Bail out if string conversion failed. | 99 // Bail out if string conversion failed. |
96 if (v8String.IsEmpty()) | 100 if (v8String.IsEmpty()) |
97 return; | 101 return; |
98 | 102 |
99 functionString = toWebCoreString(v8String); | 103 functionString = toWebCoreString(v8String); |
100 } | 104 } |
101 | 105 |
102 // Don't allow setting timeouts to run empty functions! | 106 // Don't allow setting timeouts to run empty functions! |
103 // (Bug 1009597) | 107 // (Bug 1009597) |
104 if (!functionString.length()) | 108 if (!functionString.length()) |
105 return; | 109 return; |
106 } | 110 } |
107 | 111 |
108 int32_t timeout = 0; | |
109 if (argumentCount >= 2) | |
110 timeout = args[1]->Int32Value(); | |
111 | |
112 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame())) | 112 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame())) |
113 return; | 113 return; |
114 | 114 |
115 int id; | 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 v8::Local<v8::Value>* params = 0; | 118 OwnArrayPtr<v8::Local<v8::Value> > params; |
119 if (paramCount > 0) { | 119 if (paramCount > 0) { |
120 params = 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 |
123 params[i] = args[i+2]; | 123 params[i] = args[i+2]; |
124 } | 124 } |
125 } | 125 } |
126 | 126 |
127 // params is passed to action, and released in action's destructor | 127 // params is passed to action, and released in action's destructor |
128 ASSERT(imp->frame()); | 128 ASSERT(imp->frame()); |
129 OwnPtr<ScheduledAction> action = adoptPtr(new ScheduledAction(imp->frame
()->script()->currentWorldContext(), v8::Handle<v8::Function>::Cast(function), p
aramCount, params, args.GetIsolate())); | 129 action = adoptPtr(new ScheduledAction(imp->frame()->script()->currentWor
ldContext(), v8::Handle<v8::Function>::Cast(function), paramCount, params.get(),
args.GetIsolate())); |
130 | |
131 // FIXME: We should use OwnArrayPtr for params. | |
132 delete[] params; | |
133 | |
134 id = DOMTimer::install(scriptContext, action.release(), timeout, singleS
hot); | |
135 } else { | 130 } else { |
136 if (imp->document() && !imp->document()->contentSecurityPolicy()->allowE
val()) { | 131 if (imp->document() && !imp->document()->contentSecurityPolicy()->allowE
val()) { |
137 v8SetReturnValue(args, 0); | 132 v8SetReturnValue(args, 0); |
138 return; | 133 return; |
139 } | 134 } |
140 ASSERT(imp->frame()); | 135 ASSERT(imp->frame()); |
141 id = DOMTimer::install(scriptContext, adoptPtr(new ScheduledAction(imp->
frame()->script()->currentWorldContext(), functionString, KURL(), args.GetIsolat
e())), timeout, singleShot); | 136 action = adoptPtr(new ScheduledAction(imp->frame()->script()->currentWor
ldContext(), functionString, KURL(), args.GetIsolate())); |
142 } | 137 } |
143 | 138 |
| 139 int32_t timeout = argumentCount >= 2 ? args[1]->Int32Value() : 0; |
| 140 int timerId; |
| 141 if (singleShot) |
| 142 timerId = DOMWindowTimers::setTimeout(imp, action.release(), timeout); |
| 143 else |
| 144 timerId = DOMWindowTimers::setInterval(imp, action.release(), timeout); |
| 145 |
144 // Try to do the idle notification before the timeout expires to get better | 146 // Try to do the idle notification before the timeout expires to get better |
145 // use of any idle time. Aim for the middle of the interval for simplicity. | 147 // use of any idle time. Aim for the middle of the interval for simplicity. |
146 if (timeout >= 0) { | 148 if (timeout >= 0) { |
147 double maximumFireInterval = static_cast<double>(timeout) / 1000 / 2; | 149 double maximumFireInterval = static_cast<double>(timeout) / 1000 / 2; |
148 V8GCForContextDispose::instance().notifyIdleSooner(maximumFireInterval); | 150 V8GCForContextDispose::instance().notifyIdleSooner(maximumFireInterval); |
149 } | 151 } |
150 | 152 |
151 v8SetReturnValue(args, id); | 153 v8SetReturnValue(args, timerId); |
152 } | 154 } |
153 | 155 |
154 void V8Window::eventAttrGetterCustom(v8::Local<v8::String> name, const v8::Prope
rtyCallbackInfo<v8::Value>& info) | 156 void V8Window::eventAttrGetterCustom(v8::Local<v8::String> name, const v8::Prope
rtyCallbackInfo<v8::Value>& info) |
155 { | 157 { |
156 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()))
); |
157 if (holder.IsEmpty()) | 159 if (holder.IsEmpty()) |
158 return; | 160 return; |
159 | 161 |
160 Frame* frame = V8Window::toNative(holder)->frame(); | 162 Frame* frame = V8Window::toNative(holder)->frame(); |
161 if (!BindingSecurity::shouldAllowAccessToFrame(frame)) | 163 if (!BindingSecurity::shouldAllowAccessToFrame(frame)) |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 ASSERT(!global.IsEmpty()); | 541 ASSERT(!global.IsEmpty()); |
540 return global; | 542 return global; |
541 } | 543 } |
542 | 544 |
543 v8::Handle<v8::Value> toV8ForMainWorld(DOMWindow* window, v8::Handle<v8::Object>
creationContext, v8::Isolate* isolate) | 545 v8::Handle<v8::Value> toV8ForMainWorld(DOMWindow* window, v8::Handle<v8::Object>
creationContext, v8::Isolate* isolate) |
544 { | 546 { |
545 return toV8(window, creationContext, isolate); | 547 return toV8(window, creationContext, isolate); |
546 } | 548 } |
547 | 549 |
548 } // namespace WebCore | 550 } // namespace WebCore |
OLD | NEW |