Bug 1334975 - Get rid of nsIFilePicker.show() use in gecko, r=ochameau

This commit is contained in:
Andrea Marchesini 2017-03-03 09:42:27 +01:00
Родитель 9b8c984305
Коммит 24004054a8
23 изменённых файлов: 462 добавлений и 359 удалений

Просмотреть файл

@ -47,22 +47,23 @@ module.exports = createClass({
fp.init(window, fp.init(window,
Strings.GetStringFromName("selectAddonFromFile2"), Strings.GetStringFromName("selectAddonFromFile2"),
Ci.nsIFilePicker.modeOpen); Ci.nsIFilePicker.modeOpen);
let res = fp.show(); fp.open(res => {
if (res == Ci.nsIFilePicker.returnCancel || !fp.file) { if (res == Ci.nsIFilePicker.returnCancel || !fp.file) {
return; return;
} }
let file = fp.file; let file = fp.file;
// AddonManager.installTemporaryAddon accepts either // AddonManager.installTemporaryAddon accepts either
// addon directory or final xpi file. // addon directory or final xpi file.
if (!file.isDirectory() && !file.leafName.endsWith(".xpi")) { if (!file.isDirectory() && !file.leafName.endsWith(".xpi")) {
file = file.parent; file = file.parent;
} }
AddonManager.installTemporaryAddon(file) AddonManager.installTemporaryAddon(file)
.catch(e => { .catch(e => {
console.error(e); console.error(e);
this.setState({ installError: e.message }); this.setState({ installError: e.message });
}); });
});
}, },
render() { render() {

Просмотреть файл

@ -113,7 +113,7 @@ function getTabList(document) {
function* installAddon({document, path, name, isWebExtension}) { function* installAddon({document, path, name, isWebExtension}) {
// Mock the file picker to select a test addon // Mock the file picker to select a test addon
let MockFilePicker = SpecialPowers.MockFilePicker; let MockFilePicker = SpecialPowers.MockFilePicker;
MockFilePicker.init(null); MockFilePicker.init(window);
let file = getSupportsFile(path); let file = getSupportsFile(path);
MockFilePicker.returnFiles = [file.file]; MockFilePicker.returnFiles = [file.file];

Просмотреть файл

@ -357,38 +357,40 @@ var SnapshotsListView = Heritage.extend(WidgetMethods, {
fp.appendFilter(L10N.getStr("snapshotsList.saveDialogJSONFilter"), "*.json"); fp.appendFilter(L10N.getStr("snapshotsList.saveDialogJSONFilter"), "*.json");
fp.appendFilter(L10N.getStr("snapshotsList.saveDialogAllFilter"), "*.*"); fp.appendFilter(L10N.getStr("snapshotsList.saveDialogAllFilter"), "*.*");
if (fp.show() != Ci.nsIFilePicker.returnOK) { fp.open(rv => {
return; if (rv != Ci.nsIFilePicker.returnOK) {
}
let channel = NetUtil.newChannel({
uri: NetUtil.newURI(fp.file), loadUsingSystemPrincipal: true});
channel.contentType = "text/plain";
NetUtil.asyncFetch(channel, (inputStream, status) => {
if (!Components.isSuccessCode(status)) {
console.error("Could not import recorded animation frame snapshot file.");
return;
}
try {
let string = NetUtil.readInputStreamToString(inputStream, inputStream.available());
var data = JSON.parse(string);
} catch (e) {
console.error("Could not read animation frame snapshot file.");
return;
}
if (data.fileType != CALLS_LIST_SERIALIZER_IDENTIFIER) {
console.error("Unrecognized animation frame snapshot file.");
return; return;
} }
// Add a `isLoadedFromDisk` flag on everything to avoid sending invalid let channel = NetUtil.newChannel({
// requests to the backend, since we're not dealing with actors anymore. uri: NetUtil.newURI(fp.file), loadUsingSystemPrincipal: true});
let snapshotItem = this.addSnapshot(); channel.contentType = "text/plain";
snapshotItem.isLoadedFromDisk = true;
data.calls.forEach(e => e.isLoadedFromDisk = true);
this.customizeSnapshot(snapshotItem, data.calls, data); NetUtil.asyncFetch(channel, (inputStream, status) => {
if (!Components.isSuccessCode(status)) {
console.error("Could not import recorded animation frame snapshot file.");
return;
}
try {
let string = NetUtil.readInputStreamToString(inputStream, inputStream.available());
var data = JSON.parse(string);
} catch (e) {
console.error("Could not read animation frame snapshot file.");
return;
}
if (data.fileType != CALLS_LIST_SERIALIZER_IDENTIFIER) {
console.error("Unrecognized animation frame snapshot file.");
return;
}
// Add a `isLoadedFromDisk` flag on everything to avoid sending invalid
// requests to the backend, since we're not dealing with actors anymore.
let snapshotItem = this.addSnapshot();
snapshotItem.isLoadedFromDisk = true;
data.calls.forEach(e => e.isLoadedFromDisk = true);
this.customizeSnapshot(snapshotItem, data.calls, data);
});
}); });
}, },

Просмотреть файл

@ -50,11 +50,11 @@ var JsonView = {
* in the parent process. * in the parent process.
*/ */
onSave: function (message) { onSave: function (message) {
let value = message.data; JsonViewUtils.getTargetFile(file => {
let file = JsonViewUtils.getTargetFile(); if (file) {
if (file) { JsonViewUtils.saveToFile(file, message.data);
JsonViewUtils.saveToFile(file, value); }
} });
} }
}; };

Просмотреть файл

@ -23,21 +23,24 @@ const OPEN_FLAGS = {
* Open File Save As dialog and let the user to pick proper file location. * Open File Save As dialog and let the user to pick proper file location.
*/ */
exports.getTargetFile = function () { exports.getTargetFile = function () {
let fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker); return new Promise(resolve => {
let fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
let win = getMostRecentBrowserWindow(); let win = getMostRecentBrowserWindow();
fp.init(win, null, Ci.nsIFilePicker.modeSave); fp.init(win, null, Ci.nsIFilePicker.modeSave);
fp.appendFilter("JSON Files", "*.json; *.jsonp;"); fp.appendFilter("JSON Files", "*.json; *.jsonp;");
fp.appendFilters(Ci.nsIFilePicker.filterText); fp.appendFilters(Ci.nsIFilePicker.filterText);
fp.appendFilters(Ci.nsIFilePicker.filterAll); fp.appendFilters(Ci.nsIFilePicker.filterAll);
fp.filterIndex = 0; fp.filterIndex = 0;
let rv = fp.show(); fp.open(rv => {
if (rv == Ci.nsIFilePicker.returnOK || rv == Ci.nsIFilePicker.returnReplace) { if (rv == Ci.nsIFilePicker.returnOK || rv == Ci.nsIFilePicker.returnReplace) {
return fp.file; resolve(fp.file);
} } else {
resolve(null);
return null; }
});
});
}; };
/** /**

Просмотреть файл

@ -56,7 +56,7 @@ var HarUtils = {
* Open File Save As dialog and let the user pick the proper file * Open File Save As dialog and let the user pick the proper file
* location for generated HAR log. * location for generated HAR log.
*/ */
getTargetFile: function (fileName, jsonp, compress) { getTargetFile: function (fileName, jsonp, compress, cb) {
let browser = getMostRecentBrowserWindow(); let browser = getMostRecentBrowserWindow();
let fp = Cc["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker); let fp = Cc["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
@ -68,12 +68,13 @@ var HarUtils = {
fp.defaultString = this.getHarFileName(fileName, jsonp, compress); fp.defaultString = this.getHarFileName(fileName, jsonp, compress);
let rv = fp.show(); fp.open(rv => {
if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) { if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
return fp.file; cb(fp.file);
} } else {
cb(null);
return null; }
});
}, },
getHarFileName: function (defaultFileName, jsonp, compress) { getHarFileName: function (defaultFileName, jsonp, compress) {

Просмотреть файл

@ -359,9 +359,11 @@ var PerformanceView = {
fp.appendFilter(L10N.getStr("recordingsList.saveDialogJSONFilter"), "*.json"); fp.appendFilter(L10N.getStr("recordingsList.saveDialogJSONFilter"), "*.json");
fp.appendFilter(L10N.getStr("recordingsList.saveDialogAllFilter"), "*.*"); fp.appendFilter(L10N.getStr("recordingsList.saveDialogAllFilter"), "*.*");
if (fp.show() == Ci.nsIFilePicker.returnOK) { fp.open(rv => {
this.emit(EVENTS.UI_IMPORT_RECORDING, fp.file); if (rv == Ci.nsIFilePicker.returnOK) {
} this.emit(EVENTS.UI_IMPORT_RECORDING, fp.file);
}
});
}, },
/** /**

Просмотреть файл

@ -110,62 +110,65 @@ function doOK() {
return false; return false;
} }
let folder;
/* Chrome mochitest support */ /* Chrome mochitest support */
let testOptions = window.arguments[0].testOptions; let promise = new Promise((resolve, reject) => {
if (testOptions) { let testOptions = window.arguments[0].testOptions;
folder = testOptions.folder; if (testOptions) {
} else { resolve(testOptions.folder);
let fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker); } else {
fp.init(window, "Select directory where to create app directory", Ci.nsIFilePicker.modeGetFolder); let fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
let res = fp.show(); fp.init(window, "Select directory where to create app directory", Ci.nsIFilePicker.modeGetFolder);
if (res == Ci.nsIFilePicker.returnCancel) { fp.open(res => {
console.error("No directory selected"); if (res == Ci.nsIFilePicker.returnCancel) {
return false; console.error("No directory selected");
reject(null);
} else {
resolve(fp.file);
}
});
} }
folder = fp.file; });
}
// Create subfolder with fs-friendly name of project
let subfolder = projectName.replace(/[\\/:*?"<>|]/g, "").toLowerCase();
let win = Services.wm.getMostRecentWindow("devtools:webide");
folder.append(subfolder);
try {
folder.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
} catch (e) {
win.UI.reportError("error_folderCreationFailed");
window.close();
return false;
}
// Download boilerplate zip
let template = gTemplateList[templatelistNode.selectedIndex];
let source = template.file;
let target = folder.clone();
target.append(subfolder + ".zip");
let bail = (e) => { let bail = (e) => {
console.error(e); console.error(e);
window.close(); window.close();
}; };
Downloads.fetch(source, target).then(() => { promise.then(folder => {
ZipUtils.extractFiles(target, folder); // Create subfolder with fs-friendly name of project
target.remove(false); let subfolder = projectName.replace(/[\\/:*?"<>|]/g, "").toLowerCase();
AppProjects.addPackaged(folder).then((project) => { let win = Services.wm.getMostRecentWindow("devtools:webide");
window.arguments[0].location = project.location; folder.append(subfolder);
AppManager.validateAndUpdateProject(project).then(() => {
if (project.manifest) { try {
project.manifest.name = projectName; folder.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
AppManager.writeManifest(project).then(() => { } catch (e) {
AppManager.validateAndUpdateProject(project).then( win.UI.reportError("error_folderCreationFailed");
() => {window.close();}, bail); window.close();
}, bail); return;
} else { }
bail("Manifest not found");
} // Download boilerplate zip
let template = gTemplateList[templatelistNode.selectedIndex];
let source = template.file;
let target = folder.clone();
target.append(subfolder + ".zip");
Downloads.fetch(source, target).then(() => {
ZipUtils.extractFiles(target, folder);
target.remove(false);
AppProjects.addPackaged(folder).then((project) => {
window.arguments[0].location = project.location;
AppManager.validateAndUpdateProject(project).then(() => {
if (project.manifest) {
project.manifest.name = projectName;
AppManager.writeManifest(project).then(() => {
AppManager.validateAndUpdateProject(project).then(
() => {window.close();}, bail);
}, bail);
} else {
bail("Manifest not found");
}
}, bail);
}, bail); }, bail);
}, bail); }, bail);
}, bail); }, bail);

Просмотреть файл

@ -289,12 +289,13 @@ var SimulatorEditor = {
case "version": case "version":
switch (input.value) { switch (input.value) {
case "pick": case "pick":
let file = utils.getCustomBinary(window); utils.getCustomBinary(window).then(file => {
if (file) { if (file) {
this.version = file.path; this.version = file.path;
} }
// Whatever happens, don't stay on the "pick" option. // Whatever happens, don't stay on the "pick" option.
this.updateVersionSelector(); this.updateVersionSelector();
});
break; break;
case "custom": case "custom":
this.version = input[input.selectedIndex].textContent; this.version = input[input.selectedIndex].textContent;
@ -306,12 +307,13 @@ var SimulatorEditor = {
case "profile": case "profile":
switch (input.value) { switch (input.value) {
case "pick": case "pick":
let directory = utils.getCustomProfile(window); utils.getCustomProfile(window).then(directory => {
if (directory) { if (directory) {
this.profile = directory.path; this.profile = directory.path;
} }
// Whatever happens, don't stay on the "pick" option. // Whatever happens, don't stay on the "pick" option.
this.updateProfileSelector(); this.updateProfileSelector();
});
break; break;
case "custom": case "custom":
this.profile = input[input.selectedIndex].textContent; this.profile = input[input.selectedIndex].textContent;

Просмотреть файл

@ -92,7 +92,7 @@ ProjectList.prototype = {
let parentWindow = this._parentWindow; let parentWindow = this._parentWindow;
let UI = this._UI; let UI = this._UI;
return UI.busyUntil(Task.spawn(function* () { return UI.busyUntil(Task.spawn(function* () {
let directory = utils.getPackagedDirectory(parentWindow, location); let directory = yield utils.getPackagedDirectory(parentWindow, location);
if (!directory) { if (!directory) {
// User cancelled directory selection // User cancelled directory selection

Просмотреть файл

@ -15,15 +15,20 @@ exports.doesFileExist = doesFileExist;
function _getFile(location, ...pickerParams) { function _getFile(location, ...pickerParams) {
if (location) { if (location) {
return new FileUtils.File(location); return Promise.resolve(new FileUtils.File(location));
} }
let fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker); let fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
fp.init(...pickerParams); fp.init(...pickerParams);
let res = fp.show();
if (res == Ci.nsIFilePicker.returnCancel) { return new Promise(resolve => {
return null; fp.open(res => {
} if (res == Ci.nsIFilePicker.returnCancel) {
return fp.file; resolve(null);
} else {
resolve(fp.file);
}
});
});
} }
function getCustomBinary(window, location) { function getCustomBinary(window, location) {

Просмотреть файл

@ -167,10 +167,12 @@ function openFile()
.createInstance(nsIFilePicker); .createInstance(nsIFilePicker);
fp.init(window, "Select a File", nsIFilePicker.modeOpen); fp.init(window, "Select a File", nsIFilePicker.modeOpen);
fp.appendFilters(nsIFilePicker.filterHTML | nsIFilePicker.filterAll); fp.appendFilters(nsIFilePicker.filterHTML | nsIFilePicker.filterAll);
if (fp.show() == nsIFilePicker.returnOK && fp.fileURL.spec && fp.open(rv => {
fp.fileURL.spec.length > 0) { if (rv == nsIFilePicker.returnOK && fp.fileURL.spec &&
gBrowser.loadURI(fp.fileURL.spec); fp.fileURL.spec.length > 0) {
} gBrowser.loadURI(fp.fileURL.spec);
}
});
} }
const LDB_RDFNS = "http://mozilla.org/newlayout/LDB-rdf#"; const LDB_RDFNS = "http://mozilla.org/newlayout/LDB-rdf#";
const NC_RDFNS = "http://home.netscape.com/NC-rdf#"; const NC_RDFNS = "http://home.netscape.com/NC-rdf#";
@ -264,17 +266,19 @@ RTestIndexList.prototype = {
fp.init(window, "New Regression Test List", nsIFilePicker.modeOpen); fp.init(window, "New Regression Test List", nsIFilePicker.modeOpen);
fp.appendFilters(nsIFilePicker.filterAll); fp.appendFilters(nsIFilePicker.filterAll);
fp.defaultString = "rtest.lst"; fp.defaultString = "rtest.lst";
if (fp.show() != nsIFilePicker.returnOK) fp.open(rv => {
return; if (rv != nsIFilePicker.returnOK) {
return;
}
var file = fp.file.persistentDescriptor; var file = fp.file.persistentDescriptor;
var resource = this.mRDFService.GetResource(file); var resource = this.mRDFService.GetResource(file);
var literal = this.mRDFService.GetLiteral(file); var literal = this.mRDFService.GetLiteral(file);
this.mDataSource.Assert(this.mLDB_Root, this.mNC_Child, resource, true); this.mDataSource.Assert(this.mLDB_Root, this.mNC_Child, resource, true);
this.mDataSource.Assert(resource, this.mNC_Name, literal, true); this.mDataSource.Assert(resource, this.mNC_Name, literal, true);
this.save();
this.save();
});
}, },
remove : function(file) remove : function(file)

Просмотреть файл

@ -332,10 +332,11 @@ function backupCerts()
fp.appendFilter(bundle.getString("file_browse_PKCS12_spec"), fp.appendFilter(bundle.getString("file_browse_PKCS12_spec"),
"*.p12"); "*.p12");
fp.appendFilters(nsIFilePicker.filterAll); fp.appendFilters(nsIFilePicker.filterAll);
var rv = fp.show(); fp.open(rv => {
if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) { if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
certdb.exportPKCS12File(fp.file, selected_certs.length, selected_certs); certdb.exportPKCS12File(fp.file, selected_certs.length, selected_certs);
} }
});
} }
function backupAllCerts() function backupAllCerts()
@ -367,7 +368,11 @@ function restoreCerts()
fp.appendFilter(bundle.getString("file_browse_Certificate_spec"), fp.appendFilter(bundle.getString("file_browse_Certificate_spec"),
gCertFileTypes); gCertFileTypes);
fp.appendFilters(nsIFilePicker.filterAll); fp.appendFilters(nsIFilePicker.filterAll);
if (fp.show() == nsIFilePicker.returnOK) { fp.open(rv => {
if (rv != nsIFilePicker.returnOK) {
return;
}
// If this is an X509 user certificate, import it as one. // If this is an X509 user certificate, import it as one.
var isX509FileType = false; var isX509FileType = false;
@ -407,7 +412,7 @@ function restoreCerts()
caTreeView.loadCertsFromCache(certcache, nsIX509Cert.CA_CERT); caTreeView.loadCertsFromCache(certcache, nsIX509Cert.CA_CERT);
caTreeView.selection.clearSelection(); caTreeView.selection.clearSelection();
enableBackupAllButton(); enableBackupAllButton();
} });
} }
function exportCerts() function exportCerts()
@ -485,11 +490,13 @@ function addCACerts()
fp.appendFilter(bundle.getString("file_browse_Certificate_spec"), fp.appendFilter(bundle.getString("file_browse_Certificate_spec"),
gCertFileTypes); gCertFileTypes);
fp.appendFilters(nsIFilePicker.filterAll); fp.appendFilters(nsIFilePicker.filterAll);
if (fp.show() == nsIFilePicker.returnOK) { fp.open(rv => {
certdb.importCertsFromFile(fp.file, nsIX509Cert.CA_CERT); if (rv == nsIFilePicker.returnOK) {
caTreeView.loadCerts(nsIX509Cert.CA_CERT); certdb.importCertsFromFile(fp.file, nsIX509Cert.CA_CERT);
caTreeView.selection.clearSelection(); caTreeView.loadCerts(nsIX509Cert.CA_CERT);
} caTreeView.selection.clearSelection();
}
});
} }
function onSmartCardChange() function onSmartCardChange()
@ -519,14 +526,16 @@ function addEmailCert()
fp.appendFilter(bundle.getString("file_browse_Certificate_spec"), fp.appendFilter(bundle.getString("file_browse_Certificate_spec"),
gCertFileTypes); gCertFileTypes);
fp.appendFilters(nsIFilePicker.filterAll); fp.appendFilters(nsIFilePicker.filterAll);
if (fp.show() == nsIFilePicker.returnOK) { fp.open(rv => {
certdb.importCertsFromFile(fp.file, nsIX509Cert.EMAIL_CERT); if (rv == nsIFilePicker.returnOK) {
var certcache = certdb.getCerts(); certdb.importCertsFromFile(fp.file, nsIX509Cert.EMAIL_CERT);
emailTreeView.loadCertsFromCache(certcache, nsIX509Cert.EMAIL_CERT); var certcache = certdb.getCerts();
emailTreeView.selection.clearSelection(); emailTreeView.loadCertsFromCache(certcache, nsIX509Cert.EMAIL_CERT);
caTreeView.loadCertsFromCache(certcache, nsIX509Cert.CA_CERT); emailTreeView.selection.clearSelection();
caTreeView.selection.clearSelection(); caTreeView.loadCertsFromCache(certcache, nsIX509Cert.CA_CERT);
} caTreeView.selection.clearSelection();
}
});
} }
function addException() function addException()

Просмотреть файл

@ -76,6 +76,7 @@ this.MockFilePicker = {
this.returnFiles = []; this.returnFiles = [];
this.returnValue = null; this.returnValue = null;
this.showCallback = null; this.showCallback = null;
this.afterOpenCallback = null;
this.shown = false; this.shown = false;
this.showing = false; this.showing = false;
}, },
@ -210,6 +211,9 @@ MockFilePickerInstance.prototype = {
}; };
}, },
show: function() { show: function() {
throw "This is not implemented";
},
_openInternal: function() {
MockFilePicker.displayDirectory = this.displayDirectory; MockFilePicker.displayDirectory = this.displayDirectory;
MockFilePicker.shown = true; MockFilePicker.shown = true;
if (typeof MockFilePicker.showCallback == "function") { if (typeof MockFilePicker.showCallback == "function") {
@ -224,12 +228,17 @@ MockFilePickerInstance.prototype = {
this.window.setTimeout(function() { this.window.setTimeout(function() {
let result = Components.interfaces.nsIFilePicker.returnCancel; let result = Components.interfaces.nsIFilePicker.returnCancel;
try { try {
result = this.show(); result = this._openInternal();
} catch(ex) { } catch(ex) {
} }
if (aFilePickerShownCallback) { if (aFilePickerShownCallback) {
aFilePickerShownCallback.done(result); aFilePickerShownCallback.done(result);
} }
if (typeof MockFilePicker.afterOpenCallback == "function") {
this.window.setTimeout(() => {
MockFilePicker.afterOpenCallback(this);
}, 0);
}
}.bind(this), 0); }.bind(this), 0);
} }
}; };

Просмотреть файл

@ -193,15 +193,17 @@ AppPicker.prototype =
fp.displayDirectory = fp.displayDirectory =
fileLoc.get(startLocation, Components.interfaces.nsILocalFile); fileLoc.get(startLocation, Components.interfaces.nsILocalFile);
if (fp.show() == nsIFilePicker.returnOK && fp.file) { fp.open(rv => {
var localHandlerApp = if (rv == nsIFilePicker.returnOK && fp.file) {
Components.classes["@mozilla.org/uriloader/local-handler-app;1"]. var localHandlerApp =
createInstance(Components.interfaces.nsILocalHandlerApp); Components.classes["@mozilla.org/uriloader/local-handler-app;1"].
localHandlerApp.executable = fp.file; createInstance(Components.interfaces.nsILocalHandlerApp);
localHandlerApp.executable = fp.file;
this._incomingParams.handlerApp = localHandlerApp; this._incomingParams.handlerApp = localHandlerApp;
window.close(); window.close();
} }
});
return true; return true;
} }
} }

Просмотреть файл

@ -302,7 +302,11 @@ function onLoad() {
// --------------------------------------------------- // ---------------------------------------------------
function onAccept() { function onAccept() {
if (gPrintSettings != null) { let promise;
if (gPrintSettings == null) {
promise = Promise.resolve();
} else {
var print_howToEnableUI = gPrintSetInterface.kFrameEnableNone; var print_howToEnableUI = gPrintSetInterface.kFrameEnableNone;
// save these out so they can be picked up by the device spec // save these out so they can be picked up by the device spec
@ -310,66 +314,75 @@ function onAccept() {
print_howToEnableUI = gPrintSettings.howToEnableFrameUI; print_howToEnableUI = gPrintSettings.howToEnableFrameUI;
gPrintSettings.printToFile = dialog.fileCheck.checked; gPrintSettings.printToFile = dialog.fileCheck.checked;
if (gPrintSettings.printToFile && !chooseFile()) if (gPrintSettings.printToFile) {
return false; promise = chooseFile();
} else {
if (dialog.allpagesRadio.selected) { promise = Promise.resolve();
gPrintSettings.printRange = gPrintSetInterface.kRangeAllPages;
} else if (dialog.rangeRadio.selected) {
gPrintSettings.printRange = gPrintSetInterface.kRangeSpecifiedPageRange;
} else if (dialog.selectionRadio.selected) {
gPrintSettings.printRange = gPrintSetInterface.kRangeSelection;
} }
gPrintSettings.startPageRange = dialog.frompageInput.value;
gPrintSettings.endPageRange = dialog.topageInput.value;
gPrintSettings.numCopies = dialog.numCopiesInput.value;
var frametype = gPrintSetInterface.kNoFrames; promise = promise.then(() => {
if (print_howToEnableUI != gPrintSetInterface.kFrameEnableNone) { if (dialog.allpagesRadio.selected) {
if (dialog.aslaidoutRadio.selected) { gPrintSettings.printRange = gPrintSetInterface.kRangeAllPages;
frametype = gPrintSetInterface.kFramesAsIs; } else if (dialog.rangeRadio.selected) {
} else if (dialog.selectedframeRadio.selected) { gPrintSettings.printRange = gPrintSetInterface.kRangeSpecifiedPageRange;
frametype = gPrintSetInterface.kSelectedFrame; } else if (dialog.selectionRadio.selected) {
} else if (dialog.eachframesepRadio.selected) { gPrintSettings.printRange = gPrintSetInterface.kRangeSelection;
frametype = gPrintSetInterface.kEachFrameSep;
} else {
frametype = gPrintSetInterface.kSelectedFrame;
} }
gPrintSettings.startPageRange = dialog.frompageInput.value;
gPrintSettings.endPageRange = dialog.topageInput.value;
gPrintSettings.numCopies = dialog.numCopiesInput.value;
var frametype = gPrintSetInterface.kNoFrames;
if (print_howToEnableUI != gPrintSetInterface.kFrameEnableNone) {
if (dialog.aslaidoutRadio.selected) {
frametype = gPrintSetInterface.kFramesAsIs;
} else if (dialog.selectedframeRadio.selected) {
frametype = gPrintSetInterface.kSelectedFrame;
} else if (dialog.eachframesepRadio.selected) {
frametype = gPrintSetInterface.kEachFrameSep;
} else {
frametype = gPrintSetInterface.kSelectedFrame;
}
}
gPrintSettings.printFrameType = frametype;
if (doDebug) {
dump("onAccept*********************************************\n");
dump("frametype " + frametype + "\n");
dump("numCopies " + gPrintSettings.numCopies + "\n");
dump("printRange " + gPrintSettings.printRange + "\n");
dump("printerName " + gPrintSettings.printerName + "\n");
dump("startPageRange " + gPrintSettings.startPageRange + "\n");
dump("endPageRange " + gPrintSettings.endPageRange + "\n");
dump("printToFile " + gPrintSettings.printToFile + "\n");
}
});
}
promise.then(() => {
var saveToPrefs = false;
saveToPrefs = gPrefs.getBoolPref("print.save_print_settings");
if (saveToPrefs && printService != null) {
var flags = gPrintSetInterface.kInitSavePaperSize |
gPrintSetInterface.kInitSaveEdges |
gPrintSetInterface.kInitSaveInColor |
gPrintSetInterface.kInitSaveShrinkToFit |
gPrintSetInterface.kInitSaveScaling;
printService.savePrintSettingsToPrefs(gPrintSettings, true, flags);
} }
gPrintSettings.printFrameType = frametype;
if (doDebug) { // set return value to "print"
dump("onAccept*********************************************\n"); if (paramBlock) {
dump("frametype " + frametype + "\n"); paramBlock.SetInt(0, 1);
dump("numCopies " + gPrintSettings.numCopies + "\n"); } else {
dump("printRange " + gPrintSettings.printRange + "\n"); dump("*** FATAL ERROR: No paramBlock\n");
dump("printerName " + gPrintSettings.printerName + "\n");
dump("startPageRange " + gPrintSettings.startPageRange + "\n");
dump("endPageRange " + gPrintSettings.endPageRange + "\n");
dump("printToFile " + gPrintSettings.printToFile + "\n");
} }
}
var saveToPrefs = false; window.close();
});
saveToPrefs = gPrefs.getBoolPref("print.save_print_settings"); return false;
if (saveToPrefs && printService != null) {
var flags = gPrintSetInterface.kInitSavePaperSize |
gPrintSetInterface.kInitSaveEdges |
gPrintSetInterface.kInitSaveInColor |
gPrintSetInterface.kInitSaveShrinkToFit |
gPrintSetInterface.kInitSaveScaling;
printService.savePrintSettingsToPrefs(gPrintSettings, true, flags);
}
// set return value to "print"
if (paramBlock) {
paramBlock.SetInt(0, 1);
} else {
dump("*** FATAL ERROR: No paramBlock\n");
}
return true;
} }
// --------------------------------------------------- // ---------------------------------------------------
@ -387,19 +400,17 @@ function onCancel() {
// --------------------------------------------------- // ---------------------------------------------------
const nsIFilePicker = Components.interfaces.nsIFilePicker; const nsIFilePicker = Components.interfaces.nsIFilePicker;
function chooseFile() { function chooseFile() {
try { return new Promise(resolve => {
var fp = Components.classes["@mozilla.org/filepicker;1"] var fp = Components.classes["@mozilla.org/filepicker;1"]
.createInstance(nsIFilePicker); .createInstance(nsIFilePicker);
fp.init(window, dialog.fpDialog.getAttribute("label"), nsIFilePicker.modeSave); fp.init(window, dialog.fpDialog.getAttribute("label"), nsIFilePicker.modeSave);
fp.appendFilters(nsIFilePicker.filterAll); fp.appendFilters(nsIFilePicker.filterAll);
if (fp.show() != Components.interfaces.nsIFilePicker.returnCancel && fp.open(rv => {
fp.file && fp.file.path) { if (rv != Components.interfaces.nsIFilePicker.returnCancel &&
gPrintSettings.toFileName = fp.file.path; fp.file && fp.file.path) {
return true; gPrintSettings.toFileName = fp.file.path;
} resolve(null);
} catch (ex) { }
dump(ex); });
} });
return false;
} }

Просмотреть файл

@ -316,53 +316,55 @@ nsUnknownContentTypeDialog.prototype = {
if (lastDir && isUsableDirectory(lastDir)) if (lastDir && isUsableDirectory(lastDir))
picker.displayDirectory = lastDir; picker.displayDirectory = lastDir;
if (picker.show() == nsIFilePicker.returnCancel) { picker.open(returnValue => {
// null result means user cancelled. if (returnValue == nsIFilePicker.returnCancel) {
aLauncher.saveDestinationAvailable(null); // null result means user cancelled.
return; aLauncher.saveDestinationAvailable(null);
} return;
// Be sure to save the directory the user chose through the Save As...
// dialog as the new browser.download.dir since the old one
// didn't exist.
result = picker.file;
if (result) {
try {
// Remove the file so that it's not there when we ensure non-existence later;
// this is safe because for the file to exist, the user would have had to
// confirm that he wanted the file overwritten.
// Only remove file if final name exists
if (result.exists() && this.getFinalLeafName(result.leafName) == result.leafName)
result.remove(false);
}
catch (ex) {
// As it turns out, the failure to remove the file, for example due to
// permission error, will be handled below eventually somehow.
} }
var newDir = result.parent.QueryInterface(Components.interfaces.nsILocalFile); // Be sure to save the directory the user chose through the Save As...
// dialog as the new browser.download.dir since the old one
// didn't exist.
result = picker.file;
// Do not store the last save directory as a pref inside the private browsing mode if (result) {
gDownloadLastDir.setFile(aLauncher.source, newDir); try {
// Remove the file so that it's not there when we ensure non-existence later;
try { // this is safe because for the file to exist, the user would have had to
result = this.validateLeafName(newDir, result.leafName, null); // confirm that he wanted the file overwritten.
} // Only remove file if final name exists
catch (ex) { if (result.exists() && this.getFinalLeafName(result.leafName) == result.leafName)
// When the chosen download directory is write-protected, result.remove(false);
// display an informative error message. }
// In all cases, download will be stopped. catch (ex) {
// As it turns out, the failure to remove the file, for example due to
if (ex.result == Components.results.NS_ERROR_FILE_ACCESS_DENIED) { // permission error, will be handled below eventually somehow.
this.displayBadPermissionAlert();
aLauncher.saveDestinationAvailable(null);
return;
} }
var newDir = result.parent.QueryInterface(Components.interfaces.nsILocalFile);
// Do not store the last save directory as a pref inside the private browsing mode
gDownloadLastDir.setFile(aLauncher.source, newDir);
try {
result = this.validateLeafName(newDir, result.leafName, null);
}
catch (ex) {
// When the chosen download directory is write-protected,
// display an informative error message.
// In all cases, download will be stopped.
if (ex.result == Components.results.NS_ERROR_FILE_ACCESS_DENIED) {
this.displayBadPermissionAlert();
aLauncher.saveDestinationAvailable(null);
return;
}
}
} }
} aLauncher.saveDestinationAvailable(result);
aLauncher.saveDestinationAvailable(result); });
}.bind(this)); }.bind(this));
}.bind(this)).then(null, Components.utils.reportError); }.bind(this)).then(null, Components.utils.reportError);
}, },

Просмотреть файл

@ -1411,17 +1411,19 @@ var gViewController = {
fp.appendFilters(nsIFilePicker.filterAll); fp.appendFilters(nsIFilePicker.filterAll);
} catch (e) { } } catch (e) { }
if (fp.show() != nsIFilePicker.returnOK) fp.open(result => {
return; if (result != nsIFilePicker.returnOK)
return;
let browser = getBrowserElement(); let browser = getBrowserElement();
let files = fp.files; let files = fp.files;
while (files.hasMoreElements()) { while (files.hasMoreElements()) {
let file = files.getNext(); let file = files.getNext();
AddonManager.getInstallForFile(file, install => { AddonManager.getInstallForFile(file, install => {
AddonManager.installAddonFromAOM(browser, document.documentURI, install); AddonManager.installAddonFromAOM(browser, document.documentURI, install);
}); });
} }
});
} }
}, },

Просмотреть файл

@ -374,10 +374,12 @@
} }
} catch (e) {} } catch (e) {}
} }
if (filePicker.show() != Ci.nsIFilePicker.returnCancel) { filePicker.open(rv => {
this.value = filePicker.file.path; if (rv != Ci.nsIFilePicker.returnCancel && filePicker.file) {
this.inputChanged(); this.value = filePicker.file.path;
} this.inputChanged();
}
});
]]> ]]>
</body> </body>
</method> </method>

Просмотреть файл

@ -277,20 +277,25 @@ add_test(function() {
is(input.color, "#FF9900", "Color picker should have updated value"); is(input.color, "#FF9900", "Color picker should have updated value");
is(Services.prefs.getCharPref("extensions.inlinesettings1.color"), "#FF9900", "Color pref should have been updated"); is(Services.prefs.getCharPref("extensions.inlinesettings1.color"), "#FF9900", "Color pref should have been updated");
try { ok(!settings[6].hasAttribute("first-row"), "Not the first row");
ok(!settings[6].hasAttribute("first-row"), "Not the first row"); var button = gManagerWindow.document.getAnonymousElementByAttribute(settings[6], "anonid", "button");
var button = gManagerWindow.document.getAnonymousElementByAttribute(settings[6], "anonid", "button"); input = gManagerWindow.document.getAnonymousElementByAttribute(settings[6], "anonid", "input");
input = gManagerWindow.document.getAnonymousElementByAttribute(settings[6], "anonid", "input"); is(input.value, "", "Label value should be empty");
is(input.value, "", "Label value should be empty"); is(input.tooltipText, "", "Label tooltip should be empty");
is(input.tooltipText, "", "Label tooltip should be empty");
var testFile = Services.dirsvc.get("ProfD", Ci.nsIFile); var testFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
testFile.append("\u2622"); testFile.append("\u2622");
var curProcD = Services.dirsvc.get("CurProcD", Ci.nsIFile); var curProcD = Services.dirsvc.get("CurProcD", Ci.nsIFile);
MockFilePicker.returnFiles = [testFile]; MockFilePicker.returnFiles = [testFile];
MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK; MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK;
let promise = new Promise(resolve => {
MockFilePicker.afterOpenCallback = resolve;
EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
});
promise.then(() => {
is(MockFilePicker.mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file"); is(MockFilePicker.mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file");
is(input.value, testFile.path, "Label value should match file chosen"); is(input.value, testFile.path, "Label value should match file chosen");
is(input.tooltipText, testFile.path, "Label tooltip should match file chosen"); is(input.tooltipText, testFile.path, "Label tooltip should match file chosen");
@ -298,7 +303,12 @@ add_test(function() {
MockFilePicker.returnFiles = [curProcD]; MockFilePicker.returnFiles = [curProcD];
MockFilePicker.returnValue = Ci.nsIFilePicker.returnCancel; MockFilePicker.returnValue = Ci.nsIFilePicker.returnCancel;
EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
return new Promise(resolve => {
MockFilePicker.afterOpenCallback = resolve;
EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
});
}).then(() => {
is(MockFilePicker.mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file"); is(MockFilePicker.mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file");
is(input.value, testFile.path, "Label value should not have changed"); is(input.value, testFile.path, "Label value should not have changed");
is(input.tooltipText, testFile.path, "Label tooltip should not have changed"); is(input.tooltipText, testFile.path, "Label tooltip should not have changed");
@ -312,7 +322,12 @@ add_test(function() {
MockFilePicker.returnFiles = [testFile]; MockFilePicker.returnFiles = [testFile];
MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK; MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK;
EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
return new Promise(resolve => {
MockFilePicker.afterOpenCallback = resolve;
EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
});
}).then(() => {
is(MockFilePicker.mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory"); is(MockFilePicker.mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory");
is(input.value, testFile.path, "Label value should match file chosen"); is(input.value, testFile.path, "Label value should match file chosen");
is(input.tooltipText, testFile.path, "Label tooltip should match file chosen"); is(input.tooltipText, testFile.path, "Label tooltip should match file chosen");
@ -320,7 +335,12 @@ add_test(function() {
MockFilePicker.returnFiles = [curProcD]; MockFilePicker.returnFiles = [curProcD];
MockFilePicker.returnValue = Ci.nsIFilePicker.returnCancel; MockFilePicker.returnValue = Ci.nsIFilePicker.returnCancel;
EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
return new Promise(resolve => {
MockFilePicker.afterOpenCallback = resolve;
EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
});
}).then(() => {
is(MockFilePicker.mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory"); is(MockFilePicker.mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory");
is(input.value, testFile.path, "Label value should not have changed"); is(input.value, testFile.path, "Label value should not have changed");
is(input.tooltipText, testFile.path, "Label tooltip should not have changed"); is(input.tooltipText, testFile.path, "Label tooltip should not have changed");
@ -329,12 +349,12 @@ add_test(function() {
var unsizedInput = gManagerWindow.document.getAnonymousElementByAttribute(settings[2], "anonid", "input"); var unsizedInput = gManagerWindow.document.getAnonymousElementByAttribute(settings[2], "anonid", "input");
var sizedInput = gManagerWindow.document.getAnonymousElementByAttribute(settings[8], "anonid", "input"); var sizedInput = gManagerWindow.document.getAnonymousElementByAttribute(settings[8], "anonid", "input");
is(unsizedInput.clientWidth > sizedInput.clientWidth, true, "Input with size attribute should be smaller than input without"); is(unsizedInput.clientWidth > sizedInput.clientWidth, true, "Input with size attribute should be smaller than input without");
} finally { }).then(() => {
button = gManagerWindow.document.getElementById("detail-prefs-btn"); button = gManagerWindow.document.getElementById("detail-prefs-btn");
is_element_hidden(button, "Preferences button should not be visible"); is_element_hidden(button, "Preferences button should not be visible");
gCategoryUtilities.openType("extension", run_next_test); gCategoryUtilities.openType("extension", run_next_test);
} });
}); });
}); });

Просмотреть файл

@ -269,23 +269,28 @@ add_test(function() {
is(input.color, "#FF9900", "Color picker should have updated value"); is(input.color, "#FF9900", "Color picker should have updated value");
is(Services.prefs.getCharPref("extensions.inlinesettings1.color"), "#FF9900", "Color pref should have been updated"); is(Services.prefs.getCharPref("extensions.inlinesettings1.color"), "#FF9900", "Color pref should have been updated");
try { ok(!settings[6].hasAttribute("first-row"), "Not the first row");
ok(!settings[6].hasAttribute("first-row"), "Not the first row"); var button = gManagerWindow.document.getAnonymousElementByAttribute(settings[6], "anonid", "button");
var button = gManagerWindow.document.getAnonymousElementByAttribute(settings[6], "anonid", "button");
// Workaround for bug 1155324 - we need to ensure that the button is scrolled into view. // Workaround for bug 1155324 - we need to ensure that the button is scrolled into view.
button.scrollIntoView(); button.scrollIntoView();
input = gManagerWindow.document.getAnonymousElementByAttribute(settings[6], "anonid", "input"); input = gManagerWindow.document.getAnonymousElementByAttribute(settings[6], "anonid", "input");
is(input.value, "", "Label value should be empty"); is(input.value, "", "Label value should be empty");
is(input.tooltipText, "", "Label tooltip should be empty"); is(input.tooltipText, "", "Label tooltip should be empty");
var profD = Services.dirsvc.get("ProfD", Ci.nsIFile); var profD = Services.dirsvc.get("ProfD", Ci.nsIFile);
var curProcD = Services.dirsvc.get("CurProcD", Ci.nsIFile); var curProcD = Services.dirsvc.get("CurProcD", Ci.nsIFile);
MockFilePicker.returnFiles = [profD]; MockFilePicker.returnFiles = [profD];
MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK; MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK;
let promise = new Promise(resolve => {
MockFilePicker.afterOpenCallback = resolve;
EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
});
promise.then(() => {
is(MockFilePicker.mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file"); is(MockFilePicker.mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file");
is(input.value, profD.path, "Label value should match file chosen"); is(input.value, profD.path, "Label value should match file chosen");
is(input.tooltipText, profD.path, "Label tooltip should match file chosen"); is(input.tooltipText, profD.path, "Label tooltip should match file chosen");
@ -293,7 +298,12 @@ add_test(function() {
MockFilePicker.returnFiles = [curProcD]; MockFilePicker.returnFiles = [curProcD];
MockFilePicker.returnValue = Ci.nsIFilePicker.returnCancel; MockFilePicker.returnValue = Ci.nsIFilePicker.returnCancel;
EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
return promise = new Promise(resolve => {
MockFilePicker.afterOpenCallback = resolve;
EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
});
}).then(() => {
is(MockFilePicker.mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file"); is(MockFilePicker.mode, Ci.nsIFilePicker.modeOpen, "File picker mode should be open file");
is(input.value, profD.path, "Label value should not have changed"); is(input.value, profD.path, "Label value should not have changed");
is(input.tooltipText, profD.path, "Label tooltip should not have changed"); is(input.tooltipText, profD.path, "Label tooltip should not have changed");
@ -307,7 +317,12 @@ add_test(function() {
MockFilePicker.returnFiles = [profD]; MockFilePicker.returnFiles = [profD];
MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK; MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK;
EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
return new Promise(resolve => {
MockFilePicker.afterOpenCallback = resolve;
EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
});
}).then(() => {
is(MockFilePicker.mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory"); is(MockFilePicker.mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory");
is(input.value, profD.path, "Label value should match file chosen"); is(input.value, profD.path, "Label value should match file chosen");
is(input.tooltipText, profD.path, "Label tooltip should match file chosen"); is(input.tooltipText, profD.path, "Label tooltip should match file chosen");
@ -315,18 +330,22 @@ add_test(function() {
MockFilePicker.returnFiles = [curProcD]; MockFilePicker.returnFiles = [curProcD];
MockFilePicker.returnValue = Ci.nsIFilePicker.returnCancel; MockFilePicker.returnValue = Ci.nsIFilePicker.returnCancel;
EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
return new Promise(resolve => {
MockFilePicker.afterOpenCallback = resolve;
EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
});
}).then(() => {
is(MockFilePicker.mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory"); is(MockFilePicker.mode, Ci.nsIFilePicker.modeGetFolder, "File picker mode should be directory");
is(input.value, profD.path, "Label value should not have changed"); is(input.value, profD.path, "Label value should not have changed");
is(input.tooltipText, profD.path, "Label tooltip should not have changed"); is(input.tooltipText, profD.path, "Label tooltip should not have changed");
is(Services.prefs.getCharPref("extensions.inlinesettings1.directory"), profD.path, "Directory pref should not have changed"); is(Services.prefs.getCharPref("extensions.inlinesettings1.directory"), profD.path, "Directory pref should not have changed");
}).then(() => {
} finally {
button = gManagerWindow.document.getElementById("detail-prefs-btn"); button = gManagerWindow.document.getElementById("detail-prefs-btn");
is_element_hidden(button, "Preferences button should not be visible"); is_element_hidden(button, "Preferences button should not be visible");
gCategoryUtilities.openType("extension", run_next_test); gCategoryUtilities.openType("extension", run_next_test);
} });
}); });
}); });

Просмотреть файл

@ -166,35 +166,37 @@ var dialog = {
fp.init(window, title, Ci.nsIFilePicker.modeOpen); fp.init(window, title, Ci.nsIFilePicker.modeOpen);
fp.appendFilters(Ci.nsIFilePicker.filterApps); fp.appendFilters(Ci.nsIFilePicker.filterApps);
if (fp.show() == Ci.nsIFilePicker.returnOK && fp.file) { fp.open(rv => {
let uri = Cc["@mozilla.org/network/util;1"]. if (rv == Ci.nsIFilePicker.returnOK && fp.file) {
getService(Ci.nsIIOService). let uri = Cc["@mozilla.org/network/util;1"].
newFileURI(fp.file); getService(Ci.nsIIOService).
newFileURI(fp.file);
let handlerApp = Cc["@mozilla.org/uriloader/local-handler-app;1"]. let handlerApp = Cc["@mozilla.org/uriloader/local-handler-app;1"].
createInstance(Ci.nsILocalHandlerApp); createInstance(Ci.nsILocalHandlerApp);
handlerApp.executable = fp.file; handlerApp.executable = fp.file;
// if this application is already in the list, select it and don't add it again // if this application is already in the list, select it and don't add it again
let parent = document.getElementById("items"); let parent = document.getElementById("items");
for (let i = 0; i < parent.childNodes.length; ++i) { for (let i = 0; i < parent.childNodes.length; ++i) {
let elm = parent.childNodes[i]; let elm = parent.childNodes[i];
if (elm.obj instanceof Ci.nsILocalHandlerApp && elm.obj.equals(handlerApp)) { if (elm.obj instanceof Ci.nsILocalHandlerApp && elm.obj.equals(handlerApp)) {
parent.selectedItem = elm; parent.selectedItem = elm;
parent.ensureSelectedElementIsVisible(); parent.ensureSelectedElementIsVisible();
return; return;
}
} }
let elm = document.createElement("richlistitem");
elm.setAttribute("type", "handler");
elm.setAttribute("name", fp.file.leafName);
elm.setAttribute("image", "moz-icon://" + uri.spec + "?size=32");
elm.obj = handlerApp;
parent.selectedItem = parent.insertBefore(elm, parent.firstChild);
parent.ensureSelectedElementIsVisible();
} }
});
let elm = document.createElement("richlistitem");
elm.setAttribute("type", "handler");
elm.setAttribute("name", fp.file.leafName);
elm.setAttribute("image", "moz-icon://" + uri.spec + "?size=32");
elm.obj = handlerApp;
parent.selectedItem = parent.insertBefore(elm, parent.firstChild);
parent.ensureSelectedElementIsVisible();
}
}, },
/** /**

Просмотреть файл

@ -165,6 +165,8 @@ interface nsIFilePicker : nsISupports
attribute boolean addToRecentDocs; attribute boolean addToRecentDocs;
/** /**
* This method is **deprecated**. Please use open()
*
* Show File Dialog. The dialog is displayed modally. * Show File Dialog. The dialog is displayed modally.
* *
* @return returnOK if the user selects OK, returnCancel if the user selects cancel * @return returnOK if the user selects OK, returnCancel if the user selects cancel