diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 20c7275c15f0..eab678bc5089 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -10285,11 +10285,9 @@ nsGlobalWindow::GetSessionStorage(ErrorResult& aError) return nullptr; } - nsCOMPtr loadContext = do_QueryInterface(docShell); - nsCOMPtr storage; aError = storageManager->CreateStorage(this, principal, documentURI, - loadContext && loadContext->UsePrivateBrowsing(), + IsPrivateBrowsing(), getter_AddRefs(storage)); if (aError.Failed()) { return nullptr; @@ -10365,12 +10363,9 @@ nsGlobalWindow::GetLocalStorage(ErrorResult& aError) mDoc->GetDocumentURI(documentURI); } - nsIDocShell* docShell = GetDocShell(); - nsCOMPtr loadContext = do_QueryInterface(docShell); - nsCOMPtr storage; aError = storageManager->CreateStorage(this, principal, documentURI, - loadContext && loadContext->UsePrivateBrowsing(), + IsPrivateBrowsing(), getter_AddRefs(storage)); if (aError.Failed()) { return nullptr; @@ -11200,9 +11195,7 @@ nsGlobalWindow::Observe(nsISupports* aSubject, const char* aTopic, return NS_OK; } - nsCOMPtr loadContext = do_QueryInterface(GetDocShell()); - bool isPrivate = loadContext && loadContext->UsePrivateBrowsing(); - if (changingStorage->IsPrivate() != isPrivate) { + if (changingStorage->IsPrivate() != IsPrivateBrowsing()) { return NS_OK; } @@ -12634,6 +12627,13 @@ nsGlobalWindow::SecurityCheckURL(const char *aURL) return NS_OK; } +bool +nsGlobalWindow::IsPrivateBrowsing() +{ + nsCOMPtr loadContext = do_QueryInterface(GetDocShell()); + return loadContext && loadContext->UsePrivateBrowsing(); +} + void nsGlobalWindow::FlushPendingNotifications(mozFlushType aType) { diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index dbc274e26e6b..067999f83714 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -1351,6 +1351,7 @@ public: already_AddRefed GetTreeOwnerWindow(); already_AddRefed GetWebBrowserChrome(); nsresult SecurityCheckURL(const char *aURL); + bool IsPrivateBrowsing(); bool PopupWhitelisted(); PopupControlState RevisePopupAbuseLevel(PopupControlState);