chrome/src/nsChromeRegistry.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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

mercurial