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: 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 | |
michael@0 | 6 | #include "nsJSInspector.h" |
michael@0 | 7 | #include "nsIXPConnect.h" |
michael@0 | 8 | #include "nsThreadUtils.h" |
michael@0 | 9 | #include "jsfriendapi.h" |
michael@0 | 10 | #include "js/OldDebugAPI.h" |
michael@0 | 11 | #include "mozilla/HoldDropJSObjects.h" |
michael@0 | 12 | #include "mozilla/ModuleUtils.h" |
michael@0 | 13 | #include "mozilla/dom/ScriptSettings.h" |
michael@0 | 14 | #include "nsServiceManagerUtils.h" |
michael@0 | 15 | #include "nsMemory.h" |
michael@0 | 16 | #include "nsArray.h" |
michael@0 | 17 | #include "nsTArray.h" |
michael@0 | 18 | |
michael@0 | 19 | #define JSINSPECTOR_CONTRACTID \ |
michael@0 | 20 | "@mozilla.org/jsinspector;1" |
michael@0 | 21 | |
michael@0 | 22 | #define JSINSPECTOR_CID \ |
michael@0 | 23 | { 0xec5aa99c, 0x7abb, 0x4142, { 0xac, 0x5f, 0xaa, 0xb2, 0x41, 0x9e, 0x38, 0xe2 } } |
michael@0 | 24 | |
michael@0 | 25 | namespace mozilla { |
michael@0 | 26 | namespace jsinspector { |
michael@0 | 27 | |
michael@0 | 28 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsJSInspector) |
michael@0 | 29 | |
michael@0 | 30 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsJSInspector) |
michael@0 | 31 | NS_INTERFACE_MAP_ENTRY(nsISupports) |
michael@0 | 32 | NS_INTERFACE_MAP_ENTRY(nsIJSInspector) |
michael@0 | 33 | NS_INTERFACE_MAP_END |
michael@0 | 34 | |
michael@0 | 35 | NS_IMPL_CYCLE_COLLECTION_CLASS(nsJSInspector) |
michael@0 | 36 | |
michael@0 | 37 | NS_IMPL_CYCLE_COLLECTING_ADDREF(nsJSInspector) |
michael@0 | 38 | NS_IMPL_CYCLE_COLLECTING_RELEASE(nsJSInspector) |
michael@0 | 39 | |
michael@0 | 40 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsJSInspector) |
michael@0 | 41 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS |
michael@0 | 42 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END |
michael@0 | 43 | |
michael@0 | 44 | NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsJSInspector) |
michael@0 | 45 | tmp->mRequestors.Clear(); |
michael@0 | 46 | tmp->mLastRequestor = JS::NullValue(); |
michael@0 | 47 | NS_IMPL_CYCLE_COLLECTION_UNLINK_END |
michael@0 | 48 | |
michael@0 | 49 | NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsJSInspector) |
michael@0 | 50 | for (uint32_t i = 0; i < tmp->mRequestors.Length(); ++i) { |
michael@0 | 51 | NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(mRequestors[i]) |
michael@0 | 52 | } |
michael@0 | 53 | NS_IMPL_CYCLE_COLLECTION_TRACE_JSVAL_MEMBER_CALLBACK(mLastRequestor) |
michael@0 | 54 | NS_IMPL_CYCLE_COLLECTION_TRACE_END |
michael@0 | 55 | |
michael@0 | 56 | nsJSInspector::nsJSInspector() : mNestedLoopLevel(0), mRequestors(1), mLastRequestor(JSVAL_NULL) |
michael@0 | 57 | { |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | nsJSInspector::~nsJSInspector() |
michael@0 | 61 | { |
michael@0 | 62 | MOZ_ASSERT(mRequestors.Length() == 0); |
michael@0 | 63 | MOZ_ASSERT(mLastRequestor.isNull()); |
michael@0 | 64 | mozilla::DropJSObjects(this); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | NS_IMETHODIMP |
michael@0 | 68 | nsJSInspector::EnterNestedEventLoop(JS::Handle<JS::Value> requestor, uint32_t *out) |
michael@0 | 69 | { |
michael@0 | 70 | nsresult rv = NS_OK; |
michael@0 | 71 | |
michael@0 | 72 | mLastRequestor = requestor; |
michael@0 | 73 | mRequestors.AppendElement(requestor); |
michael@0 | 74 | mozilla::HoldJSObjects(this); |
michael@0 | 75 | |
michael@0 | 76 | mozilla::dom::AutoNoJSAPI nojsapi; |
michael@0 | 77 | |
michael@0 | 78 | uint32_t nestLevel = ++mNestedLoopLevel; |
michael@0 | 79 | while (NS_SUCCEEDED(rv) && mNestedLoopLevel >= nestLevel) { |
michael@0 | 80 | if (!NS_ProcessNextEvent()) |
michael@0 | 81 | rv = NS_ERROR_UNEXPECTED; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | NS_ASSERTION(mNestedLoopLevel <= nestLevel, |
michael@0 | 85 | "nested event didn't unwind properly"); |
michael@0 | 86 | |
michael@0 | 87 | if (mNestedLoopLevel == nestLevel) { |
michael@0 | 88 | mLastRequestor = mRequestors.ElementAt(--mNestedLoopLevel); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | *out = mNestedLoopLevel; |
michael@0 | 92 | return rv; |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | NS_IMETHODIMP |
michael@0 | 96 | nsJSInspector::ExitNestedEventLoop(uint32_t *out) |
michael@0 | 97 | { |
michael@0 | 98 | if (mNestedLoopLevel > 0) { |
michael@0 | 99 | mRequestors.RemoveElementAt(--mNestedLoopLevel); |
michael@0 | 100 | if (mNestedLoopLevel > 0) |
michael@0 | 101 | mLastRequestor = mRequestors.ElementAt(mNestedLoopLevel - 1); |
michael@0 | 102 | else |
michael@0 | 103 | mLastRequestor = JSVAL_NULL; |
michael@0 | 104 | } else { |
michael@0 | 105 | return NS_ERROR_FAILURE; |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | *out = mNestedLoopLevel; |
michael@0 | 109 | |
michael@0 | 110 | return NS_OK; |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | NS_IMETHODIMP |
michael@0 | 114 | nsJSInspector::GetEventLoopNestLevel(uint32_t *out) |
michael@0 | 115 | { |
michael@0 | 116 | *out = mNestedLoopLevel; |
michael@0 | 117 | return NS_OK; |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | NS_IMETHODIMP |
michael@0 | 121 | nsJSInspector::GetLastNestRequestor(JS::MutableHandle<JS::Value> out) |
michael@0 | 122 | { |
michael@0 | 123 | out.set(mLastRequestor); |
michael@0 | 124 | return NS_OK; |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | } |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | NS_DEFINE_NAMED_CID(JSINSPECTOR_CID); |
michael@0 | 131 | |
michael@0 | 132 | static const mozilla::Module::CIDEntry kJSInspectorCIDs[] = { |
michael@0 | 133 | { &kJSINSPECTOR_CID, false, nullptr, mozilla::jsinspector::nsJSInspectorConstructor }, |
michael@0 | 134 | { nullptr } |
michael@0 | 135 | }; |
michael@0 | 136 | |
michael@0 | 137 | static const mozilla::Module::ContractIDEntry kJSInspectorContracts[] = { |
michael@0 | 138 | { JSINSPECTOR_CONTRACTID, &kJSINSPECTOR_CID }, |
michael@0 | 139 | { nullptr } |
michael@0 | 140 | }; |
michael@0 | 141 | |
michael@0 | 142 | static const mozilla::Module kJSInspectorModule = { |
michael@0 | 143 | mozilla::Module::kVersion, |
michael@0 | 144 | kJSInspectorCIDs, |
michael@0 | 145 | kJSInspectorContracts |
michael@0 | 146 | }; |
michael@0 | 147 | |
michael@0 | 148 | NSMODULE_DEFN(jsinspector) = &kJSInspectorModule; |