Commit 20139e60 authored by Tim Huang's avatar Tim Huang
Browse files

Bug 1842030 - Part 2: Check the global private browsing state for...

Bug 1842030 - Part 2: Check the global private browsing state for HttpBaseChannel::IsBrowsingContextDiscarded() if the loadGroup is not avaiable. r=necko-reviewers,jesup, a=dmeehan

The HttpBaseChannel::IsBrowsingContextDiscarded() did always return
false if the loadGroup is not avaiable. But, this may not be correct for
the private channels if the private session has been ended. To fix this,
we make the function to check the global private browsing state
if the loadGroup is not available for private channels.

Depends on D184010

Differential Revision: https://phabricator.services.mozilla.com/D184479
parent a00674cf
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -2396,7 +2396,23 @@ void HttpBaseChannel::NotifySetCookie(const nsACString& aCookie) {
}

bool HttpBaseChannel::IsBrowsingContextDiscarded() const {
  return mLoadGroup && mLoadGroup->GetIsBrowsingContextDiscarded();
  // If there is no loadGroup attached to the current channel, we check the
  // global private browsing state for the private channel instead. For
  // non-private channel, we will always return false here.
  //
  // Note that we can only access the global private browsing state in the
  // parent process. So, we will fallback to just return false in the content
  // process.
  if (!mLoadGroup) {
    if (!XRE_IsParentProcess()) {
      return false;
    }

    return mLoadInfo->GetOriginAttributes().mPrivateBrowsingId != 0 &&
           !dom::CanonicalBrowsingContext::IsPrivateBrowsingActive();
  }

  return mLoadGroup->GetIsBrowsingContextDiscarded();
}

// https://mikewest.github.io/corpp/#process-navigation-response
+1 −0
Original line number Diff line number Diff line
@@ -676,6 +676,7 @@ class HttpBaseChannel : public nsHashPropertyBag,
  friend class OpaqueResponseBlocker;
  friend class PrivateBrowsingChannel<HttpBaseChannel>;
  friend class InterceptFailedOnStop;
  friend class HttpChannelParent;

 protected:
  // this section is for main-thread-only object
+12 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include "mozilla/net/NeckoParent.h"
#include "mozilla/InputStreamLengthHelper.h"
#include "mozilla/IntegerPrintfMacros.h"
#include "mozilla/Preferences.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/StoragePrincipalHelper.h"
#include "mozilla/UniquePtr.h"
@@ -2108,6 +2109,17 @@ void HttpChannelParent::SetCookie(nsCString&& aCookie) {
  LOG(("HttpChannelParent::SetCookie [this=%p]", this));
  MOZ_ASSERT(!mAfterOnStartRequestBegun);
  MOZ_ASSERT(mCookie.IsEmpty());

  // The loadGroup of the channel in the parent process could be null in the
  // XPCShell content process test, see test_cookiejars_wrap.js. In this case,
  // we cannot explicitly set the loadGroup for the parent channel because it's
  // created from the content process. To workaround this, we add a testing pref
  // to skip this check.
  if (!Preferences::GetBool(
          "network.cookie.skip_browsing_context_check_in_parent_for_testing") &&
      mChannel->IsBrowsingContextDiscarded()) {
    return;
  }
  mCookie = std::move(aCookie);
}

+17 −0
Original line number Diff line number Diff line
@@ -60,6 +60,23 @@ function setupChannel(path) {
  });
  chan.loadInfo.originAttributes = tests[i].originAttributes;
  chan.QueryInterface(Ci.nsIHttpChannel);

  let loadGroup = Cc["@mozilla.org/network/load-group;1"].createInstance(
    Ci.nsILoadGroup
  );

  if (chan.loadInfo.originAttributes.privateBrowsingId == 0) {
    loadGroup.notificationCallbacks = Cu.createLoadContext();
    chan.loadGroup = loadGroup;

    chan.notificationCallbacks = Cu.createLoadContext();
  } else {
    loadGroup.notificationCallbacks = Cu.createPrivateLoadContext();
    chan.loadGroup = loadGroup;

    chan.notificationCallbacks = Cu.createPrivateLoadContext();
  }

  return chan;
}

+4 −0
Original line number Diff line number Diff line
@@ -4,6 +4,10 @@ function run_test() {
    "network.cookieJarSettings.unblocked_for_testing",
    true
  );
  Services.prefs.setBoolPref(
    "network.cookie.skip_browsing_context_check_in_parent_for_testing",
    true
  );
  Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
  run_test_in_child("../unit/test_cookiejars.js");
}