Bug 1265771 P1 Only store active documents in the global observer list. r=bz

This commit is contained in:
Ben Kelly 2016-04-24 08:11:32 -07:00
Родитель 6a7fdf9b55
Коммит 2464cb6262
1 изменённых файлов: 31 добавлений и 12 удалений

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

@ -1679,11 +1679,6 @@ nsDocument::~nsDocument()
mImageTracker.Clear();
mPlugins.Clear();
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) {
os->RemoveObserver(this, "service-worker-get-client");
}
}
NS_INTERFACE_TABLE_HEAD(nsDocument)
@ -2085,11 +2080,6 @@ nsDocument::Init()
mozilla::HoldJSObjects(this);
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) {
os->AddObserver(this, "service-worker-get-client", /* ownsWeak */ true);
}
return NS_OK;
}
@ -4712,6 +4702,28 @@ nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject)
}
swm->MaybeStopControlling(this);
}
// Remove ourself from the list of clients. We only register
// content principal documents in this list.
if (!nsContentUtils::IsSystemPrincipal(GetPrincipal()) &&
!GetPrincipal()->GetIsNullPrincipal()) {
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) {
os->RemoveObserver(this, "service-worker-get-client");
}
}
} else if (!mScriptGlobalObject && aScriptGlobalObject &&
mDocumentContainer && GetChannel() &&
!nsContentUtils::IsSystemPrincipal(GetPrincipal()) &&
!GetPrincipal()->GetIsNullPrincipal()) {
// This document is being activated. Register it in the list of
// clients. We only do this for content principal documents
// since we can never observe system or null principals.
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) {
os->AddObserver(this, "service-worker-get-client", /* ownsWeak */ false);
}
}
mScriptGlobalObject = aScriptGlobalObject;
@ -12469,11 +12481,18 @@ nsDocument::Observe(nsISupports *aSubject,
OnAppThemeChanged();
}
} else if (strcmp("service-worker-get-client", aTopic) == 0) {
nsAutoString clientId;
GetOrCreateId(clientId);
// No need to generate the ID if it doesn't exist here. The ID being
// requested must already be generated in order to passed in as
// aSubject.
nsString clientId = GetId();
if (!clientId.IsEmpty() && clientId.Equals(aData)) {
nsCOMPtr<nsISupportsInterfacePointer> ifptr = do_QueryInterface(aSubject);
if (ifptr) {
#ifdef DEBUG
nsCOMPtr<nsISupports> value;
MOZ_ALWAYS_SUCCEEDS(ifptr->GetData(getter_AddRefs(value)));
MOZ_ASSERT(!value);
#endif
ifptr->SetData(static_cast<nsIDocument*>(this));
ifptr->SetDataIID(&NS_GET_IID(nsIDocument));
}