Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
nsChromeRegistry.cpp File Reference
#include <string.h>
#include "nsArrayEnumerator.h"
#include "nsCOMPtr.h"
#include "nsIChromeRegistry.h"
#include "nsChromeRegistry.h"
#include "nsChromeUIDataSource.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFObserver.h"
#include "nsIRDFRemoteDataSource.h"
#include "nsIRDFXMLSink.h"
#include "rdf.h"
#include "nsIServiceManager.h"
#include "nsIRDFService.h"
#include "nsRDFCID.h"
#include "nsIRDFResource.h"
#include "nsIRDFContainer.h"
#include "nsIRDFContainerUtils.h"
#include "nsHashtable.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsXPIDLString.h"
#include "nsISimpleEnumerator.h"
#include "nsNetUtil.h"
#include "nsIFileChannel.h"
#include "nsIXBLService.h"
#include "nsIDOMWindowInternal.h"
#include "nsIDOMWindowCollection.h"
#include "nsIDOMLocation.h"
#include "nsIWindowMediator.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
#include "nsIStyleSheet.h"
#include "nsICSSLoader.h"
#include "nsICSSStyleSheet.h"
#include "nsIPresShell.h"
#include "nsIDocShell.h"
#include "nsISupportsArray.h"
#include "nsIDocumentObserver.h"
#include "nsIIOService.h"
#include "nsLayoutCID.h"
#include "nsIBindingManager.h"
#include "prio.h"
#include "nsInt64.h"
#include "nsEscape.h"
#include "nsIDirectoryService.h"
#include "nsILocalFile.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsIObserverService.h"
#include "nsIDOMElement.h"
#include "nsIAtom.h"
#include "nsStaticAtom.h"
#include "nsNetCID.h"
#include "nsIJARURI.h"
#include "nsIFileURL.h"
#include "nsIXPConnect.h"

Go to the source code of this file.

Defines

#define kChromeFileName   NS_LITERAL_CSTRING("chrome.rdf")
#define kInstalledChromeFileName   NS_LITERAL_CSTRING("installed-chrome.txt")
#define CHROME_URI   "http://www.mozilla.org/rdf/chrome#"

Functions

static NS_DEFINE_CID (kWindowMediatorCID, NS_WINDOWMEDIATOR_CID)
static NS_DEFINE_CID (kRDFServiceCID, NS_RDFSERVICE_CID)
static NS_DEFINE_CID (kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID)
static NS_DEFINE_CID (kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID)
static NS_DEFINE_CID (kCSSLoaderCID, NS_CSS_LOADER_CID)
 DEFINE_RDF_VOCAB (CHROME_URI, CHROME, selectedSkin)
 DEFINE_RDF_VOCAB (CHROME_URI, CHROME, selectedLocale)
 DEFINE_RDF_VOCAB (CHROME_URI, CHROME, baseURL)
 DEFINE_RDF_VOCAB (CHROME_URI, CHROME, packages)
 DEFINE_RDF_VOCAB (CHROME_URI, CHROME, package)
 DEFINE_RDF_VOCAB (CHROME_URI, CHROME, name)
 DEFINE_RDF_VOCAB (CHROME_URI, CHROME, image)
 DEFINE_RDF_VOCAB (CHROME_URI, CHROME, locType)
 DEFINE_RDF_VOCAB (CHROME_URI, CHROME, allowScripts)
 DEFINE_RDF_VOCAB (CHROME_URI, CHROME, hasOverlays)
 DEFINE_RDF_VOCAB (CHROME_URI, CHROME, hasStylesheets)
 DEFINE_RDF_VOCAB (CHROME_URI, CHROME, skinVersion)
 DEFINE_RDF_VOCAB (CHROME_URI, CHROME, localeVersion)
 DEFINE_RDF_VOCAB (CHROME_URI, CHROME, packageVersion)
 DEFINE_RDF_VOCAB (CHROME_URI, CHROME, disabled)
 DEFINE_RDF_VOCAB (CHROME_URI, CHROME, xpcNativeWrappers)
static PRBool PR_CALLBACK DatasourceEnumerator (nsHashKey *aKey, void *aData, void *closure)
 NS_IMPL_THREADSAFE_ISUPPORTS6 (nsChromeRegistry, nsIChromeRegistry, nsIXULChromeRegistry, nsIChromeRegistrySea, nsIXULOverlayProvider, nsIObserver, nsISupportsWeakReference) nsresult nsChromeRegistry
static nsresult SplitURL (nsIURI *aChromeURI, nsCString &aPackage, nsCString &aProvider, nsCString &aFile, PRBool *aModified=nsnull)
static nsresult GetBaseURLFile (const nsACString &aBaseURL, nsIFile **aFile)
static void FlushSkinBindingsForWindow (nsIDOMWindowInternal *aWindow)
static PRBool IsChromeURI (nsIURI *aURI)

Variables

static char kChromePrefix [] = "chrome://"
nsIChromeRegistrygChromeRegistry = nsnull

Define Documentation

#define CHROME_URI   "http://www.mozilla.org/rdf/chrome#"

Definition at line 117 of file nsChromeRegistry.cpp.

Definition at line 104 of file nsChromeRegistry.cpp.

#define kInstalledChromeFileName   NS_LITERAL_CSTRING("installed-chrome.txt")

Definition at line 105 of file nsChromeRegistry.cpp.


Function Documentation

static PRBool PR_CALLBACK DatasourceEnumerator ( nsHashKey *  aKey,
void aData,
void closure 
) [static]

Definition at line 152 of file nsChromeRegistry.cpp.

{
  if (!closure || !aData)
    return PR_FALSE;

  nsIRDFCompositeDataSource* compositeDS = (nsIRDFCompositeDataSource*) closure;

  nsCOMPtr<nsISupports> supports = (nsISupports*)aData;

  nsCOMPtr<nsIRDFDataSource> dataSource = do_QueryInterface(supports);
  if (!dataSource)
    return PR_FALSE;

#ifdef DEBUG
  nsresult rv =
#endif
  compositeDS->RemoveDataSource(dataSource);
  NS_ASSERTION(NS_SUCCEEDED(rv), "failed to RemoveDataSource");
  return PR_TRUE;
}

Here is the call graph for this function:

DEFINE_RDF_VOCAB ( CHROME_URI  ,
CHROME  ,
selectedSkin   
)
DEFINE_RDF_VOCAB ( CHROME_URI  ,
CHROME  ,
selectedLocale   
)
DEFINE_RDF_VOCAB ( CHROME_URI  ,
CHROME  ,
baseURL   
)
DEFINE_RDF_VOCAB ( CHROME_URI  ,
CHROME  ,
packages   
)
DEFINE_RDF_VOCAB ( CHROME_URI  ,
CHROME  ,
package   
)
DEFINE_RDF_VOCAB ( CHROME_URI  ,
CHROME  ,
name   
)
DEFINE_RDF_VOCAB ( CHROME_URI  ,
CHROME  ,
image   
)
DEFINE_RDF_VOCAB ( CHROME_URI  ,
CHROME  ,
locType   
)
DEFINE_RDF_VOCAB ( CHROME_URI  ,
CHROME  ,
allowScripts   
)
DEFINE_RDF_VOCAB ( CHROME_URI  ,
CHROME  ,
hasOverlays   
)
DEFINE_RDF_VOCAB ( CHROME_URI  ,
CHROME  ,
hasStylesheets   
)
DEFINE_RDF_VOCAB ( CHROME_URI  ,
CHROME  ,
skinVersion   
)
DEFINE_RDF_VOCAB ( CHROME_URI  ,
CHROME  ,
localeVersion   
)
DEFINE_RDF_VOCAB ( CHROME_URI  ,
CHROME  ,
packageVersion   
)
DEFINE_RDF_VOCAB ( CHROME_URI  ,
CHROME  ,
disabled   
)
DEFINE_RDF_VOCAB ( CHROME_URI  ,
CHROME  ,
xpcNativeWrappers   
)
static void FlushSkinBindingsForWindow ( nsIDOMWindowInternal aWindow) [static]

Definition at line 1309 of file nsChromeRegistry.cpp.

{
  // Get the DOM document.
  nsCOMPtr<nsIDOMDocument> domDocument;
  aWindow->GetDocument(getter_AddRefs(domDocument));
  if (!domDocument)
    return;

  nsCOMPtr<nsIDocument> document = do_QueryInterface(domDocument);
  if (!document)
    return;

  // Annihilate all XBL bindings.
  document->BindingManager()->FlushSkinBindings();
}

Here is the call graph for this function:

static nsresult GetBaseURLFile ( const nsACString &  aBaseURL,
nsIFile **  aFile 
) [static]

Definition at line 428 of file nsChromeRegistry.cpp.

{
  NS_ENSURE_ARG_POINTER(aFile);
  *aFile = nsnull;

  nsresult rv;
  nsCOMPtr<nsIIOService> ioServ(do_GetService(NS_IOSERVICE_CONTRACTID, &rv));
  if (NS_FAILED(rv)) return rv;

  nsCOMPtr<nsIURI> uri;
  rv = ioServ->NewURI(aBaseURL, nsnull, nsnull, getter_AddRefs(uri));
  if (NS_FAILED(rv)) return rv;

  // Loop, jar: URIs can nest (e.g. jar:jar:A.jar!B.jar!C.xml).
  // Often, however, we have jar:resource:/chrome/A.jar!C.xml.
  nsCOMPtr<nsIJARURI> jarURI;
  while ((jarURI = do_QueryInterface(uri)) != nsnull)
    jarURI->GetJARFile(getter_AddRefs(uri));

  // Here we must have a URL of the form resource:/chrome/A.jar
  // or file:/some/path/to/A.jar.
  nsCOMPtr<nsIFileURL> fileURL(do_QueryInterface(uri));
  if (fileURL) {
    nsCOMPtr<nsIFile> file;
    fileURL->GetFile(getter_AddRefs(file));
    if (file) {
      NS_ADDREF(*aFile = file);
      return NS_OK;
    }
  }
  NS_ERROR("GetBaseURLFile() failed. Remote chrome?");
  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool IsChromeURI ( nsIURI aURI) [static]

Definition at line 1377 of file nsChromeRegistry.cpp.

{
    PRBool isChrome=PR_FALSE;
    if (NS_SUCCEEDED(aURI->SchemeIs("chrome", &isChrome)) && isChrome)
        return PR_TRUE;
    return PR_FALSE;
}
static NS_DEFINE_CID ( kWindowMediatorCID  ,
NS_WINDOWMEDIATOR_CID   
) [static]
static NS_DEFINE_CID ( kRDFServiceCID  ,
NS_RDFSERVICE_CID   
) [static]
static NS_DEFINE_CID ( kRDFXMLDataSourceCID  ,
NS_RDFXMLDATASOURCE_CID   
) [static]
static NS_DEFINE_CID ( kRDFContainerUtilsCID  ,
NS_RDFCONTAINERUTILS_CID   
) [static]
static NS_DEFINE_CID ( kCSSLoaderCID  ,
NS_CSS_LOADER_CID   
) [static]

Definition at line 188 of file nsChromeRegistry.cpp.

{
  // these atoms appear in almost every chrome registry manifest.rdf
  // in some form or another. making static atoms prevents the atoms
  // from constantly being created/destroyed during parsing
  
  static const nsStaticAtom atoms[] = {
    { "c",             &sCPrefix },
    { "chrome",        nsnull },
    { "NC",            nsnull },
    { "baseURL",       nsnull},
    { "allowScripts",  nsnull },
    { "skinVersion",   nsnull },
    { "package",       nsnull },
    { "packages",      nsnull },
    { "locType",       nsnull },
    { "displayName",   nsnull },
    { "author",        nsnull },
    { "localeVersion", nsnull },
    { "localeType",    nsnull },
    { "selectedLocale", nsnull },
    { "selectedSkin",  nsnull },
    { "hasOverlays",   nsnull },
    { "xpcNativeWrappers", nsnull },
    { "previewURL", nsnull },
  };

  NS_RegisterStaticAtoms(atoms, NS_ARRAY_LENGTH(atoms));
  
  gChromeRegistry = this;
  
  nsresult rv;
  rv = CallGetService(kRDFServiceCID, &mRDFService);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = CallGetService(kRDFContainerUtilsCID, &mRDFContainerUtils);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = mRDFService->GetResource(nsDependentCString(kURICHROME_selectedSkin),
                                getter_AddRefs(mSelectedSkin));
  NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource");

  rv = mRDFService->GetResource(nsDependentCString(kURICHROME_selectedLocale),
                                getter_AddRefs(mSelectedLocale));
  NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource");

  rv = mRDFService->GetResource(nsDependentCString(kURICHROME_baseURL),
                                getter_AddRefs(mBaseURL));
  NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource");

  rv = mRDFService->GetResource(nsDependentCString(kURICHROME_packages),
                                getter_AddRefs(mPackages));
  NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource");

  rv = mRDFService->GetResource(nsDependentCString(kURICHROME_package),
                                getter_AddRefs(mPackage));
  NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource");

  rv = mRDFService->GetResource(nsDependentCString(kURICHROME_name),
                                getter_AddRefs(mName));
  NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource");

  rv = mRDFService->GetResource(nsDependentCString(kURICHROME_image),
                                getter_AddRefs(mImage));
  NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource");

  rv = mRDFService->GetResource(nsDependentCString(kURICHROME_locType),
                                getter_AddRefs(mLocType));
  NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource");

  rv = mRDFService->GetResource(nsDependentCString(kURICHROME_allowScripts),
                                getter_AddRefs(mAllowScripts));
  NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource");

  rv = mRDFService->GetResource(nsDependentCString(kURICHROME_hasOverlays),
                                getter_AddRefs(mHasOverlays));
  NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource");

  rv = mRDFService->GetResource(nsDependentCString(kURICHROME_hasStylesheets),
                                getter_AddRefs(mHasStylesheets));
  NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource");

  rv = mRDFService->GetResource(nsDependentCString(kURICHROME_skinVersion),
                                getter_AddRefs(mSkinVersion));
  NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource");

  rv = mRDFService->GetResource(nsDependentCString(kURICHROME_localeVersion),
                                getter_AddRefs(mLocaleVersion));
  NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource");

  rv = mRDFService->GetResource(nsDependentCString(kURICHROME_packageVersion),
                                getter_AddRefs(mPackageVersion));
  NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource");

  rv = mRDFService->GetResource(nsDependentCString(kURICHROME_disabled),
                                getter_AddRefs(mDisabled));
  NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource");

  rv = mRDFService->GetResource(nsDependentCString(kURICHROME_xpcNativeWrappers),
                                getter_AddRefs(mXPCNativeWrappers));
  NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource");

  nsCOMPtr<nsIObserverService> observerService =
           do_GetService("@mozilla.org/observer-service;1", &rv);
  if (observerService) {
    observerService->AddObserver(this, "profile-before-change", PR_TRUE);
    observerService->AddObserver(this, "profile-after-change", PR_TRUE);
  }

  CheckForNewChrome();
  // CheckForNewChrome suppresses these during chrome registration
  FlagXPCNativeWrappers();

  return NS_OK;
}

Here is the call graph for this function:

static nsresult SplitURL ( nsIURI aChromeURI,
nsCString aPackage,
nsCString aProvider,
nsCString aFile,
PRBool aModified = nsnull 
) [static]

Definition at line 318 of file nsChromeRegistry.cpp.

{
  // Splits a "chrome:" URL into its package, provider, and file parts.
  // Here are the current portions of a
  // chrome: url that make up the chrome-
  //
  //     chrome://global/skin/foo?bar
  //     \------/ \----/\---/ \-----/
  //         |       |     |     |
  //         |       |     |     `-- RemainingPortion
  //         |       |     |
  //         |       |     `-- Provider
  //         |       |
  //         |       `-- Package
  //         |
  //         `-- Always "chrome://"
  //
  //

  nsresult rv;

  nsCAutoString str;
  rv = aChromeURI->GetSpec(str);
  if (NS_FAILED(rv)) return rv;

  // We only want to deal with "chrome:" URLs here. We could return
  // an error code if the URL isn't properly prefixed here...
  if (PL_strncmp(str.get(), kChromePrefix, sizeof(kChromePrefix) - 1) != 0)
    return NS_ERROR_INVALID_ARG;

  // Cull out the "package" string; e.g., "navigator"
  aPackage = str.get() + sizeof(kChromePrefix) - 1;

  PRInt32 idx;
  idx = aPackage.FindChar('/');
  if (idx < 0)
    return NS_OK;

  // Cull out the "provider" string; e.g., "content"
  aPackage.Right(aProvider, aPackage.Length() - (idx + 1));
  aPackage.Truncate(idx);

  idx = aProvider.FindChar('/');
  if (idx < 0) {
    // Force the provider to end with a '/'
    idx = aProvider.Length();
    aProvider.Append('/');
  }

  // Cull out the "file"; e.g., "navigator.xul"
  aProvider.Right(aFile, aProvider.Length() - (idx + 1));
  aProvider.Truncate(idx);

  PRBool nofile = aFile.IsEmpty();
  if (nofile) {
    // If there is no file, then construct the default file
    aFile = aPackage;

    if (aProvider.Equals("content")) {
      aFile += ".xul";
    }
    else if (aProvider.Equals("skin")) {
      aFile += ".css";
    }
    else if (aProvider.Equals("locale")) {
      aFile += ".dtd";
    }
    else {
      NS_ERROR("unknown provider");
      return NS_ERROR_FAILURE;
    }
  } else {
    // Protect against URIs containing .. that reach up out of the
    // chrome directory to grant chrome privileges to non-chrome files.
    // XXX: If we find %-escaped dot or % in a chrome URI we assume
    // someone is trying to trick us.
    const char* pos = aFile.BeginReading();
    const char* end = aFile.EndReading();
    while (pos < end) {
      switch (*pos) {
        case ':':
          return NS_ERROR_FAILURE;
        case '.':
          if (pos[1] == '.')
            return NS_ERROR_FAILURE;
          break;
        case '%':
          // chrome: URIs with escaped dots are trying to trick us.
          // Double-escapes (%25) doubly so
          if (pos[1] == '2' &&
               ( pos[2] == 'e' || pos[2] == 'E' ||
                 pos[2] == '5' ))
            return NS_ERROR_FAILURE;
          break;
        case '?':
        case '#':
          // leave any query or ref section alone
          pos = end;
          continue;
      }
      ++pos;
    }
  }
  if (aModified)
    *aModified = nofile;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 115 of file nsChromeRegistry.cpp.

char kChromePrefix[] = "chrome://" [static]

Definition at line 101 of file nsChromeRegistry.cpp.