From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- .../aboutwindowsmessages/AboutWindowsMessages.cpp | 93 ++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 toolkit/components/aboutwindowsmessages/AboutWindowsMessages.cpp (limited to 'toolkit/components/aboutwindowsmessages/AboutWindowsMessages.cpp') diff --git a/toolkit/components/aboutwindowsmessages/AboutWindowsMessages.cpp b/toolkit/components/aboutwindowsmessages/AboutWindowsMessages.cpp new file mode 100644 index 0000000000..4d9f94f593 --- /dev/null +++ b/toolkit/components/aboutwindowsmessages/AboutWindowsMessages.cpp @@ -0,0 +1,93 @@ +/* -*- 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/. */ + +#include "AboutWindowsMessages.h" + +#include "mozilla/ClearOnShutdown.h" +#include "mozilla/dom/Promise.h" +#include "mozilla/StaticPtr.h" +#include "nsThreadUtils.h" +#include "nsPIDOMWindow.h" +#include "nsGlobalWindowOuter.h" +#include "nsServiceManagerUtils.h" +#include "nsIWindowMediator.h" +#include "nsIAppWindow.h" +#include "nsIBaseWindow.h" +#include "nsDocShellTreeOwner.h" +#include "mozilla/WidgetUtils.h" +#include "mozilla/widget/nsWindowLoggedMessages.h" + +namespace mozilla { + +static StaticRefPtr sSingleton; + +NS_IMPL_ISUPPORTS(AboutWindowsMessages, nsIAboutWindowsMessages); + +/*static*/ +already_AddRefed AboutWindowsMessages::GetSingleton() { + if (!sSingleton) { + sSingleton = new AboutWindowsMessages; + ClearOnShutdown(&sSingleton); + } + + return do_AddRef(sSingleton); +} + +static bool GetWindowTitleFromWindow(const nsCOMPtr& window, + nsAutoString& title) { + nsIDocShell* docShell = window->GetDocShell(); + if (docShell) { + nsCOMPtr parentTreeOwner; + docShell->GetTreeOwner(getter_AddRefs(parentTreeOwner)); + nsCOMPtr baseWindow(do_QueryInterface(parentTreeOwner)); + baseWindow->GetTitle(title); + return true; + } + return false; +} + +NS_IMETHODIMP +AboutWindowsMessages::GetMessages(mozIDOMWindowProxy* currentWindow, + nsTArray>& messages, + nsTArray& windowTitles) { + messages.Clear(); + // Display the current window's messages first + auto currentWindowOuter = nsPIDOMWindowOuter::From(currentWindow); + RefPtr currentWidget = + widget::WidgetUtils::DOMWindowToWidget(currentWindowOuter); + nsAutoString currentWindowTitle; + if (GetWindowTitleFromWindow(currentWindowOuter, currentWindowTitle)) { + nsTArray windowMessages; + widget::GetLatestWindowMessages(currentWidget, windowMessages); + windowTitles.AppendElement(currentWindowTitle); + messages.EmplaceBack(std::move(windowMessages)); + } + nsCOMPtr mediator( + do_GetService(NS_WINDOWMEDIATOR_CONTRACTID)); + nsCOMPtr windowEnumerator; + mediator->GetEnumerator(nullptr, getter_AddRefs(windowEnumerator)); + if (!windowEnumerator) return NS_ERROR_FAILURE; + bool more; + while (NS_SUCCEEDED(windowEnumerator->HasMoreElements(&more)) && more) { + nsCOMPtr isupports; + if (NS_FAILED(windowEnumerator->GetNext(getter_AddRefs(isupports)))) break; + nsCOMPtr window = do_QueryInterface(isupports); + NS_ASSERTION(window, "not an nsPIDOMWindowOuter"); + RefPtr windowWidget = + widget::WidgetUtils::DOMWindowToWidget(window); + if (&*windowWidget != &*currentWidget) { + nsAutoString title; + if (GetWindowTitleFromWindow(window, title)) { + nsTArray windowMessages; + widget::GetLatestWindowMessages(windowWidget, windowMessages); + windowTitles.AppendElement(title); + messages.EmplaceBack(std::move(windowMessages)); + } + } + } + return NS_OK; +} +} // namespace mozilla -- cgit v1.2.3