2010-04-28 23:08:15 -07:00
|
|
|
/* This code is mostly copied from chrome/test/unit/head_crtestutils.js */
|
|
|
|
|
|
|
|
const NS_CHROME_MANIFESTS_FILE_LIST = "ChromeML";
|
|
|
|
const XUL_CACHE_PREF = "nglayout.debug.disable_xul_cache";
|
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cr = Components.results;
|
|
|
|
|
2010-06-27 14:04:45 -07:00
|
|
|
let gDirSvc = Cc["@mozilla.org/file/directory_service;1"].
|
|
|
|
getService(Ci.nsIDirectoryService).QueryInterface(Ci.nsIProperties);
|
2010-04-28 23:08:15 -07:00
|
|
|
let gChromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"].
|
|
|
|
getService(Ci.nsIXULChromeRegistry);
|
|
|
|
let gPrefs = Cc["@mozilla.org/preferences-service;1"].
|
|
|
|
getService(Ci.nsIPrefBranch);
|
|
|
|
|
2010-06-27 14:04:45 -07:00
|
|
|
// Create the temporary file in the profile, instead of in TmpD, because
|
|
|
|
// we know the mochitest harness kills off the profile when it's done.
|
|
|
|
function copyToTemporaryFile(f)
|
2010-04-28 23:08:15 -07:00
|
|
|
{
|
2010-06-27 14:04:45 -07:00
|
|
|
let tmpd = gDirSvc.get("ProfD", Ci.nsIFile);
|
|
|
|
tmpf = tmpd.clone();
|
|
|
|
tmpf.append("temp.manifest");
|
|
|
|
tmpf.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0600);
|
2010-06-29 20:24:09 -07:00
|
|
|
tmpf.remove(false);
|
2010-06-27 14:04:45 -07:00
|
|
|
|
|
|
|
f.copyTo(tmpd, tmpf.leafName);
|
|
|
|
return tmpf;
|
|
|
|
}
|
|
|
|
|
|
|
|
function convertChromeURI(chromeURI)
|
|
|
|
{
|
|
|
|
let uri = Cc["@mozilla.org/network/io-service;1"].
|
|
|
|
getService(Ci.nsIIOService).newURI(chromeURI, null, null);
|
|
|
|
return gChromeReg.convertChromeURL(uri);
|
2010-04-28 23:08:15 -07:00
|
|
|
}
|
|
|
|
|
2010-06-27 14:04:45 -07:00
|
|
|
function chromeURIToFile(chromeURI)
|
2010-04-28 23:08:15 -07:00
|
|
|
{
|
2010-08-24 10:29:34 -07:00
|
|
|
var jar = getJar(chromeURI);
|
|
|
|
if (jar) {
|
|
|
|
var tmpDir = extractJarToTmp(jar);
|
|
|
|
let parts = chromeURI.split('/');
|
|
|
|
if (parts[parts.length - 1] != '') {
|
|
|
|
tmpDir.append(parts[parts.length - 1]);
|
|
|
|
}
|
|
|
|
return tmpDir;
|
|
|
|
}
|
|
|
|
|
2010-06-27 14:04:45 -07:00
|
|
|
return convertChromeURI(chromeURI).
|
|
|
|
QueryInterface(Ci.nsIFileURL).file;
|
|
|
|
}
|
2010-04-28 23:08:15 -07:00
|
|
|
|
2010-06-27 14:04:45 -07:00
|
|
|
// Register a chrome manifest temporarily and return a function which un-does
|
|
|
|
// the registrarion when no longer needed.
|
|
|
|
function registerManifestTemporarily(manifestURI)
|
|
|
|
{
|
2010-04-28 23:08:15 -07:00
|
|
|
gPrefs.setBoolPref(XUL_CACHE_PREF, true);
|
|
|
|
|
2010-06-27 14:04:45 -07:00
|
|
|
let file = chromeURIToFile(manifestURI);
|
|
|
|
let tempfile = copyToTemporaryFile(file);
|
2010-06-27 11:03:05 -07:00
|
|
|
Components.manager.QueryInterface(Ci.nsIComponentRegistrar).
|
2010-06-27 14:04:45 -07:00
|
|
|
autoRegister(tempfile);
|
|
|
|
|
|
|
|
gChromeReg.refreshSkins();
|
|
|
|
|
|
|
|
return function() {
|
|
|
|
tempfile.fileSize = 0; // truncate the manifest
|
|
|
|
gChromeReg.checkForNewChrome();
|
|
|
|
gChromeReg.refreshSkins();
|
|
|
|
gPrefs.clearUserPref(XUL_CACHE_PREF);
|
|
|
|
}
|
2010-04-28 23:08:15 -07:00
|
|
|
}
|
|
|
|
|
2010-06-27 14:04:45 -07:00
|
|
|
function registerManifestPermanently(manifestURI)
|
2010-04-28 23:08:15 -07:00
|
|
|
{
|
2010-06-27 14:04:45 -07:00
|
|
|
Components.manager.QueryInterface(Ci.nsIComponentRegistrar).
|
|
|
|
autoRegister(chromeURIToFile(manifestURI));
|
2010-04-28 23:08:15 -07:00
|
|
|
}
|