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

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

Issue 54283002: Rename |args| to |info| in V8 bindings (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 1 month 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
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 #include "core/platform/graphics/MediaPlayer.h" 66 #include "core/platform/graphics/MediaPlayer.h"
67 #include "core/storage/Storage.h" 67 #include "core/storage/Storage.h"
68 #include "platform/PlatformScreen.h" 68 #include "platform/PlatformScreen.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>& args, bool singleShot, ExceptionState& es) 76 void WindowSetTimeoutImpl(const v8::FunctionCallbackInfo<v8::Value>& info, bool singleShot, ExceptionState& es)
77 { 77 {
78 int argumentCount = args.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(args.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 es.throwUninformativeAndGenericDOMException(InvalidAccessError);
88 return; 88 return;
89 } 89 }
90 90
91 v8::Handle<v8::Value> function = args[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;
(...skipping 11 matching lines...) Expand all
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
123 params[i] = args[i+2]; 123 params[i] = info[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 action = adoptPtr(new ScheduledAction(imp->frame()->script().currentWorl dContext(), v8::Handle<v8::Function>::Cast(function), paramCount, params.get(), args.GetIsolate())); 129 action = adoptPtr(new ScheduledAction(imp->frame()->script().currentWorl dContext(), v8::Handle<v8::Function>::Cast(function), paramCount, params.get(), info.GetIsolate()));
130 } else { 130 } else {
131 if (imp->document() && !imp->document()->contentSecurityPolicy()->allowE val()) { 131 if (imp->document() && !imp->document()->contentSecurityPolicy()->allowE val()) {
132 v8SetReturnValue(args, 0); 132 v8SetReturnValue(info, 0);
133 return; 133 return;
134 } 134 }
135 ASSERT(imp->frame()); 135 ASSERT(imp->frame());
136 action = adoptPtr(new ScheduledAction(imp->frame()->script().currentWorl dContext(), functionString, KURL(), args.GetIsolate())); 136 action = adoptPtr(new ScheduledAction(imp->frame()->script().currentWorl dContext(), functionString, KURL(), info.GetIsolate()));
137 } 137 }
138 138
139 int32_t timeout = argumentCount >= 2 ? args[1]->Int32Value() : 0; 139 int32_t timeout = argumentCount >= 2 ? info[1]->Int32Value() : 0;
140 int timerId; 140 int timerId;
141 if (singleShot) 141 if (singleShot)
142 timerId = DOMWindowTimers::setTimeout(imp, action.release(), timeout); 142 timerId = DOMWindowTimers::setTimeout(imp, action.release(), timeout);
143 else 143 else
144 timerId = DOMWindowTimers::setInterval(imp, action.release(), timeout); 144 timerId = DOMWindowTimers::setInterval(imp, action.release(), timeout);
145 145
146 // 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
147 // 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.
148 if (timeout >= 0) { 148 if (timeout >= 0) {
149 double maximumFireInterval = static_cast<double>(timeout) / 1000 / 2; 149 double maximumFireInterval = static_cast<double>(timeout) / 1000 / 2;
150 V8GCForContextDispose::instance().notifyIdleSooner(maximumFireInterval); 150 V8GCForContextDispose::instance().notifyIdleSooner(maximumFireInterval);
151 } 151 }
152 152
153 v8SetReturnValue(args, timerId); 153 v8SetReturnValue(info, timerId);
154 } 154 }
155 155
156 void V8Window::eventAttributeGetterCustom(v8::Local<v8::String> name, const v8:: PropertyCallbackInfo<v8::Value>& info) 156 void V8Window::eventAttributeGetterCustom(v8::Local<v8::String> name, const v8:: PropertyCallbackInfo<v8::Value>& 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 es(info.GetIsolate());
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 227 }
228 228
229 static bool isLegacyTargetOriginDesignation(v8::Handle<v8::Value> value) 229 static bool isLegacyTargetOriginDesignation(v8::Handle<v8::Value> value)
230 { 230 {
231 if (value->IsString() || value->IsStringObject()) 231 if (value->IsString() || value->IsStringObject())
232 return true; 232 return true;
233 return false; 233 return false;
234 } 234 }
235 235
236 236
237 void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value> & args) 237 void V8Window::postMessageMethodCustom(const v8::FunctionCallbackInfo<v8::Value> & info)
238 { 238 {
239 // None of these need to be RefPtr because args and context are guaranteed 239 // None of these need to be RefPtr because info and context are guaranteed
240 // to hold on to them. 240 // to hold on to them.
241 DOMWindow* window = V8Window::toNative(args.Holder()); 241 DOMWindow* window = V8Window::toNative(info.Holder());
242 DOMWindow* source = activeDOMWindow(); 242 DOMWindow* source = activeDOMWindow();
243 243
244 // If called directly by WebCore we don't have a calling context. 244 // If called directly by WebCore we don't have a calling context.
245 if (!source) { 245 if (!source) {
246 throwUninformativeAndGenericTypeError(args.GetIsolate()); 246 throwUninformativeAndGenericTypeError(info.GetIsolate());
247 return; 247 return;
248 } 248 }
249 249
250 // This function has variable arguments and can be: 250 // This function has variable arguments and can be:
251 // Per current spec: 251 // Per current spec:
252 // postMessage(message, targetOrigin) 252 // postMessage(message, targetOrigin)
253 // postMessage(message, targetOrigin, {sequence of transferrables}) 253 // postMessage(message, targetOrigin, {sequence of transferrables})
254 // Legacy non-standard implementations in webkit allowed: 254 // Legacy non-standard implementations in webkit allowed:
255 // postMessage(message, {sequence of transferrables}, targetOrigin); 255 // postMessage(message, {sequence of transferrables}, targetOrigin);
256 MessagePortArray portArray; 256 MessagePortArray portArray;
257 ArrayBufferArray arrayBufferArray; 257 ArrayBufferArray arrayBufferArray;
258 int targetOriginArgIndex = 1; 258 int targetOriginArgIndex = 1;
259 if (args.Length() > 2) { 259 if (info.Length() > 2) {
260 int transferablesArgIndex = 2; 260 int transferablesArgIndex = 2;
261 if (isLegacyTargetOriginDesignation(args[2])) { 261 if (isLegacyTargetOriginDesignation(info[2])) {
262 targetOriginArgIndex = 2; 262 targetOriginArgIndex = 2;
263 transferablesArgIndex = 1; 263 transferablesArgIndex = 1;
264 } 264 }
265 bool notASequence = false; 265 bool notASequence = false;
266 if (!extractTransferables(args[transferablesArgIndex], portArray, arrayB ufferArray, notASequence, args.GetIsolate())) { 266 if (!extractTransferables(info[transferablesArgIndex], portArray, arrayB ufferArray, notASequence, info.GetIsolate())) {
267 if (notASequence) 267 if (notASequence)
268 throwTypeError(ExceptionMessages::failedToExecute("postMessage", "Window", ExceptionMessages::notAnArrayTypeArgumentOrValue(transferablesArgInde x + 1)), args.GetIsolate()); 268 throwTypeError(ExceptionMessages::failedToExecute("postMessage", "Window", ExceptionMessages::notAnArrayTypeArgumentOrValue(transferablesArgInde x + 1)), info.GetIsolate());
269 return; 269 return;
270 } 270 }
271 } 271 }
272 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithUndefinedOrNullChe ck>, targetOrigin, args[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(args[0], &portArray, &arrayBufferArray, di dThrow, args.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(args.GetIsolate()); 280 ExceptionState es(info.GetIsolate());
281 window->postMessage(message.release(), &portArray, targetOrigin, source, es) ; 281 window->postMessage(message.release(), &portArray, targetOrigin, source, es) ;
282 es.throwIfNeeded(); 282 es.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>& a rgs) 289 void V8Window::toStringMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& i nfo)
290 { 290 {
291 v8::Handle<v8::Object> domWrapper = args.This()->FindInstanceInPrototypeChai n(V8Window::GetTemplate(args.GetIsolate(), worldTypeInMainThread(args.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()) {
293 v8SetReturnValue(args, args.This()->ObjectProtoToString()); 293 v8SetReturnValue(info, info.This()->ObjectProtoToString());
294 return; 294 return;
295 } 295 }
296 v8SetReturnValue(args, domWrapper->ObjectProtoToString()); 296 v8SetReturnValue(info, domWrapper->ObjectProtoToString());
297 } 297 }
298 298
299 class DialogHandler { 299 class DialogHandler {
300 public: 300 public:
301 explicit DialogHandler(v8::Handle<v8::Value> dialogArguments) 301 explicit DialogHandler(v8::Handle<v8::Value> dialogArguments)
302 : m_dialogArguments(dialogArguments) 302 : m_dialogArguments(dialogArguments)
303 { 303 {
304 } 304 }
305 305
306 void dialogCreated(DOMWindow*); 306 void dialogCreated(DOMWindow*);
(...skipping 24 matching lines...) Expand all
331 if (returnValue.IsEmpty()) 331 if (returnValue.IsEmpty())
332 return v8::Undefined(isolate); 332 return v8::Undefined(isolate);
333 return returnValue; 333 return returnValue;
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>& args) 341 void V8Window::showModalDialogMethodCustom(const v8::FunctionCallbackInfo<v8::Va lue>& info)
342 { 342 {
343 DOMWindow* impl = V8Window::toNative(args.Holder()); 343 DOMWindow* impl = V8Window::toNative(info.Holder());
344 ExceptionState es(args.GetIsolate()); 344 ExceptionState es(info.GetIsolate());
345 if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame(), es)) { 345 if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame(), es)) {
346 es.throwIfNeeded(); 346 es.throwIfNeeded();
347 return; 347 return;
348 } 348 }
349 349
350 // FIXME: Handle exceptions properly. 350 // FIXME: Handle exceptions properly.
351 String urlString = toWebCoreStringWithUndefinedOrNullCheck(args[0]); 351 String urlString = toWebCoreStringWithUndefinedOrNullCheck(info[0]);
352 DialogHandler handler(args[1]); 352 DialogHandler handler(info[1]);
353 String dialogFeaturesString = toWebCoreStringWithUndefinedOrNullCheck(args[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(args, handler.returnValue(args.GetIsolate())); 357 v8SetReturnValue(info, handler.returnValue(info.GetIsolate()));
358 } 358 }
359 359
360 void V8Window::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args) 360 void V8Window::openMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
361 { 361 {
362 DOMWindow* impl = V8Window::toNative(args.Holder()); 362 DOMWindow* impl = V8Window::toNative(info.Holder());
363 ExceptionState es(args.GetIsolate()); 363 ExceptionState es(info.GetIsolate());
364 if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame(), es)) { 364 if (!BindingSecurity::shouldAllowAccessToFrame(impl->frame(), es)) {
365 es.throwIfNeeded(); 365 es.throwIfNeeded();
366 return; 366 return;
367 } 367 }
368 368
369 // FIXME: Handle exceptions properly. 369 // FIXME: Handle exceptions properly.
370 String urlString = toWebCoreStringWithUndefinedOrNullCheck(args[0]); 370 String urlString = toWebCoreStringWithUndefinedOrNullCheck(info[0]);
371 AtomicString frameName = (args[1]->IsUndefined() || args[1]->IsNull()) ? "_b lank" : toWebCoreAtomicString(args[1]); 371 AtomicString frameName = (info[1]->IsUndefined() || info[1]->IsNull()) ? "_b lank" : toWebCoreAtomicString(info[1]);
372 String windowFeaturesString = toWebCoreStringWithUndefinedOrNullCheck(args[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)
376 return; 376 return;
377 377
378 v8SetReturnValueFast(args, openedWindow.release(), impl); 378 v8SetReturnValueFast(info, openedWindow.release(), impl);
379 } 379 }
380 380
381 void V8Window::namedPropertyGetterCustom(v8::Local<v8::String> name, const v8::P ropertyCallbackInfo<v8::Value>& info) 381 void V8Window::namedPropertyGetterCustom(v8::Local<v8::String> name, const v8::P ropertyCallbackInfo<v8::Value>& info)
382 { 382 {
383 383
384 DOMWindow* window = V8Window::toNative(info.Holder()); 384 DOMWindow* window = V8Window::toNative(info.Holder());
385 if (!window) 385 if (!window)
386 return; 386 return;
387 387
388 Frame* frame = window->frame(); 388 Frame* frame = window->frame();
(...skipping 25 matching lines...) Expand all
414 return; 414 return;
415 } 415 }
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>& args) 424 void V8Window::setTimeoutMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
425 { 425 {
426 ExceptionState es(args.GetIsolate()); 426 ExceptionState es(info.GetIsolate());
427 WindowSetTimeoutImpl(args, true, es); 427 WindowSetTimeoutImpl(info, true, es);
428 es.throwIfNeeded(); 428 es.throwIfNeeded();
429 } 429 }
430 430
431 431
432 void V8Window::setIntervalMethodCustom(const v8::FunctionCallbackInfo<v8::Value> & args) 432 void V8Window::setIntervalMethodCustom(const v8::FunctionCallbackInfo<v8::Value> & info)
433 { 433 {
434 ExceptionState es(args.GetIsolate()); 434 ExceptionState es(info.GetIsolate());
435 WindowSetTimeoutImpl(args, false, es); 435 WindowSetTimeoutImpl(info, false, es);
436 es.throwIfNeeded(); 436 es.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
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « Source/bindings/v8/custom/V8WebKitPointCustom.cpp ('k') | Source/bindings/v8/custom/V8WorkerCryptoCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698