Bug 552121 - Point chrome uris to the omnijar [5/7], r=bsmedberg

--HG--
extra : rebase_source : 68bfe81be76b51d54bc977ace52562683817a99d
This commit is contained in:
Michael Wu 2010-06-14 14:41:12 -07:00
Родитель 6f1108b4e5
Коммит 8a37190f51
2 изменённых файлов: 85 добавлений и 33 удалений

Просмотреть файл

@ -72,6 +72,7 @@
#include "nsXPIDLString.h"
#include "nsXULAppAPI.h"
#include "nsTextFormatter.h"
#include "nsZipArchive.h"
#include "nsIAtom.h"
#include "nsICommandLine.h"
@ -112,6 +113,8 @@
#include "nsIXULAppInfo.h"
#include "nsIXULRuntime.h"
#include "mozilla/Omnijar.h"
#define UILOCALE_CMD_LINE_ARG "UILocale"
#define MATCH_OS_LOCALE_PREF "intl.locale.matchOS"
@ -1144,6 +1147,48 @@ RemoveAll(PLDHashTable *table, PLDHashEntryHdr *entry, PRUint32 number, void *ar
return (PLDHashOperator) (PL_DHASH_NEXT | PL_DHASH_REMOVE);
}
#ifdef MOZ_OMNIJAR
nsresult
nsChromeRegistry::CheckOmnijarChrome()
{
nsresult rv;
nsZipArchive* jarReader = mozilla::OmnijarReader();
// just proceed normally if there is no omnijar
if (!jarReader)
return NS_OK;
nsZipItem* manifest = jarReader->GetItem("chrome/chrome.manifest");
NS_ENSURE_TRUE(manifest, NS_ERROR_NOT_AVAILABLE);
nsCAutoString omniJarSpec;
rv = NS_GetURLSpecFromActualFile(mozilla::OmnijarPath(), omniJarSpec);
NS_ENSURE_SUCCESS(rv, rv);
PRUint32 len = manifest->RealSize();
nsAutoArrayPtr<PRUint8> outbuf(new PRUint8[len]);
NS_ENSURE_TRUE(outbuf, NS_ERROR_OUT_OF_MEMORY);
nsZipCursor cursor(manifest, jarReader, outbuf, len);
PRUint32 readlen;
PRUint8* buf = cursor.Read(&readlen);
NS_ENSURE_TRUE(buf, NS_ERROR_FILE_CORRUPTED);
nsAutoString jarString(NS_LITERAL_STRING("jar:"));
AppendUTF8toUTF16(omniJarSpec, jarString);
jarString += NS_LITERAL_STRING("!/chrome/chrome.manifest");
nsCOMPtr<nsIURI> manifestURI;
rv = NS_NewURI(getter_AddRefs(manifestURI), jarString);
NS_ENSURE_SUCCESS(rv, rv);
rv = ProcessManifestBuffer((char *)buf, readlen, manifestURI, PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
return rv;
}
#endif /* MOZ_OMNIJAR */
NS_IMETHODIMP
nsChromeRegistry::CheckForNewChrome()
{
@ -1157,6 +1202,11 @@ nsChromeRegistry::CheckForNewChrome()
nsCOMPtr<nsIProperties> dirSvc (do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
NS_ENSURE_TRUE(dirSvc, NS_ERROR_FAILURE);
#ifdef MOZ_OMNIJAR
rv = CheckOmnijarChrome();
NS_ENSURE_SUCCESS(rv, rv);
#endif
// check the extra chrome directories
nsCOMPtr<nsISimpleEnumerator> chromeML;
rv = dirSvc->Get(NS_CHROME_MANIFESTS_FILE_LIST, NS_GET_IID(nsISimpleEnumerator),
@ -1378,7 +1428,10 @@ nsChromeRegistry::ProcessManifest(nsILocalFile* aManifest, PRBool aSkinOnly)
n = PR_Read(fd, buf, size);
if (n > 0) {
buf[size] = '\0';
rv = ProcessManifestBuffer(buf, size, aManifest, aSkinOnly);
nsCOMPtr<nsIURI> manifestURI;
rv = NS_NewFileURI(getter_AddRefs(manifestURI), aManifest);
if (NS_SUCCEEDED(rv))
rv = ProcessManifestBuffer(buf, size, manifestURI, aSkinOnly);
}
free(buf);
@ -1604,7 +1657,7 @@ EnsureLowerCase(char *aBuf)
nsresult
nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
nsILocalFile* aManifest,
nsIURI* aManifest,
PRBool aSkinOnly)
{
nsresult rv;
@ -1626,10 +1679,6 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
nsCOMPtr<nsIResProtocolHandler> rph (do_QueryInterface(ph));
if (!rph) return NS_ERROR_FAILURE;
nsCOMPtr<nsIURI> manifestURI;
rv = io->NewFileURI(aManifest, getter_AddRefs(manifestURI));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIXPConnect> xpc (do_GetService("@mozilla.org/js/xpc/XPConnect;1"));
nsCOMPtr<nsIVersionComparator> vc (do_GetService("@mozilla.org/xpcom/version-comparator;1"));
@ -1696,14 +1745,14 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
if (!strcmp(token, "content")) {
if (aSkinOnly) {
LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag,
LogMessageWithContext(aManifest, line, nsIScriptError::warningFlag,
"Warning: Ignoring content registration in skin-only manifest.");
continue;
}
char *package = nsCRT::strtok(whitespace, kWhitespace, &whitespace);
char *uri = nsCRT::strtok(whitespace, kWhitespace, &whitespace);
if (!package || !uri) {
LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag,
LogMessageWithContext(aManifest, line, nsIScriptError::warningFlag,
"Warning: Malformed content registration.");
continue;
}
@ -1735,7 +1784,7 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
CheckVersionFlag(kAppVersion, wtoken, appVersion, vc, stAppVersion))
continue;
LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag,
LogMessageWithContext(aManifest, line, nsIScriptError::warningFlag,
"Warning: Unrecognized chrome registration modifier '%s'.",
token);
badFlag = PR_TRUE;
@ -1746,7 +1795,7 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
continue;
nsCOMPtr<nsIURI> resolved;
rv = io->NewURI(nsDependentCString(uri), nsnull, manifestURI,
rv = io->NewURI(nsDependentCString(uri), nsnull, aManifest,
getter_AddRefs(resolved));
if (NS_FAILED(rv))
continue;
@ -1782,7 +1831,7 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
}
else if (!strcmp(token, "locale")) {
if (aSkinOnly) {
LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag,
LogMessageWithContext(aManifest, line, nsIScriptError::warningFlag,
"Warning: Ignoring locale registration in skin-only manifest.");
continue;
}
@ -1790,7 +1839,7 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
char *provider = nsCRT::strtok(whitespace, kWhitespace, &whitespace);
char *uri = nsCRT::strtok(whitespace, kWhitespace, &whitespace);
if (!package || !provider || !uri) {
LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag,
LogMessageWithContext(aManifest, line, nsIScriptError::warningFlag,
"Warning: Malformed locale registration.");
continue;
}
@ -1815,7 +1864,7 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
CheckVersionFlag(kAppVersion, wtoken, appVersion, vc, stAppVersion))
continue;
LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag,
LogMessageWithContext(aManifest, line, nsIScriptError::warningFlag,
"Warning: Unrecognized chrome registration modifier '%s'.",
token);
badFlag = PR_TRUE;
@ -1826,7 +1875,7 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
continue;
nsCOMPtr<nsIURI> resolved;
rv = io->NewURI(nsDependentCString(uri), nsnull, manifestURI,
rv = io->NewURI(nsDependentCString(uri), nsnull, aManifest,
getter_AddRefs(resolved));
if (NS_FAILED(rv))
continue;
@ -1852,7 +1901,7 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
char *provider = nsCRT::strtok(whitespace, kWhitespace, &whitespace);
char *uri = nsCRT::strtok(whitespace, kWhitespace, &whitespace);
if (!package || !provider || !uri) {
LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag,
LogMessageWithContext(aManifest, line, nsIScriptError::warningFlag,
"Warning: Malformed skin registration.");
continue;
}
@ -1877,7 +1926,7 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
CheckVersionFlag(kAppVersion, wtoken, appVersion, vc, stAppVersion))
continue;
LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag,
LogMessageWithContext(aManifest, line, nsIScriptError::warningFlag,
"Warning: Unrecognized chrome registration modifier '%s'.",
token);
badFlag = PR_TRUE;
@ -1888,7 +1937,7 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
continue;
nsCOMPtr<nsIURI> resolved;
rv = io->NewURI(nsDependentCString(uri), nsnull, manifestURI,
rv = io->NewURI(nsDependentCString(uri), nsnull, aManifest,
getter_AddRefs(resolved));
if (NS_FAILED(rv))
continue;
@ -1911,14 +1960,14 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
}
else if (!strcmp(token, "overlay")) {
if (aSkinOnly) {
LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag,
LogMessageWithContext(aManifest, line, nsIScriptError::warningFlag,
"Warning: Ignoring overlay registration in skin-only manifest.");
continue;
}
char *base = nsCRT::strtok(whitespace, kWhitespace, &whitespace);
char *overlay = nsCRT::strtok(whitespace, kWhitespace, &whitespace);
if (!base || !overlay) {
LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag,
LogMessageWithContext(aManifest, line, nsIScriptError::warningFlag,
"Warning: malformed chrome overlay instruction.");
continue;
}
@ -1941,7 +1990,7 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
CheckVersionFlag(kAppVersion, wtoken, appVersion, vc, stAppVersion))
continue;
LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag,
LogMessageWithContext(aManifest, line, nsIScriptError::warningFlag,
"Warning: Unrecognized chrome registration modifier '%s'.",
token);
badFlag = PR_TRUE;
@ -1974,7 +2023,7 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
char *base = nsCRT::strtok(whitespace, kWhitespace, &whitespace);
char *overlay = nsCRT::strtok(whitespace, kWhitespace, &whitespace);
if (!base || !overlay) {
LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag,
LogMessageWithContext(aManifest, line, nsIScriptError::warningFlag,
"Warning: malformed chrome style instruction.");
continue;
}
@ -1997,7 +2046,7 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
CheckVersionFlag(kAppVersion, wtoken, appVersion, vc, stAppVersion))
continue;
LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag,
LogMessageWithContext(aManifest, line, nsIScriptError::warningFlag,
"Warning: Unrecognized chrome registration modifier '%s'.",
token);
badFlag = PR_TRUE;
@ -2026,7 +2075,7 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
}
else if (!strcmp(token, "override")) {
if (aSkinOnly) {
LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag,
LogMessageWithContext(aManifest, line, nsIScriptError::warningFlag,
"Warning: Ignoring override registration in skin-only manifest.");
continue;
}
@ -2034,7 +2083,7 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
char *chrome = nsCRT::strtok(whitespace, kWhitespace, &whitespace);
char *resolved = nsCRT::strtok(whitespace, kWhitespace, &whitespace);
if (!chrome || !resolved) {
LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag,
LogMessageWithContext(aManifest, line, nsIScriptError::warningFlag,
"Warning: malformed chrome override instruction.");
continue;
}
@ -2057,7 +2106,7 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
CheckVersionFlag(kAppVersion, wtoken, appVersion, vc, stAppVersion))
continue;
LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag,
LogMessageWithContext(aManifest, line, nsIScriptError::warningFlag,
"Warning: Unrecognized chrome registration modifier '%s'.",
token);
badFlag = PR_TRUE;
@ -2070,7 +2119,7 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
nsCOMPtr<nsIURI> chromeuri, resolveduri;
rv = io->NewURI(nsDependentCString(chrome), nsnull, nsnull,
getter_AddRefs(chromeuri));
rv |= io->NewURI(nsDependentCString(resolved), nsnull, manifestURI,
rv |= io->NewURI(nsDependentCString(resolved), nsnull, aManifest,
getter_AddRefs(resolveduri));
if (NS_FAILED(rv))
continue;
@ -2086,7 +2135,7 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
}
else if (!strcmp(token, "resource")) {
if (aSkinOnly) {
LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag,
LogMessageWithContext(aManifest, line, nsIScriptError::warningFlag,
"Warning: Ignoring resource registration in skin-only manifest.");
continue;
}
@ -2094,7 +2143,7 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
char *package = nsCRT::strtok(whitespace, kWhitespace, &whitespace);
char *uri = nsCRT::strtok(whitespace, kWhitespace, &whitespace);
if (!package || !uri) {
LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag,
LogMessageWithContext(aManifest, line, nsIScriptError::warningFlag,
"Warning: Malformed resource registration.");
continue;
}
@ -2119,7 +2168,7 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
CheckVersionFlag(kAppVersion, wtoken, appVersion, vc, stAppVersion))
continue;
LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag,
LogMessageWithContext(aManifest, line, nsIScriptError::warningFlag,
"Warning: Unrecognized chrome registration modifier '%s'.",
token);
badFlag = PR_TRUE;
@ -2135,14 +2184,14 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
rv = rph->HasSubstitution(host, &exists);
NS_ENSURE_SUCCESS(rv, rv);
if (exists) {
LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag,
LogMessageWithContext(aManifest, line, nsIScriptError::warningFlag,
"Warning: Duplicate resource declaration for '%s' ignored.",
package);
continue;
}
nsCOMPtr<nsIURI> resolved;
rv = io->NewURI(nsDependentCString(uri), nsnull, manifestURI,
rv = io->NewURI(nsDependentCString(uri), nsnull, aManifest,
getter_AddRefs(resolved));
if (NS_FAILED(rv))
continue;
@ -2158,7 +2207,7 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length,
NS_ENSURE_SUCCESS(rv, rv);
}
else {
LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag,
LogMessageWithContext(aManifest, line, nsIScriptError::warningFlag,
"Warning: Ignoring unrecognized chrome manifest instruction.");
}
}

Просмотреть файл

@ -116,6 +116,9 @@ protected:
private:
nsresult SelectLocaleFromPref(nsIPrefBranch* prefs);
#ifdef MOZ_OMNIJAR
nsresult CheckOmnijarChrome();
#endif
static nsresult RefreshWindow(nsIDOMWindowInternal* aWindow);
static nsresult GetProviderAndPath(nsIURL* aChromeURL,
@ -131,7 +134,7 @@ private:
#endif
NS_HIDDEN_(nsresult) ProcessManifest(nsILocalFile* aManifest, PRBool aSkinOnly);
NS_HIDDEN_(nsresult) ProcessManifestBuffer(char *aBuffer, PRInt32 aLength, nsILocalFile* aManifest, PRBool aSkinOnly);
NS_HIDDEN_(nsresult) ProcessManifestBuffer(char *aBuffer, PRInt32 aLength, nsIURI* aManifest, PRBool aSkinOnly);
NS_HIDDEN_(nsresult) ProcessNewChromeFile(nsILocalFile *aListFile, nsIURI* aManifest);
NS_HIDDEN_(nsresult) ProcessNewChromeBuffer(char *aBuffer, PRInt32 aLength, nsIURI* aManifest);