2016-10-29 01:57:50 +03:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
2016-10-07 00:23:08 +03:00
|
|
|
#include "mozilla/dom/DocGroup.h"
|
2016-10-28 21:25:43 +03:00
|
|
|
#include "mozilla/dom/TabGroup.h"
|
2016-10-07 00:23:08 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
#include "nsIDocShell.h"
|
2016-10-29 01:57:50 +03:00
|
|
|
#include "nsIEffectiveTLDService.h"
|
|
|
|
#include "nsIURI.h"
|
2016-10-07 00:23:08 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2017-01-17 03:10:27 +03:00
|
|
|
/* static */ nsresult
|
2016-10-07 00:23:08 +03:00
|
|
|
DocGroup::GetKey(nsIPrincipal* aPrincipal, nsACString& aKey)
|
|
|
|
{
|
|
|
|
aKey.Truncate();
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = aPrincipal->GetURI(getter_AddRefs(uri));
|
2017-01-17 03:10:27 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return NS_OK; // aKey is the empty string
|
|
|
|
}
|
|
|
|
|
2016-11-02 10:24:00 +03:00
|
|
|
// GetBaseDomain works fine if |uri| is null, but it outputs a warning
|
|
|
|
// which ends up cluttering the logs.
|
2017-01-17 03:10:27 +03:00
|
|
|
if (!uri) {
|
|
|
|
return NS_OK; // aKey is the empty string
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIEffectiveTLDService> tldService =
|
|
|
|
do_GetService(NS_EFFECTIVETLDSERVICE_CONTRACTID);
|
|
|
|
if (!tldService) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2016-10-07 00:23:08 +03:00
|
|
|
}
|
2017-01-17 03:10:27 +03:00
|
|
|
|
|
|
|
rv = tldService->GetBaseDomain(uri, 0, aKey);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aKey.Truncate();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK; // aKey may be the empty string
|
2016-10-07 00:23:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DocGroup::RemoveDocument(nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mDocuments.Contains(aDocument));
|
|
|
|
mDocuments.RemoveElement(aDocument);
|
|
|
|
}
|
|
|
|
|
|
|
|
DocGroup::DocGroup(TabGroup* aTabGroup, const nsACString& aKey)
|
|
|
|
: mKey(aKey), mTabGroup(aTabGroup)
|
|
|
|
{
|
|
|
|
// This method does not add itself to mTabGroup->mDocGroups as the caller does it for us.
|
|
|
|
}
|
|
|
|
|
|
|
|
DocGroup::~DocGroup()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mDocuments.IsEmpty());
|
|
|
|
mTabGroup->mDocGroups.RemoveEntry(mKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(DocGroup, nsISupports)
|
|
|
|
|
2016-10-29 01:25:08 +03:00
|
|
|
nsresult
|
|
|
|
DocGroup::Dispatch(const char* aName,
|
|
|
|
TaskCategory aCategory,
|
|
|
|
already_AddRefed<nsIRunnable>&& aRunnable)
|
|
|
|
{
|
2016-11-23 08:14:39 +03:00
|
|
|
return mTabGroup->Dispatch(aName, aCategory, Move(aRunnable));
|
|
|
|
}
|
|
|
|
|
2016-12-16 00:48:14 +03:00
|
|
|
nsIEventTarget*
|
2016-11-23 08:14:39 +03:00
|
|
|
DocGroup::EventTargetFor(TaskCategory aCategory) const
|
|
|
|
{
|
|
|
|
return mTabGroup->EventTargetFor(aCategory);
|
2016-10-29 01:25:08 +03:00
|
|
|
}
|
|
|
|
|
2016-10-07 00:23:08 +03:00
|
|
|
}
|
|
|
|
}
|