зеркало из https://github.com/mozilla/pjs.git
Bug 729162 - Add per-docshell privacy mode transition observers. r=bz
This commit is contained in:
Родитель
5ca3d9ab23
Коммит
6a0874a709
|
@ -83,6 +83,7 @@ XPIDLSRCS = \
|
|||
nsIRefreshURI.idl \
|
||||
nsIContentViewerContainer.idl \
|
||||
nsIDocumentLoaderFactory.idl \
|
||||
nsIPrivacyTransitionObserver.idl \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
|
|
|
@ -107,6 +107,7 @@
|
|||
#include "nsIScriptChannel.h"
|
||||
#include "nsIOfflineCacheUpdate.h"
|
||||
#include "nsITimedChannel.h"
|
||||
#include "nsIPrivacyTransitionObserver.h"
|
||||
#include "nsCPrefetchService.h"
|
||||
#include "nsJSON.h"
|
||||
#include "IHistory.h"
|
||||
|
@ -2041,7 +2042,8 @@ nsDocShell::GetUsePrivateBrowsing(bool* aUsePrivateBrowsing)
|
|||
NS_IMETHODIMP
|
||||
nsDocShell::SetUsePrivateBrowsing(bool aUsePrivateBrowsing)
|
||||
{
|
||||
if (aUsePrivateBrowsing != mInPrivateBrowsing) {
|
||||
bool changed = aUsePrivateBrowsing != mInPrivateBrowsing;
|
||||
if (changed) {
|
||||
mInPrivateBrowsing = aUsePrivateBrowsing;
|
||||
if (aUsePrivateBrowsing) {
|
||||
IncreasePrivateDocShellCount();
|
||||
|
@ -2057,9 +2059,32 @@ nsDocShell::SetUsePrivateBrowsing(bool aUsePrivateBrowsing)
|
|||
shell->SetUsePrivateBrowsing(aUsePrivateBrowsing);
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
nsTObserverArray<nsWeakPtr>::ForwardIterator iter(mPrivacyObservers);
|
||||
while (iter.HasMore()) {
|
||||
nsWeakPtr ref = iter.GetNext();
|
||||
nsCOMPtr<nsIPrivacyTransitionObserver> obs = do_QueryReferent(ref);
|
||||
if (!obs) {
|
||||
mPrivacyObservers.RemoveElement(ref);
|
||||
} else {
|
||||
obs->PrivateModeChanged(aUsePrivateBrowsing);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::AddWeakPrivacyTransitionObserver(nsIPrivacyTransitionObserver* aObserver)
|
||||
{
|
||||
nsWeakPtr weakObs = do_GetWeakReference(aObserver);
|
||||
if (!weakObs) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
return mPrivacyObservers.AppendElement(weakObs) ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDocShell::GetAllowMetaRedirects(bool * aReturn)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aReturn);
|
||||
|
|
|
@ -847,6 +847,7 @@ protected:
|
|||
private:
|
||||
nsCOMPtr<nsIAtom> mForcedCharset;
|
||||
nsCOMPtr<nsIAtom> mParentCharset;
|
||||
nsTObserverArray<nsWeakPtr> mPrivacyObservers;
|
||||
PRInt32 mParentCharsetSource;
|
||||
|
||||
#ifdef DEBUG
|
||||
|
|
|
@ -71,8 +71,9 @@ interface nsIDOMStorage;
|
|||
interface nsIPrincipal;
|
||||
interface nsIWebBrowserPrint;
|
||||
interface nsIVariant;
|
||||
interface nsIPrivacyTransitionObserver;
|
||||
|
||||
[scriptable, uuid(c7325422-817e-4321-957a-c0bdd764941d)]
|
||||
[scriptable, uuid(6f60ac96-fa2c-41a5-92b4-29aaadbd7a7b)]
|
||||
interface nsIDocShell : nsISupports
|
||||
{
|
||||
/**
|
||||
|
@ -603,6 +604,12 @@ interface nsIDocShell : nsISupports
|
|||
*/
|
||||
attribute PRInt32 parentCharsetSource;
|
||||
|
||||
/**
|
||||
* Add an observer to the list of parties to be notified when this docshell's
|
||||
* private browsing status is changed. |obs| must support weak references.
|
||||
*/
|
||||
void addWeakPrivacyTransitionObserver(in nsIPrivacyTransitionObserver obs);
|
||||
|
||||
/*
|
||||
* Is this docshell a browser frame (i.e., does it correspond to an <iframe
|
||||
* mozbrowser>)? The frameloader is responsible for setting this property
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, function, uuid(b4b1449d-0ef0-47f5-b62e-adc57fd49702)]
|
||||
interface nsIPrivacyTransitionObserver : nsISupports
|
||||
{
|
||||
void privateModeChanged(in bool enabled);
|
||||
};
|
|
@ -0,0 +1,23 @@
|
|||
var gNotifications = 0;
|
||||
|
||||
var observer = {
|
||||
QueryInterface: function(iid) {
|
||||
if (Ci.nsIPrivacyTransitionObserver.equals(iid) ||
|
||||
Ci.nsISupportsWeakReference.equals(iid) ||
|
||||
Ci.nsISupports.equals(iid))
|
||||
return this;
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
},
|
||||
|
||||
privateModeChanged: function(enabled) {
|
||||
gNotifications++;
|
||||
}
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
var docshell = Cc["@mozilla.org/docshell;1"].createInstance(Ci.nsIDocShell);
|
||||
docshell.addWeakPrivacyTransitionObserver(observer);
|
||||
docshell.QueryInterface(Ci.nsILoadContext).usePrivateBrowsing = true;
|
||||
docshell.QueryInterface(Ci.nsILoadContext).usePrivateBrowsing = false;
|
||||
do_check_eq(gNotifications, 2);
|
||||
}
|
|
@ -6,3 +6,4 @@ tail =
|
|||
[test_bug442584.js]
|
||||
[test_nsIDownloadHistory.js]
|
||||
[test_pb_notification.js]
|
||||
[test_privacy_transition.js]
|
Загрузка…
Ссылка в новой задаче