OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/battery/BatteryManager.h" | 5 #include "modules/battery/BatteryManager.h" |
6 | 6 |
7 #include "core/dom/DOMException.h" | 7 #include "core/dom/DOMException.h" |
8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
9 #include "core/events/Event.h" | 9 #include "core/events/Event.h" |
10 #include "modules/battery/BatteryDispatcher.h" | 10 #include "modules/battery/BatteryDispatcher.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 stopUpdating(); | 102 stopUpdating(); |
103 } | 103 } |
104 | 104 |
105 void BatteryManager::resume() { | 105 void BatteryManager::resume() { |
106 m_hasEventListener = true; | 106 m_hasEventListener = true; |
107 startUpdating(); | 107 startUpdating(); |
108 } | 108 } |
109 | 109 |
110 void BatteryManager::contextDestroyed() { | 110 void BatteryManager::contextDestroyed() { |
111 m_hasEventListener = false; | 111 m_hasEventListener = false; |
112 m_batteryProperty.clear(); | 112 m_batteryProperty = nullptr; |
113 stopUpdating(); | 113 stopUpdating(); |
114 } | 114 } |
115 | 115 |
116 bool BatteryManager::hasPendingActivity() const { | 116 bool BatteryManager::hasPendingActivity() const { |
117 // Prevent V8 from garbage collecting the wrapper object if there are | 117 // Prevent V8 from garbage collecting the wrapper object if there are |
118 // event listeners attached to it. | 118 // event listeners attached to it. |
119 return hasEventListeners(); | 119 return getExecutionContext() && hasEventListeners(); |
120 } | 120 } |
121 | 121 |
122 DEFINE_TRACE(BatteryManager) { | 122 DEFINE_TRACE(BatteryManager) { |
123 visitor->trace(m_batteryProperty); | 123 visitor->trace(m_batteryProperty); |
124 PlatformEventController::trace(visitor); | 124 PlatformEventController::trace(visitor); |
125 EventTargetWithInlineData::trace(visitor); | 125 EventTargetWithInlineData::trace(visitor); |
126 SuspendableObject::trace(visitor); | 126 SuspendableObject::trace(visitor); |
127 } | 127 } |
128 | 128 |
129 } // namespace blink | 129 } // namespace blink |
OLD | NEW |