Commit 47a2086b authored by Marian-Vasile Laza's avatar Marian-Vasile Laza
Browse files

Backed out changeset 4854ff4fff72 (bug 1701303) for causing bustages on nsDocShell.cpp. CLOSED TREE

parent e0f049bb
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ skip-if = verify
[browser_privatebrowsing_downloadLastDir_toggle.js]
[browser_privatebrowsing_favicon.js]
[browser_privatebrowsing_history_shift_click.js]
[browser_privatebrowsing_last_private_browsing_context_exited.js]
[browser_privatebrowsing_lastpbcontextexited.js]
[browser_privatebrowsing_localStorage.js]
[browser_privatebrowsing_localStorage_before_after.js]
+0 −66
Original line number 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_no_notification_when_pb_autostart() {
  let observedLastPBContext = false;
  let observerExited = {
    observe(aSubject, aTopic, aData) {
      observedLastPBContext = true;
    },
  };
  Services.obs.addObserver(observerExited, "last-pb-context-exited");

  await SpecialPowers.pushPrefEnv({
    set: [["browser.privatebrowsing.autostart", true]],
  });

  let win = await BrowserTestUtils.openNewBrowserWindow();

  let browser = win.gBrowser.selectedTab.linkedBrowser;
  ok(browser.browsingContext.usePrivateBrowsing, "should use private browsing");

  await BrowserTestUtils.closeWindow(win);

  await SpecialPowers.popPrefEnv();
  Services.obs.removeObserver(observerExited, "last-pb-context-exited");
  ok(!observedLastPBContext, "No last-pb-context-exited notification seen");
});

add_task(async function test_notification_when_about_preferences() {
  let observedLastPBContext = false;
  let observerExited = {
    observe(aSubject, aTopic, aData) {
      observedLastPBContext = true;
    },
  };
  Services.obs.addObserver(observerExited, "last-pb-context-exited");

  let win = await BrowserTestUtils.openNewBrowserWindow({ private: true });

  let browser = win.gBrowser.selectedTab.linkedBrowser;
  ok(browser.browsingContext.usePrivateBrowsing, "should use private browsing");
  ok(browser.browsingContext.isContent, "should be content browsing context");

  let tab = await BrowserTestUtils.addTab(win.gBrowser, "about:preferences");
  ok(
    tab.linkedBrowser.browsingContext.usePrivateBrowsing,
    "should use private browsing"
  );
  ok(
    tab.linkedBrowser.browsingContext.isContent,
    "should be content browsing context"
  );

  let tabClose = BrowserTestUtils.waitForTabClosing(win.gBrowser.selectedTab);
  BrowserTestUtils.removeTab(win.gBrowser.selectedTab);
  await tabClose;

  ok(!observedLastPBContext, "No last-pb-context-exited notification seen");

  await BrowserTestUtils.closeWindow(win);

  Services.obs.removeObserver(observerExited, "last-pb-context-exited");
  ok(observedLastPBContext, "No last-pb-context-exited notification seen");
});
+0 −8
Original line number Diff line number Diff line
@@ -799,10 +799,6 @@ void BrowsingContext::Attach(bool aFromIPC, ContentParent* aOriginProcess) {
    obs->NotifyWhenScriptSafe(ToSupports(this), "browsing-context-attached",
                              nullptr);
  }

  if (XRE_IsParentProcess()) {
    Canonical()->CanonicalAttach();
  }
}

void BrowsingContext::Detach(bool aFromIPC) {
@@ -1592,10 +1588,6 @@ NS_IMETHODIMP BrowsingContext::SetPrivateBrowsing(bool aPrivateBrowsing) {
    if (IsContent()) {
      mOriginAttributes.SyncAttributesWithPrivateBrowsing(aPrivateBrowsing);
    }

    if (XRE_IsParentProcess()) {
      Canonical()->AdjustPrivateBrowsingCount(aPrivateBrowsing);
    }
  }
  AssertOriginAttributesMatchPrivateBrowsing();

+0 −84
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@
#include "mozilla/NullPrincipal.h"
#include "mozilla/StaticPrefs_docshell.h"
#include "mozilla/StaticPrefs_fission.h"
#include "mozilla/Telemetry.h"
#include "nsIWebNavigation.h"
#include "mozilla/MozPromiseInlines.h"
#include "nsDocShell.h"
@@ -61,49 +60,6 @@ extern mozilla::LazyLogModule gSHIPBFCacheLog;
#define AUTOPLAY_LOG(msg, ...) \
  MOZ_LOG(gAutoplayPermissionLog, LogLevel::Debug, (msg, ##__VA_ARGS__))

static mozilla::LazyLogModule sPBContext("PBContext");

// Global count of canonical browsing contexts with the private attribute set
static uint32_t gNumberOfPrivateContexts = 0;

static void IncreasePrivateCount() {
  gNumberOfPrivateContexts++;
  MOZ_LOG(sPBContext, mozilla::LogLevel::Debug,
          ("%s: Private browsing context count %d -> %d", __func__,
           gNumberOfPrivateContexts - 1, gNumberOfPrivateContexts));
  if (gNumberOfPrivateContexts > 1) {
    return;
  }

  static bool sHasSeenPrivateContext = false;
  if (!sHasSeenPrivateContext) {
    sHasSeenPrivateContext = true;
    mozilla::Telemetry::ScalarSet(
        mozilla::Telemetry::ScalarID::DOM_PARENTPROCESS_PRIVATE_WINDOW_USED,
        true);
  }
}

static void DecreasePrivateCount() {
  MOZ_ASSERT(gNumberOfPrivateContexts > 0);
  gNumberOfPrivateContexts--;

  MOZ_LOG(sPBContext, mozilla::LogLevel::Debug,
          ("%s: Private browsing context count %d -> %d", __func__,
           gNumberOfPrivateContexts + 1, gNumberOfPrivateContexts));
  if (!gNumberOfPrivateContexts &&
      !mozilla::Preferences::GetBool("browser.privatebrowsing.autostart")) {
    nsCOMPtr<nsIObserverService> observerService =
        mozilla::services::GetObserverService();
    if (observerService) {
      MOZ_LOG(sPBContext, mozilla::LogLevel::Debug,
              ("%s: last-pb-context-exited fired", __func__));
      observerService->NotifyObservers(nullptr, "last-pb-context-exited",
                                       nullptr);
    }
  }
}

namespace mozilla {
namespace dom {

@@ -1133,30 +1089,6 @@ void CanonicalBrowsingContext::CanonicalDiscard() {
  }

  CancelSessionStoreUpdate();

  if (UsePrivateBrowsing() && EverAttached() && IsContent()) {
    DecreasePrivateCount();
  }
}

void CanonicalBrowsingContext::CanonicalAttach() {
  if (UsePrivateBrowsing() && IsContent()) {
    IncreasePrivateCount();
  }
}

void CanonicalBrowsingContext::AdjustPrivateBrowsingCount(
    bool aPrivateBrowsing) {
  if (IsDiscarded() || !EverAttached() || IsChrome()) {
    return;
  }

  MOZ_DIAGNOSTIC_ASSERT(aPrivateBrowsing == UsePrivateBrowsing());
  if (aPrivateBrowsing) {
    IncreasePrivateCount();
  } else {
    DecreasePrivateCount();
  }
}

void CanonicalBrowsingContext::NotifyStartDelayedAutoplayMedia() {
@@ -1440,22 +1372,6 @@ nsresult CanonicalBrowsingContext::PendingRemotenessChange::FinishTopContent() {
  MOZ_RELEASE_ASSERT(frameLoaderOwner,
                     "embedder browser must be nsFrameLoaderOwner");

  // If we're process switching a browsing context in private browsing
  // mode we might decrease the private browsing count to '0', which
  // would make us fire "last-pb-context-exited" and drop the private
  // session. To prevent that we artificially increment the number of
  // private browsing contexts with '1' until the process switch is done.
  bool usePrivateBrowsing = mTarget->UsePrivateBrowsing();
  if (usePrivateBrowsing) {
    IncreasePrivateCount();
  }

  auto restorePrivateCount = MakeScopeExit([usePrivateBrowsing]() {
    if (usePrivateBrowsing) {
      DecreasePrivateCount();
    }
  });

  // Tell frontend code that this browser element is about to change process.
  nsresult rv = browser->BeforeChangeRemoteness();
  if (NS_FAILED(rv)) {
+0 −7
Original line number Diff line number Diff line
@@ -335,13 +335,6 @@ class CanonicalBrowsingContext final : public BrowsingContext {
  // Called when the browsing context is being discarded.
  void CanonicalDiscard();

  // Called when the browsing context is being attached.
  void CanonicalAttach();

  // Called when the browsing context private mode is changed after
  // being attached, but before being discarded.
  void AdjustPrivateBrowsingCount(bool aPrivateBrowsing);

  using Type = BrowsingContext::Type;
  CanonicalBrowsingContext(WindowContext* aParentWindow,
                           BrowsingContextGroup* aGroup,
Loading