2 # Parent a7dea879b4b445a23186f438900562155bb39e99
3 Bug 620931 part 1 - Use chrome manifest to register resource://gre-resources/
5 diff --git a/layout/style/jar.mn b/layout/style/jar.mn
6 --- a/layout/style/jar.mn
7 +++ b/layout/style/jar.mn
11 res/html.css (html.css)
12 res/quirk.css (quirk.css)
13 res/viewsource.css (viewsource.css)
14 * res/forms.css (forms.css)
15 res/arrow.gif (arrow.gif)
16 res/arrowd.gif (arrowd.gif)
18 +% resource gre-resources %res/
19 diff --git a/netwerk/protocol/res/nsResProtocolHandler.cpp b/netwerk/protocol/res/nsResProtocolHandler.cpp
20 --- a/netwerk/protocol/res/nsResProtocolHandler.cpp
21 +++ b/netwerk/protocol/res/nsResProtocolHandler.cpp
22 @@ -75,17 +75,16 @@ static nsResProtocolHandler *gResHandler
24 // this enables PR_LOG_ALWAYS level information and places all output in
27 static PRLogModuleInfo *gResLog;
30 #define kGRE NS_LITERAL_CSTRING("gre")
31 -#define kGRE_RESOURCES NS_LITERAL_CSTRING("gre-resources")
33 //----------------------------------------------------------------------------
34 // nsResURL : overrides nsStandardURL::GetFile to provide nsIFile resolution
35 //----------------------------------------------------------------------------
38 nsResURL::EnsureFile()
40 @@ -197,28 +196,16 @@ nsResProtocolHandler::Init()
41 NS_ENSURE_SUCCESS(rv, rv);
44 // make resource://gre/ point to the GRE directory
46 rv = AddSpecialDir(NS_GRE_DIR, kGRE);
47 NS_ENSURE_SUCCESS(rv, rv);
49 - // make resource://gre-resources/ point to gre toolkit[.jar]/res
50 - nsCOMPtr<nsIURI> greURI;
51 - nsCOMPtr<nsIURI> greResURI;
52 - GetSubstitution(kGRE, getter_AddRefs(greURI));
53 -#ifdef MOZ_CHROME_FILE_FORMAT_JAR
54 - NS_NAMED_LITERAL_CSTRING(strGRE_RES_URL, "jar:chrome/toolkit.jar!/res/");
56 - NS_NAMED_LITERAL_CSTRING(strGRE_RES_URL, "chrome/toolkit/res/");
58 - rv = mIOService->NewURI(strGRE_RES_URL, nsnull, greURI,
59 - getter_AddRefs(greResURI));
60 - SetSubstitution(kGRE_RESOURCES, greResURI);
61 //XXXbsmedberg Neil wants a resource://pchrome/ for the profile chrome dir...
62 // but once I finish multiple chrome registration I'm not sure that it is needed
64 // XXX dveditz: resource://pchrome/ defeats profile directory salting
65 // if web content can load it. Tread carefully.
69 @@ -242,22 +229,16 @@ nsResProtocolHandler::Init(nsIFile *aOmn
70 // these entries should be kept in sync with the normal Init function
72 // resource:/// points to jar:omni.jar!/
73 SetSubstitution(EmptyCString(), uri);
75 // resource://gre/ points to jar:omni.jar!/
76 SetSubstitution(kGRE, uri);
78 - urlStr += "chrome/toolkit/res/";
79 - rv = mIOService->NewURI(urlStr, nsnull, nsnull, getter_AddRefs(uri));
80 - NS_ENSURE_SUCCESS(rv, rv);
82 - // resource://gre-resources/ points to jar:omni.jar!/chrome/toolkit/res/
83 - SetSubstitution(kGRE_RESOURCES, uri);
89 static PLDHashOperator
90 EnumerateSubstitution(const nsACString& aKey,
93 # Parent 3038cccba1a071d6b418e15442d0f2d9f3dcb11d
94 Bug 620931 part 2 - When building --with-libxul-sdk, use the right preferences directory
96 diff --git a/browser/locales/Makefile.in b/browser/locales/Makefile.in
97 --- a/browser/locales/Makefile.in
98 +++ b/browser/locales/Makefile.in
99 @@ -183,17 +183,17 @@ install:: $(addsuffix .xml,$(SEARCH_PLUG
100 $(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/searchplugins
104 $(NSINSTALL) -D $(DIST)/install
105 @$(MAKE) -C ../../toolkit/locales libs-$* BOTH_MANIFESTS=1
106 @$(MAKE) -C ../../services/sync/locales AB_CD=$* XPI_NAME=locale-$* BOTH_MANIFESTS=1
107 @$(MAKE) -C ../../extensions/spellcheck/locales AB_CD=$* XPI_NAME=locale-$* BOTH_MANIFESTS=1
108 - @$(MAKE) libs AB_CD=$* XPI_NAME=locale-$* PREF_DIR=defaults/pref BOTH_MANIFESTS=1
109 + @$(MAKE) libs AB_CD=$* XPI_NAME=locale-$* PREF_DIR=$(PREF_DIR) BOTH_MANIFESTS=1
110 @$(MAKE) -C $(DEPTH)/$(MOZ_BRANDING_DIRECTORY)/locales AB_CD=$* XPI_NAME=locale-$* BOTH_MANIFESTS=1
113 repackage-win32-installer: WIN32_INSTALLER_OUT="$(_ABS_DIST)/$(PKG_INST_PATH)$(PKG_INST_BASENAME).exe"
114 repackage-win32-installer: $(WIN32_INSTALLER_IN) $(SUBMAKEFILES)
115 @echo "Repackaging $(WIN32_INSTALLER_IN) into $(WIN32_INSTALLER_OUT)."
116 $(MAKE) -C $(DEPTH)/$(MOZ_BRANDING_DIRECTORY) export
117 $(MAKE) -C ../installer/windows CONFIG_DIR=l10ngen l10ngen/setup.exe l10ngen/7zSD.sfx
118 diff --git a/toolkit/mozapps/installer/packager.mk b/toolkit/mozapps/installer/packager.mk
119 --- a/toolkit/mozapps/installer/packager.mk
120 +++ b/toolkit/mozapps/installer/packager.mk
121 @@ -307,17 +307,17 @@ OMNIJAR_FILES = \
128 NON_OMNIJAR_FILES += \
130 - defaults/pref/channel-prefs.js \
131 + $(PREF_DIR)/channel-prefs.js \
133 res/MainMenu.nib/\* \
137 rm -f omni.jar components/binary.manifest && \
138 grep -h '^binary-component' components/*.manifest > binary.manifest ; \
139 sed -e 's/^binary-component/\#binary-component/' components/components.manifest > components.manifest && \
141 # Parent cd8df8030f7ad7530692bd7c4391a8009df56a02
142 Bug 620931 part 3 - Allow GRE and XUL application to use omni.jar independently
144 We now store two independent locations for an omni.jar, allowing GRE/XRE and
145 XUL application to each have their own omni.jar. And since xulrunner setups
146 are very independent from the XUL applications, we implement support for both
147 omni.jar and non omni.jar cases in the same runtime, with the side effect of
148 allowing to switch from one to the other manually without rebuilding the
151 We let the mozilla::Omnijar API handle both cases, so that callers don't need
152 too much work to support them.
154 We also make the preferences service load the same set of preferences in all
155 the various cases (unified vs. separate, omni.jar vs. no omni.jar).
157 The child process launcher for IPC is modified to pass the base directories
158 needed for the mozilla::Omnijar API initialization in the child process.
160 Finally, the startupcache file name canonicalization is modified to separate
161 APP and GRE resources.
163 diff --git a/ipc/glue/GeckoChildProcessHost.cpp b/ipc/glue/GeckoChildProcessHost.cpp
164 --- a/ipc/glue/GeckoChildProcessHost.cpp
165 +++ b/ipc/glue/GeckoChildProcessHost.cpp
166 @@ -440,26 +440,29 @@ GeckoChildProcessHost::PerformAsyncLaunc
167 // other end of the socketpair() from us
169 std::vector<std::string> childArgv;
171 childArgv.push_back(exePath.value());
173 childArgv.insert(childArgv.end(), aExtraOpts.begin(), aExtraOpts.end());
176 // Make sure the child process can find the omnijar
177 // See XRE_InitCommandLine in nsAppRunner.cpp
178 - nsCAutoString omnijarPath;
179 - if (mozilla::OmnijarPath()) {
180 - mozilla::OmnijarPath()->GetNativePath(omnijarPath);
181 - childArgv.push_back("-omnijar");
182 - childArgv.push_back(omnijarPath.get());
183 + nsCAutoString path;
184 + nsCOMPtr<nsIFile> file = mozilla::Omnijar::GetBase(mozilla::Omnijar::GRE);
185 + if (file && NS_SUCCEEDED(file->GetNativePath(path))) {
186 + childArgv.push_back("-grebase");
187 + childArgv.push_back(path.get());
190 + file = mozilla::Omnijar::GetBase(mozilla::Omnijar::APP);
191 + if (file && NS_SUCCEEDED(file->GetNativePath(path))) {
192 + childArgv.push_back("-appbase");
193 + childArgv.push_back(path.get());
196 childArgv.push_back(pidstring);
198 #if defined(MOZ_CRASHREPORTER)
199 # if defined(OS_LINUX)
200 int childCrashFd, childCrashRemapFd;
201 if (!CrashReporter::CreateNotificationPipeForChild(
202 &childCrashFd, &childCrashRemapFd))
203 @@ -552,26 +555,29 @@ GeckoChildProcessHost::PerformAsyncLaunc
204 for (std::vector<std::string>::iterator it = aExtraOpts.begin();
205 it != aExtraOpts.end();
207 cmdLine.AppendLooseValue(UTF8ToWide(*it));
210 cmdLine.AppendLooseValue(std::wstring(mGroupId.get()));
213 // Make sure the child process can find the omnijar
214 // See XRE_InitCommandLine in nsAppRunner.cpp
215 - nsAutoString omnijarPath;
216 - if (mozilla::OmnijarPath()) {
217 - mozilla::OmnijarPath()->GetPath(omnijarPath);
218 - cmdLine.AppendLooseValue(UTF8ToWide("-omnijar"));
219 - cmdLine.AppendLooseValue(omnijarPath.get());
221 + nsCOMPtr<nsIFile> file = mozilla::Omnijar::GetBase(mozilla::Omnijar::GRE);
222 + if (file && NS_SUCCEEDED(file->GetPath(path))) {
223 + cmdLine.AppendLooseValue(UTF8ToWide("-grebase"));
224 + cmdLine.AppendLooseValue(path.get());
227 + file = mozilla::Omnijar::GetBase(mozilla::Omnijar::APP);
228 + if (file && NS_SUCCEEDED(file->GetPath(path))) {
229 + cmdLine.AppendLooseValue(UTF8ToWide("-appbase"));
230 + cmdLine.AppendLooseValue(path.get());
233 cmdLine.AppendLooseValue(UTF8ToWide(pidstring));
235 #if defined(MOZ_CRASHREPORTER)
236 cmdLine.AppendLooseValue(
237 UTF8ToWide(CrashReporter::GetChildNotificationPipe()));
240 diff --git a/js/src/xpconnect/loader/mozJSComponentLoader.cpp b/js/src/xpconnect/loader/mozJSComponentLoader.cpp
241 --- a/js/src/xpconnect/loader/mozJSComponentLoader.cpp
242 +++ b/js/src/xpconnect/loader/mozJSComponentLoader.cpp
244 #include "nsIConsoleService.h"
245 #include "nsIStorageStream.h"
246 #include "nsIStringStream.h"
249 #include "nsILocalFileWin.h"
251 #include "xpcprivate.h"
252 +#include "nsIResProtocolHandler.h"
254 #ifdef MOZ_ENABLE_LIBXUL
255 #include "mozilla/scache/StartupCache.h"
256 #include "mozilla/scache/StartupCacheUtils.h"
258 #include "mozilla/Omnijar.h"
260 #include "jsdbgapi.h"
261 @@ -621,34 +622,21 @@ mozJSComponentLoader::LoadModule(nsILoca
263 const mozilla::Module*
264 mozJSComponentLoader::LoadModuleFromJAR(nsILocalFile *aJarFile,
265 const nsACString &aComponentPath)
267 #if !defined(XPCONNECT_STANDALONE)
270 - nsCAutoString fullSpec;
274 - rv = aJarFile->Equals(mozilla::OmnijarPath(), &equal);
275 - if (NS_SUCCEEDED(rv) && equal) {
276 - fullSpec = "resource://gre/";
279 - nsCAutoString fileSpec;
280 - NS_GetURLSpecFromActualFile(aJarFile, fileSpec);
282 - fullSpec += fileSpec;
288 + nsCAutoString fullSpec, fileSpec;
289 + NS_GetURLSpecFromActualFile(aJarFile, fileSpec);
291 + fullSpec += fileSpec;
293 fullSpec += aComponentPath;
295 nsCOMPtr<nsIURI> uri;
296 rv = NS_NewURI(getter_AddRefs(uri), fullSpec);
300 nsAutoString hashstring;
301 @@ -833,57 +821,138 @@ class JSScriptHolder
302 JSScriptHolder(JSContext *cx, JSScript *script)
303 : mCx(cx), mScript(script) {}
304 ~JSScriptHolder() { ::JS_DestroyScript(mCx, mScript); }
310 +static const char baseName[2][5] = { "gre/", "app/" };
312 +static inline PRBool
313 +canonicalizeBase(nsCAutoString &spec, nsACString &out, mozilla::Omnijar::Type aType)
315 + nsCAutoString base;
316 + nsresult rv = mozilla::Omnijar::GetURIString(aType, base);
318 + if (NS_FAILED(rv) || !base.Length())
321 + if (base.Compare(spec.get(), PR_FALSE, base.Length()))
324 + out.Append("/resource/");
325 + out.Append(baseName[aType]);
326 + out.Append(Substring(spec, base.Length()));
330 * PathifyURI transforms mozilla .js uris into useful zip paths
331 * to make it makes it easier to manipulate startup cache entries
332 * using standard zip tools.
333 * Transformations applied:
334 - * * jsloader/<scheme> prefix is used to group mozJSComponentLoader cache entries in
335 + * * jsloader/ prefix is used to group mozJSComponentLoader cache entries in
336 * a top-level zip directory.
337 - * * In MOZ_OMNIJAR case resource:/// and resource://gre/ URIs refer to the same path
338 - * so treat both of them as resource://gre/
339 + * * resource:// URIs are resolved to their corresponding file/jar URI to
340 + * canonicalize resources URIs other than gre and app.
341 + * * Paths under GRE or APP directory have their base path replaced with
342 + * resource/gre or resource/app to avoid depending on install location.
343 + * * jar:file:///path/to/file.jar!/sub/path urls are replaced with
344 + * /path/to/file.jar/sub/path
345 * * .bin suffix is added to the end of the path to indicate that jsloader/ entries
346 * are binary representations of JS source.
348 - * resource://gre/modules/XPCOMUtils.jsm becomes
349 - * jsloader/resource/gre/modules/XPCOMUtils.jsm.bin
350 + * resource://gre/modules/XPCOMUtils.jsm or
351 + * file://$GRE_DIR/modules/XPCOMUtils.jsm or
352 + * jar:file://$GRE_DIR/omni.jar!/modules/XPCOMUtils.jsm become
353 + * jsloader/resource/gre/modules/XPCOMUtils.jsm.bin
354 + * file://$PROFILE_DIR/extensions/{uuid}/components/component.js becomes
355 + * jsloader/$PROFILE_DIR/extensions/%7Buuid%7D/components/component.js.bin
356 + * jar:file://$PROFILE_DIR/extensions/some.xpi!/components/component.js becomes
357 + * jsloader/$PROFILE_DIR/extensions/some.xpi/components/component.js.bin
360 PathifyURI(nsIURI *in, nsACString &out)
363 - nsCAutoString scheme;
364 - nsresult rv = in->GetScheme(scheme);
365 - NS_ENSURE_SUCCESS(rv, rv);
366 - out.Append(scheme);
367 - nsCAutoString host;
368 - // OK for GetHost to fail since it's not implemented sometimes
371 - if (scheme.Equals("resource") && host.Length() == 0){
375 - if (host.Length()) {
379 - nsCAutoString path;
380 - rv = in->GetPath(path);
381 - NS_ENSURE_SUCCESS(rv, rv);
383 - out.Append(".bin");
387 + nsCOMPtr<nsIURI> uri = in;
388 + nsCAutoString spec;
392 + // Resolve resource:// URIs. At the end of this if/else block, we
393 + // have both spec and uri variables identifying the same URI.
394 + if (NS_SUCCEEDED(in->SchemeIs("resource", &equals)) && equals) {
395 + nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
396 + NS_ENSURE_SUCCESS(rv, rv);
398 + nsCOMPtr<nsIProtocolHandler> ph;
399 + rv = ioService->GetProtocolHandler("resource", getter_AddRefs(ph));
400 + NS_ENSURE_SUCCESS(rv, rv);
402 + nsCOMPtr<nsIResProtocolHandler> irph(do_QueryInterface(ph, &rv));
403 + NS_ENSURE_SUCCESS(rv, rv);
405 + rv = irph->ResolveURI(in, spec);
406 + NS_ENSURE_SUCCESS(rv, rv);
408 + rv = ioService->NewURI(spec, nsnull, nsnull, getter_AddRefs(uri));
409 + NS_ENSURE_SUCCESS(rv, rv);
411 + rv = in->GetSpec(spec);
412 + NS_ENSURE_SUCCESS(rv, rv);
415 + if (!canonicalizeBase(spec, out, mozilla::Omnijar::GRE) &&
416 + !canonicalizeBase(spec, out, mozilla::Omnijar::APP)) {
417 + if (NS_SUCCEEDED(uri->SchemeIs("file", &equals)) && equals) {
418 + nsCOMPtr<nsIFileURL> baseFileURL;
419 + baseFileURL = do_QueryInterface(uri, &rv);
420 + NS_ENSURE_SUCCESS(rv, rv);
422 + nsCAutoString path;
423 + rv = baseFileURL->GetPath(path);
424 + NS_ENSURE_SUCCESS(rv, rv);
427 + } else if (NS_SUCCEEDED(uri->SchemeIs("jar", &equals)) && equals) {
428 + nsCOMPtr<nsIJARURI> jarURI = do_QueryInterface(uri, &rv);
429 + NS_ENSURE_SUCCESS(rv, rv);
431 + nsCOMPtr<nsIURI> jarFileURI;
432 + rv = jarURI->GetJARFile(getter_AddRefs(jarFileURI));
433 + NS_ENSURE_SUCCESS(rv, rv);
435 + nsCOMPtr<nsIFileURL> jarFileURL;
436 + jarFileURL = do_QueryInterface(jarFileURI, &rv);
437 + NS_ENSURE_SUCCESS(rv, rv);
439 + nsCAutoString path;
440 + rv = jarFileURL->GetPath(path);
441 + NS_ENSURE_SUCCESS(rv, rv);
444 + rv = jarURI->GetJAREntry(path);
445 + NS_ENSURE_SUCCESS(rv, rv);
448 + } else { // Very unlikely
449 + nsCAutoString spec;
450 + rv = uri->GetSpec(spec);
451 + NS_ENSURE_SUCCESS(rv, rv);
458 + out.Append(".bin");
463 #ifdef MOZ_ENABLE_LIBXUL
465 mozJSComponentLoader::ReadScript(StartupCache* cache, nsIURI *uri,
466 JSContext *cx, JSScript **script)
468 diff --git a/modules/libjar/nsJAR.cpp b/modules/libjar/nsJAR.cpp
469 --- a/modules/libjar/nsJAR.cpp
470 +++ b/modules/libjar/nsJAR.cpp
471 @@ -171,26 +171,23 @@ nsJAR::Open(nsIFile* zipFile)
472 if (mLock) return NS_ERROR_FAILURE; // Already open!
475 mOuterZipEntry.Truncate();
477 mLock = PR_NewLock();
478 NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
481 // The omnijar is special, it is opened early on and closed late
482 // this avoids reopening it
484 - nsresult rv = zipFile->Equals(mozilla::OmnijarPath(), &equals);
485 - if (NS_SUCCEEDED(rv) && equals) {
486 - mZip = mozilla::OmnijarReader();
487 + nsZipArchive *zip = mozilla::Omnijar::GetReader(zipFile);
493 return mZip->OpenArchive(zipFile);
497 nsJAR::OpenInner(nsIZipReader *aZipReader, const char *aZipEntry)
499 NS_ENSURE_ARG_POINTER(aZipReader);
500 NS_ENSURE_ARG_POINTER(aZipEntry);
501 @@ -234,23 +231,22 @@ nsJAR::Close()
505 mParsedManifest = PR_FALSE;
506 mManifestData.Reset();
507 mGlobalStatus = JAR_MANIFEST_NOT_PARSED;
508 mTotalItemsInManifest = 0;
511 - if (mZip == mozilla::OmnijarReader()) {
512 + if ((mZip == mozilla::Omnijar::GetReader(mozilla::Omnijar::GRE)) ||
513 + (mZip == mozilla::Omnijar::GetReader(mozilla::Omnijar::APP))) {
515 mZip = new nsZipArchive();
519 return mZip->CloseArchive();
523 nsJAR::Test(const char *aEntryName)
525 return mZip->Test(aEntryName);
527 @@ -391,22 +387,21 @@ nsJAR::GetInputStreamWithSpec(const nsAC
529 nsJAR::GetCertificatePrincipal(const char* aFilename, nsIPrincipal** aPrincipal)
533 return NS_ERROR_NULL_POINTER;
534 *aPrincipal = nsnull;
537 // Don't check signatures in the omnijar - this is only
538 // interesting for extensions/XPIs.
539 - if (mZip == mozilla::OmnijarReader())
540 + if ((mZip == mozilla::Omnijar::GetReader(mozilla::Omnijar::GRE)) ||
541 + (mZip == mozilla::Omnijar::GetReader(mozilla::Omnijar::APP)))
545 //-- Parse the manifest
546 nsresult rv = ParseManifest();
547 if (NS_FAILED(rv)) return rv;
548 if (mGlobalStatus == JAR_NO_MANIFEST)
551 PRInt16 requestedStatus;
552 diff --git a/modules/libpref/src/nsPrefService.cpp b/modules/libpref/src/nsPrefService.cpp
553 --- a/modules/libpref/src/nsPrefService.cpp
554 +++ b/modules/libpref/src/nsPrefService.cpp
558 #include "prefread.h"
559 #include "prefapi_private_data.h"
560 #include "PrefTuple.h"
562 #include "nsITimelineService.h"
565 #include "mozilla/Omnijar.h"
566 #include "nsZipArchive.h"
570 #define INITIAL_PREF_FILES 10
571 static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
574 static nsresult openPrefFile(nsIFile* aFile);
575 static nsresult pref_InitInitialObjects(void);
576 @@ -793,124 +791,144 @@ static nsresult pref_LoadPrefsInDirList(
577 pref_LoadPrefsInDir(dir, nsnull, 0);
585 -//----------------------------------------------------------------------------------------
586 -// Initialize default preference JavaScript buffers from
587 -// appropriate TEXT resources
588 -//----------------------------------------------------------------------------------------
589 -static nsresult pref_InitDefaults()
591 - nsCOMPtr<nsIFile> greprefsFile;
594 - rv = NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(greprefsFile));
595 - NS_ENSURE_SUCCESS(rv, rv);
597 - rv = greprefsFile->AppendNative(NS_LITERAL_CSTRING("greprefs.js"));
598 - NS_ENSURE_SUCCESS(rv, rv);
600 - rv = openPrefFile(greprefsFile);
601 - if (NS_FAILED(rv)) {
602 - NS_WARNING("Error parsing GRE default preferences. Is this an old-style embedding app?");
609 static nsresult pref_ReadPrefFromJar(nsZipArchive* jarReader, const char *name)
611 nsZipItemPtr<char> manifest(jarReader, name, true);
612 NS_ENSURE_TRUE(manifest.Buffer(), NS_ERROR_NOT_AVAILABLE);
615 PREF_InitParseState(&ps, PREF_ReaderCallback, NULL);
616 nsresult rv = PREF_ParseBuf(&ps, manifest, manifest.Length());
617 PREF_FinalizeParseState(&ps);
622 -static nsresult pref_InitAppDefaultsFromOmnijar()
626 - nsZipArchive* jarReader = mozilla::OmnijarReader();
628 - return pref_InitDefaults();
630 - rv = pref_ReadPrefFromJar(jarReader, "greprefs.js");
631 - NS_ENSURE_SUCCESS(rv, rv);
633 - nsZipFind *findPtr;
634 - rv = jarReader->FindInit("defaults/pref/*.js$", &findPtr);
635 - NS_ENSURE_SUCCESS(rv, rv);
637 - nsAutoPtr<nsZipFind> find(findPtr);
639 - nsTArray<nsCString> prefEntries;
640 - const char *entryName;
641 - PRUint16 entryNameLen;
642 - while (NS_SUCCEEDED(find->FindNext(&entryName, &entryNameLen))) {
643 - prefEntries.AppendElement(Substring(entryName, entryName + entryNameLen));
646 - prefEntries.Sort();
647 - for (PRUint32 i = prefEntries.Length(); i--; ) {
648 - rv = pref_ReadPrefFromJar(jarReader, prefEntries[i].get());
650 - NS_WARNING("Error parsing preferences.");
657 +//----------------------------------------------------------------------------------------
658 +// Initialize default preference JavaScript buffers from
659 +// appropriate TEXT resources
660 +//----------------------------------------------------------------------------------------
661 static nsresult pref_InitInitialObjects()
665 - // first we parse the GRE default prefs. This also works if we're not using a GRE,
667 - rv = pref_InitAppDefaultsFromOmnijar();
669 - rv = pref_InitDefaults();
671 - NS_ENSURE_SUCCESS(rv, rv);
672 + // In omni.jar case, we load the following prefs:
673 + // - jar:$gre/omni.jar!/greprefs.js
674 + // - jar:$gre/omni.jar!/defaults/pref/*.js
675 + // In non omni.jar case, we load:
676 + // - $gre/greprefs.js
678 + // When $app == $gre, we additionally load, in all cases:
679 + // - $gre/defaults/pref/*.js
680 + // This is kept for bug 591866 (channel-prefs.js should not be in omni.jar).
681 + // We load all files instead of channel-prefs.js only to have the same
682 + // behaviour as $app != $gre.
684 + // When $app != $gre, we additionally load, in omni.jar case:
685 + // - jar:$app/omni.jar!/defaults/preferences/*.js
686 + // - $app/defaults/preferences/*.js
687 + // and in non omni.jar case:
688 + // - $app/defaults/preferences/*.js
690 - nsCOMPtr<nsIFile> defaultPrefDir;
691 - // now parse the "application" default preferences
692 - rv = NS_GetSpecialDirectory(NS_APP_PREF_DEFAULTS_50_DIR, getter_AddRefs(defaultPrefDir));
693 - NS_ENSURE_SUCCESS(rv, rv);
694 + nsZipFind *findPtr;
695 + nsAutoPtr<nsZipFind> find;
696 + nsTArray<nsCString> prefEntries;
697 + const char *entryName;
698 + PRUint16 entryNameLen;
700 - /* these pref file names should not be used: we process them after all other application pref files for backwards compatibility */
701 - static const char* specialFiles[] = {
702 + nsZipArchive* jarReader = mozilla::Omnijar::GetReader(mozilla::Omnijar::GRE);
704 + // Load jar:$gre/omni.jar!/greprefs.js
705 + rv = pref_ReadPrefFromJar(jarReader, "greprefs.js");
706 + NS_ENSURE_SUCCESS(rv, rv);
708 + // Load jar:$gre/omni.jar!/defaults/pref/*.js
709 + rv = jarReader->FindInit("defaults/pref/*.js$", &findPtr);
710 + NS_ENSURE_SUCCESS(rv, rv);
713 + while (NS_SUCCEEDED(find->FindNext(&entryName, &entryNameLen))) {
714 + prefEntries.AppendElement(Substring(entryName, entryName + entryNameLen));
717 + prefEntries.Sort();
718 + for (PRUint32 i = prefEntries.Length(); i--; ) {
719 + rv = pref_ReadPrefFromJar(jarReader, prefEntries[i].get());
721 + NS_WARNING("Error parsing preferences.");
724 + // Load $gre/greprefs.js
725 + nsCOMPtr<nsIFile> greprefsFile;
726 + rv = NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(greprefsFile));
727 + NS_ENSURE_SUCCESS(rv, rv);
729 + rv = greprefsFile->AppendNative(NS_LITERAL_CSTRING("greprefs.js"));
730 + NS_ENSURE_SUCCESS(rv, rv);
732 + rv = openPrefFile(greprefsFile);
734 + NS_WARNING("Error parsing GRE default preferences. Is this an old-style embedding app?");
737 + if (!mozilla::Omnijar::HasOmnijar(mozilla::Omnijar::APP)) {
738 + // Load $gre/defaults/pref/*.js
739 + nsCOMPtr<nsIFile> defaultPrefDir;
741 + rv = NS_GetSpecialDirectory(NS_APP_PREF_DEFAULTS_50_DIR, getter_AddRefs(defaultPrefDir));
742 + NS_ENSURE_SUCCESS(rv, rv);
744 + /* these pref file names should not be used: we process them after all other application pref files for backwards compatibility */
745 + static const char* specialFiles[] = {
746 #if defined(XP_MAC) || defined(XP_MACOSX)
748 #elif defined(XP_WIN)
750 #elif defined(XP_UNIX)
758 #elif defined(XP_OS2)
760 +#elif defined(XP_BEOS)
766 - rv = pref_LoadPrefsInDir(defaultPrefDir, specialFiles, NS_ARRAY_LENGTH(specialFiles));
767 - if (NS_FAILED(rv)) {
768 - NS_WARNING("Error parsing application default preferences.");
769 + rv = pref_LoadPrefsInDir(defaultPrefDir, specialFiles, NS_ARRAY_LENGTH(specialFiles));
771 + NS_WARNING("Error parsing application default preferences.");
774 + // Load jar:$app/omni.jar!/defaults/preferences/*.js
775 + nsZipArchive *appJarReader = mozilla::Omnijar::GetReader(mozilla::Omnijar::APP);
776 + if (appJarReader) {
777 + rv = appJarReader->FindInit("defaults/preferences/*.js$", &findPtr);
778 + NS_ENSURE_SUCCESS(rv, rv);
780 + prefEntries.Clear();
781 + while (NS_SUCCEEDED(find->FindNext(&entryName, &entryNameLen))) {
782 + prefEntries.AppendElement(Substring(entryName, entryName + entryNameLen));
784 + prefEntries.Sort();
785 + for (PRUint32 i = prefEntries.Length(); i--; ) {
786 + rv = pref_ReadPrefFromJar(appJarReader, prefEntries[i].get());
788 + NS_WARNING("Error parsing preferences.");
792 rv = pref_LoadPrefsInDirList(NS_APP_PREFS_DEFAULTS_DIR_LIST);
793 NS_ENSURE_SUCCESS(rv, rv);
795 NS_CreateServicesFromCategory(NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID,
796 nsnull, NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID);
798 diff --git a/netwerk/protocol/res/nsResProtocolHandler.cpp b/netwerk/protocol/res/nsResProtocolHandler.cpp
799 --- a/netwerk/protocol/res/nsResProtocolHandler.cpp
800 +++ b/netwerk/protocol/res/nsResProtocolHandler.cpp
801 @@ -152,97 +152,62 @@ nsResProtocolHandler::nsResProtocolHandl
804 nsResProtocolHandler::~nsResProtocolHandler()
806 gResHandler = nsnull;
810 -nsResProtocolHandler::AddSpecialDir(const char* aSpecialDir, const nsACString& aSubstitution)
812 - nsCOMPtr<nsIFile> file;
813 - nsresult rv = NS_GetSpecialDirectory(aSpecialDir, getter_AddRefs(file));
814 - NS_ENSURE_SUCCESS(rv, rv);
816 - nsCOMPtr<nsIURI> uri;
817 - rv = mIOService->NewFileURI(file, getter_AddRefs(uri));
818 - NS_ENSURE_SUCCESS(rv, rv);
820 - return SetSubstitution(aSubstitution, uri);
824 nsResProtocolHandler::Init()
826 if (!mSubstitutions.Init(32))
827 return NS_ERROR_UNEXPECTED;
831 mIOService = do_GetIOService(&rv);
832 NS_ENSURE_SUCCESS(rv, rv);
835 - nsCOMPtr<nsIFile> omniJar(mozilla::OmnijarPath());
837 - return Init(omniJar);
840 - // these entries should be kept in sync with the omnijar Init function
841 + nsCAutoString appURI, greURI;
842 + rv = mozilla::Omnijar::GetURIString(mozilla::Omnijar::APP, appURI);
843 + NS_ENSURE_SUCCESS(rv, rv);
844 + rv = mozilla::Omnijar::GetURIString(mozilla::Omnijar::GRE, greURI);
845 + NS_ENSURE_SUCCESS(rv, rv);
848 - // make resource:/// point to the application directory
849 + // make resource:/// point to the application directory or omnijar
851 - rv = AddSpecialDir(NS_OS_CURRENT_PROCESS_DIR, EmptyCString());
852 + nsCOMPtr<nsIURI> uri;
853 + rv = NS_NewURI(getter_AddRefs(uri), appURI.Length() ? appURI : greURI);
854 + NS_ENSURE_SUCCESS(rv, rv);
856 + rv = SetSubstitution(EmptyCString(), uri);
857 NS_ENSURE_SUCCESS(rv, rv);
860 // make resource://gre/ point to the GRE directory
862 - rv = AddSpecialDir(NS_GRE_DIR, kGRE);
863 + if (appURI.Length()) { // We already have greURI in uri if appURI.Length() is 0.
864 + rv = NS_NewURI(getter_AddRefs(uri), greURI);
865 + NS_ENSURE_SUCCESS(rv, rv);
868 + rv = SetSubstitution(kGRE, uri);
869 NS_ENSURE_SUCCESS(rv, rv);
871 //XXXbsmedberg Neil wants a resource://pchrome/ for the profile chrome dir...
872 // but once I finish multiple chrome registration I'm not sure that it is needed
874 // XXX dveditz: resource://pchrome/ defeats profile directory salting
875 // if web content can load it. Tread carefully.
882 -nsResProtocolHandler::Init(nsIFile *aOmniJar)
885 - nsCOMPtr<nsIURI> uri;
886 - nsCAutoString omniJarSpec;
887 - NS_GetURLSpecFromActualFile(aOmniJar, omniJarSpec, mIOService);
889 - nsCAutoString urlStr("jar:");
890 - urlStr += omniJarSpec;
893 - rv = mIOService->NewURI(urlStr, nsnull, nsnull, getter_AddRefs(uri));
894 - NS_ENSURE_SUCCESS(rv, rv);
896 - // these entries should be kept in sync with the normal Init function
898 - // resource:/// points to jar:omni.jar!/
899 - SetSubstitution(EmptyCString(), uri);
901 - // resource://gre/ points to jar:omni.jar!/
902 - SetSubstitution(kGRE, uri);
909 static PLDHashOperator
910 EnumerateSubstitution(const nsACString& aKey,
914 nsTArray<ResourceMapping>* resources =
915 static_cast<nsTArray<ResourceMapping>*>(aArg);
916 diff --git a/startupcache/StartupCache.cpp b/startupcache/StartupCache.cpp
917 --- a/startupcache/StartupCache.cpp
918 +++ b/startupcache/StartupCache.cpp
919 @@ -237,27 +237,36 @@ StartupCache::GetBuffer(const char* id,
920 nsZipItemPtr<char> zipItem(mArchive, id, true);
922 *outbuf = zipItem.Forget();
923 *length = zipItem.Length();
929 - if (mozilla::OmnijarReader()) {
930 + if (mozilla::Omnijar::GetReader(mozilla::Omnijar::APP)) {
931 // no need to checksum omnijarred entries
932 - nsZipItemPtr<char> zipItem(mozilla::OmnijarReader(), id);
933 + nsZipItemPtr<char> zipItem(mozilla::Omnijar::GetReader(mozilla::Omnijar::APP), id);
935 *outbuf = zipItem.Forget();
936 *length = zipItem.Length();
942 + if (mozilla::Omnijar::GetReader(mozilla::Omnijar::GRE)) {
943 + // no need to checksum omnijarred entries
944 + nsZipItemPtr<char> zipItem(mozilla::Omnijar::GetReader(mozilla::Omnijar::GRE), id);
946 + *outbuf = zipItem.Forget();
947 + *length = zipItem.Length();
952 return NS_ERROR_NOT_AVAILABLE;
955 // Makes a copy of the buffer, client retains ownership of inbuf.
957 StartupCache::PutBuffer(const char* id, const char* inbuf, PRUint32 len)
960 diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp
961 --- a/toolkit/xre/nsAppRunner.cpp
962 +++ b/toolkit/xre/nsAppRunner.cpp
963 @@ -3897,35 +3897,45 @@ XRE_InitCommandLine(int aArgc, char* aAr
964 CommandLine::Init(aArgc, canonArgs);
966 for (int i = 0; i < aArgc; ++i)
973 - const char *omnijarPath = nsnull;
974 - ArgResult ar = CheckArg("omnijar", PR_FALSE, &omnijarPath);
975 + const char *path = nsnull;
976 + ArgResult ar = CheckArg("grebase", PR_FALSE, &path);
978 - PR_fprintf(PR_STDERR, "Error: argument -omnijar requires an omnijar path\n");
979 + PR_fprintf(PR_STDERR, "Error: argument -grebase requires a path argument\n");
980 return NS_ERROR_FAILURE;
987 - nsCOMPtr<nsILocalFile> omnijar;
988 - rv = NS_NewNativeLocalFile(nsDependentCString(omnijarPath), PR_TRUE,
989 - getter_AddRefs(omnijar));
990 - if (NS_SUCCEEDED(rv))
991 - mozilla::SetOmnijar(omnijar);
995 + nsCOMPtr<nsILocalFile> greBase;
996 + rv = XRE_GetFileFromPath(path, getter_AddRefs(greBase));
1000 + ar = CheckArg("appbase", PR_FALSE, &path);
1001 + if (ar == ARG_BAD) {
1002 + PR_fprintf(PR_STDERR, "Error: argument -appbase requires a path argument\n");
1003 + return NS_ERROR_FAILURE;
1006 + nsCOMPtr<nsILocalFile> appBase;
1008 + rv = XRE_GetFileFromPath(path, getter_AddRefs(appBase));
1009 + if (NS_FAILED(rv))
1013 + return mozilla::Omnijar::SetBase(greBase, appBase);
1017 XRE_DeinitCommandLine()
1019 nsresult rv = NS_OK;
1021 #if defined(MOZ_IPC)
1022 diff --git a/toolkit/xre/nsEmbedFunctions.cpp b/toolkit/xre/nsEmbedFunctions.cpp
1023 --- a/toolkit/xre/nsEmbedFunctions.cpp
1024 +++ b/toolkit/xre/nsEmbedFunctions.cpp
1025 @@ -512,19 +512,17 @@ XRE_InitChildProcess(int aArgc,
1028 // Run the UI event loop on the main thread.
1029 uiMessageLoop.MessageLoop::Run();
1031 // Allow ProcessChild to clean up after itself before going out of
1032 // scope and being deleted
1035 - mozilla::SetOmnijar(nsnull);
1037 + mozilla::Omnijar::SetBase(nsnull, nsnull);
1042 return XRE_DeinitCommandLine();
1046 diff --git a/xpcom/build/Makefile.in b/xpcom/build/Makefile.in
1047 --- a/xpcom/build/Makefile.in
1048 +++ b/xpcom/build/Makefile.in
1049 @@ -64,28 +64,25 @@ CSRCS = \
1053 $(XPCOM_GLUE_SRC_LCPPSRCS) \
1054 $(XPCOM_GLUENS_SRC_LCPPSRCS) \
1056 nsXPCOMStrings.cpp \
1061 ifndef MOZ_ENABLE_LIBXUL
1062 ifeq (,$(filter-out WINNT WINCE OS2,$(OS_ARCH)))
1063 CPPSRCS += dlldeps.cpp
1068 -CPPSRCS += Omnijar.cpp
1071 SHARED_LIBRARY_LIBS = \
1072 $(DEPTH)/chrome/src/$(LIB_PREFIX)chrome_s.$(LIB_SUFFIX) \
1073 ../ds/$(LIB_PREFIX)xpcomds_s.$(LIB_SUFFIX) \
1074 ../io/$(LIB_PREFIX)xpcomio_s.$(LIB_SUFFIX) \
1075 ../components/$(LIB_PREFIX)xpcomcomponents_s.$(LIB_SUFFIX) \
1076 ../threads/$(LIB_PREFIX)xpcomthreads_s.$(LIB_SUFFIX) \
1077 ../proxy/src/$(LIB_PREFIX)xpcomproxy_s.$(LIB_SUFFIX) \
1078 ../base/$(LIB_PREFIX)xpcombase_s.$(LIB_SUFFIX) \
1079 diff --git a/xpcom/build/Omnijar.cpp b/xpcom/build/Omnijar.cpp
1080 --- a/xpcom/build/Omnijar.cpp
1081 +++ b/xpcom/build/Omnijar.cpp
1084 * The Initial Developer of the Original Code is
1085 * Mozilla Foundation.
1086 * Portions created by the Initial Developer are Copyright (C) 2010
1087 * the Initial Developer. All Rights Reserved.
1090 * Michael Wu <mwu@mozilla.com>
1091 + * Mike Hommey <mh@glandium.org>
1093 * Alternatively, the contents of this file may be used under the terms of
1094 * either the GNU General Public License Version 2 or later (the "GPL"), or
1095 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
1096 * in which case the provisions of the GPL or the LGPL are applicable instead
1097 * of those above. If you wish to allow use of your version of this file only
1098 * under the terms of either the GPL or the LGPL, and not to allow others to
1099 * use your version of this file under the terms of the MPL, indicate your
1100 @@ -33,69 +34,175 @@
1101 * and other provisions required by the GPL or the LGPL. If you do not delete
1102 * the provisions above, a recipient may use your version of this file under
1103 * the terms of any one of the MPL, the GPL or the LGPL.
1105 * ***** END LICENSE BLOCK ***** */
1107 #include "Omnijar.h"
1109 -#include "nsILocalFile.h"
1110 -#include "nsXULAppAPI.h"
1111 +#include "nsIFile.h"
1112 #include "nsZipArchive.h"
1113 +#include "nsNetUtil.h"
1115 -static nsILocalFile* sOmnijarPath = nsnull;
1116 -static nsZipArchive* sOmnijarReader = nsnull;
1117 +namespace mozilla {
1121 +nsIFile *Omnijar::sPath[2] = { nsnull, nsnull };
1122 +PRBool Omnijar::sIsOmnijar[2] = { PR_FALSE, PR_FALSE };
1124 +#ifdef MOZ_ENABLE_LIBXUL
1125 +nsZipArchive *Omnijar::sReader[2] = { nsnull, nsnull };
1128 +static already_AddRefed<nsIFile>
1129 +ComputePath(nsIFile *aPath, PRBool &aIsOmnijar)
1131 - if (!sOmnijarPath) {
1134 + aIsOmnijar = PR_FALSE;
1135 + if (!aPath || NS_FAILED(aPath->IsDirectory(&isDir)) || !isDir)
1138 + nsCOMPtr<nsIFile> path;
1139 +#ifdef MOZ_ENABLE_LIBXUL
1140 + // Search for omni.jar in the given directory
1141 + if (!isDir || NS_FAILED(aPath->Clone(getter_AddRefs(path))))
1144 + if (NS_FAILED(path->AppendNative(NS_LITERAL_CSTRING("omni.jar"))))
1147 + if (NS_FAILED(path->Exists(&aIsOmnijar)))
1151 + if (!aIsOmnijar && NS_FAILED(aPath->Clone(getter_AddRefs(path))))
1154 + return path.forget();
1158 +Omnijar::SetBase(nsIFile *aGrePath, nsIFile *aAppPath)
1160 + NS_ABORT_IF_FALSE(aGrePath || !aAppPath, "Omnijar::SetBase(NULL, something) call forbidden");
1162 +#ifdef MOZ_ENABLE_LIBXUL
1163 + if (sReader[GRE]) {
1164 + sReader[GRE]->CloseArchive();
1165 + delete sReader[GRE];
1167 + if (sReader[APP]) {
1168 + sReader[APP]->CloseArchive();
1169 + delete sReader[APP];
1171 + sReader[APP] = sReader[GRE] = nsnull;
1177 + rv = aAppPath->Equals(aGrePath, &equals);
1178 + NS_ENSURE_SUCCESS(rv, rv);
1183 - nsZipArchive* zipReader = new nsZipArchive();
1185 - NS_IF_RELEASE(sOmnijarPath);
1187 + nsCOMPtr<nsIFile> grePath = ComputePath(aGrePath, sIsOmnijar[GRE]);
1188 + nsCOMPtr<nsIFile> appPath = ComputePath(equals ? nsnull : aAppPath, sIsOmnijar[APP]);
1190 + NS_IF_RELEASE(sPath[GRE]);
1191 + sPath[GRE] = grePath;
1192 + NS_IF_ADDREF(sPath[GRE]);
1194 + NS_IF_RELEASE(sPath[APP]);
1195 + sPath[APP] = appPath;
1196 + NS_IF_ADDREF(sPath[APP]);
1201 +already_AddRefed<nsIFile>
1202 +Omnijar::GetBase(Type aType)
1204 + NS_ABORT_IF_FALSE(sPath[0], "Omnijar not initialized");
1206 + if (!sIsOmnijar[aType]) {
1207 + NS_IF_ADDREF(sPath[aType]);
1208 + return sPath[aType];
1211 - if (NS_FAILED(zipReader->OpenArchive(sOmnijarPath))) {
1212 + nsCOMPtr<nsIFile> file, path;
1213 + if (NS_FAILED(sPath[aType]->Clone(getter_AddRefs(file))))
1216 + if (NS_FAILED(file->GetParent(getter_AddRefs(path))))
1218 + return path.forget();
1221 +#ifdef MOZ_ENABLE_LIBXUL
1223 +Omnijar::GetReader(Type aType)
1225 + if (!sIsOmnijar[aType])
1228 + if (sReader[aType])
1229 + return sReader[aType];
1231 + nsZipArchive* zipReader = new nsZipArchive();
1235 + if (NS_FAILED(zipReader->OpenArchive(sPath[aType]))) {
1237 - NS_IF_RELEASE(sOmnijarPath);
1242 - sOmnijarReader = zipReader;
1243 + return (sReader[aType] = zipReader);
1247 -mozilla::OmnijarPath()
1249 +Omnijar::GetReader(nsIFile *aPath)
1251 - if (!sOmnijarReader)
1256 - return sOmnijarPath;
1257 + if (sIsOmnijar[GRE]) {
1258 + rv = sPath[GRE]->Equals(aPath, &equals);
1259 + if (NS_SUCCEEDED(rv) && equals)
1260 + return GetReader(GRE);
1262 + if (sIsOmnijar[APP]) {
1263 + rv = sPath[APP]->Equals(aPath, &equals);
1264 + if (NS_SUCCEEDED(rv) && equals)
1265 + return GetReader(APP);
1272 +Omnijar::GetURIString(Type aType, nsCString &result)
1274 + NS_ABORT_IF_FALSE(sPath[0], "Omnijar not initialized");
1278 + if ((aType == APP) && (!sPath[APP]))
1281 + nsCAutoString omniJarSpec;
1282 + nsresult rv = NS_GetURLSpecFromActualFile(sPath[aType], omniJarSpec);
1283 + NS_ENSURE_SUCCESS(rv, rv);
1285 + if (sIsOmnijar[aType]) {
1287 + result += omniJarSpec;
1290 + result = omniJarSpec;
1297 -mozilla::OmnijarReader()
1299 - if (!sOmnijarReader)
1302 - return sOmnijarReader;
1306 -mozilla::SetOmnijar(nsILocalFile* aPath)
1308 - NS_IF_RELEASE(sOmnijarPath);
1309 - if (sOmnijarReader) {
1310 - sOmnijarReader->CloseArchive();
1311 - delete sOmnijarReader;
1312 - sOmnijarReader = nsnull;
1315 - sOmnijarPath = aPath;
1316 - NS_IF_ADDREF(sOmnijarPath);
1319 +} /* namespace mozilla */
1320 diff --git a/xpcom/build/Omnijar.h b/xpcom/build/Omnijar.h
1321 --- a/xpcom/build/Omnijar.h
1322 +++ b/xpcom/build/Omnijar.h
1325 * The Initial Developer of the Original Code is
1326 * Mozilla Foundation.
1327 * Portions created by the Initial Developer are Copyright (C) 2010
1328 * the Initial Developer. All Rights Reserved.
1331 * Michael Wu <mwu@mozilla.com>
1332 + * Mike Hommey <mh@glandium.org>
1334 * Alternatively, the contents of this file may be used under the terms of
1335 * either the GNU General Public License Version 2 or later (the "GPL"), or
1336 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
1337 * in which case the provisions of the GPL or the LGPL are applicable instead
1338 * of those above. If you wish to allow use of your version of this file only
1339 * under the terms of either the GPL or the LGPL, and not to allow others to
1340 * use your version of this file under the terms of the MPL, indicate your
1341 @@ -34,29 +35,137 @@
1342 * the provisions above, a recipient may use your version of this file under
1343 * the terms of any one of the MPL, the GPL or the LGPL.
1345 * ***** END LICENSE BLOCK ***** */
1347 #ifndef mozilla_Omnijar_h
1348 #define mozilla_Omnijar_h
1350 -class nsILocalFile;
1351 +#include "nscore.h"
1352 +#include "nsTArray.h"
1353 +#include "nsCOMPtr.h"
1354 +#include "nsString.h"
1364 +#ifdef MOZ_ENABLE_LIBXUL
1365 +#define OMNIJAR_EXPORT
1367 +#define OMNIJAR_EXPORT NS_EXPORT
1370 +class OMNIJAR_EXPORT Omnijar {
1373 - * This returns the path to the omnijar.
1374 - * If the omnijar isn't available, this function will return null.
1375 - * Callers should fallback to flat packaging if null.
1376 + * Store an nsIFile for either a base directory when there is no omni.jar,
1377 + * or omni.jar itself. We can store two paths here, one for GRE
1378 + * (corresponding to resource://gre/) and one for APP
1379 + * (corresponding to resource:/// and resource://app/), but only
1380 + * store one when both point to the same location (unified).
1382 -nsILocalFile *OmnijarPath();
1383 -nsZipArchive *OmnijarReader();
1384 -void SetOmnijar(nsILocalFile* aPath);
1385 +static nsIFile *sPath[2];
1387 + * Store whether the corresponding sPath is an omni.jar or a directory
1389 +static PRBool sIsOmnijar[2];
1391 +#ifdef MOZ_ENABLE_LIBXUL
1393 + * Cached nsZipArchives for the corresponding sPath
1395 +static nsZipArchive *sReader[2];
1405 + * Returns whether SetBase has been called at least once with
1411 + // GRE path is always set after initialization.
1412 + return sPath[0] != nsnull;
1416 + * Sets the base directories for GRE and APP. APP base directory
1417 + * may be nsnull, in case the APP and GRE directories are the same.
1419 +static nsresult SetBase(nsIFile *aGrePath, nsIFile *aAppPath);
1422 + * Returns an nsIFile pointing to the omni.jar file for GRE or APP.
1423 + * Returns nsnull when there is no corresponding omni.jar.
1424 + * Also returns nsnull for APP in the unified case.
1426 +static already_AddRefed<nsIFile>
1427 +GetPath(Type aType)
1429 + NS_ABORT_IF_FALSE(sPath[0], "Omnijar not initialized");
1431 + if (sIsOmnijar[aType]) {
1432 + NS_IF_ADDREF(sPath[aType]);
1433 + return sPath[aType];
1439 + * Returns whether GRE or APP use an omni.jar. Returns PR_False when
1440 + * using an omni.jar in the unified case.
1443 +HasOmnijar(Type aType)
1445 + return sIsOmnijar[aType];
1449 + * Returns the base directory for GRE or APP. In the unified case,
1450 + * returns nsnull for APP.
1452 +static already_AddRefed<nsIFile> GetBase(Type aType);
1455 + * Returns a nsZipArchive pointer for the omni.jar file for GRE or
1456 + * APP. Returns nsnull in the same cases GetPath() would.
1458 +#ifdef MOZ_ENABLE_LIBXUL
1459 +static nsZipArchive *GetReader(Type aType);
1461 +static nsZipArchive *GetReader(Type aType) { return nsnull; }
1465 + * Returns a nsZipArchive pointer for the given path IAOI the given
1466 + * path is the omni.jar for either GRE or APP.
1468 +#ifdef MOZ_ENABLE_LIBXUL
1469 +static nsZipArchive *GetReader(nsIFile *aPath);
1471 +static nsZipArchive *GetReader(nsIFile *aPath) { return nsnull; }
1475 + * Returns the URI string corresponding to the omni.jar or directory
1476 + * for GRE or APP. i.e. jar:/path/to/omni.jar!/ for omni.jar and
1477 + * /path/to/base/dir/ otherwise. Returns an empty string for APP in
1478 + * the unified case.
1479 + * The returned URI is guaranteed to end with a slash.
1481 +static nsresult GetURIString(Type aType, nsCString &result);
1483 +}; /* class Omnijar */
1485 } /* namespace mozilla */
1487 -#endif /* MOZ_OMNIJAR */
1489 #endif /* mozilla_Omnijar_h */
1490 diff --git a/xpcom/build/nsXPComInit.cpp b/xpcom/build/nsXPComInit.cpp
1491 --- a/xpcom/build/nsXPComInit.cpp
1492 +++ b/xpcom/build/nsXPComInit.cpp
1493 @@ -462,35 +462,35 @@ NS_InitXPCOM2(nsIServiceManager* *result
1494 nsDirectoryService::gService->Set(NS_XPCOM_LIBRARY_FILE, xpcomLib);
1497 if (appFileLocationProvider) {
1498 rv = nsDirectoryService::gService->RegisterProvider(appFileLocationProvider);
1499 if (NS_FAILED(rv)) return rv;
1503 NS_TIME_FUNCTION_MARK("Next: Omnijar init");
1505 - if (!mozilla::OmnijarPath()) {
1506 - nsCOMPtr<nsILocalFile> omnijar;
1507 + if (!mozilla::Omnijar::IsInitialized()) {
1508 + nsCOMPtr<nsILocalFile> greDir, appDir;
1509 nsCOMPtr<nsIFile> file;
1511 - rv = NS_ERROR_FAILURE;
1512 nsDirectoryService::gService->Get(NS_GRE_DIR,
1513 NS_GET_IID(nsIFile),
1514 getter_AddRefs(file));
1516 - rv = file->Append(NS_LITERAL_STRING("omni.jar"));
1517 - if (NS_SUCCEEDED(rv))
1518 - omnijar = do_QueryInterface(file);
1519 - if (NS_SUCCEEDED(rv))
1520 - mozilla::SetOmnijar(omnijar);
1521 + greDir = do_QueryInterface(file);
1523 + nsDirectoryService::gService->Get(NS_XPCOM_CURRENT_PROCESS_DIR,
1524 + NS_GET_IID(nsIFile),
1525 + getter_AddRefs(file));
1526 + appDir = do_QueryInterface(file);
1528 + rv = mozilla::Omnijar::SetBase(greDir, appDir);
1529 + NS_ENSURE_SUCCESS(rv, rv);
1534 if ((sCommandLineWasInitialized = !CommandLine::IsInitialized())) {
1535 NS_TIME_FUNCTION_MARK("Next: IPC command line init");
1538 CommandLine::Init(0, nsnull);
1540 @@ -769,18 +769,16 @@ ShutdownXPCOM(nsIServiceManager* servMgr
1541 sCommandLineWasInitialized = false;
1544 delete sExitManager;
1545 sExitManager = nsnull;
1550 - mozilla::SetOmnijar(nsnull);
1552 + mozilla::Omnijar::SetBase(nsnull, nsnull);
1559 } // namespace mozilla
1560 diff --git a/xpcom/components/nsComponentManager.cpp b/xpcom/components/nsComponentManager.cpp
1561 --- a/xpcom/components/nsComponentManager.cpp
1562 +++ b/xpcom/components/nsComponentManager.cpp
1563 @@ -175,18 +175,16 @@ NS_DEFINE_CID(kCategoryManagerCID, NS_CA
1564 #define COMPMGR_TIME_FUNCTION_CONTRACTID(cid) \
1565 NS_TIME_FUNCTION_MIN_FMT(5, "%s (line %d) (contractid: %s)", MOZ_FUNCTION_NAME, \
1568 #define COMPMGR_TIME_FUNCTION_CID(cid) do {} while (0)
1569 #define COMPMGR_TIME_FUNCTION_CONTRACTID(cid) do {} while (0)
1572 -#define kOMNIJAR_PREFIX NS_LITERAL_CSTRING("resource:///")
1575 nsGetServiceFromCategory::operator()(const nsIID& aIID, void** aInstancePtr) const
1578 nsXPIDLCString value;
1579 nsCOMPtr<nsICategoryManager> catman;
1580 nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
1582 @@ -390,47 +388,44 @@ nsresult nsComponentManagerImpl::Init()
1584 nsCategoryManager::GetSingleton()->SuppressNotifications(true);
1586 RegisterModule(&kXPCOMModule, NULL);
1588 for (PRUint32 i = 0; i < sStaticModules->Length(); ++i)
1589 RegisterModule((*sStaticModules)[i], NULL);
1592 - if (mozilla::OmnijarPath()) {
1593 - nsCOMPtr<nsIZipReader> omnijarReader = new nsJAR();
1594 - rv = omnijarReader->Open(mozilla::OmnijarPath());
1595 - if (NS_SUCCEEDED(rv))
1596 - RegisterJarManifest(omnijarReader, "chrome.manifest", false);
1597 + nsCOMPtr<nsIFile> appOmnijar = mozilla::Omnijar::GetPath(mozilla::Omnijar::APP);
1599 + cl = sModuleLocations->InsertElementAt(1); // Insert after greDir
1600 + cl->type = NS_COMPONENT_LOCATION;
1601 + cl->location = do_QueryInterface(appOmnijar);
1605 + nsCOMPtr<nsIFile> greOmnijar = mozilla::Omnijar::GetPath(mozilla::Omnijar::GRE);
1607 + cl = sModuleLocations->InsertElementAt(0);
1608 + cl->type = NS_COMPONENT_LOCATION;
1609 + cl->location = do_QueryInterface(greOmnijar);
1613 for (PRUint32 i = 0; i < sModuleLocations->Length(); ++i) {
1614 ComponentLocation& l = sModuleLocations->ElementAt(i);
1616 RegisterManifestFile(l.type, l.location, false);
1620 nsCOMPtr<nsIZipReader> reader = do_CreateInstance(kZipReaderCID, &rv);
1621 rv = reader->Open(l.location);
1622 if (NS_SUCCEEDED(rv))
1623 RegisterJarManifest(reader, "chrome.manifest", false);
1627 - if (mozilla::OmnijarPath()) {
1628 - cl = sModuleLocations->InsertElementAt(0);
1629 - cl->type = NS_COMPONENT_LOCATION;
1630 - cl->location = mozilla::OmnijarPath();
1635 nsCategoryManager::GetSingleton()->SuppressNotifications(false);
1643 # HG changeset patch
1644 # Parent ff1b810f78226d7f4010909d3cde05a57fdcf20c
1645 Bug 620931 part 4 - Fix resource://app/ to always point to the same as resource:///
1647 diff --git a/netwerk/protocol/res/nsResProtocolHandler.cpp b/netwerk/protocol/res/nsResProtocolHandler.cpp
1648 --- a/netwerk/protocol/res/nsResProtocolHandler.cpp
1649 +++ b/netwerk/protocol/res/nsResProtocolHandler.cpp
1650 @@ -74,16 +74,17 @@ static nsResProtocolHandler *gResHandler
1651 // set NSPR_LOG_FILE=log.txt
1653 // this enables PR_LOG_ALWAYS level information and places all output in
1656 static PRLogModuleInfo *gResLog;
1659 +#define kAPP NS_LITERAL_CSTRING("app")
1660 #define kGRE NS_LITERAL_CSTRING("gre")
1662 //----------------------------------------------------------------------------
1663 // nsResURL : overrides nsStandardURL::GetFile to provide nsIFile resolution
1664 //----------------------------------------------------------------------------
1667 nsResURL::EnsureFile()
1668 @@ -179,16 +180,22 @@ nsResProtocolHandler::Init()
1669 nsCOMPtr<nsIURI> uri;
1670 rv = NS_NewURI(getter_AddRefs(uri), appURI.Length() ? appURI : greURI);
1671 NS_ENSURE_SUCCESS(rv, rv);
1673 rv = SetSubstitution(EmptyCString(), uri);
1674 NS_ENSURE_SUCCESS(rv, rv);
1677 + // make resource://app/ point to the application directory or omnijar
1679 + rv = SetSubstitution(kAPP, uri);
1680 + NS_ENSURE_SUCCESS(rv, rv);
1683 // make resource://gre/ point to the GRE directory
1685 if (appURI.Length()) { // We already have greURI in uri if appURI.Length() is 0.
1686 rv = NS_NewURI(getter_AddRefs(uri), greURI);
1687 NS_ENSURE_SUCCESS(rv, rv);
1690 rv = SetSubstitution(kGRE, uri);
1691 diff --git a/toolkit/xre/nsXREDirProvider.cpp b/toolkit/xre/nsXREDirProvider.cpp
1692 --- a/toolkit/xre/nsXREDirProvider.cpp
1693 +++ b/toolkit/xre/nsXREDirProvider.cpp
1694 @@ -300,19 +300,16 @@ nsXREDirProvider::GetFile(const char* aP
1697 else if (!strcmp(aProperty, XRE_EXECUTABLE_FILE) && gArgv[0]) {
1698 nsCOMPtr<nsILocalFile> lf;
1699 rv = XRE_GetBinaryPath(gArgv[0], getter_AddRefs(lf));
1700 if (NS_SUCCEEDED(rv))
1703 - else if (!strcmp(aProperty, "resource:app")) {
1704 - rv = GetAppDir()->Clone(getter_AddRefs(file));
1707 else if (!strcmp(aProperty, NS_APP_PROFILE_DIR_STARTUP) && mProfileDir) {
1708 return mProfileDir->Clone(aFile);
1710 else if (!strcmp(aProperty, NS_APP_PROFILE_LOCAL_DIR_STARTUP)) {
1711 if (mProfileLocalDir)
1712 return mProfileLocalDir->Clone(aFile);
1714 # HG changeset patch
1715 # Parent 7d2228db71a299afca60babff632a967d2d6c456
1716 Bug 620931 part 5 - Enable omni.jar by default on xulrunner
1718 diff --git a/xulrunner/confvars.sh b/xulrunner/confvars.sh
1719 --- a/xulrunner/confvars.sh
1720 +++ b/xulrunner/confvars.sh
1723 # ***** END LICENSE BLOCK *****
1725 MOZ_APP_NAME=xulrunner
1726 MOZ_APP_DISPLAYNAME=XULRunner
1730 +MOZ_CHROME_FILE_FORMAT=omni
1731 MOZ_STATIC_BUILD_UNSUPPORTED=1
1732 MOZ_APP_VERSION=$MOZILLA_VERSION
1733 if test "$MOZ_STORAGE"; then
1736 MOZ_EXTENSIONS_DEFAULT=" gnomevfs"
1737 MOZ_URL_CLASSIFIER=1