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.
nsAutoString 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_();
net::ReferrerPolicy net_referrerPolicy = net::RP_Unset;
net::ReferrerPolicy net_referrerPolicy = mRequest->GetEnvironmentReferrerPolicy();
switch (referrerPolicy) {
case ReferrerPolicy::_empty:
net_referrerPolicy = net::RP_Default;
break;
case ReferrerPolicy::No_referrer:
net_referrerPolicy = net::RP_No_Referrer;
@ -294,12 +298,10 @@ FetchDriver::HttpFetch()
rv = NS_NewURI(getter_AddRefs(referrerURI), referrer, nullptr, nullptr);
NS_ENSURE_SUCCESS(rv, rv);
uint32_t documentReferrerPolicy = mDocument ? mDocument->GetReferrerPolicy() :
net::RP_Default;
rv =
httpChan->SetReferrerWithPolicy(referrerURI,
referrerPolicy == ReferrerPolicy::_empty ?
documentReferrerPolicy :
mRequest->GetEnvironmentReferrerPolicy() :
net_referrerPolicy);
NS_ENSURE_SUCCESS(rv, rv);
}

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

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

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

@ -11,6 +11,7 @@
#include "mozilla/dom/InternalHeaders.h"
#include "mozilla/dom/RequestBinding.h"
#include "mozilla/LoadTainting.h"
#include "mozilla/net/ReferrerPolicy.h"
#include "nsIContentPolicy.h"
#include "nsIInputStream.h"
@ -95,6 +96,7 @@ public:
, mContentPolicyType(nsIContentPolicy::TYPE_FETCH)
, mReferrer(NS_LITERAL_STRING(kFETCH_CLIENT_REFERRER_STR))
, mReferrerPolicy(ReferrerPolicy::_empty)
, mEnvironmentReferrerPolicy(net::RP_Default)
, mMode(RequestMode::No_cors)
, mCredentialsMode(RequestCredentials::Omit)
, mResponseTainting(LoadTainting::Basic)
@ -132,6 +134,7 @@ public:
, mContentPolicyType(aContentPolicyType)
, mReferrer(aReferrer)
, mReferrerPolicy(aReferrerPolicy)
, mEnvironmentReferrerPolicy(net::RP_Default)
, mMode(aMode)
, mCredentialsMode(aRequestCredentials)
, mResponseTainting(LoadTainting::Basic)
@ -266,6 +269,18 @@ public:
mReferrerPolicy = aReferrerPolicy;
}
net::ReferrerPolicy
GetEnvironmentReferrerPolicy() const
{
return mEnvironmentReferrerPolicy;
}
void
SetEnvironmentReferrerPolicy(net::ReferrerPolicy aReferrerPolicy)
{
mEnvironmentReferrerPolicy = aReferrerPolicy;
}
bool
SkipServiceWorker() const
{
@ -492,6 +507,13 @@ private:
nsString mReferrer;
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;
RequestCredentials mCredentialsMode;
MOZ_INIT_OUTSIDE_CTOR LoadTainting mResponseTainting;

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

@ -413,6 +413,23 @@ Request::Constructor(const GlobalObject& aGlobal,
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_) {
request->ClearCreatedByFetchEvent();
request->SetMode(mode);