OLD | NEW |
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 Loading... |
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 "bindings/core/v8/V8GCForContextDispose.h" |
| 37 #include "core/dom/Document.h" |
| 38 #include "core/dom/ExecutionContext.h" |
36 #include "core/events/EventTarget.h" | 39 #include "core/events/EventTarget.h" |
37 #include "core/frame/DOMTimer.h" | 40 #include "core/frame/DOMTimer.h" |
| 41 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 42 #include "core/workers/WorkerGlobalScope.h" |
38 | 43 |
39 namespace blink { | 44 namespace blink { |
40 | 45 |
41 namespace DOMWindowTimers { | 46 namespace DOMWindowTimers { |
42 | 47 |
43 int setTimeout(EventTarget& eventTarget, PassOwnPtr<ScheduledAction> action, int
timeout) | 48 static bool isAllowed(ExecutionContext* executionContext, bool isEval) |
44 { | 49 { |
45 return DOMTimer::install(eventTarget.executionContext(), action, timeout, tr
ue); | 50 if (executionContext->isDocument()) { |
| 51 Document* document = static_cast<Document*>(executionContext); |
| 52 if (isEval && !document->contentSecurityPolicy()->allowEval()) |
| 53 return false; |
| 54 return true; |
| 55 } |
| 56 if (executionContext->isWorkerGlobalScope()) { |
| 57 WorkerGlobalScope* workerGlobalScope = static_cast<WorkerGlobalScope*>(e
xecutionContext); |
| 58 if (!workerGlobalScope->script()) |
| 59 return false; |
| 60 ContentSecurityPolicy* policy = workerGlobalScope->contentSecurityPolicy
(); |
| 61 if (isEval && policy && !policy->allowEval()) |
| 62 return false; |
| 63 return true; |
| 64 } |
| 65 ASSERT_NOT_REACHED(); |
| 66 return false; |
46 } | 67 } |
47 | 68 |
48 int setInterval(EventTarget& eventTarget, PassOwnPtr<ScheduledAction> action, in
t timeout) | 69 int setTimeout(ScriptState* scriptState, EventTarget& eventTarget, const ScriptV
alue& handler, int timeout, const Vector<ScriptValue>& arguments) |
49 { | 70 { |
50 return DOMTimer::install(eventTarget.executionContext(), action, timeout, fa
lse); | 71 ExecutionContext* executionContext = eventTarget.executionContext(); |
| 72 if (!isAllowed(executionContext, false)) |
| 73 return 0; |
| 74 if (timeout >= 0 && executionContext->isDocument()) { |
| 75 // FIXME: Crude hack that attempts to pass idle time to V8. This should |
| 76 // be done using the scheduler instead. |
| 77 V8GCForContextDispose::instance().notifyIdle(); |
| 78 } |
| 79 OwnPtr<ScheduledAction> action = ScheduledAction::create(scriptState, handle
r, arguments); |
| 80 return DOMTimer::install(executionContext, action.release(), timeout, true); |
| 81 } |
| 82 |
| 83 int setTimeout(ScriptState* scriptState, EventTarget& eventTarget, const String&
handler, int timeout, const Vector<ScriptValue>&) |
| 84 { |
| 85 ExecutionContext* executionContext = eventTarget.executionContext(); |
| 86 if (!isAllowed(executionContext, true)) |
| 87 return 0; |
| 88 // Don't allow setting timeouts to run empty functions. Was historically a |
| 89 // perfomance issue. |
| 90 if (handler.isEmpty()) |
| 91 return 0; |
| 92 if (timeout >= 0 && executionContext->isDocument()) { |
| 93 // FIXME: Crude hack that attempts to pass idle time to V8. This should |
| 94 // be done using the scheduler instead. |
| 95 V8GCForContextDispose::instance().notifyIdle(); |
| 96 } |
| 97 OwnPtr<ScheduledAction> action = ScheduledAction::create(scriptState, handle
r); |
| 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 = ScheduledAction::create(scriptState, handle
r, arguments); |
| 107 return DOMTimer::install(executionContext, action.release(), timeout, false)
; |
| 108 } |
| 109 |
| 110 int setInterval(ScriptState* scriptState, EventTarget& eventTarget, const String
& handler, 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. Was historically a |
| 116 // perfomance issue. |
| 117 if (handler.isEmpty()) |
| 118 return 0; |
| 119 OwnPtr<ScheduledAction> action = ScheduledAction::create(scriptState, handle
r); |
| 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 |
OLD | NEW |