--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -110,16 +110,18 @@ XPCOMUtils.defineLazyModuleGetter(this,
XPCOMUtils.defineLazyModuleGetter(this, "Notifications",
"resource://gre/modules/Notifications.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "ReaderMode", "resource://gre/modules/ReaderMode.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Snackbars", "resource://gre/modules/Snackbars.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "RuntimePermissions", "resource://gre/modules/RuntimePermissions.jsm");
+
XPCOMUtils.defineLazyServiceGetter(this, "FontEnumerator",
"@mozilla.org/gfx/fontenumerator;1",
"nsIFontEnumerator");
var lazilyLoadedBrowserScripts = [
["SelectHelper", "chrome://browser/content/SelectHelper.js"],
["InputWidgetHelper", "chrome://browser/content/InputWidgetHelper.js"],
["MasterPassword", "chrome://browser/content/MasterPassword.js"],
@@ -1415,38 +1417,44 @@ var BrowserApp = {
BrowserApp.sanitize(aClear.sanitize, function() {
let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
appStartup.quit(Ci.nsIAppStartup.eForceQuit);
});
},
saveAsPDF: function saveAsPDF(aBrowser) {
- Task.spawn(function* () {
- let fileName = ContentAreaUtils.getDefaultFileName(aBrowser.contentTitle, aBrowser.currentURI, null, null);
- fileName = fileName.trim() + ".pdf";
-
- let downloadsDir = yield Downloads.getPreferredDownloadsDirectory();
- let file = OS.Path.join(downloadsDir, fileName);
-
- // Force this to have a unique name.
- let openedFile = yield OS.File.openUnique(file, { humanReadable: true });
- file = openedFile.path;
- yield openedFile.file.close();
-
- let download = yield Downloads.createDownload({
- source: aBrowser.contentWindow,
- target: file,
- saver: "pdf",
- startTime: Date.now(),
+ RuntimePermissions.waitForPermissions(RuntimePermissions.WRITE_EXTERNAL_STORAGE).then(function(permissionGranted) {
+ if (!permissionGranted) {
+ return;
+ }
+
+ Task.spawn(function* () {
+ let fileName = ContentAreaUtils.getDefaultFileName(aBrowser.contentTitle, aBrowser.currentURI, null, null);
+ fileName = fileName.trim() + ".pdf";
+
+ let downloadsDir = yield Downloads.getPreferredDownloadsDirectory();
+ let file = OS.Path.join(downloadsDir, fileName);
+
+ // Force this to have a unique name.
+ let openedFile = yield OS.File.openUnique(file, { humanReadable: true });
+ file = openedFile.path;
+ yield openedFile.file.close();
+
+ let download = yield Downloads.createDownload({
+ source: aBrowser.contentWindow,
+ target: file,
+ saver: "pdf",
+ startTime: Date.now(),
+ });
+
+ let list = yield Downloads.getList(download.source.isPrivate ? Downloads.PRIVATE : Downloads.PUBLIC)
+ yield list.add(download);
+ yield download.start();
});
-
- let list = yield Downloads.getList(download.source.isPrivate ? Downloads.PRIVATE : Downloads.PUBLIC)
- yield list.add(download);
- yield download.start();
});
},
notifyPrefObservers: function(aPref) {
this._prefObservers[aPref].forEach(function(aRequestId) {
this.getPreferences(aRequestId, [aPref], 1);
}, this);
},