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

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

Issue 721033004: Implement WindowTimers.set{Timeout,Interval} without [Custom] (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@idl-overload-with-variadic
Patch Set: Created 6 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
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 #include "core/loader/FrameLoadRequest.h" 62 #include "core/loader/FrameLoadRequest.h"
63 #include "core/loader/FrameLoader.h" 63 #include "core/loader/FrameLoader.h"
64 #include "core/storage/Storage.h" 64 #include "core/storage/Storage.h"
65 #include "platform/PlatformScreen.h" 65 #include "platform/PlatformScreen.h"
66 #include "platform/graphics/media/MediaPlayer.h" 66 #include "platform/graphics/media/MediaPlayer.h"
67 #include "wtf/Assertions.h" 67 #include "wtf/Assertions.h"
68 #include "wtf/OwnPtr.h" 68 #include "wtf/OwnPtr.h"
69 69
70 namespace blink { 70 namespace blink {
71 71
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.");
Jens Widell 2014/11/13 12:37:47 This exception is no longer thrown. The new genera
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) 72 void V8Window::eventAttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Val ue>& info)
151 { 73 {
152 LocalFrame* frame = toLocalDOMWindow(V8Window::toImpl(info.Holder()))->frame (); 74 LocalFrame* frame = toLocalDOMWindow(V8Window::toImpl(info.Holder()))->frame ();
153 ExceptionState exceptionState(ExceptionState::GetterContext, "event", "Windo w", info.Holder(), info.GetIsolate()); 75 ExceptionState exceptionState(ExceptionState::GetterContext, "event", "Windo w", info.Holder(), info.GetIsolate());
154 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), frame, exc eptionState)) { 76 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), frame, exc eptionState)) {
155 exceptionState.throwIfNeeded(); 77 exceptionState.throwIfNeeded();
156 return; 78 return;
157 } 79 }
158 80
159 ASSERT(frame); 81 ASSERT(frame);
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 v8SetReturnValueFast(info, items->item(0), window); 353 v8SetReturnValueFast(info, items->item(0), window);
432 return; 354 return;
433 } 355 }
434 v8SetReturnValueFast(info, items.release(), window); 356 v8SetReturnValueFast(info, items.release(), window);
435 return; 357 return;
436 } 358 }
437 } 359 }
438 } 360 }
439 } 361 }
440 362
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>) 363 bool V8Window::namedSecurityCheckCustom(v8::Local<v8::Object> host, v8::Local<v8 ::Value> key, v8::AccessType type, v8::Local<v8::Value>)
458 { 364 {
459 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 365 v8::Isolate* isolate = v8::Isolate::GetCurrent();
460 v8::Handle<v8::Object> window = V8Window::findInstanceInPrototypeChain(host, isolate); 366 v8::Handle<v8::Object> window = V8Window::findInstanceInPrototypeChain(host, isolate);
461 if (window.IsEmpty()) 367 if (window.IsEmpty())
462 return false; // the frame is gone. 368 return false; // the frame is gone.
463 369
464 DOMWindow* targetWindow = V8Window::toImpl(window); 370 DOMWindow* targetWindow = V8Window::toImpl(window);
465 ASSERT(targetWindow); 371 ASSERT(targetWindow);
466 if (!targetWindow->isLocalDOMWindow()) 372 if (!targetWindow->isLocalDOMWindow())
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 v8::Handle<v8::Context> context = toV8Context(frame, DOMWrapperWorld::curren t(isolate)); 456 v8::Handle<v8::Context> context = toV8Context(frame, DOMWrapperWorld::curren t(isolate));
551 if (context.IsEmpty()) 457 if (context.IsEmpty())
552 return v8Undefined(); 458 return v8Undefined();
553 459
554 v8::Handle<v8::Object> global = context->Global(); 460 v8::Handle<v8::Object> global = context->Global();
555 ASSERT(!global.IsEmpty()); 461 ASSERT(!global.IsEmpty());
556 return global; 462 return global;
557 } 463 }
558 464
559 } // namespace blink 465 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698