Bug 1528697 - Add cenum referrerpolicy in ReferrerInfo.idl r=ckerschb,Gijs

Differential Revision: https://phabricator.services.mozilla.com/D41955

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Thomas Nguyen 2019-08-21 13:28:23 +00:00
Родитель 32ab8293ff
Коммит bbd6f51a56
34 изменённых файлов: 253 добавлений и 172 удалений

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

@ -6526,16 +6526,12 @@ nsBrowserAccess.prototype = {
let referrerInfo;
if (aFlags & Ci.nsIBrowserDOMWindow.OPEN_NO_REFERRER) {
referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
false,
null
);
referrerInfo = new ReferrerInfo(Ci.nsIReferrerInfo.EMPTY, false, null);
} else {
referrerInfo = new ReferrerInfo(
aOpener && aOpener.document
? aOpener.document.referrerPolicy
: Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
? aOpener.document.referrerInfo.referrerPolicy
: Ci.nsIReferrerInfo.EMPTY,
true,
aOpener ? makeURI(aOpener.location.href) : null
);

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

@ -782,7 +782,7 @@ function saveMedia() {
// Bug 1565216 to evaluate passing referrer as item.baseURL
let referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
Ci.nsIReferrerInfo.EMPTY,
true,
Services.io.newURI(item.baseURI)
);
@ -805,7 +805,7 @@ function saveMedia() {
uniqueFile(aChosenData.file);
let referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
Ci.nsIReferrerInfo.EMPTY,
true,
aBaseURI
);

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

@ -18,7 +18,7 @@ add_task(async function() {
function addTab(aURL, aReferrer) {
let referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
Ci.nsIReferrerInfo.EMPTY,
true,
aReferrer
);

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

@ -366,7 +366,7 @@ function openLinkIn(url, where, params) {
var aCharset = params.charset;
var aReferrerInfo = params.referrerInfo
? params.referrerInfo
: new ReferrerInfo(Ci.nsIHttpChannel.REFERRER_POLICY_UNSET, true, null);
: new ReferrerInfo(Ci.nsIReferrerInfo.EMPTY, true, null);
var aRelatedToCurrent = params.relatedToCurrent;
var aAllowInheritPrincipal = !!params.allowInheritPrincipal;
var aAllowMixedContent = params.allowMixedContent;

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

@ -39,7 +39,7 @@ add_task(async function() {
gBrowser.selectedTab = tab;
let referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
Ci.nsIReferrerInfo.EMPTY,
true,
gBrowser.currentURI
);
@ -55,7 +55,7 @@ add_task(async function() {
gBrowser.selectedTab = tab;
referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
Ci.nsIReferrerInfo.EMPTY,
true,
gBrowser.currentURI
);

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

@ -286,7 +286,7 @@ class PlacesFeed {
"init"
);
params.referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSAFE_URL,
Ci.nsIReferrerInfo.UNSAFE_URL,
true,
Services.io.newURI(referrer)
);

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

@ -117,7 +117,7 @@ const TEST_GLOBAL = {
},
Ci: {
nsICryptoHash: {},
nsIHttpChannel: { REFERRER_POLICY_UNSAFE_URL: 5 },
nsIReferrerInfo: { UNSAFE_URL: 5 },
nsITimer: { TYPE_ONE_SHOT: 1 },
nsIWebProgressListener: { LOCATION_CHANGE_SAME_DOCUMENT: 1 },
nsIDOMWindow: Object,

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

@ -219,7 +219,7 @@ ContentRestoreInternal.prototype = {
let referrerPolicy =
"referrerPolicy" in loadArguments
? loadArguments.referrerPolicy
: Ci.nsIHttpChannel.REFERRER_POLICY_UNSET;
: Ci.nsIReferrerInfo.EMPTY;
let ReferrerInfo = Components.Constructor(
"@mozilla.org/referrer-info;1",
"nsIReferrerInfo",

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

@ -30,7 +30,7 @@ add_task(async function() {
// Load a new URI with a specific referrer.
let referrerInfo1 = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
Ci.nsIReferrerInfo.EMPTY,
true,
Services.io.newURI(REFERRER1)
);
@ -52,7 +52,7 @@ add_task(async function() {
);
let referrerInfo2 = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
Ci.nsIReferrerInfo.EMPTY,
true,
Services.io.newURI(REFERRER2)
);

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

@ -60,7 +60,7 @@ BrowserElementWebNavigation.prototype = {
uri,
flags,
referrer,
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
Ci.nsIReferrerInfo.EMPTY,
postData,
headers,
null,

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

@ -13,11 +13,7 @@ function run_test() {
Services.prefs.setBoolPref("network.prefetch-next", true);
for (var i = 0; i < 5; i++) {
var uri = Services.io.newURI("http://localhost/" + i);
var referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
true,
uri
);
var referrerInfo = new ReferrerInfo(Ci.nsIReferrerInfo.EMPTY, true, uri);
prefetch.prefetchURI(uri, referrerInfo, null, true);
}
@ -32,11 +28,7 @@ function run_test() {
Services.prefs.setBoolPref("network.prefetch-next", true);
for (var k = 0; k < 5; k++) {
var uri2 = Services.io.newURI("http://localhost/" + k);
var referrerInfo2 = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
true,
uri2
);
var referrerInfo2 = new ReferrerInfo(Ci.nsIReferrerInfo.EMPTY, true, uri2);
prefetch.prefetchURI(uri2, referrerInfo2, null, true);
}
Assert.ok(prefetch.hasMoreElements());

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

@ -37,11 +37,7 @@ function run_test() {
add_test(function test_cancel1() {
var uri = ios.newURI("http://localhost/1");
var referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
true,
uri
);
var referrerInfo = new ReferrerInfo(Ci.nsIReferrerInfo.EMPTY, true, uri);
prefetch.prefetchURI(uri, referrerInfo, node1, true);
@ -74,11 +70,7 @@ add_test(function test_cancel2() {
// in the queue and canceling one will not cancel the other.
var uri = ios.newURI("http://localhost/1");
var referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
true,
uri
);
var referrerInfo = new ReferrerInfo(Ci.nsIReferrerInfo.EMPTY, true, uri);
prefetch.prefetchURI(uri, referrerInfo, node1, true);
prefetch.prefetchURI(uri, referrerInfo, node2, true);
@ -102,11 +94,7 @@ add_test(function test_cancel3() {
// Request a prefetch of a uri. Trying to cancel a prefetch for the same uri
// with a different node will fail.
var uri = ios.newURI("http://localhost/1");
var referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
true,
uri
);
var referrerInfo = new ReferrerInfo(Ci.nsIReferrerInfo.EMPTY, true, uri);
prefetch.prefetchURI(uri, referrerInfo, node1, true);
@ -136,11 +124,7 @@ add_test(function test_cancel4() {
// with the same node will fail.
var uri1 = ios.newURI("http://localhost/1");
var uri2 = ios.newURI("http://localhost/2");
var referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
true,
uri1
);
var referrerInfo = new ReferrerInfo(Ci.nsIReferrerInfo.EMPTY, true, uri1);
prefetch.prefetchURI(uri1, referrerInfo, node1, true);

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

@ -19,6 +19,59 @@ native URIRef(already_AddRefed<nsIURI>);
[scriptable, builtinclass, uuid(081cdc36-f2e2-4f94-87bf-78578f06f1eb)]
interface nsIReferrerInfo : nsISerializable
{
/**
* Unfortunately we can not query the ReferrerPolicy values defined within
* ReferrerPolicy.webidl directly from xpidl. Hence we define the enum value
* ReferrerPolicyIDL to set up the ReferrerInfo object from JS. If you need
* ReferrerPolicy in native code, please directly query it from
* ReferrerPolicy.webidl.
*/
cenum ReferrerPolicyIDL : 8 {
/**
* The undefined state, or no referrer policy, usually causing a fallback to a
* referrer policy definded in higher level policy. For example: request by
* clicking <a> element with empty referrer policy will be sent with the
* referrer policy of the a elements node document.
* If there is no higher-level policy available, we fall back to the default
* value, which usually is "no-referrer-when-downgrade".
*/
EMPTY = 0,
/**
* Do not send referrer from https->http
*/
NO_REFERRER_WHEN_DOWNGRADE = 1,
/**
* Do not send referrer at all.
*/
NO_REFERRER = 2,
/**
* Only send the origin of the referring URL
*/
ORIGIN = 3,
/**
* Send origin when cross-origin.
*/
ORIGIN_WHEN_CROSS_ORIGIN = 4,
/**
* Always sends the referrer, even on downgrade.
*/
UNSAFE_URL = 5,
/**
* Send referrer when same-origin, no referrer when cross-origin
*/
SAME_ORIGIN = 6,
/**
* Send origin when request from https->https or http->http(s). No referrer
* when request from https->http.
*/
STRICT_ORIGIN = 7,
/**
* Send referrer when same-origin, send origin when cross-origin from
* https->https or http->http(s). No referrer when request from https->http.
*/
STRICT_ORIGIN_WHEN_CROSS_ORIGIN = 8,
};
/**
* The original referrer URI which indicates the full referrer before applying
* referrer policy
@ -28,7 +81,7 @@ interface nsIReferrerInfo : nsISerializable
/**
* Referrer policy which is applied to the referrer
*/
readonly attribute ReferrerPolicy referrerPolicy;
[implicit_jscontext] readonly attribute nsIReferrerInfo_ReferrerPolicyIDL referrerPolicy;
/**
* C++ friendly version of referrerPolicy getter
@ -60,12 +113,13 @@ interface nsIReferrerInfo : nsISerializable
boolean equals(in nsIReferrerInfo other);
/**
* Initialize method.
* Initialize method to create ReferrerInfo object from JS
* @param aReferrerPolicy referrer policy of the created object
* @param aSendReferrer sendReferrer of the created object, defaults to false
* @param aOriginalReferrer the original referrer, defaults to null.
*/
void init(in uint32_t aReferrerPolicy,
[implicit_jscontext]
void init(in nsIReferrerInfo_ReferrerPolicyIDL aReferrerPolicy,
[optional] in boolean aSendReferrer,
[optional] in nsIURI aOriginalReferrer);

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

@ -626,6 +626,81 @@ void ReferrerInfo::LogMessageToConsole(
Unused << NS_WARN_IF(NS_FAILED(rv));
}
ReferrerPolicy ReferrerPolicyIDLToReferrerPolicy(
nsIReferrerInfo::ReferrerPolicyIDL aReferrerPolicy) {
switch (aReferrerPolicy) {
case nsIReferrerInfo::EMPTY:
return ReferrerPolicy::_empty;
break;
case nsIReferrerInfo::NO_REFERRER:
return ReferrerPolicy::No_referrer;
break;
case nsIReferrerInfo::NO_REFERRER_WHEN_DOWNGRADE:
return ReferrerPolicy::No_referrer_when_downgrade;
break;
case nsIReferrerInfo::ORIGIN:
return ReferrerPolicy::Origin;
break;
case nsIReferrerInfo::ORIGIN_WHEN_CROSS_ORIGIN:
return ReferrerPolicy::Origin_when_cross_origin;
break;
case nsIReferrerInfo::UNSAFE_URL:
return ReferrerPolicy::Unsafe_url;
break;
case nsIReferrerInfo::SAME_ORIGIN:
return ReferrerPolicy::Same_origin;
break;
case nsIReferrerInfo::STRICT_ORIGIN:
return ReferrerPolicy::Strict_origin;
break;
case nsIReferrerInfo::STRICT_ORIGIN_WHEN_CROSS_ORIGIN:
return ReferrerPolicy::Strict_origin_when_cross_origin;
break;
default:
MOZ_ASSERT_UNREACHABLE("Invalid ReferrerPolicy value");
break;
}
return ReferrerPolicy::_empty;
}
nsIReferrerInfo::ReferrerPolicyIDL ReferrerPolicyToReferrerPolicyIDL(ReferrerPolicy aReferrerPolicy) {
switch (aReferrerPolicy) {
case ReferrerPolicy::_empty:
return nsIReferrerInfo::EMPTY;
break;
case ReferrerPolicy::No_referrer:
return nsIReferrerInfo::NO_REFERRER;
break;
case ReferrerPolicy::No_referrer_when_downgrade:
return nsIReferrerInfo::NO_REFERRER_WHEN_DOWNGRADE;
break;
case ReferrerPolicy::Origin:
return nsIReferrerInfo::ORIGIN;
break;
case ReferrerPolicy::Origin_when_cross_origin:
return nsIReferrerInfo::ORIGIN_WHEN_CROSS_ORIGIN;
break;
case ReferrerPolicy::Unsafe_url:
return nsIReferrerInfo::UNSAFE_URL;
break;
case ReferrerPolicy::Same_origin:
return nsIReferrerInfo::SAME_ORIGIN;
break;
case ReferrerPolicy::Strict_origin:
return nsIReferrerInfo::STRICT_ORIGIN;
break;
case ReferrerPolicy::Strict_origin_when_cross_origin:
return nsIReferrerInfo::STRICT_ORIGIN_WHEN_CROSS_ORIGIN;
break;
default:
MOZ_ASSERT_UNREACHABLE("Invalid ReferrerPolicy value");
break;
}
return nsIReferrerInfo::EMPTY;
}
ReferrerInfo::ReferrerInfo()
: mOriginalReferrer(nullptr),
mPolicy(ReferrerPolicy::_empty),
@ -686,8 +761,8 @@ ReferrerInfo::GetOriginalReferrer(nsIURI** aOriginalReferrer) {
}
NS_IMETHODIMP
ReferrerInfo::GetReferrerPolicy(ReferrerPolicyEnum* aReferrerPolicy) {
*aReferrerPolicy = mPolicy;
ReferrerInfo::GetReferrerPolicy(JSContext* aCx, nsIReferrerInfo::ReferrerPolicyIDL* aReferrerPolicy) {
*aReferrerPolicy = ReferrerPolicyToReferrerPolicyIDL(mPolicy);
return NS_OK;
}
@ -773,14 +848,14 @@ HashNumber ReferrerInfo::Hash() const {
}
NS_IMETHODIMP
ReferrerInfo::Init(uint32_t aReferrerPolicy, bool aSendReferrer,
nsIURI* aOriginalReferrer) {
ReferrerInfo::Init(nsIReferrerInfo::ReferrerPolicyIDL aReferrerPolicy, bool aSendReferrer,
nsIURI* aOriginalReferrer, JSContext* aCx) {
MOZ_ASSERT(!mInitialized);
if (mInitialized) {
return NS_ERROR_ALREADY_INITIALIZED;
};
mPolicy = aReferrerPolicy;
mPolicy = ReferrerPolicyIDLToReferrerPolicy(aReferrerPolicy);
mSendReferrer = aSendReferrer;
mOriginalReferrer = aOriginalReferrer;
mInitialized = true;
@ -1161,12 +1236,16 @@ ReferrerInfo::Read(nsIObjectInputStream* aStream) {
mOriginalReferrer = nullptr;
}
// ReferrerPolicy.webidl has different order with ReferrerPolicyIDL. We store
// to disk using the order of ReferrerPolicyIDL, so we convert to
// ReferrerPolicyIDL to make it be compatible to the old format.
uint32_t policy;
rv = aStream->Read32(&policy);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mPolicy = static_cast<ReferrerPolicyEnum>(policy);
mPolicy = ReferrerPolicyIDLToReferrerPolicy(
static_cast<nsIReferrerInfo::ReferrerPolicyIDL>(policy));
rv = aStream->ReadBoolean(&mSendReferrer);
if (NS_WARN_IF(NS_FAILED(rv))) {
@ -1222,7 +1301,7 @@ ReferrerInfo::Write(nsIObjectOutputStream* aStream) {
}
}
rv = aStream->Write32(static_cast<uint32_t>(mPolicy));
rv = aStream->Write32(ReferrerPolicyToReferrerPolicyIDL(mPolicy));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

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

@ -9,7 +9,7 @@ const ReferrerInfo = Components.Constructor(
);
const referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_ORIGIN,
Ci.nsIReferrerInfo.ORIGIN,
true,
Services.io.newURI(TEST_REFERRER)
);

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

@ -1295,11 +1295,11 @@ class FetchEventRunnable : public ExtendableFunctionalEventWorkerRunnable,
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(channel);
MOZ_ASSERT(httpChannel, "How come we don't have an HTTP channel?");
ReferrerPolicy referrerPolicy = ReferrerPolicy::_empty;
mReferrerPolicy = ReferrerPolicy::_empty;
mReferrer = EmptyString();
nsCOMPtr<nsIReferrerInfo> referrerInfo = httpChannel->GetReferrerInfo();
if (referrerInfo) {
referrerPolicy = referrerInfo->ReferrerPolicy();
mReferrerPolicy = referrerInfo->ReferrerPolicy();
Unused << referrerInfo->GetComputedReferrerSpec(mReferrer);
}

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

@ -100,7 +100,7 @@ function checkSecondLoad() {
.getService(Ci.imgITools)
.createScriptedObserver(listener);
var referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_NO_REFERRER_WHEN_DOWNGRADE,
Ci.nsIReferrerInfo.NO_REFERRER_WHEN_DOWNGRADE,
true,
null
);
@ -217,7 +217,7 @@ function startImageCallback(otherCb) {
.getService(Ci.imgITools)
.createScriptedObserver(listener2);
var referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_NO_REFERRER_WHEN_DOWNGRADE,
Ci.nsIReferrerInfo.NO_REFERRER_WHEN_DOWNGRADE,
true,
null
);
@ -271,7 +271,7 @@ function run_test() {
.getService(Ci.imgITools)
.createScriptedObserver(listener);
var referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_NO_REFERRER_WHEN_DOWNGRADE,
Ci.nsIReferrerInfo.NO_REFERRER_WHEN_DOWNGRADE,
true,
null
);

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

@ -91,7 +91,7 @@ function loadImage(isPrivate, callback) {
: nonPrivateLoadContext;
var loader = isPrivate ? gPrivateLoader : gPublicLoader;
var referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_NO_REFERRER_WHEN_DOWNGRADE,
Ci.nsIReferrerInfo.NO_REFERRER_WHEN_DOWNGRADE,
true,
null
);

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

@ -506,11 +506,7 @@ function createReferrerInfo(aReferrer) {
referrerUri = Services.io.newURI(aReferrer);
} catch (ignored) {}
return new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
true,
referrerUri
);
return new ReferrerInfo(Ci.nsIReferrerInfo.EMPTY, true, referrerUri);
}
/**

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

@ -35,11 +35,7 @@ const createReferrerInfo = aReferrer => {
referrerUri = Services.io.newURI(aReferrer);
} catch (ignored) {}
return new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
true,
referrerUri
);
return new ReferrerInfo(Ci.nsIReferrerInfo.EMPTY, true, referrerUri);
};
// Handles navigation requests between Gecko and a GeckoView.
@ -153,7 +149,7 @@ class GeckoViewNavigation extends GeckoViewModule {
const referrerPolicy = referrerWindow.browser.referrerInfo
? referrerWindow.browser.referrerInfo.referrerPolicy
: Ci.nsIHttpChannel.REFERRER_POLICY_UNSET;
: Ci.nsIReferrerInfo.EMPTY;
referrerInfo = new ReferrerInfo(
referrerPolicy,

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

@ -73,20 +73,12 @@ function setup_test() {
Assert.equal(setOK, "foo");
var uri = NetUtil.newURI("http://foo1.invalid:80");
channel.referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
true,
uri
);
channel.referrerInfo = new ReferrerInfo(Ci.nsIReferrerInfo.EMPTY, true, uri);
setOK = channel.getRequestHeader("Referer");
Assert.equal(setOK, "http://foo1.invalid/");
uri = NetUtil.newURI("http://foo2.invalid:90/bar");
channel.referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
true,
uri
);
channel.referrerInfo = new ReferrerInfo(Ci.nsIReferrerInfo.EMPTY, true, uri);
setOK = channel.getRequestHeader("Referer");
Assert.equal(setOK, "http://foo2.invalid:90/bar");

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

@ -38,7 +38,7 @@ var observer = {
Assert.equal(currentReferrer, "http://site1.com/");
var uri = ios.newURI("http://site2.com");
subject.referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
Ci.nsIReferrerInfo.EMPTY,
true,
uri
);
@ -67,7 +67,7 @@ let cancelDuringOnStartListener = {
// we expect setting referrer to fail
try {
request.referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
Ci.nsIReferrerInfo.EMPTY,
true,
uri
);
@ -120,11 +120,7 @@ function makeChan(url) {
// ENSURE_CALLED_BEFORE_CONNECT: set original value
var uri = ios.newURI("http://site1.com");
chan.referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
true,
uri
);
chan.referrerInfo = new ReferrerInfo(Ci.nsIReferrerInfo.EMPTY, true, uri);
return chan;
}

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

@ -639,7 +639,7 @@ function test_prefetch_prime() {
}).QueryInterface(Ci.nsIHttpChannel);
channel.requestMethod = "GET";
channel.referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
Ci.nsIReferrerInfo.EMPTY,
true,
prefetch_tluri
);

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

@ -66,11 +66,7 @@ function run_test() {
var chan = make_channel(URL + redirects[0]);
var uri = NetUtil.newURI("http://test.com");
httpChan = chan.QueryInterface(Ci.nsIHttpChannel);
httpChan.referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
true,
uri
);
httpChan.referrerInfo = new ReferrerInfo(Ci.nsIReferrerInfo.EMPTY, true, uri);
chan.asyncOpen(new ChannelListener(finish_test, null));
do_test_pending();
}

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

@ -20,7 +20,7 @@ function getTestReferrer(server_uri, referer_uri, isPrivate = false) {
chan.QueryInterface(Ci.nsIHttpChannel);
chan.referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
Ci.nsIReferrerInfo.EMPTY,
true,
referrer
);

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

@ -58,44 +58,44 @@ function test_policy(test) {
}
}
const nsIHttpChannel = Ci.nsIHttpChannel;
const nsIReferrerInfo = Ci.nsIReferrerInfo;
var gTests = [
// Test same origin policy w/o cross origin
{
policy: nsIHttpChannel.REFERRER_POLICY_SAME_ORIGIN,
policy: nsIReferrerInfo.SAME_ORIGIN,
url: "https://test.example/foo?a",
referrer: "https://test.example/foo?a",
expectedReferrerSpec: "https://test.example/foo?a",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_SAME_ORIGIN,
policy: nsIReferrerInfo.SAME_ORIGIN,
url: "https://test.example/foo?a",
referrer: "https://foo.example/foo?a",
expectedReferrerSpec: undefined,
},
{
policy: nsIHttpChannel.REFERRER_POLICY_SAME_ORIGIN,
policy: nsIReferrerInfo.SAME_ORIGIN,
trimmingPolicy: 1,
url: "https://test.example/foo?a",
referrer: "https://test.example/foo?a",
expectedReferrerSpec: "https://test.example/foo",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_SAME_ORIGIN,
policy: nsIReferrerInfo.SAME_ORIGIN,
trimmingPolicy: 1,
url: "https://test.example/foo?a",
referrer: "https://foo.example/foo?a",
expectedReferrerSpec: undefined,
},
{
policy: nsIHttpChannel.REFERRER_POLICY_SAME_ORIGIN,
policy: nsIReferrerInfo.SAME_ORIGIN,
trimmingPolicy: 2,
url: "https://test.example/foo?a",
referrer: "https://test.example/foo?a",
expectedReferrerSpec: "https://test.example/",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_SAME_ORIGIN,
policy: nsIReferrerInfo.SAME_ORIGIN,
trimmingPolicy: 2,
url: "https://test.example/foo?a",
referrer: "https://foo.example/foo?a",
@ -104,68 +104,68 @@ var gTests = [
// Test origin when xorigin policy w/o cross origin
{
policy: nsIHttpChannel.REFERRER_POLICY_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.ORIGIN_WHEN_CROSS_ORIGIN,
url: "https://test.example/foo?a",
referrer: "https://test.example/foo?a",
expectedReferrerSpec: "https://test.example/foo?a",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.ORIGIN_WHEN_CROSS_ORIGIN,
url: "https://test.example/foo?a",
referrer: "https://foo.example/foo?a",
expectedReferrerSpec: "https://foo.example/",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.ORIGIN_WHEN_CROSS_ORIGIN,
trimmingPolicy: 1,
url: "https://test.example/foo?a",
referrer: "https://test.example/foo?a",
expectedReferrerSpec: "https://test.example/foo",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.ORIGIN_WHEN_CROSS_ORIGIN,
trimmingPolicy: 1,
url: "https://test.example/foo?a",
referrer: "https://foo.example/foo?a",
expectedReferrerSpec: "https://foo.example/",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.ORIGIN_WHEN_CROSS_ORIGIN,
trimmingPolicy: 2,
url: "https://test.example/foo?a",
referrer: "https://test.example/foo?a",
expectedReferrerSpec: "https://test.example/",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.ORIGIN_WHEN_CROSS_ORIGIN,
trimmingPolicy: 2,
url: "https://test.example/foo?a",
referrer: "https://foo.example/foo?a",
expectedReferrerSpec: "https://foo.example/",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.ORIGIN_WHEN_CROSS_ORIGIN,
XOriginTrimmingPolicy: 1,
url: "https://test.example/foo?a",
referrer: "https://test.example/foo?a",
expectedReferrerSpec: "https://test.example/foo?a",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.ORIGIN_WHEN_CROSS_ORIGIN,
XOriginTrimmingPolicy: 1,
url: "https://test.example/foo?a",
referrer: "https://foo.example/foo?a",
expectedReferrerSpec: "https://foo.example/",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.ORIGIN_WHEN_CROSS_ORIGIN,
XOriginTrimmingPolicy: 2,
url: "https://test.example/foo?a",
referrer: "https://test.example/foo?a",
expectedReferrerSpec: "https://test.example/foo?a",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.ORIGIN_WHEN_CROSS_ORIGIN,
XOriginTrimmingPolicy: 2,
url: "https://test.example/foo?a",
referrer: "https://foo.example/foo?a",
@ -174,102 +174,102 @@ var gTests = [
// Test strict origin when xorigin policy w/o cross origin
{
policy: nsIHttpChannel.REFERRER_POLICY_STRICT_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,
url: "https://test.example/foo?a",
referrer: "https://test.example/foo?a",
expectedReferrerSpec: "https://test.example/foo?a",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_STRICT_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,
url: "https://test.example/foo?a",
referrer: "https://foo.example/foo?a",
expectedReferrerSpec: "https://foo.example/",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_STRICT_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,
url: "http://test.example/foo?a",
referrer: "https://foo.example/foo?a",
expectedReferrerSpec: undefined,
},
{
policy: nsIHttpChannel.REFERRER_POLICY_STRICT_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,
trimmingPolicy: 1,
url: "https://test.example/foo?a",
referrer: "https://test.example/foo?a",
expectedReferrerSpec: "https://test.example/foo",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_STRICT_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,
trimmingPolicy: 1,
url: "https://test.example/foo?a",
referrer: "https://foo.example/foo?a",
expectedReferrerSpec: "https://foo.example/",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_STRICT_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,
trimmingPolicy: 1,
url: "http://test.example/foo?a",
referrer: "https://foo.example/foo?a",
expectedReferrerSpec: undefined,
},
{
policy: nsIHttpChannel.REFERRER_POLICY_STRICT_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,
trimmingPolicy: 2,
url: "https://test.example/foo?a",
referrer: "https://test.example/foo?a",
expectedReferrerSpec: "https://test.example/",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_STRICT_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,
trimmingPolicy: 2,
url: "https://test.example/foo?a",
referrer: "https://foo.example/foo?a",
expectedReferrerSpec: "https://foo.example/",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_STRICT_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,
trimmingPolicy: 2,
url: "http://test.example/foo?a",
referrer: "https://foo.example/foo?a",
expectedReferrerSpec: undefined,
},
{
policy: nsIHttpChannel.REFERRER_POLICY_STRICT_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,
XOriginTrimmingPolicy: 1,
url: "https://test.example/foo?a",
referrer: "https://test.example/foo?a",
expectedReferrerSpec: "https://test.example/foo?a",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_STRICT_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,
XOriginTrimmingPolicy: 1,
url: "https://test.example/foo?a",
referrer: "https://foo.example/foo?a",
expectedReferrerSpec: "https://foo.example/",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_STRICT_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,
XOriginTrimmingPolicy: 1,
url: "http://test.example/foo?a",
referrer: "https://foo.example/foo?a",
expectedReferrerSpec: undefined,
},
{
policy: nsIHttpChannel.REFERRER_POLICY_STRICT_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,
XOriginTrimmingPolicy: 2,
url: "https://test.example/foo?a",
referrer: "https://test.example/foo?a",
expectedReferrerSpec: "https://test.example/foo?a",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_STRICT_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,
XOriginTrimmingPolicy: 2,
url: "https://test.example/foo?a",
referrer: "https://foo.example/foo?a",
expectedReferrerSpec: "https://foo.example/",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_STRICT_ORIGIN_WHEN_XORIGIN,
policy: nsIReferrerInfo.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,
XOriginTrimmingPolicy: 2,
url: "http://test.example/foo?a",
referrer: "https://foo.example/foo?a",
@ -278,7 +278,7 @@ var gTests = [
// Test mix and choose max of XOriginTrimmingPolicy and trimmingPolicy
{
policy: nsIHttpChannel.REFERRER_POLICY_UNSAFE_URL,
policy: nsIReferrerInfo.UNSAFE_URL,
XOriginTrimmingPolicy: 2,
trimmingPolicy: 1,
url: "https://test.example/foo?a",
@ -286,7 +286,7 @@ var gTests = [
expectedReferrerSpec: "https://test1.example/",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_UNSAFE_URL,
policy: nsIReferrerInfo.UNSAFE_URL,
XOriginTrimmingPolicy: 2,
trimmingPolicy: 1,
url: "https://test.example/foo?a",
@ -294,7 +294,7 @@ var gTests = [
expectedReferrerSpec: "https://test.example/foo",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_UNSAFE_URL,
policy: nsIReferrerInfo.UNSAFE_URL,
XOriginTrimmingPolicy: 1,
trimmingPolicy: 2,
url: "https://test.example/foo?a",
@ -302,7 +302,7 @@ var gTests = [
expectedReferrerSpec: "https://test.example/",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_UNSAFE_URL,
policy: nsIReferrerInfo.UNSAFE_URL,
XOriginTrimmingPolicy: 1,
trimmingPolicy: 0,
url: "https://test.example/foo?a",

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

@ -40,96 +40,96 @@ function test_policy(test) {
}
}
const nsIHttpChannel = Ci.nsIHttpChannel;
const nsIReferrerInfo = Ci.nsIReferrerInfo;
// Assuming cross origin because we have no triggering principal available
var gTests = [
{
policy: nsIHttpChannel.REFERRER_POLICY_UNSET,
policy: nsIReferrerInfo.EMPTY,
defaultReferrerPolicyPref: 0,
url: "https://test.example/foo",
referrer: "https://test.example/referrer",
expectedReferrerSpec: undefined,
},
{
policy: nsIHttpChannel.REFERRER_POLICY_UNSET,
policy: nsIReferrerInfo.EMPTY,
defaultReferrerPolicyPref: 1,
url: "http://test.example/foo",
referrer: "http://test1.example/referrer",
expectedReferrerSpec: undefined,
},
{
policy: nsIHttpChannel.REFERRER_POLICY_UNSET,
policy: nsIReferrerInfo.EMPTY,
defaultReferrerPolicyPref: 2,
url: "https://sub1.\xe4lt.example/foo",
referrer: "https://sub1.\xe4lt.example/referrer",
expectedReferrerSpec: "https://sub1.xn--lt-uia.example/",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_UNSET,
policy: nsIReferrerInfo.EMPTY,
defaultReferrerPolicyPref: 2,
url: "https://test.example/foo",
referrer: "https://test1.example/referrer",
expectedReferrerSpec: "https://test1.example/",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_UNSET,
policy: nsIReferrerInfo.EMPTY,
defaultReferrerPolicyPref: 3,
url: "https://test.example/foo",
referrer: "https://test.example/referrer",
expectedReferrerSpec: "https://test.example/referrer",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_UNSET,
policy: nsIReferrerInfo.EMPTY,
defaultReferrerPolicyPref: 3,
url: "https://sub1.\xe4lt.example/foo",
referrer: "https://sub1.\xe4lt.example/referrer",
expectedReferrerSpec: "https://sub1.xn--lt-uia.example/referrer",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_UNSET,
policy: nsIReferrerInfo.EMPTY,
defaultReferrerPolicyPref: 3,
url: "http://test.example/foo",
referrer: "https://test.example/referrer",
expectedReferrerSpec: undefined,
},
{
policy: nsIHttpChannel.REFERRER_POLICY_NO_REFERRER,
policy: nsIReferrerInfo.NO_REFERRER,
url: "https://test.example/foo",
referrer: "https://test.example/referrer",
expectedReferrerSpec: undefined,
},
{
policy: nsIHttpChannel.REFERRER_POLICY_ORIGIN,
policy: nsIReferrerInfo.ORIGIN,
url: "https://test.example/foo",
referrer: "https://test.example/referrer",
expectedReferrerSpec: "https://test.example/",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_ORIGIN,
policy: nsIReferrerInfo.ORIGIN,
url: "https://sub1.\xe4lt.example/foo",
referrer: "https://sub1.\xe4lt.example/referrer",
expectedReferrerSpec: "https://sub1.xn--lt-uia.example/",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_UNSAFE_URL,
policy: nsIReferrerInfo.UNSAFE_URL,
url: "https://test.example/foo",
referrer: "https://test.example/referrer",
expectedReferrerSpec: "https://test.example/referrer",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_UNSAFE_URL,
policy: nsIReferrerInfo.UNSAFE_URL,
url: "https://sub1.\xe4lt.example/foo",
referrer: "https://sub1.\xe4lt.example/referrer",
expectedReferrerSpec: "https://sub1.xn--lt-uia.example/referrer",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_UNSAFE_URL,
policy: nsIReferrerInfo.UNSAFE_URL,
url: "http://test.example/foo",
referrer: "https://test.example/referrer",
expectedReferrerSpec: "https://test.example/referrer",
},
{
policy: nsIHttpChannel.REFERRER_POLICY_UNSAFE_URL,
policy: nsIReferrerInfo.UNSAFE_URL,
url: "http://sub1.\xe4lt.example/foo",
referrer: "https://sub1.\xe4lt.example/referrer",
expectedReferrerSpec: "https://sub1.xn--lt-uia.example/referrer",

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

@ -27,7 +27,7 @@ function run_test() {
Assert.equal(currentReferrer, "http://site1.com/");
let uri = Services.io.newURI("http://site2.com");
subject.referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
Ci.nsIReferrerInfo.EMPTY,
true,
uri
);

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

@ -376,7 +376,7 @@ add_task(async function test_windows_zoneInformation() {
function createReferrerInfo(
aReferrer,
aRefererPolicy = Ci.nsIHttpChannel.REFERRER_POLICY_UNSET
aRefererPolicy = Ci.nsIReferrerInfo.EMPTY
) {
return new ReferrerInfo(aRefererPolicy, true, NetUtil.newURI(aReferrer));
}
@ -400,7 +400,7 @@ add_task(async function test_windows_zoneInformation() {
options: {
referrerInfo: createReferrerInfo(
TEST_REFERRER_URL,
Ci.nsIHttpChannel.REFERRER_POLICY_UNSAFE_URL
Ci.nsIReferrerInfo.UNSAFE_URL
),
},
expectedZoneId:
@ -514,7 +514,7 @@ add_task(async function test_referrer() {
});
let download;
let referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSAFE_URL,
Ci.nsIReferrerInfo.UNSAFE_URL,
true,
NetUtil.newURI(TEST_REFERRER_URL)
);

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

@ -54,7 +54,7 @@ add_task(async function test_referrer_restart() {
);
let referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSAFE_URL,
Ci.nsIReferrerInfo.UNSAFE_URL,
true,
NetUtil.newURI(TEST_REFERRER_URL)
);

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

@ -49,7 +49,7 @@ add_task(async function test_save_reload() {
storeForSave.path
);
let referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
Ci.nsIReferrerInfo.EMPTY,
true,
NetUtil.newURI(TEST_REFERRER_URL)
);
@ -171,7 +171,7 @@ add_task(async function test_load_string_predefined() {
let sourceUriLiteral = JSON.stringify(httpUrl("source.txt"));
let emptyUriLiteral = JSON.stringify(httpUrl("empty.txt"));
let referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
Ci.nsIReferrerInfo.EMPTY,
true,
NetUtil.newURI(TEST_REFERRER_URL)
);
@ -307,7 +307,7 @@ add_task(async function test_save_reload_unknownProperties() {
listForSave.add(download2);
let referrerInfo = new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
Ci.nsIReferrerInfo.EMPTY,
true,
NetUtil.newURI(TEST_REFERRER_URL)
);

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

@ -134,7 +134,7 @@ var ReaderMode = {
triggeringPrincipal: principal,
loadFlags,
referrerInfo: new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
Ci.nsIReferrerInfo.EMPTY,
true,
referrerURI
),

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

@ -26,7 +26,7 @@ add_task(async function test_referrer() {
let loadURIOptionsWithReferrer = {
triggeringPrincipal: SYSTEMPRINCIPAL,
referrerInfo: new ReferrerInfo(
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
Ci.nsIReferrerInfo.EMPTY,
true,
Services.io.newURI(DUMMY2)
),

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

@ -38,7 +38,7 @@ const appRepURLPref = "browser.safebrowsing.downloads.remote.url";
function createReferrerInfo(
aURI,
aRefererPolicy = Ci.nsIHttpChannel.REFERRER_POLICY_NO_REFERRER
aRefererPolicy = Ci.nsIReferrerInfo.NO_REFERRER
) {
return new ReferrerInfo(aRefererPolicy, true, aURI);
}
@ -300,15 +300,15 @@ add_test(function test_local_blacklist() {
add_test(async function test_referer_blacklist() {
Services.prefs.setCharPref(appRepURLPref, "http://localhost:4444/download");
let testReferrerPolicies = [
Ci.nsIHttpChannel.REFERRER_POLICY_UNSET,
Ci.nsIHttpChannel.REFERRER_POLICY_NO_REFERRER,
Ci.nsIHttpChannel.REFERRER_POLICY_NO_REFERRER_WHEN_DOWNGRADE,
Ci.nsIHttpChannel.REFERRER_POLICY_ORIGIN,
Ci.nsIHttpChannel.REFERRER_POLICY_ORIGIN_WHEN_XORIGIN,
Ci.nsIHttpChannel.REFERRER_POLICY_UNSAFE_URL,
Ci.nsIHttpChannel.REFERRER_POLICY_SAME_ORIGIN,
Ci.nsIHttpChannel.REFERRER_POLICY_STRICT_ORIGIN,
Ci.nsIHttpChannel.REFERRER_POLICY_STRICT_ORIGIN_WHEN_XORIGIN,
Ci.nsIReferrerInfo.EMPTY,
Ci.nsIReferrerInfo.NO_REFERRER,
Ci.nsIReferrerInfo.NO_REFERRER_WHEN_DOWNGRADE,
Ci.nsIReferrerInfo.ORIGIN,
Ci.nsIReferrerInfo.ORIGIN_WHEN_CROSS_ORIGIN,
Ci.nsIReferrerInfo.UNSAFE_URL,
Ci.nsIReferrerInfo.SAME_ORIGIN,
Ci.nsIReferrerInfo.STRICT_ORIGIN,
Ci.nsIReferrerInfo.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,
];
function runReferrerPolicyTest(referrerPolicy) {