mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
f855ceaa31
- Bug 1163826 - Add remainder of top .jp sites to CSS unprefixing service whitelist. r=dholbert (8ed22f2638) - Bug 1165834: Add alicdn.com (used by taobao.com) to the CSS Unprefixing Service whitelist. r=miketaylr (30d150c28c) - Bug 1166792 - Add 3rd batch of top .jp sites to CSS unprefixing service whitelists. r=dholbert (e4073c1f09) - Bug 1170375 - Add 4th batch of top .jp sites to CSS unprefixing service whitelists. r=dholbert (d741e57cb0) - Bug 1207850 - Temporary fix for canceling the pump used by FetchBody. r=nsm (bc85cb1500) - Bug 1224865: Don't set a document in FetchDriver for requests in workers. r=bkelly (7bcb0bd16b) - Bug 1108181 - Make Headers iterable; r=bzbarsky (da8d6f8bb2) - Bug 1217501 P5 Relax guard checking on Headers with existing headers. r=ehsan (75ec3b6ae5) - Bug 1207882 - Use a separate build target for config/buildid. r=gps (ad9f536aac) - Bug 1216697 - Unship Request.cache until the implementation is finished; r=bzbarsky (49264a21d8) - Bug 1218119 - Simplify defining worker prefs; r=baku (8987aa23c3) - namespace (d88c3b7fc6) - Bug 1179489 - Don't count service workers towards an origin's max worker quota; r=nsm (ce5e1345ba) - Bug 1151646 - Cleanup, r=khuey. (d119d19ea7) - Bug 1118778 - Write upload properties from upload.py; r=glandium (f8745ffda8) - Bug 1194741 - Display upload output; r=nalexander (7adaa41d11) - Bug 1197293 - allow for TC builds that don't use 'make upload'; r=ted (e671e7c651) - Bug 1137000 - Add support for SDK building to moz-automation.mk. r=mshal (69b7ccb3c8) - Bug 1175895 - aid greppability of MOZ_AUTOMATION_*; r=ted (c9a099f168) - Bug 1198179 - Kill gen_mach_buildprops.py; r=ted (fa74e1930f) - Bug 1198179 - make upload.py write properties even if not uploading; r=ted (e7ca79b807) - Bug 8623031 - Move desktop build logic to a container neutral location; r=dustin (81dc866373) - Bug 1187139 (part 1) - Replace nsBaseHashtable::Enumerate() calls in accessible/ with iterators. r=tbsaunde. (7a75c73d17) - Bug 1187139 (part 2) - Replace nsBaseHashtable::Enumerate() calls in accessible/ with iterators. r=tbsaunde. (c631350ddb) - Bug 1187139 (part 3) - Replace nsBaseHashtable::Enumerate() calls in accessible/ with iterators. r=tbsaunde. (052cced2ca) - Bug 1225396 part 4 - Remove @@iterator workaround in Codegen.py. r=bz (3b05ddc4f0) - Bug 1048695 part 1. Pass the set of globals where a member should NOT be exposed to MemberCondition. r=peterv (d5c9040323) - Bug 1048695 part 2. Make interface members not be exposed based on their nonExposedGlobals. r=peterv (e852319bd0) - Bug 1229493 - Stop shell-only modules classes being reported as standard classes r=shu (4a6457af8d) - Bug 1151646 - Fix static analysis bustage. (347564b4d2) - Bug 1231051 - Moz2Dify nsNativeThemeCocoa::DrawWidgetBackground. r=mstange. (cbcbe17e30) - Bug 1178984 - Crashes at nsMenuBarX::RemoveMenuAtIndex. r=spohl (6e5869ae28) - leftovers of Bug 1151345 - Add debug logging to help decipher this bug. r=spohl (22d42fc66d)
369 lines
9.2 KiB
C++
369 lines
9.2 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "mozilla/dom/InternalHeaders.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
|
#include "nsContentUtils.h"
|
|
#include "nsNetUtil.h"
|
|
#include "nsReadableUtils.h"
|
|
|
|
namespace mozilla {
|
|
namespace dom {
|
|
|
|
InternalHeaders::InternalHeaders(const nsTArray<Entry>&& aHeaders,
|
|
HeadersGuardEnum aGuard)
|
|
: mGuard(aGuard)
|
|
, mList(aHeaders)
|
|
{
|
|
}
|
|
|
|
void
|
|
InternalHeaders::Append(const nsACString& aName, const nsACString& aValue,
|
|
ErrorResult& aRv)
|
|
{
|
|
nsAutoCString lowerName;
|
|
ToLowerCase(aName, lowerName);
|
|
|
|
if (IsInvalidMutableHeader(lowerName, aValue, aRv)) {
|
|
return;
|
|
}
|
|
|
|
mList.AppendElement(Entry(lowerName, aValue));
|
|
}
|
|
|
|
void
|
|
InternalHeaders::Delete(const nsACString& aName, ErrorResult& aRv)
|
|
{
|
|
nsAutoCString lowerName;
|
|
ToLowerCase(aName, lowerName);
|
|
|
|
if (IsInvalidMutableHeader(lowerName, aRv)) {
|
|
return;
|
|
}
|
|
|
|
// remove in reverse order to minimize copying
|
|
for (int32_t i = mList.Length() - 1; i >= 0; --i) {
|
|
if (lowerName == mList[i].mName) {
|
|
mList.RemoveElementAt(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
InternalHeaders::Get(const nsACString& aName, nsCString& aValue, ErrorResult& aRv) const
|
|
{
|
|
nsAutoCString lowerName;
|
|
ToLowerCase(aName, lowerName);
|
|
|
|
if (IsInvalidName(lowerName, aRv)) {
|
|
return;
|
|
}
|
|
|
|
for (uint32_t i = 0; i < mList.Length(); ++i) {
|
|
if (lowerName == mList[i].mName) {
|
|
aValue = mList[i].mValue;
|
|
return;
|
|
}
|
|
}
|
|
|
|
// No value found, so return null to content
|
|
aValue.SetIsVoid(true);
|
|
}
|
|
|
|
void
|
|
InternalHeaders::GetAll(const nsACString& aName, nsTArray<nsCString>& aResults,
|
|
ErrorResult& aRv) const
|
|
{
|
|
nsAutoCString lowerName;
|
|
ToLowerCase(aName, lowerName);
|
|
|
|
if (IsInvalidName(lowerName, aRv)) {
|
|
return;
|
|
}
|
|
|
|
aResults.SetLength(0);
|
|
for (uint32_t i = 0; i < mList.Length(); ++i) {
|
|
if (lowerName == mList[i].mName) {
|
|
aResults.AppendElement(mList[i].mValue);
|
|
}
|
|
}
|
|
}
|
|
|
|
bool
|
|
InternalHeaders::Has(const nsACString& aName, ErrorResult& aRv) const
|
|
{
|
|
nsAutoCString lowerName;
|
|
ToLowerCase(aName, lowerName);
|
|
|
|
if (IsInvalidName(lowerName, aRv)) {
|
|
return false;
|
|
}
|
|
|
|
for (uint32_t i = 0; i < mList.Length(); ++i) {
|
|
if (lowerName == mList[i].mName) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void
|
|
InternalHeaders::Set(const nsACString& aName, const nsACString& aValue, ErrorResult& aRv)
|
|
{
|
|
nsAutoCString lowerName;
|
|
ToLowerCase(aName, lowerName);
|
|
|
|
if (IsInvalidMutableHeader(lowerName, aValue, aRv)) {
|
|
return;
|
|
}
|
|
|
|
int32_t firstIndex = INT32_MAX;
|
|
|
|
// remove in reverse order to minimize copying
|
|
for (int32_t i = mList.Length() - 1; i >= 0; --i) {
|
|
if (lowerName == mList[i].mName) {
|
|
firstIndex = std::min(firstIndex, i);
|
|
mList.RemoveElementAt(i);
|
|
}
|
|
}
|
|
|
|
if (firstIndex < INT32_MAX) {
|
|
Entry* entry = mList.InsertElementAt(firstIndex);
|
|
entry->mName = lowerName;
|
|
entry->mValue = aValue;
|
|
} else {
|
|
mList.AppendElement(Entry(lowerName, aValue));
|
|
}
|
|
}
|
|
|
|
void
|
|
InternalHeaders::Clear()
|
|
{
|
|
mList.Clear();
|
|
}
|
|
|
|
void
|
|
InternalHeaders::SetGuard(HeadersGuardEnum aGuard, ErrorResult& aRv)
|
|
{
|
|
// The guard is only checked during ::Set() and ::Append() in the spec. It
|
|
// does not require revalidating headers already set.
|
|
mGuard = aGuard;
|
|
}
|
|
|
|
InternalHeaders::~InternalHeaders()
|
|
{
|
|
}
|
|
|
|
// static
|
|
bool
|
|
InternalHeaders::IsSimpleHeader(const nsACString& aName, const nsACString& aValue)
|
|
{
|
|
// Note, we must allow a null content-type value here to support
|
|
// get("content-type"), but the IsInvalidValue() check will prevent null
|
|
// from being set or appended.
|
|
return aName.EqualsLiteral("accept") ||
|
|
aName.EqualsLiteral("accept-language") ||
|
|
aName.EqualsLiteral("content-language") ||
|
|
(aName.EqualsLiteral("content-type") &&
|
|
nsContentUtils::IsAllowedNonCorsContentType(aValue));
|
|
}
|
|
|
|
//static
|
|
bool
|
|
InternalHeaders::IsInvalidName(const nsACString& aName, ErrorResult& aRv)
|
|
{
|
|
if (!NS_IsValidHTTPToken(aName)) {
|
|
NS_ConvertUTF8toUTF16 label(aName);
|
|
aRv.ThrowTypeError<MSG_INVALID_HEADER_NAME>(label);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
// static
|
|
bool
|
|
InternalHeaders::IsInvalidValue(const nsACString& aValue, ErrorResult& aRv)
|
|
{
|
|
if (!NS_IsReasonableHTTPHeaderValue(aValue)) {
|
|
NS_ConvertUTF8toUTF16 label(aValue);
|
|
aRv.ThrowTypeError<MSG_INVALID_HEADER_VALUE>(label);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool
|
|
InternalHeaders::IsImmutable(ErrorResult& aRv) const
|
|
{
|
|
if (mGuard == HeadersGuardEnum::Immutable) {
|
|
aRv.ThrowTypeError<MSG_HEADERS_IMMUTABLE>();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool
|
|
InternalHeaders::IsForbiddenRequestHeader(const nsACString& aName) const
|
|
{
|
|
return mGuard == HeadersGuardEnum::Request &&
|
|
nsContentUtils::IsForbiddenRequestHeader(aName);
|
|
}
|
|
|
|
bool
|
|
InternalHeaders::IsForbiddenRequestNoCorsHeader(const nsACString& aName) const
|
|
{
|
|
return mGuard == HeadersGuardEnum::Request_no_cors &&
|
|
!IsSimpleHeader(aName, EmptyCString());
|
|
}
|
|
|
|
bool
|
|
InternalHeaders::IsForbiddenRequestNoCorsHeader(const nsACString& aName,
|
|
const nsACString& aValue) const
|
|
{
|
|
return mGuard == HeadersGuardEnum::Request_no_cors &&
|
|
!IsSimpleHeader(aName, aValue);
|
|
}
|
|
|
|
bool
|
|
InternalHeaders::IsForbiddenResponseHeader(const nsACString& aName) const
|
|
{
|
|
return mGuard == HeadersGuardEnum::Response &&
|
|
nsContentUtils::IsForbiddenResponseHeader(aName);
|
|
}
|
|
|
|
void
|
|
InternalHeaders::Fill(const InternalHeaders& aInit, ErrorResult& aRv)
|
|
{
|
|
const nsTArray<Entry>& list = aInit.mList;
|
|
for (uint32_t i = 0; i < list.Length() && !aRv.Failed(); ++i) {
|
|
const Entry& entry = list[i];
|
|
Append(entry.mName, entry.mValue, aRv);
|
|
}
|
|
}
|
|
|
|
void
|
|
InternalHeaders::Fill(const Sequence<Sequence<nsCString>>& aInit, ErrorResult& aRv)
|
|
{
|
|
for (uint32_t i = 0; i < aInit.Length() && !aRv.Failed(); ++i) {
|
|
const Sequence<nsCString>& tuple = aInit[i];
|
|
if (tuple.Length() != 2) {
|
|
aRv.ThrowTypeError<MSG_INVALID_HEADER_SEQUENCE>();
|
|
return;
|
|
}
|
|
Append(tuple[0], tuple[1], aRv);
|
|
}
|
|
}
|
|
|
|
void
|
|
InternalHeaders::Fill(const MozMap<nsCString>& aInit, ErrorResult& aRv)
|
|
{
|
|
nsTArray<nsString> keys;
|
|
aInit.GetKeys(keys);
|
|
for (uint32_t i = 0; i < keys.Length() && !aRv.Failed(); ++i) {
|
|
Append(NS_ConvertUTF16toUTF8(keys[i]), aInit.Get(keys[i]), aRv);
|
|
}
|
|
}
|
|
|
|
bool
|
|
InternalHeaders::HasOnlySimpleHeaders() const
|
|
{
|
|
for (uint32_t i = 0; i < mList.Length(); ++i) {
|
|
if (!IsSimpleHeader(mList[i].mName, mList[i].mValue)) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// static
|
|
already_AddRefed<InternalHeaders>
|
|
InternalHeaders::BasicHeaders(InternalHeaders* aHeaders)
|
|
{
|
|
RefPtr<InternalHeaders> basic = new InternalHeaders(*aHeaders);
|
|
ErrorResult result;
|
|
// The Set-Cookie headers cannot be invalid mutable headers, so the Delete
|
|
// must succeed.
|
|
basic->Delete(NS_LITERAL_CSTRING("Set-Cookie"), result);
|
|
MOZ_ASSERT(!result.Failed());
|
|
basic->Delete(NS_LITERAL_CSTRING("Set-Cookie2"), result);
|
|
MOZ_ASSERT(!result.Failed());
|
|
return basic.forget();
|
|
}
|
|
|
|
// static
|
|
already_AddRefed<InternalHeaders>
|
|
InternalHeaders::CORSHeaders(InternalHeaders* aHeaders)
|
|
{
|
|
RefPtr<InternalHeaders> cors = new InternalHeaders(aHeaders->mGuard);
|
|
ErrorResult result;
|
|
|
|
nsAutoCString acExposedNames;
|
|
aHeaders->Get(NS_LITERAL_CSTRING("Access-Control-Expose-Headers"), acExposedNames, result);
|
|
MOZ_ASSERT(!result.Failed());
|
|
|
|
nsAutoTArray<nsCString, 5> exposeNamesArray;
|
|
nsCCharSeparatedTokenizer exposeTokens(acExposedNames, ',');
|
|
while (exposeTokens.hasMoreTokens()) {
|
|
const nsDependentCSubstring& token = exposeTokens.nextToken();
|
|
if (token.IsEmpty()) {
|
|
continue;
|
|
}
|
|
|
|
if (!NS_IsValidHTTPToken(token)) {
|
|
NS_WARNING("Got invalid HTTP token in Access-Control-Expose-Headers. Header value is:");
|
|
NS_WARNING(acExposedNames.get());
|
|
exposeNamesArray.Clear();
|
|
break;
|
|
}
|
|
|
|
exposeNamesArray.AppendElement(token);
|
|
}
|
|
|
|
nsCaseInsensitiveCStringArrayComparator comp;
|
|
for (uint32_t i = 0; i < aHeaders->mList.Length(); ++i) {
|
|
const Entry& entry = aHeaders->mList[i];
|
|
if (entry.mName.EqualsASCII("cache-control") ||
|
|
entry.mName.EqualsASCII("content-language") ||
|
|
entry.mName.EqualsASCII("content-type") ||
|
|
entry.mName.EqualsASCII("expires") ||
|
|
entry.mName.EqualsASCII("last-modified") ||
|
|
entry.mName.EqualsASCII("pragma") ||
|
|
exposeNamesArray.Contains(entry.mName, comp)) {
|
|
cors->Append(entry.mName, entry.mValue, result);
|
|
MOZ_ASSERT(!result.Failed());
|
|
}
|
|
}
|
|
|
|
return cors.forget();
|
|
}
|
|
|
|
void
|
|
InternalHeaders::GetEntries(nsTArray<InternalHeaders::Entry>& aEntries) const
|
|
{
|
|
MOZ_ASSERT(aEntries.IsEmpty());
|
|
aEntries.AppendElements(mList);
|
|
}
|
|
|
|
void
|
|
InternalHeaders::GetUnsafeHeaders(nsTArray<nsCString>& aNames) const
|
|
{
|
|
MOZ_ASSERT(aNames.IsEmpty());
|
|
for (uint32_t i = 0; i < mList.Length(); ++i) {
|
|
const Entry& header = mList[i];
|
|
if (!InternalHeaders::IsSimpleHeader(header.mName, header.mValue)) {
|
|
aNames.AppendElement(header.mName);
|
|
}
|
|
}
|
|
}
|
|
|
|
} // namespace dom
|
|
} // namespace mozilla
|