Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: Source/bindings/v8/custom/V8DOMWindowCustom.cpp

Issue 17035010: Revert "Rename DOMWindow interface to Window" (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/bindings/v8/V8WindowShell.cpp ('k') | Source/bindings/v8/custom/V8DocumentCustom.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 11 matching lines...) Expand all
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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 "V8Window.h" 32 #include "V8DOMWindow.h"
33 33
34 #include "V8HTMLCollection.h" 34 #include "V8HTMLCollection.h"
35 #include "V8Node.h" 35 #include "V8Node.h"
36 #include "bindings/v8/BindingSecurity.h" 36 #include "bindings/v8/BindingSecurity.h"
37 #include "bindings/v8/ScheduledAction.h" 37 #include "bindings/v8/ScheduledAction.h"
38 #include "bindings/v8/ScriptController.h" 38 #include "bindings/v8/ScriptController.h"
39 #include "bindings/v8/ScriptSourceCode.h" 39 #include "bindings/v8/ScriptSourceCode.h"
40 #include "bindings/v8/SerializedScriptValue.h" 40 #include "bindings/v8/SerializedScriptValue.h"
41 #include "bindings/v8/V8Binding.h" 41 #include "bindings/v8/V8Binding.h"
42 #include "bindings/v8/V8EventListener.h" 42 #include "bindings/v8/V8EventListener.h"
(...skipping 26 matching lines...) Expand all
69 69
70 namespace WebCore { 70 namespace WebCore {
71 71
72 void WindowSetTimeoutImpl(const v8::FunctionCallbackInfo<v8::Value>& args, bool singleShot) 72 void WindowSetTimeoutImpl(const v8::FunctionCallbackInfo<v8::Value>& args, bool singleShot)
73 { 73 {
74 int argumentCount = args.Length(); 74 int argumentCount = args.Length();
75 75
76 if (argumentCount < 1) 76 if (argumentCount < 1)
77 return; 77 return;
78 78
79 DOMWindow* imp = V8Window::toNative(args.Holder()); 79 DOMWindow* imp = V8DOMWindow::toNative(args.Holder());
80 ScriptExecutionContext* scriptContext = static_cast<ScriptExecutionContext*> (imp->document()); 80 ScriptExecutionContext* scriptContext = static_cast<ScriptExecutionContext*> (imp->document());
81 81
82 if (!scriptContext) { 82 if (!scriptContext) {
83 setDOMException(INVALID_ACCESS_ERR, args.GetIsolate()); 83 setDOMException(INVALID_ACCESS_ERR, args.GetIsolate());
84 return; 84 return;
85 } 85 }
86 86
87 v8::Handle<v8::Value> function = args[0]; 87 v8::Handle<v8::Value> function = args[0];
88 WTF::String functionString; 88 WTF::String functionString;
89 if (!function->IsFunction()) { 89 if (!function->IsFunction()) {
90 if (function->IsString()) { 90 if (function->IsString())
91 functionString = toWebCoreString(function); 91 functionString = toWebCoreString(function);
92 } else { 92 else {
93 v8::Handle<v8::Value> v8String = function->ToString(); 93 v8::Handle<v8::Value> v8String = function->ToString();
94 94
95 // Bail out if string conversion failed. 95 // Bail out if string conversion failed.
96 if (v8String.IsEmpty()) 96 if (v8String.IsEmpty())
97 return; 97 return;
98 98
99 functionString = toWebCoreString(v8String); 99 functionString = toWebCoreString(v8String);
100 } 100 }
101 101
102 // Don't allow setting timeouts to run empty functions! 102 // Don't allow setting timeouts to run empty functions!
103 // (Bug 1009597) 103 // (Bug 1009597)
104 if (!functionString.length()) 104 if (functionString.length() == 0)
105 return; 105 return;
106 } 106 }
107 107
108 int32_t timeout = 0; 108 int32_t timeout = 0;
109 if (argumentCount >= 2) 109 if (argumentCount >= 2)
110 timeout = args[1]->Int32Value(); 110 timeout = args[1]->Int32Value();
111 111
112 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame())) 112 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame()))
113 return; 113 return;
114 114
115 int id; 115 int id;
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 v8::Local<v8::Value>* params = 0;
119 if (paramCount > 0) { 119 if (paramCount > 0) {
120 params = new v8::Local<v8::Value>[paramCount]; 120 params = 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 }
125 } 124 }
126 125
127 // params is passed to action, and released in action's destructor 126 // params is passed to action, and released in action's destructor
128 ASSERT(imp->frame()); 127 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())); 128 OwnPtr<ScheduledAction> action = adoptPtr(new ScheduledAction(imp->frame ()->script()->currentWorldContext(), v8::Handle<v8::Function>::Cast(function), p aramCount, params, args.GetIsolate()));
130 129
131 // FIXME: We should use OwnArrayPtr for params. 130 // FIXME: We should use OwnArrayPtr for params.
132 delete[] params; 131 delete[] params;
133 132
134 id = DOMTimer::install(scriptContext, action.release(), timeout, singleS hot); 133 id = DOMTimer::install(scriptContext, action.release(), timeout, singleS hot);
135 } else { 134 } else {
136 if (imp->document() && !imp->document()->contentSecurityPolicy()->allowE val()) { 135 if (imp->document() && !imp->document()->contentSecurityPolicy()->allowE val()) {
137 v8SetReturnValue(args, 0); 136 v8SetReturnValue(args, 0);
138 return; 137 return;
139 } 138 }
140 ASSERT(imp->frame()); 139 ASSERT(imp->frame());
141 id = DOMTimer::install(scriptContext, adoptPtr(new ScheduledAction(imp-> frame()->script()->currentWorldContext(), functionString, KURL(), args.GetIsolat e())), timeout, singleShot); 140 id = DOMTimer::install(scriptContext, adoptPtr(new ScheduledAction(imp-> frame()->script()->currentWorldContext(), functionString, KURL(), args.GetIsolat e())), timeout, singleShot);
142 } 141 }
143 142
144 // Try to do the idle notification before the timeout expires to get better 143 // 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. 144 // use of any idle time. Aim for the middle of the interval for simplicity.
146 if (timeout >= 0) { 145 if (timeout >= 0) {
147 double maximumFireInterval = static_cast<double>(timeout) / 1000 / 2; 146 double maximumFireInterval = static_cast<double>(timeout) / 1000 / 2;
148 V8GCForContextDispose::instance().notifyIdleSooner(maximumFireInterval); 147 V8GCForContextDispose::instance().notifyIdleSooner(maximumFireInterval);
149 } 148 }
150 149
151 v8SetReturnValue(args, id); 150 v8SetReturnValue(args, id);
152 } 151 }
153 152
154 void V8Window::eventAttrGetterCustom(v8::Local<v8::String> name, const v8::Prope rtyCallbackInfo<v8::Value>& info) 153 void V8DOMWindow::eventAttrGetterCustom(v8::Local<v8::String> name, const v8::Pr opertyCallbackInfo<v8::Value>& info)
155 { 154 {
156 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8 Window::GetTemplate(info.GetIsolate(), worldTypeInMainThread(info.GetIsolate())) ); 155 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8 DOMWindow::GetTemplate(info.GetIsolate(), worldTypeInMainThread(info.GetIsolate( ))));
157 if (holder.IsEmpty()) 156 if (holder.IsEmpty())
158 return; 157 return;
159 158
160 Frame* frame = V8Window::toNative(holder)->frame(); 159 Frame* frame = V8DOMWindow::toNative(holder)->frame();
161 if (!BindingSecurity::shouldAllowAccessToFrame(frame)) 160 if (!BindingSecurity::shouldAllowAccessToFrame(frame))
162 return; 161 return;
163 162
164 ASSERT(frame); 163 ASSERT(frame);
165 v8::Local<v8::Context> context = frame->script()->currentWorldContext(); 164 v8::Local<v8::Context> context = frame->script()->currentWorldContext();
166 if (context.IsEmpty()) 165 if (context.IsEmpty())
167 return; 166 return;
168 167
169 v8::Handle<v8::String> eventSymbol = V8HiddenPropertyName::event(); 168 v8::Handle<v8::String> eventSymbol = V8HiddenPropertyName::event();
170 v8::Handle<v8::Value> jsEvent = context->Global()->GetHiddenValue(eventSymbo l); 169 v8::Handle<v8::Value> jsEvent = context->Global()->GetHiddenValue(eventSymbo l);
171 if (jsEvent.IsEmpty()) 170 if (jsEvent.IsEmpty())
172 return; 171 return;
173 v8SetReturnValue(info, jsEvent); 172 v8SetReturnValue(info, jsEvent);
174 } 173 }
175 174
176 void V8Window::eventAttrSetterCustom(v8::Local<v8::String> name, v8::Local<v8::V alue> value, const v8::PropertyCallbackInfo<void>& info) 175 void V8DOMWindow::eventAttrSetterCustom(v8::Local<v8::String> name, v8::Local<v8 ::Value> value, const v8::PropertyCallbackInfo<void>& info)
177 { 176 {
178 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8 Window::GetTemplate(info.GetIsolate(), worldTypeInMainThread(info.GetIsolate())) ); 177 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8 DOMWindow::GetTemplate(info.GetIsolate(), worldTypeInMainThread(info.GetIsolate( ))));
179 if (holder.IsEmpty()) 178 if (holder.IsEmpty())
180 return; 179 return;
181 180
182 Frame* frame = V8Window::toNative(holder)->frame(); 181 Frame* frame = V8DOMWindow::toNative(holder)->frame();
183 if (!BindingSecurity::shouldAllowAccessToFrame(frame)) 182 if (!BindingSecurity::shouldAllowAccessToFrame(frame))
184 return; 183 return;
185 184
186 ASSERT(frame); 185 ASSERT(frame);
187 v8::Local<v8::Context> context = frame->script()->currentWorldContext(); 186 v8::Local<v8::Context> context = frame->script()->currentWorldContext();
188 if (context.IsEmpty()) 187 if (context.IsEmpty())
189 return; 188 return;
190 189
191 v8::Handle<v8::String> eventSymbol = V8HiddenPropertyName::event(); 190 v8::Handle<v8::String> eventSymbol = V8HiddenPropertyName::event();
192 context->Global()->SetHiddenValue(eventSymbol, value); 191 context->Global()->SetHiddenValue(eventSymbol, value);
193 } 192 }
194 193
195 void V8Window::locationAttrSetterCustom(v8::Local<v8::String> name, v8::Local<v8 ::Value> value, const v8::PropertyCallbackInfo<void>& info) 194 void V8DOMWindow::locationAttrSetterCustom(v8::Local<v8::String> name, v8::Local <v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
196 { 195 {
197 DOMWindow* imp = V8Window::toNative(info.Holder()); 196 DOMWindow* imp = V8DOMWindow::toNative(info.Holder());
198 197
199 DOMWindow* active = activeDOMWindow(); 198 DOMWindow* active = activeDOMWindow();
200 if (!active) 199 if (!active)
201 return; 200 return;
202 201
203 DOMWindow* first = firstDOMWindow(); 202 DOMWindow* first = firstDOMWindow();
204 if (!first) 203 if (!first)
205 return; 204 return;
206 205
207 if (Location* location = imp->location()) 206 if (Location* location = imp->location())
208 location->setHref(active, first, toWebCoreString(value)); 207 location->setHref(active, first, toWebCoreString(value));
209 } 208 }
210 209
211 void V8Window::openerAttrSetterCustom(v8::Local<v8::String> name, v8::Local<v8:: Value> value, const v8::PropertyCallbackInfo<void>& info) 210 void V8DOMWindow::openerAttrSetterCustom(v8::Local<v8::String> name, v8::Local<v 8::Value> value, const v8::PropertyCallbackInfo<void>& info)
212 { 211 {
213 DOMWindow* imp = V8Window::toNative(info.Holder()); 212 DOMWindow* imp = V8DOMWindow::toNative(info.Holder());
214 213
215 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame())) 214 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame()))
216 return; 215 return;
217 216
218 // Opener can be shadowed if it is in the same domain. 217 // Opener can be shadowed if it is in the same domain.
219 // Have a special handling of null value to behave 218 // Have a special handling of null value to behave
220 // like Firefox. See bug http://b/1224887 & http://b/791706. 219 // like Firefox. See bug http://b/1224887 & http://b/791706.
221 if (value->IsNull()) { 220 if (value->IsNull()) {
222 // imp->frame() cannot be null, 221 // imp->frame() cannot be null,
223 // otherwise, SameOrigin check would have failed. 222 // otherwise, SameOrigin check would have failed.
224 ASSERT(imp->frame()); 223 ASSERT(imp->frame());
225 imp->frame()->loader()->setOpener(0); 224 imp->frame()->loader()->setOpener(0);
226 } 225 }
227 226
228 // Delete the accessor from this object. 227 // Delete the accessor from this object.
229 info.Holder()->Delete(name); 228 info.Holder()->Delete(name);
230 229
231 // Put property on the front (this) object. 230 // Put property on the front (this) object.
232 info.This()->Set(name, value); 231 info.This()->Set(name, value);
233 } 232 }
234 233
235 void V8Window::addEventListenerMethodCustom(const v8::FunctionCallbackInfo<v8::V alue>& args) 234 void V8DOMWindow::addEventListenerMethodCustom(const v8::FunctionCallbackInfo<v8 ::Value>& args)
236 { 235 {
237 String eventType = toWebCoreString(args[0]); 236 String eventType = toWebCoreString(args[0]);
238 bool useCapture = args[2]->BooleanValue(); 237 bool useCapture = args[2]->BooleanValue();
239 238
240 DOMWindow* imp = V8Window::toNative(args.Holder()); 239 DOMWindow* imp = V8DOMWindow::toNative(args.Holder());
241 240
242 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame())) 241 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame()))
243 return; 242 return;
244 243
245 Document* doc = imp->document(); 244 Document* doc = imp->document();
246 245
247 if (!doc) 246 if (!doc)
248 return; 247 return;
249 248
250 // FIXME: Check if there is not enough arguments 249 // FIXME: Check if there is not enough arguments
251 if (!imp->frame()) 250 if (!imp->frame())
252 return; 251 return;
253 252
254 RefPtr<EventListener> listener = V8EventListenerList::getEventListener(args[ 1], false, ListenerFindOrCreate); 253 RefPtr<EventListener> listener = V8EventListenerList::getEventListener(args[ 1], false, ListenerFindOrCreate);
255 254
256 if (listener) { 255 if (listener) {
257 imp->addEventListener(eventType, listener, useCapture); 256 imp->addEventListener(eventType, listener, useCapture);
258 createHiddenDependency(args.Holder(), args[1], eventListenerCacheIndex, args.GetIsolate()); 257 createHiddenDependency(args.Holder(), args[1], eventListenerCacheIndex, args.GetIsolate());
259 } 258 }
260 } 259 }
261 260
262 261
263 void V8Window::removeEventListenerMethodCustom(const v8::FunctionCallbackInfo<v8 ::Value>& args) 262 void V8DOMWindow::removeEventListenerMethodCustom(const v8::FunctionCallbackInfo <v8::Value>& args)
264 { 263 {
265 String eventType = toWebCoreString(args[0]); 264 String eventType = toWebCoreString(args[0]);
266 bool useCapture = args[2]->BooleanValue(); 265 bool useCapture = args[2]->BooleanValue();
267 266
268 DOMWindow* imp = V8Window::toNative(args.Holder()); 267 DOMWindow* imp = V8DOMWindow::toNative(args.Holder());
269 268
270 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame())) 269 if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame()))
271 return; 270 return;
272 271
273 Document* doc = imp->document(); 272 Document* doc = imp->document();
274 273
275 if (!doc) 274 if (!doc)
276 return; 275 return;
277 276
278 if (!imp->frame()) 277 if (!imp->frame())
279 return; 278 return;
280 279
281 RefPtr<EventListener> listener = V8EventListenerList::getEventListener(args[ 1], false, ListenerFindOnly); 280 RefPtr<EventListener> listener = V8EventListenerList::getEventListener(args[ 1], false, ListenerFindOnly);
282 281
283 if (listener) { 282 if (listener) {
284 imp->removeEventListener(eventType, listener.get(), useCapture); 283 imp->removeEventListener(eventType, listener.get(), useCapture);
285 removeHiddenDependency(args.Holder(), args[1], eventListenerCacheIndex, args.GetIsolate()); 284 removeHiddenDependency(args.Holder(), args[1], eventListenerCacheIndex, args.GetIsolate());
286 } 285 }
287 } 286 }
288 287
289 static bool isLegacyTargetOriginDesignation(v8::Handle<v8::Value> value) 288 static bool isLegacyTargetOriginDesignation(v8::Handle<v8::Value> value)
290 { 289 {
291 if (value->IsString() || value->IsStringObject()) 290 if (value->IsString() || value->IsStringObject())
292 return true; 291 return true;
293 return false; 292 return false;
294 } 293 }
295 294
296 295
297 void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value> & args) 296 void V8DOMWindow::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Val ue>& args)
298 { 297 {
299 // None of these need to be RefPtr because args and context are guaranteed 298 // None of these need to be RefPtr because args and context are guaranteed
300 // to hold on to them. 299 // to hold on to them.
301 DOMWindow* window = V8Window::toNative(args.Holder()); 300 DOMWindow* window = V8DOMWindow::toNative(args.Holder());
302 DOMWindow* source = activeDOMWindow(); 301 DOMWindow* source = activeDOMWindow();
303 302
304 // If called directly by WebCore we don't have a calling context. 303 // If called directly by WebCore we don't have a calling context.
305 if (!source) { 304 if (!source) {
306 throwTypeError(0, args.GetIsolate()); 305 throwTypeError(0, args.GetIsolate());
307 return; 306 return;
308 } 307 }
309 308
310 // This function has variable arguments and can be: 309 // This function has variable arguments and can be:
311 // Per current spec: 310 // Per current spec:
(...skipping 10 matching lines...) Expand all
322 targetOriginArgIndex = 2; 321 targetOriginArgIndex = 2;
323 transferablesArgIndex = 1; 322 transferablesArgIndex = 1;
324 } 323 }
325 if (!extractTransferables(args[transferablesArgIndex], portArray, arrayB ufferArray, args.GetIsolate())) 324 if (!extractTransferables(args[transferablesArgIndex], portArray, arrayB ufferArray, args.GetIsolate()))
326 return; 325 return;
327 } 326 }
328 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithUndefinedOrNullChe ck>, targetOrigin, args[targetOriginArgIndex]); 327 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithUndefinedOrNullChe ck>, targetOrigin, args[targetOriginArgIndex]);
329 328
330 bool didThrow = false; 329 bool didThrow = false;
331 RefPtr<SerializedScriptValue> message = 330 RefPtr<SerializedScriptValue> message =
332 SerializedScriptValue::create(args[0], &portArray, &arrayBufferArray, di dThrow, args.GetIsolate()); 331 SerializedScriptValue::create(args[0],
332 &portArray,
333 &arrayBufferArray,
334 didThrow,
335 args.GetIsolate());
333 if (didThrow) 336 if (didThrow)
334 return; 337 return;
335 338
336 ExceptionCode ec = 0; 339 ExceptionCode ec = 0;
337 window->postMessage(message.release(), &portArray, targetOrigin, source, ec) ; 340 window->postMessage(message.release(), &portArray, targetOrigin, source, ec) ;
338 setDOMException(ec, args.GetIsolate()); 341 setDOMException(ec, args.GetIsolate());
339 } 342 }
340 343
341 // FIXME(fqian): returning string is cheating, and we should 344 // FIXME(fqian): returning string is cheating, and we should
342 // fix this by calling toString function on the receiver. 345 // fix this by calling toString function on the receiver.
343 // However, V8 implements toString in JavaScript, which requires 346 // However, V8 implements toString in JavaScript, which requires
344 // switching context of receiver. I consider it is dangerous. 347 // switching context of receiver. I consider it is dangerous.
345 void V8Window::toStringMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& a rgs) 348 void V8DOMWindow::toStringMethodCustom(const v8::FunctionCallbackInfo<v8::Value> & args)
346 { 349 {
347 v8::Handle<v8::Object> domWrapper = args.This()->FindInstanceInPrototypeChai n(V8Window::GetTemplate(args.GetIsolate(), worldTypeInMainThread(args.GetIsolate ()))); 350 v8::Handle<v8::Object> domWrapper = args.This()->FindInstanceInPrototypeChai n(V8DOMWindow::GetTemplate(args.GetIsolate(), worldTypeInMainThread(args.GetIsol ate())));
348 if (domWrapper.IsEmpty()) { 351 if (domWrapper.IsEmpty()) {
349 v8SetReturnValue(args, args.This()->ObjectProtoToString()); 352 v8SetReturnValue(args, args.This()->ObjectProtoToString());
350 return; 353 return;
351 } 354 }
352 v8SetReturnValue(args, domWrapper->ObjectProtoToString()); 355 v8SetReturnValue(args, domWrapper->ObjectProtoToString());
353 } 356 }
354 357
355 class DialogHandler { 358 class DialogHandler {
356 public: 359 public:
357 explicit DialogHandler(v8::Handle<v8::Value> dialogArguments) 360 explicit DialogHandler(v8::Handle<v8::Value> dialogArguments)
(...skipping 29 matching lines...) Expand all
387 if (returnValue.IsEmpty()) 390 if (returnValue.IsEmpty())
388 return v8::Undefined(); 391 return v8::Undefined();
389 return returnValue; 392 return returnValue;
390 } 393 }
391 394
392 static void setUpDialog(DOMWindow* dialog, void* handler) 395 static void setUpDialog(DOMWindow* dialog, void* handler)
393 { 396 {
394 static_cast<DialogHandler*>(handler)->dialogCreated(dialog); 397 static_cast<DialogHandler*>(handler)->dialogCreated(dialog);
395 } 398 }
396 399
397 void V8Window::showModalDialogMethodCustom(const v8::FunctionCallbackInfo<v8::Va lue>& args) 400 void V8DOMWindow::showModalDialogMethodCustom(const v8::FunctionCallbackInfo<v8: :Value>& args)
398 { 401 {
399 DOMWindow* impl = V8Window::toNative(args.Holder()); 402 DOMWindow* impl = V8DOMWindow::toNative(args.Holder());
400 if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame())) 403 if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame()))
401 return; 404 return;
402 405
403 // FIXME: Handle exceptions properly. 406 // FIXME: Handle exceptions properly.
404 String urlString = toWebCoreStringWithUndefinedOrNullCheck(args[0]); 407 String urlString = toWebCoreStringWithUndefinedOrNullCheck(args[0]);
405 DialogHandler handler(args[1]); 408 DialogHandler handler(args[1]);
406 String dialogFeaturesString = toWebCoreStringWithUndefinedOrNullCheck(args[2 ]); 409 String dialogFeaturesString = toWebCoreStringWithUndefinedOrNullCheck(args[2 ]);
407 410
408 impl->showModalDialog(urlString, dialogFeaturesString, activeDOMWindow(), fi rstDOMWindow(), setUpDialog, &handler); 411 impl->showModalDialog(urlString, dialogFeaturesString, activeDOMWindow(), fi rstDOMWindow(), setUpDialog, &handler);
409 412
410 v8SetReturnValue(args, handler.returnValue()); 413 v8SetReturnValue(args, handler.returnValue());
411 } 414 }
412 415
413 void V8Window::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args) 416 void V8DOMWindow::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& ar gs)
414 { 417 {
415 DOMWindow* impl = V8Window::toNative(args.Holder()); 418 DOMWindow* impl = V8DOMWindow::toNative(args.Holder());
416 if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame())) 419 if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame()))
417 return; 420 return;
418 421
419 // FIXME: Handle exceptions properly. 422 // FIXME: Handle exceptions properly.
420 String urlString = toWebCoreStringWithUndefinedOrNullCheck(args[0]); 423 String urlString = toWebCoreStringWithUndefinedOrNullCheck(args[0]);
421 AtomicString frameName = (args[1]->IsUndefined() || args[1]->IsNull()) ? "_b lank" : AtomicString(toWebCoreString(args[1])); 424 AtomicString frameName = (args[1]->IsUndefined() || args[1]->IsNull()) ? "_b lank" : AtomicString(toWebCoreString(args[1]));
422 String windowFeaturesString = toWebCoreStringWithUndefinedOrNullCheck(args[2 ]); 425 String windowFeaturesString = toWebCoreStringWithUndefinedOrNullCheck(args[2 ]);
423 426
424 RefPtr<DOMWindow> openedWindow = impl->open(urlString, frameName, windowFeat uresString, activeDOMWindow(), firstDOMWindow()); 427 RefPtr<DOMWindow> openedWindow = impl->open(urlString, frameName, windowFeat uresString, activeDOMWindow(), firstDOMWindow());
425 if (!openedWindow) 428 if (!openedWindow)
426 return; 429 return;
427 430
428 v8SetReturnValue(args, toV8Fast(openedWindow.release(), args, impl)); 431 v8SetReturnValue(args, toV8Fast(openedWindow.release(), args, impl));
429 } 432 }
430 433
431 void V8Window::namedPropertyGetter(v8::Local<v8::String> name, const v8::Propert yCallbackInfo<v8::Value>& info) 434 void V8DOMWindow::namedPropertyGetter(v8::Local<v8::String> name, const v8::Prop ertyCallbackInfo<v8::Value>& info)
432 { 435 {
433 436
434 DOMWindow* window = V8Window::toNative(info.Holder()); 437 DOMWindow* window = V8DOMWindow::toNative(info.Holder());
435 if (!window) 438 if (!window)
436 return; 439 return;
437 440
438 Frame* frame = window->frame(); 441 Frame* frame = window->frame();
439 // window is detached from a frame. 442 // window is detached from a frame.
440 if (!frame) 443 if (!frame)
441 return; 444 return;
442 445
443 // Search sub-frames. 446 // Search sub-frames.
444 AtomicString propName = toWebCoreAtomicString(name); 447 AtomicString propName = toWebCoreAtomicString(name);
(...skipping 19 matching lines...) Expand all
464 return; 467 return;
465 } 468 }
466 v8SetReturnValue(info, toV8Fast(items.release(), info, window)); 469 v8SetReturnValue(info, toV8Fast(items.release(), info, window));
467 return; 470 return;
468 } 471 }
469 } 472 }
470 } 473 }
471 } 474 }
472 475
473 476
474 void V8Window::setTimeoutMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args) 477 void V8DOMWindow::setTimeoutMethodCustom(const v8::FunctionCallbackInfo<v8::Valu e>& args)
475 { 478 {
476 WindowSetTimeoutImpl(args, true); 479 WindowSetTimeoutImpl(args, true);
477 } 480 }
478 481
479 482
480 void V8Window::setIntervalMethodCustom(const v8::FunctionCallbackInfo<v8::Value> & args) 483 void V8DOMWindow::setIntervalMethodCustom(const v8::FunctionCallbackInfo<v8::Val ue>& args)
481 { 484 {
482 WindowSetTimeoutImpl(args, false); 485 WindowSetTimeoutImpl(args, false);
483 } 486 }
484 487
485 bool V8Window::namedSecurityCheckCustom(v8::Local<v8::Object> host, v8::Local<v8 ::Value> key, v8::AccessType type, v8::Local<v8::Value>) 488 bool V8DOMWindow::namedSecurityCheckCustom(v8::Local<v8::Object> host, v8::Local <v8::Value> key, v8::AccessType type, v8::Local<v8::Value>)
486 { 489 {
487 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 490 v8::Isolate* isolate = v8::Isolate::GetCurrent();
488 v8::Handle<v8::Object> window = host->FindInstanceInPrototypeChain(V8Window: :GetTemplate(isolate, worldTypeInMainThread(isolate))); 491 v8::Handle<v8::Object> window = host->FindInstanceInPrototypeChain(V8DOMWind ow::GetTemplate(isolate, worldTypeInMainThread(isolate)));
489 if (window.IsEmpty()) 492 if (window.IsEmpty())
490 return false; // the frame is gone. 493 return false; // the frame is gone.
491 494
492 DOMWindow* targetWindow = V8Window::toNative(window); 495 DOMWindow* targetWindow = V8DOMWindow::toNative(window);
493 496
494 ASSERT(targetWindow); 497 ASSERT(targetWindow);
495 498
496 Frame* target = targetWindow->frame(); 499 Frame* target = targetWindow->frame();
497 if (!target) 500 if (!target)
498 return false; 501 return false;
499 502
500 // Notify the loader's client if the initial document has been accessed. 503 // Notify the loader's client if the initial document has been accessed.
501 if (target->loader()->stateMachine()->isDisplayingInitialEmptyDocument()) 504 if (target->loader()->stateMachine()->isDisplayingInitialEmptyDocument())
502 target->loader()->didAccessInitialDocument(); 505 target->loader()->didAccessInitialDocument();
(...skipping 15 matching lines...) Expand all
518 && childFrame 521 && childFrame
519 && !host->HasRealNamedProperty(keyString) 522 && !host->HasRealNamedProperty(keyString)
520 && !window->HasRealNamedProperty(keyString) 523 && !window->HasRealNamedProperty(keyString)
521 && name != nameOfProtoProperty) 524 && name != nameOfProtoProperty)
522 return true; 525 return true;
523 } 526 }
524 527
525 return BindingSecurity::shouldAllowAccessToFrame(target, DoNotReportSecurity Error); 528 return BindingSecurity::shouldAllowAccessToFrame(target, DoNotReportSecurity Error);
526 } 529 }
527 530
528 bool V8Window::indexedSecurityCheckCustom(v8::Local<v8::Object> host, uint32_t i ndex, v8::AccessType type, v8::Local<v8::Value>) 531 bool V8DOMWindow::indexedSecurityCheckCustom(v8::Local<v8::Object> host, uint32_ t index, v8::AccessType type, v8::Local<v8::Value>)
529 { 532 {
530 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 533 v8::Isolate* isolate = v8::Isolate::GetCurrent();
531 v8::Handle<v8::Object> window = host->FindInstanceInPrototypeChain(V8Window: :GetTemplate(isolate, worldTypeInMainThread(isolate))); 534 v8::Handle<v8::Object> window = host->FindInstanceInPrototypeChain(V8DOMWind ow::GetTemplate(isolate, worldTypeInMainThread(isolate)));
532 if (window.IsEmpty()) 535 if (window.IsEmpty())
533 return false; 536 return false;
534 537
535 DOMWindow* targetWindow = V8Window::toNative(window); 538 DOMWindow* targetWindow = V8DOMWindow::toNative(window);
536 539
537 ASSERT(targetWindow); 540 ASSERT(targetWindow);
538 541
539 Frame* target = targetWindow->frame(); 542 Frame* target = targetWindow->frame();
540 if (!target) 543 if (!target)
541 return false; 544 return false;
542 Frame* childFrame = target->tree()->scopedChild(index); 545 Frame* childFrame = target->tree()->scopedChild(index);
543 546
544 // Notify the loader's client if the initial document has been accessed. 547 // Notify the loader's client if the initial document has been accessed.
545 if (target->loader()->stateMachine()->isDisplayingInitialEmptyDocument()) 548 if (target->loader()->stateMachine()->isDisplayingInitialEmptyDocument())
(...skipping 21 matching lines...) Expand all
567 if (!frame) 570 if (!frame)
568 return v8Undefined(); 571 return v8Undefined();
569 572
570 // Special case: Because of executeScriptInIsolatedWorld() one DOMWindow can have 573 // Special case: Because of executeScriptInIsolatedWorld() one DOMWindow can have
571 // multiple contexts and multiple global objects associated with it. When 574 // multiple contexts and multiple global objects associated with it. When
572 // code running in one of those contexts accesses the window object, we 575 // code running in one of those contexts accesses the window object, we
573 // want to return the global object associated with that context, not 576 // want to return the global object associated with that context, not
574 // necessarily the first global object associated with that DOMWindow. 577 // necessarily the first global object associated with that DOMWindow.
575 v8::Handle<v8::Context> currentContext = v8::Context::GetCurrent(); 578 v8::Handle<v8::Context> currentContext = v8::Context::GetCurrent();
576 v8::Handle<v8::Object> currentGlobal = currentContext->Global(); 579 v8::Handle<v8::Object> currentGlobal = currentContext->Global();
577 v8::Handle<v8::Object> windowWrapper = currentGlobal->FindInstanceInPrototyp eChain(V8Window::GetTemplate(isolate, worldTypeInMainThread(isolate))); 580 v8::Handle<v8::Object> windowWrapper = currentGlobal->FindInstanceInPrototyp eChain(V8DOMWindow::GetTemplate(isolate, worldTypeInMainThread(isolate)));
578 if (!windowWrapper.IsEmpty()) { 581 if (!windowWrapper.IsEmpty()) {
579 if (V8Window::toNative(windowWrapper) == window) 582 if (V8DOMWindow::toNative(windowWrapper) == window)
580 return currentGlobal; 583 return currentGlobal;
581 } 584 }
582 585
583 // Otherwise, return the global object associated with this frame. 586 // Otherwise, return the global object associated with this frame.
584 v8::Handle<v8::Context> context = frame->script()->currentWorldContext(); 587 v8::Handle<v8::Context> context = frame->script()->currentWorldContext();
585 if (context.IsEmpty()) 588 if (context.IsEmpty())
586 return v8Undefined(); 589 return v8Undefined();
587 590
588 v8::Handle<v8::Object> global = context->Global(); 591 v8::Handle<v8::Object> global = context->Global();
589 ASSERT(!global.IsEmpty()); 592 ASSERT(!global.IsEmpty());
590 return global; 593 return global;
591 } 594 }
592 595
593 v8::Handle<v8::Value> toV8ForMainWorld(DOMWindow* window, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 596 v8::Handle<v8::Value> toV8ForMainWorld(DOMWindow* window, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
594 { 597 {
595 return toV8(window, creationContext, isolate); 598 return toV8(window, creationContext, isolate);
596 } 599 }
597 600
598 } // namespace WebCore 601 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/V8WindowShell.cpp ('k') | Source/bindings/v8/custom/V8DocumentCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698