Bug 1721306, hide the tooltip when deactivating a BrowserParent, r=peterv

Differential Revision: https://phabricator.services.mozilla.com/D121756
This commit is contained in:
Olli Pettay 2021-08-06 19:33:04 +00:00
parent 547568f702
commit 6492d1564b
5 changed files with 61 additions and 4 deletions

View File

@ -19,6 +19,7 @@
#include "mozilla/StaticPrefs_fission.h"
#include "mozilla/Tuple.h"
#include "mozilla/dom/BrowserParent.h"
#include "mozilla/dom/CanonicalBrowsingContext.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/CSPMessageUtils.h"
@ -1376,8 +1377,12 @@ void SessionHistoryEntry::SetFrameLoader(nsFrameLoader* aFrameLoader) {
MOZ_RELEASE_ASSERT(!aFrameLoader || mozilla::BFCacheInParent());
SharedInfo()->SetFrameLoader(aFrameLoader);
if (aFrameLoader) {
if (BrowserParent* bp = aFrameLoader->GetBrowserParent()) {
bp->Deactivated();
if (BrowsingContext* bc = aFrameLoader->GetMaybePendingBrowsingContext()) {
bc->PreOrderWalk([&](BrowsingContext* aContext) {
if (BrowserParent* bp = aContext->Canonical()->GetBrowserParent()) {
bp->Deactivated();
}
});
}
// When a new frameloader is stored, try to evict some older

View File

@ -235,7 +235,8 @@ BrowserParent::BrowserParent(ContentParent* aManager, const TabId& aTabId,
mHasPresented(false),
mIsReadyToHandleInputEvents(false),
mIsMouseEnterIntoWidgetEventSuppressed(false),
mLockedNativePointer(false) {
mLockedNativePointer(false),
mShowingTooltip(false) {
MOZ_ASSERT(aManager);
// When the input event queue is disabled, we don't need to handle the case
// that some input events are dispatched before PBrowserConstructor.
@ -597,6 +598,10 @@ void BrowserParent::RemoveWindowListeners() {
}
void BrowserParent::Deactivated() {
if (mShowingTooltip) {
// Reuse the normal tooltip hiding method.
mozilla::Unused << RecvHideTooltip();
}
UnlockNativePointer();
UnsetTopLevelWebFocus(this);
UnsetLastMouseRemoteTarget(this);
@ -2296,11 +2301,16 @@ mozilla::ipc::IPCResult BrowserParent::RecvShowTooltip(
nsCOMPtr<Element> el = do_QueryInterface(flo);
if (!el) return IPC_OK();
xulBrowserWindow->ShowTooltip(aX, aY, aTooltip, aDirection, el);
if (NS_SUCCEEDED(
xulBrowserWindow->ShowTooltip(aX, aY, aTooltip, aDirection, el))) {
mShowingTooltip = true;
}
return IPC_OK();
}
mozilla::ipc::IPCResult BrowserParent::RecvHideTooltip() {
mShowingTooltip = false;
nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow = GetXULBrowserWindow();
if (!xulBrowserWindow) {
return IPC_OK();

View File

@ -973,6 +973,9 @@ class BrowserParent final : public PBrowserParent,
// True after RecvLockNativePointer has been called and until
// UnlockNativePointer has been called.
bool mLockedNativePointer : 1;
// True between ShowTooltip and HideTooltip messages.
bool mShowingTooltip : 1;
};
struct MOZ_STACK_CLASS BrowserParent::AutoUseNewTab final {

View File

@ -20,6 +20,7 @@ skip-if =
!crashreporter
verify
[browser_domainPolicy.js]
[browser_hide_tooltip.js]
[browser_memory_distribution_telemetry.js]
skip-if = true
!e10s # This is an e10s only probe, but the test is currently broken. See Bug 1449991

View File

@ -0,0 +1,38 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function test_hiding_tooltip() {
let page1 = "data:text/html,<html title='title'><body>page 1<body></html>";
let page2 = "data:text/html,<html><body>page 2</body></html>";
let tab = await BrowserTestUtils.openNewForegroundTab({
gBrowser,
opening: page1,
});
let popup = new Promise(function(resolve) {
window.addEventListener("popupshown", resolve, { once: true });
});
// Fire a mousemove to trigger the tooltip.
EventUtils.synthesizeMouseAtCenter(gBrowser.selectedBrowser, {
type: "mousemove",
});
await popup;
let hiding = new Promise(function(resolve) {
window.addEventListener("popuphiding", resolve, { once: true });
});
let loaded = BrowserTestUtils.browserLoaded(
gBrowser.selectedBrowser,
false,
page2
);
BrowserTestUtils.loadURI(gBrowser, page2);
await loaded;
await hiding;
ok(true, "Should have hidden the tooltip");
BrowserTestUtils.removeTab(tab);
});