зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1503070 part 2. Remove download() method from BrowserElement. r=ehsan
This commit is contained in:
Родитель
2d6e9368a0
Коммит
8a0b60f33c
|
@ -7,7 +7,6 @@ const METHODS = {
|
|||
goForward: {},
|
||||
reload: {},
|
||||
stop: {},
|
||||
download: {},
|
||||
purgeHistory: {},
|
||||
getScreenshot: {},
|
||||
zoom: {},
|
||||
|
|
|
@ -635,140 +635,6 @@ BrowserElementParent.prototype = {
|
|||
purgeHistory: defineDOMRequestMethod('purge-history'),
|
||||
|
||||
|
||||
download: function(_url, _options) {
|
||||
if (!this._isAlive()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let uri = Services.io.newURI(_url);
|
||||
let url = uri.QueryInterface(Ci.nsIURL);
|
||||
|
||||
debug('original _options = ' + uneval(_options));
|
||||
|
||||
// Ensure we have _options, we always use it to send the filename.
|
||||
_options = _options || {};
|
||||
if (!_options.filename) {
|
||||
_options.filename = url.fileName;
|
||||
}
|
||||
|
||||
debug('final _options = ' + uneval(_options));
|
||||
|
||||
// Ensure we have a filename.
|
||||
if (!_options.filename) {
|
||||
throw Components.Exception("Invalid argument", Cr.NS_ERROR_INVALID_ARG);
|
||||
}
|
||||
|
||||
let interfaceRequestor =
|
||||
this._frameLoader.loadContext.QueryInterface(Ci.nsIInterfaceRequestor);
|
||||
let req = Services.DOMRequest.createRequest(this._window);
|
||||
|
||||
function DownloadListener() {
|
||||
debug('DownloadListener Constructor');
|
||||
}
|
||||
DownloadListener.prototype = {
|
||||
extListener: null,
|
||||
onStartRequest: function(aRequest, aContext) {
|
||||
debug('DownloadListener - onStartRequest');
|
||||
let extHelperAppSvc =
|
||||
Cc['@mozilla.org/uriloader/external-helper-app-service;1'].
|
||||
getService(Ci.nsIExternalHelperAppService);
|
||||
let channel = aRequest.QueryInterface(Ci.nsIChannel);
|
||||
|
||||
// First, we'll ensure the filename doesn't have any leading
|
||||
// periods. We have to do it here to avoid ending up with a filename
|
||||
// that's only an extension with no extension (e.g. Sending in
|
||||
// '.jpeg' without stripping the '.' would result in a filename of
|
||||
// 'jpeg' where we want 'jpeg.jpeg'.
|
||||
_options.filename = _options.filename.replace(/^\.+/, "");
|
||||
|
||||
let ext = null;
|
||||
let mimeSvc = extHelperAppSvc.QueryInterface(Ci.nsIMIMEService);
|
||||
try {
|
||||
ext = '.' + mimeSvc.getPrimaryExtension(channel.contentType, '');
|
||||
} catch (e) { ext = null; }
|
||||
|
||||
// Check if we need to add an extension to the filename.
|
||||
if (ext && !_options.filename.endsWith(ext)) {
|
||||
_options.filename += ext;
|
||||
}
|
||||
// Set the filename to use when saving to disk.
|
||||
channel.contentDispositionFilename = _options.filename;
|
||||
|
||||
this.extListener =
|
||||
extHelperAppSvc.doContent(
|
||||
channel.contentType,
|
||||
aRequest,
|
||||
interfaceRequestor,
|
||||
true);
|
||||
this.extListener.onStartRequest(aRequest, aContext);
|
||||
},
|
||||
onStopRequest: function(aRequest, aContext, aStatusCode) {
|
||||
debug('DownloadListener - onStopRequest (aStatusCode = ' +
|
||||
aStatusCode + ')');
|
||||
if (aStatusCode == Cr.NS_OK) {
|
||||
// Everything looks great.
|
||||
debug('DownloadListener - Download Successful.');
|
||||
Services.DOMRequest.fireSuccess(req, aStatusCode);
|
||||
}
|
||||
else {
|
||||
// In case of failure, we'll simply return the failure status code.
|
||||
debug('DownloadListener - Download Failed!');
|
||||
Services.DOMRequest.fireError(req, aStatusCode);
|
||||
}
|
||||
|
||||
if (this.extListener) {
|
||||
this.extListener.onStopRequest(aRequest, aContext, aStatusCode);
|
||||
}
|
||||
},
|
||||
onDataAvailable: function(aRequest, aContext, aInputStream,
|
||||
aOffset, aCount) {
|
||||
this.extListener.onDataAvailable(aRequest, aContext, aInputStream,
|
||||
aOffset, aCount);
|
||||
},
|
||||
QueryInterface: ChromeUtils.generateQI([Ci.nsIStreamListener,
|
||||
Ci.nsIRequestObserver])
|
||||
};
|
||||
|
||||
let referrer = Services.io.newURI(_options.referrer);
|
||||
let principal =
|
||||
Services.scriptSecurityManager.createCodebasePrincipal(
|
||||
referrer, this._frameLoader.loadContext.originAttributes);
|
||||
|
||||
let channel = NetUtil.newChannel({
|
||||
uri: url,
|
||||
loadingPrincipal: principal,
|
||||
securityFlags: SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS,
|
||||
contentPolicyType: Ci.nsIContentPolicy.TYPE_OTHER
|
||||
});
|
||||
|
||||
// XXX We would set private browsing information prior to calling this.
|
||||
channel.notificationCallbacks = interfaceRequestor;
|
||||
|
||||
// Since we're downloading our own local copy we'll want to bypass the
|
||||
// cache and local cache if the channel let's us specify this.
|
||||
let flags = Ci.nsIChannel.LOAD_CALL_CONTENT_SNIFFERS |
|
||||
Ci.nsIChannel.LOAD_BYPASS_CACHE;
|
||||
if (channel instanceof Ci.nsICachingChannel) {
|
||||
debug('This is a caching channel. Forcing bypass.');
|
||||
flags |= Ci.nsICachingChannel.LOAD_BYPASS_LOCAL_CACHE_IF_BUSY;
|
||||
}
|
||||
|
||||
channel.loadFlags |= flags;
|
||||
|
||||
if (channel instanceof Ci.nsIHttpChannel) {
|
||||
debug('Setting HTTP referrer = ' + (referrer && referrer.spec));
|
||||
channel.referrer = referrer;
|
||||
if (channel instanceof Ci.nsIHttpChannelInternal) {
|
||||
channel.forceAllowThirdPartyCookie = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Set-up complete, let's get things started.
|
||||
channel.asyncOpen2(new DownloadListener());
|
||||
|
||||
return req;
|
||||
},
|
||||
|
||||
getScreenshot: function(_width, _height, _mimeType) {
|
||||
if (!this._isAlive()) {
|
||||
throw Components.Exception("Dead content process",
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
/* Any copyright is dedicated to the public domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
// Bug 983747 - Test 'download' method on iframe.
|
||||
|
||||
"use strict";
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
browserElementTestHelpers.setEnabledPref(true);
|
||||
browserElementTestHelpers.addPermission();
|
||||
|
||||
var iframe;
|
||||
var downloadURL = 'http://test/tests/dom/browser-element/mochitest/file_download_bin.sjs';
|
||||
|
||||
function runTest() {
|
||||
iframe = document.createElement('iframe');
|
||||
iframe.setAttribute('mozbrowser', 'true');
|
||||
|
||||
iframe.addEventListener('mozbrowserloadend', loadend);
|
||||
iframe.src = 'data:text/html,<html><body>hello</body></html>';
|
||||
iframe.setAttribute('remote', 'true');
|
||||
|
||||
document.body.appendChild(iframe);
|
||||
}
|
||||
|
||||
function loadend() {
|
||||
var req = iframe.download(downloadURL, { filename: 'test.bin' });
|
||||
req.onsuccess = function() {
|
||||
ok(true, 'Download finished as expected.');
|
||||
SimpleTest.finish();
|
||||
}
|
||||
req.onerror = function() {
|
||||
ok(false, 'Expected no error, got ' + req.error);
|
||||
}
|
||||
}
|
||||
|
||||
addEventListener('testready', runTest);
|
|
@ -1,4 +0,0 @@
|
|||
function handleRequest(request, response) {
|
||||
response.setHeader("Content-Type", "application/octet-stream", false);
|
||||
response.write("BIN");
|
||||
}
|
|
@ -32,8 +32,6 @@ disabled = Disabling some OOP tests for WebIDL scope changes (bug 1310706 for re
|
|||
[test_browserElement_oop_DataURI.html]
|
||||
[test_browserElement_oop_DocumentFirstPaint.html]
|
||||
disabled = Disabling some OOP tests for WebIDL scope changes (bug 1310706 for re-enabling)
|
||||
[test_browserElement_oop_Download.html]
|
||||
disabled = bug 1022281
|
||||
[test_browserElement_oop_ErrorSecurity.html]
|
||||
[test_browserElement_oop_ExecuteScript.html]
|
||||
disabled = Disabling some OOP tests for WebIDL scope changes (bug 1310706 for re-enabling)
|
||||
|
|
|
@ -20,7 +20,6 @@ support-files =
|
|||
browserElement_DataURI.js
|
||||
browserElement_DataURILoad.html
|
||||
browserElement_DataURILoad.js
|
||||
browserElement_Download.js
|
||||
browserElement_ErrorSecurity.js
|
||||
browserElement_ExposableURI.js
|
||||
browserElement_FirstPaint.js
|
||||
|
@ -82,7 +81,6 @@ support-files =
|
|||
file_browserElement_XFrameOptionsDeny.html
|
||||
file_browserElement_XFrameOptionsSameOrigin.html
|
||||
file_bug741717.sjs
|
||||
file_download_bin.sjs
|
||||
file_empty.html
|
||||
file_empty_script.js
|
||||
file_focus.html
|
||||
|
@ -115,8 +113,6 @@ support-files =
|
|||
subsuite = clipboard
|
||||
skip-if = (os == "android") # Disabled on Android, see bug 1230421
|
||||
[test_browserElement_inproc_DataURI.html]
|
||||
[test_browserElement_inproc_Download.html]
|
||||
disabled = bug 1022281
|
||||
[test_browserElement_inproc_ExposableURI.html]
|
||||
[test_browserElement_inproc_FirstPaint.html]
|
||||
[test_browserElement_inproc_ForwardName.html]
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test for Bug 983747</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript" src="browserElementTestHelpers.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<script type="application/javascript" src="browserElement_Download.js">
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,13 +0,0 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test for Bug 983747</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript" src="browserElementTestHelpers.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<script type="application/javascript" src="browserElement_Download.js">
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -56,8 +56,6 @@ interface nsIBrowserElementAPI : nsISupports
|
|||
void goForward();
|
||||
void reload(in boolean hardReload);
|
||||
void stop();
|
||||
DOMRequest download(in AString url,
|
||||
[optional] in jsval options);
|
||||
DOMRequest purgeHistory();
|
||||
DOMRequest getScreenshot(in uint32_t width,
|
||||
in uint32_t height,
|
||||
|
|
|
@ -176,39 +176,6 @@ nsBrowserElement::Stop(ErrorResult& aRv)
|
|||
}
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
nsBrowserElement::Download(const nsAString& aUrl,
|
||||
const BrowserElementDownloadOptions& aOptions,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
NS_ENSURE_TRUE(IsBrowserElementOrThrow(aRv), nullptr);
|
||||
|
||||
RefPtr<DOMRequest> req;
|
||||
nsCOMPtr<nsIXPConnectWrappedJS> wrappedObj = do_QueryInterface(mBrowserElementAPI);
|
||||
MOZ_ASSERT(wrappedObj, "Failed to get wrapped JS from XPCOM component.");
|
||||
MOZ_RELEASE_ASSERT(!js::IsWrapper(wrappedObj->GetJSObject()));
|
||||
AutoJSAPI jsapi;
|
||||
if (!jsapi.Init(wrappedObj->GetJSObject())) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
return nullptr;
|
||||
}
|
||||
JSContext* cx = jsapi.cx();
|
||||
JS::Rooted<JS::Value> options(cx);
|
||||
aRv.MightThrowJSException();
|
||||
if (!ToJSValue(cx, aOptions, &options)) {
|
||||
aRv.StealExceptionFromJSContext(cx);
|
||||
return nullptr;
|
||||
}
|
||||
nsresult rv = mBrowserElementAPI->Download(aUrl, options, getter_AddRefs(req));
|
||||
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return req.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
nsBrowserElement::PurgeHistory(ErrorResult& aRv)
|
||||
{
|
||||
|
|
|
@ -17,7 +17,6 @@ class nsFrameLoader;
|
|||
namespace mozilla {
|
||||
|
||||
namespace dom {
|
||||
struct BrowserElementDownloadOptions;
|
||||
struct BrowserElementExecuteScriptOptions;
|
||||
class DOMRequest;
|
||||
enum class BrowserFindCaseSensitivity: uint8_t;
|
||||
|
@ -58,11 +57,6 @@ public:
|
|||
void Reload(bool aHardReload, ErrorResult& aRv);
|
||||
void Stop(ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<dom::DOMRequest>
|
||||
Download(const nsAString& aUrl,
|
||||
const dom::BrowserElementDownloadOptions& options,
|
||||
ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<dom::DOMRequest> PurgeHistory(ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<dom::DOMRequest>
|
||||
|
|
|
@ -7,11 +7,6 @@
|
|||
enum BrowserFindCaseSensitivity { "case-sensitive", "case-insensitive" };
|
||||
enum BrowserFindDirection { "forward", "backward" };
|
||||
|
||||
dictionary BrowserElementDownloadOptions {
|
||||
DOMString? filename;
|
||||
DOMString? referrer;
|
||||
};
|
||||
|
||||
dictionary BrowserElementExecuteScriptOptions {
|
||||
DOMString? url;
|
||||
DOMString? origin;
|
||||
|
@ -70,12 +65,6 @@ interface BrowserElementPrivileged {
|
|||
ChromeOnly]
|
||||
void stop();
|
||||
|
||||
[Throws,
|
||||
Pref="dom.mozBrowserFramesEnabled",
|
||||
ChromeOnly]
|
||||
DOMRequest download(DOMString url,
|
||||
optional BrowserElementDownloadOptions options);
|
||||
|
||||
[Throws,
|
||||
Pref="dom.mozBrowserFramesEnabled",
|
||||
ChromeOnly]
|
||||
|
|
Загрузка…
Ссылка в новой задаче