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.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "JSDebugger.h"
7 #include "nsIXPConnect.h"
8 #include "nsThreadUtils.h"
9 #include "jsapi.h"
10 #include "jsfriendapi.h"
11 #include "jswrapper.h"
12 #include "js/OldDebugAPI.h"
13 #include "mozilla/ModuleUtils.h"
14 #include "nsServiceManagerUtils.h"
15 #include "nsMemory.h"
17 #define JSDEBUGGER_CONTRACTID \
18 "@mozilla.org/jsdebugger;1"
20 #define JSDEBUGGER_CID \
21 { 0x0365cbd5, 0xd46e, 0x4e94, { 0xa3, 0x9f, 0x83, 0xb6, 0x3c, 0xd1, 0xa9, 0x63 } }
23 namespace mozilla {
24 namespace jsdebugger {
26 NS_GENERIC_FACTORY_CONSTRUCTOR(JSDebugger)
28 NS_IMPL_ISUPPORTS(JSDebugger, IJSDebugger)
30 JSDebugger::JSDebugger()
31 {
32 }
34 JSDebugger::~JSDebugger()
35 {
36 }
38 NS_IMETHODIMP
39 JSDebugger::AddClass(JS::Handle<JS::Value> global, JSContext* cx)
40 {
41 nsresult rv;
42 nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID(), &rv);
44 if (!global.isObject()) {
45 return NS_ERROR_INVALID_ARG;
46 }
48 JS::RootedObject obj(cx, &global.toObject());
49 obj = js::UncheckedUnwrap(obj, /* stopAtOuter = */ false);
50 if (!obj) {
51 return NS_ERROR_FAILURE;
52 }
54 JSAutoCompartment ac(cx, obj);
55 if (JS_GetGlobalForObject(cx, obj) != obj) {
56 return NS_ERROR_INVALID_ARG;
57 }
59 if (!JS_DefineDebuggerObject(cx, obj)) {
60 return NS_ERROR_FAILURE;
61 }
63 return NS_OK;
64 }
66 }
67 }
69 NS_DEFINE_NAMED_CID(JSDEBUGGER_CID);
71 static const mozilla::Module::CIDEntry kJSDebuggerCIDs[] = {
72 { &kJSDEBUGGER_CID, false, nullptr, mozilla::jsdebugger::JSDebuggerConstructor },
73 { nullptr }
74 };
76 static const mozilla::Module::ContractIDEntry kJSDebuggerContracts[] = {
77 { JSDEBUGGER_CONTRACTID, &kJSDEBUGGER_CID },
78 { nullptr }
79 };
81 static const mozilla::Module kJSDebuggerModule = {
82 mozilla::Module::kVersion,
83 kJSDebuggerCIDs,
84 kJSDebuggerContracts
85 };
87 NSMODULE_DEFN(jsdebugger) = &kJSDebuggerModule;