Backed out changeset be11a3290029 (bug 1469916) for test orange involving `Not enough arguments [nsIWebBrowserPersist.saveURI]`

This commit is contained in:
Gijs Kruitbosch 2018-07-03 15:45:13 +01:00
Родитель 7c2962923a
Коммит 9396488809
25 изменённых файлов: 56 добавлений и 280 удалений

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

@ -995,22 +995,12 @@ nsContextMenu.prototype = {
target: this.target,
});
// Cache this because we fetch the data async
let {documentURIObject} = gContextMenuContentData;
let onMessage = (message) => {
mm.removeMessageListener("ContextMenu:SaveVideoFrameAsImage:Result", onMessage);
// FIXME can we switch this to a blob URL?
let dataURL = message.data.dataURL;
saveImageURL(dataURL, name, "SaveImageTitle",
true, // bypass cache
false, // don't skip prompt for where to save
documentURIObject, // referrer
null, // document
null, // content type
null, // content disposition
isPrivate,
this.principal);
saveImageURL(dataURL, name, "SaveImageTitle", true, false,
document.documentURIObject, null, null, null,
isPrivate);
};
mm.addMessageListener("ContextMenu:SaveVideoFrameAsImage:Result", onMessage);
},
@ -1248,15 +1238,13 @@ nsContextMenu.prototype = {
this._canvasToBlobURL(this.target).then(function(blobURL) {
saveImageURL(blobURL, "canvas.png", "SaveImageTitle",
true, false, referrerURI, null, null, null,
isPrivate,
document.nodePrincipal /* system, because blob: */);
isPrivate);
}, Cu.reportError);
} else if (this.onImage) {
urlSecurityCheck(this.mediaURL, this.principal);
saveImageURL(this.mediaURL, null, "SaveImageTitle", false,
false, referrerURI, null, gContextMenuContentData.contentType,
gContextMenuContentData.contentDisposition, isPrivate,
this.principal);
gContextMenuContentData.contentDisposition, isPrivate);
} else if (this.onVideo || this.onAudio) {
var dialogTitle = this.onVideo ? "SaveVideoTitle" : "SaveAudioTitle";
this.saveHelper(this.mediaURL, null, dialogTitle, false, doc, referrerURI,

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

@ -689,8 +689,7 @@ function saveMedia() {
var saveAnImage = function(aURIString, aChosenData, aBaseURI) {
uniqueFile(aChosenData.file);
internalSave(aURIString, null, null, null, null, false, "SaveImageTitle",
aChosenData, aBaseURI, null, false, null,
gDocInfo.isContentWindowPrivate, gDocInfo.principal);
aChosenData, aBaseURI, null, false, null, gDocInfo.isContentWindowPrivate);
};
for (var i = 0; i < rowArray.length; i++) {

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

@ -305,8 +305,7 @@ function openLinkIn(url, where, params) {
// ContentClick.jsm passes isContentWindowPrivate for saveURL instead of passing a CPOW initiatingDoc
if ("isContentWindowPrivate" in params) {
saveURL(url, null, null, true, true, aNoReferrer ? null : aReferrerURI,
null, params.isContentWindowPrivate, aPrincipal);
saveURL(url, null, null, true, true, aNoReferrer ? null : aReferrerURI, null, params.isContentWindowPrivate);
} else {
if (!aInitiatingDoc) {
Cu.reportError("openUILink/openLinkIn was called with " +

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

@ -153,7 +153,7 @@ nsMacShellService::SetDesktopBackground(Element* aElement,
loadContext = do_QueryInterface(docShell);
}
return wbp->SaveURI(imageURI, aElement->NodePrincipal(), 0,
return wbp->SaveURI(imageURI, 0,
docURI, aElement->OwnerDoc()->GetReferrerPolicy(),
nullptr, nullptr,
mBackgroundFile, loadContext);

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

@ -554,6 +554,7 @@ var saveToFile = Task.async(function* (context, reply) {
// the downloads toolbar button when the save is done.
const nsIWBP = Ci.nsIWebBrowserPersist;
const flags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
nsIWBP.PERSIST_FLAGS_FORCE_ALLOW_COOKIES |
nsIWBP.PERSIST_FLAGS_BYPASS_CACHE |
nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
const isPrivate =
@ -572,9 +573,7 @@ var saveToFile = Task.async(function* (context, reply) {
isPrivate);
const listener = new DownloadListener(window, tr);
persist.progressListener = listener;
const principal = Services.scriptSecurityManager.getSystemPrincipal();
persist.savePrivacyAwareURI(sourceURI,
principal,
0,
document.documentURIObject,
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,

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

@ -141,7 +141,6 @@ NS_IMPL_ISUPPORTS(nsContentAreaDragDropDataProvider, nsIFlavorDataProvider)
// into the file system
nsresult
nsContentAreaDragDropDataProvider::SaveURIToFile(nsIURI* inSourceURI,
nsIPrincipal* inTriggeringPrincipal,
nsIFile* inDestFile,
bool isPrivate)
{
@ -163,8 +162,7 @@ nsContentAreaDragDropDataProvider::SaveURIToFile(nsIURI* inSourceURI,
persist->SetPersistFlags(nsIWebBrowserPersist::PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION);
// referrer policy can be anything since the referrer is nullptr
return persist->SavePrivacyAwareURI(inSourceURI,
inTriggeringPrincipal, 0, nullptr,
return persist->SavePrivacyAwareURI(inSourceURI, 0, nullptr,
mozilla::net::RP_Unset,
nullptr, nullptr,
inDestFile, isPrivate);
@ -344,9 +342,7 @@ nsContentAreaDragDropDataProvider::GetFlavorData(nsITransferable *aTransferable,
bool isPrivate;
aTransferable->GetIsPrivateData(&isPrivate);
nsCOMPtr<nsIPrincipal> principal;
aTransferable->GetRequestingPrincipal(getter_AddRefs(principal));
rv = SaveURIToFile(sourceURI, principal, file, isPrivate);
rv = SaveURIToFile(sourceURI, file, isPrivate);
// send back an nsIFile
if (NS_SUCCEEDED(rv)) {
CallQueryInterface(file, aData);

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

@ -77,7 +77,6 @@ public:
NS_DECL_NSIFLAVORDATAPROVIDER
nsresult SaveURIToFile(nsIURI* inSourceURI,
nsIPrincipal* inTriggeringPrincipal,
nsIFile* inDestFile, bool isPrivate);
};

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

@ -57,10 +57,6 @@ skip-if = !e10s || (os == "win" && processor == "x86") || (verify && debug && (o
[browser_localStorage_e10s.js]
skip-if = !e10s || verify # This is a test of e10s functionality.
[browser_localStorage_privatestorageevent.js]
[browser_persist_cookies.js]
support-files =
set-samesite-cookies-and-redirect.sjs
mimeme.sjs
[browser_test_focus_after_modal_state.js]
skip-if = verify
support-files =

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

@ -1,83 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const TEST_PATH = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "https://example.org");
const TEST_PATH2 = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "https://example.com");
var MockFilePicker = SpecialPowers.MockFilePicker;
MockFilePicker.init(window);
registerCleanupFunction(function() {
info("Running the cleanup code");
MockFilePicker.cleanup();
Services.obs.removeObserver(checkRequest, "http-on-modify-request");
if (gTestDir) {
gTestDir.remove(true);
}
});
let gTestDir;
function checkRequest(subject) {
let httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
let spec = httpChannel.URI.spec;
// Ignore initial requests for page that sets cookies and its favicon, which may not have
// cookies.
if (httpChannel.URI.host == "example.org" && !spec.endsWith("favicon.ico") && !spec.includes("redirect.sjs")) {
let cookie = httpChannel.getRequestHeader("cookie");
is(cookie.trim(), "normalCookie=true", "Should have correct cookie in request for " + spec);
}
}
function createTemporarySaveDirectory() {
var saveDir = Services.dirsvc.get("TmpD", Ci.nsIFile);
saveDir.append("testsavedir");
if (!saveDir.exists()) {
info("create testsavedir!");
saveDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
}
info("return from createTempSaveDir: " + saveDir.path);
return saveDir;
}
add_task(async function() {
await BrowserTestUtils.withNewTab("about:blank", async function(browser) {
Services.obs.addObserver(checkRequest, "http-on-modify-request");
BrowserTestUtils.loadURI(browser, TEST_PATH + "set-samesite-cookies-and-redirect.sjs");
// Test that the original document load doesn't send same-site cookies.
await BrowserTestUtils.browserLoaded(browser, true, TEST_PATH2 + "set-samesite-cookies-and-redirect.sjs");
// Now check the saved page.
// Create the folder the link will be saved into.
gTestDir = createTemporarySaveDirectory();
let destFile = gTestDir.clone();
MockFilePicker.displayDirectory = gTestDir;
let fileName;
MockFilePicker.showCallback = function(fp) {
info("showCallback");
fileName = fp.defaultString;
info("fileName: " + fileName);
destFile.append(fileName);
info("path: " + destFile.path);
MockFilePicker.setFiles([destFile]);
MockFilePicker.filterIndex = 0; // kSaveAsType_Complete
info("done showCallback");
};
saveBrowser(browser);
await new Promise(async (resolve) => {
let dls = await Downloads.getList(Downloads.PUBLIC);
dls.addView({
onDownloadChanged(download) {
if (download.succeeded) {
dls.removeView(this);
dls.removeFinished();
resolve();
}
}
});
});
});
});

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

@ -1,26 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
function handleRequest(request, response) {
let mimeType = request.queryString.match(/type=([a-z]*)/)[1];
switch (mimeType) {
case "css":
response.setHeader("Content-Type", "text/css");
response.write("#hi {color: red}");
break;
case "js":
response.setHeader("Content-Type", "application/javascript");
response.write("var foo;");
break;
case "png":
response.setHeader("Content-Type", "image/png");
response.write("");
break;
case "html":
response.setHeader("Content-Type", "text/html");
response.write("<body>I am a subframe</body>");
break;
}
}

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

@ -1,33 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
function handleRequest(request, response) {
// Set cookies and redirect for .org:
if (request.host.endsWith(".org")) {
response.setHeader("Set-Cookie", "normalCookie=true; path=/;", true);
response.setHeader("Set-Cookie", "laxHeader=true; path=/; SameSite=Lax", true);
response.setHeader("Set-Cookie", "strictHeader=true; path=/; SameSite=Strict", true);
response.write(`
<head>
<meta http-equiv='set-cookie' content='laxMeta=true; path=/; SameSite=Lax'>
<meta http-equiv='set-cookie' content='strictMeta=true; path=/; SameSite=Strict'>
</head>
<body>
<script>
document.cookie = 'laxScript=true; path=/; SameSite=Lax';
document.cookie = 'strictScript=true; path=/; SameSite=Strict';
location.href = location.href.replace(/\.org/, ".com");
</script>
</body>`);
} else {
let baseURI = "https://example.org/" + request.path.replace(/[a-z-]*\.sjs/, "mimeme.sjs?type=");
response.write(`
<link rel="stylesheet" type="text/css" href="${baseURI}css">
<iframe src="${baseURI}html"></iframe>
<script src="${baseURI}js"></script>
<img src="${baseURI}png">
`);
}
}

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

@ -10,7 +10,6 @@ include protocol PFileDescriptorSet;
include protocol PChildToParentStream; //FIXME: bug #792908
include protocol PParentToChildStream; //FIXME: bug #792908
include PBackgroundSharedTypes;
include IPCStream;
namespace mozilla {
@ -30,7 +29,6 @@ struct WebBrowserPersistDocumentAttrs {
nsString contentDisposition;
uint32_t cacheKey;
uint32_t persistFlags;
PrincipalInfo principal;
};
// IPDL doesn't have tuples, so this gives the pair of strings from

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

@ -41,7 +41,6 @@ WebBrowserPersistDocumentChild::Start(nsIWebBrowserPersistDocument* aDocument)
return;
}
nsCOMPtr<nsIPrincipal> principal;
WebBrowserPersistDocumentAttrs attrs;
nsCOMPtr<nsIInputStream> postDataStream;
#define ENSURE(e) do { \
@ -61,10 +60,6 @@ WebBrowserPersistDocumentChild::Start(nsIWebBrowserPersistDocument* aDocument)
ENSURE(aDocument->GetContentDisposition(attrs.contentDisposition()));
ENSURE(aDocument->GetCacheKey(&(attrs.cacheKey())));
ENSURE(aDocument->GetPersistFlags(&(attrs.persistFlags())));
ENSURE(aDocument->GetPrincipal(getter_AddRefs(principal)));
ENSURE(ipc::PrincipalToPrincipalInfo(principal, &(attrs.principal())));
ENSURE(aDocument->GetPostData(getter_AddRefs(postDataStream)));
#undef ENSURE

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

@ -184,14 +184,6 @@ WebBrowserPersistLocalDocument::GetPostData(nsIInputStream** aStream)
return history->GetPostData(aStream);
}
NS_IMETHODIMP
WebBrowserPersistLocalDocument::GetPrincipal(nsIPrincipal** aPrincipal)
{
nsCOMPtr<nsIPrincipal> nodePrincipal = mDocument->NodePrincipal();
nodePrincipal.forget(aPrincipal);
return NS_OK;
}
already_AddRefed<nsISHEntry>
WebBrowserPersistLocalDocument::GetHistory()
{

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

@ -9,9 +9,6 @@
#include "WebBrowserPersistResourcesParent.h"
#include "WebBrowserPersistSerializeParent.h"
#include "mozilla/Unused.h"
#include "mozilla/ipc/BackgroundUtils.h"
#include "nsIPrincipal.h"
namespace mozilla {
@ -26,8 +23,6 @@ WebBrowserPersistRemoteDocument
, mAttrs(aAttrs)
, mPostData(aPostData)
{
nsresult rv;
mPrincipal = ipc::PrincipalInfoToPrincipal(mAttrs.principal(), &rv);
}
WebBrowserPersistRemoteDocument::~WebBrowserPersistRemoteDocument()
@ -137,14 +132,6 @@ WebBrowserPersistRemoteDocument::GetPostData(nsIInputStream** aStream)
return NS_OK;
}
NS_IMETHODIMP
WebBrowserPersistRemoteDocument::GetPrincipal(nsIPrincipal** aPrincipal)
{
nsCOMPtr<nsIPrincipal> nodePrincipal = mPrincipal;
nodePrincipal.forget(aPrincipal);
return NS_OK;
}
NS_IMETHODIMP
WebBrowserPersistRemoteDocument::ReadResources(nsIWebBrowserPersistResourceVisitor* aVisitor)
{

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

@ -13,8 +13,6 @@
#include "nsIWebBrowserPersistDocument.h"
#include "nsIInputStream.h"
class nsIPrincipal;
// This class is the XPCOM half of the glue between the
// nsIWebBrowserPersistDocument interface and a remote document; it is
// created by WebBrowserPersistDocumentParent when (and if) it
@ -42,7 +40,6 @@ private:
WebBrowserPersistDocumentParent* mActor;
Attrs mAttrs;
nsCOMPtr<nsIInputStream> mPostData;
nsCOMPtr<nsIPrincipal> mPrincipal;
friend class WebBrowserPersistDocumentParent;
WebBrowserPersistRemoteDocument(WebBrowserPersistDocumentParent* aActor,

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

@ -12,7 +12,6 @@ interface nsIWebProgressListener;
interface nsIFile;
interface nsIChannel;
interface nsILoadContext;
interface nsIPrincipal;
/**
* Interface for persisting DOM documents and URIs to local or remote storage.
@ -66,6 +65,12 @@ interface nsIWebBrowserPersist : nsICancelable
*/
const unsigned long PERSIST_FLAGS_APPEND_TO_FILE = 32768;
/**
* Force relevant cookies to be sent with this load even if normally they
* wouldn't be.
*/
const unsigned long PERSIST_FLAGS_FORCE_ALLOW_COOKIES = 65536;
/**
* Flags governing how data is fetched and saved from the network.
* It is best to set this value explicitly unless you are prepared
@ -111,8 +116,6 @@ interface nsIWebBrowserPersist : nsICancelable
* @param aURI URI to save to file. Some implementations of this interface
* may also support <CODE>nullptr</CODE> to imply the currently
* loaded URI.
* @param aTriggeringPrincipal
* The triggering principal for the URI we're saving.
* @param aCacheKey The necko cache key integer.
* @param aReferrer The referrer URI to pass with an HTTP request or
* <CODE>nullptr</CODE>.
@ -139,8 +142,7 @@ interface nsIWebBrowserPersist : nsICancelable
*
* @throws NS_ERROR_INVALID_ARG One or more arguments was invalid.
*/
void saveURI(in nsIURI aURI, in nsIPrincipal aTriggeringPrincipal,
in unsigned long aCacheKey,
void saveURI(in nsIURI aURI, in unsigned long aCacheKey,
in nsIURI aReferrer, in unsigned long aReferrerPolicy,
in nsIInputStream aPostData,
in string aExtraHeaders, in nsISupports aFile,
@ -152,8 +154,7 @@ interface nsIWebBrowserPersist : nsICancelable
* of intermediate data, etc.)
* @see saveURI for all other parameter descriptions
*/
void savePrivacyAwareURI(in nsIURI aURI,
in nsIPrincipal aTriggeringPrincipal, in unsigned long aCacheKey,
void savePrivacyAwareURI(in nsIURI aURI, in unsigned long aCacheKey,
in nsIURI aReferrer, in unsigned long aReferrerPolicy,
in nsIInputStream aPostData,
in string aExtraHeaders, in nsISupports aFile,

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

@ -8,7 +8,6 @@
interface nsIInputStream;
interface nsIOutputStream;
interface nsIPrincipal;
interface nsITabParent;
interface nsIWebBrowserPersistResourceVisitor;
interface nsIWebBrowserPersistWriteCompletion;
@ -61,7 +60,6 @@ interface nsIWebBrowserPersistDocument : nsISupports
readonly attribute AString referrer;
readonly attribute AString contentDisposition;
readonly attribute nsIInputStream postData;
readonly attribute nsIPrincipal principal;
/**
* The cache key. Unlike in nsISHEntry, where it's wrapped in an

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

@ -83,7 +83,6 @@ struct nsWebBrowserPersist::DocData
nsCOMPtr<nsIURI> mBaseURI;
nsCOMPtr<nsIWebBrowserPersistDocument> mDocument;
nsCOMPtr<nsIURI> mFile;
nsCOMPtr<nsIPrincipal> mPrincipal;
nsCString mCharset;
};
@ -414,20 +413,18 @@ NS_IMETHODIMP nsWebBrowserPersist::SetProgressListener(
}
NS_IMETHODIMP nsWebBrowserPersist::SaveURI(
nsIURI *aURI, nsIPrincipal *aPrincipal, uint32_t aCacheKey,
nsIURI *aURI, uint32_t aCacheKey,
nsIURI *aReferrer, uint32_t aReferrerPolicy,
nsIInputStream *aPostData, const char *aExtraHeaders,
nsISupports *aFile, nsILoadContext* aPrivacyContext)
{
bool isPrivate =
aPrivacyContext && aPrivacyContext->UsePrivateBrowsing();
return SavePrivacyAwareURI(aURI, aPrincipal, aCacheKey,
aReferrer, aReferrerPolicy,
aPostData, aExtraHeaders, aFile, isPrivate);
return SavePrivacyAwareURI(aURI, aCacheKey, aReferrer, aReferrerPolicy,
aPostData, aExtraHeaders, aFile,
aPrivacyContext && aPrivacyContext->UsePrivateBrowsing());
}
NS_IMETHODIMP nsWebBrowserPersist::SavePrivacyAwareURI(
nsIURI *aURI, nsIPrincipal *aPrincipal, uint32_t aCacheKey,
nsIURI *aURI, uint32_t aCacheKey,
nsIURI *aReferrer, uint32_t aReferrerPolicy,
nsIInputStream *aPostData, const char *aExtraHeaders,
nsISupports *aFile, bool aIsPrivate)
@ -442,10 +439,8 @@ NS_IMETHODIMP nsWebBrowserPersist::SavePrivacyAwareURI(
// SaveURI doesn't like broken uris.
mPersistFlags |= PERSIST_FLAGS_FAIL_ON_BROKEN_LINKS;
rv = SaveURIInternal(aURI, aPrincipal, aCacheKey,
aReferrer, aReferrerPolicy,
aPostData, aExtraHeaders, fileAsURI,
false, aIsPrivate);
rv = SaveURIInternal(aURI, aCacheKey, aReferrer, aReferrerPolicy,
aPostData, aExtraHeaders, fileAsURI, false, aIsPrivate);
return NS_FAILED(rv) ? rv : NS_OK;
}
@ -604,13 +599,6 @@ nsWebBrowserPersist::SerializeNextFile()
}
if (urisToPersist > 0) {
nsCOMPtr<nsIPrincipal> docPrincipal;
//XXXgijs I *think* this is already always true, but let's be sure.
MOZ_ASSERT(mDocList.Length() > 0,
"Should have the document for any walked URIs to persist!");
nsresult rv = mDocList.ElementAt(0)->mDocument->
GetPrincipal(getter_AddRefs(docPrincipal));
NS_ENSURE_SUCCESS_VOID(rv);
// Persist each file in the uri map. The document(s)
// will be saved after the last one of these is saved.
for (auto iter = mURIMap.Iter(); !iter.Done(); iter.Next()) {
@ -620,6 +608,8 @@ nsWebBrowserPersist::SerializeNextFile()
continue;
}
nsresult rv;
// Create a URI from the key.
nsCOMPtr<nsIURI> uri;
rv = NS_NewURI(getter_AddRefs(uri), iter.Key(),
@ -637,7 +627,7 @@ nsWebBrowserPersist::SerializeNextFile()
// The Referrer Policy doesn't matter here since the referrer is
// nullptr.
rv = SaveURIInternal(uri, docPrincipal, 0, nullptr,
rv = SaveURIInternal(uri, 0, nullptr,
mozilla::net::RP_Unset, nullptr, nullptr,
fileAsURI, true, mIsPrivate);
// If SaveURIInternal fails, then it will have called EndDownload,
@ -1334,8 +1324,7 @@ nsWebBrowserPersist::AppendPathToURI(nsIURI *aURI, const nsAString & aPath, nsCO
}
nsresult nsWebBrowserPersist::SaveURIInternal(
nsIURI *aURI, nsIPrincipal* aTriggeringPrincipal,
uint32_t aCacheKey, nsIURI *aReferrer,
nsIURI *aURI, uint32_t aCacheKey, nsIURI *aReferrer,
uint32_t aReferrerPolicy, nsIInputStream *aPostData,
const char *aExtraHeaders, nsIURI *aFile,
bool aCalcFileExt, bool aIsPrivate)
@ -1361,7 +1350,7 @@ nsresult nsWebBrowserPersist::SaveURIInternal(
nsCOMPtr<nsIChannel> inputChannel;
rv = NS_NewChannel(getter_AddRefs(inputChannel),
aURI,
aTriggeringPrincipal,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
nsIContentPolicy::TYPE_OTHER,
nullptr, // aPerformanceStorage
@ -1391,6 +1380,16 @@ nsresult nsWebBrowserPersist::SaveURIInternal(
}
}
if (mPersistFlags & PERSIST_FLAGS_FORCE_ALLOW_COOKIES)
{
nsCOMPtr<nsIHttpChannelInternal> httpChannelInternal =
do_QueryInterface(inputChannel);
if (httpChannelInternal) {
rv = httpChannelInternal->SetThirdPartyFlags(nsIHttpChannelInternal::THIRD_PARTY_FORCE_ALLOW);
MOZ_ASSERT(NS_SUCCEEDED(rv));
}
}
// Set the referrer, post data and headers if any
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(inputChannel));
if (httpChannel)

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

@ -57,8 +57,7 @@ public:
private:
virtual ~nsWebBrowserPersist();
nsresult SaveURIInternal(
nsIURI *aURI, nsIPrincipal* aTriggeringPrincipal,
uint32_t aCacheKey, nsIURI *aReferrer,
nsIURI *aURI, uint32_t aCacheKey, nsIURI *aReferrer,
uint32_t aReferrerPolicy, nsIInputStream *aPostData,
const char *aExtraHeaders, nsIURI *aFile,
bool aCalcFileExt, bool aIsPrivate);

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

@ -986,7 +986,6 @@ nsWebBrowser::SetProgressListener(nsIWebProgressListener* aProgressListener)
NS_IMETHODIMP
nsWebBrowser::SaveURI(nsIURI* aURI,
nsIPrincipal* aPrincipal,
uint32_t aCacheKey,
nsIURI* aReferrer,
uint32_t aReferrerPolicy,
@ -996,14 +995,12 @@ nsWebBrowser::SaveURI(nsIURI* aURI,
nsILoadContext* aPrivacyContext)
{
return SavePrivacyAwareURI(
aURI, aPrincipal, aCacheKey, aReferrer, aReferrerPolicy, aPostData,
aExtraHeaders, aFile,
aPrivacyContext && aPrivacyContext->UsePrivateBrowsing());
aURI, aCacheKey, aReferrer, aReferrerPolicy, aPostData, aExtraHeaders,
aFile, aPrivacyContext && aPrivacyContext->UsePrivateBrowsing());
}
NS_IMETHODIMP
nsWebBrowser::SavePrivacyAwareURI(nsIURI* aURI,
nsIPrincipal* aPrincipal,
uint32_t aCacheKey,
nsIURI* aReferrer,
uint32_t aReferrerPolicy,
@ -1041,9 +1038,8 @@ nsWebBrowser::SavePrivacyAwareURI(nsIURI* aURI,
mPersist->SetPersistFlags(mPersistFlags);
mPersist->GetCurrentState(&mPersistCurrentState);
rv = mPersist->SavePrivacyAwareURI(uri, aPrincipal, aCacheKey,
aReferrer, aReferrerPolicy, aPostData,
aExtraHeaders, aFile, aIsPrivate);
rv = mPersist->SavePrivacyAwareURI(uri, aCacheKey, aReferrer, aReferrerPolicy,
aPostData, aExtraHeaders, aFile, aIsPrivate);
if (NS_FAILED(rv)) {
mPersist = nullptr;
}

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

@ -283,8 +283,7 @@ function promiseStartLegacyDownload(aSourceUrl, aOptions) {
// Start the actual download process.
persist.savePrivacyAwareURI(
sourceURI, Services.scriptSecurityManager.getSystemPrincipal(),
0, referrer, Ci.nsIHttpChannel.REFERRER_POLICY_UNSAFE_URL,
sourceURI, 0, referrer, Ci.nsIHttpChannel.REFERRER_POLICY_UNSAFE_URL,
null, null, targetFile, isPrivate);
}).catch(do_report_unexpected_exception);

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

@ -226,11 +226,7 @@ var gViewSourceUtils = {
webBrowserPersist.persistFlags = this.mnsIWebBrowserPersist.PERSIST_FLAGS_REPLACE_EXISTING_FILES;
webBrowserPersist.progressListener = this.viewSourceProgressListener;
let referrerPolicy = Ci.nsIHttpChannel.REFERRER_POLICY_NO_REFERRER;
let ssm = Services.scriptSecurityManager;
let principal = ssm.createCodebasePrincipal(data.uri,
browser.contentPrincipal.originAttributes);
webBrowserPersist.savePrivacyAwareURI(uri, principal, null, null,
referrerPolicy, null, null, file, data.isPrivate);
webBrowserPersist.savePrivacyAwareURI(uri, null, null, referrerPolicy, null, null, file, data.isPrivate);
let helperService = Cc["@mozilla.org/uriloader/external-helper-app-service;1"]
.getService(Ci.nsPIExternalAppLauncher);

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

@ -62,15 +62,14 @@ function forbidCPOW(arg, func, argname) {
// - A linked document using Alt-click Save Link As...
//
function saveURL(aURL, aFileName, aFilePickerTitleKey, aShouldBypassCache,
aSkipPrompt, aReferrer, aSourceDocument,
aIsContentWindowPrivate, aPrincipal) {
aSkipPrompt, aReferrer, aSourceDocument, aIsContentWindowPrivate) {
forbidCPOW(aURL, "saveURL", "aURL");
forbidCPOW(aReferrer, "saveURL", "aReferrer");
// Allow aSourceDocument to be a CPOW.
internalSave(aURL, null, aFileName, null, null, aShouldBypassCache,
aFilePickerTitleKey, null, aReferrer, aSourceDocument,
aSkipPrompt, null, aIsContentWindowPrivate, aPrincipal);
aSkipPrompt, null, aIsContentWindowPrivate);
}
// Just like saveURL, but will get some info off the image before
@ -113,7 +112,7 @@ const nsISupportsCString = Ci.nsISupportsCString;
*/
function saveImageURL(aURL, aFileName, aFilePickerTitleKey, aShouldBypassCache,
aSkipPrompt, aReferrer, aDoc, aContentType, aContentDisp,
aIsContentWindowPrivate, aPrincipal) {
aIsContentWindowPrivate) {
forbidCPOW(aURL, "saveImageURL", "aURL");
forbidCPOW(aReferrer, "saveImageURL", "aReferrer");
@ -157,7 +156,7 @@ function saveImageURL(aURL, aFileName, aFilePickerTitleKey, aShouldBypassCache,
internalSave(aURL, null, aFileName, aContentDisp, aContentType,
aShouldBypassCache, aFilePickerTitleKey, null, aReferrer,
aDoc, aSkipPrompt, null, aIsContentWindowPrivate, aPrincipal);
null, aSkipPrompt, null, aIsContentWindowPrivate);
}
// This is like saveDocument, but takes any browser/frame-like element
@ -332,15 +331,11 @@ XPCOMUtils.defineConstant(this, "kSaveAsType_Text", kSaveAsType_Text);
* This parameter is provided when the aInitiatingDocument is not a
* real document object. Stores whether aInitiatingDocument.defaultView
* was private or not.
* @param aPrincipal [optional]
* This parameter is provided when neither aDocument nor
* aInitiatingDocument is provided. Used to determine what level of
* privilege to load the URI with.
*/
function internalSave(aURL, aDocument, aDefaultFileName, aContentDisposition,
aContentType, aShouldBypassCache, aFilePickerTitleKey,
aChosenData, aReferrer, aInitiatingDocument, aSkipPrompt,
aCacheKey, aIsContentWindowPrivate, aPrincipal) {
aCacheKey, aIsContentWindowPrivate) {
forbidCPOW(aURL, "internalSave", "aURL");
forbidCPOW(aReferrer, "internalSave", "aReferrer");
forbidCPOW(aCacheKey, "internalSave", "aCacheKey");
@ -416,17 +411,8 @@ function internalSave(aURL, aDocument, aDefaultFileName, aContentDisposition,
: aInitiatingDocument.isPrivate;
}
// We have to cover the cases here where we were either passed an explicit
// principal, or a 'real' document (with a nodePrincipal property), or an
// nsIWebBrowserPersistDocument which has a principal property.
let sourcePrincipal =
aPrincipal ||
(aDocument && (aDocument.nodePrincipal || aDocument.principal)) ||
(aInitiatingDocument && aInitiatingDocument.nodePrincipal);
var persistArgs = {
sourceURI,
sourcePrincipal,
sourceReferrer: aReferrer,
sourceDocument: useSaveDocument ? aDocument : null,
targetContentType: (saveAsType == kSaveAsType_Text) ? "text/plain" : null,
@ -477,7 +463,8 @@ function internalPersist(persistArgs) {
// Calculate persist flags.
const nsIWBP = Ci.nsIWebBrowserPersist;
const flags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES;
const flags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
nsIWBP.PERSIST_FLAGS_FORCE_ALLOW_COOKIES;
if (persistArgs.bypassCache)
persist.persistFlags = flags | nsIWBP.PERSIST_FLAGS_BYPASS_CACHE;
else
@ -524,7 +511,6 @@ function internalPersist(persistArgs) {
persistArgs.targetContentType, encodingFlags, kWrapColumn);
} else {
persist.savePrivacyAwareURI(persistArgs.sourceURI,
persistArgs.sourcePrincipal,
persistArgs.sourceCacheKey,
persistArgs.sourceReferrer,
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,

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

@ -36,8 +36,7 @@ add_task(async function preferred_API() {
return image.href;
});
saveImageURL(url, "image.jpg", null, true, false, null, null, null, null,
false, gBrowser.contentPrincipal);
saveImageURL(url, "image.jpg", null, true, false, null, null, null, null, false);
let channel = gBrowser.contentDocumentAsCPOW.docShell.currentDocumentChannel;
if (channel) {
ok(true, channel.QueryInterface(Ci.nsIHttpChannelInternal)