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