toolkit/mozapps/installer/precompile_cache.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 // see http://mxr.mozilla.org/mozilla-central/source/services/sync/Weave.js#76
michael@0 8
michael@0 9 const Cc = Components.classes;
michael@0 10 const Ci = Components.interfaces;
michael@0 11 const Cu = Components.utils;
michael@0 12
michael@0 13 Cu.import("resource://gre/modules/Services.jsm");
michael@0 14
michael@0 15 const rph = Services.io.getProtocolHandler("resource").QueryInterface(Ci.nsIResProtocolHandler);
michael@0 16
michael@0 17 function endsWith(str, end) {
michael@0 18 return str.slice(-end.length) == end;
michael@0 19 }
michael@0 20
michael@0 21 function jar_entries(jarReader, pattern) {
michael@0 22 var entries = [];
michael@0 23 var enumerator = jarReader.findEntries(pattern);
michael@0 24 while (enumerator.hasMore()) {
michael@0 25 entries.push(enumerator.getNext());
michael@0 26 }
michael@0 27 return entries;
michael@0 28 }
michael@0 29
michael@0 30 function dir_entries(baseDir, subpath, ext) {
michael@0 31 var dir = baseDir.clone();
michael@0 32 dir.append(subpath);
michael@0 33 var enumerator = dir.directoryEntries;
michael@0 34 var entries = [];
michael@0 35 while (enumerator.hasMoreElements()) {
michael@0 36 var file = enumerator.getNext().QueryInterface(Ci.nsIFile);
michael@0 37 if (file.isDirectory()) {
michael@0 38 entries = entries.concat(dir_entries(dir, file.leafName, ext).map(function(p) subpath + "/" + p));
michael@0 39 } else if (endsWith(file.leafName, ext)) {
michael@0 40 entries.push(subpath + "/" + file.leafName);
michael@0 41 }
michael@0 42 }
michael@0 43 return entries;
michael@0 44 }
michael@0 45
michael@0 46 function get_modules_under(uri) {
michael@0 47 if (uri instanceof Ci.nsIJARURI) {
michael@0 48 var jar = uri.QueryInterface(Ci.nsIJARURI);
michael@0 49 var jarReader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(Ci.nsIZipReader);
michael@0 50 var file = jar.JARFile.QueryInterface(Ci.nsIFileURL);
michael@0 51 jarReader.open(file.file);
michael@0 52 var entries = jar_entries(jarReader, "components/*.js")
michael@0 53 .concat(jar_entries(jarReader, "modules/*.js"))
michael@0 54 .concat(jar_entries(jarReader, "modules/*.jsm"));
michael@0 55 jarReader.close();
michael@0 56 return entries;
michael@0 57 } else if (uri instanceof Ci.nsIFileURL){
michael@0 58 var file = uri.QueryInterface(Ci.nsIFileURL);
michael@0 59 return dir_entries(file.file, "components", ".js")
michael@0 60 .concat(dir_entries(file.file, "modules", ".js"))
michael@0 61 .concat(dir_entries(file.file, "modules", ".jsm"));
michael@0 62 } else {
michael@0 63 throw "Expected a nsIJARURI or nsIFileURL";
michael@0 64 }
michael@0 65 }
michael@0 66
michael@0 67 function load_modules_under(spec, uri) {
michael@0 68 var entries = get_modules_under(uri).sort();
michael@0 69 // The precompilation of JS here sometimes reports errors, which we don't
michael@0 70 // really care about. But if the errors are ever reported to xpcshell's
michael@0 71 // error reporter, it will cause it to return an error code, which will break
michael@0 72 // automation. Currently they won't be, because the component loader spins up
michael@0 73 // its JSContext before xpcshell has time to set its context callback (which
michael@0 74 // overrides the error reporter on all newly-created JSContexts). But as we
michael@0 75 // move towards a singled-cxed browser, we'll run into this. So let's be
michael@0 76 // forward-thinking and deal with it now.
michael@0 77 ignoreReportedErrors(true);
michael@0 78 for each (let entry in entries) {
michael@0 79 try {
michael@0 80 dump(spec + entry + "\n");
michael@0 81 Cu.import(spec + entry, null);
michael@0 82 } catch(e) {}
michael@0 83 }
michael@0 84 ignoreReportedErrors(false);
michael@0 85 }
michael@0 86
michael@0 87 function resolveResource(spec) {
michael@0 88 var uri = Services.io.newURI(spec, null, null);
michael@0 89 return Services.io.newURI(rph.resolveURI(uri), null, null);
michael@0 90 }
michael@0 91
michael@0 92 function precompile_startupcache(uri) {
michael@0 93 load_modules_under(uri, resolveResource(uri));
michael@0 94 }

mercurial