| OLD | NEW |
| 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 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 // second at most. | 62 // second at most. |
| 63 return 1.0; | 63 return 1.0; |
| 64 } | 64 } |
| 65 | 65 |
| 66 double DOMTimer::visiblePageAlignmentInterval() | 66 double DOMTimer::visiblePageAlignmentInterval() |
| 67 { | 67 { |
| 68 // Alignment does not apply to timers on visible pages. | 68 // Alignment does not apply to timers on visible pages. |
| 69 return 0; | 69 return 0; |
| 70 } | 70 } |
| 71 | 71 |
| 72 int DOMTimer::install(ScriptExecutionContext* context, PassOwnPtr<ScheduledActio
n> action, int timeout, bool singleShot) | 72 int DOMTimer::install(ScriptExecutionContext* context, TimerType timerType, Pass
OwnPtr<ScheduledAction> action, int timeout) |
| 73 { | 73 { |
| 74 int timeoutID = context->installNewTimeout(action, timeout, singleShot); | 74 int timeoutID = context->installNewTimeout(timerType, action, timeout); |
| 75 InspectorInstrumentation::didInstallTimer(context, timeoutID, timeout, singl
eShot); | 75 InspectorInstrumentation::didInstallTimer(context, timeoutID, timeout, timer
Type == TimerTypeTimeout); // FIXME: Fix inspector so it can accept a TimerType
value. |
| 76 return timeoutID; | 76 return timeoutID; |
| 77 } | 77 } |
| 78 | 78 |
| 79 void DOMTimer::removeByID(ScriptExecutionContext* context, int timeoutID) | 79 void DOMTimer::removeByIDIfTypeMatches(ScriptExecutionContext* context, TimerTyp
e timerType, int timeoutID) |
| 80 { | 80 { |
| 81 context->removeTimeoutByID(timeoutID); | 81 context->removeTimeoutByIDIfTypeMatches(timerType, timeoutID); |
| 82 InspectorInstrumentation::didRemoveTimer(context, timeoutID); | 82 InspectorInstrumentation::didRemoveTimer(context, timeoutID == TimerTypeTime
out); // FIXME: Ditto. |
| 83 } | 83 } |
| 84 | 84 |
| 85 DOMTimer::DOMTimer(ScriptExecutionContext* context, PassOwnPtr<ScheduledAction>
action, int interval, bool singleShot, int timeoutID) | 85 DOMTimer::DOMTimer(ScriptExecutionContext* context, TimerType timerType, PassOwn
Ptr<ScheduledAction> action, int interval, int timeoutID) |
| 86 : SuspendableTimer(context) | 86 : SuspendableTimer(context) |
| 87 , m_timerType(timerType) |
| 87 , m_timeoutID(timeoutID) | 88 , m_timeoutID(timeoutID) |
| 88 , m_nestingLevel(timerNestingLevel + 1) | 89 , m_nestingLevel(timerNestingLevel + 1) |
| 89 , m_action(action) | 90 , m_action(action) |
| 90 { | 91 { |
| 91 ASSERT(timeoutID > 0); | 92 ASSERT(timeoutID > 0); |
| 92 if (shouldForwardUserGesture(interval, m_nestingLevel)) | 93 if (shouldForwardUserGesture(interval, m_nestingLevel)) |
| 93 m_userGestureToken = UserGestureIndicator::currentToken(); | 94 m_userGestureToken = UserGestureIndicator::currentToken(); |
| 94 | 95 |
| 95 double intervalMilliseconds = max(oneMillisecond, interval * oneMillisecond)
; | 96 double intervalMilliseconds = max(oneMillisecond, interval * oneMillisecond)
; |
| 96 if (intervalMilliseconds < minimumInterval && m_nestingLevel >= maxTimerNest
ingLevel) | 97 if (intervalMilliseconds < minimumInterval && m_nestingLevel >= maxTimerNest
ingLevel) |
| 97 intervalMilliseconds = minimumInterval; | 98 intervalMilliseconds = minimumInterval; |
| 98 if (singleShot) | 99 switch (timerType) { |
| 100 case TimerTypeTimeout: |
| 99 startOneShot(intervalMilliseconds); | 101 startOneShot(intervalMilliseconds); |
| 100 else | 102 break; |
| 103 case TimerTypeInterval: |
| 101 startRepeating(intervalMilliseconds); | 104 startRepeating(intervalMilliseconds); |
| 105 break; |
| 106 } |
| 102 } | 107 } |
| 103 | 108 |
| 104 DOMTimer::~DOMTimer() | 109 DOMTimer::~DOMTimer() |
| 105 { | 110 { |
| 106 } | 111 } |
| 107 | 112 |
| 108 int DOMTimer::timeoutID() const | 113 int DOMTimer::timeoutID() const |
| 109 { | 114 { |
| 110 return m_timeoutID; | 115 return m_timeoutID; |
| 111 } | 116 } |
| 112 | 117 |
| 118 DOMTimer::TimerType DOMTimer::timerType() const |
| 119 { |
| 120 return m_timerType; |
| 121 } |
| 122 |
| 113 void DOMTimer::fired() | 123 void DOMTimer::fired() |
| 114 { | 124 { |
| 115 ScriptExecutionContext* context = scriptExecutionContext(); | 125 ScriptExecutionContext* context = scriptExecutionContext(); |
| 116 timerNestingLevel = m_nestingLevel; | 126 timerNestingLevel = m_nestingLevel; |
| 117 ASSERT(!context->activeDOMObjectsAreSuspended()); | 127 ASSERT(!context->activeDOMObjectsAreSuspended()); |
| 118 // Only the first execution of a multi-shot timer should get an affirmative
user gesture indicator. | 128 // Only the first execution of a multi-shot timer should get an affirmative
user gesture indicator. |
| 119 UserGestureIndicator gestureIndicator(m_userGestureToken.release()); | 129 UserGestureIndicator gestureIndicator(m_userGestureToken.release()); |
| 120 | 130 |
| 121 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willFireTi
mer(context, m_timeoutID); | 131 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willFireTi
mer(context, m_timeoutID); |
| 122 | 132 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 133 | 143 |
| 134 InspectorInstrumentation::didFireTimer(cookie); | 144 InspectorInstrumentation::didFireTimer(cookie); |
| 135 | 145 |
| 136 return; | 146 return; |
| 137 } | 147 } |
| 138 | 148 |
| 139 // Delete timer before executing the action for one-shot timers. | 149 // Delete timer before executing the action for one-shot timers. |
| 140 OwnPtr<ScheduledAction> action = m_action.release(); | 150 OwnPtr<ScheduledAction> action = m_action.release(); |
| 141 | 151 |
| 142 // This timer is being deleted; no access to member variables allowed after
this point. | 152 // This timer is being deleted; no access to member variables allowed after
this point. |
| 143 context->removeTimeoutByID(m_timeoutID); | 153 context->removeTimeoutByIDIfTypeMatches(m_timerType, m_timeoutID); |
| 144 | 154 |
| 145 action->execute(context); | 155 action->execute(context); |
| 146 | 156 |
| 147 InspectorInstrumentation::didFireTimer(cookie); | 157 InspectorInstrumentation::didFireTimer(cookie); |
| 148 | 158 |
| 149 timerNestingLevel = 0; | 159 timerNestingLevel = 0; |
| 150 } | 160 } |
| 151 | 161 |
| 152 void DOMTimer::contextDestroyed() | 162 void DOMTimer::contextDestroyed() |
| 153 { | 163 { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 180 | 190 |
| 181 void DOMTimer::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const | 191 void DOMTimer::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const |
| 182 { | 192 { |
| 183 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM); | 193 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM); |
| 184 SuspendableTimer::reportMemoryUsage(memoryObjectInfo); | 194 SuspendableTimer::reportMemoryUsage(memoryObjectInfo); |
| 185 info.addMember(m_action, "action"); | 195 info.addMember(m_action, "action"); |
| 186 info.addMember(m_userGestureToken, "userGestureToken"); | 196 info.addMember(m_userGestureToken, "userGestureToken"); |
| 187 } | 197 } |
| 188 | 198 |
| 189 } // namespace WebCore | 199 } // namespace WebCore |
| OLD | NEW |