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

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: rebased 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;
53 return true;
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;
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 int setTimeout(ScriptState* scriptState, EventTarget& eventTarget, const ScriptV alue& handler, int timeout, const Vector<ScriptValue>& arguments)
49 { 69 {
50 return DOMTimer::install(eventTarget.executionContext(), action, timeout, fa lse); 70 ExecutionContext* executionContext = eventTarget.executionContext();
71 if (!isAllowed(executionContext, false))
72 return 0;
73 OwnPtr<ScheduledAction> action = ScheduledAction::create(scriptState, handle r, arguments);
74 return DOMTimer::install(executionContext, action.release(), timeout, true);
75 }
76
77 int setTimeout(ScriptState* scriptState, EventTarget& eventTarget, String handle r, int timeout, const Vector<ScriptValue>&)
78 {
79 ExecutionContext* executionContext = eventTarget.executionContext();
80 if (!isAllowed(executionContext, true))
81 return 0;
82 // Don't allow setting timeouts to run empty functions!
83 // (Bug 1009597)
Yuta Kitamura 2014/11/14 08:24:06 I know that's not something you wrote, but I had i
Jens Widell 2014/11/14 10:19:27 Thanks for the information! I did wonder what kind
84 if (handler.isEmpty())
85 return 0;
86 OwnPtr<ScheduledAction> action = ScheduledAction::create(scriptState, handle r);
87 return DOMTimer::install(executionContext, action.release(), timeout, true);
88 }
89
90 int setInterval(ScriptState* scriptState, EventTarget& eventTarget, const Script Value& handler, int timeout, const Vector<ScriptValue>& arguments)
91 {
92 ExecutionContext* executionContext = eventTarget.executionContext();
93 if (!isAllowed(executionContext, false))
94 return 0;
95 OwnPtr<ScheduledAction> action = ScheduledAction::create(scriptState, handle r, arguments);
96 return DOMTimer::install(executionContext, action.release(), timeout, false) ;
97 }
98
99 int setInterval(ScriptState* scriptState, EventTarget& eventTarget, String handl er, int timeout, const Vector<ScriptValue>&)
100 {
101 ExecutionContext* executionContext = eventTarget.executionContext();
102 if (!isAllowed(executionContext, true))
103 return 0;
104 // Don't allow setting timeouts to run empty functions!
105 // (Bug 1009597)
Yuta Kitamura 2014/11/14 08:24:06 Ditto.
106 if (handler.isEmpty())
107 return 0;
108 OwnPtr<ScheduledAction> action = ScheduledAction::create(scriptState, handle r);
109 return DOMTimer::install(executionContext, action.release(), timeout, false) ;
51 } 110 }
52 111
53 void clearTimeout(EventTarget& eventTarget, int timeoutID) 112 void clearTimeout(EventTarget& eventTarget, int timeoutID)
54 { 113 {
55 if (ExecutionContext* context = eventTarget.executionContext()) 114 if (ExecutionContext* context = eventTarget.executionContext())
56 DOMTimer::removeByID(context, timeoutID); 115 DOMTimer::removeByID(context, timeoutID);
57 } 116 }
58 117
59 void clearInterval(EventTarget& eventTarget, int timeoutID) 118 void clearInterval(EventTarget& eventTarget, int timeoutID)
60 { 119 {
61 if (ExecutionContext* context = eventTarget.executionContext()) 120 if (ExecutionContext* context = eventTarget.executionContext())
62 DOMTimer::removeByID(context, timeoutID); 121 DOMTimer::removeByID(context, timeoutID);
63 } 122 }
64 123
65 } // namespace DOMWindowTimers 124 } // namespace DOMWindowTimers
66 125
67 } // namespace blink 126 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698