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 #ifndef BatteryManager_h | 5 #ifndef BatteryManager_h |
6 #define BatteryManager_h | 6 #define BatteryManager_h |
7 | 7 |
| 8 #include "bindings/v8/ScriptPromise.h" |
| 9 #include "bindings/v8/ScriptPromiseResolverWithContext.h" |
8 #include "core/dom/ContextLifecycleObserver.h" | 10 #include "core/dom/ContextLifecycleObserver.h" |
9 #include "core/dom/Document.h" | 11 #include "core/dom/Document.h" |
10 #include "core/frame/DeviceEventControllerBase.h" | 12 #include "core/frame/DeviceEventControllerBase.h" |
11 #include "modules/EventTargetModules.h" | 13 #include "modules/EventTargetModules.h" |
12 #include "platform/heap/Handle.h" | 14 #include "platform/heap/Handle.h" |
13 | 15 |
14 namespace WebCore { | 16 namespace WebCore { |
15 | 17 |
16 class BatteryStatus; | 18 class BatteryStatus; |
17 class Navigator; | |
18 | 19 |
19 class BatteryManager FINAL : public RefCountedWillBeRefCountedGarbageCollected<B
atteryManager>, public ActiveDOMObject, public DeviceEventControllerBase, public
EventTargetWithInlineData { | 20 class BatteryManager FINAL : public RefCountedWillBeRefCountedGarbageCollected<B
atteryManager>, public ActiveDOMObject, public DeviceEventControllerBase, public
EventTargetWithInlineData { |
20 REFCOUNTED_EVENT_TARGET(BatteryManager); | 21 REFCOUNTED_EVENT_TARGET(BatteryManager); |
21 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(BatteryManager); | 22 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(BatteryManager); |
22 public: | 23 public: |
23 virtual ~BatteryManager(); | 24 virtual ~BatteryManager(); |
24 static PassRefPtrWillBeRawPtr<BatteryManager> create(ExecutionContext*); | 25 static PassRefPtrWillBeRawPtr<BatteryManager> create(ExecutionContext*); |
25 | 26 |
| 27 // Returns a promise object that will be resolved with this BatteryManager. |
| 28 ScriptPromise startRequest(ScriptState*); |
| 29 |
26 // EventTarget implementation. | 30 // EventTarget implementation. |
27 virtual const WTF::AtomicString& interfaceName() const OVERRIDE { return Eve
ntTargetNames::BatteryManager; } | 31 virtual const WTF::AtomicString& interfaceName() const OVERRIDE { return Eve
ntTargetNames::BatteryManager; } |
28 virtual ExecutionContext* executionContext() const OVERRIDE { return Context
LifecycleObserver::executionContext(); } | 32 virtual ExecutionContext* executionContext() const OVERRIDE { return Context
LifecycleObserver::executionContext(); } |
29 | 33 |
30 bool charging(); | 34 bool charging(); |
31 double chargingTime(); | 35 double chargingTime(); |
32 double dischargingTime(); | 36 double dischargingTime(); |
33 double level(); | 37 double level(); |
34 | 38 |
35 DEFINE_ATTRIBUTE_EVENT_LISTENER(chargingchange); | 39 DEFINE_ATTRIBUTE_EVENT_LISTENER(chargingchange); |
36 DEFINE_ATTRIBUTE_EVENT_LISTENER(chargingtimechange); | 40 DEFINE_ATTRIBUTE_EVENT_LISTENER(chargingtimechange); |
37 DEFINE_ATTRIBUTE_EVENT_LISTENER(dischargingtimechange); | 41 DEFINE_ATTRIBUTE_EVENT_LISTENER(dischargingtimechange); |
38 DEFINE_ATTRIBUTE_EVENT_LISTENER(levelchange); | 42 DEFINE_ATTRIBUTE_EVENT_LISTENER(levelchange); |
39 | 43 |
40 // Inherited from DeviceEventControllerBase. | 44 // Inherited from DeviceEventControllerBase. |
41 virtual void didUpdateData() OVERRIDE; | 45 virtual void didUpdateData() OVERRIDE; |
42 virtual void registerWithDispatcher() OVERRIDE; | 46 virtual void registerWithDispatcher() OVERRIDE; |
43 virtual void unregisterWithDispatcher() OVERRIDE; | 47 virtual void unregisterWithDispatcher() OVERRIDE; |
44 virtual bool hasLastData() OVERRIDE; | 48 virtual bool hasLastData() OVERRIDE; |
45 | 49 |
46 // ActiveDOMObject implementation. | 50 // ActiveDOMObject implementation. |
47 virtual bool canSuspend() const { return true; } | 51 virtual bool canSuspend() const { return true; } |
48 virtual void suspend() OVERRIDE; | 52 virtual void suspend() OVERRIDE; |
49 virtual void resume() OVERRIDE; | 53 virtual void resume() OVERRIDE; |
50 virtual void stop() OVERRIDE; | 54 virtual void stop() OVERRIDE; |
51 | 55 |
52 private: | 56 private: |
| 57 enum State { |
| 58 NotStarted, |
| 59 Pending, |
| 60 Resolved, |
| 61 }; |
| 62 |
53 explicit BatteryManager(ExecutionContext*); | 63 explicit BatteryManager(ExecutionContext*); |
54 | 64 |
| 65 RefPtr<ScriptPromiseResolverWithContext> m_resolver; |
55 RefPtr<BatteryStatus> m_batteryStatus; | 66 RefPtr<BatteryStatus> m_batteryStatus; |
| 67 State m_state; |
56 }; | 68 }; |
57 | 69 |
58 } | 70 } |
59 | 71 |
60 #endif // BatteryManager_h | 72 #endif // BatteryManager_h |
61 | 73 |
OLD | NEW |