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

Side by Side Diff: third_party/WebKit/Source/core/frame/DOMWindowTimers.cpp

Issue 2702213004: Add security checks to scheduled actions (Closed)
Patch Set: updates Created 3 years, 10 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
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 int timeout, 78 int timeout,
79 const Vector<ScriptValue>& arguments) { 79 const Vector<ScriptValue>& arguments) {
80 ExecutionContext* executionContext = eventTarget.getExecutionContext(); 80 ExecutionContext* executionContext = eventTarget.getExecutionContext();
81 if (!isAllowed(scriptState, executionContext, false)) 81 if (!isAllowed(scriptState, executionContext, false))
82 return 0; 82 return 0;
83 if (timeout >= 0 && executionContext->isDocument()) { 83 if (timeout >= 0 && executionContext->isDocument()) {
84 // FIXME: Crude hack that attempts to pass idle time to V8. This should 84 // FIXME: Crude hack that attempts to pass idle time to V8. This should
85 // be done using the scheduler instead. 85 // be done using the scheduler instead.
86 V8GCForContextDispose::instance().notifyIdle(); 86 V8GCForContextDispose::instance().notifyIdle();
87 } 87 }
88 ScheduledAction* action = 88 ScheduledAction* action = ScheduledAction::create(
89 ScheduledAction::create(scriptState, handler, arguments); 89 scriptState, executionContext, handler, arguments);
90 return DOMTimer::install(executionContext, action, timeout, true); 90 return DOMTimer::install(executionContext, action, timeout, true);
91 } 91 }
92 92
93 int setTimeout(ScriptState* scriptState, 93 int setTimeout(ScriptState* scriptState,
94 EventTarget& eventTarget, 94 EventTarget& eventTarget,
95 const String& handler, 95 const String& handler,
96 int timeout, 96 int timeout,
97 const Vector<ScriptValue>&) { 97 const Vector<ScriptValue>&) {
98 ExecutionContext* executionContext = eventTarget.getExecutionContext(); 98 ExecutionContext* executionContext = eventTarget.getExecutionContext();
99 if (!isAllowed(scriptState, executionContext, true)) 99 if (!isAllowed(scriptState, executionContext, true))
100 return 0; 100 return 0;
101 // Don't allow setting timeouts to run empty functions. Was historically a 101 // Don't allow setting timeouts to run empty functions. Was historically a
102 // perfomance issue. 102 // perfomance issue.
103 if (handler.isEmpty()) 103 if (handler.isEmpty())
104 return 0; 104 return 0;
105 if (timeout >= 0 && executionContext->isDocument()) { 105 if (timeout >= 0 && executionContext->isDocument()) {
106 // FIXME: Crude hack that attempts to pass idle time to V8. This should 106 // FIXME: Crude hack that attempts to pass idle time to V8. This should
107 // be done using the scheduler instead. 107 // be done using the scheduler instead.
108 V8GCForContextDispose::instance().notifyIdle(); 108 V8GCForContextDispose::instance().notifyIdle();
109 } 109 }
110 ScheduledAction* action = ScheduledAction::create(scriptState, handler); 110 ScheduledAction* action =
111 ScheduledAction::create(scriptState, executionContext, handler);
111 return DOMTimer::install(executionContext, action, timeout, true); 112 return DOMTimer::install(executionContext, action, timeout, true);
112 } 113 }
113 114
114 int setInterval(ScriptState* scriptState, 115 int setInterval(ScriptState* scriptState,
115 EventTarget& eventTarget, 116 EventTarget& eventTarget,
116 const ScriptValue& handler, 117 const ScriptValue& handler,
117 int timeout, 118 int timeout,
118 const Vector<ScriptValue>& arguments) { 119 const Vector<ScriptValue>& arguments) {
119 ExecutionContext* executionContext = eventTarget.getExecutionContext(); 120 ExecutionContext* executionContext = eventTarget.getExecutionContext();
120 if (!isAllowed(scriptState, executionContext, false)) 121 if (!isAllowed(scriptState, executionContext, false))
121 return 0; 122 return 0;
122 ScheduledAction* action = 123 ScheduledAction* action = ScheduledAction::create(
123 ScheduledAction::create(scriptState, handler, arguments); 124 scriptState, executionContext, handler, arguments);
124 return DOMTimer::install(executionContext, action, timeout, false); 125 return DOMTimer::install(executionContext, action, timeout, false);
125 } 126 }
126 127
127 int setInterval(ScriptState* scriptState, 128 int setInterval(ScriptState* scriptState,
128 EventTarget& eventTarget, 129 EventTarget& eventTarget,
129 const String& handler, 130 const String& handler,
130 int timeout, 131 int timeout,
131 const Vector<ScriptValue>&) { 132 const Vector<ScriptValue>&) {
132 ExecutionContext* executionContext = eventTarget.getExecutionContext(); 133 ExecutionContext* executionContext = eventTarget.getExecutionContext();
133 if (!isAllowed(scriptState, executionContext, true)) 134 if (!isAllowed(scriptState, executionContext, true))
134 return 0; 135 return 0;
135 // Don't allow setting timeouts to run empty functions. Was historically a 136 // Don't allow setting timeouts to run empty functions. Was historically a
136 // perfomance issue. 137 // perfomance issue.
137 if (handler.isEmpty()) 138 if (handler.isEmpty())
138 return 0; 139 return 0;
139 ScheduledAction* action = ScheduledAction::create(scriptState, handler); 140 ScheduledAction* action =
141 ScheduledAction::create(scriptState, executionContext, handler);
140 return DOMTimer::install(executionContext, action, timeout, false); 142 return DOMTimer::install(executionContext, action, timeout, false);
141 } 143 }
142 144
143 void clearTimeout(EventTarget& eventTarget, int timeoutID) { 145 void clearTimeout(EventTarget& eventTarget, int timeoutID) {
144 if (ExecutionContext* context = eventTarget.getExecutionContext()) 146 if (ExecutionContext* context = eventTarget.getExecutionContext())
145 DOMTimer::removeByID(context, timeoutID); 147 DOMTimer::removeByID(context, timeoutID);
146 } 148 }
147 149
148 void clearInterval(EventTarget& eventTarget, int timeoutID) { 150 void clearInterval(EventTarget& eventTarget, int timeoutID) {
149 if (ExecutionContext* context = eventTarget.getExecutionContext()) 151 if (ExecutionContext* context = eventTarget.getExecutionContext())
150 DOMTimer::removeByID(context, timeoutID); 152 DOMTimer::removeByID(context, timeoutID);
151 } 153 }
152 154
153 } // namespace DOMWindowTimers 155 } // namespace DOMWindowTimers
154 156
155 } // namespace blink 157 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/ScheduledAction.cpp ('k') | third_party/WebKit/Source/core/testing/Internals.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698