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 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * vim: set ts=8 sts=4 et sw=4 tw=99: |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef vm_ProxyObject_h |
michael@0 | 8 | #define vm_ProxyObject_h |
michael@0 | 9 | |
michael@0 | 10 | #include "jsobj.h" |
michael@0 | 11 | #include "jsproxy.h" |
michael@0 | 12 | |
michael@0 | 13 | namespace js { |
michael@0 | 14 | |
michael@0 | 15 | // This is the base class for the various kinds of proxy objects. It's never |
michael@0 | 16 | // instantiated. |
michael@0 | 17 | class ProxyObject : public JSObject |
michael@0 | 18 | { |
michael@0 | 19 | // These are just local renamings of the slot constants that are part of |
michael@0 | 20 | // the API in jsproxy.h. |
michael@0 | 21 | static const uint32_t PRIVATE_SLOT = PROXY_PRIVATE_SLOT; |
michael@0 | 22 | static const uint32_t HANDLER_SLOT = PROXY_HANDLER_SLOT; |
michael@0 | 23 | static const uint32_t EXTRA_SLOT = PROXY_EXTRA_SLOT; |
michael@0 | 24 | |
michael@0 | 25 | public: |
michael@0 | 26 | static ProxyObject *New(JSContext *cx, BaseProxyHandler *handler, HandleValue priv, |
michael@0 | 27 | TaggedProto proto_, JSObject *parent_, |
michael@0 | 28 | const ProxyOptions &options); |
michael@0 | 29 | |
michael@0 | 30 | const Value &private_() { |
michael@0 | 31 | return GetReservedSlot(this, PRIVATE_SLOT); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | void initCrossCompartmentPrivate(HandleValue priv); |
michael@0 | 35 | |
michael@0 | 36 | HeapSlot *slotOfPrivate() { |
michael@0 | 37 | return &getReservedSlotRef(PRIVATE_SLOT); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | JSObject *target() const { |
michael@0 | 41 | return const_cast<ProxyObject*>(this)->private_().toObjectOrNull(); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | BaseProxyHandler *handler() { |
michael@0 | 45 | return static_cast<BaseProxyHandler*>(GetReservedSlot(this, HANDLER_SLOT).toPrivate()); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | void initHandler(BaseProxyHandler *handler); |
michael@0 | 49 | |
michael@0 | 50 | void setHandler(BaseProxyHandler *handler) { |
michael@0 | 51 | SetReservedSlot(this, HANDLER_SLOT, PrivateValue(handler)); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | static size_t offsetOfHandler() { |
michael@0 | 55 | return getFixedSlotOffset(HANDLER_SLOT); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | const Value &extra(size_t n) const { |
michael@0 | 59 | JS_ASSERT(n == 0 || n == 1); |
michael@0 | 60 | return GetReservedSlot(const_cast<ProxyObject*>(this), EXTRA_SLOT + n); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | void setExtra(size_t n, const Value &extra) { |
michael@0 | 64 | JS_ASSERT(n == 0 || n == 1); |
michael@0 | 65 | SetReservedSlot(this, EXTRA_SLOT + n, extra); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | private: |
michael@0 | 69 | HeapSlot *slotOfExtra(size_t n) { |
michael@0 | 70 | JS_ASSERT(n == 0 || n == 1); |
michael@0 | 71 | return &getReservedSlotRef(EXTRA_SLOT + n); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | HeapSlot *slotOfClassSpecific(size_t n) { |
michael@0 | 75 | JS_ASSERT(n >= PROXY_MINIMUM_SLOTS); |
michael@0 | 76 | JS_ASSERT(n < JSCLASS_RESERVED_SLOTS(getClass())); |
michael@0 | 77 | return &getReservedSlotRef(n); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | static bool isValidProxyClass(const Class *clasp) { |
michael@0 | 81 | // Since we can take classes from the outside, make sure that they |
michael@0 | 82 | // are "sane". They have to quack enough like proxies for us to belive |
michael@0 | 83 | // they should be treated as such. |
michael@0 | 84 | |
michael@0 | 85 | // proxy_Trace is just a trivial wrapper around ProxyObject::trace for |
michael@0 | 86 | // friend api exposure. |
michael@0 | 87 | return clasp->isProxy() && |
michael@0 | 88 | (clasp->flags & JSCLASS_IMPLEMENTS_BARRIERS) && |
michael@0 | 89 | clasp->trace == proxy_Trace && |
michael@0 | 90 | JSCLASS_RESERVED_SLOTS(clasp) >= PROXY_MINIMUM_SLOTS; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | public: |
michael@0 | 94 | static unsigned grayLinkSlot(JSObject *obj); |
michael@0 | 95 | |
michael@0 | 96 | void renew(JSContext *cx, BaseProxyHandler *handler, Value priv); |
michael@0 | 97 | |
michael@0 | 98 | static void trace(JSTracer *trc, JSObject *obj); |
michael@0 | 99 | |
michael@0 | 100 | void nuke(BaseProxyHandler *handler); |
michael@0 | 101 | |
michael@0 | 102 | static const Class callableClass_; |
michael@0 | 103 | static const Class uncallableClass_; |
michael@0 | 104 | }; |
michael@0 | 105 | |
michael@0 | 106 | } // namespace js |
michael@0 | 107 | |
michael@0 | 108 | // Note: the following |JSObject::is<T>| methods are implemented in terms of |
michael@0 | 109 | // the Is*Proxy() friend API functions to ensure the implementations are tied |
michael@0 | 110 | // together. The exception is |JSObject::is<js::OuterWindowProxyObject>() |
michael@0 | 111 | // const|, which uses the standard template definition, because there is no |
michael@0 | 112 | // IsOuterWindowProxy() function in the friend API. |
michael@0 | 113 | |
michael@0 | 114 | template<> |
michael@0 | 115 | inline bool |
michael@0 | 116 | JSObject::is<js::ProxyObject>() const |
michael@0 | 117 | { |
michael@0 | 118 | return js::IsProxy(const_cast<JSObject*>(this)); |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | #endif /* vm_ProxyObject_h */ |