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/core/frame/DOMWindowTimers.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) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
4 * Copyright (C) 2013 Samsung Electronics. All rights reserved. 4 * Copyright (C) 2013 Samsung Electronics. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are 7 * modification, are permitted provided that the following conditions are
8 * met: 8 * met:
9 * 9 *
10 * * Redistributions of source code must retain the above copyright 10 * * Redistributions of source code must retain the above copyright
(...skipping 15 matching lines...) Expand all
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33 #include "config.h" 33 #include "config.h"
34 #include "core/frame/DOMWindowTimers.h" 34 #include "core/frame/DOMWindowTimers.h"
35 35
36 #include "core/dom/Document.h"
37 #include "core/dom/ExecutionContext.h"
36 #include "core/events/EventTarget.h" 38 #include "core/events/EventTarget.h"
37 #include "core/frame/DOMTimer.h" 39 #include "core/frame/DOMTimer.h"
40 #include "core/frame/csp/ContentSecurityPolicy.h"
41 #include "core/workers/WorkerGlobalScope.h"
38 42
39 namespace blink { 43 namespace blink {
40 44
41 namespace DOMWindowTimers { 45 namespace DOMWindowTimers {
42 46
43 int setTimeout(EventTarget& eventTarget, PassOwnPtr<ScheduledAction> action, int timeout) 47 static bool isAllowed(ExecutionContext* executionContext, bool isEval)
44 { 48 {
45 return DOMTimer::install(eventTarget.executionContext(), action, timeout, tr ue); 49 if (executionContext->isDocument()) {
50 Document* document = static_cast<Document*>(executionContext);
51 if (isEval && document->contentSecurityPolicy()->allowEval())
52 return false;
haraken 2014/11/13 12:59:31 Shouldn't this return true?
Jens Widell 2014/11/13 13:12:42 I was intending to have if (!allowEval()) r
Jens Widell 2014/11/13 13:26:48 I've fixed the logic here to be what I initially i
53 return true;
haraken 2014/11/13 12:59:32 return false?
54 }
55 if (executionContext->isWorkerGlobalScope()) {
56 WorkerGlobalScope* workerGlobalScope = static_cast<WorkerGlobalScope*>(e xecutionContext);
57 if (!workerGlobalScope->script())
58 return false;
59 ContentSecurityPolicy* policy = workerGlobalScope->contentSecurityPolicy ();
60 if (isEval && policy && !policy->allowEval())
61 return false;
haraken 2014/11/13 12:59:31 I guess this should be: if (isEval && policy && p
62 return true;
63 }
64 ASSERT_NOT_REACHED();
65 return false;
46 } 66 }
47 67
48 int setInterval(EventTarget& eventTarget, PassOwnPtr<ScheduledAction> action, in t timeout) 68 static PassOwnPtr<ScheduledAction> makeScheduledAction(ScriptState* scriptState, const ScriptValue& handler, const Vector<ScriptValue>& arguments)
49 { 69 {
50 return DOMTimer::install(eventTarget.executionContext(), action, timeout, fa lse); 70 ASSERT(handler.isFunction());
71 return adoptPtr(new ScheduledAction(scriptState, handler, arguments, scriptS tate->isolate()));
72 }
73
74 static PassOwnPtr<ScheduledAction> makeScheduledAction(ScriptState* scriptState, String handler)
haraken 2014/11/13 12:59:32 Instead of adding makeScheduledAction(), we should
Jens Widell 2014/11/13 13:26:48 Done.
75 {
76 return adoptPtr(new ScheduledAction(scriptState, handler, KURL(), scriptStat e->isolate()));
77 }
78
79 int setTimeout(ScriptState* scriptState, EventTarget& eventTarget, const ScriptV alue& handler, int timeout, const Vector<ScriptValue>& arguments)
80 {
81 ExecutionContext* executionContext = eventTarget.executionContext();
Jens Widell 2014/11/13 12:37:47 The old custom code in V8WindowCustom.cpp had an !
haraken 2014/11/13 12:59:31 I think we should check against scriptState->execu
Jens Widell 2014/11/13 13:12:42 But isn't scriptState the calling script, whereas
82 if (!isAllowed(executionContext, false))
haraken 2014/11/13 12:59:32 Do we need to call isAllowed() when isEval==false?
Jens Widell 2014/11/13 13:12:41 I might be badly named for what I intended it to b
83 return 0;
84 OwnPtr<ScheduledAction> action = makeScheduledAction(scriptState, handler, a rguments);
85 return DOMTimer::install(executionContext, action.release(), timeout, true);
86 }
87
88 int setTimeout(ScriptState* scriptState, EventTarget& eventTarget, String handle r, int timeout, const Vector<ScriptValue>&)
89 {
90 ExecutionContext* executionContext = eventTarget.executionContext();
91 if (!isAllowed(executionContext, true))
92 return 0;
93 // Don't allow setting timeouts to run empty functions!
94 // (Bug 1009597)
95 if (handler.isEmpty())
96 return 0;
97 OwnPtr<ScheduledAction> action = makeScheduledAction(scriptState, handler);
98 return DOMTimer::install(executionContext, action.release(), timeout, true);
99 }
100
101 int setInterval(ScriptState* scriptState, EventTarget& eventTarget, const Script Value& handler, int timeout, const Vector<ScriptValue>& arguments)
102 {
103 ExecutionContext* executionContext = eventTarget.executionContext();
104 if (!isAllowed(executionContext, false))
105 return 0;
106 OwnPtr<ScheduledAction> action = makeScheduledAction(scriptState, handler, a rguments);
107 return DOMTimer::install(executionContext, action.release(), timeout, false) ;
108 }
109
110 int setInterval(ScriptState* scriptState, EventTarget& eventTarget, String handl er, int timeout, const Vector<ScriptValue>&)
111 {
112 ExecutionContext* executionContext = eventTarget.executionContext();
113 if (!isAllowed(executionContext, true))
114 return 0;
115 // Don't allow setting timeouts to run empty functions!
116 // (Bug 1009597)
117 if (handler.isEmpty())
118 return 0;
119 OwnPtr<ScheduledAction> action = makeScheduledAction(scriptState, handler);
120 return DOMTimer::install(executionContext, action.release(), timeout, false) ;
51 } 121 }
52 122
53 void clearTimeout(EventTarget& eventTarget, int timeoutID) 123 void clearTimeout(EventTarget& eventTarget, int timeoutID)
54 { 124 {
55 if (ExecutionContext* context = eventTarget.executionContext()) 125 if (ExecutionContext* context = eventTarget.executionContext())
56 DOMTimer::removeByID(context, timeoutID); 126 DOMTimer::removeByID(context, timeoutID);
57 } 127 }
58 128
59 void clearInterval(EventTarget& eventTarget, int timeoutID) 129 void clearInterval(EventTarget& eventTarget, int timeoutID)
60 { 130 {
61 if (ExecutionContext* context = eventTarget.executionContext()) 131 if (ExecutionContext* context = eventTarget.executionContext())
62 DOMTimer::removeByID(context, timeoutID); 132 DOMTimer::removeByID(context, timeoutID);
63 } 133 }
64 134
65 } // namespace DOMWindowTimers 135 } // namespace DOMWindowTimers
66 136
67 } // namespace blink 137 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698