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

Side by Side Diff: third_party/WebKit/WebCore/page/DOMTimer.cpp

Issue 20076: WebKit merge 40500:40539 [WebKit side] (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 * 24 *
25 */ 25 */
26 26
27 #include "config.h" 27 #include "config.h"
28 #include "DOMTimer.h" 28 #include "DOMTimer.h"
29 29
30 #include "Document.h"
31 #include "ScheduledAction.h" 30 #include "ScheduledAction.h"
32 #include "ScriptExecutionContext.h" 31 #include "ScriptExecutionContext.h"
33 #include <wtf/HashSet.h> 32 #include <wtf/HashSet.h>
34 #include <wtf/StdLibExtras.h> 33 #include <wtf/StdLibExtras.h>
35 34
36 using namespace std; 35 using namespace std;
37 36
38 namespace WebCore { 37 namespace WebCore {
39 38
40 static const int maxTimerNestingLevel = 5; 39 static const int maxTimerNestingLevel = 5;
(...skipping 10 matching lines...) Expand all
51 { 50 {
52 static int lastUsedTimeoutId = 0; 51 static int lastUsedTimeoutId = 0;
53 ++lastUsedTimeoutId; 52 ++lastUsedTimeoutId;
54 // Avoid wraparound going negative on us. 53 // Avoid wraparound going negative on us.
55 if (lastUsedTimeoutId <= 0) 54 if (lastUsedTimeoutId <= 0)
56 lastUsedTimeoutId = 1; 55 lastUsedTimeoutId = 1;
57 m_timeoutId = lastUsedTimeoutId; 56 m_timeoutId = lastUsedTimeoutId;
58 57
59 m_nestingLevel = timerNestingLevel + 1; 58 m_nestingLevel = timerNestingLevel + 1;
60 59
61 // FIXME: Move the timeout map and API to ScriptExecutionContext to be able 60 scriptExecutionContext()->addTimeout(m_timeoutId, this);
62 // to create timeouts from Workers.
63 ASSERT(scriptExecutionContext() && scriptExecutionContext()->isDocument());
64 static_cast<Document*>(scriptExecutionContext())->addTimeout(m_timeoutId, th is);
65 61
66 double intervalMilliseconds = max(oneMillisecond, timeout * oneMillisecond); 62 double intervalMilliseconds = max(oneMillisecond, timeout * oneMillisecond);
67 63
68 // Use a minimum interval of 10 ms to match other browsers, but only once we 've 64 // Use a minimum interval of 10 ms to match other browsers, but only once we 've
69 // nested enough to notice that we're repeating. 65 // nested enough to notice that we're repeating.
70 // Faster timers might be "better", but they're incompatible. 66 // Faster timers might be "better", but they're incompatible.
71 if (intervalMilliseconds < minTimerInterval && m_nestingLevel >= maxTimerNes tingLevel) 67 if (intervalMilliseconds < minTimerInterval && m_nestingLevel >= maxTimerNes tingLevel)
72 intervalMilliseconds = minTimerInterval; 68 intervalMilliseconds = minTimerInterval;
73 if (singleShot) 69 if (singleShot)
74 startOneShot(intervalMilliseconds); 70 startOneShot(intervalMilliseconds);
75 else 71 else
76 startRepeating(intervalMilliseconds); 72 startRepeating(intervalMilliseconds);
77 } 73 }
78 74
79 DOMTimer::~DOMTimer() 75 DOMTimer::~DOMTimer()
80 { 76 {
81 if (scriptExecutionContext()) { 77 if (scriptExecutionContext()) {
82 ASSERT(scriptExecutionContext()->isDocument()); 78 scriptExecutionContext()->removeTimeout(m_timeoutId);
83 static_cast<Document*>(scriptExecutionContext())->removeTimeout(m_timeou tId);
84 } 79 }
85 } 80 }
86 81
87 int DOMTimer::install(ScriptExecutionContext* context, ScheduledAction* action, int timeout, bool singleShot) 82 int DOMTimer::install(ScriptExecutionContext* context, ScheduledAction* action, int timeout, bool singleShot)
88 { 83 {
89 // DOMTimer constructor links the new timer into a list of ActiveDOMObjects held by the 'context'. 84 // DOMTimer constructor links the new timer into a list of ActiveDOMObjects held by the 'context'.
90 // The timer is deleted when context is deleted (DOMTimer::contextDestroyed) or explicitly via DOMTimer::removeById(), 85 // The timer is deleted when context is deleted (DOMTimer::contextDestroyed) or explicitly via DOMTimer::removeById(),
91 // or if it is a one-time timer and it has fired (DOMTimer::fired). 86 // or if it is a one-time timer and it has fired (DOMTimer::fired).
92 DOMTimer* timer = new DOMTimer(context, action, timeout, singleShot); 87 DOMTimer* timer = new DOMTimer(context, action, timeout, singleShot);
93 return timer->m_timeoutId; 88 return timer->m_timeoutId;
94 } 89 }
95 90
96 void DOMTimer::removeById(ScriptExecutionContext* context, int timeoutId) 91 void DOMTimer::removeById(ScriptExecutionContext* context, int timeoutId)
97 { 92 {
98 // timeout IDs have to be positive, and 0 and -1 are unsafe to 93 // timeout IDs have to be positive, and 0 and -1 are unsafe to
99 // even look up since they are the empty and deleted value 94 // even look up since they are the empty and deleted value
100 // respectively 95 // respectively
101 if (timeoutId <= 0) 96 if (timeoutId <= 0)
102 return; 97 return;
103 ASSERT(context && context->isDocument()); 98 delete context->findTimeout(timeoutId);
104 delete static_cast<Document*>(context)->findTimeout(timeoutId);
105 } 99 }
106 100
107 void DOMTimer::fired() 101 void DOMTimer::fired()
108 { 102 {
109 ScriptExecutionContext* context = scriptExecutionContext(); 103 ScriptExecutionContext* context = scriptExecutionContext();
110 timerNestingLevel = m_nestingLevel; 104 timerNestingLevel = m_nestingLevel;
111 105
112 // Simple case for non-one-shot timers. 106 // Simple case for non-one-shot timers.
113 if (isActive()) { 107 if (isActive()) {
114 if (repeatInterval() && repeatInterval() < minTimerInterval) { 108 if (repeatInterval() && repeatInterval() < minTimerInterval) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 m_repeatInterval = 0; 162 m_repeatInterval = 0;
169 } 163 }
170 164
171 165
172 bool DOMTimer::canSuspend() const 166 bool DOMTimer::canSuspend() const
173 { 167 {
174 return true; 168 return true;
175 } 169 }
176 170
177 } // namespace WebCore 171 } // namespace WebCore
OLDNEW
« no previous file with comments | « third_party/WebKit/WebCore/loader/archive/cf/LegacyWebArchive.cpp ('k') | third_party/WebKit/WebCore/page/DragController.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698