Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifndef mozilla_dom_GamepadService_h_ |
michael@0 | 6 | #define mozilla_dom_GamepadService_h_ |
michael@0 | 7 | |
michael@0 | 8 | #include <stdint.h> |
michael@0 | 9 | #include "Gamepad.h" |
michael@0 | 10 | #include "nsAutoPtr.h" |
michael@0 | 11 | #include "nsCOMArray.h" |
michael@0 | 12 | #include "nsIGamepadServiceTest.h" |
michael@0 | 13 | #include "nsGlobalWindow.h" |
michael@0 | 14 | #include "nsIFocusManager.h" |
michael@0 | 15 | #include "nsIObserver.h" |
michael@0 | 16 | #include "nsITimer.h" |
michael@0 | 17 | #include "nsTArray.h" |
michael@0 | 18 | |
michael@0 | 19 | class nsIDOMDocument; |
michael@0 | 20 | |
michael@0 | 21 | namespace mozilla { |
michael@0 | 22 | namespace dom { |
michael@0 | 23 | |
michael@0 | 24 | class EventTarget; |
michael@0 | 25 | |
michael@0 | 26 | class GamepadService : public nsIObserver |
michael@0 | 27 | { |
michael@0 | 28 | public: |
michael@0 | 29 | NS_DECL_ISUPPORTS |
michael@0 | 30 | NS_DECL_NSIOBSERVER |
michael@0 | 31 | |
michael@0 | 32 | // Get the singleton service |
michael@0 | 33 | static already_AddRefed<GamepadService> GetService(); |
michael@0 | 34 | // Return true if the API is preffed on. |
michael@0 | 35 | static bool IsAPIEnabled(); |
michael@0 | 36 | |
michael@0 | 37 | void BeginShutdown(); |
michael@0 | 38 | |
michael@0 | 39 | // Indicate that |aWindow| wants to receive gamepad events. |
michael@0 | 40 | void AddListener(nsGlobalWindow* aWindow); |
michael@0 | 41 | // Indicate that |aWindow| should no longer receive gamepad events. |
michael@0 | 42 | void RemoveListener(nsGlobalWindow* aWindow); |
michael@0 | 43 | |
michael@0 | 44 | // Add a gamepad to the list of known gamepads, and return its index. |
michael@0 | 45 | uint32_t AddGamepad(const char* aID, GamepadMappingType aMapping, |
michael@0 | 46 | uint32_t aNumButtons, uint32_t aNumAxes); |
michael@0 | 47 | // Remove the gamepad at |aIndex| from the list of known gamepads. |
michael@0 | 48 | void RemoveGamepad(uint32_t aIndex); |
michael@0 | 49 | |
michael@0 | 50 | // Update the state of |aButton| for the gamepad at |aIndex| for all |
michael@0 | 51 | // windows that are listening and visible, and fire one of |
michael@0 | 52 | // a gamepadbutton{up,down} event at them as well. |
michael@0 | 53 | // aPressed is used for digital buttons, aValue is for analog buttons. |
michael@0 | 54 | void NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed, |
michael@0 | 55 | double aValue); |
michael@0 | 56 | // When only a digital button is available the value will be synthesized. |
michael@0 | 57 | void NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed); |
michael@0 | 58 | |
michael@0 | 59 | // Update the state of |aAxis| for the gamepad at |aIndex| for all |
michael@0 | 60 | // windows that are listening and visible, and fire a gamepadaxismove |
michael@0 | 61 | // event at them as well. |
michael@0 | 62 | void NewAxisMoveEvent(uint32_t aIndex, uint32_t aAxis, double aValue); |
michael@0 | 63 | |
michael@0 | 64 | // Synchronize the state of |aGamepad| to match the gamepad stored at |aIndex| |
michael@0 | 65 | void SyncGamepadState(uint32_t aIndex, Gamepad* aGamepad); |
michael@0 | 66 | |
michael@0 | 67 | protected: |
michael@0 | 68 | GamepadService(); |
michael@0 | 69 | virtual ~GamepadService() {}; |
michael@0 | 70 | void StartCleanupTimer(); |
michael@0 | 71 | |
michael@0 | 72 | // Fire a gamepadconnected or gamepaddisconnected event for the gamepad |
michael@0 | 73 | // at |aIndex| to all windows that are listening and have received |
michael@0 | 74 | // gamepad input. |
michael@0 | 75 | void NewConnectionEvent(uint32_t aIndex, bool aConnected); |
michael@0 | 76 | |
michael@0 | 77 | // Fire a gamepadaxismove event to the window at |aTarget| for |aGamepad|. |
michael@0 | 78 | void FireAxisMoveEvent(EventTarget* aTarget, |
michael@0 | 79 | Gamepad* aGamepad, |
michael@0 | 80 | uint32_t axis, |
michael@0 | 81 | double value); |
michael@0 | 82 | |
michael@0 | 83 | // Fire one of gamepadbutton{up,down} event at the window at |aTarget| for |
michael@0 | 84 | // |aGamepad|. |
michael@0 | 85 | void FireButtonEvent(EventTarget* aTarget, |
michael@0 | 86 | Gamepad* aGamepad, |
michael@0 | 87 | uint32_t aButton, |
michael@0 | 88 | double aValue); |
michael@0 | 89 | |
michael@0 | 90 | // Fire one of gamepad{connected,disconnected} event at the window at |
michael@0 | 91 | // |aTarget| for |aGamepad|. |
michael@0 | 92 | void FireConnectionEvent(EventTarget* aTarget, |
michael@0 | 93 | Gamepad* aGamepad, |
michael@0 | 94 | bool aConnected); |
michael@0 | 95 | |
michael@0 | 96 | // true if this feature is enabled in preferences |
michael@0 | 97 | bool mEnabled; |
michael@0 | 98 | // true if non-standard events are enabled in preferences |
michael@0 | 99 | bool mNonstandardEventsEnabled; |
michael@0 | 100 | // true if the platform-specific backend has started work |
michael@0 | 101 | bool mStarted; |
michael@0 | 102 | // true when shutdown has begun |
michael@0 | 103 | bool mShuttingDown; |
michael@0 | 104 | |
michael@0 | 105 | private: |
michael@0 | 106 | // Returns true if we have already sent data from this gamepad |
michael@0 | 107 | // to this window. This should only return true if the user |
michael@0 | 108 | // explicitly interacted with a gamepad while this window |
michael@0 | 109 | // was focused, by pressing buttons or similar actions. |
michael@0 | 110 | bool WindowHasSeenGamepad(nsGlobalWindow* aWindow, uint32_t aIndex); |
michael@0 | 111 | // Indicate that a window has recieved data from a gamepad. |
michael@0 | 112 | void SetWindowHasSeenGamepad(nsGlobalWindow* aWindow, uint32_t aIndex, |
michael@0 | 113 | bool aHasSeen = true); |
michael@0 | 114 | |
michael@0 | 115 | static void TimeoutHandler(nsITimer* aTimer, void* aClosure); |
michael@0 | 116 | static bool sShutdown; |
michael@0 | 117 | |
michael@0 | 118 | // Gamepads connected to the system. Copies of these are handed out |
michael@0 | 119 | // to each window. |
michael@0 | 120 | nsTArray<nsRefPtr<Gamepad> > mGamepads; |
michael@0 | 121 | // nsGlobalWindows that are listening for gamepad events. |
michael@0 | 122 | // has been sent to that window. |
michael@0 | 123 | nsTArray<nsRefPtr<nsGlobalWindow> > mListeners; |
michael@0 | 124 | nsCOMPtr<nsITimer> mTimer; |
michael@0 | 125 | nsCOMPtr<nsIFocusManager> mFocusManager; |
michael@0 | 126 | nsCOMPtr<nsIObserver> mObserver; |
michael@0 | 127 | }; |
michael@0 | 128 | |
michael@0 | 129 | // Service for testing purposes |
michael@0 | 130 | class GamepadServiceTest : public nsIGamepadServiceTest |
michael@0 | 131 | { |
michael@0 | 132 | public: |
michael@0 | 133 | NS_DECL_ISUPPORTS |
michael@0 | 134 | NS_DECL_NSIGAMEPADSERVICETEST |
michael@0 | 135 | |
michael@0 | 136 | GamepadServiceTest(); |
michael@0 | 137 | |
michael@0 | 138 | static already_AddRefed<GamepadServiceTest> CreateService(); |
michael@0 | 139 | |
michael@0 | 140 | private: |
michael@0 | 141 | static GamepadServiceTest* sSingleton; |
michael@0 | 142 | virtual ~GamepadServiceTest() {}; |
michael@0 | 143 | }; |
michael@0 | 144 | |
michael@0 | 145 | } // namespace dom |
michael@0 | 146 | } // namespace mozilla |
michael@0 | 147 | |
michael@0 | 148 | #define NS_GAMEPAD_TEST_CID \ |
michael@0 | 149 | { 0xfb1fcb57, 0xebab, 0x4cf4, \ |
michael@0 | 150 | { 0x96, 0x3b, 0x1e, 0x4d, 0xb8, 0x52, 0x16, 0x96 } } |
michael@0 | 151 | #define NS_GAMEPAD_TEST_CONTRACTID "@mozilla.org/gamepad-test;1" |
michael@0 | 152 | |
michael@0 | 153 | #endif // mozilla_dom_GamepadService_h_ |