Commit 6492d156 authored by Olli Pettay's avatar Olli Pettay
Browse files

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

parent 547568f7
Loading
Loading
Loading
Loading
+7 −2
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@
#include "mozilla/StaticPrefs_fission.h"
#include "mozilla/StaticPrefs_fission.h"
#include "mozilla/Tuple.h"
#include "mozilla/Tuple.h"
#include "mozilla/dom/BrowserParent.h"
#include "mozilla/dom/BrowserParent.h"
#include "mozilla/dom/CanonicalBrowsingContext.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/CSPMessageUtils.h"
#include "mozilla/dom/CSPMessageUtils.h"
@@ -1376,9 +1377,13 @@ void SessionHistoryEntry::SetFrameLoader(nsFrameLoader* aFrameLoader) {
  MOZ_RELEASE_ASSERT(!aFrameLoader || mozilla::BFCacheInParent());
  MOZ_RELEASE_ASSERT(!aFrameLoader || mozilla::BFCacheInParent());
  SharedInfo()->SetFrameLoader(aFrameLoader);
  SharedInfo()->SetFrameLoader(aFrameLoader);
  if (aFrameLoader) {
  if (aFrameLoader) {
    if (BrowserParent* bp = aFrameLoader->GetBrowserParent()) {
    if (BrowsingContext* bc = aFrameLoader->GetMaybePendingBrowsingContext()) {
      bc->PreOrderWalk([&](BrowsingContext* aContext) {
        if (BrowserParent* bp = aContext->Canonical()->GetBrowserParent()) {
          bp->Deactivated();
          bp->Deactivated();
        }
        }
      });
    }


    // When a new frameloader is stored, try to evict some older
    // When a new frameloader is stored, try to evict some older
    // frameloaders. Non-SHIP session history has a similar call in
    // frameloaders. Non-SHIP session history has a similar call in
+12 −2
Original line number Original line Diff line number Diff line
@@ -235,7 +235,8 @@ BrowserParent::BrowserParent(ContentParent* aManager, const TabId& aTabId,
      mHasPresented(false),
      mHasPresented(false),
      mIsReadyToHandleInputEvents(false),
      mIsReadyToHandleInputEvents(false),
      mIsMouseEnterIntoWidgetEventSuppressed(false),
      mIsMouseEnterIntoWidgetEventSuppressed(false),
      mLockedNativePointer(false) {
      mLockedNativePointer(false),
      mShowingTooltip(false) {
  MOZ_ASSERT(aManager);
  MOZ_ASSERT(aManager);
  // When the input event queue is disabled, we don't need to handle the case
  // When the input event queue is disabled, we don't need to handle the case
  // that some input events are dispatched before PBrowserConstructor.
  // that some input events are dispatched before PBrowserConstructor.
@@ -597,6 +598,10 @@ void BrowserParent::RemoveWindowListeners() {
}
}


void BrowserParent::Deactivated() {
void BrowserParent::Deactivated() {
  if (mShowingTooltip) {
    // Reuse the normal tooltip hiding method.
    mozilla::Unused << RecvHideTooltip();
  }
  UnlockNativePointer();
  UnlockNativePointer();
  UnsetTopLevelWebFocus(this);
  UnsetTopLevelWebFocus(this);
  UnsetLastMouseRemoteTarget(this);
  UnsetLastMouseRemoteTarget(this);
@@ -2296,11 +2301,16 @@ mozilla::ipc::IPCResult BrowserParent::RecvShowTooltip(
  nsCOMPtr<Element> el = do_QueryInterface(flo);
  nsCOMPtr<Element> el = do_QueryInterface(flo);
  if (!el) return IPC_OK();
  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();
  return IPC_OK();
}
}


mozilla::ipc::IPCResult BrowserParent::RecvHideTooltip() {
mozilla::ipc::IPCResult BrowserParent::RecvHideTooltip() {
  mShowingTooltip = false;

  nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow = GetXULBrowserWindow();
  nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow = GetXULBrowserWindow();
  if (!xulBrowserWindow) {
  if (!xulBrowserWindow) {
    return IPC_OK();
    return IPC_OK();
+3 −0
Original line number Original line Diff line number Diff line
@@ -973,6 +973,9 @@ class BrowserParent final : public PBrowserParent,
  // True after RecvLockNativePointer has been called and until
  // True after RecvLockNativePointer has been called and until
  // UnlockNativePointer has been called.
  // UnlockNativePointer has been called.
  bool mLockedNativePointer : 1;
  bool mLockedNativePointer : 1;

  // True between ShowTooltip and HideTooltip messages.
  bool mShowingTooltip : 1;
};
};


struct MOZ_STACK_CLASS BrowserParent::AutoUseNewTab final {
struct MOZ_STACK_CLASS BrowserParent::AutoUseNewTab final {
+1 −0
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ skip-if =
  !crashreporter
  !crashreporter
  verify
  verify
[browser_domainPolicy.js]
[browser_domainPolicy.js]
[browser_hide_tooltip.js]
[browser_memory_distribution_telemetry.js]
[browser_memory_distribution_telemetry.js]
skip-if = true
skip-if = true
  !e10s # This is an e10s only probe, but the test is currently broken. See Bug 1449991
  !e10s # This is an e10s only probe, but the test is currently broken. See Bug 1449991
+38 −0
Original line number Original line Diff line number Diff line
/* 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);
});