зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1585306 - nsILoadGroup observes last-pb-context-exit to monitor the browsing context, r=mayhemer
Differential Revision: https://phabricator.services.mozilla.com/D66745 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
f1cec250a8
Коммит
4a7c415e8a
|
@ -95,4 +95,11 @@ interface nsILoadGroup : nsIRequest
|
|||
* the docShell has created the default request.)
|
||||
*/
|
||||
attribute nsLoadFlags defaultLoadFlags;
|
||||
|
||||
/**
|
||||
* Returns true if the loadGroup belongs to a discarded context, such as, a
|
||||
* terminated private browsing session.
|
||||
*/
|
||||
[infallible]
|
||||
readonly attribute boolean isBrowsingContextDiscarded;
|
||||
};
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "nsArrayEnumerator.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "mozilla/Logging.h"
|
||||
#include "nsString.h"
|
||||
#include "nsTArray.h"
|
||||
|
@ -91,6 +92,7 @@ nsLoadGroup::nsLoadGroup()
|
|||
mStatus(NS_OK),
|
||||
mIsCanceling(false),
|
||||
mDefaultLoadIsTimed(false),
|
||||
mBrowsingContextDiscarded(false),
|
||||
mTimedRequests(0),
|
||||
mCachedRequests(0) {
|
||||
LOG(("LOADGROUP [%p]: Created.\n", this));
|
||||
|
@ -106,6 +108,11 @@ nsLoadGroup::~nsLoadGroup() {
|
|||
mRequestContextService->RemoveRequestContext(mRequestContext->GetID());
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
||||
if (os) {
|
||||
Unused << os->RemoveObserver(this, "last-pb-context-exited");
|
||||
}
|
||||
|
||||
LOG(("LOADGROUP [%p]: Destroyed.\n", this));
|
||||
}
|
||||
|
||||
|
@ -113,7 +120,7 @@ nsLoadGroup::~nsLoadGroup() {
|
|||
// nsISupports methods:
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsLoadGroup, nsILoadGroup, nsILoadGroupChild, nsIRequest,
|
||||
nsISupportsPriority, nsISupportsWeakReference)
|
||||
nsISupportsPriority, nsISupportsWeakReference, nsIObserver)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIRequest methods:
|
||||
|
@ -960,6 +967,31 @@ nsresult nsLoadGroup::Init() {
|
|||
getter_AddRefs(mRequestContext));
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
||||
NS_ENSURE_STATE(os);
|
||||
|
||||
Unused << os->AddObserver(this, "last-pb-context-exited", true);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLoadGroup::Observe(nsISupports* aSubject, const char* aTopic,
|
||||
const char16_t* aData) {
|
||||
MOZ_ASSERT(!strcmp(aTopic, "last-pb-context-exited"));
|
||||
|
||||
OriginAttributes attrs = nsContentUtils::GetOriginAttributes(this);
|
||||
if (attrs.mPrivateBrowsingId == 0) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
mBrowsingContextDiscarded = true;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLoadGroup::GetIsBrowsingContextDiscarded(bool* aIsBrowsingContextDiscarded) {
|
||||
*aIsBrowsingContextDiscarded = mBrowsingContextDiscarded;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "nsILoadGroup.h"
|
||||
#include "nsILoadGroupChild.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsWeakReference.h"
|
||||
#include "nsISupportsPriority.h"
|
||||
|
@ -23,6 +24,7 @@ namespace net {
|
|||
|
||||
class nsLoadGroup : public nsILoadGroup,
|
||||
public nsILoadGroupChild,
|
||||
public nsIObserver,
|
||||
public nsISupportsPriority,
|
||||
public nsSupportsWeakReference {
|
||||
public:
|
||||
|
@ -44,6 +46,10 @@ class nsLoadGroup : public nsILoadGroup,
|
|||
// nsISupportsPriority methods:
|
||||
NS_DECL_NSISUPPORTSPRIORITY
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// nsIObserver methods:
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// nsLoadGroup methods:
|
||||
|
||||
|
@ -85,6 +91,7 @@ class nsLoadGroup : public nsILoadGroup,
|
|||
nsresult mStatus;
|
||||
bool mIsCanceling;
|
||||
bool mDefaultLoadIsTimed;
|
||||
bool mBrowsingContextDiscarded;
|
||||
|
||||
/* Telemetry */
|
||||
mozilla::TimeStamp mDefaultRequestCreationTime;
|
||||
|
|
|
@ -2132,6 +2132,14 @@ void HttpBaseChannel::NotifySetCookie(const nsACString& aCookie) {
|
|||
}
|
||||
}
|
||||
|
||||
bool HttpBaseChannel::IsBrowsingContextDiscarded() const {
|
||||
if (mLoadGroup && mLoadGroup->GetIsBrowsingContextDiscarded()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
HttpBaseChannel::SetCookie(const nsACString& aCookieHeader) {
|
||||
if (mLoadFlags & LOAD_ANONYMOUS) return NS_OK;
|
||||
|
|
|
@ -601,6 +601,8 @@ class HttpBaseChannel : public nsHashPropertyBag,
|
|||
|
||||
void MaybeFlushConsoleReports();
|
||||
|
||||
bool IsBrowsingContextDiscarded() const;
|
||||
|
||||
friend class PrivateBrowsingChannel<HttpBaseChannel>;
|
||||
friend class InterceptFailedOnStop;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче