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 | #include "nsContentUtils.h" |
michael@0 | 8 | #include "BackstagePass.h" |
michael@0 | 9 | #include "nsIProgrammingLanguage.h" |
michael@0 | 10 | #include "nsDOMClassInfo.h" |
michael@0 | 11 | #include "nsIPrincipal.h" |
michael@0 | 12 | |
michael@0 | 13 | #include "mozilla/dom/workers/Workers.h" |
michael@0 | 14 | |
michael@0 | 15 | using mozilla::dom::workers::ResolveWorkerClasses; |
michael@0 | 16 | |
michael@0 | 17 | NS_INTERFACE_MAP_BEGIN(BackstagePass) |
michael@0 | 18 | NS_INTERFACE_MAP_ENTRY(nsIGlobalObject) |
michael@0 | 19 | NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable) |
michael@0 | 20 | NS_INTERFACE_MAP_ENTRY(nsIClassInfo) |
michael@0 | 21 | NS_INTERFACE_MAP_ENTRY(nsIScriptObjectPrincipal) |
michael@0 | 22 | NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) |
michael@0 | 23 | NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXPCScriptable) |
michael@0 | 24 | NS_INTERFACE_MAP_END |
michael@0 | 25 | |
michael@0 | 26 | NS_IMPL_ADDREF(BackstagePass) |
michael@0 | 27 | NS_IMPL_RELEASE(BackstagePass) |
michael@0 | 28 | |
michael@0 | 29 | // The nsIXPCScriptable map declaration that will generate stubs for us... |
michael@0 | 30 | #define XPC_MAP_CLASSNAME BackstagePass |
michael@0 | 31 | #define XPC_MAP_QUOTED_CLASSNAME "BackstagePass" |
michael@0 | 32 | #define XPC_MAP_WANT_NEWRESOLVE |
michael@0 | 33 | #define XPC_MAP_WANT_FINALIZE |
michael@0 | 34 | #define XPC_MAP_WANT_PRECREATE |
michael@0 | 35 | |
michael@0 | 36 | #define XPC_MAP_FLAGS nsIXPCScriptable::USE_JSSTUB_FOR_ADDPROPERTY | \ |
michael@0 | 37 | nsIXPCScriptable::USE_JSSTUB_FOR_DELPROPERTY | \ |
michael@0 | 38 | nsIXPCScriptable::USE_JSSTUB_FOR_SETPROPERTY | \ |
michael@0 | 39 | nsIXPCScriptable::DONT_ENUM_STATIC_PROPS | \ |
michael@0 | 40 | nsIXPCScriptable::DONT_ENUM_QUERY_INTERFACE | \ |
michael@0 | 41 | nsIXPCScriptable::IS_GLOBAL_OBJECT | \ |
michael@0 | 42 | nsIXPCScriptable::DONT_REFLECT_INTERFACE_NAMES |
michael@0 | 43 | #include "xpc_map_end.h" /* This will #undef the above */ |
michael@0 | 44 | |
michael@0 | 45 | /* bool newResolve (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in jsval id, out JSObjectPtr objp); */ |
michael@0 | 46 | NS_IMETHODIMP |
michael@0 | 47 | BackstagePass::NewResolve(nsIXPConnectWrappedNative *wrapper, |
michael@0 | 48 | JSContext * cx, JSObject * objArg, |
michael@0 | 49 | jsid idArg, JSObject * *objpArg, |
michael@0 | 50 | bool *_retval) |
michael@0 | 51 | { |
michael@0 | 52 | JS::RootedObject obj(cx, objArg); |
michael@0 | 53 | JS::RootedId id(cx, idArg); |
michael@0 | 54 | |
michael@0 | 55 | bool resolved; |
michael@0 | 56 | *objpArg = nullptr; |
michael@0 | 57 | |
michael@0 | 58 | *_retval = !!JS_ResolveStandardClass(cx, obj, id, &resolved); |
michael@0 | 59 | NS_ENSURE_TRUE(*_retval, NS_ERROR_FAILURE); |
michael@0 | 60 | |
michael@0 | 61 | if (resolved) { |
michael@0 | 62 | *objpArg = obj; |
michael@0 | 63 | return NS_OK; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | JS::RootedObject objp(cx, *objpArg); |
michael@0 | 67 | |
michael@0 | 68 | *_retval = ResolveWorkerClasses(cx, obj, id, &objp); |
michael@0 | 69 | NS_ENSURE_TRUE(*_retval, NS_ERROR_FAILURE); |
michael@0 | 70 | |
michael@0 | 71 | if (objp) { |
michael@0 | 72 | *objpArg = objp; |
michael@0 | 73 | return NS_OK; |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | return NS_OK; |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | /***************************************************************************/ |
michael@0 | 80 | /* void getInterfaces (out uint32_t count, [array, size_is (count), retval] |
michael@0 | 81 | out nsIIDPtr array); */ |
michael@0 | 82 | NS_IMETHODIMP |
michael@0 | 83 | BackstagePass::GetInterfaces(uint32_t *aCount, nsIID * **aArray) |
michael@0 | 84 | { |
michael@0 | 85 | const uint32_t count = 2; |
michael@0 | 86 | *aCount = count; |
michael@0 | 87 | nsIID **array; |
michael@0 | 88 | *aArray = array = static_cast<nsIID**>(nsMemory::Alloc(count * sizeof(nsIID*))); |
michael@0 | 89 | if (!array) |
michael@0 | 90 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 91 | |
michael@0 | 92 | uint32_t index = 0; |
michael@0 | 93 | nsIID* clone; |
michael@0 | 94 | #define PUSH_IID(id) \ |
michael@0 | 95 | clone = static_cast<nsIID *>(nsMemory::Clone(&NS_GET_IID( id ), \ |
michael@0 | 96 | sizeof(nsIID))); \ |
michael@0 | 97 | if (!clone) \ |
michael@0 | 98 | goto oom; \ |
michael@0 | 99 | array[index++] = clone; |
michael@0 | 100 | |
michael@0 | 101 | PUSH_IID(nsIXPCScriptable) |
michael@0 | 102 | PUSH_IID(nsIScriptObjectPrincipal) |
michael@0 | 103 | #undef PUSH_IID |
michael@0 | 104 | |
michael@0 | 105 | return NS_OK; |
michael@0 | 106 | oom: |
michael@0 | 107 | while (index) |
michael@0 | 108 | nsMemory::Free(array[--index]); |
michael@0 | 109 | nsMemory::Free(array); |
michael@0 | 110 | *aArray = nullptr; |
michael@0 | 111 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | /* nsISupports getHelperForLanguage (in uint32_t language); */ |
michael@0 | 115 | NS_IMETHODIMP |
michael@0 | 116 | BackstagePass::GetHelperForLanguage(uint32_t language, |
michael@0 | 117 | nsISupports **retval) |
michael@0 | 118 | { |
michael@0 | 119 | nsCOMPtr<nsISupports> supports = |
michael@0 | 120 | do_QueryInterface(static_cast<nsIGlobalObject *>(this)); |
michael@0 | 121 | supports.forget(retval); |
michael@0 | 122 | return NS_OK; |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | /* readonly attribute string contractID; */ |
michael@0 | 126 | NS_IMETHODIMP |
michael@0 | 127 | BackstagePass::GetContractID(char * *aContractID) |
michael@0 | 128 | { |
michael@0 | 129 | *aContractID = nullptr; |
michael@0 | 130 | return NS_ERROR_NOT_AVAILABLE; |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | /* readonly attribute string classDescription; */ |
michael@0 | 134 | NS_IMETHODIMP |
michael@0 | 135 | BackstagePass::GetClassDescription(char * *aClassDescription) |
michael@0 | 136 | { |
michael@0 | 137 | static const char classDescription[] = "BackstagePass"; |
michael@0 | 138 | *aClassDescription = (char*)nsMemory::Clone(classDescription, sizeof(classDescription)); |
michael@0 | 139 | return *aClassDescription ? NS_OK : NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | /* readonly attribute nsCIDPtr classID; */ |
michael@0 | 143 | NS_IMETHODIMP |
michael@0 | 144 | BackstagePass::GetClassID(nsCID * *aClassID) |
michael@0 | 145 | { |
michael@0 | 146 | *aClassID = nullptr; |
michael@0 | 147 | return NS_OK; |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | /* readonly attribute uint32_t implementationLanguage; */ |
michael@0 | 151 | NS_IMETHODIMP |
michael@0 | 152 | BackstagePass::GetImplementationLanguage(uint32_t *aImplementationLanguage) |
michael@0 | 153 | { |
michael@0 | 154 | *aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS; |
michael@0 | 155 | return NS_OK; |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | /* readonly attribute uint32_t flags; */ |
michael@0 | 159 | NS_IMETHODIMP |
michael@0 | 160 | BackstagePass::GetFlags(uint32_t *aFlags) |
michael@0 | 161 | { |
michael@0 | 162 | *aFlags = nsIClassInfo::MAIN_THREAD_ONLY; |
michael@0 | 163 | return NS_OK; |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | /* [notxpcom] readonly attribute nsCID classIDNoAlloc; */ |
michael@0 | 167 | NS_IMETHODIMP |
michael@0 | 168 | BackstagePass::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc) |
michael@0 | 169 | { |
michael@0 | 170 | return NS_ERROR_NOT_AVAILABLE; |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | NS_IMETHODIMP |
michael@0 | 174 | BackstagePass::Finalize(nsIXPConnectWrappedNative *wrapper, JSFreeOp * fop, JSObject * obj) |
michael@0 | 175 | { |
michael@0 | 176 | nsCOMPtr<nsIGlobalObject> bsp(do_QueryWrappedNative(wrapper)); |
michael@0 | 177 | MOZ_ASSERT(bsp); |
michael@0 | 178 | static_cast<BackstagePass*>(bsp.get())->ForgetGlobalObject(); |
michael@0 | 179 | return NS_OK; |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | NS_IMETHODIMP |
michael@0 | 183 | BackstagePass::PreCreate(nsISupports *nativeObj, JSContext *cx, |
michael@0 | 184 | JSObject *globalObj, JSObject **parentObj) |
michael@0 | 185 | { |
michael@0 | 186 | // We do the same trick here as for WindowSH. Return the js global |
michael@0 | 187 | // as parent, so XPConenct can find the right scope and the wrapper |
michael@0 | 188 | // that already exists. |
michael@0 | 189 | nsCOMPtr<nsIGlobalObject> global(do_QueryInterface(nativeObj)); |
michael@0 | 190 | MOZ_ASSERT(global, "nativeObj not a global object!"); |
michael@0 | 191 | |
michael@0 | 192 | JSObject *jsglobal = global->GetGlobalJSObject(); |
michael@0 | 193 | if (jsglobal) |
michael@0 | 194 | *parentObj = jsglobal; |
michael@0 | 195 | return NS_OK; |
michael@0 | 196 | } |
michael@0 | 197 | |
michael@0 | 198 | nsresult |
michael@0 | 199 | NS_NewBackstagePass(BackstagePass** ret) |
michael@0 | 200 | { |
michael@0 | 201 | nsRefPtr<BackstagePass> bsp = new BackstagePass( |
michael@0 | 202 | nsContentUtils::GetSystemPrincipal()); |
michael@0 | 203 | bsp.forget(ret); |
michael@0 | 204 | return NS_OK; |
michael@0 | 205 | } |