updated on Sun Jan 15 08:01:04 UTC 2012
[aur-mirror.git] / firefox-pgo-beta / xulrunner-omnijar.patch
blob66ec5206c65ae3f67a80242baa626dd4870fc852
1 # HG changeset patch
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
8 @@ -1,8 +1,10 @@
9 toolkit.jar:
10 * res/ua.css (ua.css)
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
25 // the file log.txt
27 static PRLogModuleInfo *gResLog;
28 #endif
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 //----------------------------------------------------------------------------
37 nsresult
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/");
55 -#else
56 - NS_NAMED_LITERAL_CSTRING(strGRE_RES_URL, "chrome/toolkit/res/");
57 -#endif
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.
67 return rv;
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);
84 return NS_OK;
86 #endif
88 #ifdef MOZ_IPC
89 static PLDHashOperator
90 EnumerateSubstitution(const nsACString& aKey,
91 nsIURI* aURI,
92 # HG changeset patch
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
103 libs-%:
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 = \
122 res \
123 defaults \
124 greprefs.js \
125 jsloader \
126 $(NULL)
128 NON_OMNIJAR_FILES += \
129 chrome/icons/\* \
130 - defaults/pref/channel-prefs.js \
131 + $(PREF_DIR)/channel-prefs.js \
132 res/cursors/\* \
133 res/MainMenu.nib/\* \
134 $(NULL)
136 PACK_OMNIJAR = \
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 && \
140 # HG changeset patch
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
149 binaries.
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());
175 -#ifdef MOZ_OMNIJAR
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());
189 -#endif
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();
206 ++it) {
207 cmdLine.AppendLooseValue(UTF8ToWide(*it));
210 cmdLine.AppendLooseValue(std::wstring(mGroupId.get()));
212 -#ifdef MOZ_OMNIJAR
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());
220 + nsAutoString path;
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());
226 -#endif
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()));
238 #endif
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
243 @@ -81,16 +81,17 @@
244 #include "nsIConsoleService.h"
245 #include "nsIStorageStream.h"
246 #include "nsIStringStream.h"
247 #include "prmem.h"
248 #if defined(XP_WIN)
249 #include "nsILocalFileWin.h"
250 #endif
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"
257 #endif
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)
268 nsresult rv;
270 - nsCAutoString fullSpec;
272 -#ifdef MOZ_OMNIJAR
273 - PRBool equal;
274 - rv = aJarFile->Equals(mozilla::OmnijarPath(), &equal);
275 - if (NS_SUCCEEDED(rv) && equal) {
276 - fullSpec = "resource://gre/";
277 - } else {
278 -#endif
279 - nsCAutoString fileSpec;
280 - NS_GetURLSpecFromActualFile(aJarFile, fileSpec);
281 - fullSpec = "jar:";
282 - fullSpec += fileSpec;
283 - fullSpec += "!/";
284 -#ifdef MOZ_OMNIJAR
286 -#endif
288 + nsCAutoString fullSpec, fileSpec;
289 + NS_GetURLSpecFromActualFile(aJarFile, fileSpec);
290 + fullSpec = "jar:";
291 + fullSpec += fileSpec;
292 + fullSpec += "!/";
293 fullSpec += aComponentPath;
295 nsCOMPtr<nsIURI> uri;
296 rv = NS_NewURI(getter_AddRefs(uri), fullSpec);
297 if (NS_FAILED(rv))
298 return NULL;
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); }
305 private:
306 JSContext *mCx;
307 JSScript *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())
319 + return PR_FALSE;
321 + if (base.Compare(spec.get(), PR_FALSE, base.Length()))
322 + return PR_FALSE;
324 + out.Append("/resource/");
325 + out.Append(baseName[aType]);
326 + out.Append(Substring(spec, base.Length()));
327 + return PR_TRUE;
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.
347 * For example:
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
359 static nsresult
360 PathifyURI(nsIURI *in, nsACString &out)
362 - out = "jsloader/";
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
369 - in->GetHost(host);
370 -#ifdef MOZ_OMNIJAR
371 - if (scheme.Equals("resource") && host.Length() == 0){
372 - host = "gre";
374 -#endif
375 - if (host.Length()) {
376 - out.Append("/");
377 - out.Append(host);
379 - nsCAutoString path;
380 - rv = in->GetPath(path);
381 - NS_ENSURE_SUCCESS(rv, rv);
382 - out.Append(path);
383 - out.Append(".bin");
384 - return NS_OK;
385 + PRBool equals;
386 + nsresult rv;
387 + nsCOMPtr<nsIURI> uri = in;
388 + nsCAutoString spec;
390 + out = "jsloader";
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);
410 + } else {
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);
426 + out.Append(path);
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);
442 + out.Append(path);
444 + rv = jarURI->GetJAREntry(path);
445 + NS_ENSURE_SUCCESS(rv, rv);
446 + out.Append("/");
447 + out.Append(path);
448 + } else { // Very unlikely
449 + nsCAutoString spec;
450 + rv = uri->GetSpec(spec);
451 + NS_ENSURE_SUCCESS(rv, rv);
453 + out.Append("/");
454 + out.Append(spec);
458 + out.Append(".bin");
459 + return NS_OK;
462 /* static */
463 #ifdef MOZ_ENABLE_LIBXUL
464 nsresult
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!
474 mZipFile = zipFile;
475 mOuterZipEntry.Truncate();
477 mLock = PR_NewLock();
478 NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
480 -#ifdef MOZ_OMNIJAR
481 // The omnijar is special, it is opened early on and closed late
482 // this avoids reopening it
483 - PRBool equals;
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);
488 + if (zip) {
489 + mZip = zip;
490 return NS_OK;
492 -#endif
493 return mZip->OpenArchive(zipFile);
496 NS_IMETHODIMP
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()
502 mLock = nsnull;
505 mParsedManifest = PR_FALSE;
506 mManifestData.Reset();
507 mGlobalStatus = JAR_MANIFEST_NOT_PARSED;
508 mTotalItemsInManifest = 0;
510 -#ifdef MOZ_OMNIJAR
511 - if (mZip == mozilla::OmnijarReader()) {
512 + if ((mZip == mozilla::Omnijar::GetReader(mozilla::Omnijar::GRE)) ||
513 + (mZip == mozilla::Omnijar::GetReader(mozilla::Omnijar::APP))) {
514 mZip.forget();
515 mZip = new nsZipArchive();
516 return NS_OK;
518 -#endif
519 return mZip->CloseArchive();
522 NS_IMETHODIMP
523 nsJAR::Test(const char *aEntryName)
525 return mZip->Test(aEntryName);
527 @@ -391,22 +387,21 @@ nsJAR::GetInputStreamWithSpec(const nsAC
528 NS_IMETHODIMP
529 nsJAR::GetCertificatePrincipal(const char* aFilename, nsIPrincipal** aPrincipal)
531 //-- Parameter check
532 if (!aPrincipal)
533 return NS_ERROR_NULL_POINTER;
534 *aPrincipal = nsnull;
536 -#ifdef MOZ_OMNIJAR
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)))
542 return NS_OK;
543 -#endif
545 //-- Parse the manifest
546 nsresult rv = ParseManifest();
547 if (NS_FAILED(rv)) return rv;
548 if (mGlobalStatus == JAR_NO_MANIFEST)
549 return NS_OK;
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
555 @@ -67,20 +67,18 @@
557 #include "prefapi.h"
558 #include "prefread.h"
559 #include "prefapi_private_data.h"
560 #include "PrefTuple.h"
562 #include "nsITimelineService.h"
564 -#ifdef MOZ_OMNIJAR
565 #include "mozilla/Omnijar.h"
566 #include "nsZipArchive.h"
567 -#endif
569 // Definitions
570 #define INITIAL_PREF_FILES 10
571 static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
573 // Prototypes
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);
582 return NS_OK;
585 -//----------------------------------------------------------------------------------------
586 -// Initialize default preference JavaScript buffers from
587 -// appropriate TEXT resources
588 -//----------------------------------------------------------------------------------------
589 -static nsresult pref_InitDefaults()
591 - nsCOMPtr<nsIFile> greprefsFile;
592 - nsresult rv;
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?");
605 - return NS_OK;
608 -#ifdef MOZ_OMNIJAR
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);
614 PrefParseState ps;
615 PREF_InitParseState(&ps, PREF_ReaderCallback, NULL);
616 nsresult rv = PREF_ParseBuf(&ps, manifest, manifest.Length());
617 PREF_FinalizeParseState(&ps);
619 return rv;
622 -static nsresult pref_InitAppDefaultsFromOmnijar()
624 - nsresult rv;
626 - nsZipArchive* jarReader = mozilla::OmnijarReader();
627 - if (!jarReader)
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());
649 - if (NS_FAILED(rv))
650 - NS_WARNING("Error parsing preferences.");
653 - return NS_OK;
655 -#endif
657 +//----------------------------------------------------------------------------------------
658 +// Initialize default preference JavaScript buffers from
659 +// appropriate TEXT resources
660 +//----------------------------------------------------------------------------------------
661 static nsresult pref_InitInitialObjects()
663 nsresult rv;
665 - // first we parse the GRE default prefs. This also works if we're not using a GRE,
666 -#ifdef MOZ_OMNIJAR
667 - rv = pref_InitAppDefaultsFromOmnijar();
668 -#else
669 - rv = pref_InitDefaults();
670 -#endif
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
677 + //
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.
683 + //
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);
703 + if (jarReader) {
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);
712 + find = findPtr;
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());
720 + if (NS_FAILED(rv))
721 + NS_WARNING("Error parsing preferences.");
723 + } else {
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);
733 + if (NS_FAILED(rv))
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)
747 "macprefs.js"
748 #elif defined(XP_WIN)
749 "winpref.js"
750 #elif defined(XP_UNIX)
751 "unix.js"
752 -#if defined(_AIX)
753 +#if defined(VMS)
754 + , "openvms.js"
755 +#elif defined(_AIX)
756 , "aix.js"
757 #endif
758 #elif defined(XP_OS2)
759 "os2pref.js"
760 +#elif defined(XP_BEOS)
761 + "beos.js"
762 #endif
763 - };
764 + };
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));
770 + if (NS_FAILED(rv))
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);
779 + find = findPtr;
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());
787 + if (NS_FAILED(rv))
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;
809 nsresult
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);
823 -nsresult
824 nsResProtocolHandler::Init()
826 if (!mSubstitutions.Init(32))
827 return NS_ERROR_UNEXPECTED;
829 nsresult rv;
831 mIOService = do_GetIOService(&rv);
832 NS_ENSURE_SUCCESS(rv, rv);
834 -#ifdef MOZ_OMNIJAR
835 - nsCOMPtr<nsIFile> omniJar(mozilla::OmnijarPath());
836 - if (omniJar)
837 - return Init(omniJar);
838 -#endif
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.
877 return rv;
880 -#ifdef MOZ_OMNIJAR
881 -nsresult
882 -nsResProtocolHandler::Init(nsIFile *aOmniJar)
884 - nsresult rv;
885 - nsCOMPtr<nsIURI> uri;
886 - nsCAutoString omniJarSpec;
887 - NS_GetURLSpecFromActualFile(aOmniJar, omniJarSpec, mIOService);
889 - nsCAutoString urlStr("jar:");
890 - urlStr += omniJarSpec;
891 - urlStr += "!/";
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);
904 - return NS_OK;
906 -#endif
908 #ifdef MOZ_IPC
909 static PLDHashOperator
910 EnumerateSubstitution(const nsACString& aKey,
911 nsIURI* aURI,
912 void* aArg)
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);
921 if (zipItem) {
922 *outbuf = zipItem.Forget();
923 *length = zipItem.Length();
924 return NS_OK;
928 -#ifdef MOZ_OMNIJAR
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);
934 if (zipItem) {
935 *outbuf = zipItem.Forget();
936 *length = zipItem.Length();
937 return NS_OK;
940 -#endif
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);
945 + if (zipItem) {
946 + *outbuf = zipItem.Forget();
947 + *length = zipItem.Length();
948 + return NS_OK;
949 + }
952 return NS_ERROR_NOT_AVAILABLE;
955 // Makes a copy of the buffer, client retains ownership of inbuf.
956 nsresult
957 StartupCache::PutBuffer(const char* id, const char* inbuf, PRUint32 len)
959 WaitOnWriteThread();
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)
967 free(canonArgs[i]);
968 delete[] canonArgs;
969 #endif
970 #endif
972 -#ifdef MOZ_OMNIJAR
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);
977 if (ar == ARG_BAD) {
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;
983 - if (!omnijarPath)
984 + if (!path)
985 return rv;
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);
992 -#endif
994 - return rv;
995 + nsCOMPtr<nsILocalFile> greBase;
996 + rv = XRE_GetFileFromPath(path, getter_AddRefs(greBase));
997 + if (NS_FAILED(rv))
998 + return rv;
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;
1007 + if (path) {
1008 + rv = XRE_GetFileFromPath(path, getter_AddRefs(appBase));
1009 + if (NS_FAILED(rv))
1010 + return rv;
1013 + return mozilla::Omnijar::SetBase(greBase, appBase);
1016 nsresult
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
1033 process->CleanUp();
1034 -#ifdef MOZ_OMNIJAR
1035 - mozilla::SetOmnijar(nsnull);
1036 -#endif
1037 + mozilla::Omnijar::SetBase(nsnull, nsnull);
1041 NS_LogTerm();
1042 return XRE_DeinitCommandLine();
1045 MessageLoop*
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 = \
1050 $(NULL)
1052 CPPSRCS = \
1053 $(XPCOM_GLUE_SRC_LCPPSRCS) \
1054 $(XPCOM_GLUENS_SRC_LCPPSRCS) \
1055 nsXPComInit.cpp \
1056 nsXPCOMStrings.cpp \
1057 Services.cpp \
1058 + Omnijar.cpp \
1059 $(NULL)
1061 ifndef MOZ_ENABLE_LIBXUL
1062 ifeq (,$(filter-out WINNT WINCE OS2,$(OS_ARCH)))
1063 CPPSRCS += dlldeps.cpp
1064 endif
1065 endif
1067 -ifdef MOZ_OMNIJAR
1068 -CPPSRCS += Omnijar.cpp
1069 -endif
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
1082 @@ -16,16 +16,17 @@
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.
1089 * Contributor(s):
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 {
1119 -static void
1120 -SetupReader()
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 };
1126 +#endif
1128 +static already_AddRefed<nsIFile>
1129 +ComputePath(nsIFile *aPath, PRBool &aIsOmnijar)
1131 - if (!sOmnijarPath) {
1132 - return;
1133 + PRBool isDir;
1134 + aIsOmnijar = PR_FALSE;
1135 + if (!aPath || NS_FAILED(aPath->IsDirectory(&isDir)) || !isDir)
1136 + return nsnull;
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))))
1142 + return nsnull;
1144 + if (NS_FAILED(path->AppendNative(NS_LITERAL_CSTRING("omni.jar"))))
1145 + return nsnull;
1147 + if (NS_FAILED(path->Exists(&aIsOmnijar)))
1148 + return nsnull;
1149 +#endif
1151 + if (!aIsOmnijar && NS_FAILED(aPath->Clone(getter_AddRefs(path))))
1152 + return nsnull;
1154 + return path.forget();
1157 +nsresult
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;
1172 +#endif
1174 + nsresult rv;
1175 + PRBool equals;
1176 + if (aAppPath) {
1177 + rv = aAppPath->Equals(aGrePath, &equals);
1178 + NS_ENSURE_SUCCESS(rv, rv);
1179 + } else {
1180 + equals = PR_TRUE;
1183 - nsZipArchive* zipReader = new nsZipArchive();
1184 - if (!zipReader) {
1185 - NS_IF_RELEASE(sOmnijarPath);
1186 - return;
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]);
1198 + return NS_OK;
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))))
1214 + return nsnull;
1216 + if (NS_FAILED(file->GetParent(getter_AddRefs(path))))
1217 + return nsnull;
1218 + return path.forget();
1221 +#ifdef MOZ_ENABLE_LIBXUL
1222 +nsZipArchive *
1223 +Omnijar::GetReader(Type aType)
1225 + if (!sIsOmnijar[aType])
1226 + return nsnull;
1228 + if (sReader[aType])
1229 + return sReader[aType];
1231 + nsZipArchive* zipReader = new nsZipArchive();
1232 + if (!zipReader)
1233 + return nsnull;
1235 + if (NS_FAILED(zipReader->OpenArchive(sPath[aType]))) {
1236 delete zipReader;
1237 - NS_IF_RELEASE(sOmnijarPath);
1238 - return;
1239 + return nsnull;
1242 - sOmnijarReader = zipReader;
1243 + return (sReader[aType] = zipReader);
1246 -nsILocalFile*
1247 -mozilla::OmnijarPath()
1248 +nsZipArchive *
1249 +Omnijar::GetReader(nsIFile *aPath)
1251 - if (!sOmnijarReader)
1252 - SetupReader();
1253 + PRBool equals;
1254 + nsresult rv;
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);
1267 + return nsnull;
1269 +#endif
1271 +nsresult
1272 +Omnijar::GetURIString(Type aType, nsCString &result)
1274 + NS_ABORT_IF_FALSE(sPath[0], "Omnijar not initialized");
1276 + result = "";
1278 + if ((aType == APP) && (!sPath[APP]))
1279 + return NS_OK;
1281 + nsCAutoString omniJarSpec;
1282 + nsresult rv = NS_GetURLSpecFromActualFile(sPath[aType], omniJarSpec);
1283 + NS_ENSURE_SUCCESS(rv, rv);
1285 + if (sIsOmnijar[aType]) {
1286 + result = "jar:";
1287 + result += omniJarSpec;
1288 + result += "!";
1289 + } else {
1290 + result = omniJarSpec;
1292 + result += "/";
1293 + return NS_OK;
1296 -nsZipArchive*
1297 -mozilla::OmnijarReader()
1299 - if (!sOmnijarReader)
1300 - SetupReader();
1302 - return sOmnijarReader;
1305 -void
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
1323 @@ -16,16 +16,17 @@
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.
1330 * Contributor(s):
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"
1356 +class nsIFile;
1357 class nsZipArchive;
1359 -#ifdef MOZ_OMNIJAR
1360 +class nsIURI;
1362 namespace mozilla {
1364 +#ifdef MOZ_ENABLE_LIBXUL
1365 +#define OMNIJAR_EXPORT
1366 +#else
1367 +#define OMNIJAR_EXPORT NS_EXPORT
1368 +#endif
1370 +class OMNIJAR_EXPORT Omnijar {
1371 +private:
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];
1386 +/**
1387 + * Store whether the corresponding sPath is an omni.jar or a directory
1388 + */
1389 +static PRBool sIsOmnijar[2];
1391 +#ifdef MOZ_ENABLE_LIBXUL
1392 +/**
1393 + * Cached nsZipArchives for the corresponding sPath
1394 + */
1395 +static nsZipArchive *sReader[2];
1396 +#endif
1398 +public:
1399 +enum Type {
1400 + GRE = 0,
1401 + APP = 1
1404 +/**
1405 + * Returns whether SetBase has been called at least once with
1406 + * a valid nsIFile
1407 + */
1408 +static PRBool
1409 +IsInitialized()
1411 + // GRE path is always set after initialization.
1412 + return sPath[0] != nsnull;
1415 +/**
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.
1418 + */
1419 +static nsresult SetBase(nsIFile *aGrePath, nsIFile *aAppPath);
1421 +/**
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.
1425 + */
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];
1435 + return nsnull;
1438 +/**
1439 + * Returns whether GRE or APP use an omni.jar. Returns PR_False when
1440 + * using an omni.jar in the unified case.
1441 + */
1442 +static PRBool
1443 +HasOmnijar(Type aType)
1445 + return sIsOmnijar[aType];
1448 +/**
1449 + * Returns the base directory for GRE or APP. In the unified case,
1450 + * returns nsnull for APP.
1451 + */
1452 +static already_AddRefed<nsIFile> GetBase(Type aType);
1454 +/**
1455 + * Returns a nsZipArchive pointer for the omni.jar file for GRE or
1456 + * APP. Returns nsnull in the same cases GetPath() would.
1457 + */
1458 +#ifdef MOZ_ENABLE_LIBXUL
1459 +static nsZipArchive *GetReader(Type aType);
1460 +#else
1461 +static nsZipArchive *GetReader(Type aType) { return nsnull; }
1462 +#endif
1464 +/**
1465 + * Returns a nsZipArchive pointer for the given path IAOI the given
1466 + * path is the omni.jar for either GRE or APP.
1467 + */
1468 +#ifdef MOZ_ENABLE_LIBXUL
1469 +static nsZipArchive *GetReader(nsIFile *aPath);
1470 +#else
1471 +static nsZipArchive *GetReader(nsIFile *aPath) { return nsnull; }
1472 +#endif
1474 +/**
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.
1480 + */
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;
1502 -#ifdef MOZ_OMNIJAR
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));
1515 - if (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);
1531 -#endif
1533 #ifdef MOZ_IPC
1534 if ((sCommandLineWasInitialized = !CommandLine::IsInitialized())) {
1535 NS_TIME_FUNCTION_MARK("Next: IPC command line init");
1537 #ifdef OS_WIN
1538 CommandLine::Init(0, nsnull);
1539 #else
1540 @@ -769,18 +769,16 @@ ShutdownXPCOM(nsIServiceManager* servMgr
1541 sCommandLineWasInitialized = false;
1543 if (sExitManager) {
1544 delete sExitManager;
1545 sExitManager = nsnull;
1547 #endif
1549 -#ifdef MOZ_OMNIJAR
1550 - mozilla::SetOmnijar(nsnull);
1551 -#endif
1552 + mozilla::Omnijar::SetBase(nsnull, nsnull);
1554 NS_LogTerm();
1556 return NS_OK;
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, \
1566 __LINE__, (cid))
1567 #else
1568 #define COMPMGR_TIME_FUNCTION_CID(cid) do {} while (0)
1569 #define COMPMGR_TIME_FUNCTION_CONTRACTID(cid) do {} while (0)
1570 #endif
1572 -#define kOMNIJAR_PREFIX NS_LITERAL_CSTRING("resource:///")
1574 nsresult
1575 nsGetServiceFromCategory::operator()(const nsIID& aIID, void** aInstancePtr) const
1577 nsresult rv;
1578 nsXPIDLCString value;
1579 nsCOMPtr<nsICategoryManager> catman;
1580 nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
1581 if (!compMgr) {
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);
1591 -#ifdef MOZ_OMNIJAR
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);
1598 + if (appOmnijar) {
1599 + cl = sModuleLocations->InsertElementAt(1); // Insert after greDir
1600 + cl->type = NS_COMPONENT_LOCATION;
1601 + cl->location = do_QueryInterface(appOmnijar);
1602 + cl->jar = true;
1604 -#endif
1605 + nsCOMPtr<nsIFile> greOmnijar = mozilla::Omnijar::GetPath(mozilla::Omnijar::GRE);
1606 + if (greOmnijar) {
1607 + cl = sModuleLocations->InsertElementAt(0);
1608 + cl->type = NS_COMPONENT_LOCATION;
1609 + cl->location = do_QueryInterface(greOmnijar);
1610 + cl->jar = true;
1613 for (PRUint32 i = 0; i < sModuleLocations->Length(); ++i) {
1614 ComponentLocation& l = sModuleLocations->ElementAt(i);
1615 if (!l.jar) {
1616 RegisterManifestFile(l.type, l.location, false);
1617 continue;
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);
1626 -#ifdef MOZ_OMNIJAR
1627 - if (mozilla::OmnijarPath()) {
1628 - cl = sModuleLocations->InsertElementAt(0);
1629 - cl->type = NS_COMPONENT_LOCATION;
1630 - cl->location = mozilla::OmnijarPath();
1631 - cl->jar = true;
1633 -#endif
1635 nsCategoryManager::GetSingleton()->SuppressNotifications(false);
1637 mStatus = NORMAL;
1639 return NS_OK;
1642 void
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
1654 // the file log.txt
1656 static PRLogModuleInfo *gResLog;
1657 #endif
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 //----------------------------------------------------------------------------
1666 nsresult
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
1678 + //
1679 + rv = SetSubstitution(kAPP, uri);
1680 + NS_ENSURE_SUCCESS(rv, rv);
1682 + //
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))
1701 file = lf;
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
1721 @@ -36,15 +36,16 @@
1723 # ***** END LICENSE BLOCK *****
1725 MOZ_APP_NAME=xulrunner
1726 MOZ_APP_DISPLAYNAME=XULRunner
1727 MOZ_UPDATER=1
1728 MOZ_XULRUNNER=1
1729 MOZ_ENABLE_LIBXUL=1
1730 +MOZ_CHROME_FILE_FORMAT=omni
1731 MOZ_STATIC_BUILD_UNSUPPORTED=1
1732 MOZ_APP_VERSION=$MOZILLA_VERSION
1733 if test "$MOZ_STORAGE"; then
1734 MOZ_PLACES=1
1736 MOZ_EXTENSIONS_DEFAULT=" gnomevfs"
1737 MOZ_URL_CLASSIFIER=1