Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
nsEmbedChromeRegistry.cpp File Reference
#include "nsEmbedChromeRegistry.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "plstr.h"
#include "nsIDirectoryService.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsIProperties.h"
#include "nsILocalFile.h"
#include "nsIURI.h"

Go to the source code of this file.

Classes

struct  chromeToken

Defines

#define CHROME_TYPE_CONTENT   0
#define CHROME_TYPE_LOCALE   1
#define CHROME_TYPE_SKIN   2
#define MAX_TOKENS   5

Functions

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

Variables

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

Class Documentation

struct chromeToken

Definition at line 228 of file nsEmbedChromeRegistry.cpp.

Class Members
const char * tokenEnd
const char * tokenStart

Define Documentation

Definition at line 49 of file nsEmbedChromeRegistry.cpp.

Definition at line 50 of file nsEmbedChromeRegistry.cpp.

Definition at line 51 of file nsEmbedChromeRegistry.cpp.

#define MAX_TOKENS   5

Definition at line 227 of file nsEmbedChromeRegistry.cpp.


Function Documentation

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

Definition at line 56 of file nsEmbedChromeRegistry.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.
    int depth = 0;
    PRBool sawSlash = PR_TRUE;  // .. at the beginning is suspect as well as /..
    for (const char* p=aFile.get(); *p; p++) {
      if (sawSlash) {
        if (p[0] == '.' && p[1] == '.'){
          depth--;    // we have /.., decrement depth.
        } else {
          static const char escape[] = "%2E%2E";
          if (PL_strncasecmp(p, escape, sizeof(escape)-1) == 0)
            depth--;   // we have the HTML-escaped form of /.., decrement depth.
        }
      } else if (p[0] != '/') {
        depth++;        // we have /x for some x that is not /
      }
      sawSlash = (p[0] == '/');

      if (depth < 0) {
        return NS_ERROR_FAILURE;
      }
    }
  }
  if (aModified)
    *aModified = nofile;
  return NS_OK;
}

Here is the call graph for this function:


Variable Documentation

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

Definition at line 53 of file nsEmbedChromeRegistry.cpp.