Back to index

lightning-sunbird  0.9+nobinonly
Defines | Enumerations | Functions | Variables
nsChromeRegistry.cpp File Reference
#include "nsChromeRegistry.h"
#include <string.h>
#include "prio.h"
#include "prprf.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsArrayEnumerator.h"
#include "nsStringEnumerator.h"
#include "nsEnumeratorUtils.h"
#include "nsCOMPtr.h"
#include "nsDOMError.h"
#include "nsEscape.h"
#include "nsInt64.h"
#include "nsLayoutCID.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
#include "nsReadableUtils.h"
#include "nsStaticAtom.h"
#include "nsString.h"
#include "nsUnicharUtils.h"
#include "nsWidgetsCID.h"
#include "nsXPIDLString.h"
#include "nsXULAppAPI.h"
#include "nsIAtom.h"
#include "nsIBindingManager.h"
#include "nsICommandLine.h"
#include "nsICSSLoader.h"
#include "nsICSSStyleSheet.h"
#include "nsIConsoleService.h"
#include "nsIDirectoryService.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
#include "nsIDocShell.h"
#include "nsIDocumentObserver.h"
#include "nsIDOMElement.h"
#include "nsIDOMLocation.h"
#include "nsIDOMWindowCollection.h"
#include "nsIDOMWindowInternal.h"
#include "nsIFileChannel.h"
#include "nsIFileURL.h"
#include "nsIIOService.h"
#include "nsIJARURI.h"
#include "nsILocalFile.h"
#include "nsILocaleService.h"
#include "nsILookAndFeel.h"
#include "nsIObserverService.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIPrefBranch2.h"
#include "nsIPresShell.h"
#include "nsIScriptError.h"
#include "nsIServiceManager.h"
#include "nsISimpleEnumerator.h"
#include "nsIStyleSheet.h"
#include "nsISupportsArray.h"
#include "nsIVersionComparator.h"
#include "nsIWindowMediator.h"
#include "nsIXPConnect.h"
#include "nsIXULAppInfo.h"
#include "nsIXULRuntime.h"
#include "rdf.h"
#include "nsRDFCID.h"
#include "nsIRDFService.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFObserver.h"
#include "nsIRDFRemoteDataSource.h"
#include "nsIRDFXMLSink.h"
#include "nsIRDFResource.h"
#include "nsIRDFContainer.h"
#include "nsIRDFContainerUtils.h"

Go to the source code of this file.

Defines

#define UILOCALE_CMD_LINE_ARG   "UILocale"
#define MATCH_OS_LOCALE_PREF   "intl.locale.matchOS"
#define SELECTED_LOCALE_PREF   "general.useragent.locale"
#define SELECTED_SKIN_PREF   "general.skins.selectedSkin"
#define CHROME_URI   "http://www.mozilla.org/rdf/chrome#"
#define COMPARE_EQ   1 << 0
 Check for a modifier flag of the following form: "flag=version" "flag<=version" "flag<version" "flag>=version" "flag>version".
#define COMPARE_LT   1 << 1
#define COMPARE_GT   1 << 2

Enumerations

enum  TriState { eUnspecified, eBad, eOK }

Functions

static NS_DEFINE_CID (kCSSLoaderCID, NS_CSS_LOADER_CID)
static NS_DEFINE_CID (kLookAndFeelCID, NS_LOOKANDFEEL_CID)
 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, platformPackage)
static void LogMessage (const char *aMsg,...)
static void LogMessageWithContext (nsIURI *aURL, PRUint32 aLineNumber, PRUint32 flags, const char *aMsg,...)
static PRBool LanguagesMatch (const nsACString &a, const nsACString &b)
 Match the language-part of two lang-COUNTRY codes, hopefully but not guaranteed to be in the form ab-CD or abz-CD.
 NS_IMPL_THREADSAFE_ISUPPORTS6 (nsChromeRegistry, nsIChromeRegistry, nsIXULChromeRegistry, nsIToolkitChromeRegistry, nsIXULOverlayProvider, nsIObserver, nsISupportsWeakReference) static nsresult getUILangCountry(nsACString &aUILang)
static void FlushSkinBindingsForWindow (nsIDOMWindowInternal *aWindow)
static PRBool IsChromeURI (nsIURI *aURI)
static PLDHashOperator RemoveAll (PLDHashTable *table, PLDHashEntryHdr *entry, PRUint32 number, void *arg)
static nsresult GetContainerEnumerator (nsIRDFDataSource *ds, nsIRDFResource *res, nsISimpleEnumerator **aResult, PRInt32 *aCountResult=nsnull)
static void FollowLiteral (nsIRDFDataSource *ds, nsIRDFResource *res, nsIRDFResource *arc, nsACString &result)
static void FollowResource (nsIRDFDataSource *ds, nsIRDFResource *res, nsIRDFResource *arc, nsIRDFResource **result)
static void GetRelativePath (nsIURI *base, nsIURI *relative, nsACString &result)
static void GetResourceName (nsIRDFResource *res, nsACString &result)
static void GetLiteralText (nsIRDFLiteral *lit, nsACString &result)
static PRBool CheckFlag (const nsSubstring &aFlag, const nsSubstring &aData, PRBool &aResult)
 Check for a modifier flag of the following forms: "flag" (same as "true") "flag=yes|true|1" "flag="no|false|0".
static PRBool CheckStringFlag (const nsSubstring &aFlag, const nsSubstring &aData, const nsSubstring &aValue, TriState &aResult)
 Check for a modifier flag of the following form: "flag=string".
static PRBool CheckVersionFlag (const nsSubstring &aFlag, const nsSubstring &aData, const nsSubstring &aValue, nsIVersionComparator *aChecker, TriState &aResult)

Variables

static const PRInt32 kNSPR_APPEND_FLAGS = PR_WRONLY | PR_CREATE_FILE | PR_APPEND
static const PRInt32 kNSPR_TRUNCATE_FLAGS = PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE
static const char kWhitespace [] = "\t "
static const char kNewlines [] = "\r\n"

Define Documentation

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

Definition at line 129 of file nsChromeRegistry.cpp.

#define COMPARE_EQ   1 << 0

Check for a modifier flag of the following form: "flag=version" "flag<=version" "flag<version" "flag>=version" "flag>version".

Parameters:
aFlagThe flag to compare.
aDataThe tokenized data to check; this is lowercased before being passed in.
aValueThe value that is expected.
aCheckerthe version checker to use. If null, aResult will always be eBad.
aResultIf this is eOK when passed in, this is left alone. Otherwise if the flag is found it is set to eBad or eOK.
Returns:
Whether the flag was handled.

Definition at line 1979 of file nsChromeRegistry.cpp.

#define COMPARE_GT   1 << 2

Definition at line 1981 of file nsChromeRegistry.cpp.

#define COMPARE_LT   1 << 1

Definition at line 1980 of file nsChromeRegistry.cpp.

#define MATCH_OS_LOCALE_PREF   "intl.locale.matchOS"

Definition at line 120 of file nsChromeRegistry.cpp.

#define SELECTED_LOCALE_PREF   "general.useragent.locale"

Definition at line 121 of file nsChromeRegistry.cpp.

#define SELECTED_SKIN_PREF   "general.skins.selectedSkin"

Definition at line 122 of file nsChromeRegistry.cpp.

#define UILOCALE_CMD_LINE_ARG   "UILocale"

Definition at line 118 of file nsChromeRegistry.cpp.


Enumeration Type Documentation

enum TriState
Enumerator:
eUnspecified 
eBad 
eOK 

Definition at line 1920 of file nsChromeRegistry.cpp.


Function Documentation

static PRBool CheckFlag ( const nsSubstring aFlag,
const nsSubstring aData,
PRBool aResult 
) [static]

Check for a modifier flag of the following forms: "flag" (same as "true") "flag=yes|true|1" "flag="no|false|0".

Parameters:
aFlagThe flag to compare.
aDataThe tokenized data to check; this is lowercased before being passed in.
aResultIf the flag is found, the value is assigned here.
Returns:
Whether the flag was handled.

Definition at line 1882 of file nsChromeRegistry.cpp.

{
  if (!StringBeginsWith(aData, aFlag))
    return PR_FALSE;

  if (aFlag.Length() == aData.Length()) {
    // the data is simply "flag", which is the same as "flag=yes"
    aResult = PR_TRUE;
    return PR_TRUE;
  }

  if (aData.CharAt(aFlag.Length()) != '=') {
    // the data is "flag2=", which is not anything we care about
    return PR_FALSE;
  }

  if (aData.Length() == aFlag.Length() + 1) {
    aResult = PR_FALSE;
    return PR_TRUE;
  }

  switch (aData.CharAt(aFlag.Length() + 1)) {
  case '1':
  case 't': //true
  case 'y': //yes
    aResult = PR_TRUE;
    return PR_TRUE;

  case '0':
  case 'f': //false
  case 'n': //no
    aResult = PR_FALSE;
    return PR_TRUE;
  }

  return PR_FALSE;
}

Here is the call graph for this function:

static PRBool CheckStringFlag ( const nsSubstring aFlag,
const nsSubstring aData,
const nsSubstring aValue,
TriState aResult 
) [static]

Check for a modifier flag of the following form: "flag=string".

Parameters:
aFlagThe flag to compare.
aDataThe tokenized data to check; this is lowercased before being passed in.
aValueThe value that is expected.
aResultIf this is "ok" when passed in, this is left alone. Otherwise if the flag is found it is set to eBad or eOK.
Returns:
Whether the flag was handled.

Definition at line 1938 of file nsChromeRegistry.cpp.

{
  if (aData.Length() < aFlag.Length() + 1)
    return PR_FALSE;

  if (!StringBeginsWith(aData, aFlag))
    return PR_FALSE;

  if (aData[aFlag.Length()] != '=')
    return PR_FALSE;

  if (aResult != eOK) {
    nsDependentSubstring testdata = Substring(aData, aFlag.Length() + 1);
    if (testdata.Equals(aValue))
      aResult = eOK;
    else
      aResult = eBad;
  }

  return PR_TRUE;
}

Here is the call graph for this function:

static PRBool CheckVersionFlag ( const nsSubstring aFlag,
const nsSubstring aData,
const nsSubstring aValue,
nsIVersionComparator aChecker,
TriState aResult 
) [static]

Definition at line 1984 of file nsChromeRegistry.cpp.

{
  if (aData.Length() < aFlag.Length() + 2)
    return PR_FALSE;

  if (!StringBeginsWith(aData, aFlag))
    return PR_FALSE;

  PRUint32 comparison;
  nsAutoString testdata;

  switch (aData[aFlag.Length()]) {
  case '=':
    comparison = COMPARE_EQ;
    testdata = Substring(aData, aFlag.Length() + 1);
    break;

  case '<':
    if (aData[aFlag.Length() + 1] == '=') {
      comparison = COMPARE_EQ | COMPARE_LT;
      testdata = Substring(aData, aFlag.Length() + 2);
    }
    else {
      comparison = COMPARE_LT;
      testdata = Substring(aData, aFlag.Length() + 1);
    }
    break;

  case '>':
    if (aData[aFlag.Length() + 1] == '=') {
      comparison = COMPARE_EQ | COMPARE_GT;
      testdata = Substring(aData, aFlag.Length() + 2);
    }
    else {
      comparison = COMPARE_GT;
      testdata = Substring(aData, aFlag.Length() + 1);
    }
    break;

  default:
    return PR_FALSE;
  }

  if (testdata.Length() == 0)
    return PR_FALSE;

  if (aResult != eOK) {
    if (!aChecker) {
      aResult = eBad;
    }
    else {
      PRInt32 c;
      nsresult rv = aChecker->Compare(NS_ConvertUTF16toUTF8(aValue),
                                      NS_ConvertUTF16toUTF8(testdata), &c);
      if (NS_FAILED(rv)) {
        aResult = eBad;
      }
      else {
        if ((c == 0 && comparison & COMPARE_EQ) ||
            (c < 0 && comparison & COMPARE_LT) ||
            (c > 0 && comparison & COMPARE_GT))
          aResult = eOK;
        else
          aResult = eBad;
      }
    }
  }

  return PR_TRUE;
}

Here is the call graph for this function:

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  ,
platformPackage   
)
static void FlushSkinBindingsForWindow ( nsIDOMWindowInternal aWindow) [static]

Definition at line 834 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 void FollowLiteral ( nsIRDFDataSource ds,
nsIRDFResource res,
nsIRDFResource arc,
nsACString &  result 
) [static]

Definition at line 1454 of file nsChromeRegistry.cpp.

{
  nsresult rv;

  nsCOMPtr<nsIRDFNode> node;
  rv = ds->GetTarget(res, arc, PR_TRUE, getter_AddRefs(node));
  if (NS_FAILED(rv) || !node) {
    result.Truncate();
    return;
  }

  nsCOMPtr<nsIRDFLiteral> literal (do_QueryInterface(node));
  if (!literal) {
    NS_ERROR("Arc found, but doesn't point to expected literal!");
    result.Truncate();
    return;
  }

  const PRUnichar* value;
  literal->GetValueConst(&value);
  CopyUTF16toUTF8(value, result);
}

Here is the call graph for this function:

static void FollowResource ( nsIRDFDataSource ds,
nsIRDFResource res,
nsIRDFResource arc,
nsIRDFResource **  result 
) [static]

Definition at line 1479 of file nsChromeRegistry.cpp.

{
  nsresult rv;

  nsCOMPtr<nsIRDFNode> node;
  rv = ds->GetTarget(res, arc, PR_TRUE, getter_AddRefs(node));
  if (NS_FAILED(rv) || !node) {
    *result = nsnull;
    return;
  }

  CallQueryInterface(node, result);
}

Here is the call graph for this function:

static nsresult GetContainerEnumerator ( nsIRDFDataSource ds,
nsIRDFResource res,
nsISimpleEnumerator **  aResult,
PRInt32 aCountResult = nsnull 
) [static]

Definition at line 1435 of file nsChromeRegistry.cpp.

{
  nsresult rv;

  nsCOMPtr<nsIRDFContainer> container
    (do_CreateInstance("@mozilla.org/rdf/container;1"));
  NS_ENSURE_TRUE(container, NS_ERROR_FAILURE);

  rv = container->Init(ds, res);
  if (NS_FAILED(rv)) return rv;

  if (aCountResult)
    container->GetCount(aCountResult);

  return container->GetElements(aResult);
}

Here is the call graph for this function:

static void GetLiteralText ( nsIRDFLiteral lit,
nsACString &  result 
) [static]

Definition at line 1768 of file nsChromeRegistry.cpp.

{
  const PRUnichar* value;
  lit->GetValueConst(&value);
  CopyUTF16toUTF8(value, result);
}

Here is the call graph for this function:

static void GetRelativePath ( nsIURI base,
nsIURI relative,
nsACString &  result 
) [static]

Definition at line 1495 of file nsChromeRegistry.cpp.

{
  nsresult rv;

  nsCOMPtr<nsIJARURI> jarrelative (do_QueryInterface(relative));
  if (jarrelative) {
    nsCOMPtr<nsIURI> jarbase;
    jarrelative->GetJARFile(getter_AddRefs(jarbase));

    nsCAutoString relativeBase;
    GetRelativePath(base, jarbase, relativeBase);

    nsCAutoString jarEntry;
    jarrelative->GetJAREntry(jarEntry);

    result.Assign(NS_LITERAL_CSTRING("jar:"));
    result.Append(relativeBase);
    result.Append(NS_LITERAL_CSTRING("!/"));
    result.Append(jarEntry);
    return;
  }

  nsCOMPtr<nsIURL> baseURL (do_QueryInterface(base));
  if (!baseURL) {
    relative->GetSpec(result);
    return;
  }

  rv = baseURL->GetRelativeSpec(relative, result);
  if (NS_FAILED(rv)) {
    relative->GetSpec(result);
  }
}

Here is the call graph for this function:

static void GetResourceName ( nsIRDFResource res,
nsACString &  result 
) [static]

Definition at line 1656 of file nsChromeRegistry.cpp.

{
  // we need to get the provider name. Instead of doing something sane,
  // we munge the resource URI, looking from the right for colons.

  nsCAutoString providerURI;
  res->GetValueUTF8(providerURI);

  PRInt32 found = providerURI.RFindChar(':');
  if (found == kNotFound) {
    result.Truncate();
    return;
  }

  result.Assign(Substring(providerURI, found + 1));
}

Here is the call graph for this function:

static PRBool IsChromeURI ( nsIURI aURI) [static]

Definition at line 902 of file nsChromeRegistry.cpp.

{
    PRBool isChrome=PR_FALSE;
    if (NS_SUCCEEDED(aURI->SchemeIs("chrome", &isChrome)) && isChrome)
        return PR_TRUE;
    return PR_FALSE;
}

Here is the caller graph for this function:

static PRBool LanguagesMatch ( const nsACString &  a,
const nsACString &  b 
) [static]

Match the language-part of two lang-COUNTRY codes, hopefully but not guaranteed to be in the form ab-CD or abz-CD.

"ab" should also work, any other garbage-in will produce undefined results as long as it does not crash.

Definition at line 207 of file nsChromeRegistry.cpp.

{
  if (a.Length() < 2 || b.Length() < 2)
    return PR_FALSE;

  nsACString::const_iterator as, ae, bs, be;
  a.BeginReading(as);
  a.EndReading(ae);
  b.BeginReading(bs);
  b.EndReading(be);

  while (*as == *bs) {
    if (*as == '-')
      return PR_TRUE;
 
    ++as; ++bs;

    // reached the end
    if (as == ae && bs == be)
      return PR_TRUE;

    // "a" is short
    if (as == ae)
      return (*bs == '-');

    // "b" is short
    if (bs == be)
      return (*as == '-');
  }

  return PR_FALSE;
}

Here is the caller graph for this function:

static void LogMessage ( const char *  aMsg,
  ... 
) [static]

Definition at line 139 of file nsChromeRegistry.cpp.

{
  nsCOMPtr<nsIConsoleService> console 
    (do_GetService(NS_CONSOLESERVICE_CONTRACTID));
  if (!console)
    return;

  va_list args;
  va_start(args, aMsg);
  char* formatted = PR_vsmprintf(aMsg, args);
  va_end(args);
  if (!formatted)
    return;

  console->LogStringMessage(NS_ConvertUTF8toUTF16(formatted).get());
  PR_smprintf_free(formatted);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void LogMessageWithContext ( nsIURI aURL,
PRUint32  aLineNumber,
PRUint32  flags,
const char *  aMsg,
  ... 
) [static]

Definition at line 158 of file nsChromeRegistry.cpp.

{
  nsresult rv;

  nsCOMPtr<nsIConsoleService> console 
    (do_GetService(NS_CONSOLESERVICE_CONTRACTID));

  nsCOMPtr<nsIScriptError> error
    (do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
  if (!console || !error)
    return;

  va_list args;
  va_start(args, aMsg);
  char* formatted = PR_vsmprintf(aMsg, args);
  va_end(args);
  if (!formatted)
    return;

  nsCString spec;
  if (aURL)
    aURL->GetSpec(spec);

  rv = error->Init(NS_ConvertUTF8toUTF16(formatted).get(),
                   NS_ConvertUTF8toUTF16(spec).get(),
                   nsnull,
                   aLineNumber, 0, flags, "chrome registration");
  PR_smprintf_free(formatted);

  if (NS_FAILED(rv))
    return;

  console->LogMessage(error);
}

Here is the call graph for this function:

static NS_DEFINE_CID ( kCSSLoaderCID  ,
NS_CSS_LOADER_CID   
) [static]
static NS_DEFINE_CID ( kLookAndFeelCID  ,
NS_LOOKANDFEEL_CID   
) [static]

Definition at line 430 of file nsChromeRegistry.cpp.

{
  nsresult rv;

  nsCOMPtr<nsILocaleService> localeService = do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  nsAutoString uiLang;
  rv = localeService->GetLocaleComponentForUserAgent(uiLang);
  NS_ENSURE_SUCCESS(rv, rv);

  CopyUTF16toUTF8(uiLang, aUILang);
  return NS_OK;
}

Here is the call graph for this function:

static PLDHashOperator RemoveAll ( PLDHashTable table,
PLDHashEntryHdr entry,
PRUint32  number,
void arg 
) [static]

Definition at line 1116 of file nsChromeRegistry.cpp.


Variable Documentation

const char kNewlines[] = "\r\n" [static]

Definition at line 1868 of file nsChromeRegistry.cpp.

Definition at line 1529 of file nsChromeRegistry.cpp.

Definition at line 1530 of file nsChromeRegistry.cpp.

const char kWhitespace[] = "\t " [static]

Definition at line 1867 of file nsChromeRegistry.cpp.