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 | |
michael@0 | 2 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 3 | * vim: set ts=8 sts=4 et sw=4 tw=99: |
michael@0 | 4 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef vm_SavedStacks_h |
michael@0 | 9 | #define vm_SavedStacks_h |
michael@0 | 10 | |
michael@0 | 11 | #include "jscntxt.h" |
michael@0 | 12 | #include "js/HashTable.h" |
michael@0 | 13 | #include "vm/Stack.h" |
michael@0 | 14 | |
michael@0 | 15 | namespace js { |
michael@0 | 16 | |
michael@0 | 17 | class SavedFrame : public JSObject { |
michael@0 | 18 | friend class SavedStacks; |
michael@0 | 19 | |
michael@0 | 20 | public: |
michael@0 | 21 | static const Class class_; |
michael@0 | 22 | static void finalize(FreeOp *fop, JSObject *obj); |
michael@0 | 23 | |
michael@0 | 24 | // Prototype methods and properties to be exposed to JS. |
michael@0 | 25 | static const JSPropertySpec properties[]; |
michael@0 | 26 | static const JSFunctionSpec methods[]; |
michael@0 | 27 | static bool construct(JSContext *cx, unsigned argc, Value *vp); |
michael@0 | 28 | static bool sourceProperty(JSContext *cx, unsigned argc, Value *vp); |
michael@0 | 29 | static bool lineProperty(JSContext *cx, unsigned argc, Value *vp); |
michael@0 | 30 | static bool columnProperty(JSContext *cx, unsigned argc, Value *vp); |
michael@0 | 31 | static bool functionDisplayNameProperty(JSContext *cx, unsigned argc, Value *vp); |
michael@0 | 32 | static bool parentProperty(JSContext *cx, unsigned argc, Value *vp); |
michael@0 | 33 | static bool toStringMethod(JSContext *cx, unsigned argc, Value *vp); |
michael@0 | 34 | |
michael@0 | 35 | // Convenient getters for SavedFrame's reserved slots for use from C++. |
michael@0 | 36 | JSAtom *getSource(); |
michael@0 | 37 | size_t getLine(); |
michael@0 | 38 | size_t getColumn(); |
michael@0 | 39 | JSAtom *getFunctionDisplayName(); |
michael@0 | 40 | SavedFrame *getParent(); |
michael@0 | 41 | JSPrincipals *getPrincipals(); |
michael@0 | 42 | |
michael@0 | 43 | bool isSelfHosted(); |
michael@0 | 44 | |
michael@0 | 45 | struct Lookup; |
michael@0 | 46 | struct HashPolicy; |
michael@0 | 47 | |
michael@0 | 48 | typedef HashSet<SavedFrame *, |
michael@0 | 49 | HashPolicy, |
michael@0 | 50 | SystemAllocPolicy> Set; |
michael@0 | 51 | |
michael@0 | 52 | private: |
michael@0 | 53 | void initFromLookup(Lookup &lookup); |
michael@0 | 54 | |
michael@0 | 55 | enum { |
michael@0 | 56 | // The reserved slots in the SavedFrame class. |
michael@0 | 57 | JSSLOT_SOURCE, |
michael@0 | 58 | JSSLOT_LINE, |
michael@0 | 59 | JSSLOT_COLUMN, |
michael@0 | 60 | JSSLOT_FUNCTIONDISPLAYNAME, |
michael@0 | 61 | JSSLOT_PARENT, |
michael@0 | 62 | JSSLOT_PRINCIPALS, |
michael@0 | 63 | JSSLOT_PRIVATE_PARENT, |
michael@0 | 64 | |
michael@0 | 65 | // The total number of reserved slots in the SavedFrame class. |
michael@0 | 66 | JSSLOT_COUNT |
michael@0 | 67 | }; |
michael@0 | 68 | |
michael@0 | 69 | // Because we hash the parent pointer, we need to rekey a saved frame |
michael@0 | 70 | // whenever its parent was relocated by the GC. However, the GC doesn't |
michael@0 | 71 | // notify us when this occurs. As a work around, we keep a duplicate copy of |
michael@0 | 72 | // the parent pointer as a private value in a reserved slot. Whenever the |
michael@0 | 73 | // private value parent pointer doesn't match the regular parent pointer, we |
michael@0 | 74 | // know that GC moved the parent and we need to update our private value and |
michael@0 | 75 | // rekey the saved frame in its hash set. These two methods are helpers for |
michael@0 | 76 | // this process. |
michael@0 | 77 | bool parentMoved(); |
michael@0 | 78 | void updatePrivateParent(); |
michael@0 | 79 | |
michael@0 | 80 | static SavedFrame *checkThis(JSContext *cx, CallArgs &args, const char *fnName); |
michael@0 | 81 | }; |
michael@0 | 82 | |
michael@0 | 83 | struct SavedFrame::Lookup { |
michael@0 | 84 | Lookup(JSAtom *source, size_t line, size_t column, JSAtom *functionDisplayName, |
michael@0 | 85 | Handle<SavedFrame*> parent, JSPrincipals *principals) |
michael@0 | 86 | : source(source), |
michael@0 | 87 | line(line), |
michael@0 | 88 | column(column), |
michael@0 | 89 | functionDisplayName(functionDisplayName), |
michael@0 | 90 | parent(parent), |
michael@0 | 91 | principals(principals) |
michael@0 | 92 | { |
michael@0 | 93 | JS_ASSERT(source); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | JSAtom *source; |
michael@0 | 97 | size_t line; |
michael@0 | 98 | size_t column; |
michael@0 | 99 | JSAtom *functionDisplayName; |
michael@0 | 100 | Handle<SavedFrame*> parent; |
michael@0 | 101 | JSPrincipals *principals; |
michael@0 | 102 | }; |
michael@0 | 103 | |
michael@0 | 104 | struct SavedFrame::HashPolicy |
michael@0 | 105 | { |
michael@0 | 106 | typedef SavedFrame::Lookup Lookup; |
michael@0 | 107 | typedef PointerHasher<SavedFrame *, 3> SavedFramePtrHasher; |
michael@0 | 108 | typedef PointerHasher<JSPrincipals *, 3> JSPrincipalsPtrHasher; |
michael@0 | 109 | |
michael@0 | 110 | static HashNumber hash(const Lookup &lookup); |
michael@0 | 111 | static bool match(SavedFrame *existing, const Lookup &lookup); |
michael@0 | 112 | |
michael@0 | 113 | typedef SavedFrame* Key; |
michael@0 | 114 | static void rekey(Key &key, const Key &newKey); |
michael@0 | 115 | }; |
michael@0 | 116 | |
michael@0 | 117 | class SavedStacks { |
michael@0 | 118 | public: |
michael@0 | 119 | SavedStacks() : frames(), savedFrameProto(nullptr) { } |
michael@0 | 120 | |
michael@0 | 121 | bool init(); |
michael@0 | 122 | bool initialized() const { return frames.initialized(); } |
michael@0 | 123 | bool saveCurrentStack(JSContext *cx, MutableHandle<SavedFrame*> frame); |
michael@0 | 124 | void sweep(JSRuntime *rt); |
michael@0 | 125 | uint32_t count(); |
michael@0 | 126 | void clear(); |
michael@0 | 127 | |
michael@0 | 128 | size_t sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf); |
michael@0 | 129 | |
michael@0 | 130 | private: |
michael@0 | 131 | SavedFrame::Set frames; |
michael@0 | 132 | JSObject *savedFrameProto; |
michael@0 | 133 | |
michael@0 | 134 | bool insertFrames(JSContext *cx, ScriptFrameIter &iter, MutableHandle<SavedFrame*> frame); |
michael@0 | 135 | SavedFrame *getOrCreateSavedFrame(JSContext *cx, SavedFrame::Lookup &lookup); |
michael@0 | 136 | // |SavedFrame.prototype| is created lazily and held weakly. It should only |
michael@0 | 137 | // be accessed through this method. |
michael@0 | 138 | JSObject *getOrCreateSavedFramePrototype(JSContext *cx); |
michael@0 | 139 | SavedFrame *createFrameFromLookup(JSContext *cx, SavedFrame::Lookup &lookup); |
michael@0 | 140 | }; |
michael@0 | 141 | |
michael@0 | 142 | } /* namespace js */ |
michael@0 | 143 | |
michael@0 | 144 | #endif /* vm_SavedStacks_h */ |