Bug 945323 - [Download API] Downloaded path isn't honoring download attribute. r=bz

This commit is contained in:
Ghislain 'Aus' Lacroix 2014-02-13 14:43:58 -08:00
Родитель 5c731adbd8
Коммит 1fa90496e3
9 изменённых файлов: 57 добавлений и 15 удалений

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

@ -26,7 +26,6 @@ SimpleTest.waitForExplicitFinish();
var index = -1;
var todayDate = new Date();
var baseServeURL = "http://mochi.test:8888/tests/dom/downloads/tests/";
var baseDownloadPath = "/mnt/sdcard/downloads/";
var lastKnownCurrentBytes = 0;
function next() {
@ -45,11 +44,12 @@ function next() {
function checkConsistentDownloadAttributes(download) {
var href = document.getElementById("download1").getAttribute("href");
var expectedServeURL = baseServeURL + href;
var expectedDownloadPath = baseDownloadPath + "test.bin";
var destinationRegEx = /test\(?[0-9]*\)?\.bin$/;
// bug 945323: Download path isn't honoring download attribute
todo(download.path === expectedDownloadPath,
"Download path = " + expectedDownloadPath);
ok(destinationRegEx.test(download.path),
"Download path '" + download.path +
"' should match '" + destinationRegEx + "' regexp.");
ok(download.startTime >= todayDate,
"Download start time should be greater than or equal to today");

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

@ -959,6 +959,8 @@ PExternalHelperAppChild*
ContentChild::AllocPExternalHelperAppChild(const OptionalURIParams& uri,
const nsCString& aMimeContentType,
const nsCString& aContentDisposition,
const uint32_t& aContentDispositionHint,
const nsString& aContentDispositionFilename,
const bool& aForceSave,
const int64_t& aContentLength,
const OptionalURIParams& aReferrer,

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

@ -144,6 +144,8 @@ public:
const OptionalURIParams& uri,
const nsCString& aMimeContentType,
const nsCString& aContentDisposition,
const uint32_t& aContentDispositionHint,
const nsString& aContentDispositionFilename,
const bool& aForceSave,
const int64_t& aContentLength,
const OptionalURIParams& aReferrer,

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

@ -2393,6 +2393,8 @@ PExternalHelperAppParent*
ContentParent::AllocPExternalHelperAppParent(const OptionalURIParams& uri,
const nsCString& aMimeContentType,
const nsCString& aContentDisposition,
const uint32_t& aContentDispositionHint,
const nsString& aContentDispositionFilename,
const bool& aForceSave,
const int64_t& aContentLength,
const OptionalURIParams& aReferrer,
@ -2400,7 +2402,14 @@ ContentParent::AllocPExternalHelperAppParent(const OptionalURIParams& uri,
{
ExternalHelperAppParent *parent = new ExternalHelperAppParent(uri, aContentLength);
parent->AddRef();
parent->Init(this, aMimeContentType, aContentDisposition, aForceSave, aReferrer, aBrowser);
parent->Init(this,
aMimeContentType,
aContentDisposition,
aContentDispositionHint,
aContentDispositionFilename,
aForceSave,
aReferrer,
aBrowser);
return parent;
}

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

@ -367,6 +367,8 @@ private:
const OptionalURIParams& aUri,
const nsCString& aMimeContentType,
const nsCString& aContentDisposition,
const uint32_t& aContentDispositionHint,
const nsString& aContentDispositionFilename,
const bool& aForceSave,
const int64_t& aContentLength,
const OptionalURIParams& aReferrer,

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

@ -422,9 +422,14 @@ parent:
CloseAlert(nsString name, Principal principal);
PExternalHelperApp(OptionalURIParams uri, nsCString aMimeContentType,
nsCString aContentDisposition, bool aForceSave,
int64_t aContentLength, OptionalURIParams aReferrer,
PExternalHelperApp(OptionalURIParams uri,
nsCString aMimeContentType,
nsCString aContentDisposition,
uint32_t aContentDispositionHint,
nsString aContentDispositionFilename,
bool aForceSave,
int64_t aContentLength,
OptionalURIParams aReferrer,
nullable PBrowser aBrowser);
AddGeolocationListener(Principal principal, bool highAccuracy);

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

@ -48,6 +48,8 @@ void
ExternalHelperAppParent::Init(ContentParent *parent,
const nsCString& aMimeContentType,
const nsCString& aContentDispositionHeader,
const uint32_t& aContentDispositionHint,
const nsString& aContentDispositionFilename,
const bool& aForceSave,
const OptionalURIParams& aReferrer,
PBrowserParent* aBrowser)
@ -61,8 +63,17 @@ ExternalHelperAppParent::Init(ContentParent *parent,
SetPropertyAsInterface(NS_LITERAL_STRING("docshell.internalReferrer"), referrer);
mContentDispositionHeader = aContentDispositionHeader;
NS_GetFilenameFromDisposition(mContentDispositionFilename, mContentDispositionHeader, mURI);
mContentDisposition = NS_GetContentDispositionFromHeader(mContentDispositionHeader, this);
if (!mContentDispositionHeader.IsEmpty()) {
NS_GetFilenameFromDisposition(mContentDispositionFilename,
mContentDispositionHeader,
mURI);
mContentDisposition =
NS_GetContentDispositionFromHeader(mContentDispositionHeader, this);
}
else {
mContentDisposition = aContentDispositionHint;
mContentDispositionFilename = aContentDispositionFilename;
}
nsCOMPtr<nsIInterfaceRequestor> window;
if (aBrowser) {
@ -301,7 +312,8 @@ ExternalHelperAppParent::GetContentDisposition(uint32_t *aContentDisposition)
NS_IMETHODIMP
ExternalHelperAppParent::SetContentDisposition(uint32_t aContentDisposition)
{
return NS_ERROR_NOT_AVAILABLE;
mContentDisposition = aContentDisposition;
return NS_OK;
}
NS_IMETHODIMP
@ -317,7 +329,8 @@ ExternalHelperAppParent::GetContentDispositionFilename(nsAString& aContentDispos
NS_IMETHODIMP
ExternalHelperAppParent::SetContentDispositionFilename(const nsAString& aContentDispositionFilename)
{
return NS_ERROR_NOT_AVAILABLE;
mContentDispositionFilename = aContentDispositionFilename;
return NS_OK;
}
NS_IMETHODIMP

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

@ -50,6 +50,8 @@ public:
void Init(ContentParent *parent,
const nsCString& aMimeContentType,
const nsCString& aContentDisposition,
const uint32_t& aContentDispositionHint,
const nsString& aContentDispositionFilename,
const bool& aForceSave,
const OptionalURIParams& aReferrer,
PBrowserParent* aBrowser);

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

@ -670,6 +670,8 @@ NS_IMETHODIMP nsExternalHelperAppService::DoContent(const nsACString& aMimeConte
nsAutoString fileName;
nsAutoCString fileExtension;
uint32_t reason = nsIHelperAppLauncherDialog::REASON_CANTHANDLE;
uint32_t contentDisposition = -1;
nsresult rv;
// Get the file extension and name that we will need later
@ -679,7 +681,10 @@ NS_IMETHODIMP nsExternalHelperAppService::DoContent(const nsACString& aMimeConte
if (channel) {
channel->GetURI(getter_AddRefs(uri));
channel->GetContentLength(&contentLength);
channel->GetContentDisposition(&contentDisposition);
channel->GetContentDispositionFilename(fileName);
}
if (XRE_GetProcessType() == GeckoProcessType_Content) {
nsCOMPtr<nsIDOMWindow> window = do_GetInterface(aWindowContext);
NS_ENSURE_STATE(window);
@ -696,8 +701,9 @@ NS_IMETHODIMP nsExternalHelperAppService::DoContent(const nsACString& aMimeConte
return NS_ERROR_FAILURE;
nsCString disp;
if (channel)
if (channel) {
channel->GetContentDispositionHeader(disp);
}
nsCOMPtr<nsIURI> referrer;
rv = NS_GetReferrerFromChannel(channel, getter_AddRefs(referrer));
@ -713,8 +719,9 @@ NS_IMETHODIMP nsExternalHelperAppService::DoContent(const nsACString& aMimeConte
mozilla::dom::PExternalHelperAppChild *pc =
child->SendPExternalHelperAppConstructor(uriParams,
nsCString(aMimeContentType),
disp, aForceSave, contentLength,
referrerParams,
disp, contentDisposition,
fileName, aForceSave,
contentLength, referrerParams,
mozilla::dom::TabChild::GetFrom(window));
ExternalHelperAppChild *childListener = static_cast<ExternalHelperAppChild *>(pc);