Bug 1414755 - Get rid of ContentPrincipalInfoOriginNoSuffix, r=bz, r=bkelly

This patch uses MozURL in ServiceWorkerRegistrar and in DBScheme to obtain the
origin of a URL. This is safe because the URL is always http/https/ftp.

It also changes the serialization of Principal in nsJSPrincipals in order to
pass the originNoSuffix together with the OriginAttributes and the spec.
This commit is contained in:
Andrea Marchesini 2017-11-15 11:19:26 +01:00
Родитель ed78be27fa
Коммит 155b15b8e0
7 изменённых файлов: 221 добавлений и 181 удалений

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

@ -124,9 +124,10 @@ nsJSPrincipals::ReadPrincipals(JSContext* aCx, JSStructuredCloneReader* aReader,
}
static bool
ReadSuffixAndSpec(JSStructuredCloneReader* aReader,
ReadPrincipalInfo(JSStructuredCloneReader* aReader,
OriginAttributes& aAttrs,
nsACString& aSpec)
nsACString& aSpec,
nsACString& aOriginNoSuffix)
{
uint32_t suffixLength, specLength;
if (!JS_ReadUint32Pair(aReader, &suffixLength, &specLength)) {
@ -154,6 +155,22 @@ ReadSuffixAndSpec(JSStructuredCloneReader* aReader,
return false;
}
uint32_t originNoSuffixLength, dummy;
if (!JS_ReadUint32Pair(aReader, &originNoSuffixLength, &dummy)) {
return false;
}
MOZ_ASSERT(dummy == 0);
if (!aOriginNoSuffix.SetLength(originNoSuffixLength, fallible)) {
return false;
}
if (!JS_ReadBytes(aReader, aOriginNoSuffix.BeginWriting(),
originNoSuffixLength)) {
return false;
}
return true;
}
@ -167,7 +184,8 @@ ReadPrincipalInfo(JSStructuredCloneReader* aReader,
} else if (aTag == SCTAG_DOM_NULL_PRINCIPAL) {
OriginAttributes attrs;
nsAutoCString spec;
if (!ReadSuffixAndSpec(aReader, attrs, spec)) {
nsAutoCString originNoSuffix;
if (!ReadPrincipalInfo(aReader, attrs, spec, originNoSuffix)) {
return false;
}
aInfo = NullPrincipalInfo(attrs, spec);
@ -196,11 +214,14 @@ ReadPrincipalInfo(JSStructuredCloneReader* aReader,
} else if (aTag == SCTAG_DOM_CONTENT_PRINCIPAL) {
OriginAttributes attrs;
nsAutoCString spec;
if (!ReadSuffixAndSpec(aReader, attrs, spec)) {
nsAutoCString originNoSuffix;
if (!ReadPrincipalInfo(aReader, attrs, spec, originNoSuffix)) {
return false;
}
aInfo = ContentPrincipalInfo(attrs, void_t(), spec);
MOZ_DIAGNOSTIC_ASSERT(!originNoSuffix.IsEmpty());
aInfo = ContentPrincipalInfo(attrs, originNoSuffix, spec);
} else {
MOZ_CRASH("unexpected principal structured clone tag");
}
@ -241,16 +262,20 @@ nsJSPrincipals::ReadKnownPrincipalType(JSContext* aCx,
}
static bool
WriteSuffixAndSpec(JSStructuredCloneWriter* aWriter,
WritePrincipalInfo(JSStructuredCloneWriter* aWriter,
const OriginAttributes& aAttrs,
const nsCString& aSpec)
const nsCString& aSpec,
const nsCString& aOriginNoSuffix)
{
nsAutoCString suffix;
aAttrs.CreateSuffix(suffix);
return JS_WriteUint32Pair(aWriter, suffix.Length(), aSpec.Length()) &&
JS_WriteBytes(aWriter, suffix.get(), suffix.Length()) &&
JS_WriteBytes(aWriter, aSpec.get(), aSpec.Length());
JS_WriteBytes(aWriter, aSpec.get(), aSpec.Length()) &&
JS_WriteUint32Pair(aWriter, aOriginNoSuffix.Length(), 0) &&
JS_WriteBytes(aWriter, aOriginNoSuffix.get(),
aOriginNoSuffix.Length());
}
static bool
@ -259,7 +284,8 @@ WritePrincipalInfo(JSStructuredCloneWriter* aWriter, const PrincipalInfo& aInfo)
if (aInfo.type() == PrincipalInfo::TNullPrincipalInfo) {
const NullPrincipalInfo& nullInfo = aInfo;
return JS_WriteUint32Pair(aWriter, SCTAG_DOM_NULL_PRINCIPAL, 0) &&
WriteSuffixAndSpec(aWriter, nullInfo.attrs(), nullInfo.spec());
WritePrincipalInfo(aWriter, nullInfo.attrs(), nullInfo.spec(),
EmptyCString());
}
if (aInfo.type() == PrincipalInfo::TSystemPrincipalInfo) {
return JS_WriteUint32Pair(aWriter, SCTAG_DOM_SYSTEM_PRINCIPAL, 0);
@ -282,7 +308,8 @@ WritePrincipalInfo(JSStructuredCloneWriter* aWriter, const PrincipalInfo& aInfo)
MOZ_ASSERT(aInfo.type() == PrincipalInfo::TContentPrincipalInfo);
const ContentPrincipalInfo& cInfo = aInfo;
return JS_WriteUint32Pair(aWriter, SCTAG_DOM_CONTENT_PRINCIPAL, 0) &&
WriteSuffixAndSpec(aWriter, cInfo.attrs(), cInfo.spec());
WritePrincipalInfo(aWriter, cInfo.attrs(), cInfo.spec(),
cInfo.originNoSuffix());
}
bool

18
dom/cache/DBSchema.cpp поставляемый
Просмотреть файл

@ -17,6 +17,7 @@
#include "mozilla/dom/cache/SavedTypes.h"
#include "mozilla/dom/cache/Types.h"
#include "mozilla/dom/cache/TypeUtils.h"
#include "mozilla/net/MozURL.h"
#include "mozIStorageConnection.h"
#include "mozIStorageStatement.h"
#include "mozStorageHelper.h"
@ -2114,8 +2115,23 @@ ReadResponse(mozIStorageConnection* aConn, EntryId aEntryId,
return NS_ERROR_FAILURE;
}
RefPtr<net::MozURL> url;
rv = net::MozURL::Init(getter_AddRefs(url), specNoSuffix);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
#ifdef DEBUG
nsCString scheme;
rv = url->GetScheme(scheme);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
MOZ_ASSERT(scheme == "http" || scheme == "https" || scheme == "file");
#endif
nsCString origin;
rv = url->GetOrigin(origin);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
aSavedResponseOut->mValue.principalInfo() =
mozilla::ipc::ContentPrincipalInfo(attrs, void_t(), specNoSuffix);
mozilla::ipc::ContentPrincipalInfo(attrs, origin, specNoSuffix);
}
bool nullPadding = false;

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

@ -45,8 +45,7 @@ ClientIsValidPrincipalInfo(const PrincipalInfo& aPrincipalInfo)
// Verify the principal originNoSuffix parses.
RefPtr<MozURL> originURL;
rv = MozURL::Init(getter_AddRefs(originURL),
content.originNoSuffix().get_nsCString());
rv = MozURL::Init(getter_AddRefs(originURL), content.originNoSuffix());
NS_ENSURE_SUCCESS(rv, false);
nsAutoCString originOrigin;
@ -98,8 +97,7 @@ ClientIsValidCreationURL(const PrincipalInfo& aPrincipalInfo,
// Parse the principal origin URL as well. This ensures any MozURL
// parser issues effect both URLs equally.
RefPtr<MozURL> principalURL;
rv = MozURL::Init(getter_AddRefs(principalURL),
content.originNoSuffix().get_nsCString());
rv = MozURL::Init(getter_AddRefs(principalURL), content.originNoSuffix());
NS_ENSURE_SUCCESS(rv, false);
nsAutoCString origin;

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

@ -6,6 +6,7 @@
#include "ServiceWorkerRegistrar.h"
#include "mozilla/dom/ServiceWorkerRegistrarTypes.h"
#include "mozilla/net/MozURL.h"
#include "nsIEventTarget.h"
#include "nsIInputStream.h"
@ -52,6 +53,80 @@ static const char* gSupportedRegistrarVersions[] = {
StaticRefPtr<ServiceWorkerRegistrar> gServiceWorkerRegistrar;
nsresult
GetOrigin(const nsACString& aURL, nsACString& aOrigin)
{
RefPtr<MozURL> url;
nsresult rv = MozURL::Init(getter_AddRefs(url), aURL);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = url->GetOrigin(aOrigin);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
nsresult
ReadLine(nsILineInputStream* aStream, nsACString& aValue)
{
bool hasMoreLines;
nsresult rv = aStream->ReadLine(aValue, &hasMoreLines);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (NS_WARN_IF(!hasMoreLines)) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
nsresult
CreatePrincipalInfo(nsILineInputStream* aStream,
ServiceWorkerRegistrationData* aEntry,
bool aSkipSpec = false)
{
nsAutoCString suffix;
nsresult rv = ReadLine(aStream, suffix);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
OriginAttributes attrs;
if (!attrs.PopulateFromSuffix(suffix)) {
return NS_ERROR_INVALID_ARG;
}
if (aSkipSpec) {
nsAutoCString unused;
nsresult rv = ReadLine(aStream, unused);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
rv = ReadLine(aStream, aEntry->scope());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
nsCString origin;
rv = GetOrigin(aEntry->scope(), origin);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
aEntry->principal() =
mozilla::ipc::ContentPrincipalInfo(attrs, origin, aEntry->scope());
return NS_OK;
}
} // namespace
NS_IMPL_ISUPPORTS(ServiceWorkerRegistrar,
@ -340,21 +415,12 @@ ServiceWorkerRegistrar::ReadData()
}
nsAutoCString line;
nsAutoCString unused;
if (version.EqualsLiteral(SERVICEWORKERREGISTRAR_VERSION)) {
nsAutoCString suffix;
GET_LINE(suffix);
OriginAttributes attrs;
if (!attrs.PopulateFromSuffix(suffix)) {
return NS_ERROR_INVALID_ARG;
rv = CreatePrincipalInfo(lineInputStream, entry);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
GET_LINE(entry->scope());
entry->principal() =
mozilla::ipc::ContentPrincipalInfo(attrs, void_t(), entry->scope());
GET_LINE(entry->currentWorkerURL());
nsAutoCString fetchFlag;
@ -403,19 +469,11 @@ ServiceWorkerRegistrar::ReadData()
}
entry->lastUpdateTime() = lastUpdateTime;
} else if (version.EqualsLiteral("7")) {
nsAutoCString suffix;
GET_LINE(suffix);
OriginAttributes attrs;
if (!attrs.PopulateFromSuffix(suffix)) {
return NS_ERROR_INVALID_ARG;
rv = CreatePrincipalInfo(lineInputStream, entry);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
GET_LINE(entry->scope());
entry->principal() =
mozilla::ipc::ContentPrincipalInfo(attrs, void_t(), entry->scope());
GET_LINE(entry->currentWorkerURL());
nsAutoCString fetchFlag;
@ -466,19 +524,11 @@ ServiceWorkerRegistrar::ReadData()
}
entry->lastUpdateTime() = lastUpdateTime;
} else if (version.EqualsLiteral("6")) {
nsAutoCString suffix;
GET_LINE(suffix);
OriginAttributes attrs;
if (!attrs.PopulateFromSuffix(suffix)) {
return NS_ERROR_INVALID_ARG;
rv = CreatePrincipalInfo(lineInputStream, entry);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
GET_LINE(entry->scope());
entry->principal() =
mozilla::ipc::ContentPrincipalInfo(attrs, void_t(), entry->scope());
GET_LINE(entry->currentWorkerURL());
nsAutoCString fetchFlag;
@ -512,19 +562,11 @@ ServiceWorkerRegistrar::ReadData()
overwrite = true;
dedupe = true;
nsAutoCString suffix;
GET_LINE(suffix);
OriginAttributes attrs;
if (!attrs.PopulateFromSuffix(suffix)) {
return NS_ERROR_INVALID_ARG;
rv = CreatePrincipalInfo(lineInputStream, entry);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
GET_LINE(entry->scope());
entry->principal() =
mozilla::ipc::ContentPrincipalInfo(attrs, void_t(), entry->scope());
GET_LINE(entry->currentWorkerURL());
nsAutoCString fetchFlag;
@ -550,19 +592,11 @@ ServiceWorkerRegistrar::ReadData()
overwrite = true;
dedupe = true;
nsAutoCString suffix;
GET_LINE(suffix);
OriginAttributes attrs;
if (!attrs.PopulateFromSuffix(suffix)) {
return NS_ERROR_INVALID_ARG;
rv = CreatePrincipalInfo(lineInputStream, entry);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
GET_LINE(entry->scope());
entry->principal() =
mozilla::ipc::ContentPrincipalInfo(attrs, void_t(), entry->scope());
GET_LINE(entry->currentWorkerURL());
// default handlesFetch flag to Enabled
@ -582,22 +616,11 @@ ServiceWorkerRegistrar::ReadData()
overwrite = true;
dedupe = true;
nsAutoCString suffix;
GET_LINE(suffix);
OriginAttributes attrs;
if (!attrs.PopulateFromSuffix(suffix)) {
return NS_ERROR_INVALID_ARG;
rv = CreatePrincipalInfo(lineInputStream, entry, true);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// principal spec is no longer used; we use scope directly instead
GET_LINE(unused);
GET_LINE(entry->scope());
entry->principal() =
mozilla::ipc::ContentPrincipalInfo(attrs, void_t(), entry->scope());
GET_LINE(entry->currentWorkerURL());
// default handlesFetch flag to Enabled
@ -617,23 +640,13 @@ ServiceWorkerRegistrar::ReadData()
overwrite = true;
dedupe = true;
nsAutoCString suffix;
GET_LINE(suffix);
OriginAttributes attrs;
if (!attrs.PopulateFromSuffix(suffix)) {
return NS_ERROR_INVALID_ARG;
rv = CreatePrincipalInfo(lineInputStream, entry, true);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// principal spec is no longer used; we use scope directly instead
GET_LINE(unused);
GET_LINE(entry->scope());
entry->principal() =
mozilla::ipc::ContentPrincipalInfo(attrs, void_t(), entry->scope());
// scriptSpec is no more used in latest version.
nsAutoCString unused;
GET_LINE(unused);
GET_LINE(entry->currentWorkerURL());

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

@ -155,7 +155,7 @@ TEST(ServiceWorkerRegistrar, TestReadData)
nsAutoCString buffer(SERVICEWORKERREGISTRAR_VERSION "\n");
buffer.AppendLiteral("^appId=123&inBrowser=1\n");
buffer.AppendLiteral("scope 0\ncurrentWorkerURL 0\n");
buffer.AppendLiteral("https://scope_0.org\ncurrentWorkerURL 0\n");
buffer.Append(SERVICEWORKERREGISTRAR_TRUE "\n");
buffer.AppendLiteral("cacheName 0\n");
buffer.AppendInt(nsIServiceWorkerRegistrationInfo::UPDATE_VIA_CACHE_IMPORTS, 16);
@ -169,7 +169,7 @@ TEST(ServiceWorkerRegistrar, TestReadData)
buffer.Append(SERVICEWORKERREGISTRAR_TERMINATOR "\n");
buffer.AppendLiteral("\n");
buffer.AppendLiteral("scope 1\ncurrentWorkerURL 1\n");
buffer.AppendLiteral("https://scope_1.org\ncurrentWorkerURL 1\n");
buffer.Append(SERVICEWORKERREGISTRAR_FALSE "\n");
buffer.AppendLiteral("cacheName 1\n");
buffer.AppendInt(nsIServiceWorkerRegistrationInfo::UPDATE_VIA_CACHE_ALL, 16);
@ -201,8 +201,8 @@ TEST(ServiceWorkerRegistrar, TestReadData)
cInfo0.attrs().CreateSuffix(suffix0);
ASSERT_STREQ("^appId=123&inBrowser=1", suffix0.get());
ASSERT_STREQ("scope 0", cInfo0.spec().get());
ASSERT_STREQ("scope 0", data[0].scope().get());
ASSERT_STREQ("https://scope_0.org", cInfo0.spec().get());
ASSERT_STREQ("https://scope_0.org", data[0].scope().get());
ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get());
ASSERT_TRUE(data[0].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName 0", NS_ConvertUTF16toUTF8(data[0].cacheName()).get());
@ -220,8 +220,8 @@ TEST(ServiceWorkerRegistrar, TestReadData)
cInfo1.attrs().CreateSuffix(suffix1);
ASSERT_STREQ("", suffix1.get());
ASSERT_STREQ("scope 1", cInfo1.spec().get());
ASSERT_STREQ("scope 1", data[1].scope().get());
ASSERT_STREQ("https://scope_1.org", cInfo1.spec().get());
ASSERT_STREQ("https://scope_1.org", data[1].scope().get());
ASSERT_STREQ("currentWorkerURL 1", data[1].currentWorkerURL().get());
ASSERT_FALSE(data[1].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName 1", NS_ConvertUTF16toUTF8(data[1].cacheName()).get());
@ -257,7 +257,7 @@ TEST(ServiceWorkerRegistrar, TestWriteData)
for (int i = 0; i < 10; ++i) {
ServiceWorkerRegistrationData reg;
reg.scope() = nsPrintfCString("scope write %d", i);
reg.scope() = nsPrintfCString("https://scope_write_%d.org", i);
reg.currentWorkerURL() = nsPrintfCString("currentWorkerURL write %d", i);
reg.currentWorkerHandlesFetch() = true;
reg.cacheName() =
@ -273,7 +273,7 @@ TEST(ServiceWorkerRegistrar, TestWriteData)
spec.AppendPrintf("spec write %d", i);
reg.principal() =
mozilla::ipc::ContentPrincipalInfo(mozilla::OriginAttributes(i, i % 2),
mozilla::void_t(), spec);
spec, spec);
swr->TestRegisterServiceWorker(reg);
}
@ -303,11 +303,11 @@ TEST(ServiceWorkerRegistrar, TestWriteData)
ASSERT_STREQ(expectSuffix.get(), suffix.get());
test.AppendPrintf("scope write %d", i);
test.AppendPrintf("https://scope_write_%d.org", i);
ASSERT_STREQ(test.get(), cInfo.spec().get());
test.Truncate();
test.AppendPrintf("scope write %d", i);
test.AppendPrintf("https://scope_write_%d.org", i);
ASSERT_STREQ(test.get(), data[i].scope().get());
test.Truncate();
@ -334,11 +334,11 @@ TEST(ServiceWorkerRegistrar, TestVersion2Migration)
nsAutoCString buffer("2" "\n");
buffer.AppendLiteral("^appId=123&inBrowser=1\n");
buffer.AppendLiteral("spec 0\nscope 0\nscriptSpec 0\ncurrentWorkerURL 0\nactiveCache 0\nwaitingCache 0\n");
buffer.AppendLiteral("spec 0\nhttps://scope_0.org\nscriptSpec 0\ncurrentWorkerURL 0\nactiveCache 0\nwaitingCache 0\n");
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_TERMINATOR "\n");
buffer.AppendLiteral("\n");
buffer.AppendLiteral("spec 1\nscope 1\nscriptSpec 1\ncurrentWorkerURL 1\nactiveCache 1\nwaitingCache 1\n");
buffer.AppendLiteral("spec 1\nhttps://scope_1.org\nscriptSpec 1\ncurrentWorkerURL 1\nactiveCache 1\nwaitingCache 1\n");
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_TERMINATOR "\n");
ASSERT_TRUE(CreateFile(buffer)) << "CreateFile should not fail";
@ -359,8 +359,8 @@ TEST(ServiceWorkerRegistrar, TestVersion2Migration)
cInfo0.attrs().CreateSuffix(suffix0);
ASSERT_STREQ("^appId=123&inBrowser=1", suffix0.get());
ASSERT_STREQ("scope 0", cInfo0.spec().get());
ASSERT_STREQ("scope 0", data[0].scope().get());
ASSERT_STREQ("https://scope_0.org", cInfo0.spec().get());
ASSERT_STREQ("https://scope_0.org", data[0].scope().get());
ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get());
ASSERT_EQ(true, data[0].currentWorkerHandlesFetch());
ASSERT_STREQ("activeCache 0", NS_ConvertUTF16toUTF8(data[0].cacheName()).get());
@ -378,8 +378,8 @@ TEST(ServiceWorkerRegistrar, TestVersion2Migration)
cInfo1.attrs().CreateSuffix(suffix1);
ASSERT_STREQ("", suffix1.get());
ASSERT_STREQ("scope 1", cInfo1.spec().get());
ASSERT_STREQ("scope 1", data[1].scope().get());
ASSERT_STREQ("https://scope_1.org", cInfo1.spec().get());
ASSERT_STREQ("https://scope_1.org", data[1].scope().get());
ASSERT_STREQ("currentWorkerURL 1", data[1].currentWorkerURL().get());
ASSERT_EQ(true, data[1].currentWorkerHandlesFetch());
ASSERT_STREQ("activeCache 1", NS_ConvertUTF16toUTF8(data[1].cacheName()).get());
@ -395,11 +395,11 @@ TEST(ServiceWorkerRegistrar, TestVersion3Migration)
nsAutoCString buffer("3" "\n");
buffer.AppendLiteral("^appId=123&inBrowser=1\n");
buffer.AppendLiteral("spec 0\nscope 0\ncurrentWorkerURL 0\ncacheName 0\n");
buffer.AppendLiteral("spec 0\nhttps://scope_0.org\ncurrentWorkerURL 0\ncacheName 0\n");
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_TERMINATOR "\n");
buffer.AppendLiteral("\n");
buffer.AppendLiteral("spec 1\nscope 1\ncurrentWorkerURL 1\ncacheName 1\n");
buffer.AppendLiteral("spec 1\nhttps://scope_1.org\ncurrentWorkerURL 1\ncacheName 1\n");
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_TERMINATOR "\n");
ASSERT_TRUE(CreateFile(buffer)) << "CreateFile should not fail";
@ -420,8 +420,8 @@ TEST(ServiceWorkerRegistrar, TestVersion3Migration)
cInfo0.attrs().CreateSuffix(suffix0);
ASSERT_STREQ("^appId=123&inBrowser=1", suffix0.get());
ASSERT_STREQ("scope 0", cInfo0.spec().get());
ASSERT_STREQ("scope 0", data[0].scope().get());
ASSERT_STREQ("https://scope_0.org", cInfo0.spec().get());
ASSERT_STREQ("https://scope_0.org", data[0].scope().get());
ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get());
ASSERT_EQ(true, data[0].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName 0", NS_ConvertUTF16toUTF8(data[0].cacheName()).get());
@ -439,8 +439,8 @@ TEST(ServiceWorkerRegistrar, TestVersion3Migration)
cInfo1.attrs().CreateSuffix(suffix1);
ASSERT_STREQ("", suffix1.get());
ASSERT_STREQ("scope 1", cInfo1.spec().get());
ASSERT_STREQ("scope 1", data[1].scope().get());
ASSERT_STREQ("https://scope_1.org", cInfo1.spec().get());
ASSERT_STREQ("https://scope_1.org", data[1].scope().get());
ASSERT_STREQ("currentWorkerURL 1", data[1].currentWorkerURL().get());
ASSERT_EQ(true, data[1].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName 1", NS_ConvertUTF16toUTF8(data[1].cacheName()).get());
@ -456,11 +456,11 @@ TEST(ServiceWorkerRegistrar, TestVersion4Migration)
nsAutoCString buffer("4" "\n");
buffer.AppendLiteral("^appId=123&inBrowser=1\n");
buffer.AppendLiteral("scope 0\ncurrentWorkerURL 0\ncacheName 0\n");
buffer.AppendLiteral("https://scope_0.org\ncurrentWorkerURL 0\ncacheName 0\n");
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_TERMINATOR "\n");
buffer.AppendLiteral("\n");
buffer.AppendLiteral("scope 1\ncurrentWorkerURL 1\ncacheName 1\n");
buffer.AppendLiteral("https://scope_1.org\ncurrentWorkerURL 1\ncacheName 1\n");
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_TERMINATOR "\n");
ASSERT_TRUE(CreateFile(buffer)) << "CreateFile should not fail";
@ -481,8 +481,8 @@ TEST(ServiceWorkerRegistrar, TestVersion4Migration)
cInfo0.attrs().CreateSuffix(suffix0);
ASSERT_STREQ("^appId=123&inBrowser=1", suffix0.get());
ASSERT_STREQ("scope 0", cInfo0.spec().get());
ASSERT_STREQ("scope 0", data[0].scope().get());
ASSERT_STREQ("https://scope_0.org", cInfo0.spec().get());
ASSERT_STREQ("https://scope_0.org", data[0].scope().get());
ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get());
// default is true
ASSERT_EQ(true, data[0].currentWorkerHandlesFetch());
@ -501,8 +501,8 @@ TEST(ServiceWorkerRegistrar, TestVersion4Migration)
cInfo1.attrs().CreateSuffix(suffix1);
ASSERT_STREQ("", suffix1.get());
ASSERT_STREQ("scope 1", cInfo1.spec().get());
ASSERT_STREQ("scope 1", data[1].scope().get());
ASSERT_STREQ("https://scope_1.org", cInfo1.spec().get());
ASSERT_STREQ("https://scope_1.org", data[1].scope().get());
ASSERT_STREQ("currentWorkerURL 1", data[1].currentWorkerURL().get());
// default is true
ASSERT_EQ(true, data[1].currentWorkerHandlesFetch());
@ -519,13 +519,13 @@ TEST(ServiceWorkerRegistrar, TestVersion5Migration)
nsAutoCString buffer("5" "\n");
buffer.AppendLiteral("^appId=123&inBrowser=1\n");
buffer.AppendLiteral("scope 0\ncurrentWorkerURL 0\n");
buffer.AppendLiteral("https://scope_0.org\ncurrentWorkerURL 0\n");
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_TRUE "\n");
buffer.AppendLiteral("cacheName 0\n");
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_TERMINATOR "\n");
buffer.AppendLiteral("\n");
buffer.AppendLiteral("scope 1\ncurrentWorkerURL 1\n");
buffer.AppendLiteral("https://scope_1.org\ncurrentWorkerURL 1\n");
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_FALSE "\n");
buffer.AppendLiteral("cacheName 1\n");
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_TERMINATOR "\n");
@ -548,8 +548,8 @@ TEST(ServiceWorkerRegistrar, TestVersion5Migration)
cInfo0.attrs().CreateSuffix(suffix0);
ASSERT_STREQ("^appId=123&inBrowser=1", suffix0.get());
ASSERT_STREQ("scope 0", cInfo0.spec().get());
ASSERT_STREQ("scope 0", data[0].scope().get());
ASSERT_STREQ("https://scope_0.org", cInfo0.spec().get());
ASSERT_STREQ("https://scope_0.org", data[0].scope().get());
ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get());
ASSERT_TRUE(data[0].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName 0", NS_ConvertUTF16toUTF8(data[0].cacheName()).get());
@ -567,8 +567,8 @@ TEST(ServiceWorkerRegistrar, TestVersion5Migration)
cInfo1.attrs().CreateSuffix(suffix1);
ASSERT_STREQ("", suffix1.get());
ASSERT_STREQ("scope 1", cInfo1.spec().get());
ASSERT_STREQ("scope 1", data[1].scope().get());
ASSERT_STREQ("https://scope_1.org", cInfo1.spec().get());
ASSERT_STREQ("https://scope_1.org", data[1].scope().get());
ASSERT_STREQ("currentWorkerURL 1", data[1].currentWorkerURL().get());
ASSERT_FALSE(data[1].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName 1", NS_ConvertUTF16toUTF8(data[1].cacheName()).get());
@ -584,7 +584,7 @@ TEST(ServiceWorkerRegistrar, TestVersion6Migration)
nsAutoCString buffer("6" "\n");
buffer.AppendLiteral("^appId=123&inBrowser=1\n");
buffer.AppendLiteral("scope 0\ncurrentWorkerURL 0\n");
buffer.AppendLiteral("https://scope_0.org\ncurrentWorkerURL 0\n");
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_TRUE "\n");
buffer.AppendLiteral("cacheName 0\n");
buffer.AppendInt(nsIRequest::LOAD_NORMAL, 16);
@ -592,7 +592,7 @@ TEST(ServiceWorkerRegistrar, TestVersion6Migration)
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_TERMINATOR "\n");
buffer.AppendLiteral("\n");
buffer.AppendLiteral("scope 1\ncurrentWorkerURL 1\n");
buffer.AppendLiteral("https://scope_1.org\ncurrentWorkerURL 1\n");
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_FALSE "\n");
buffer.AppendLiteral("cacheName 1\n");
buffer.AppendInt(nsIRequest::VALIDATE_ALWAYS, 16);
@ -617,8 +617,8 @@ TEST(ServiceWorkerRegistrar, TestVersion6Migration)
cInfo0.attrs().CreateSuffix(suffix0);
ASSERT_STREQ("^appId=123&inBrowser=1", suffix0.get());
ASSERT_STREQ("scope 0", cInfo0.spec().get());
ASSERT_STREQ("scope 0", data[0].scope().get());
ASSERT_STREQ("https://scope_0.org", cInfo0.spec().get());
ASSERT_STREQ("https://scope_0.org", data[0].scope().get());
ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get());
ASSERT_TRUE(data[0].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName 0", NS_ConvertUTF16toUTF8(data[0].cacheName()).get());
@ -636,8 +636,8 @@ TEST(ServiceWorkerRegistrar, TestVersion6Migration)
cInfo1.attrs().CreateSuffix(suffix1);
ASSERT_STREQ("", suffix1.get());
ASSERT_STREQ("scope 1", cInfo1.spec().get());
ASSERT_STREQ("scope 1", data[1].scope().get());
ASSERT_STREQ("https://scope_1.org", cInfo1.spec().get());
ASSERT_STREQ("https://scope_1.org", data[1].scope().get());
ASSERT_STREQ("currentWorkerURL 1", data[1].currentWorkerURL().get());
ASSERT_FALSE(data[1].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName 1", NS_ConvertUTF16toUTF8(data[1].cacheName()).get());
@ -653,7 +653,7 @@ TEST(ServiceWorkerRegistrar, TestVersion7Migration)
nsAutoCString buffer("7" "\n");
buffer.AppendLiteral("^appId=123&inBrowser=1\n");
buffer.AppendLiteral("scope 0\ncurrentWorkerURL 0\n");
buffer.AppendLiteral("https://scope_0.org\ncurrentWorkerURL 0\n");
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_TRUE "\n");
buffer.AppendLiteral("cacheName 0\n");
buffer.AppendInt(nsIRequest::LOAD_NORMAL, 16);
@ -667,7 +667,7 @@ TEST(ServiceWorkerRegistrar, TestVersion7Migration)
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_TERMINATOR "\n");
buffer.AppendLiteral("\n");
buffer.AppendLiteral("scope 1\ncurrentWorkerURL 1\n");
buffer.AppendLiteral("https://scope_1.org\ncurrentWorkerURL 1\n");
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_FALSE "\n");
buffer.AppendLiteral("cacheName 1\n");
buffer.AppendInt(nsIRequest::VALIDATE_ALWAYS, 16);
@ -699,8 +699,8 @@ TEST(ServiceWorkerRegistrar, TestVersion7Migration)
cInfo0.attrs().CreateSuffix(suffix0);
ASSERT_STREQ("^appId=123&inBrowser=1", suffix0.get());
ASSERT_STREQ("scope 0", cInfo0.spec().get());
ASSERT_STREQ("scope 0", data[0].scope().get());
ASSERT_STREQ("https://scope_0.org", cInfo0.spec().get());
ASSERT_STREQ("https://scope_0.org", data[0].scope().get());
ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get());
ASSERT_TRUE(data[0].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName 0", NS_ConvertUTF16toUTF8(data[0].cacheName()).get());
@ -718,8 +718,8 @@ TEST(ServiceWorkerRegistrar, TestVersion7Migration)
cInfo1.attrs().CreateSuffix(suffix1);
ASSERT_STREQ("", suffix1.get());
ASSERT_STREQ("scope 1", cInfo1.spec().get());
ASSERT_STREQ("scope 1", data[1].scope().get());
ASSERT_STREQ("https://scope_1.org", cInfo1.spec().get());
ASSERT_STREQ("https://scope_1.org", data[1].scope().get());
ASSERT_STREQ("currentWorkerURL 1", data[1].currentWorkerURL().get());
ASSERT_FALSE(data[1].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName 1", NS_ConvertUTF16toUTF8(data[1].cacheName()).get());
@ -736,24 +736,24 @@ TEST(ServiceWorkerRegistrar, TestDedupeRead)
// unique entries
buffer.AppendLiteral("^appId=123&inBrowser=1\n");
buffer.AppendLiteral("spec 0\nscope 0\ncurrentWorkerURL 0\ncacheName 0\n");
buffer.AppendLiteral("spec 0\nhttps://scope_0.org\ncurrentWorkerURL 0\ncacheName 0\n");
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_TERMINATOR "\n");
buffer.AppendLiteral("\n");
buffer.AppendLiteral("spec 1\nscope 1\ncurrentWorkerURL 1\ncacheName 1\n");
buffer.AppendLiteral("spec 1\nhttps://scope_1.org\ncurrentWorkerURL 1\ncacheName 1\n");
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_TERMINATOR "\n");
// dupe entries
buffer.AppendLiteral("^appId=123&inBrowser=1\n");
buffer.AppendLiteral("spec 1\nscope 0\ncurrentWorkerURL 0\ncacheName 0\n");
buffer.AppendLiteral("spec 1\nhttps://scope_0.org\ncurrentWorkerURL 0\ncacheName 0\n");
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_TERMINATOR "\n");
buffer.AppendLiteral("^appId=123&inBrowser=1\n");
buffer.AppendLiteral("spec 2\nscope 0\ncurrentWorkerURL 0\ncacheName 0\n");
buffer.AppendLiteral("spec 2\nhttps://scope_0.org\ncurrentWorkerURL 0\ncacheName 0\n");
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_TERMINATOR "\n");
buffer.AppendLiteral("\n");
buffer.AppendLiteral("spec 3\nscope 1\ncurrentWorkerURL 1\ncacheName 1\n");
buffer.AppendLiteral("spec 3\nhttps://scope_1.org\ncurrentWorkerURL 1\ncacheName 1\n");
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_TERMINATOR "\n");
ASSERT_TRUE(CreateFile(buffer)) << "CreateFile should not fail";
@ -774,8 +774,8 @@ TEST(ServiceWorkerRegistrar, TestDedupeRead)
cInfo0.attrs().CreateSuffix(suffix0);
ASSERT_STREQ("^appId=123&inBrowser=1", suffix0.get());
ASSERT_STREQ("scope 0", cInfo0.spec().get());
ASSERT_STREQ("scope 0", data[0].scope().get());
ASSERT_STREQ("https://scope_0.org", cInfo0.spec().get());
ASSERT_STREQ("https://scope_0.org", data[0].scope().get());
ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get());
ASSERT_EQ(true, data[0].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName 0", NS_ConvertUTF16toUTF8(data[0].cacheName()).get());
@ -793,8 +793,8 @@ TEST(ServiceWorkerRegistrar, TestDedupeRead)
cInfo1.attrs().CreateSuffix(suffix1);
ASSERT_STREQ("", suffix1.get());
ASSERT_STREQ("scope 1", cInfo1.spec().get());
ASSERT_STREQ("scope 1", data[1].scope().get());
ASSERT_STREQ("https://scope_1.org", cInfo1.spec().get());
ASSERT_STREQ("https://scope_1.org", data[1].scope().get());
ASSERT_STREQ("currentWorkerURL 1", data[1].currentWorkerURL().get());
ASSERT_EQ(true, data[1].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName 1", NS_ConvertUTF16toUTF8(data[1].cacheName()).get());
@ -813,7 +813,7 @@ TEST(ServiceWorkerRegistrar, TestDedupeWrite)
for (int i = 0; i < 10; ++i) {
ServiceWorkerRegistrationData reg;
reg.scope() = NS_LITERAL_CSTRING("scope write dedupe");
reg.scope() = NS_LITERAL_CSTRING("https://scope_write.dedupe");
reg.currentWorkerURL() = nsPrintfCString("currentWorkerURL write %d", i);
reg.currentWorkerHandlesFetch() = true;
reg.cacheName() =
@ -825,7 +825,7 @@ TEST(ServiceWorkerRegistrar, TestDedupeWrite)
spec.AppendPrintf("spec write dedupe/%d", i);
reg.principal() =
mozilla::ipc::ContentPrincipalInfo(mozilla::OriginAttributes(0, false),
mozilla::void_t(), spec);
spec, spec);
swr->TestRegisterServiceWorker(reg);
}
@ -854,8 +854,8 @@ TEST(ServiceWorkerRegistrar, TestDedupeWrite)
// Last entry passed to RegisterServiceWorkerInternal() should overwrite
// previous values. So expect "9" in values here.
ASSERT_STREQ(expectSuffix.get(), suffix.get());
ASSERT_STREQ("scope write dedupe", cInfo.spec().get());
ASSERT_STREQ("scope write dedupe", data[0].scope().get());
ASSERT_STREQ("https://scope_write.dedupe", cInfo.spec().get());
ASSERT_STREQ("https://scope_write.dedupe", data[0].scope().get());
ASSERT_STREQ("currentWorkerURL write 9", data[0].currentWorkerURL().get());
ASSERT_EQ(true, data[0].currentWorkerHandlesFetch());
ASSERT_STREQ("cacheName write 9",

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

@ -96,16 +96,12 @@ PrincipalInfoToPrincipal(const PrincipalInfo& aPrincipalInfo,
return nullptr;
}
// When the principal is serialized, the origin is extract from it. This
// can fail, and in case, here we will havea Tvoid_t. If we have a string,
// it must match with what the_new_principal.getOrigin returns.
if (info.originNoSuffix().type() == ContentPrincipalInfoOriginNoSuffix::TnsCString) {
nsAutoCString originNoSuffix;
rv = principal->GetOriginNoSuffix(originNoSuffix);
if (NS_WARN_IF(NS_FAILED(rv)) ||
!info.originNoSuffix().get_nsCString().Equals(originNoSuffix)) {
MOZ_CRASH("If the origin was in the contentPrincipalInfo, it must be available when deserialized");
}
// Origin must match what the_new_principal.getOrigin returns.
nsAutoCString originNoSuffix;
rv = principal->GetOriginNoSuffix(originNoSuffix);
if (NS_WARN_IF(NS_FAILED(rv)) ||
!info.originNoSuffix().Equals(originNoSuffix)) {
MOZ_CRASH("Origin must be available when deserialized");
}
return principal.forget();
@ -232,18 +228,14 @@ PrincipalToPrincipalInfo(nsIPrincipal* aPrincipal,
return rv;
}
ContentPrincipalInfoOriginNoSuffix infoOriginNoSuffix;
nsCString originNoSuffix;
rv = aPrincipal->GetOriginNoSuffix(originNoSuffix);
if (NS_WARN_IF(NS_FAILED(rv))) {
infoOriginNoSuffix = void_t();
} else {
infoOriginNoSuffix = originNoSuffix;
return rv;
}
*aPrincipalInfo = ContentPrincipalInfo(aPrincipal->OriginAttributesRef(),
infoOriginNoSuffix, spec);
originNoSuffix, spec);
return NS_OK;
}

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

@ -8,12 +8,6 @@ using struct mozilla::void_t from "ipc/IPCMessageUtils.h";
namespace mozilla {
namespace ipc {
union ContentPrincipalInfoOriginNoSuffix
{
nsCString;
void_t;
};
struct ContentPrincipalInfo
{
OriginAttributes attrs;
@ -25,7 +19,7 @@ struct ContentPrincipalInfo
// Another important reason why we have this attribute is that
// ContentPrincipalInfo is used out of the main-thread. Having this value
// here allows us to retrive the origin without creating a full nsIPrincipal.
ContentPrincipalInfoOriginNoSuffix originNoSuffix;
nsCString originNoSuffix;
nsCString spec;
};