|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 #ifndef mozilla_dom_power_PowerManager_h |
|
6 #define mozilla_dom_power_PowerManager_h |
|
7 |
|
8 #include "nsCOMPtr.h" |
|
9 #include "nsTArray.h" |
|
10 #include "nsIDOMWakeLockListener.h" |
|
11 #include "nsIDOMWindow.h" |
|
12 #include "nsWeakReference.h" |
|
13 #include "nsCycleCollectionParticipant.h" |
|
14 #include "nsWrapperCache.h" |
|
15 |
|
16 class nsPIDOMWindow; |
|
17 |
|
18 namespace mozilla { |
|
19 class ErrorResult; |
|
20 |
|
21 namespace dom { |
|
22 |
|
23 class PowerManager MOZ_FINAL : public nsIDOMMozWakeLockListener |
|
24 , public nsWrapperCache |
|
25 { |
|
26 public: |
|
27 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
28 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(PowerManager) |
|
29 NS_DECL_NSIDOMMOZWAKELOCKLISTENER |
|
30 |
|
31 PowerManager() |
|
32 { |
|
33 SetIsDOMBinding(); |
|
34 } |
|
35 |
|
36 nsresult Init(nsIDOMWindow *aWindow); |
|
37 nsresult Shutdown(); |
|
38 |
|
39 static bool CheckPermission(nsPIDOMWindow*); |
|
40 |
|
41 static already_AddRefed<PowerManager> CreateInstance(nsPIDOMWindow*); |
|
42 |
|
43 // WebIDL |
|
44 nsIDOMWindow* GetParentObject() const |
|
45 { |
|
46 return mWindow; |
|
47 } |
|
48 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
49 void Reboot(ErrorResult& aRv); |
|
50 void FactoryReset(); |
|
51 void PowerOff(ErrorResult& aRv); |
|
52 void AddWakeLockListener(nsIDOMMozWakeLockListener* aListener); |
|
53 void RemoveWakeLockListener(nsIDOMMozWakeLockListener* aListener); |
|
54 void GetWakeLockState(const nsAString& aTopic, nsAString& aState, |
|
55 ErrorResult& aRv); |
|
56 bool ScreenEnabled(); |
|
57 void SetScreenEnabled(bool aEnabled); |
|
58 double ScreenBrightness(); |
|
59 void SetScreenBrightness(double aBrightness, ErrorResult& aRv); |
|
60 bool CpuSleepAllowed(); |
|
61 void SetCpuSleepAllowed(bool aAllowed); |
|
62 |
|
63 private: |
|
64 nsCOMPtr<nsIDOMWindow> mWindow; |
|
65 nsTArray<nsCOMPtr<nsIDOMMozWakeLockListener> > mListeners; |
|
66 }; |
|
67 |
|
68 } // namespace dom |
|
69 } // namespace mozilla |
|
70 |
|
71 #endif // mozilla_dom_power_PowerManager_h |