Skip to content

Commit

Permalink
Bug 1528697 - Remove ReferrerPolicy.h and add utils to ReferrerInfo r…
Browse files Browse the repository at this point in the history
…=ckerschb

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

--HG--
extra : moz-landing-system : lando
  • Loading branch information
Thomas Nguyen committed Aug 21, 2019
1 parent bbd6f51 commit cf20303
Show file tree
Hide file tree
Showing 17 changed files with 237 additions and 288 deletions.
8 changes: 3 additions & 5 deletions devtools/server/actors/network-monitor/network-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,11 +616,9 @@ NetworkObserver.prototype = {
event.fromServiceWorker = fromServiceWorker;
event.isThirdPartyTrackingResource = channel.isThirdPartyTrackingResource();
const referrerInfo = channel.referrerInfo;
event.referrerPolicy = Services.netUtils.getReferrerPolicyString(
referrerInfo
? referrerInfo.referrerPolicy
: Ci.nsIHttpChannel.REFERRER_POLICY_UNSET
);
event.referrerPolicy = referrerInfo
? referrerInfo.getReferrerPolicyString()
: "";
httpActivity.fromServiceWorker = fromServiceWorker;

if (extraStringData) {
Expand Down
2 changes: 1 addition & 1 deletion dom/base/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ class Document : public nsINode,
void UpdateReferrerInfoFromMeta(const nsAString& aMetaReferrer,
bool aPreload) {
ReferrerPolicyEnum policy =
mozilla::net::ReferrerPolicyFromString(aMetaReferrer);
ReferrerInfo::ReferrerPolicyFromMetaString(aMetaReferrer);
// The empty string "" corresponds to no referrer policy, causing a fallback
// to a referrer policy defined elsewhere.
if (policy == ReferrerPolicy::_empty) {
Expand Down
4 changes: 2 additions & 2 deletions dom/base/nsContentSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,8 @@ nsresult nsContentSink::ProcessStyleLinkFromHeader(

// Link header is working like a <link> node, so referrerPolicy attr should
// have higher priority than referrer policy from document.
net::ReferrerPolicy policy =
net::AttributeReferrerPolicyFromString(aReferrerPolicy);
ReferrerPolicy policy =
ReferrerInfo::ReferrerPolicyAttributeFromString(aReferrerPolicy);
nsCOMPtr<nsIReferrerInfo> referrerInfo =
ReferrerInfo::CreateFromDocumentAndPolicyOverride(mDocument, policy);

Expand Down
24 changes: 2 additions & 22 deletions dom/base/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7881,27 +7881,6 @@ bool nsContentUtils::IsUpgradableDisplayType(nsContentPolicyType aType) {
aType == nsIContentPolicy::TYPE_MEDIA);
}

// static
ReferrerPolicy nsContentUtils::GetReferrerPolicyFromHeader(
const nsAString& aHeader) {
// Multiple headers could be concatenated into one comma-separated
// list of policies. Need to tokenize the multiple headers.
nsCharSeparatedTokenizer tokenizer(aHeader, ',');
nsAutoString token;
ReferrerPolicy referrerPolicy = ReferrerPolicy::_empty;
while (tokenizer.hasMoreTokens()) {
token = tokenizer.nextToken();
if (token.IsEmpty()) {
continue;
}
ReferrerPolicy policy = net::ReferrerPolicyFromString(token);
if (policy != ReferrerPolicy::_empty) {
referrerPolicy = policy;
}
}
return referrerPolicy;
}

// static
ReferrerPolicy nsContentUtils::GetReferrerPolicyFromChannel(
nsIChannel* aChannel) {
Expand All @@ -7918,7 +7897,8 @@ ReferrerPolicy nsContentUtils::GetReferrerPolicyFromChannel(
return ReferrerPolicy::_empty;
}

return GetReferrerPolicyFromHeader(NS_ConvertUTF8toUTF16(headerValue));
return ReferrerInfo::ReferrerPolicyFromHeaderString(
NS_ConvertUTF8toUTF16(headerValue));
}

// static
Expand Down
10 changes: 0 additions & 10 deletions dom/base/nsContentUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2841,16 +2841,6 @@ class nsContentUtils {
static mozilla::dom::ReferrerPolicy GetReferrerPolicyFromChannel(
nsIChannel* aChannel);

/*
* Parse a referrer policy from a Referrer-Policy header
* https://www.w3.org/TR/referrer-policy/#parse-referrer-policy-from-header
*
* @param aHeader the response's Referrer-Policy header to parse
* @return referrer policy from the response header.
*/
static mozilla::dom::ReferrerPolicy GetReferrerPolicyFromHeader(
const nsAString& aHeader);

static bool IsNonSubresourceRequest(nsIChannel* aChannel);

static bool IsNonSubresourceInternalPolicyType(nsContentPolicyType aType);
Expand Down
44 changes: 24 additions & 20 deletions dom/html/nsGenericHTMLElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "nsIPrincipal.h"
#include "nsContainerFrame.h"
#include "nsStyleUtil.h"
#include "ReferrerInfo.h"

#include "mozilla/PresState.h"
#include "nsILayoutHistoryState.h"
Expand Down Expand Up @@ -100,7 +101,6 @@
#include "mozilla/dom/HTMLBodyElement.h"
#include "imgIContainer.h"
#include "nsComputedDOMStyle.h"
#include "ReferrerPolicy.h"
#include "mozilla/dom/HTMLLabelElement.h"
#include "mozilla/dom/HTMLInputElement.h"

Expand Down Expand Up @@ -1034,25 +1034,29 @@ bool nsGenericHTMLElement::ParseImageAttribute(nsAtom* aAttribute,

bool nsGenericHTMLElement::ParseReferrerAttribute(const nsAString& aString,
nsAttrValue& aResult) {
static const nsAttrValue::EnumTable kReferrerTable[] = {
{ReferrerPolicyToString(net::RP_No_Referrer),
static_cast<int16_t>(net::RP_No_Referrer)},
{ReferrerPolicyToString(net::RP_Origin),
static_cast<int16_t>(net::RP_Origin)},
{ReferrerPolicyToString(net::RP_Origin_When_Crossorigin),
static_cast<int16_t>(net::RP_Origin_When_Crossorigin)},
{ReferrerPolicyToString(net::RP_No_Referrer_When_Downgrade),
static_cast<int16_t>(net::RP_No_Referrer_When_Downgrade)},
{ReferrerPolicyToString(net::RP_Unsafe_URL),
static_cast<int16_t>(net::RP_Unsafe_URL)},
{ReferrerPolicyToString(net::RP_Strict_Origin),
static_cast<int16_t>(net::RP_Strict_Origin)},
{ReferrerPolicyToString(net::RP_Same_Origin),
static_cast<int16_t>(net::RP_Same_Origin)},
{ReferrerPolicyToString(net::RP_Strict_Origin_When_Cross_Origin),
static_cast<int16_t>(net::RP_Strict_Origin_When_Cross_Origin)},
{nullptr, 0}};
return aResult.ParseEnumValue(aString, kReferrerTable, false);
using mozilla::dom::ReferrerInfo;
static const nsAttrValue::EnumTable kReferrerPolicyTable[] = {
{ReferrerInfo::ReferrerPolicyToString(ReferrerPolicy::No_referrer),
static_cast<int16_t>(ReferrerPolicy::No_referrer)},
{ReferrerInfo::ReferrerPolicyToString(ReferrerPolicy::Origin),
static_cast<int16_t>(ReferrerPolicy::Origin)},
{ReferrerInfo::ReferrerPolicyToString(
ReferrerPolicy::Origin_when_cross_origin),
static_cast<int16_t>(ReferrerPolicy::Origin_when_cross_origin)},
{ReferrerInfo::ReferrerPolicyToString(
ReferrerPolicy::No_referrer_when_downgrade),
static_cast<int16_t>(ReferrerPolicy::No_referrer_when_downgrade)},
{ReferrerInfo::ReferrerPolicyToString(ReferrerPolicy::Unsafe_url),
static_cast<int16_t>(ReferrerPolicy::Unsafe_url)},
{ReferrerInfo::ReferrerPolicyToString(ReferrerPolicy::Strict_origin),
static_cast<int16_t>(ReferrerPolicy::Strict_origin)},
{ReferrerInfo::ReferrerPolicyToString(ReferrerPolicy::Same_origin),
static_cast<int16_t>(ReferrerPolicy::Same_origin)},
{ReferrerInfo::ReferrerPolicyToString(
ReferrerPolicy::Strict_origin_when_cross_origin),
static_cast<int16_t>(ReferrerPolicy::Strict_origin_when_cross_origin)},
{nullptr, ReferrerPolicy::_empty}};
return aResult.ParseEnumValue(aString, kReferrerPolicyTable, false);
}

bool nsGenericHTMLElement::ParseFrameborderValue(const nsAString& aString,
Expand Down
5 changes: 5 additions & 0 deletions dom/interfaces/security/nsIReferrerInfo.idl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ interface nsIReferrerInfo : nsISerializable
[noscript, notxpcom, nostdcall, binaryname(ReferrerPolicy)]
ReferrerPolicy binaryReferrerPolicy();

/**
* Get referrer policy as string
*/
ACString getReferrerPolicyString();

/**
* Indicates if the referrer should not be sent or not even when it's available.
*/
Expand Down
Loading

0 comments on commit cf20303

Please sign in to comment.