зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1593969 Refactor nsWindowMemoryReporter.cpp r=ckerschb
Differential Revision: https://phabricator.services.mozilla.com/D51800 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
8f46d9d516
Коммит
44ce57c37d
|
@ -116,64 +116,60 @@ nsWindowMemoryReporter* nsWindowMemoryReporter::Get() {
|
||||||
return sWindowReporter;
|
return sWindowReporter;
|
||||||
}
|
}
|
||||||
|
|
||||||
static already_AddRefed<nsIURI> GetWindowURI(nsGlobalWindowInner* aWindow) {
|
static nsCString GetWindowURISpec(nsGlobalWindowInner* aWindow) {
|
||||||
NS_ENSURE_TRUE(aWindow, nullptr);
|
NS_ENSURE_TRUE(aWindow, NS_LITERAL_CSTRING(""));
|
||||||
|
|
||||||
nsCOMPtr<Document> doc = aWindow->GetExtantDoc();
|
nsCOMPtr<Document> doc = aWindow->GetExtantDoc();
|
||||||
nsCOMPtr<nsIURI> uri;
|
|
||||||
|
|
||||||
if (doc) {
|
if (doc) {
|
||||||
|
nsCOMPtr<nsIURI> uri;
|
||||||
uri = doc->GetDocumentURI();
|
uri = doc->GetDocumentURI();
|
||||||
|
return uri->GetSpecOrDefault();
|
||||||
}
|
}
|
||||||
|
nsCOMPtr<nsIScriptObjectPrincipal> scriptObjPrincipal =
|
||||||
|
do_QueryObject(aWindow);
|
||||||
|
NS_ENSURE_TRUE(scriptObjPrincipal, NS_LITERAL_CSTRING(""));
|
||||||
|
|
||||||
if (!uri) {
|
// GetPrincipal() will print a warning if the window does not have an outer
|
||||||
nsCOMPtr<nsIScriptObjectPrincipal> scriptObjPrincipal =
|
// window, so check here for an outer window first. This code is
|
||||||
do_QueryObject(aWindow);
|
// functionally correct if we leave out the GetOuterWindow() check, but we
|
||||||
NS_ENSURE_TRUE(scriptObjPrincipal, nullptr);
|
// end up printing a lot of warnings during debug mochitests.
|
||||||
|
if (!aWindow->GetOuterWindow()) {
|
||||||
// GetPrincipal() will print a warning if the window does not have an outer
|
return NS_LITERAL_CSTRING("");
|
||||||
// window, so check here for an outer window first. This code is
|
|
||||||
// functionally correct if we leave out the GetOuterWindow() check, but we
|
|
||||||
// end up printing a lot of warnings during debug mochitests.
|
|
||||||
if (aWindow->GetOuterWindow()) {
|
|
||||||
nsIPrincipal* principal = scriptObjPrincipal->GetPrincipal();
|
|
||||||
if (principal) {
|
|
||||||
principal->GetURI(getter_AddRefs(uri));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
nsIPrincipal* principal = scriptObjPrincipal->GetPrincipal();
|
||||||
return uri.forget();
|
if (!principal) {
|
||||||
|
return NS_LITERAL_CSTRING("");
|
||||||
|
}
|
||||||
|
nsCString spec;
|
||||||
|
principal->GetAsciiSpec(spec);
|
||||||
|
return spec;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Forward to the inner window if we need to when getting the window's URI.
|
// Forward to the inner window if we need to when getting the window's URI.
|
||||||
static already_AddRefed<nsIURI> GetWindowURI(nsGlobalWindowOuter* aWindow) {
|
static nsCString GetWindowURISpec(nsGlobalWindowOuter* aWindow) {
|
||||||
NS_ENSURE_TRUE(aWindow, nullptr);
|
NS_ENSURE_TRUE(aWindow, NS_LITERAL_CSTRING(""));
|
||||||
return GetWindowURI(aWindow->GetCurrentInnerWindowInternal());
|
return GetWindowURISpec(aWindow->GetCurrentInnerWindowInternal());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AppendWindowURI(nsGlobalWindowInner* aWindow, nsACString& aStr,
|
static void AppendWindowURI(nsGlobalWindowInner* aWindow, nsACString& aStr,
|
||||||
bool aAnonymize) {
|
bool aAnonymize) {
|
||||||
nsCOMPtr<nsIURI> uri = GetWindowURI(aWindow);
|
nsCString spec = GetWindowURISpec(aWindow);
|
||||||
|
|
||||||
if (uri) {
|
if (spec.IsEmpty()) {
|
||||||
if (aAnonymize && !aWindow->IsChromeWindow()) {
|
|
||||||
aStr.AppendPrintf("<anonymized-%" PRIu64 ">", aWindow->WindowID());
|
|
||||||
} else {
|
|
||||||
nsCString spec = uri->GetSpecOrDefault();
|
|
||||||
|
|
||||||
// A hack: replace forward slashes with '\\' so they aren't
|
|
||||||
// treated as path separators. Users of the reporters
|
|
||||||
// (such as about:memory) have to undo this change.
|
|
||||||
spec.ReplaceChar('/', '\\');
|
|
||||||
|
|
||||||
aStr += spec;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// If we're unable to find a URI, we're dealing with a chrome window with
|
// If we're unable to find a URI, we're dealing with a chrome window with
|
||||||
// no document in it (or somesuch), so we call this a "system window".
|
// no document in it (or somesuch), so we call this a "system window".
|
||||||
aStr += NS_LITERAL_CSTRING("[system]");
|
aStr += NS_LITERAL_CSTRING("[system]");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
if (aAnonymize && !aWindow->IsChromeWindow()) {
|
||||||
|
aStr.AppendPrintf("<anonymized-%" PRIu64 ">", aWindow->WindowID());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// A hack: replace forward slashes with '\\' so they aren't
|
||||||
|
// treated as path separators. Users of the reporters
|
||||||
|
// (such as about:memory) have to undo this change.
|
||||||
|
spec.ReplaceChar('/', '\\');
|
||||||
|
aStr += spec;
|
||||||
}
|
}
|
||||||
|
|
||||||
MOZ_DEFINE_MALLOC_SIZE_OF(WindowsMallocSizeOf)
|
MOZ_DEFINE_MALLOC_SIZE_OF(WindowsMallocSizeOf)
|
||||||
|
@ -227,18 +223,11 @@ static void CollectWindowReports(nsGlobalWindowInner* aWindow,
|
||||||
// Avoid calling aWindow->GetInProcessTop() if there's no outer window. It
|
// Avoid calling aWindow->GetInProcessTop() if there's no outer window. It
|
||||||
// will work just fine, but will spew a lot of warnings.
|
// will work just fine, but will spew a lot of warnings.
|
||||||
nsGlobalWindowOuter* top = nullptr;
|
nsGlobalWindowOuter* top = nullptr;
|
||||||
nsCOMPtr<nsIURI> location;
|
|
||||||
if (aWindow->GetOuterWindow()) {
|
if (aWindow->GetOuterWindow()) {
|
||||||
// Our window should have a null top iff it has a null docshell.
|
// Our window should have a null top iff it has a null docshell.
|
||||||
MOZ_ASSERT(!!aWindow->GetInProcessTopInternal() ==
|
MOZ_ASSERT(!!aWindow->GetInProcessTopInternal() ==
|
||||||
!!aWindow->GetDocShell());
|
!!aWindow->GetDocShell());
|
||||||
top = aWindow->GetInProcessTopInternal();
|
top = aWindow->GetInProcessTopInternal();
|
||||||
if (top) {
|
|
||||||
location = GetWindowURI(top);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!location) {
|
|
||||||
location = GetWindowURI(aWindow);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
windowPath += NS_LITERAL_CSTRING("window-objects/");
|
windowPath += NS_LITERAL_CSTRING("window-objects/");
|
||||||
|
|
Загрузка…
Ссылка в новой задаче