nsChromeRegistry.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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/. */
  5. #ifndef nsChromeRegistry_h
  6. #define nsChromeRegistry_h
  7. #include "nsIToolkitChromeRegistry.h"
  8. #include "nsIObserver.h"
  9. #include "nsWeakReference.h"
  10. #ifdef MOZ_XUL
  11. #include "nsIXULOverlayProvider.h"
  12. #endif
  13. #include "nsString.h"
  14. #include "nsURIHashKey.h"
  15. #include "nsInterfaceHashtable.h"
  16. #include "nsXULAppAPI.h"
  17. #include "nsIXPConnect.h"
  18. #include "mozilla/FileLocation.h"
  19. class nsPIDOMWindowOuter;
  20. class nsIPrefBranch;
  21. class nsIURL;
  22. // The chrome registry is actually split between nsChromeRegistryChrome and
  23. // nsChromeRegistryContent. The work/data that is common to both resides in
  24. // the shared nsChromeRegistry implementation, with operations that only make
  25. // sense for one side erroring out in the other.
  26. // for component registration
  27. // {47049e42-1d87-482a-984d-56ae185e367a}
  28. #define NS_CHROMEREGISTRY_CID \
  29. { 0x47049e42, 0x1d87, 0x482a, { 0x98, 0x4d, 0x56, 0xae, 0x18, 0x5e, 0x36, 0x7a } }
  30. class nsChromeRegistry : public nsIToolkitChromeRegistry,
  31. #ifdef MOZ_XUL
  32. public nsIXULOverlayProvider,
  33. #endif
  34. public nsIObserver,
  35. public nsSupportsWeakReference
  36. {
  37. public:
  38. NS_DECL_ISUPPORTS
  39. // nsIXULChromeRegistry methods:
  40. NS_IMETHOD ReloadChrome() override;
  41. NS_IMETHOD RefreshSkins() override;
  42. NS_IMETHOD AllowScriptsForPackage(nsIURI* url,
  43. bool* _retval) override;
  44. NS_IMETHOD AllowContentToAccess(nsIURI* url,
  45. bool* _retval) override;
  46. NS_IMETHOD CanLoadURLRemotely(nsIURI* url,
  47. bool* _retval) override;
  48. NS_IMETHOD MustLoadURLRemotely(nsIURI* url,
  49. bool* _retval) override;
  50. // nsIChromeRegistry methods:
  51. NS_IMETHOD_(bool) WrappersEnabled(nsIURI *aURI) override;
  52. NS_IMETHOD ConvertChromeURL(nsIURI* aChromeURI, nsIURI* *aResult) override;
  53. // nsChromeRegistry methods:
  54. nsChromeRegistry() : mInitialized(false) { }
  55. virtual nsresult Init();
  56. static already_AddRefed<nsIChromeRegistry> GetService();
  57. static nsChromeRegistry* gChromeRegistry;
  58. static nsresult Canonify(nsIURL* aChromeURL);
  59. protected:
  60. virtual ~nsChromeRegistry();
  61. void FlushSkinCaches();
  62. void FlushAllCaches();
  63. // Update the selected locale used by the chrome registry, and fire a
  64. // notification about this change
  65. virtual nsresult UpdateSelectedLocale() = 0;
  66. static void LogMessage(const char* aMsg, ...);
  67. static void LogMessageWithContext(nsIURI* aURL, uint32_t aLineNumber, uint32_t flags,
  68. const char* aMsg, ...);
  69. virtual nsIURI* GetBaseURIFromPackage(const nsCString& aPackage,
  70. const nsCString& aProvider,
  71. const nsCString& aPath) = 0;
  72. virtual nsresult GetFlagsFromPackage(const nsCString& aPackage,
  73. uint32_t* aFlags) = 0;
  74. nsresult SelectLocaleFromPref(nsIPrefBranch* prefs);
  75. static nsresult RefreshWindow(nsPIDOMWindowOuter* aWindow);
  76. static nsresult GetProviderAndPath(nsIURL* aChromeURL,
  77. nsACString& aProvider, nsACString& aPath);
  78. bool GetDirectionForLocale(const nsACString& aLocale);
  79. void SanitizeForBCP47(nsACString& aLocale);
  80. public:
  81. static already_AddRefed<nsChromeRegistry> GetSingleton();
  82. struct ManifestProcessingContext
  83. {
  84. ManifestProcessingContext(NSLocationType aType, mozilla::FileLocation &aFile)
  85. : mType(aType)
  86. , mFile(aFile)
  87. { }
  88. ~ManifestProcessingContext()
  89. { }
  90. nsIURI* GetManifestURI();
  91. nsIXPConnect* GetXPConnect();
  92. already_AddRefed<nsIURI> ResolveURI(const char* uri);
  93. NSLocationType mType;
  94. mozilla::FileLocation mFile;
  95. nsCOMPtr<nsIURI> mManifestURI;
  96. nsCOMPtr<nsIXPConnect> mXPConnect;
  97. };
  98. virtual void ManifestContent(ManifestProcessingContext& cx, int lineno,
  99. char *const * argv, int flags) = 0;
  100. virtual void ManifestLocale(ManifestProcessingContext& cx, int lineno,
  101. char *const * argv, int flags) = 0;
  102. virtual void ManifestSkin(ManifestProcessingContext& cx, int lineno,
  103. char *const * argv, int flags) = 0;
  104. virtual void ManifestOverlay(ManifestProcessingContext& cx, int lineno,
  105. char *const * argv, int flags) = 0;
  106. virtual void ManifestStyle(ManifestProcessingContext& cx, int lineno,
  107. char *const * argv, int flags) = 0;
  108. virtual void ManifestOverride(ManifestProcessingContext& cx, int lineno,
  109. char *const * argv, int flags) = 0;
  110. virtual void ManifestResource(ManifestProcessingContext& cx, int lineno,
  111. char *const * argv, int flags) = 0;
  112. // Available flags
  113. enum {
  114. // This is a "platform" package (e.g. chrome://global-platform/).
  115. // Appends one of win/ unix/ mac/ to the base URI.
  116. PLATFORM_PACKAGE = 1 << 0,
  117. // This package should use the new XPCNativeWrappers to separate
  118. // content from chrome. This flag is currently unused (because we call
  119. // into xpconnect at registration time).
  120. XPCNATIVEWRAPPERS = 1 << 1,
  121. // Content script may access files in this package
  122. CONTENT_ACCESSIBLE = 1 << 2,
  123. // Package may be loaded remotely
  124. REMOTE_ALLOWED = 1 << 3,
  125. // Package must be loaded remotely
  126. REMOTE_REQUIRED = 1 << 4,
  127. };
  128. bool mInitialized;
  129. // "Override" table (chrome URI string -> real URI)
  130. nsInterfaceHashtable<nsURIHashKey, nsIURI> mOverrideTable;
  131. };
  132. #endif // nsChromeRegistry_h