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