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 | #include "Gamepad.h" |
michael@0 | 6 | #include "nsAutoPtr.h" |
michael@0 | 7 | #include "nsTArray.h" |
michael@0 | 8 | #include "nsVariant.h" |
michael@0 | 9 | #include "mozilla/dom/GamepadBinding.h" |
michael@0 | 10 | |
michael@0 | 11 | namespace mozilla { |
michael@0 | 12 | namespace dom { |
michael@0 | 13 | |
michael@0 | 14 | NS_IMPL_CYCLE_COLLECTING_ADDREF(Gamepad) |
michael@0 | 15 | NS_IMPL_CYCLE_COLLECTING_RELEASE(Gamepad) |
michael@0 | 16 | |
michael@0 | 17 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Gamepad) |
michael@0 | 18 | NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
michael@0 | 19 | NS_INTERFACE_MAP_ENTRY(nsISupports) |
michael@0 | 20 | NS_INTERFACE_MAP_END |
michael@0 | 21 | |
michael@0 | 22 | NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(Gamepad, mParent, mButtons) |
michael@0 | 23 | |
michael@0 | 24 | Gamepad::Gamepad(nsISupports* aParent, |
michael@0 | 25 | const nsAString& aID, uint32_t aIndex, |
michael@0 | 26 | GamepadMappingType aMapping, |
michael@0 | 27 | uint32_t aNumButtons, uint32_t aNumAxes) |
michael@0 | 28 | : mParent(aParent), |
michael@0 | 29 | mID(aID), |
michael@0 | 30 | mIndex(aIndex), |
michael@0 | 31 | mMapping(aMapping), |
michael@0 | 32 | mConnected(true), |
michael@0 | 33 | mButtons(aNumButtons), |
michael@0 | 34 | mAxes(aNumAxes) |
michael@0 | 35 | { |
michael@0 | 36 | SetIsDOMBinding(); |
michael@0 | 37 | for (unsigned i = 0; i < aNumButtons; i++) { |
michael@0 | 38 | mButtons.InsertElementAt(i, new GamepadButton(mParent)); |
michael@0 | 39 | } |
michael@0 | 40 | mAxes.InsertElementsAt(0, aNumAxes, 0.0f); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | void |
michael@0 | 44 | Gamepad::SetIndex(uint32_t aIndex) |
michael@0 | 45 | { |
michael@0 | 46 | mIndex = aIndex; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | void |
michael@0 | 50 | Gamepad::SetConnected(bool aConnected) |
michael@0 | 51 | { |
michael@0 | 52 | mConnected = aConnected; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | void |
michael@0 | 56 | Gamepad::SetButton(uint32_t aButton, bool aPressed, double aValue) |
michael@0 | 57 | { |
michael@0 | 58 | MOZ_ASSERT(aButton < mButtons.Length()); |
michael@0 | 59 | mButtons[aButton]->SetPressed(aPressed); |
michael@0 | 60 | mButtons[aButton]->SetValue(aValue); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | void |
michael@0 | 64 | Gamepad::SetAxis(uint32_t aAxis, double aValue) |
michael@0 | 65 | { |
michael@0 | 66 | MOZ_ASSERT(aAxis < mAxes.Length()); |
michael@0 | 67 | if (mAxes[aAxis] != aValue) { |
michael@0 | 68 | mAxes[aAxis] = aValue; |
michael@0 | 69 | GamepadBinding::ClearCachedAxesValue(this); |
michael@0 | 70 | } |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | void |
michael@0 | 74 | Gamepad::SyncState(Gamepad* aOther) |
michael@0 | 75 | { |
michael@0 | 76 | if (mButtons.Length() != aOther->mButtons.Length() || |
michael@0 | 77 | mAxes.Length() != aOther->mAxes.Length()) { |
michael@0 | 78 | return; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | mConnected = aOther->mConnected; |
michael@0 | 82 | for (uint32_t i = 0; i < mButtons.Length(); ++i) { |
michael@0 | 83 | mButtons[i]->SetPressed(aOther->mButtons[i]->Pressed()); |
michael@0 | 84 | mButtons[i]->SetValue(aOther->mButtons[i]->Value()); |
michael@0 | 85 | } |
michael@0 | 86 | bool changed = false; |
michael@0 | 87 | for (uint32_t i = 0; i < mAxes.Length(); ++i) { |
michael@0 | 88 | changed = changed || (mAxes[i] != aOther->mAxes[i]); |
michael@0 | 89 | mAxes[i] = aOther->mAxes[i]; |
michael@0 | 90 | } |
michael@0 | 91 | if (changed) { |
michael@0 | 92 | GamepadBinding::ClearCachedAxesValue(this); |
michael@0 | 93 | } |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | already_AddRefed<Gamepad> |
michael@0 | 97 | Gamepad::Clone(nsISupports* aParent) |
michael@0 | 98 | { |
michael@0 | 99 | nsRefPtr<Gamepad> out = |
michael@0 | 100 | new Gamepad(aParent, mID, mIndex, mMapping, |
michael@0 | 101 | mButtons.Length(), mAxes.Length()); |
michael@0 | 102 | out->SyncState(this); |
michael@0 | 103 | return out.forget(); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | /* virtual */ JSObject* |
michael@0 | 107 | Gamepad::WrapObject(JSContext* aCx) |
michael@0 | 108 | { |
michael@0 | 109 | return GamepadBinding::Wrap(aCx, this); |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | } // namespace dom |
michael@0 | 113 | } // namespace mozilla |