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: 8; 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 #ifndef mozilla_Module_h
7 #define mozilla_Module_h
9 #include "nscore.h"
10 #include "nsID.h"
11 #include "nsIFactory.h"
12 #include "nsCOMPtr.h" // for already_AddRefed
14 namespace mozilla {
16 /**
17 * A module implements one or more XPCOM components. This structure is used
18 * for both binary and script modules, but the registration members
19 * (cids/contractids/categoryentries) are unused for modules which are loaded
20 * via a module loader.
21 */
22 struct Module
23 {
24 static const unsigned int kVersion = 31;
26 struct CIDEntry;
28 typedef already_AddRefed<nsIFactory> (*GetFactoryProcPtr)
29 (const Module& module, const CIDEntry& entry);
31 typedef nsresult (*ConstructorProcPtr)(nsISupports* aOuter,
32 const nsIID& aIID,
33 void** aResult);
35 typedef nsresult (*LoadFuncPtr)();
36 typedef void (*UnloadFuncPtr)();
38 /**
39 * This selector allows CIDEntrys to be marked so that they're only loaded
40 * into certain kinds of processes.
41 */
42 enum ProcessSelector
43 {
44 ANY_PROCESS = 0,
45 MAIN_PROCESS_ONLY,
46 CONTENT_PROCESS_ONLY
47 };
49 /**
50 * The constructor callback is an implementation detail of the default binary
51 * loader and may be null.
52 */
53 struct CIDEntry
54 {
55 const nsCID* cid;
56 bool service;
57 GetFactoryProcPtr getFactoryProc;
58 ConstructorProcPtr constructorProc;
59 ProcessSelector processSelector;
60 };
62 struct ContractIDEntry
63 {
64 const char* contractid;
65 nsID const * cid;
66 ProcessSelector processSelector;
67 };
69 struct CategoryEntry
70 {
71 const char* category;
72 const char* entry;
73 const char* value;
74 };
76 /**
77 * Binary compatibility check, should be kModuleVersion.
78 */
79 unsigned int mVersion;
81 /**
82 * An array of CIDs (class IDs) implemented by this module. The final entry
83 * should be { nullptr }.
84 */
85 const CIDEntry* mCIDs;
87 /**
88 * An array of mappings from contractid to CID. The final entry should
89 * be { nullptr }.
90 */
91 const ContractIDEntry* mContractIDs;
93 /**
94 * An array of category manager entries. The final entry should be
95 * { nullptr }.
96 */
97 const CategoryEntry* mCategoryEntries;
99 /**
100 * When the component manager tries to get the factory for a CID, it first
101 * checks for this module-level getfactory callback. If this function is
102 * not implemented, it checks the CIDEntry getfactory callback. If that is
103 * also nullptr, a generic factory is generated using the CIDEntry
104 * constructor callback which must be non-nullptr.
105 */
106 GetFactoryProcPtr getFactoryProc;
108 /**
109 * Optional Function which are called when this module is loaded and
110 * at shutdown. These are not C++ constructor/destructors to avoid
111 * calling them too early in startup or too late in shutdown.
112 */
113 LoadFuncPtr loadProc;
114 UnloadFuncPtr unloadProc;
115 };
117 } // namespace
119 #if defined(MOZILLA_INTERNAL_API)
120 # define NSMODULE_NAME(_name) _name##_NSModule
121 # define NSMODULE_DECL(_name) extern mozilla::Module const *const NSMODULE_NAME(_name)
122 # define NSMODULE_DEFN(_name) NSMODULE_DECL(_name)
123 #else
124 # define NSMODULE_NAME(_name) NSModule
125 # define NSMODULE_DEFN(_name) extern "C" NS_EXPORT mozilla::Module const *const NSModule
126 #endif
128 #endif // mozilla_Module_h