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: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
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 "xpcprivate.h" |
michael@0 | 8 | #include "XPCWrapper.h" |
michael@0 | 9 | #include "WrapperFactory.h" |
michael@0 | 10 | #include "AccessCheck.h" |
michael@0 | 11 | |
michael@0 | 12 | using namespace xpc; |
michael@0 | 13 | using namespace mozilla; |
michael@0 | 14 | |
michael@0 | 15 | namespace XPCNativeWrapper { |
michael@0 | 16 | |
michael@0 | 17 | static inline |
michael@0 | 18 | bool |
michael@0 | 19 | ThrowException(nsresult ex, JSContext *cx) |
michael@0 | 20 | { |
michael@0 | 21 | XPCThrower::Throw(ex, cx); |
michael@0 | 22 | |
michael@0 | 23 | return false; |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | static bool |
michael@0 | 27 | UnwrapNW(JSContext *cx, unsigned argc, jsval *vp) |
michael@0 | 28 | { |
michael@0 | 29 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
michael@0 | 30 | if (args.length() != 1) { |
michael@0 | 31 | return ThrowException(NS_ERROR_XPC_NOT_ENOUGH_ARGS, cx); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | JS::RootedValue v(cx, args[0]); |
michael@0 | 35 | if (!v.isObject() || !js::IsWrapper(&v.toObject())) { |
michael@0 | 36 | args.rval().set(v); |
michael@0 | 37 | return true; |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | if (AccessCheck::wrapperSubsumes(&v.toObject())) { |
michael@0 | 41 | bool ok = xpc::WrapperFactory::WaiveXrayAndWrap(cx, &v); |
michael@0 | 42 | NS_ENSURE_TRUE(ok, false); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | args.rval().set(v); |
michael@0 | 46 | return true; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | static bool |
michael@0 | 50 | XrayWrapperConstructor(JSContext *cx, unsigned argc, jsval *vp) |
michael@0 | 51 | { |
michael@0 | 52 | JS::CallArgs args = CallArgsFromVp(argc, vp); |
michael@0 | 53 | if (args.length() == 0) { |
michael@0 | 54 | return ThrowException(NS_ERROR_XPC_NOT_ENOUGH_ARGS, cx); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | if (!args[0].isObject()) { |
michael@0 | 58 | args.rval().set(args[0]); |
michael@0 | 59 | return true; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | args.rval().setObject(*js::UncheckedUnwrap(&args[0].toObject())); |
michael@0 | 63 | return JS_WrapValue(cx, args.rval()); |
michael@0 | 64 | } |
michael@0 | 65 | // static |
michael@0 | 66 | bool |
michael@0 | 67 | AttachNewConstructorObject(JSContext *aCx, JS::HandleObject aGlobalObject) |
michael@0 | 68 | { |
michael@0 | 69 | // Pushing a JSContext calls ActivateDebugger which calls this function, so |
michael@0 | 70 | // we can't use an AutoJSContext here until JSD is gone. |
michael@0 | 71 | JSAutoCompartment ac(aCx, aGlobalObject); |
michael@0 | 72 | JSFunction *xpcnativewrapper = |
michael@0 | 73 | JS_DefineFunction(aCx, aGlobalObject, "XPCNativeWrapper", |
michael@0 | 74 | XrayWrapperConstructor, 1, |
michael@0 | 75 | JSPROP_READONLY | JSPROP_PERMANENT | JSFUN_STUB_GSOPS | JSFUN_CONSTRUCTOR); |
michael@0 | 76 | if (!xpcnativewrapper) { |
michael@0 | 77 | return false; |
michael@0 | 78 | } |
michael@0 | 79 | JS::RootedObject obj(aCx, JS_GetFunctionObject(xpcnativewrapper)); |
michael@0 | 80 | return JS_DefineFunction(aCx, obj, "unwrap", UnwrapNW, 1, |
michael@0 | 81 | JSPROP_READONLY | JSPROP_PERMANENT) != nullptr; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | } // namespace XPCNativeWrapper |
michael@0 | 85 | |
michael@0 | 86 | namespace XPCWrapper { |
michael@0 | 87 | |
michael@0 | 88 | JSObject * |
michael@0 | 89 | UnsafeUnwrapSecurityWrapper(JSObject *obj) |
michael@0 | 90 | { |
michael@0 | 91 | if (js::IsProxy(obj)) { |
michael@0 | 92 | return js::UncheckedUnwrap(obj); |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | return obj; |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | } // namespace XPCWrapper |