Backed out changeset 274999e28c07 (bug 1266747)

This commit is contained in:
Sebastian Hengst 2017-02-28 18:54:20 +01:00
Родитель d41395acab
Коммит 78abfe9e2f
3 изменённых файлов: 43 добавлений и 72 удалений

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

@ -33,9 +33,8 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ServiceWorkerClient)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
ServiceWorkerClientInfo::ServiceWorkerClientInfo(nsIDocument* aDoc, uint32_t aOrdinal)
ServiceWorkerClientInfo::ServiceWorkerClientInfo(nsIDocument* aDoc)
: mType(ClientType::Window)
, mOrdinal(aOrdinal)
, mWindowId(0)
, mFrameType(FrameType::None)
{
@ -83,36 +82,6 @@ ServiceWorkerClientInfo::ServiceWorkerClientInfo(nsIDocument* aDoc, uint32_t aOr
}
}
bool
ServiceWorkerClientInfo::operator<(const ServiceWorkerClientInfo& aRight) const
{
// Note: the mLastFocusTime comparisons are reversed because we need to
// put most recently focused values first. The mOrdinal comparison is
// normal, though, because otherwise we want normal creation order.
if (mLastFocusTime == aRight.mLastFocusTime) {
return mOrdinal < aRight.mOrdinal;
}
if (mLastFocusTime.IsNull()) {
return false;
}
if (aRight.mLastFocusTime.IsNull()) {
return true;
}
return mLastFocusTime > aRight.mLastFocusTime;
}
bool
ServiceWorkerClientInfo::operator==(const ServiceWorkerClientInfo& aRight) const
{
return mLastFocusTime == aRight.mLastFocusTime &&
mOrdinal == aRight.mOrdinal &&
mClientId == aRight.mClientId;
}
JSObject*
ServiceWorkerClient::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{

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

@ -31,19 +31,15 @@ class ServiceWorkerClientInfo final
friend class ServiceWorkerWindowClient;
public:
explicit ServiceWorkerClientInfo(nsIDocument* aDoc, uint32_t aOrdinal = 0);
explicit ServiceWorkerClientInfo(nsIDocument* aDoc);
const nsString& ClientId() const
{
return mClientId;
}
bool operator<(const ServiceWorkerClientInfo& aRight) const;
bool operator==(const ServiceWorkerClientInfo& aRight) const;
private:
const mozilla::dom::ClientType mType;
const uint32_t mOrdinal;
nsString mClientId;
uint64_t mWindowId;
nsString mUrl;

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

@ -2974,55 +2974,61 @@ ServiceWorkerManager::GetAllClients(nsIPrincipal* aPrincipal,
return;
}
// Get a list of Client documents out of the observer service
AutoTArray<nsCOMPtr<nsIDocument>, 32> docList;
bool loop = true;
while (NS_SUCCEEDED(enumerator->HasMoreElements(&loop)) && loop) {
nsCOMPtr<nsISupports> ptr;
rv = enumerator->GetNext(getter_AddRefs(ptr));
if (NS_WARN_IF(NS_FAILED(rv))) {
continue;
}
nsCOMPtr<nsIDocument> doc = do_QueryInterface(ptr);
if (!doc || !doc->GetWindow()) {
continue;
auto ProcessDocument = [&aDocuments](nsIPrincipal* aPrincipal, nsIDocument* aDoc) {
if (!aDoc || !aDoc->GetWindow()) {
return;
}
bool equals = false;
Unused << aPrincipal->Equals(doc->NodePrincipal(), &equals);
aPrincipal->Equals(aDoc->NodePrincipal(), &equals);
if (!equals) {
continue;
return;
}
// Treat http windows with devtools opened as secure if the correct devtools
// setting is enabled.
if (!doc->GetWindow()->GetServiceWorkersTestingEnabled() &&
if (!aDoc->GetWindow()->GetServiceWorkersTestingEnabled() &&
!Preferences::GetBool("dom.serviceWorkers.testing.enabled") &&
!IsFromAuthenticatedOrigin(doc)) {
continue;
!IsFromAuthenticatedOrigin(aDoc)) {
return;
}
if (!aIncludeUncontrolled && !mControlledDocuments.Contains(doc)) {
continue;
ServiceWorkerClientInfo clientInfo(aDoc);
aDocuments.AppendElement(aDoc);
};
// Since it's not simple to check whether a document is in
// mControlledDocuments, we take different code paths depending on whether we
// need to look at all documents. The common parts of the two loops are
// factored out into the ProcessDocument lambda.
if (aIncludeUncontrolled) {
bool loop = true;
while (NS_SUCCEEDED(enumerator->HasMoreElements(&loop)) && loop) {
nsCOMPtr<nsISupports> ptr;
rv = enumerator->GetNext(getter_AddRefs(ptr));
if (NS_WARN_IF(NS_FAILED(rv))) {
continue;
}
nsCOMPtr<nsIDocument> doc = do_QueryInterface(ptr);
ProcessDocument(aPrincipal, doc);
}
} else {
for (auto iter = mControlledDocuments.Iter(); !iter.Done(); iter.Next()) {
ServiceWorkerRegistrationInfo* thisRegistration = iter.UserData();
MOZ_ASSERT(thisRegistration);
if (!registration->mScope.Equals(thisRegistration->mScope)) {
continue;
}
docList.AppendElement(doc.forget());
nsCOMPtr<nsIDocument> doc = do_QueryInterface(iter.Key());
// All controlled documents must have an outer window.
MOZ_ASSERT(doc->GetWindow());
ProcessDocument(aPrincipal, doc);
}
}
// The observer service gives us the list in reverse creation order.
// We need to maintain creation order, so reverse the list before
// processing.
docList.Reverse();
// Finally convert to the list of ServiceWorkerClientInfo objects.
uint32_t ordinal = 0;
for (uint32_t i = 0; i < docList.Length(); ++i) {
aDocuments.AppendElement(ServiceWorkerClientInfo(docList[i], ordinal));
ordinal += 1;
}
aDocuments.Sort();
}
void