nsDocShellModule.cpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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/. */
  5. #include "mozilla/ModuleUtils.h"
  6. #include "nsDocShellCID.h"
  7. #include "nsDocShell.h"
  8. #include "nsDefaultURIFixup.h"
  9. #include "nsWebNavigationInfo.h"
  10. #include "nsAboutRedirector.h"
  11. #include "nsCDefaultURIFixup.h"
  12. // uriloader
  13. #include "nsURILoader.h"
  14. #include "nsDocLoader.h"
  15. #include "nsOSHelperAppService.h"
  16. #include "nsExternalProtocolHandler.h"
  17. #include "nsPrefetchService.h"
  18. #include "nsOfflineCacheUpdate.h"
  19. #include "nsLocalHandlerApp.h"
  20. #include "ContentHandlerService.h"
  21. #ifdef MOZ_ENABLE_DBUS
  22. #include "nsDBusHandlerApp.h"
  23. #endif
  24. // session history
  25. #include "nsSHEntry.h"
  26. #include "nsSHEntryShared.h"
  27. #include "nsSHistory.h"
  28. #include "nsSHTransaction.h"
  29. // download history
  30. #include "nsDownloadHistory.h"
  31. using mozilla::dom::ContentHandlerService;
  32. static bool gInitialized = false;
  33. // The one time initialization for this module
  34. static nsresult
  35. Initialize()
  36. {
  37. NS_PRECONDITION(!gInitialized, "docshell module already initialized");
  38. if (gInitialized) {
  39. return NS_OK;
  40. }
  41. gInitialized = true;
  42. nsresult rv = nsSHistory::Startup();
  43. NS_ENSURE_SUCCESS(rv, rv);
  44. return NS_OK;
  45. }
  46. static void
  47. Shutdown()
  48. {
  49. nsSHistory::Shutdown();
  50. nsSHEntryShared::Shutdown();
  51. gInitialized = false;
  52. }
  53. // docshell
  54. NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsDocShell, Init)
  55. NS_GENERIC_FACTORY_CONSTRUCTOR(nsDefaultURIFixup)
  56. NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsWebNavigationInfo, Init)
  57. // uriloader
  58. NS_GENERIC_FACTORY_CONSTRUCTOR(nsURILoader)
  59. NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsDocLoader, Init)
  60. NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsOSHelperAppService, Init)
  61. NS_GENERIC_FACTORY_CONSTRUCTOR(nsExternalProtocolHandler)
  62. NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrefetchService, Init)
  63. NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsOfflineCacheUpdateService,
  64. nsOfflineCacheUpdateService::GetInstance)
  65. NS_GENERIC_FACTORY_CONSTRUCTOR(nsOfflineCacheUpdate)
  66. NS_GENERIC_FACTORY_CONSTRUCTOR(PlatformLocalHandlerApp_t)
  67. #ifdef MOZ_ENABLE_DBUS
  68. NS_GENERIC_FACTORY_CONSTRUCTOR(nsDBusHandlerApp)
  69. #endif
  70. NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(ContentHandlerService, Init)
  71. // session history
  72. NS_GENERIC_FACTORY_CONSTRUCTOR(nsSHEntry)
  73. NS_GENERIC_FACTORY_CONSTRUCTOR(nsSHTransaction)
  74. NS_GENERIC_FACTORY_CONSTRUCTOR(nsSHistory)
  75. // download history
  76. NS_GENERIC_FACTORY_CONSTRUCTOR(nsDownloadHistory)
  77. NS_DEFINE_NAMED_CID(NS_DOCSHELL_CID);
  78. NS_DEFINE_NAMED_CID(NS_DEFAULTURIFIXUP_CID);
  79. NS_DEFINE_NAMED_CID(NS_WEBNAVIGATION_INFO_CID);
  80. NS_DEFINE_NAMED_CID(NS_ABOUT_REDIRECTOR_MODULE_CID);
  81. NS_DEFINE_NAMED_CID(NS_URI_LOADER_CID);
  82. NS_DEFINE_NAMED_CID(NS_DOCUMENTLOADER_SERVICE_CID);
  83. NS_DEFINE_NAMED_CID(NS_EXTERNALHELPERAPPSERVICE_CID);
  84. NS_DEFINE_NAMED_CID(NS_EXTERNALPROTOCOLHANDLER_CID);
  85. NS_DEFINE_NAMED_CID(NS_PREFETCHSERVICE_CID);
  86. NS_DEFINE_NAMED_CID(NS_OFFLINECACHEUPDATESERVICE_CID);
  87. NS_DEFINE_NAMED_CID(NS_OFFLINECACHEUPDATE_CID);
  88. NS_DEFINE_NAMED_CID(NS_LOCALHANDLERAPP_CID);
  89. #ifdef MOZ_ENABLE_DBUS
  90. NS_DEFINE_NAMED_CID(NS_DBUSHANDLERAPP_CID);
  91. #endif
  92. NS_DEFINE_NAMED_CID(NS_SHENTRY_CID);
  93. NS_DEFINE_NAMED_CID(NS_SHTRANSACTION_CID);
  94. NS_DEFINE_NAMED_CID(NS_SHISTORY_CID);
  95. NS_DEFINE_NAMED_CID(NS_SHISTORY_INTERNAL_CID);
  96. NS_DEFINE_NAMED_CID(NS_DOWNLOADHISTORY_CID);
  97. NS_DEFINE_NAMED_CID(NS_CONTENTHANDLERSERVICE_CID);
  98. const mozilla::Module::CIDEntry kDocShellCIDs[] = {
  99. { &kNS_DOCSHELL_CID, false, nullptr, nsDocShellConstructor },
  100. { &kNS_DEFAULTURIFIXUP_CID, false, nullptr, nsDefaultURIFixupConstructor },
  101. { &kNS_WEBNAVIGATION_INFO_CID, false, nullptr, nsWebNavigationInfoConstructor },
  102. { &kNS_ABOUT_REDIRECTOR_MODULE_CID, false, nullptr, nsAboutRedirector::Create },
  103. { &kNS_URI_LOADER_CID, false, nullptr, nsURILoaderConstructor },
  104. { &kNS_DOCUMENTLOADER_SERVICE_CID, false, nullptr, nsDocLoaderConstructor },
  105. { &kNS_EXTERNALHELPERAPPSERVICE_CID, false, nullptr, nsOSHelperAppServiceConstructor },
  106. { &kNS_CONTENTHANDLERSERVICE_CID, false, nullptr, ContentHandlerServiceConstructor,
  107. mozilla::Module::CONTENT_PROCESS_ONLY },
  108. { &kNS_EXTERNALPROTOCOLHANDLER_CID, false, nullptr, nsExternalProtocolHandlerConstructor },
  109. { &kNS_PREFETCHSERVICE_CID, false, nullptr, nsPrefetchServiceConstructor },
  110. { &kNS_OFFLINECACHEUPDATESERVICE_CID, false, nullptr, nsOfflineCacheUpdateServiceConstructor },
  111. { &kNS_OFFLINECACHEUPDATE_CID, false, nullptr, nsOfflineCacheUpdateConstructor },
  112. { &kNS_LOCALHANDLERAPP_CID, false, nullptr, PlatformLocalHandlerApp_tConstructor },
  113. #ifdef MOZ_ENABLE_DBUS
  114. { &kNS_DBUSHANDLERAPP_CID, false, nullptr, nsDBusHandlerAppConstructor },
  115. #endif
  116. { &kNS_SHENTRY_CID, false, nullptr, nsSHEntryConstructor },
  117. { &kNS_SHTRANSACTION_CID, false, nullptr, nsSHTransactionConstructor },
  118. { &kNS_SHISTORY_CID, false, nullptr, nsSHistoryConstructor },
  119. { &kNS_SHISTORY_INTERNAL_CID, false, nullptr, nsSHistoryConstructor },
  120. { &kNS_DOWNLOADHISTORY_CID, false, nullptr, nsDownloadHistoryConstructor },
  121. { nullptr }
  122. };
  123. const mozilla::Module::ContractIDEntry kDocShellContracts[] = {
  124. { "@mozilla.org/docshell;1", &kNS_DOCSHELL_CID },
  125. { NS_URIFIXUP_CONTRACTID, &kNS_DEFAULTURIFIXUP_CID },
  126. { NS_WEBNAVIGATION_INFO_CONTRACTID, &kNS_WEBNAVIGATION_INFO_CID },
  127. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  128. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "about", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  129. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "addons", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  130. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "buildconfig", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  131. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "checkerboard", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  132. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "config", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  133. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "console", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  134. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "credits", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  135. #ifdef MOZ_DEVTOOLS
  136. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "debugging", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  137. #endif
  138. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "license", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  139. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "logo", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  140. #ifdef MOZ_PHOENIX
  141. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "logopage", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  142. #endif
  143. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "memory", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  144. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "mozilla", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  145. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "neterror", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  146. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "networking", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  147. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "newaddon", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  148. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "performance", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  149. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "plugins", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  150. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "serviceworkers", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  151. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "profiles", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  152. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "srcdoc", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  153. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "support", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  154. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "telemetry", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  155. #ifdef MOZ_WEBRTC
  156. { NS_ABOUT_MODULE_CONTRACTID_PREFIX "webrtc", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
  157. #endif
  158. { NS_URI_LOADER_CONTRACTID, &kNS_URI_LOADER_CID },
  159. { NS_DOCUMENTLOADER_SERVICE_CONTRACTID, &kNS_DOCUMENTLOADER_SERVICE_CID },
  160. { NS_HANDLERSERVICE_CONTRACTID, &kNS_CONTENTHANDLERSERVICE_CID, mozilla::Module::CONTENT_PROCESS_ONLY },
  161. { NS_EXTERNALHELPERAPPSERVICE_CONTRACTID, &kNS_EXTERNALHELPERAPPSERVICE_CID },
  162. { NS_EXTERNALPROTOCOLSERVICE_CONTRACTID, &kNS_EXTERNALHELPERAPPSERVICE_CID },
  163. { NS_MIMESERVICE_CONTRACTID, &kNS_EXTERNALHELPERAPPSERVICE_CID },
  164. { NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX"default", &kNS_EXTERNALPROTOCOLHANDLER_CID },
  165. { NS_PREFETCHSERVICE_CONTRACTID, &kNS_PREFETCHSERVICE_CID },
  166. { NS_OFFLINECACHEUPDATESERVICE_CONTRACTID, &kNS_OFFLINECACHEUPDATESERVICE_CID },
  167. { NS_OFFLINECACHEUPDATE_CONTRACTID, &kNS_OFFLINECACHEUPDATE_CID },
  168. { NS_LOCALHANDLERAPP_CONTRACTID, &kNS_LOCALHANDLERAPP_CID },
  169. #ifdef MOZ_ENABLE_DBUS
  170. { NS_DBUSHANDLERAPP_CONTRACTID, &kNS_DBUSHANDLERAPP_CID },
  171. #endif
  172. { NS_SHENTRY_CONTRACTID, &kNS_SHENTRY_CID },
  173. { NS_SHTRANSACTION_CONTRACTID, &kNS_SHTRANSACTION_CID },
  174. { NS_SHISTORY_CONTRACTID, &kNS_SHISTORY_CID },
  175. { NS_SHISTORY_INTERNAL_CONTRACTID, &kNS_SHISTORY_INTERNAL_CID },
  176. { NS_DOWNLOADHISTORY_CONTRACTID, &kNS_DOWNLOADHISTORY_CID },
  177. { nullptr }
  178. };
  179. static const mozilla::Module kDocShellModule = {
  180. mozilla::Module::kVersion,
  181. kDocShellCIDs,
  182. kDocShellContracts,
  183. nullptr,
  184. nullptr,
  185. Initialize,
  186. Shutdown
  187. };
  188. NSMODULE_DEFN(docshell_provider) = &kDocShellModule;