Bug 1594752, expose WindowGlobalParent's document title attribute to script, and fire a pagetitlechanged event on the frame/browser when it changes, r=nika

Differential Revision: https://phabricator.services.mozilla.com/D72561
This commit is contained in:
Neil Deakin 2020-05-13 19:25:45 +00:00
Родитель b8f7ac9956
Коммит c0e5a6c003
4 изменённых файлов: 24 добавлений и 2 удалений

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

@ -53,6 +53,7 @@ interface WindowGlobalParent : WindowContext {
readonly attribute Principal documentPrincipal;
readonly attribute Principal? contentBlockingAllowListPrincipal;
readonly attribute URI? documentURI;
readonly attribute DOMString documentTitle;
// Bit mask containing content blocking events that are recorded in
// the document's content blocking log.

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

@ -6,6 +6,7 @@
#include "mozilla/dom/WindowGlobalParent.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/ipc/InProcessParent.h"
#include "mozilla/dom/BrowserBridgeParent.h"
@ -279,7 +280,27 @@ IPCResult WindowGlobalParent::RecvUpdateDocumentPrincipal(
}
mozilla::ipc::IPCResult WindowGlobalParent::RecvUpdateDocumentTitle(
const nsString& aTitle) {
if (mDocumentTitle == aTitle) {
return IPC_OK();
}
mDocumentTitle = aTitle;
// Send a pagetitlechanged event only for changes to the title
// for top-level frames.
if (!BrowsingContext()->IsTop()) {
return IPC_OK();
}
Element* frameElement = BrowsingContext()->GetEmbedderElement();
if (!frameElement) {
return IPC_OK();
}
(new AsyncEventDispatcher(frameElement, NS_LITERAL_STRING("pagetitlechanged"),
CanBubble::eYes, ChromeOnlyDispatch::eYes))
->RunDOMEventWhenSafe();
return IPC_OK();
}

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

@ -120,7 +120,7 @@ class WindowGlobalParent final : public WindowContext,
// The current URI which loaded in the document.
nsIURI* GetDocumentURI() override { return mDocumentURI; }
const nsString& GetDocumentTitle() const { return mDocumentTitle; }
void GetDocumentTitle(nsAString& aTitle) const { aTitle = mDocumentTitle; }
nsIPrincipal* GetContentBlockingAllowListPrincipal() const {
return mDocContentBlockingAllowListPrincipal;

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

@ -176,7 +176,7 @@ nsString MediaSessionController::GetDefaultTitle() const {
}
defaultTitle.AppendLiteral(" is playing media");
} else {
defaultTitle = globalParent->GetDocumentTitle();
globalParent->GetDocumentTitle(defaultTitle);
}
return defaultTitle;
}