зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1340654 P1 Set referrer policy in service workers. r=baku
This commit is contained in:
Родитель
5a378c4750
Коммит
e070aa7b47
|
@ -476,6 +476,7 @@ private:
|
|||
UniquePtr<PrincipalInfo> mPrincipalInfo;
|
||||
nsCString mCSPHeaderValue;
|
||||
nsCString mCSPReportOnlyHeaderValue;
|
||||
nsCString mReferrerPolicyHeaderValue;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(CacheScriptLoader, nsIStreamLoaderObserver)
|
||||
|
@ -1160,6 +1161,9 @@ private:
|
|||
tCspROHeaderValue);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
mWorkerPrivate->SetReferrerPolicyFromHeaderValue(tRPHeaderCValue);
|
||||
|
||||
WorkerPrivate* parent = mWorkerPrivate->GetParent();
|
||||
if (parent) {
|
||||
// XHR Params Allowed
|
||||
|
@ -1167,16 +1171,6 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
NS_ConvertUTF8toUTF16 tRPHeaderValue(tRPHeaderCValue);
|
||||
// If there's a Referrer-Policy header, apply it.
|
||||
if (!tRPHeaderValue.IsEmpty()) {
|
||||
net::ReferrerPolicy policy =
|
||||
nsContentUtils::GetReferrerPolicyFromHeader(tRPHeaderValue);
|
||||
if (policy != net::RP_Unset) {
|
||||
mWorkerPrivate->SetReferrerPolicy(policy);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1186,7 +1180,8 @@ private:
|
|||
const mozilla::dom::ChannelInfo& aChannelInfo,
|
||||
UniquePtr<PrincipalInfo> aPrincipalInfo,
|
||||
const nsACString& aCSPHeaderValue,
|
||||
const nsACString& aCSPReportOnlyHeaderValue)
|
||||
const nsACString& aCSPReportOnlyHeaderValue,
|
||||
const nsACString& aReferrerPolicyHeaderValue)
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
MOZ_ASSERT(aIndex < mLoadInfos.Length());
|
||||
|
@ -1252,6 +1247,8 @@ private:
|
|||
rv = mWorkerPrivate->SetCSPFromHeaderValues(aCSPHeaderValue,
|
||||
aCSPReportOnlyHeaderValue);
|
||||
MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
mWorkerPrivate->SetReferrerPolicyFromHeaderValue(aReferrerPolicyHeaderValue);
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
@ -1667,6 +1664,8 @@ CacheScriptLoader::ResolvedCallback(JSContext* aCx,
|
|||
mCSPHeaderValue, ignored);
|
||||
headers->Get(NS_LITERAL_CSTRING("content-security-policy-report-only"),
|
||||
mCSPReportOnlyHeaderValue, ignored);
|
||||
headers->Get(NS_LITERAL_CSTRING("referrer-policy"),
|
||||
mReferrerPolicyHeaderValue, ignored);
|
||||
|
||||
nsCOMPtr<nsIInputStream> inputStream;
|
||||
response->GetBody(getter_AddRefs(inputStream));
|
||||
|
@ -1680,7 +1679,8 @@ CacheScriptLoader::ResolvedCallback(JSContext* aCx,
|
|||
mLoadInfo.mCacheStatus = ScriptLoadInfo::Cached;
|
||||
mRunnable->DataReceivedFromCache(mIndex, (uint8_t*)"", 0, mChannelInfo,
|
||||
Move(mPrincipalInfo), mCSPHeaderValue,
|
||||
mCSPReportOnlyHeaderValue);
|
||||
mCSPReportOnlyHeaderValue,
|
||||
mReferrerPolicyHeaderValue);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1741,7 +1741,8 @@ CacheScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader, nsISupports* aCont
|
|||
MOZ_ASSERT(mPrincipalInfo);
|
||||
mRunnable->DataReceivedFromCache(mIndex, aString, aStringLen, mChannelInfo,
|
||||
Move(mPrincipalInfo), mCSPHeaderValue,
|
||||
mCSPReportOnlyHeaderValue);
|
||||
mCSPReportOnlyHeaderValue,
|
||||
mReferrerPolicyHeaderValue);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -2691,6 +2691,26 @@ WorkerPrivateParent<Derived>::SetCSPFromHeaderValues(const nsACString& aCSPHeade
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
template <class Derived>
|
||||
void
|
||||
WorkerPrivateParent<Derived>::SetReferrerPolicyFromHeaderValue(
|
||||
const nsACString& aReferrerPolicyHeaderValue)
|
||||
{
|
||||
NS_ConvertUTF8toUTF16 headerValue(aReferrerPolicyHeaderValue);
|
||||
|
||||
if (headerValue.IsEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
net::ReferrerPolicy policy =
|
||||
nsContentUtils::GetReferrerPolicyFromHeader(headerValue);
|
||||
if (policy == net::RP_Unset) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetReferrerPolicy(policy);
|
||||
}
|
||||
|
||||
|
||||
// Can't use NS_IMPL_CYCLE_COLLECTION_CLASS(WorkerPrivateParent) because of the
|
||||
// templates.
|
||||
|
|
|
@ -706,6 +706,9 @@ public:
|
|||
SetCSPFromHeaderValues(const nsACString& aCSPHeaderValue,
|
||||
const nsACString& aCSPReportOnlyHeaderValue);
|
||||
|
||||
void
|
||||
SetReferrerPolicyFromHeaderValue(const nsACString& aReferrerPolicyHeaderValue);
|
||||
|
||||
net::ReferrerPolicy
|
||||
GetReferrerPolicy() const
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче