| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/dom/DocumentLifecycle.h" | 32 #include "core/dom/DocumentLifecycle.h" |
| 33 | 33 |
| 34 #include "platform/RuntimeEnabledFeatures.h" | 34 #include "platform/RuntimeEnabledFeatures.h" |
| 35 #include "wtf/Assertions.h" | 35 #include "wtf/Assertions.h" |
| 36 | 36 |
| 37 namespace blink { | 37 namespace blink { |
| 38 | 38 |
| 39 static DocumentLifecycle::DeprecatedTransition* s_deprecatedTransitionStack = 0; | 39 static DocumentLifecycle::DeprecatedTransition* s_deprecatedTransitionStack = 0; |
| 40 | 40 |
| 41 // TODO(skyostil): Come up with a better way to store cross-frame lifecycle |
| 42 // related data to avoid this being a global setting. |
| 43 static unsigned s_preventThrottlingCount = 0; |
| 44 |
| 41 DocumentLifecycle::Scope::Scope(DocumentLifecycle& lifecycle, State finalState) | 45 DocumentLifecycle::Scope::Scope(DocumentLifecycle& lifecycle, State finalState) |
| 42 : m_lifecycle(lifecycle) | 46 : m_lifecycle(lifecycle) |
| 43 , m_finalState(finalState) | 47 , m_finalState(finalState) |
| 44 { | 48 { |
| 45 } | 49 } |
| 46 | 50 |
| 47 DocumentLifecycle::Scope::~Scope() | 51 DocumentLifecycle::Scope::~Scope() |
| 48 { | 52 { |
| 49 m_lifecycle.advanceTo(m_finalState); | 53 m_lifecycle.advanceTo(m_finalState); |
| 50 } | 54 } |
| 51 | 55 |
| 52 DocumentLifecycle::DeprecatedTransition::DeprecatedTransition(State from, State
to) | 56 DocumentLifecycle::DeprecatedTransition::DeprecatedTransition(State from, State
to) |
| 53 : m_previous(s_deprecatedTransitionStack) | 57 : m_previous(s_deprecatedTransitionStack) |
| 54 , m_from(from) | 58 , m_from(from) |
| 55 , m_to(to) | 59 , m_to(to) |
| 56 { | 60 { |
| 57 s_deprecatedTransitionStack = this; | 61 s_deprecatedTransitionStack = this; |
| 58 } | 62 } |
| 59 | 63 |
| 60 DocumentLifecycle::DeprecatedTransition::~DeprecatedTransition() | 64 DocumentLifecycle::DeprecatedTransition::~DeprecatedTransition() |
| 61 { | 65 { |
| 62 s_deprecatedTransitionStack = m_previous; | 66 s_deprecatedTransitionStack = m_previous; |
| 63 } | 67 } |
| 64 | 68 |
| 69 DocumentLifecycle::PreventThrottlingScope::PreventThrottlingScope(DocumentLifecy
cle& lifecycle) |
| 70 { |
| 71 s_preventThrottlingCount++; |
| 72 } |
| 73 |
| 74 DocumentLifecycle::PreventThrottlingScope::~PreventThrottlingScope() |
| 75 { |
| 76 ASSERT(s_preventThrottlingCount > 0); |
| 77 s_preventThrottlingCount--; |
| 78 } |
| 79 |
| 65 DocumentLifecycle::DocumentLifecycle() | 80 DocumentLifecycle::DocumentLifecycle() |
| 66 : m_state(Uninitialized) | 81 : m_state(Uninitialized) |
| 67 , m_detachCount(0) | 82 , m_detachCount(0) |
| 68 { | 83 { |
| 69 } | 84 } |
| 70 | 85 |
| 71 DocumentLifecycle::~DocumentLifecycle() | 86 DocumentLifecycle::~DocumentLifecycle() |
| 72 { | 87 { |
| 73 } | 88 } |
| 74 | 89 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 void DocumentLifecycle::ensureStateAtMost(State state) | 299 void DocumentLifecycle::ensureStateAtMost(State state) |
| 285 { | 300 { |
| 286 ASSERT(state == VisualUpdatePending || state == StyleClean || state == Layou
tClean); | 301 ASSERT(state == VisualUpdatePending || state == StyleClean || state == Layou
tClean); |
| 287 if (m_state <= state) | 302 if (m_state <= state) |
| 288 return; | 303 return; |
| 289 ASSERT_WITH_MESSAGE(canRewindTo(state), | 304 ASSERT_WITH_MESSAGE(canRewindTo(state), |
| 290 "Cannot rewind document lifecycle from %s to %s.", stateAsDebugString(m_
state), stateAsDebugString(state)); | 305 "Cannot rewind document lifecycle from %s to %s.", stateAsDebugString(m_
state), stateAsDebugString(state)); |
| 291 m_state = state; | 306 m_state = state; |
| 292 } | 307 } |
| 293 | 308 |
| 309 bool DocumentLifecycle::throttlingAllowed() const |
| 310 { |
| 311 return !s_preventThrottlingCount; |
| 312 } |
| 313 |
| 294 #if ENABLE(ASSERT) | 314 #if ENABLE(ASSERT) |
| 295 #define DEBUG_STRING_CASE(StateName) \ | 315 #define DEBUG_STRING_CASE(StateName) \ |
| 296 case StateName: return #StateName | 316 case StateName: return #StateName |
| 297 | 317 |
| 298 const char* DocumentLifecycle::stateAsDebugString(const State state) | 318 const char* DocumentLifecycle::stateAsDebugString(const State state) |
| 299 { | 319 { |
| 300 switch (state) { | 320 switch (state) { |
| 301 DEBUG_STRING_CASE(Uninitialized); | 321 DEBUG_STRING_CASE(Uninitialized); |
| 302 DEBUG_STRING_CASE(Inactive); | 322 DEBUG_STRING_CASE(Inactive); |
| 303 DEBUG_STRING_CASE(VisualUpdatePending); | 323 DEBUG_STRING_CASE(VisualUpdatePending); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 323 DEBUG_STRING_CASE(Stopped); | 343 DEBUG_STRING_CASE(Stopped); |
| 324 DEBUG_STRING_CASE(Disposed); | 344 DEBUG_STRING_CASE(Disposed); |
| 325 } | 345 } |
| 326 | 346 |
| 327 ASSERT_NOT_REACHED(); | 347 ASSERT_NOT_REACHED(); |
| 328 return "Unknown"; | 348 return "Unknown"; |
| 329 } | 349 } |
| 330 #endif | 350 #endif |
| 331 | 351 |
| 332 } | 352 } |
| OLD | NEW |