Bug 1251378 - Use referrer policy of worker instead of default. r=ehsan

MozReview-Commit-ID: I8X8nMkaS9V
This commit is contained in:
Thomas Nguyen 2016-04-01 11:52:28 +08:00
Родитель d9b3fe6291
Коммит 64fdf9d702
4 изменённых файлов: 48 добавлений и 5 удалений

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

@ -252,11 +252,15 @@ FetchDriver::HttpFetch()
// Step 2. Set the referrer. // Step 2. Set the referrer.
nsAutoString referrer; nsAutoString referrer;
mRequest->GetReferrer(referrer); mRequest->GetReferrer(referrer);
// The Referrer Policy in Request can be used to override a referrer policy
// associated with an environment settings object.
// If there's no Referrer Policy in the request, it should be inherited
// from environment.
ReferrerPolicy referrerPolicy = mRequest->ReferrerPolicy_(); ReferrerPolicy referrerPolicy = mRequest->ReferrerPolicy_();
net::ReferrerPolicy net_referrerPolicy = net::RP_Unset; net::ReferrerPolicy net_referrerPolicy = mRequest->GetEnvironmentReferrerPolicy();
switch (referrerPolicy) { switch (referrerPolicy) {
case ReferrerPolicy::_empty: case ReferrerPolicy::_empty:
net_referrerPolicy = net::RP_Default;
break; break;
case ReferrerPolicy::No_referrer: case ReferrerPolicy::No_referrer:
net_referrerPolicy = net::RP_No_Referrer; net_referrerPolicy = net::RP_No_Referrer;
@ -294,12 +298,10 @@ FetchDriver::HttpFetch()
rv = NS_NewURI(getter_AddRefs(referrerURI), referrer, nullptr, nullptr); rv = NS_NewURI(getter_AddRefs(referrerURI), referrer, nullptr, nullptr);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
uint32_t documentReferrerPolicy = mDocument ? mDocument->GetReferrerPolicy() :
net::RP_Default;
rv = rv =
httpChan->SetReferrerWithPolicy(referrerURI, httpChan->SetReferrerWithPolicy(referrerURI,
referrerPolicy == ReferrerPolicy::_empty ? referrerPolicy == ReferrerPolicy::_empty ?
documentReferrerPolicy : mRequest->GetEnvironmentReferrerPolicy() :
net_referrerPolicy); net_referrerPolicy);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }

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

@ -40,6 +40,7 @@ InternalRequest::GetRequestConstructorCopy(nsIGlobalObject* aGlobal, ErrorResult
copy->mPreserveContentCodings = true; copy->mPreserveContentCodings = true;
// The default referrer is already about:client. // The default referrer is already about:client.
copy->mReferrerPolicy = mReferrerPolicy; copy->mReferrerPolicy = mReferrerPolicy;
copy->mEnvironmentReferrerPolicy = mEnvironmentReferrerPolicy;
copy->mContentPolicyType = mContentPolicyTypeOverridden ? copy->mContentPolicyType = mContentPolicyTypeOverridden ?
mContentPolicyType : mContentPolicyType :
@ -84,6 +85,7 @@ InternalRequest::InternalRequest(const InternalRequest& aOther)
, mContentPolicyType(aOther.mContentPolicyType) , mContentPolicyType(aOther.mContentPolicyType)
, mReferrer(aOther.mReferrer) , mReferrer(aOther.mReferrer)
, mReferrerPolicy(aOther.mReferrerPolicy) , mReferrerPolicy(aOther.mReferrerPolicy)
, mEnvironmentReferrerPolicy(aOther.mEnvironmentReferrerPolicy)
, mMode(aOther.mMode) , mMode(aOther.mMode)
, mCredentialsMode(aOther.mCredentialsMode) , mCredentialsMode(aOther.mCredentialsMode)
, mResponseTainting(aOther.mResponseTainting) , mResponseTainting(aOther.mResponseTainting)

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

@ -11,6 +11,7 @@
#include "mozilla/dom/InternalHeaders.h" #include "mozilla/dom/InternalHeaders.h"
#include "mozilla/dom/RequestBinding.h" #include "mozilla/dom/RequestBinding.h"
#include "mozilla/LoadTainting.h" #include "mozilla/LoadTainting.h"
#include "mozilla/net/ReferrerPolicy.h"
#include "nsIContentPolicy.h" #include "nsIContentPolicy.h"
#include "nsIInputStream.h" #include "nsIInputStream.h"
@ -95,6 +96,7 @@ public:
, mContentPolicyType(nsIContentPolicy::TYPE_FETCH) , mContentPolicyType(nsIContentPolicy::TYPE_FETCH)
, mReferrer(NS_LITERAL_STRING(kFETCH_CLIENT_REFERRER_STR)) , mReferrer(NS_LITERAL_STRING(kFETCH_CLIENT_REFERRER_STR))
, mReferrerPolicy(ReferrerPolicy::_empty) , mReferrerPolicy(ReferrerPolicy::_empty)
, mEnvironmentReferrerPolicy(net::RP_Default)
, mMode(RequestMode::No_cors) , mMode(RequestMode::No_cors)
, mCredentialsMode(RequestCredentials::Omit) , mCredentialsMode(RequestCredentials::Omit)
, mResponseTainting(LoadTainting::Basic) , mResponseTainting(LoadTainting::Basic)
@ -132,6 +134,7 @@ public:
, mContentPolicyType(aContentPolicyType) , mContentPolicyType(aContentPolicyType)
, mReferrer(aReferrer) , mReferrer(aReferrer)
, mReferrerPolicy(aReferrerPolicy) , mReferrerPolicy(aReferrerPolicy)
, mEnvironmentReferrerPolicy(net::RP_Default)
, mMode(aMode) , mMode(aMode)
, mCredentialsMode(aRequestCredentials) , mCredentialsMode(aRequestCredentials)
, mResponseTainting(LoadTainting::Basic) , mResponseTainting(LoadTainting::Basic)
@ -266,6 +269,18 @@ public:
mReferrerPolicy = aReferrerPolicy; mReferrerPolicy = aReferrerPolicy;
} }
net::ReferrerPolicy
GetEnvironmentReferrerPolicy() const
{
return mEnvironmentReferrerPolicy;
}
void
SetEnvironmentReferrerPolicy(net::ReferrerPolicy aReferrerPolicy)
{
mEnvironmentReferrerPolicy = aReferrerPolicy;
}
bool bool
SkipServiceWorker() const SkipServiceWorker() const
{ {
@ -492,6 +507,13 @@ private:
nsString mReferrer; nsString mReferrer;
ReferrerPolicy mReferrerPolicy; ReferrerPolicy mReferrerPolicy;
// This will be used for request created from Window or Worker contexts
// In case there's no Referrer Policy in Request, this will be passed to
// channel.
// The Environment Referrer Policy should be net::ReferrerPolicy so that it
// could be associated with nsIHttpChannel.
net::ReferrerPolicy mEnvironmentReferrerPolicy;
RequestMode mMode; RequestMode mMode;
RequestCredentials mCredentialsMode; RequestCredentials mCredentialsMode;
MOZ_INIT_OUTSIDE_CTOR LoadTainting mResponseTainting; MOZ_INIT_OUTSIDE_CTOR LoadTainting mResponseTainting;

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

@ -413,6 +413,23 @@ Request::Constructor(const GlobalObject& aGlobal,
request->SetReferrerPolicy(aInit.mReferrerPolicy.Value()); request->SetReferrerPolicy(aInit.mReferrerPolicy.Value());
} }
if (NS_IsMainThread()) {
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(global);
if (window) {
nsCOMPtr<nsIDocument> doc;
doc = window->GetExtantDoc();
if (doc) {
request->SetEnvironmentReferrerPolicy(doc->GetReferrerPolicy());
}
}
} else {
workers::WorkerPrivate* worker = workers::GetCurrentThreadWorkerPrivate();
if (worker) {
worker->AssertIsOnWorkerThread();
request->SetEnvironmentReferrerPolicy(worker->GetReferrerPolicy());
}
}
if (mode != RequestMode::EndGuard_) { if (mode != RequestMode::EndGuard_) {
request->ClearCreatedByFetchEvent(); request->ClearCreatedByFetchEvent();
request->SetMode(mode); request->SetMode(mode);