зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1162088 - patch 2 - ServiceWorkerManager should use OriginAttributes from the principal as scopeKey, r=nsm
This commit is contained in:
Родитель
a71e717b67
Коммит
8adec8a2d4
|
@ -33,7 +33,7 @@ interface nsIServiceWorkerInfo : nsISupports
|
|||
readonly attribute DOMString waitingCacheName;
|
||||
};
|
||||
|
||||
[scriptable, builtinclass, uuid(bfb913ad-177d-49ae-bf62-efd32ca73424)]
|
||||
[scriptable, builtinclass, uuid(d130fcbd-1afe-4dd9-b70d-08a4b2373af5)]
|
||||
interface nsIServiceWorkerManager : nsISupports
|
||||
{
|
||||
/**
|
||||
|
|
|
@ -167,7 +167,9 @@ ServiceWorkerRegistrar::RegisterServiceWorker(
|
|||
}
|
||||
|
||||
void
|
||||
ServiceWorkerRegistrar::UnregisterServiceWorker(const nsACString& aScope)
|
||||
ServiceWorkerRegistrar::UnregisterServiceWorker(
|
||||
const PrincipalInfo& aPrincipalInfo,
|
||||
const nsACString& aScope)
|
||||
{
|
||||
AssertIsOnBackgroundThread();
|
||||
|
||||
|
@ -183,7 +185,8 @@ ServiceWorkerRegistrar::UnregisterServiceWorker(const nsACString& aScope)
|
|||
MOZ_ASSERT(mDataLoaded);
|
||||
|
||||
for (uint32_t i = 0; i < mData.Length(); ++i) {
|
||||
if (mData[i].scope() == aScope) {
|
||||
if (mData[i].principal() == aPrincipalInfo &&
|
||||
mData[i].scope() == aScope) {
|
||||
mData.RemoveElementAt(i);
|
||||
deleted = true;
|
||||
break;
|
||||
|
@ -281,35 +284,24 @@ ServiceWorkerRegistrar::ReadData()
|
|||
|
||||
GET_LINE(line);
|
||||
|
||||
if (line.EqualsLiteral(SERVICEWORKERREGISTRAR_SYSTEM_PRINCIPAL)) {
|
||||
entry->principal() = mozilla::ipc::SystemPrincipalInfo();
|
||||
} else {
|
||||
if (!line.EqualsLiteral(SERVICEWORKERREGISTRAR_CONTENT_PRINCIPAL)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
GET_LINE(line);
|
||||
|
||||
uint32_t appId = line.ToInteger(&rv);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
GET_LINE(line);
|
||||
|
||||
if (!line.EqualsLiteral(SERVICEWORKERREGISTRAR_TRUE) &&
|
||||
!line.EqualsLiteral(SERVICEWORKERREGISTRAR_FALSE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
bool isInBrowserElement = line.EqualsLiteral(SERVICEWORKERREGISTRAR_TRUE);
|
||||
|
||||
GET_LINE(line);
|
||||
entry->principal() =
|
||||
mozilla::ipc::ContentPrincipalInfo(appId, isInBrowserElement,
|
||||
line);
|
||||
uint32_t appId = line.ToInteger(&rv);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
GET_LINE(line);
|
||||
|
||||
if (!line.EqualsLiteral(SERVICEWORKERREGISTRAR_TRUE) &&
|
||||
!line.EqualsLiteral(SERVICEWORKERREGISTRAR_FALSE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
bool isInBrowserElement = line.EqualsLiteral(SERVICEWORKERREGISTRAR_TRUE);
|
||||
|
||||
GET_LINE(line);
|
||||
entry->principal() =
|
||||
mozilla::ipc::ContentPrincipalInfo(appId, isInBrowserElement, line);
|
||||
|
||||
GET_LINE(entry->scope());
|
||||
GET_LINE(entry->scriptSpec());
|
||||
GET_LINE(entry->currentWorkerURL());
|
||||
|
@ -518,30 +510,24 @@ ServiceWorkerRegistrar::WriteData()
|
|||
for (uint32_t i = 0, len = data.Length(); i < len; ++i) {
|
||||
const mozilla::ipc::PrincipalInfo& info = data[i].principal();
|
||||
|
||||
if (info.type() == mozilla::ipc::PrincipalInfo::TSystemPrincipalInfo) {
|
||||
buffer.AssignLiteral(SERVICEWORKERREGISTRAR_SYSTEM_PRINCIPAL);
|
||||
MOZ_ASSERT(info.type() == mozilla::ipc::PrincipalInfo::TContentPrincipalInfo);
|
||||
|
||||
const mozilla::ipc::ContentPrincipalInfo& cInfo =
|
||||
info.get_ContentPrincipalInfo();
|
||||
|
||||
buffer.Truncate();
|
||||
buffer.AppendInt(cInfo.appId());
|
||||
buffer.Append('\n');
|
||||
|
||||
if (cInfo.isInBrowserElement()) {
|
||||
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_TRUE);
|
||||
} else {
|
||||
MOZ_ASSERT(info.type() == mozilla::ipc::PrincipalInfo::TContentPrincipalInfo);
|
||||
|
||||
const mozilla::ipc::ContentPrincipalInfo& cInfo =
|
||||
info.get_ContentPrincipalInfo();
|
||||
|
||||
buffer.AssignLiteral(SERVICEWORKERREGISTRAR_CONTENT_PRINCIPAL);
|
||||
buffer.Append('\n');
|
||||
|
||||
buffer.AppendInt(cInfo.appId());
|
||||
buffer.Append('\n');
|
||||
|
||||
if (cInfo.isInBrowserElement()) {
|
||||
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_TRUE);
|
||||
} else {
|
||||
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_FALSE);
|
||||
}
|
||||
|
||||
buffer.Append('\n');
|
||||
buffer.Append(cInfo.spec());
|
||||
buffer.AppendLiteral(SERVICEWORKERREGISTRAR_FALSE);
|
||||
}
|
||||
|
||||
buffer.Append('\n');
|
||||
buffer.Append(cInfo.spec());
|
||||
|
||||
buffer.Append('\n');
|
||||
|
||||
buffer.Append(data[i].scope());
|
||||
|
|
|
@ -20,13 +20,15 @@
|
|||
#define SERVICEWORKERREGISTRAR_TERMINATOR "#"
|
||||
#define SERVICEWORKERREGISTRAR_TRUE "true"
|
||||
#define SERVICEWORKERREGISTRAR_FALSE "false"
|
||||
#define SERVICEWORKERREGISTRAR_SYSTEM_PRINCIPAL "system"
|
||||
#define SERVICEWORKERREGISTRAR_CONTENT_PRINCIPAL "content"
|
||||
|
||||
|
||||
class nsIFile;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
namespace ipc {
|
||||
class PrincipalInfo;
|
||||
}
|
||||
|
||||
namespace dom {
|
||||
|
||||
class ServiceWorkerRegistrationData;
|
||||
|
@ -50,7 +52,8 @@ public:
|
|||
void GetRegistrations(nsTArray<ServiceWorkerRegistrationData>& aValues);
|
||||
|
||||
void RegisterServiceWorker(const ServiceWorkerRegistrationData& aData);
|
||||
void UnregisterServiceWorker(const nsACString& aScope);
|
||||
void UnregisterServiceWorker(const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
|
||||
const nsACString& aScope);
|
||||
|
||||
protected:
|
||||
// These methods are protected because we test this class using gTest
|
||||
|
|
|
@ -140,18 +140,12 @@ TEST(ServiceWorkerRegistrar, TestReadData)
|
|||
{
|
||||
nsAutoCString buffer(SERVICEWORKERREGISTRAR_VERSION "\n");
|
||||
|
||||
buffer.Append(SERVICEWORKERREGISTRAR_SYSTEM_PRINCIPAL "\n");
|
||||
buffer.Append("scope 0\nscriptSpec 0\ncurrentWorkerURL 0\nactiveCache 0\nwaitingCache 0\n");
|
||||
buffer.Append(SERVICEWORKERREGISTRAR_TERMINATOR "\n");
|
||||
|
||||
buffer.Append(SERVICEWORKERREGISTRAR_CONTENT_PRINCIPAL "\n");
|
||||
buffer.Append("123\n" SERVICEWORKERREGISTRAR_TRUE "\n");
|
||||
buffer.Append("spec 1\nscope 1\nscriptSpec 1\ncurrentWorkerURL 1\nactiveCache 1\nwaitingCache 1\n");
|
||||
buffer.Append("spec 0\nscope 0\nscriptSpec 0\ncurrentWorkerURL 0\nactiveCache 0\nwaitingCache 0\n");
|
||||
buffer.Append(SERVICEWORKERREGISTRAR_TERMINATOR "\n");
|
||||
|
||||
buffer.Append(SERVICEWORKERREGISTRAR_CONTENT_PRINCIPAL "\n");
|
||||
buffer.Append("0\n" SERVICEWORKERREGISTRAR_FALSE "\n");
|
||||
buffer.Append("spec 2\nscope 2\nscriptSpec 2\ncurrentWorkerURL 2\nactiveCache 2\nwaitingCache 2\n");
|
||||
buffer.Append("spec 1\nscope 1\nscriptSpec 1\ncurrentWorkerURL 1\nactiveCache 1\nwaitingCache 1\n");
|
||||
buffer.Append(SERVICEWORKERREGISTRAR_TERMINATOR "\n");
|
||||
|
||||
ASSERT_TRUE(CreateFile(buffer)) << "CreateFile should not fail";
|
||||
|
@ -162,11 +156,15 @@ TEST(ServiceWorkerRegistrar, TestReadData)
|
|||
ASSERT_EQ(NS_OK, rv) << "ReadData() should not fail";
|
||||
|
||||
const nsTArray<ServiceWorkerRegistrationData>& data = swr->TestGetData();
|
||||
ASSERT_EQ((uint32_t)3, data.Length()) << "4 entries should be found";
|
||||
ASSERT_EQ((uint32_t)2, data.Length()) << "4 entries should be found";
|
||||
|
||||
const mozilla::ipc::PrincipalInfo& info0 = data[0].principal();
|
||||
ASSERT_EQ(info0.type(), mozilla::ipc::PrincipalInfo::TSystemPrincipalInfo) << "First principal must be system";
|
||||
ASSERT_EQ(info0.type(), mozilla::ipc::PrincipalInfo::TContentPrincipalInfo) << "First principal must be content";
|
||||
const mozilla::ipc::ContentPrincipalInfo& cInfo0 = data[0].principal();
|
||||
|
||||
ASSERT_EQ((uint32_t)123, cInfo0.appId());
|
||||
ASSERT_EQ((uint32_t)true, cInfo0.isInBrowserElement());
|
||||
ASSERT_STREQ("spec 0", cInfo0.spec().get());
|
||||
ASSERT_STREQ("scope 0", data[0].scope().get());
|
||||
ASSERT_STREQ("scriptSpec 0", data[0].scriptSpec().get());
|
||||
ASSERT_STREQ("currentWorkerURL 0", data[0].currentWorkerURL().get());
|
||||
|
@ -177,27 +175,14 @@ TEST(ServiceWorkerRegistrar, TestReadData)
|
|||
ASSERT_EQ(info1.type(), mozilla::ipc::PrincipalInfo::TContentPrincipalInfo) << "First principal must be content";
|
||||
const mozilla::ipc::ContentPrincipalInfo& cInfo1 = data[1].principal();
|
||||
|
||||
ASSERT_EQ((uint32_t)123, cInfo1.appId());
|
||||
ASSERT_EQ((uint32_t)true, cInfo1.isInBrowserElement());
|
||||
ASSERT_EQ((uint32_t)0, cInfo1.appId());
|
||||
ASSERT_EQ((uint32_t)false, cInfo1.isInBrowserElement());
|
||||
ASSERT_STREQ("spec 1", cInfo1.spec().get());
|
||||
ASSERT_STREQ("scope 1", data[1].scope().get());
|
||||
ASSERT_STREQ("scriptSpec 1", data[1].scriptSpec().get());
|
||||
ASSERT_STREQ("currentWorkerURL 1", data[1].currentWorkerURL().get());
|
||||
ASSERT_STREQ("activeCache 1", NS_ConvertUTF16toUTF8(data[1].activeCacheName()).get());
|
||||
ASSERT_STREQ("waitingCache 1", NS_ConvertUTF16toUTF8(data[1].waitingCacheName()).get());
|
||||
|
||||
const mozilla::ipc::PrincipalInfo& info2 = data[2].principal();
|
||||
ASSERT_EQ(info2.type(), mozilla::ipc::PrincipalInfo::TContentPrincipalInfo) << "First principal must be content";
|
||||
const mozilla::ipc::ContentPrincipalInfo& cInfo2 = data[2].principal();
|
||||
|
||||
ASSERT_EQ((uint32_t)0, cInfo2.appId());
|
||||
ASSERT_EQ((uint32_t)false, cInfo2.isInBrowserElement());
|
||||
ASSERT_STREQ("spec 2", cInfo2.spec().get());
|
||||
ASSERT_STREQ("scope 2", data[2].scope().get());
|
||||
ASSERT_STREQ("scriptSpec 2", data[2].scriptSpec().get());
|
||||
ASSERT_STREQ("currentWorkerURL 2", data[2].currentWorkerURL().get());
|
||||
ASSERT_STREQ("activeCache 2", NS_ConvertUTF16toUTF8(data[2].activeCacheName()).get());
|
||||
ASSERT_STREQ("waitingCache 2", NS_ConvertUTF16toUTF8(data[2].waitingCacheName()).get());
|
||||
}
|
||||
|
||||
TEST(ServiceWorkerRegistrar, TestDeleteData)
|
||||
|
@ -227,14 +212,9 @@ TEST(ServiceWorkerRegistrar, TestWriteData)
|
|||
for (int i = 0; i < 10; ++i) {
|
||||
ServiceWorkerRegistrationData* d = data.AppendElement();
|
||||
|
||||
if ((i % 2) == 0) {
|
||||
d->principal() = mozilla::ipc::SystemPrincipalInfo();
|
||||
} else if ((i % 2) == 1) {
|
||||
nsAutoCString spec;
|
||||
spec.AppendPrintf("spec write %d", i);
|
||||
d->principal() = mozilla::ipc::ContentPrincipalInfo(i, i % 2, spec);
|
||||
}
|
||||
|
||||
nsAutoCString spec;
|
||||
spec.AppendPrintf("spec write %d", i);
|
||||
d->principal() = mozilla::ipc::ContentPrincipalInfo(i, i % 2, spec);
|
||||
d->scope().AppendPrintf("scope write %d", i);
|
||||
d->scriptSpec().AppendPrintf("scriptSpec write %d", i);
|
||||
d->currentWorkerURL().AppendPrintf("currentWorkerURL write %d", i);
|
||||
|
@ -257,18 +237,14 @@ TEST(ServiceWorkerRegistrar, TestWriteData)
|
|||
for (int i = 0; i < 10; ++i) {
|
||||
nsAutoCString test;
|
||||
|
||||
if ((i % 2) == 0) {
|
||||
ASSERT_EQ(data[i].principal().type(), mozilla::ipc::PrincipalInfo::TSystemPrincipalInfo);
|
||||
} else if ((i % 2) == 1) {
|
||||
ASSERT_EQ(data[i].principal().type(), mozilla::ipc::PrincipalInfo::TContentPrincipalInfo);
|
||||
const mozilla::ipc::ContentPrincipalInfo& cInfo = data[i].principal();
|
||||
ASSERT_EQ(data[i].principal().type(), mozilla::ipc::PrincipalInfo::TContentPrincipalInfo);
|
||||
const mozilla::ipc::ContentPrincipalInfo& cInfo = data[i].principal();
|
||||
|
||||
ASSERT_EQ((uint32_t)i, cInfo.appId());
|
||||
ASSERT_EQ((uint32_t)(i %2), cInfo.isInBrowserElement());
|
||||
ASSERT_EQ((uint32_t)i, cInfo.appId());
|
||||
ASSERT_EQ((uint32_t)(i %2), cInfo.isInBrowserElement());
|
||||
|
||||
test.AppendPrintf("spec write %d", i);
|
||||
ASSERT_STREQ(test.get(), cInfo.spec().get());
|
||||
}
|
||||
test.AppendPrintf("spec write %d", i);
|
||||
ASSERT_STREQ(test.get(), cInfo.spec().get());
|
||||
|
||||
test.Truncate();
|
||||
test.AppendPrintf("scope write %d", i);
|
||||
|
|
|
@ -514,8 +514,10 @@ private:
|
|||
class UnregisterServiceWorkerCallback final : public nsRunnable
|
||||
{
|
||||
public:
|
||||
explicit UnregisterServiceWorkerCallback(const nsString& aScope)
|
||||
: mScope(aScope)
|
||||
UnregisterServiceWorkerCallback(const PrincipalInfo& aPrincipalInfo,
|
||||
const nsString& aScope)
|
||||
: mPrincipalInfo(aPrincipalInfo)
|
||||
, mScope(aScope)
|
||||
{
|
||||
AssertIsInMainProcess();
|
||||
AssertIsOnBackgroundThread();
|
||||
|
@ -531,11 +533,13 @@ public:
|
|||
dom::ServiceWorkerRegistrar::Get();
|
||||
MOZ_ASSERT(service);
|
||||
|
||||
service->UnregisterServiceWorker(NS_ConvertUTF16toUTF8(mScope));
|
||||
service->UnregisterServiceWorker(mPrincipalInfo,
|
||||
NS_ConvertUTF16toUTF8(mScope));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
const PrincipalInfo mPrincipalInfo;
|
||||
nsString mScope;
|
||||
};
|
||||
|
||||
|
@ -597,7 +601,8 @@ BackgroundParentImpl::RecvRegisterServiceWorker(
|
|||
// Basic validation.
|
||||
if (aData.scope().IsEmpty() ||
|
||||
aData.scriptSpec().IsEmpty() ||
|
||||
aData.principal().type() == PrincipalInfo::TNullPrincipalInfo) {
|
||||
aData.principal().type() == PrincipalInfo::TNullPrincipalInfo ||
|
||||
aData.principal().type() == PrincipalInfo::TSystemPrincipalInfo) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -631,12 +636,13 @@ BackgroundParentImpl::RecvUnregisterServiceWorker(
|
|||
|
||||
// Basic validation.
|
||||
if (aScope.IsEmpty() ||
|
||||
aPrincipalInfo.type() == PrincipalInfo::TNullPrincipalInfo) {
|
||||
aPrincipalInfo.type() == PrincipalInfo::TNullPrincipalInfo ||
|
||||
aPrincipalInfo.type() == PrincipalInfo::TSystemPrincipalInfo) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsRefPtr<UnregisterServiceWorkerCallback> callback =
|
||||
new UnregisterServiceWorkerCallback(aScope);
|
||||
new UnregisterServiceWorkerCallback(aPrincipalInfo, aScope);
|
||||
|
||||
nsRefPtr<ContentParent> parent = BackgroundParent::GetContentParent(this);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче