| author | Simone Bruno <sbruno@mozilla.com> |
| Mon, 31 Mar 2014 19:59:04 +0200 | |
| changeset 176187 | ccd91b78561fb629333db0fd40114bc1f73c933a |
| parent 173287 | 709e9207641d12065f566ef1aa480a23a0e4f859 |
| child 182803 | ab1394be8e93f82c72576c7377de849e16290411 |
| permissions | -rw-r--r-- |
|
151399
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
1 |
// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- |
|
94475
f4157e8c410708d76703f19e4dfb61859bfe32d8
Bug 716478 - update licence to MPL 2.
Gervase Markham <gerv@gerv.net>
parents:
89885
diff
changeset
|
2 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
|
f4157e8c410708d76703f19e4dfb61859bfe32d8
Bug 716478 - update licence to MPL 2.
Gervase Markham <gerv@gerv.net>
parents:
89885
diff
changeset
|
3 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
|
f4157e8c410708d76703f19e4dfb61859bfe32d8
Bug 716478 - update licence to MPL 2.
Gervase Markham <gerv@gerv.net>
parents:
89885
diff
changeset
|
4 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
65192
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
5 |
|
|
151399
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
6 |
const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components; |
|
65192
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
7 |
|
| 172978 | 8 |
const APK_MIME_TYPE = "application/vnd.android.package-archive"; |
|
65192
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
9 |
const PREF_BD_USEDOWNLOADDIR = "browser.download.useDownloadDir"; |
|
94927
7d34bf17109677b5b2059505cc306a90c6408c3b
Bug 741430 - Use new icons for status alert notifications r=sriram
Mark Finkle <mfinkle@mozilla.com>
parents:
94475
diff
changeset
|
10 |
const URI_GENERIC_ICON_DOWNLOAD = "drawable://alert_download"; |
|
65192
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
11 |
|
| 172978 | 12 |
Cu.import("resource://gre/modules/FileUtils.jsm"); |
13 |
Cu.import("resource://gre/modules/HelperApps.jsm"); |
|
14 |
Cu.import("resource://gre/modules/Prompt.jsm"); |
|
|
66434
3065f2121b0929d858da19fb332a1bdac3c34b01
Fix Service/Services typo, r=mfinkle
Brian Crowder <crowderbt@gmail.com>
parents:
66362
diff
changeset
|
15 |
Cu.import("resource://gre/modules/Services.jsm"); |
| 172978 | 16 |
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
|
65192
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
17 |
|
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
18 |
// ----------------------------------------------------------------------- |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
19 |
// HelperApp Launcher Dialog |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
20 |
// ----------------------------------------------------------------------- |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
21 |
|
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
22 |
function HelperAppLauncherDialog() { } |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
23 |
|
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
24 |
HelperAppLauncherDialog.prototype = { |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
25 |
classID: Components.ID("{e9d277a0-268a-4ec2-bb8c-10fdf3e44611}"), |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
26 |
QueryInterface: XPCOMUtils.generateQI([Ci.nsIHelperAppLauncherDialog]), |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
27 |
|
| 172978 | 28 |
getNativeWindow: function () { |
29 |
try { |
|
30 |
let win = Services.wm.getMostRecentWindow("navigator:browser"); |
|
31 |
if (win && win.NativeWindow) { |
|
32 |
return win.NativeWindow; |
|
33 |
} |
|
34 |
} catch (e) { |
|
35 |
} |
|
36 |
return null; |
|
37 |
}, |
|
38 |
||
39 |
/** |
|
40 |
* Returns false if `url` represents a local or special URL that we don't |
|
41 |
* wish to ever download. |
|
42 |
* |
|
43 |
* Returns true otherwise. |
|
44 |
*/ |
|
45 |
_canDownload: function (url, alreadyResolved=false) { |
|
46 |
// The common case. |
|
47 |
if (url.schemeIs("http") || |
|
48 |
url.schemeIs("https") || |
|
49 |
url.schemeIs("ftp")) { |
|
50 |
return true; |
|
51 |
} |
|
52 |
||
53 |
// The less-common opposite case. |
|
54 |
if (url.schemeIs("chrome") || |
|
55 |
url.schemeIs("jar") || |
|
56 |
url.schemeIs("resource") || |
|
57 |
url.schemeIs("wyciwyg")) { |
|
58 |
return false; |
|
59 |
} |
|
60 |
||
61 |
// For all other URIs, try to resolve them to an inner URI, and check that. |
|
62 |
if (!alreadyResolved) { |
|
63 |
let ioSvc = Cc["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService); |
|
64 |
let innerURI = ioSvc.newChannelFromURI(url).URI; |
|
65 |
if (!url.equals(innerURI)) { |
|
66 |
return this._canDownload(innerURI, true); |
|
67 |
} |
|
68 |
} |
|
69 |
||
70 |
if (url.schemeIs("file")) { |
|
71 |
// If it's in our app directory or profile directory, we never ever |
|
72 |
// want to do anything with it, including saving to disk or passing the |
|
73 |
// file to another application. |
|
74 |
let file = url.QueryInterface(Ci.nsIFileURL).file; |
|
75 |
||
76 |
// TODO: pref blacklist? |
|
77 |
||
78 |
let appRoot = FileUtils.getFile("XREExeF", []); |
|
79 |
if (appRoot.contains(file, true)) { |
|
80 |
return false; |
|
81 |
} |
|
82 |
||
83 |
let profileRoot = FileUtils.getFile("ProfD", []); |
|
84 |
if (profileRoot.contains(file, true)) { |
|
85 |
return false; |
|
86 |
} |
|
87 |
||
88 |
return true; |
|
89 |
} |
|
90 |
||
91 |
// Anything else is fine to download. |
|
92 |
return true; |
|
93 |
}, |
|
94 |
||
95 |
/** |
|
96 |
* Returns true if `launcher` represents a download for which we wish |
|
97 |
* to prompt. |
|
98 |
*/ |
|
99 |
_shouldPrompt: function (launcher) { |
|
100 |
let mimeType = this._getMimeTypeFromLauncher(launcher); |
|
101 |
||
102 |
// Straight equality: nsIMIMEInfo normalizes. |
|
103 |
return APK_MIME_TYPE == mimeType; |
|
104 |
}, |
|
105 |
||
|
65192
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
106 |
show: function hald_show(aLauncher, aContext, aReason) { |
| 172978 | 107 |
if (!this._canDownload(aLauncher.source)) { |
108 |
aLauncher.cancel(Cr.NS_BINDING_ABORTED); |
|
109 |
||
110 |
let win = this.getNativeWindow(); |
|
111 |
if (!win) { |
|
112 |
// Oops. |
|
113 |
Services.console.logStringMessage("Refusing download, but can't show a toast."); |
|
114 |
return; |
|
115 |
} |
|
116 |
||
117 |
Services.console.logStringMessage("Refusing download of non-downloadable file."); |
|
118 |
let bundle = Services.strings.createBundle("chrome://browser/locale/handling.properties"); |
|
119 |
let failedText = bundle.GetStringFromName("protocol.failed"); |
|
120 |
win.toast.show(failedText, "long"); |
|
121 |
||
122 |
return; |
|
123 |
} |
|
124 |
||
|
151399
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
125 |
let bundle = Services.strings.createBundle("chrome://browser/locale/browser.properties"); |
|
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
126 |
|
|
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
127 |
let defaultHandler = new Object(); |
|
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
128 |
let apps = HelperApps.getAppsForUri(aLauncher.source, { |
|
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
129 |
mimeType: aLauncher.MIMEInfo.MIMEType, |
|
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
130 |
}); |
|
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
131 |
|
| 172978 | 132 |
// Add a fake intent for save to disk at the top of the list. |
|
151399
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
133 |
apps.unshift({ |
|
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
134 |
name: bundle.GetStringFromName("helperapps.saveToDisk"), |
|
151538
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
135 |
packageName: "org.mozilla.gecko.Download", |
|
151399
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
136 |
iconUri: "drawable://icon", |
|
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
137 |
launch: function() { |
| 172978 | 138 |
// Reset the preferredAction here. |
|
151399
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
139 |
aLauncher.MIMEInfo.preferredAction = Ci.nsIMIMEInfo.saveToDisk; |
|
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
140 |
aLauncher.saveToDisk(null, false); |
|
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
141 |
return true; |
|
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
142 |
} |
|
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
143 |
}); |
|
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
144 |
|
|
151538
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
145 |
// See if the user already marked something as the default for this mimetype, |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
146 |
// and if that app is still installed. |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
147 |
let preferredApp = this._getPreferredApp(aLauncher); |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
148 |
if (preferredApp) { |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
149 |
let pref = apps.filter(function(app) { |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
150 |
return app.packageName === preferredApp; |
|
151399
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
151 |
}); |
|
151538
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
152 |
|
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
153 |
if (pref.length > 0) { |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
154 |
pref[0].launch(aLauncher.source); |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
155 |
return; |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
156 |
} |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
157 |
} |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
158 |
|
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
159 |
let callback = function(app) { |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
160 |
aLauncher.MIMEInfo.preferredAction = Ci.nsIMIMEInfo.useHelperApp; |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
161 |
if (!app.launch(aLauncher.source)) { |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
162 |
aLauncher.cancel(Cr.NS_BINDING_ABORTED); |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
163 |
} |
|
151399
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
164 |
} |
|
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
165 |
|
| 172978 | 166 |
// If there's only one choice, and we don't want to prompt, go right ahead |
167 |
// and choose that app automatically. |
|
168 |
if (!this._shouldPrompt(aLauncher) && (apps.length === 1)) { |
|
169 |
callback(apps[0]); |
|
170 |
return; |
|
171 |
} |
|
|
151538
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
172 |
|
| 172978 | 173 |
// Otherwise, let's go through the prompt. |
174 |
HelperApps.prompt(apps, { |
|
175 |
title: bundle.GetStringFromName("helperapps.pick"), |
|
176 |
buttons: [ |
|
177 |
bundle.GetStringFromName("helperapps.alwaysUse"), |
|
178 |
bundle.GetStringFromName("helperapps.useJustOnce") |
|
179 |
] |
|
180 |
}, (data) => { |
|
181 |
if (data.button < 0) { |
|
182 |
return; |
|
183 |
} |
|
|
151538
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
184 |
|
| 172978 | 185 |
callback(apps[data.icongrid0]); |
186 |
||
187 |
if (data.button === 0) { |
|
188 |
this._setPreferredApp(aLauncher, apps[data.icongrid0]); |
|
189 |
} |
|
190 |
}); |
|
|
151538
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
191 |
}, |
|
151399
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
192 |
|
|
151538
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
193 |
_getPrefName: function getPrefName(mimetype) { |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
194 |
return "browser.download.preferred." + mimetype.replace("\\", "."); |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
195 |
}, |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
196 |
|
| 172978 | 197 |
_getMimeTypeFromLauncher: function (launcher) { |
|
151538
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
198 |
let mime = launcher.MIMEInfo.MIMEType; |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
199 |
if (!mime) |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
200 |
mime = ContentAreaUtils.getMIMETypeForURI(launcher.source) || ""; |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
201 |
return mime; |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
202 |
}, |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
203 |
|
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
204 |
_getPreferredApp: function getPreferredApp(launcher) { |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
205 |
let mime = this._getMimeTypeFromLauncher(launcher); |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
206 |
if (!mime) |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
207 |
return; |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
208 |
|
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
209 |
try { |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
210 |
return Services.prefs.getCharPref(this._getPrefName(mime)); |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
211 |
} catch(ex) { |
| 172978 | 212 |
Services.console.logStringMessage("Error getting pref for " + mime + "."); |
|
151538
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
213 |
} |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
214 |
return null; |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
215 |
}, |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
216 |
|
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
217 |
_setPreferredApp: function setPreferredApp(launcher, app) { |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
218 |
let mime = this._getMimeTypeFromLauncher(launcher); |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
219 |
if (!mime) |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
220 |
return; |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
221 |
|
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
222 |
if (app) |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
223 |
Services.prefs.setCharPref(this._getPrefName(mime), app.packageName); |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
224 |
else |
|
04f77c1e3337dcec793622c5b47b6f67fcc76c23
Bug 780379 - Add buttons to download prompts. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
151399
diff
changeset
|
225 |
Services.prefs.clearUserPref(this._getPrefName(mime)); |
|
65192
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
226 |
}, |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
227 |
|
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
228 |
promptForSaveToFile: function hald_promptForSaveToFile(aLauncher, aContext, aDefaultFile, aSuggestedFileExt, aForcePrompt) { |
|
149341
d71579c316c17b0ca7aa1130075dc9d70d3ff5b3
Backout 41701d2c0341 (bug 875731), Caused a regression that breaks all downloads in Firefox for Android (bug 921944)
Mark Finkle <mfinkle@mozilla.com>
parents:
149082
diff
changeset
|
229 |
// Retrieve the user's default download directory |
|
d71579c316c17b0ca7aa1130075dc9d70d3ff5b3
Backout 41701d2c0341 (bug 875731), Caused a regression that breaks all downloads in Firefox for Android (bug 921944)
Mark Finkle <mfinkle@mozilla.com>
parents:
149082
diff
changeset
|
230 |
let dnldMgr = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager); |
|
d71579c316c17b0ca7aa1130075dc9d70d3ff5b3
Backout 41701d2c0341 (bug 875731), Caused a regression that breaks all downloads in Firefox for Android (bug 921944)
Mark Finkle <mfinkle@mozilla.com>
parents:
149082
diff
changeset
|
231 |
let defaultFolder = dnldMgr.userDownloadsDirectory; |
|
65192
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
232 |
|
|
149341
d71579c316c17b0ca7aa1130075dc9d70d3ff5b3
Backout 41701d2c0341 (bug 875731), Caused a regression that breaks all downloads in Firefox for Android (bug 921944)
Mark Finkle <mfinkle@mozilla.com>
parents:
149082
diff
changeset
|
233 |
try { |
|
d71579c316c17b0ca7aa1130075dc9d70d3ff5b3
Backout 41701d2c0341 (bug 875731), Caused a regression that breaks all downloads in Firefox for Android (bug 921944)
Mark Finkle <mfinkle@mozilla.com>
parents:
149082
diff
changeset
|
234 |
file = this.validateLeafName(defaultFolder, aDefaultFile, aSuggestedFileExt); |
|
d71579c316c17b0ca7aa1130075dc9d70d3ff5b3
Backout 41701d2c0341 (bug 875731), Caused a regression that breaks all downloads in Firefox for Android (bug 921944)
Mark Finkle <mfinkle@mozilla.com>
parents:
149082
diff
changeset
|
235 |
} catch (e) { } |
|
65192
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
236 |
|
|
149341
d71579c316c17b0ca7aa1130075dc9d70d3ff5b3
Backout 41701d2c0341 (bug 875731), Caused a regression that breaks all downloads in Firefox for Android (bug 921944)
Mark Finkle <mfinkle@mozilla.com>
parents:
149082
diff
changeset
|
237 |
return file; |
|
65192
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
238 |
}, |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
239 |
|
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
240 |
validateLeafName: function hald_validateLeafName(aLocalFile, aLeafName, aFileExt) { |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
241 |
if (!(aLocalFile && this.isUsableDirectory(aLocalFile))) |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
242 |
return null; |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
243 |
|
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
244 |
// Remove any leading periods, since we don't want to save hidden files |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
245 |
// automatically. |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
246 |
aLeafName = aLeafName.replace(/^\.+/, ""); |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
247 |
|
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
248 |
if (aLeafName == "") |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
249 |
aLeafName = "unnamed" + (aFileExt ? "." + aFileExt : ""); |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
250 |
aLocalFile.append(aLeafName); |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
251 |
|
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
252 |
this.makeFileUnique(aLocalFile); |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
253 |
return aLocalFile; |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
254 |
}, |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
255 |
|
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
256 |
makeFileUnique: function hald_makeFileUnique(aLocalFile) { |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
257 |
try { |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
258 |
// Note - this code is identical to that in |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
259 |
// toolkit/content/contentAreaUtils.js. |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
260 |
// If you are updating this code, update that code too! We can't share code |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
261 |
// here since this is called in a js component. |
|
151399
0cc4a019835f096a5df82d9070db9b96addc75d6
Bug 780379 - Show a custom intent chooser for downloads that can be downloaded by an external app. r=mfinkle
Wes Johnston <wjohnston@mozilla.com>
parents:
149341
diff
changeset
|
262 |
let collisionCount = 0; |
|
65192
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
263 |
while (aLocalFile.exists()) { |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
264 |
collisionCount++; |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
265 |
if (collisionCount == 1) { |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
266 |
// Append "(2)" before the last dot in (or at the end of) the filename |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
267 |
// special case .ext.gz etc files so we don't wind up with .tar(2).gz |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
268 |
if (aLocalFile.leafName.match(/\.[^\.]{1,3}\.(gz|bz2|Z)$/i)) |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
269 |
aLocalFile.leafName = aLocalFile.leafName.replace(/\.[^\.]{1,3}\.(gz|bz2|Z)$/i, "(2)$&"); |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
270 |
else |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
271 |
aLocalFile.leafName = aLocalFile.leafName.replace(/(\.[^\.]*)?$/, "(2)$&"); |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
272 |
} |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
273 |
else { |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
274 |
// replace the last (n) in the filename with (n+1) |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
275 |
aLocalFile.leafName = aLocalFile.leafName.replace(/^(.*\()\d+\)/, "$1" + (collisionCount+1) + ")"); |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
276 |
} |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
277 |
} |
|
66543
28e5592fb1902a699faa99d4c60bae5735a66921
Bug 592902 - Provide a way to cleanup or stop accidental downloads [r=mfinkle]
Wesley Johnston <wjohnston@mozilla.com>
parents:
66522
diff
changeset
|
278 |
aLocalFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0600); |
|
65192
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
279 |
} |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
280 |
catch (e) { |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
281 |
dump("*** exception in validateLeafName: " + e + "\n"); |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
282 |
|
|
66543
28e5592fb1902a699faa99d4c60bae5735a66921
Bug 592902 - Provide a way to cleanup or stop accidental downloads [r=mfinkle]
Wesley Johnston <wjohnston@mozilla.com>
parents:
66522
diff
changeset
|
283 |
if (e.result == Cr.NS_ERROR_FILE_ACCESS_DENIED) |
|
65192
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
284 |
throw e; |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
285 |
|
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
286 |
if (aLocalFile.leafName == "" || aLocalFile.isDirectory()) { |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
287 |
aLocalFile.append("unnamed"); |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
288 |
if (aLocalFile.exists()) |
|
66543
28e5592fb1902a699faa99d4c60bae5735a66921
Bug 592902 - Provide a way to cleanup or stop accidental downloads [r=mfinkle]
Wesley Johnston <wjohnston@mozilla.com>
parents:
66522
diff
changeset
|
289 |
aLocalFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0600); |
|
65192
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
290 |
} |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
291 |
} |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
292 |
}, |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
293 |
|
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
294 |
isUsableDirectory: function hald_isUsableDirectory(aDirectory) { |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
295 |
return aDirectory.exists() && aDirectory.isDirectory() && aDirectory.isWritable(); |
|
66560
6b9420db098c03f2a7f870a33b0943079466ac77
Bug 594504 - Show a message to explain why downloads with no helper apps were cancelled [r=mfinkle]
Wesley Johnston <wjohnston@mozilla.com>
parents:
66543
diff
changeset
|
296 |
}, |
|
65192
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
297 |
}; |
|
455077dd5abf4a6db66d724648714707e10a53be
Bug 479808: Save As dialog is oversized and ugly, r=blassey
Mark Finkle <mfinkle@mozilla.com>
parents:
diff
changeset
|
298 |
|
|
111947
5ce71981e005a52d4cb0b831ad3db9284f2fb356
Bug 798491: Add an option to stick all chrome JSMs/JS components in the same compartment. r=mrbkap,philikon
Kyle Huey <khuey@kylehuey.com>
parents:
111876
diff
changeset
|
299 |
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([HelperAppLauncherDialog]); |