Chromium Code Reviews| 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 static void notifyIdle() |
|
Jens Widell
2014/11/17 10:11:20
This is a helper function to avoid duplication, bu
| |
| 49 { | 70 { |
| 50 return DOMTimer::install(eventTarget.executionContext(), action, timeout, fa lse); | 71 // FIXME: Crude hack that attempts to pass idle time to V8. This should be |
| 72 // done using the scheduler instead. | |
| 73 V8GCForContextDispose::instance().notifyIdle(); | |
| 74 } | |
| 75 | |
| 76 int setTimeout(ScriptState* scriptState, EventTarget& eventTarget, const ScriptV alue& handler, int timeout, const Vector<ScriptValue>& arguments) | |
| 77 { | |
| 78 ExecutionContext* executionContext = eventTarget.executionContext(); | |
| 79 if (!isAllowed(executionContext, false)) | |
| 80 return 0; | |
| 81 if (timeout >= 0) | |
| 82 notifyIdle(); | |
| 83 OwnPtr<ScheduledAction> action = ScheduledAction::create(scriptState, handle r, arguments); | |
| 84 return DOMTimer::install(executionContext, action.release(), timeout, true); | |
| 85 } | |
| 86 | |
| 87 int setTimeout(ScriptState* scriptState, EventTarget& eventTarget, const String& handler, int timeout, const Vector<ScriptValue>&) | |
| 88 { | |
| 89 ExecutionContext* executionContext = eventTarget.executionContext(); | |
| 90 if (!isAllowed(executionContext, true)) | |
| 91 return 0; | |
| 92 // Don't allow setting timeouts to run empty functions. Was historically a | |
| 93 // perfomance issue. | |
| 94 if (handler.isEmpty()) | |
| 95 return 0; | |
| 96 if (timeout >= 0) | |
| 97 notifyIdle(); | |
| 98 OwnPtr<ScheduledAction> action = ScheduledAction::create(scriptState, handle r); | |
| 99 return DOMTimer::install(executionContext, action.release(), timeout, true); | |
| 100 } | |
| 101 | |
| 102 int setInterval(ScriptState* scriptState, EventTarget& eventTarget, const Script Value& handler, int timeout, const Vector<ScriptValue>& arguments) | |
| 103 { | |
| 104 ExecutionContext* executionContext = eventTarget.executionContext(); | |
| 105 if (!isAllowed(executionContext, false)) | |
| 106 return 0; | |
| 107 if (timeout >= 0) | |
| 108 notifyIdle(); | |
| 109 OwnPtr<ScheduledAction> action = ScheduledAction::create(scriptState, handle r, arguments); | |
| 110 return DOMTimer::install(executionContext, action.release(), timeout, false) ; | |
| 111 } | |
| 112 | |
| 113 int setInterval(ScriptState* scriptState, EventTarget& eventTarget, const String & handler, int timeout, const Vector<ScriptValue>&) | |
| 114 { | |
| 115 ExecutionContext* executionContext = eventTarget.executionContext(); | |
| 116 if (!isAllowed(executionContext, true)) | |
| 117 return 0; | |
| 118 // Don't allow setting timeouts to run empty functions. Was historically a | |
| 119 // perfomance issue. | |
| 120 if (handler.isEmpty()) | |
| 121 return 0; | |
| 122 if (timeout >= 0) | |
| 123 notifyIdle(); | |
| 124 OwnPtr<ScheduledAction> action = ScheduledAction::create(scriptState, handle r); | |
| 125 return DOMTimer::install(executionContext, action.release(), timeout, false) ; | |
| 51 } | 126 } |
| 52 | 127 |
| 53 void clearTimeout(EventTarget& eventTarget, int timeoutID) | 128 void clearTimeout(EventTarget& eventTarget, int timeoutID) |
| 54 { | 129 { |
| 55 if (ExecutionContext* context = eventTarget.executionContext()) | 130 if (ExecutionContext* context = eventTarget.executionContext()) |
| 56 DOMTimer::removeByID(context, timeoutID); | 131 DOMTimer::removeByID(context, timeoutID); |
| 57 } | 132 } |
| 58 | 133 |
| 59 void clearInterval(EventTarget& eventTarget, int timeoutID) | 134 void clearInterval(EventTarget& eventTarget, int timeoutID) |
| 60 { | 135 { |
| 61 if (ExecutionContext* context = eventTarget.executionContext()) | 136 if (ExecutionContext* context = eventTarget.executionContext()) |
| 62 DOMTimer::removeByID(context, timeoutID); | 137 DOMTimer::removeByID(context, timeoutID); |
| 63 } | 138 } |
| 64 | 139 |
| 65 } // namespace DOMWindowTimers | 140 } // namespace DOMWindowTimers |
| 66 | 141 |
| 67 } // namespace blink | 142 } // namespace blink |
| OLD | NEW |