Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
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 "JSDebugger.h" |
michael@0 | 7 | #include "nsIXPConnect.h" |
michael@0 | 8 | #include "nsThreadUtils.h" |
michael@0 | 9 | #include "jsapi.h" |
michael@0 | 10 | #include "jsfriendapi.h" |
michael@0 | 11 | #include "jswrapper.h" |
michael@0 | 12 | #include "js/OldDebugAPI.h" |
michael@0 | 13 | #include "mozilla/ModuleUtils.h" |
michael@0 | 14 | #include "nsServiceManagerUtils.h" |
michael@0 | 15 | #include "nsMemory.h" |
michael@0 | 16 | |
michael@0 | 17 | #define JSDEBUGGER_CONTRACTID \ |
michael@0 | 18 | "@mozilla.org/jsdebugger;1" |
michael@0 | 19 | |
michael@0 | 20 | #define JSDEBUGGER_CID \ |
michael@0 | 21 | { 0x0365cbd5, 0xd46e, 0x4e94, { 0xa3, 0x9f, 0x83, 0xb6, 0x3c, 0xd1, 0xa9, 0x63 } } |
michael@0 | 22 | |
michael@0 | 23 | namespace mozilla { |
michael@0 | 24 | namespace jsdebugger { |
michael@0 | 25 | |
michael@0 | 26 | NS_GENERIC_FACTORY_CONSTRUCTOR(JSDebugger) |
michael@0 | 27 | |
michael@0 | 28 | NS_IMPL_ISUPPORTS(JSDebugger, IJSDebugger) |
michael@0 | 29 | |
michael@0 | 30 | JSDebugger::JSDebugger() |
michael@0 | 31 | { |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | JSDebugger::~JSDebugger() |
michael@0 | 35 | { |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | NS_IMETHODIMP |
michael@0 | 39 | JSDebugger::AddClass(JS::Handle<JS::Value> global, JSContext* cx) |
michael@0 | 40 | { |
michael@0 | 41 | nsresult rv; |
michael@0 | 42 | nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID(), &rv); |
michael@0 | 43 | |
michael@0 | 44 | if (!global.isObject()) { |
michael@0 | 45 | return NS_ERROR_INVALID_ARG; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | JS::RootedObject obj(cx, &global.toObject()); |
michael@0 | 49 | obj = js::UncheckedUnwrap(obj, /* stopAtOuter = */ false); |
michael@0 | 50 | if (!obj) { |
michael@0 | 51 | return NS_ERROR_FAILURE; |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | JSAutoCompartment ac(cx, obj); |
michael@0 | 55 | if (JS_GetGlobalForObject(cx, obj) != obj) { |
michael@0 | 56 | return NS_ERROR_INVALID_ARG; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | if (!JS_DefineDebuggerObject(cx, obj)) { |
michael@0 | 60 | return NS_ERROR_FAILURE; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | return NS_OK; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | } |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | NS_DEFINE_NAMED_CID(JSDEBUGGER_CID); |
michael@0 | 70 | |
michael@0 | 71 | static const mozilla::Module::CIDEntry kJSDebuggerCIDs[] = { |
michael@0 | 72 | { &kJSDEBUGGER_CID, false, nullptr, mozilla::jsdebugger::JSDebuggerConstructor }, |
michael@0 | 73 | { nullptr } |
michael@0 | 74 | }; |
michael@0 | 75 | |
michael@0 | 76 | static const mozilla::Module::ContractIDEntry kJSDebuggerContracts[] = { |
michael@0 | 77 | { JSDEBUGGER_CONTRACTID, &kJSDEBUGGER_CID }, |
michael@0 | 78 | { nullptr } |
michael@0 | 79 | }; |
michael@0 | 80 | |
michael@0 | 81 | static const mozilla::Module kJSDebuggerModule = { |
michael@0 | 82 | mozilla::Module::kVersion, |
michael@0 | 83 | kJSDebuggerCIDs, |
michael@0 | 84 | kJSDebuggerContracts |
michael@0 | 85 | }; |
michael@0 | 86 | |
michael@0 | 87 | NSMODULE_DEFN(jsdebugger) = &kJSDebuggerModule; |