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