summaryrefslogtreecommitdiffstats
path: root/xulrunner-omnijar.patch
blob: 66ec5206c65ae3f67a80242baa626dd4870fc852 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
# HG changeset patch
# Parent a7dea879b4b445a23186f438900562155bb39e99
Bug 620931 part 1 - Use chrome manifest to register resource://gre-resources/

diff --git a/layout/style/jar.mn b/layout/style/jar.mn
--- a/layout/style/jar.mn
+++ b/layout/style/jar.mn
@@ -1,8 +1,10 @@
 toolkit.jar:
 *  res/ua.css    (ua.css)
    res/html.css    (html.css)
    res/quirk.css    (quirk.css)
    res/viewsource.css    (viewsource.css)
 *  res/forms.css    (forms.css)
    res/arrow.gif    (arrow.gif)
    res/arrowd.gif   (arrowd.gif)
+
+% resource gre-resources %res/
diff --git a/netwerk/protocol/res/nsResProtocolHandler.cpp b/netwerk/protocol/res/nsResProtocolHandler.cpp
--- a/netwerk/protocol/res/nsResProtocolHandler.cpp
+++ b/netwerk/protocol/res/nsResProtocolHandler.cpp
@@ -75,17 +75,16 @@ static nsResProtocolHandler *gResHandler
 //
 // this enables PR_LOG_ALWAYS level information and places all output in
 // the file log.txt
 //
 static PRLogModuleInfo *gResLog;
 #endif
 
 #define kGRE           NS_LITERAL_CSTRING("gre")
-#define kGRE_RESOURCES NS_LITERAL_CSTRING("gre-resources")
 
 //----------------------------------------------------------------------------
 // nsResURL : overrides nsStandardURL::GetFile to provide nsIFile resolution
 //----------------------------------------------------------------------------
 
 nsresult
 nsResURL::EnsureFile()
 {
@@ -197,28 +196,16 @@ nsResProtocolHandler::Init()
     NS_ENSURE_SUCCESS(rv, rv);
 
     //
     // make resource://gre/ point to the GRE directory
     //
     rv = AddSpecialDir(NS_GRE_DIR, kGRE);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    // make resource://gre-resources/ point to gre toolkit[.jar]/res
-    nsCOMPtr<nsIURI> greURI;
-    nsCOMPtr<nsIURI> greResURI;
-    GetSubstitution(kGRE, getter_AddRefs(greURI));
-#ifdef MOZ_CHROME_FILE_FORMAT_JAR
-    NS_NAMED_LITERAL_CSTRING(strGRE_RES_URL, "jar:chrome/toolkit.jar!/res/");
-#else
-    NS_NAMED_LITERAL_CSTRING(strGRE_RES_URL, "chrome/toolkit/res/");
-#endif
-    rv = mIOService->NewURI(strGRE_RES_URL, nsnull, greURI,
-                            getter_AddRefs(greResURI));
-    SetSubstitution(kGRE_RESOURCES, greResURI);
     //XXXbsmedberg Neil wants a resource://pchrome/ for the profile chrome dir...
     // but once I finish multiple chrome registration I'm not sure that it is needed
 
     // XXX dveditz: resource://pchrome/ defeats profile directory salting
     // if web content can load it. Tread carefully.
 
     return rv;
 }
@@ -242,22 +229,16 @@ nsResProtocolHandler::Init(nsIFile *aOmn
     // these entries should be kept in sync with the normal Init function
 
     // resource:/// points to jar:omni.jar!/
     SetSubstitution(EmptyCString(), uri);
 
     // resource://gre/ points to jar:omni.jar!/
     SetSubstitution(kGRE, uri);
 
-    urlStr += "chrome/toolkit/res/";
-    rv = mIOService->NewURI(urlStr, nsnull, nsnull, getter_AddRefs(uri));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    // resource://gre-resources/ points to jar:omni.jar!/chrome/toolkit/res/
-    SetSubstitution(kGRE_RESOURCES, uri);
     return NS_OK;
 }
 #endif
 
 #ifdef MOZ_IPC
 static PLDHashOperator
 EnumerateSubstitution(const nsACString& aKey,
                       nsIURI* aURI,
# HG changeset patch
# Parent 3038cccba1a071d6b418e15442d0f2d9f3dcb11d
Bug 620931 part 2 - When building --with-libxul-sdk, use the right preferences directory

diff --git a/browser/locales/Makefile.in b/browser/locales/Makefile.in
--- a/browser/locales/Makefile.in
+++ b/browser/locales/Makefile.in
@@ -183,17 +183,17 @@ install:: $(addsuffix .xml,$(SEARCH_PLUG
 	$(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/searchplugins
 
 
 libs-%:
 	$(NSINSTALL) -D $(DIST)/install
 	@$(MAKE) -C ../../toolkit/locales libs-$* BOTH_MANIFESTS=1
 	@$(MAKE) -C ../../services/sync/locales AB_CD=$* XPI_NAME=locale-$* BOTH_MANIFESTS=1
 	@$(MAKE) -C ../../extensions/spellcheck/locales AB_CD=$* XPI_NAME=locale-$* BOTH_MANIFESTS=1
-	@$(MAKE) libs AB_CD=$* XPI_NAME=locale-$* PREF_DIR=defaults/pref BOTH_MANIFESTS=1
+	@$(MAKE) libs AB_CD=$* XPI_NAME=locale-$* PREF_DIR=$(PREF_DIR) BOTH_MANIFESTS=1
 	@$(MAKE) -C $(DEPTH)/$(MOZ_BRANDING_DIRECTORY)/locales AB_CD=$* XPI_NAME=locale-$* BOTH_MANIFESTS=1
 
 
 repackage-win32-installer: WIN32_INSTALLER_OUT="$(_ABS_DIST)/$(PKG_INST_PATH)$(PKG_INST_BASENAME).exe"
 repackage-win32-installer: $(WIN32_INSTALLER_IN) $(SUBMAKEFILES)
 	@echo "Repackaging $(WIN32_INSTALLER_IN) into $(WIN32_INSTALLER_OUT)."
 	$(MAKE) -C $(DEPTH)/$(MOZ_BRANDING_DIRECTORY) export
 	$(MAKE) -C ../installer/windows CONFIG_DIR=l10ngen l10ngen/setup.exe l10ngen/7zSD.sfx
diff --git a/toolkit/mozapps/installer/packager.mk b/toolkit/mozapps/installer/packager.mk
--- a/toolkit/mozapps/installer/packager.mk
+++ b/toolkit/mozapps/installer/packager.mk
@@ -307,17 +307,17 @@ OMNIJAR_FILES	= \
   res \
   defaults \
   greprefs.js \
   jsloader \
   $(NULL)
 
 NON_OMNIJAR_FILES += \
   chrome/icons/\* \
-  defaults/pref/channel-prefs.js \
+  $(PREF_DIR)/channel-prefs.js \
   res/cursors/\* \
   res/MainMenu.nib/\* \
   $(NULL)
 
 PACK_OMNIJAR	= \
   rm -f omni.jar components/binary.manifest && \
   grep -h '^binary-component' components/*.manifest > binary.manifest ; \
   sed -e 's/^binary-component/\#binary-component/' components/components.manifest > components.manifest && \
# HG changeset patch
# Parent cd8df8030f7ad7530692bd7c4391a8009df56a02
Bug 620931 part 3 - Allow GRE and XUL application to use omni.jar independently

We now store two independent locations for an omni.jar, allowing GRE/XRE and
XUL application to each have their own omni.jar. And since xulrunner setups
are very independent from the XUL applications, we implement support for both
omni.jar and non omni.jar cases in the same runtime, with the side effect of
allowing to switch from one to the other manually without rebuilding the
binaries.

We let the mozilla::Omnijar API handle both cases, so that callers don't need
too much work to support them.

We also make the preferences service load the same set of preferences in all
the various cases (unified vs. separate, omni.jar vs. no omni.jar).

The child process launcher for IPC is modified to pass the base directories
needed for the mozilla::Omnijar API initialization in the child process.

Finally, the startupcache file name canonicalization is modified to separate
APP and GRE resources.

diff --git a/ipc/glue/GeckoChildProcessHost.cpp b/ipc/glue/GeckoChildProcessHost.cpp
--- a/ipc/glue/GeckoChildProcessHost.cpp
+++ b/ipc/glue/GeckoChildProcessHost.cpp
@@ -440,26 +440,29 @@ GeckoChildProcessHost::PerformAsyncLaunc
   // other end of the socketpair() from us
 
   std::vector<std::string> childArgv;
 
   childArgv.push_back(exePath.value());
 
   childArgv.insert(childArgv.end(), aExtraOpts.begin(), aExtraOpts.end());
 
-#ifdef MOZ_OMNIJAR
   // Make sure the child process can find the omnijar
   // See XRE_InitCommandLine in nsAppRunner.cpp
-  nsCAutoString omnijarPath;
-  if (mozilla::OmnijarPath()) {
-    mozilla::OmnijarPath()->GetNativePath(omnijarPath);
-    childArgv.push_back("-omnijar");
-    childArgv.push_back(omnijarPath.get());
+  nsCAutoString path;
+  nsCOMPtr<nsIFile> file = mozilla::Omnijar::GetBase(mozilla::Omnijar::GRE);
+  if (file && NS_SUCCEEDED(file->GetNativePath(path))) {
+    childArgv.push_back("-grebase");
+    childArgv.push_back(path.get());
   }
-#endif
+  file = mozilla::Omnijar::GetBase(mozilla::Omnijar::APP);
+  if (file && NS_SUCCEEDED(file->GetNativePath(path))) {
+    childArgv.push_back("-appbase");
+    childArgv.push_back(path.get());
+  }
 
   childArgv.push_back(pidstring);
 
 #if defined(MOZ_CRASHREPORTER)
 #  if defined(OS_LINUX)
   int childCrashFd, childCrashRemapFd;
   if (!CrashReporter::CreateNotificationPipeForChild(
         &childCrashFd, &childCrashRemapFd))
@@ -552,26 +555,29 @@ GeckoChildProcessHost::PerformAsyncLaunc
   for (std::vector<std::string>::iterator it = aExtraOpts.begin();
        it != aExtraOpts.end();
        ++it) {
       cmdLine.AppendLooseValue(UTF8ToWide(*it));
   }
 
   cmdLine.AppendLooseValue(std::wstring(mGroupId.get()));
 
-#ifdef MOZ_OMNIJAR
   // Make sure the child process can find the omnijar
   // See XRE_InitCommandLine in nsAppRunner.cpp
-  nsAutoString omnijarPath;
-  if (mozilla::OmnijarPath()) {
-    mozilla::OmnijarPath()->GetPath(omnijarPath);
-    cmdLine.AppendLooseValue(UTF8ToWide("-omnijar"));
-    cmdLine.AppendLooseValue(omnijarPath.get());
+  nsAutoString path;
+  nsCOMPtr<nsIFile> file = mozilla::Omnijar::GetBase(mozilla::Omnijar::GRE);
+  if (file && NS_SUCCEEDED(file->GetPath(path))) {
+    cmdLine.AppendLooseValue(UTF8ToWide("-grebase"));
+    cmdLine.AppendLooseValue(path.get());
   }
-#endif
+  file = mozilla::Omnijar::GetBase(mozilla::Omnijar::APP);
+  if (file && NS_SUCCEEDED(file->GetPath(path))) {
+    cmdLine.AppendLooseValue(UTF8ToWide("-appbase"));
+    cmdLine.AppendLooseValue(path.get());
+  }
 
   cmdLine.AppendLooseValue(UTF8ToWide(pidstring));
 
 #if defined(MOZ_CRASHREPORTER)
   cmdLine.AppendLooseValue(
     UTF8ToWide(CrashReporter::GetChildNotificationPipe()));
 #endif
 
diff --git a/js/src/xpconnect/loader/mozJSComponentLoader.cpp b/js/src/xpconnect/loader/mozJSComponentLoader.cpp
--- a/js/src/xpconnect/loader/mozJSComponentLoader.cpp
+++ b/js/src/xpconnect/loader/mozJSComponentLoader.cpp
@@ -81,16 +81,17 @@
 #include "nsIConsoleService.h"
 #include "nsIStorageStream.h"
 #include "nsIStringStream.h"
 #include "prmem.h"
 #if defined(XP_WIN)
 #include "nsILocalFileWin.h"
 #endif
 #include "xpcprivate.h"
+#include "nsIResProtocolHandler.h"
 
 #ifdef MOZ_ENABLE_LIBXUL
 #include "mozilla/scache/StartupCache.h"
 #include "mozilla/scache/StartupCacheUtils.h"
 #endif
 #include "mozilla/Omnijar.h"
 
 #include "jsdbgapi.h"
@@ -621,34 +622,21 @@ mozJSComponentLoader::LoadModule(nsILoca
 
 const mozilla::Module*
 mozJSComponentLoader::LoadModuleFromJAR(nsILocalFile *aJarFile,
                                         const nsACString &aComponentPath)
 {
 #if !defined(XPCONNECT_STANDALONE)
     nsresult rv;
 
-    nsCAutoString fullSpec;
-
-#ifdef MOZ_OMNIJAR
-    PRBool equal;
-    rv = aJarFile->Equals(mozilla::OmnijarPath(), &equal);
-    if (NS_SUCCEEDED(rv) && equal) {
-        fullSpec = "resource://gre/";
-    } else {
-#endif
-        nsCAutoString fileSpec;
-        NS_GetURLSpecFromActualFile(aJarFile, fileSpec);
-        fullSpec = "jar:";
-        fullSpec += fileSpec;
-        fullSpec += "!/";
-#ifdef MOZ_OMNIJAR
-    }
-#endif
-
+    nsCAutoString fullSpec, fileSpec;
+    NS_GetURLSpecFromActualFile(aJarFile, fileSpec);
+    fullSpec = "jar:";
+    fullSpec += fileSpec;
+    fullSpec += "!/";
     fullSpec += aComponentPath;
 
     nsCOMPtr<nsIURI> uri;
     rv = NS_NewURI(getter_AddRefs(uri), fullSpec);
     if (NS_FAILED(rv))
         return NULL;
 
     nsAutoString hashstring;
@@ -833,57 +821,138 @@ class JSScriptHolder
     JSScriptHolder(JSContext *cx, JSScript *script)
         : mCx(cx), mScript(script) {}
     ~JSScriptHolder() { ::JS_DestroyScript(mCx, mScript); }
  private:
     JSContext *mCx;
     JSScript *mScript;
 };
 
+static const char baseName[2][5] = { "gre/", "app/" };
+
+static inline PRBool
+canonicalizeBase(nsCAutoString &spec, nsACString &out, mozilla::Omnijar::Type aType)
+{
+    nsCAutoString base;
+    nsresult rv = mozilla::Omnijar::GetURIString(aType, base);
+
+    if (NS_FAILED(rv) || !base.Length())
+        return PR_FALSE;
+
+    if (base.Compare(spec.get(), PR_FALSE, base.Length()))
+        return PR_FALSE;
+
+    out.Append("/resource/");
+    out.Append(baseName[aType]);
+    out.Append(Substring(spec, base.Length()));
+    return PR_TRUE;
+}
 /**
  * PathifyURI transforms mozilla .js uris into useful zip paths
  * to make it makes it easier to manipulate startup cache entries
  * using standard zip tools.
  * Transformations applied:
- *  * jsloader/<scheme> prefix is used to group mozJSComponentLoader cache entries in
+ *  * jsloader/ prefix is used to group mozJSComponentLoader cache entries in
  *    a top-level zip directory.
- *  * In MOZ_OMNIJAR case resource:/// and resource://gre/ URIs refer to the same path
- *    so treat both of them as resource://gre/
+ *  * resource:// URIs are resolved to their corresponding file/jar URI to
+ *    canonicalize resources URIs other than gre and app.
+ *  * Paths under GRE or APP directory have their base path replaced with
+ *    resource/gre or resource/app to avoid depending on install location.
+ *  * jar:file:///path/to/file.jar!/sub/path urls are replaced with
+ *    /path/to/file.jar/sub/path
  *  * .bin suffix is added to the end of the path to indicate that jsloader/ entries
  *     are binary representations of JS source.
  * For example:
- *  resource://gre/modules/XPCOMUtils.jsm becomes
- *  jsloader/resource/gre/modules/XPCOMUtils.jsm.bin
+ *  resource://gre/modules/XPCOMUtils.jsm or
+ *  file://$GRE_DIR/modules/XPCOMUtils.jsm or
+ *  jar:file://$GRE_DIR/omni.jar!/modules/XPCOMUtils.jsm become
+ *     jsloader/resource/gre/modules/XPCOMUtils.jsm.bin
+ *  file://$PROFILE_DIR/extensions/{uuid}/components/component.js becomes
+ *     jsloader/$PROFILE_DIR/extensions/%7Buuid%7D/components/component.js.bin
+ *  jar:file://$PROFILE_DIR/extensions/some.xpi!/components/component.js becomes
+ *     jsloader/$PROFILE_DIR/extensions/some.xpi/components/component.js.bin
  */
 static nsresult
 PathifyURI(nsIURI *in, nsACString &out)
 { 
-   out = "jsloader/";
-   nsCAutoString scheme;
-   nsresult rv = in->GetScheme(scheme);
-   NS_ENSURE_SUCCESS(rv, rv);
-   out.Append(scheme);
-   nsCAutoString host;
-   // OK for GetHost to fail since it's not implemented sometimes
-   in->GetHost(host);
-#ifdef MOZ_OMNIJAR
-   if (scheme.Equals("resource") && host.Length() == 0){
-       host = "gre";
-   }
-#endif
-   if (host.Length()) {
-       out.Append("/");
-       out.Append(host);
-   }
-   nsCAutoString path;
-   rv = in->GetPath(path);
-   NS_ENSURE_SUCCESS(rv, rv);
-   out.Append(path);
-   out.Append(".bin");
-   return NS_OK;
+    PRBool equals;
+    nsresult rv;
+    nsCOMPtr<nsIURI> uri = in;
+    nsCAutoString spec;
+
+    out = "jsloader";
+
+    // Resolve resource:// URIs. At the end of this if/else block, we
+    // have both spec and uri variables identifying the same URI.
+    if (NS_SUCCEEDED(in->SchemeIs("resource", &equals)) && equals) {
+        nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
+        NS_ENSURE_SUCCESS(rv, rv);
+
+        nsCOMPtr<nsIProtocolHandler> ph;
+        rv = ioService->GetProtocolHandler("resource", getter_AddRefs(ph));
+        NS_ENSURE_SUCCESS(rv, rv);
+
+        nsCOMPtr<nsIResProtocolHandler> irph(do_QueryInterface(ph, &rv));
+        NS_ENSURE_SUCCESS(rv, rv);
+
+        rv = irph->ResolveURI(in, spec);
+        NS_ENSURE_SUCCESS(rv, rv);
+
+        rv = ioService->NewURI(spec, nsnull, nsnull, getter_AddRefs(uri));
+        NS_ENSURE_SUCCESS(rv, rv);
+    } else {
+        rv = in->GetSpec(spec);
+        NS_ENSURE_SUCCESS(rv, rv);
+    }
+
+    if (!canonicalizeBase(spec, out, mozilla::Omnijar::GRE) &&
+        !canonicalizeBase(spec, out, mozilla::Omnijar::APP)) {
+        if (NS_SUCCEEDED(uri->SchemeIs("file", &equals)) && equals) {
+            nsCOMPtr<nsIFileURL> baseFileURL;
+            baseFileURL = do_QueryInterface(uri, &rv);
+            NS_ENSURE_SUCCESS(rv, rv);
+
+            nsCAutoString path;
+            rv = baseFileURL->GetPath(path);
+            NS_ENSURE_SUCCESS(rv, rv);
+
+            out.Append(path);
+        } else if (NS_SUCCEEDED(uri->SchemeIs("jar", &equals)) && equals) {
+            nsCOMPtr<nsIJARURI> jarURI = do_QueryInterface(uri, &rv);
+            NS_ENSURE_SUCCESS(rv, rv);
+
+            nsCOMPtr<nsIURI> jarFileURI;
+            rv = jarURI->GetJARFile(getter_AddRefs(jarFileURI));
+            NS_ENSURE_SUCCESS(rv, rv);
+
+            nsCOMPtr<nsIFileURL> jarFileURL;
+            jarFileURL = do_QueryInterface(jarFileURI, &rv);
+            NS_ENSURE_SUCCESS(rv, rv);
+
+            nsCAutoString path;
+            rv = jarFileURL->GetPath(path);
+            NS_ENSURE_SUCCESS(rv, rv);
+            out.Append(path);
+
+            rv = jarURI->GetJAREntry(path);
+            NS_ENSURE_SUCCESS(rv, rv);
+            out.Append("/");
+            out.Append(path);
+        } else { // Very unlikely
+            nsCAutoString spec;
+            rv = uri->GetSpec(spec);
+            NS_ENSURE_SUCCESS(rv, rv);
+
+            out.Append("/");
+            out.Append(spec);
+        }
+    }
+
+    out.Append(".bin");
+    return NS_OK;
 }
 
 /* static */
 #ifdef MOZ_ENABLE_LIBXUL
 nsresult
 mozJSComponentLoader::ReadScript(StartupCache* cache, nsIURI *uri,
                                  JSContext *cx, JSScript **script)
 {
diff --git a/modules/libjar/nsJAR.cpp b/modules/libjar/nsJAR.cpp
--- a/modules/libjar/nsJAR.cpp
+++ b/modules/libjar/nsJAR.cpp
@@ -171,26 +171,23 @@ nsJAR::Open(nsIFile* zipFile)
   if (mLock) return NS_ERROR_FAILURE; // Already open!
 
   mZipFile = zipFile;
   mOuterZipEntry.Truncate();
 
   mLock = PR_NewLock();
   NS_ENSURE_TRUE(mLock, NS_ERROR_OUT_OF_MEMORY);
   
-#ifdef MOZ_OMNIJAR
   // The omnijar is special, it is opened early on and closed late
   // this avoids reopening it
-  PRBool equals;
-  nsresult rv = zipFile->Equals(mozilla::OmnijarPath(), &equals);
-  if (NS_SUCCEEDED(rv) && equals) {
-    mZip = mozilla::OmnijarReader();
+  nsZipArchive *zip = mozilla::Omnijar::GetReader(zipFile);
+  if (zip) {
+    mZip = zip;
     return NS_OK;
   }
-#endif
   return mZip->OpenArchive(zipFile);
 }
 
 NS_IMETHODIMP
 nsJAR::OpenInner(nsIZipReader *aZipReader, const char *aZipEntry)
 {
   NS_ENSURE_ARG_POINTER(aZipReader);
   NS_ENSURE_ARG_POINTER(aZipEntry);
@@ -234,23 +231,22 @@ nsJAR::Close()
     mLock = nsnull;
   }
 
   mParsedManifest = PR_FALSE;
   mManifestData.Reset();
   mGlobalStatus = JAR_MANIFEST_NOT_PARSED;
   mTotalItemsInManifest = 0;
 
-#ifdef MOZ_OMNIJAR
-  if (mZip == mozilla::OmnijarReader()) {
+  if ((mZip == mozilla::Omnijar::GetReader(mozilla::Omnijar::GRE)) ||
+      (mZip == mozilla::Omnijar::GetReader(mozilla::Omnijar::APP))) {
     mZip.forget();
     mZip = new nsZipArchive();
     return NS_OK;
   }
-#endif
   return mZip->CloseArchive();
 }
 
 NS_IMETHODIMP
 nsJAR::Test(const char *aEntryName)
 {
   return mZip->Test(aEntryName);
 }
@@ -391,22 +387,21 @@ nsJAR::GetInputStreamWithSpec(const nsAC
 NS_IMETHODIMP
 nsJAR::GetCertificatePrincipal(const char* aFilename, nsIPrincipal** aPrincipal)
 {
   //-- Parameter check
   if (!aPrincipal)
     return NS_ERROR_NULL_POINTER;
   *aPrincipal = nsnull;
 
-#ifdef MOZ_OMNIJAR
   // Don't check signatures in the omnijar - this is only
   // interesting for extensions/XPIs.
-  if (mZip == mozilla::OmnijarReader())
+  if ((mZip == mozilla::Omnijar::GetReader(mozilla::Omnijar::GRE)) ||
+      (mZip == mozilla::Omnijar::GetReader(mozilla::Omnijar::APP)))
     return NS_OK;
-#endif
 
   //-- Parse the manifest
   nsresult rv = ParseManifest();
   if (NS_FAILED(rv)) return rv;
   if (mGlobalStatus == JAR_NO_MANIFEST)
     return NS_OK;
 
   PRInt16 requestedStatus;
diff --git a/modules/libpref/src/nsPrefService.cpp b/modules/libpref/src/nsPrefService.cpp
--- a/modules/libpref/src/nsPrefService.cpp
+++ b/modules/libpref/src/nsPrefService.cpp
@@ -67,20 +67,18 @@
 
 #include "prefapi.h"
 #include "prefread.h"
 #include "prefapi_private_data.h"
 #include "PrefTuple.h"
 
 #include "nsITimelineService.h"
 
-#ifdef MOZ_OMNIJAR
 #include "mozilla/Omnijar.h"
 #include "nsZipArchive.h"
-#endif
 
 // Definitions
 #define INITIAL_PREF_FILES 10
 static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
 
 // Prototypes
 static nsresult openPrefFile(nsIFile* aFile);
 static nsresult pref_InitInitialObjects(void);
@@ -793,124 +791,144 @@ static nsresult pref_LoadPrefsInDirList(
           pref_LoadPrefsInDir(dir, nsnull, 0); 
         }
       }
     }
   }
   return NS_OK;
 }
 
-//----------------------------------------------------------------------------------------
-// Initialize default preference JavaScript buffers from
-// appropriate TEXT resources
-//----------------------------------------------------------------------------------------
-static nsresult pref_InitDefaults()
-{
-  nsCOMPtr<nsIFile> greprefsFile;
-  nsresult          rv;
-
-  rv = NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(greprefsFile));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = greprefsFile->AppendNative(NS_LITERAL_CSTRING("greprefs.js"));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = openPrefFile(greprefsFile);
-  if (NS_FAILED(rv)) {
-    NS_WARNING("Error parsing GRE default preferences. Is this an old-style embedding app?");
-  }
-
-  return NS_OK;
-}
-
-#ifdef MOZ_OMNIJAR
 static nsresult pref_ReadPrefFromJar(nsZipArchive* jarReader, const char *name)
 {
   nsZipItemPtr<char> manifest(jarReader, name, true);
   NS_ENSURE_TRUE(manifest.Buffer(), NS_ERROR_NOT_AVAILABLE);
 
   PrefParseState ps;
   PREF_InitParseState(&ps, PREF_ReaderCallback, NULL);
   nsresult rv = PREF_ParseBuf(&ps, manifest, manifest.Length());
   PREF_FinalizeParseState(&ps);
 
   return rv;
 }
 
-static nsresult pref_InitAppDefaultsFromOmnijar()
-{
-  nsresult rv;
-
-  nsZipArchive* jarReader = mozilla::OmnijarReader();
-  if (!jarReader)
-    return pref_InitDefaults();
-
-  rv = pref_ReadPrefFromJar(jarReader, "greprefs.js");
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsZipFind *findPtr;
-  rv = jarReader->FindInit("defaults/pref/*.js$", &findPtr);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsAutoPtr<nsZipFind> find(findPtr);
-
-  nsTArray<nsCString> prefEntries;
-  const char *entryName;
-  PRUint16 entryNameLen;
-  while (NS_SUCCEEDED(find->FindNext(&entryName, &entryNameLen))) {
-    prefEntries.AppendElement(Substring(entryName, entryName + entryNameLen));
-  }
-
-  prefEntries.Sort();
-  for (PRUint32 i = prefEntries.Length(); i--; ) {
-    rv = pref_ReadPrefFromJar(jarReader, prefEntries[i].get());
-    if (NS_FAILED(rv))
-      NS_WARNING("Error parsing preferences.");
-  }
-
-  return NS_OK;
-}
-#endif
-
+//----------------------------------------------------------------------------------------
+// Initialize default preference JavaScript buffers from
+// appropriate TEXT resources
+//----------------------------------------------------------------------------------------
 static nsresult pref_InitInitialObjects()
 {
   nsresult rv;
 
-  // first we parse the GRE default prefs. This also works if we're not using a GRE, 
-#ifdef MOZ_OMNIJAR
-  rv = pref_InitAppDefaultsFromOmnijar();
-#else
-  rv = pref_InitDefaults();
-#endif
-  NS_ENSURE_SUCCESS(rv, rv);
+  // In omni.jar case, we load the following prefs:
+  // - jar:$gre/omni.jar!/greprefs.js
+  // - jar:$gre/omni.jar!/defaults/pref/*.js
+  // In non omni.jar case, we load:
+  // - $gre/greprefs.js
+  //
+  // When $app == $gre, we additionally load, in all cases:
+  // - $gre/defaults/pref/*.js
+  // This is kept for bug 591866 (channel-prefs.js should not be in omni.jar).
+  // We load all files instead of channel-prefs.js only to have the same
+  // behaviour as $app != $gre.
+  //
+  // When $app != $gre, we additionally load, in omni.jar case:
+  // - jar:$app/omni.jar!/defaults/preferences/*.js
+  // - $app/defaults/preferences/*.js
+  // and in non omni.jar case:
+  // - $app/defaults/preferences/*.js
 
-  nsCOMPtr<nsIFile> defaultPrefDir;
-  // now parse the "application" default preferences
-  rv = NS_GetSpecialDirectory(NS_APP_PREF_DEFAULTS_50_DIR, getter_AddRefs(defaultPrefDir));
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsZipFind *findPtr;
+  nsAutoPtr<nsZipFind> find;
+  nsTArray<nsCString> prefEntries;
+  const char *entryName;
+  PRUint16 entryNameLen;
 
-  /* these pref file names should not be used: we process them after all other application pref files for backwards compatibility */
-  static const char* specialFiles[] = {
+  nsZipArchive* jarReader = mozilla::Omnijar::GetReader(mozilla::Omnijar::GRE);
+  if (jarReader) {
+    // Load jar:$gre/omni.jar!/greprefs.js
+    rv = pref_ReadPrefFromJar(jarReader, "greprefs.js");
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    // Load jar:$gre/omni.jar!/defaults/pref/*.js
+    rv = jarReader->FindInit("defaults/pref/*.js$", &findPtr);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    find = findPtr;
+    while (NS_SUCCEEDED(find->FindNext(&entryName, &entryNameLen))) {
+      prefEntries.AppendElement(Substring(entryName, entryName + entryNameLen));
+    }
+
+    prefEntries.Sort();
+    for (PRUint32 i = prefEntries.Length(); i--; ) {
+      rv = pref_ReadPrefFromJar(jarReader, prefEntries[i].get());
+      if (NS_FAILED(rv))
+        NS_WARNING("Error parsing preferences.");
+    }
+  } else {
+    // Load $gre/greprefs.js
+    nsCOMPtr<nsIFile> greprefsFile;
+    rv = NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(greprefsFile));
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    rv = greprefsFile->AppendNative(NS_LITERAL_CSTRING("greprefs.js"));
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    rv = openPrefFile(greprefsFile);
+    if (NS_FAILED(rv))
+      NS_WARNING("Error parsing GRE default preferences. Is this an old-style embedding app?");
+  }
+
+  if (!mozilla::Omnijar::HasOmnijar(mozilla::Omnijar::APP)) {
+    // Load $gre/defaults/pref/*.js
+    nsCOMPtr<nsIFile> defaultPrefDir;
+
+    rv = NS_GetSpecialDirectory(NS_APP_PREF_DEFAULTS_50_DIR, getter_AddRefs(defaultPrefDir));
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    /* these pref file names should not be used: we process them after all other application pref files for backwards compatibility */
+    static const char* specialFiles[] = {
 #if defined(XP_MAC) || defined(XP_MACOSX)
       "macprefs.js"
 #elif defined(XP_WIN)
       "winpref.js"
 #elif defined(XP_UNIX)
       "unix.js"
-#if defined(_AIX)
+#if defined(VMS)
+      , "openvms.js"
+#elif defined(_AIX)
       , "aix.js"
 #endif
 #elif defined(XP_OS2)
       "os2pref.js"
+#elif defined(XP_BEOS)
+      "beos.js"
 #endif
-  };
+    };
 
-  rv = pref_LoadPrefsInDir(defaultPrefDir, specialFiles, NS_ARRAY_LENGTH(specialFiles));
-  if (NS_FAILED(rv)) {
-    NS_WARNING("Error parsing application default preferences.");
+    rv = pref_LoadPrefsInDir(defaultPrefDir, specialFiles, NS_ARRAY_LENGTH(specialFiles));
+    if (NS_FAILED(rv))
+      NS_WARNING("Error parsing application default preferences.");
+  }
+
+  // Load jar:$app/omni.jar!/defaults/preferences/*.js
+  nsZipArchive *appJarReader = mozilla::Omnijar::GetReader(mozilla::Omnijar::APP);
+  if (appJarReader) {
+    rv = appJarReader->FindInit("defaults/preferences/*.js$", &findPtr);
+    NS_ENSURE_SUCCESS(rv, rv);
+    find = findPtr;
+    prefEntries.Clear();
+    while (NS_SUCCEEDED(find->FindNext(&entryName, &entryNameLen))) {
+      prefEntries.AppendElement(Substring(entryName, entryName + entryNameLen));
+    }
+    prefEntries.Sort();
+    for (PRUint32 i = prefEntries.Length(); i--; ) {
+      rv = pref_ReadPrefFromJar(appJarReader, prefEntries[i].get());
+      if (NS_FAILED(rv))
+        NS_WARNING("Error parsing preferences.");
+    }
   }
 
   rv = pref_LoadPrefsInDirList(NS_APP_PREFS_DEFAULTS_DIR_LIST);
   NS_ENSURE_SUCCESS(rv, rv);
 
   NS_CreateServicesFromCategory(NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID,
                                 nsnull, NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID);
 
diff --git a/netwerk/protocol/res/nsResProtocolHandler.cpp b/netwerk/protocol/res/nsResProtocolHandler.cpp
--- a/netwerk/protocol/res/nsResProtocolHandler.cpp
+++ b/netwerk/protocol/res/nsResProtocolHandler.cpp
@@ -152,97 +152,62 @@ nsResProtocolHandler::nsResProtocolHandl
 }
 
 nsResProtocolHandler::~nsResProtocolHandler()
 {
     gResHandler = nsnull;
 }
 
 nsresult
-nsResProtocolHandler::AddSpecialDir(const char* aSpecialDir, const nsACString& aSubstitution)
-{
-    nsCOMPtr<nsIFile> file;
-    nsresult rv = NS_GetSpecialDirectory(aSpecialDir, getter_AddRefs(file));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsCOMPtr<nsIURI> uri;
-    rv = mIOService->NewFileURI(file, getter_AddRefs(uri));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    return SetSubstitution(aSubstitution, uri);
-}
-
-nsresult
 nsResProtocolHandler::Init()
 {
     if (!mSubstitutions.Init(32))
         return NS_ERROR_UNEXPECTED;
 
     nsresult rv;
 
     mIOService = do_GetIOService(&rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
-#ifdef MOZ_OMNIJAR
-    nsCOMPtr<nsIFile> omniJar(mozilla::OmnijarPath());
-    if (omniJar)
-        return Init(omniJar);
-#endif
-
-    // these entries should be kept in sync with the omnijar Init function
+    nsCAutoString appURI, greURI;
+    rv = mozilla::Omnijar::GetURIString(mozilla::Omnijar::APP, appURI);
+    NS_ENSURE_SUCCESS(rv, rv);
+    rv = mozilla::Omnijar::GetURIString(mozilla::Omnijar::GRE, greURI);
+    NS_ENSURE_SUCCESS(rv, rv);
 
     //
-    // make resource:/// point to the application directory
+    // make resource:/// point to the application directory or omnijar
     //
-    rv = AddSpecialDir(NS_OS_CURRENT_PROCESS_DIR, EmptyCString());
+    nsCOMPtr<nsIURI> uri;
+    rv = NS_NewURI(getter_AddRefs(uri), appURI.Length() ? appURI : greURI);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    rv = SetSubstitution(EmptyCString(), uri);
     NS_ENSURE_SUCCESS(rv, rv);
 
     //
     // make resource://gre/ point to the GRE directory
     //
-    rv = AddSpecialDir(NS_GRE_DIR, kGRE);
+    if (appURI.Length()) { // We already have greURI in uri if appURI.Length() is 0.
+        rv = NS_NewURI(getter_AddRefs(uri), greURI);
+        NS_ENSURE_SUCCESS(rv, rv);
+    }
+
+    rv = SetSubstitution(kGRE, uri);
     NS_ENSURE_SUCCESS(rv, rv);
 
     //XXXbsmedberg Neil wants a resource://pchrome/ for the profile chrome dir...
     // but once I finish multiple chrome registration I'm not sure that it is needed
 
     // XXX dveditz: resource://pchrome/ defeats profile directory salting
     // if web content can load it. Tread carefully.
 
     return rv;
 }
 
-#ifdef MOZ_OMNIJAR
-nsresult
-nsResProtocolHandler::Init(nsIFile *aOmniJar)
-{
-    nsresult rv;
-    nsCOMPtr<nsIURI> uri;
-    nsCAutoString omniJarSpec;
-    NS_GetURLSpecFromActualFile(aOmniJar, omniJarSpec, mIOService);
-
-    nsCAutoString urlStr("jar:");
-    urlStr += omniJarSpec;
-    urlStr += "!/";
-
-    rv = mIOService->NewURI(urlStr, nsnull, nsnull, getter_AddRefs(uri));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    // these entries should be kept in sync with the normal Init function
-
-    // resource:/// points to jar:omni.jar!/
-    SetSubstitution(EmptyCString(), uri);
-
-    // resource://gre/ points to jar:omni.jar!/
-    SetSubstitution(kGRE, uri);
-
-    return NS_OK;
-}
-#endif
-
 #ifdef MOZ_IPC
 static PLDHashOperator
 EnumerateSubstitution(const nsACString& aKey,
                       nsIURI* aURI,
                       void* aArg)
 {
     nsTArray<ResourceMapping>* resources =
             static_cast<nsTArray<ResourceMapping>*>(aArg);
diff --git a/startupcache/StartupCache.cpp b/startupcache/StartupCache.cpp
--- a/startupcache/StartupCache.cpp
+++ b/startupcache/StartupCache.cpp
@@ -237,27 +237,36 @@ StartupCache::GetBuffer(const char* id, 
     nsZipItemPtr<char> zipItem(mArchive, id, true);
     if (zipItem) {
       *outbuf = zipItem.Forget();
       *length = zipItem.Length();
       return NS_OK;
     } 
   }
 
-#ifdef MOZ_OMNIJAR
-  if (mozilla::OmnijarReader()) {
+  if (mozilla::Omnijar::GetReader(mozilla::Omnijar::APP)) {
     // no need to checksum omnijarred entries
-    nsZipItemPtr<char> zipItem(mozilla::OmnijarReader(), id);
+    nsZipItemPtr<char> zipItem(mozilla::Omnijar::GetReader(mozilla::Omnijar::APP), id);
     if (zipItem) {
       *outbuf = zipItem.Forget();
       *length = zipItem.Length();
       return NS_OK;
     } 
   }
-#endif
+
+  if (mozilla::Omnijar::GetReader(mozilla::Omnijar::GRE)) {
+    // no need to checksum omnijarred entries
+    nsZipItemPtr<char> zipItem(mozilla::Omnijar::GetReader(mozilla::Omnijar::GRE), id);
+    if (zipItem) {
+      *outbuf = zipItem.Forget();
+      *length = zipItem.Length();
+      return NS_OK;
+    } 
+  }
+
   return NS_ERROR_NOT_AVAILABLE;
 }
 
 // Makes a copy of the buffer, client retains ownership of inbuf.
 nsresult
 StartupCache::PutBuffer(const char* id, const char* inbuf, PRUint32 len) 
 {
   WaitOnWriteThread();
diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -3897,35 +3897,45 @@ XRE_InitCommandLine(int aArgc, char* aAr
   CommandLine::Init(aArgc, canonArgs);
 
   for (int i = 0; i < aArgc; ++i)
       free(canonArgs[i]);
   delete[] canonArgs;
 #endif
 #endif
 
-#ifdef MOZ_OMNIJAR
-  const char *omnijarPath = nsnull;
-  ArgResult ar = CheckArg("omnijar", PR_FALSE, &omnijarPath);
+  const char *path = nsnull;
+  ArgResult ar = CheckArg("grebase", PR_FALSE, &path);
   if (ar == ARG_BAD) {
-    PR_fprintf(PR_STDERR, "Error: argument -omnijar requires an omnijar path\n");
+    PR_fprintf(PR_STDERR, "Error: argument -grebase requires a path argument\n");
     return NS_ERROR_FAILURE;
   }
 
-  if (!omnijarPath)
+  if (!path)
     return rv;
 
-  nsCOMPtr<nsILocalFile> omnijar;
-  rv = NS_NewNativeLocalFile(nsDependentCString(omnijarPath), PR_TRUE,
-                             getter_AddRefs(omnijar));
-  if (NS_SUCCEEDED(rv))
-    mozilla::SetOmnijar(omnijar);
-#endif
-
-  return rv;
+  nsCOMPtr<nsILocalFile> greBase;
+  rv = XRE_GetFileFromPath(path, getter_AddRefs(greBase));
+  if (NS_FAILED(rv))
+    return rv;
+
+  ar = CheckArg("appbase", PR_FALSE, &path);
+  if (ar == ARG_BAD) {
+    PR_fprintf(PR_STDERR, "Error: argument -appbase requires a path argument\n");
+    return NS_ERROR_FAILURE;
+  }
+
+  nsCOMPtr<nsILocalFile> appBase;
+  if (path) {
+      rv = XRE_GetFileFromPath(path, getter_AddRefs(appBase));
+      if (NS_FAILED(rv))
+        return rv;
+  }
+
+  return mozilla::Omnijar::SetBase(greBase, appBase);
 }
 
 nsresult
 XRE_DeinitCommandLine()
 {
   nsresult rv = NS_OK;
 
 #if defined(MOZ_IPC)
diff --git a/toolkit/xre/nsEmbedFunctions.cpp b/toolkit/xre/nsEmbedFunctions.cpp
--- a/toolkit/xre/nsEmbedFunctions.cpp
+++ b/toolkit/xre/nsEmbedFunctions.cpp
@@ -512,19 +512,17 @@ XRE_InitChildProcess(int aArgc,
       }
 
       // Run the UI event loop on the main thread.
       uiMessageLoop.MessageLoop::Run();
 
       // Allow ProcessChild to clean up after itself before going out of
       // scope and being deleted
       process->CleanUp();
-#ifdef MOZ_OMNIJAR
-      mozilla::SetOmnijar(nsnull);
-#endif
+      mozilla::Omnijar::SetBase(nsnull, nsnull);
     }
   }
 
   NS_LogTerm();
   return XRE_DeinitCommandLine();
 }
 
 MessageLoop*
diff --git a/xpcom/build/Makefile.in b/xpcom/build/Makefile.in
--- a/xpcom/build/Makefile.in
+++ b/xpcom/build/Makefile.in
@@ -64,28 +64,25 @@ CSRCS		= \
 		$(NULL)
 
 CPPSRCS		= \
 		$(XPCOM_GLUE_SRC_LCPPSRCS) \
 		$(XPCOM_GLUENS_SRC_LCPPSRCS) \
 		nsXPComInit.cpp \
 		nsXPCOMStrings.cpp \
 		Services.cpp \
+		Omnijar.cpp \
 		$(NULL)
 
 ifndef MOZ_ENABLE_LIBXUL
 ifeq (,$(filter-out WINNT WINCE OS2,$(OS_ARCH)))
 CPPSRCS += dlldeps.cpp
 endif
 endif
 
-ifdef MOZ_OMNIJAR
-CPPSRCS += Omnijar.cpp
-endif
-
 SHARED_LIBRARY_LIBS = \
 		$(DEPTH)/chrome/src/$(LIB_PREFIX)chrome_s.$(LIB_SUFFIX) \
 		../ds/$(LIB_PREFIX)xpcomds_s.$(LIB_SUFFIX) \
 		../io/$(LIB_PREFIX)xpcomio_s.$(LIB_SUFFIX) \
 		../components/$(LIB_PREFIX)xpcomcomponents_s.$(LIB_SUFFIX) \
 		../threads/$(LIB_PREFIX)xpcomthreads_s.$(LIB_SUFFIX) \
 		../proxy/src/$(LIB_PREFIX)xpcomproxy_s.$(LIB_SUFFIX) \
 		../base/$(LIB_PREFIX)xpcombase_s.$(LIB_SUFFIX) \
diff --git a/xpcom/build/Omnijar.cpp b/xpcom/build/Omnijar.cpp
--- a/xpcom/build/Omnijar.cpp
+++ b/xpcom/build/Omnijar.cpp
@@ -16,16 +16,17 @@
  *
  * The Initial Developer of the Original Code is
  * Mozilla Foundation.
  * Portions created by the Initial Developer are Copyright (C) 2010
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  *   Michael Wu <mwu@mozilla.com>
+ *   Mike Hommey <mh@glandium.org>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either the GNU General Public License Version 2 or later (the "GPL"), or
  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
@@ -33,69 +34,175 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "Omnijar.h"
 
-#include "nsILocalFile.h"
-#include "nsXULAppAPI.h"
+#include "nsIFile.h"
 #include "nsZipArchive.h"
+#include "nsNetUtil.h"
 
-static nsILocalFile* sOmnijarPath = nsnull;
-static nsZipArchive* sOmnijarReader = nsnull;
+namespace mozilla {
 
-static void
-SetupReader()
+nsIFile *Omnijar::sPath[2] = { nsnull, nsnull };
+PRBool Omnijar::sIsOmnijar[2] = { PR_FALSE, PR_FALSE };
+
+#ifdef MOZ_ENABLE_LIBXUL
+nsZipArchive *Omnijar::sReader[2] = { nsnull, nsnull };
+#endif
+
+static already_AddRefed<nsIFile>
+ComputePath(nsIFile *aPath, PRBool &aIsOmnijar)
 {
-    if (!sOmnijarPath) {
-        return;
+    PRBool isDir;
+    aIsOmnijar = PR_FALSE;
+    if (!aPath || NS_FAILED(aPath->IsDirectory(&isDir)) || !isDir)
+        return nsnull;
+
+    nsCOMPtr<nsIFile> path;
+#ifdef MOZ_ENABLE_LIBXUL
+    // Search for omni.jar in the given directory
+    if (!isDir || NS_FAILED(aPath->Clone(getter_AddRefs(path))))
+        return nsnull;
+
+    if (NS_FAILED(path->AppendNative(NS_LITERAL_CSTRING("omni.jar"))))
+        return nsnull;
+
+    if (NS_FAILED(path->Exists(&aIsOmnijar)))
+        return nsnull;
+#endif
+
+    if (!aIsOmnijar && NS_FAILED(aPath->Clone(getter_AddRefs(path))))
+        return nsnull;
+
+    return path.forget();
+}
+
+nsresult
+Omnijar::SetBase(nsIFile *aGrePath, nsIFile *aAppPath)
+{
+    NS_ABORT_IF_FALSE(aGrePath || !aAppPath, "Omnijar::SetBase(NULL, something) call forbidden");
+
+#ifdef MOZ_ENABLE_LIBXUL
+    if (sReader[GRE]) {
+        sReader[GRE]->CloseArchive();
+        delete sReader[GRE];
+    }
+    if (sReader[APP]) {
+        sReader[APP]->CloseArchive();
+        delete sReader[APP];
+    }
+    sReader[APP] = sReader[GRE] = nsnull;
+#endif
+
+    nsresult rv;
+    PRBool equals;
+    if (aAppPath) {
+        rv = aAppPath->Equals(aGrePath, &equals);
+        NS_ENSURE_SUCCESS(rv, rv);
+    } else {
+        equals = PR_TRUE;
     }
 
-    nsZipArchive* zipReader = new nsZipArchive();
-    if (!zipReader) {
-        NS_IF_RELEASE(sOmnijarPath);
-        return;
+    nsCOMPtr<nsIFile> grePath = ComputePath(aGrePath, sIsOmnijar[GRE]);
+    nsCOMPtr<nsIFile> appPath = ComputePath(equals ? nsnull : aAppPath, sIsOmnijar[APP]);
+
+    NS_IF_RELEASE(sPath[GRE]);
+    sPath[GRE] = grePath;
+    NS_IF_ADDREF(sPath[GRE]);
+
+    NS_IF_RELEASE(sPath[APP]);
+    sPath[APP] = appPath;
+    NS_IF_ADDREF(sPath[APP]);
+
+    return NS_OK;
+}
+
+already_AddRefed<nsIFile>
+Omnijar::GetBase(Type aType)
+{
+    NS_ABORT_IF_FALSE(sPath[0], "Omnijar not initialized");
+
+    if (!sIsOmnijar[aType]) {
+        NS_IF_ADDREF(sPath[aType]);
+        return sPath[aType];
     }
 
-    if (NS_FAILED(zipReader->OpenArchive(sOmnijarPath))) {
+    nsCOMPtr<nsIFile> file, path;
+    if (NS_FAILED(sPath[aType]->Clone(getter_AddRefs(file))))
+        return nsnull;
+
+    if (NS_FAILED(file->GetParent(getter_AddRefs(path))))
+        return nsnull;
+    return path.forget();
+}
+
+#ifdef MOZ_ENABLE_LIBXUL
+nsZipArchive *
+Omnijar::GetReader(Type aType)
+{
+    if (!sIsOmnijar[aType])
+        return nsnull;
+
+    if (sReader[aType])
+        return sReader[aType];
+
+    nsZipArchive* zipReader = new nsZipArchive();
+    if (!zipReader)
+        return nsnull;
+
+    if (NS_FAILED(zipReader->OpenArchive(sPath[aType]))) {
         delete zipReader;
-        NS_IF_RELEASE(sOmnijarPath);
-        return;
+        return nsnull;
     }
 
-    sOmnijarReader = zipReader;
+    return (sReader[aType] = zipReader);
 }
 
-nsILocalFile*
-mozilla::OmnijarPath()
+nsZipArchive *
+Omnijar::GetReader(nsIFile *aPath)
 {
-    if (!sOmnijarReader)
-        SetupReader();
+    PRBool equals;
+    nsresult rv;
 
-    return sOmnijarPath;
+    if (sIsOmnijar[GRE]) {
+        rv = sPath[GRE]->Equals(aPath, &equals);
+        if (NS_SUCCEEDED(rv) && equals)
+            return GetReader(GRE);
+    }
+    if (sIsOmnijar[APP]) {
+        rv = sPath[APP]->Equals(aPath, &equals);
+        if (NS_SUCCEEDED(rv) && equals)
+            return GetReader(APP);
+    }
+    return nsnull;
+}
+#endif
+
+nsresult
+Omnijar::GetURIString(Type aType, nsCString &result)
+{
+    NS_ABORT_IF_FALSE(sPath[0], "Omnijar not initialized");
+
+    result = "";
+
+    if ((aType == APP) && (!sPath[APP]))
+        return NS_OK;
+
+    nsCAutoString omniJarSpec;
+    nsresult rv = NS_GetURLSpecFromActualFile(sPath[aType], omniJarSpec);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    if (sIsOmnijar[aType]) {
+        result = "jar:";
+        result += omniJarSpec;
+        result += "!";
+    } else {
+        result = omniJarSpec;
+    }
+    result += "/";
+    return NS_OK;
 }
 
-nsZipArchive*
-mozilla::OmnijarReader()
-{
-    if (!sOmnijarReader)
-        SetupReader();
-
-    return sOmnijarReader;
-}
-
-void
-mozilla::SetOmnijar(nsILocalFile* aPath)
-{
-    NS_IF_RELEASE(sOmnijarPath);
-    if (sOmnijarReader) {
-        sOmnijarReader->CloseArchive();
-        delete sOmnijarReader;
-        sOmnijarReader = nsnull;
-    }
-
-    sOmnijarPath = aPath;
-    NS_IF_ADDREF(sOmnijarPath);
-}
-
+} /* namespace mozilla */
diff --git a/xpcom/build/Omnijar.h b/xpcom/build/Omnijar.h
--- a/xpcom/build/Omnijar.h
+++ b/xpcom/build/Omnijar.h
@@ -16,16 +16,17 @@
  *
  * The Initial Developer of the Original Code is
  * Mozilla Foundation.
  * Portions created by the Initial Developer are Copyright (C) 2010
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  *   Michael Wu <mwu@mozilla.com>
+ *   Mike Hommey <mh@glandium.org>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either the GNU General Public License Version 2 or later (the "GPL"), or
  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
@@ -34,29 +35,137 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef mozilla_Omnijar_h
 #define mozilla_Omnijar_h
 
-class nsILocalFile;
+#include "nscore.h"
+#include "nsTArray.h"
+#include "nsCOMPtr.h"
+#include "nsString.h"
+
+class nsIFile;
 class nsZipArchive;
-
-#ifdef MOZ_OMNIJAR
+class nsIURI;
 
 namespace mozilla {
 
+#ifdef MOZ_ENABLE_LIBXUL
+#define OMNIJAR_EXPORT
+#else
+#define OMNIJAR_EXPORT NS_EXPORT
+#endif
+
+class OMNIJAR_EXPORT Omnijar {
+private:
 /**
- * This returns the path to the omnijar.
- * If the omnijar isn't available, this function will return null.
- * Callers should fallback to flat packaging if null.
+ * Store an nsIFile for either a base directory when there is no omni.jar,
+ * or omni.jar itself. We can store two paths here, one for GRE
+ * (corresponding to resource://gre/) and one for APP
+ * (corresponding to resource:/// and resource://app/), but only
+ * store one when both point to the same location (unified).
  */
-nsILocalFile *OmnijarPath();
-nsZipArchive *OmnijarReader();
-void SetOmnijar(nsILocalFile* aPath);
+static nsIFile *sPath[2];
+/**
+ * Store whether the corresponding sPath is an omni.jar or a directory
+ */
+static PRBool sIsOmnijar[2];
+
+#ifdef MOZ_ENABLE_LIBXUL
+/**
+ * Cached nsZipArchives for the corresponding sPath
+ */
+static nsZipArchive *sReader[2];
+#endif
+
+public:
+enum Type {
+    GRE = 0,
+    APP = 1
+};
+
+/**
+ * Returns whether SetBase has been called at least once with
+ * a valid nsIFile
+ */
+static PRBool
+IsInitialized()
+{
+    // GRE path is always set after initialization.
+    return sPath[0] != nsnull;
+}
+
+/**
+ * Sets the base directories for GRE and APP. APP base directory
+ * may be nsnull, in case the APP and GRE directories are the same.
+ */
+static nsresult SetBase(nsIFile *aGrePath, nsIFile *aAppPath);
+
+/**
+ * Returns an nsIFile pointing to the omni.jar file for GRE or APP.
+ * Returns nsnull when there is no corresponding omni.jar.
+ * Also returns nsnull for APP in the unified case.
+ */
+static already_AddRefed<nsIFile>
+GetPath(Type aType)
+{
+    NS_ABORT_IF_FALSE(sPath[0], "Omnijar not initialized");
+
+    if (sIsOmnijar[aType]) {
+        NS_IF_ADDREF(sPath[aType]);
+        return sPath[aType];
+    }
+    return nsnull;
+}
+
+/**
+ * Returns whether GRE or APP use an omni.jar. Returns PR_False when
+ * using an omni.jar in the unified case.
+ */
+static PRBool
+HasOmnijar(Type aType)
+{
+    return sIsOmnijar[aType];
+}
+
+/**
+ * Returns the base directory for GRE or APP. In the unified case,
+ * returns nsnull for APP.
+ */
+static already_AddRefed<nsIFile> GetBase(Type aType);
+
+/**
+ * Returns a nsZipArchive pointer for the omni.jar file for GRE or
+ * APP. Returns nsnull in the same cases GetPath() would.
+ */
+#ifdef MOZ_ENABLE_LIBXUL
+static nsZipArchive *GetReader(Type aType);
+#else
+static nsZipArchive *GetReader(Type aType) { return nsnull; }
+#endif
+
+/**
+ * Returns a nsZipArchive pointer for the given path IAOI the given
+ * path is the omni.jar for either GRE or APP.
+ */
+#ifdef MOZ_ENABLE_LIBXUL
+static nsZipArchive *GetReader(nsIFile *aPath);
+#else
+static nsZipArchive *GetReader(nsIFile *aPath) { return nsnull; }
+#endif
+
+/**
+ * Returns the URI string corresponding to the omni.jar or directory
+ * for GRE or APP. i.e. jar:/path/to/omni.jar!/ for omni.jar and
+ * /path/to/base/dir/ otherwise. Returns an empty string for APP in
+ * the unified case.
+ * The returned URI is guaranteed to end with a slash.
+ */
+static nsresult GetURIString(Type aType, nsCString &result);
+
+}; /* class Omnijar */
 
 } /* namespace mozilla */
 
-#endif /* MOZ_OMNIJAR */
-
 #endif /* mozilla_Omnijar_h */
diff --git a/xpcom/build/nsXPComInit.cpp b/xpcom/build/nsXPComInit.cpp
--- a/xpcom/build/nsXPComInit.cpp
+++ b/xpcom/build/nsXPComInit.cpp
@@ -462,35 +462,35 @@ NS_InitXPCOM2(nsIServiceManager* *result
         nsDirectoryService::gService->Set(NS_XPCOM_LIBRARY_FILE, xpcomLib);
     }
     
     if (appFileLocationProvider) {
         rv = nsDirectoryService::gService->RegisterProvider(appFileLocationProvider);
         if (NS_FAILED(rv)) return rv;
     }
 
-#ifdef MOZ_OMNIJAR
     NS_TIME_FUNCTION_MARK("Next: Omnijar init");
 
-    if (!mozilla::OmnijarPath()) {
-        nsCOMPtr<nsILocalFile> omnijar;
+    if (!mozilla::Omnijar::IsInitialized()) {
+        nsCOMPtr<nsILocalFile> greDir, appDir;
         nsCOMPtr<nsIFile> file;
 
-        rv = NS_ERROR_FAILURE;
         nsDirectoryService::gService->Get(NS_GRE_DIR,
                                           NS_GET_IID(nsIFile),
                                           getter_AddRefs(file));
-        if (file)
-            rv = file->Append(NS_LITERAL_STRING("omni.jar"));
-        if (NS_SUCCEEDED(rv))
-            omnijar = do_QueryInterface(file);
-        if (NS_SUCCEEDED(rv))
-            mozilla::SetOmnijar(omnijar);
+        greDir = do_QueryInterface(file);
+
+        nsDirectoryService::gService->Get(NS_XPCOM_CURRENT_PROCESS_DIR,
+                                          NS_GET_IID(nsIFile),
+                                          getter_AddRefs(file));
+        appDir = do_QueryInterface(file);
+
+        rv = mozilla::Omnijar::SetBase(greDir, appDir);
+        NS_ENSURE_SUCCESS(rv, rv);
     }
-#endif
 
 #ifdef MOZ_IPC
     if ((sCommandLineWasInitialized = !CommandLine::IsInitialized())) {
         NS_TIME_FUNCTION_MARK("Next: IPC command line init");
 
 #ifdef OS_WIN
         CommandLine::Init(0, nsnull);
 #else
@@ -769,18 +769,16 @@ ShutdownXPCOM(nsIServiceManager* servMgr
         sCommandLineWasInitialized = false;
     }
     if (sExitManager) {
         delete sExitManager;
         sExitManager = nsnull;
     }
 #endif
 
-#ifdef MOZ_OMNIJAR
-    mozilla::SetOmnijar(nsnull);
-#endif
+    mozilla::Omnijar::SetBase(nsnull, nsnull);
 
     NS_LogTerm();
 
     return NS_OK;
 }
 
 } // namespace mozilla
diff --git a/xpcom/components/nsComponentManager.cpp b/xpcom/components/nsComponentManager.cpp
--- a/xpcom/components/nsComponentManager.cpp
+++ b/xpcom/components/nsComponentManager.cpp
@@ -175,18 +175,16 @@ NS_DEFINE_CID(kCategoryManagerCID, NS_CA
 #define COMPMGR_TIME_FUNCTION_CONTRACTID(cid)                                  \
   NS_TIME_FUNCTION_MIN_FMT(5, "%s (line %d) (contractid: %s)", MOZ_FUNCTION_NAME, \
                            __LINE__, (cid))
 #else
 #define COMPMGR_TIME_FUNCTION_CID(cid) do {} while (0)
 #define COMPMGR_TIME_FUNCTION_CONTRACTID(cid) do {} while (0)
 #endif
 
-#define kOMNIJAR_PREFIX  NS_LITERAL_CSTRING("resource:///")
-
 nsresult
 nsGetServiceFromCategory::operator()(const nsIID& aIID, void** aInstancePtr) const
 {
     nsresult rv;
     nsXPIDLCString value;
     nsCOMPtr<nsICategoryManager> catman;
     nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
     if (!compMgr) {
@@ -390,47 +388,44 @@ nsresult nsComponentManagerImpl::Init()
 
     nsCategoryManager::GetSingleton()->SuppressNotifications(true);
 
     RegisterModule(&kXPCOMModule, NULL);
 
     for (PRUint32 i = 0; i < sStaticModules->Length(); ++i)
         RegisterModule((*sStaticModules)[i], NULL);
 
-#ifdef MOZ_OMNIJAR
-    if (mozilla::OmnijarPath()) {
-        nsCOMPtr<nsIZipReader> omnijarReader = new nsJAR();
-        rv = omnijarReader->Open(mozilla::OmnijarPath());
-        if (NS_SUCCEEDED(rv))
-            RegisterJarManifest(omnijarReader, "chrome.manifest", false);
+    nsCOMPtr<nsIFile> appOmnijar = mozilla::Omnijar::GetPath(mozilla::Omnijar::APP);
+    if (appOmnijar) {
+        cl = sModuleLocations->InsertElementAt(1); // Insert after greDir
+        cl->type = NS_COMPONENT_LOCATION;
+        cl->location = do_QueryInterface(appOmnijar);
+        cl->jar = true;
     }
-#endif
+    nsCOMPtr<nsIFile> greOmnijar = mozilla::Omnijar::GetPath(mozilla::Omnijar::GRE);
+    if (greOmnijar) {
+        cl = sModuleLocations->InsertElementAt(0);
+        cl->type = NS_COMPONENT_LOCATION;
+        cl->location = do_QueryInterface(greOmnijar);
+        cl->jar = true;
+    }
 
     for (PRUint32 i = 0; i < sModuleLocations->Length(); ++i) {
         ComponentLocation& l = sModuleLocations->ElementAt(i);
         if (!l.jar) {
             RegisterManifestFile(l.type, l.location, false);
             continue;
         }
 
         nsCOMPtr<nsIZipReader> reader = do_CreateInstance(kZipReaderCID, &rv);
         rv = reader->Open(l.location);
         if (NS_SUCCEEDED(rv))
             RegisterJarManifest(reader, "chrome.manifest", false);
     }
 
-#ifdef MOZ_OMNIJAR
-    if (mozilla::OmnijarPath()) {
-        cl = sModuleLocations->InsertElementAt(0);
-        cl->type = NS_COMPONENT_LOCATION;
-        cl->location = mozilla::OmnijarPath();
-        cl->jar = true;
-    }
-#endif
-
     nsCategoryManager::GetSingleton()->SuppressNotifications(false);
 
     mStatus = NORMAL;
 
     return NS_OK;
 }
 
 void
# HG changeset patch
# Parent ff1b810f78226d7f4010909d3cde05a57fdcf20c
Bug 620931 part 4 - Fix resource://app/ to always point to the same as resource:///

diff --git a/netwerk/protocol/res/nsResProtocolHandler.cpp b/netwerk/protocol/res/nsResProtocolHandler.cpp
--- a/netwerk/protocol/res/nsResProtocolHandler.cpp
+++ b/netwerk/protocol/res/nsResProtocolHandler.cpp
@@ -74,16 +74,17 @@ static nsResProtocolHandler *gResHandler
 //    set NSPR_LOG_FILE=log.txt
 //
 // this enables PR_LOG_ALWAYS level information and places all output in
 // the file log.txt
 //
 static PRLogModuleInfo *gResLog;
 #endif
 
+#define kAPP           NS_LITERAL_CSTRING("app")
 #define kGRE           NS_LITERAL_CSTRING("gre")
 
 //----------------------------------------------------------------------------
 // nsResURL : overrides nsStandardURL::GetFile to provide nsIFile resolution
 //----------------------------------------------------------------------------
 
 nsresult
 nsResURL::EnsureFile()
@@ -179,16 +180,22 @@ nsResProtocolHandler::Init()
     nsCOMPtr<nsIURI> uri;
     rv = NS_NewURI(getter_AddRefs(uri), appURI.Length() ? appURI : greURI);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = SetSubstitution(EmptyCString(), uri);
     NS_ENSURE_SUCCESS(rv, rv);
 
     //
+    // make resource://app/ point to the application directory or omnijar
+    //
+    rv = SetSubstitution(kAPP, uri);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    //
     // make resource://gre/ point to the GRE directory
     //
     if (appURI.Length()) { // We already have greURI in uri if appURI.Length() is 0.
         rv = NS_NewURI(getter_AddRefs(uri), greURI);
         NS_ENSURE_SUCCESS(rv, rv);
     }
 
     rv = SetSubstitution(kGRE, uri);
diff --git a/toolkit/xre/nsXREDirProvider.cpp b/toolkit/xre/nsXREDirProvider.cpp
--- a/toolkit/xre/nsXREDirProvider.cpp
+++ b/toolkit/xre/nsXREDirProvider.cpp
@@ -300,19 +300,16 @@ nsXREDirProvider::GetFile(const char* aP
     }
   }
   else if (!strcmp(aProperty, XRE_EXECUTABLE_FILE) && gArgv[0]) {
     nsCOMPtr<nsILocalFile> lf;
     rv = XRE_GetBinaryPath(gArgv[0], getter_AddRefs(lf));
     if (NS_SUCCEEDED(rv))
       file = lf;
   }
-  else if (!strcmp(aProperty, "resource:app")) {
-    rv = GetAppDir()->Clone(getter_AddRefs(file));
-  }
 
   else if (!strcmp(aProperty, NS_APP_PROFILE_DIR_STARTUP) && mProfileDir) {
     return mProfileDir->Clone(aFile);
   }
   else if (!strcmp(aProperty, NS_APP_PROFILE_LOCAL_DIR_STARTUP)) {
     if (mProfileLocalDir)
       return mProfileLocalDir->Clone(aFile);
 
# HG changeset patch
# Parent 7d2228db71a299afca60babff632a967d2d6c456
Bug 620931 part 5 - Enable omni.jar by default on xulrunner

diff --git a/xulrunner/confvars.sh b/xulrunner/confvars.sh
--- a/xulrunner/confvars.sh
+++ b/xulrunner/confvars.sh
@@ -36,15 +36,16 @@
 #
 # ***** END LICENSE BLOCK *****
 
 MOZ_APP_NAME=xulrunner
 MOZ_APP_DISPLAYNAME=XULRunner
 MOZ_UPDATER=1
 MOZ_XULRUNNER=1
 MOZ_ENABLE_LIBXUL=1
+MOZ_CHROME_FILE_FORMAT=omni
 MOZ_STATIC_BUILD_UNSUPPORTED=1
 MOZ_APP_VERSION=$MOZILLA_VERSION
 if test "$MOZ_STORAGE"; then
   MOZ_PLACES=1
 fi
 MOZ_EXTENSIONS_DEFAULT=" gnomevfs"
 MOZ_URL_CLASSIFIER=1