Bug 777620 - Support access to private prowsing cookies in nsICookieManager
MozReview-Commit-ID: G97YHqCOpM6
--- a/netwerk/cookie/nsCookieService.cpp
+++ b/netwerk/cookie/nsCookieService.cpp
@@ -2473,16 +2473,35 @@ nsCookieService::RemoveNative(const nsAC
nsresult rv = Remove(aHost, *aOriginAttributes, aName, aPath, aBlocked);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
+NS_IMETHODIMP
+nsCookieService::UsePrivateMode(bool aIsPrivate,
+ nsIPrivateModeCallback* aCallback)
+{
+ if (!aCallback) {
+ return NS_ERROR_INVALID_ARG;
+ }
+
+ if (!mDBState) {
+ NS_WARNING("No DBState! Profile already closed?");
+ return NS_ERROR_NOT_AVAILABLE;
+ }
+
+ AutoRestore<DBState*> savePrevDBState(mDBState);
+ mDBState = aIsPrivate ? mPrivateDBState : mDefaultDBState;
+
+ return aCallback->Callback();
+}
+
/******************************************************************************
* nsCookieService impl:
* private file I/O functions
******************************************************************************/
// Begin an asynchronous read from the database.
OpenDBResult
nsCookieService::Read()
--- a/netwerk/cookie/nsICookieManager.idl
+++ b/netwerk/cookie/nsICookieManager.idl
@@ -10,16 +10,22 @@ namespace mozilla {
class NeckoOriginAttributes;
} // mozilla namespace
%}
[ptr] native NeckoOriginAttributesPtr(mozilla::NeckoOriginAttributes);
interface nsISimpleEnumerator;
+[scriptable, function, uuid(20709db8-8dad-4e45-b33e-6e7c761dfc5d)]
+interface nsIPrivateModeCallback : nsISupports
+{
+ void callback();
+};
+
/**
* An optional interface for accessing or removing the cookies
* that are in the cookie list
*/
[scriptable, uuid(AAAB6710-0F2C-11d5-A53B-0010A401EB10)]
interface nsICookieManager : nsISupports
{
@@ -62,9 +68,21 @@ interface nsICookieManager : nsISupports
[optional] in jsval aOriginAttributes);
[notxpcom]
nsresult removeNative(in AUTF8String aHost,
in ACString aName,
in AUTF8String aPath,
in boolean aBlocked,
in NeckoOriginAttributesPtr aOriginAttributes);
+
+ /**
+ * Set the cookie manager to work on private or non-private cookies for the
+ * duration of the callback.
+ *
+ * @param aIsPrivate True to work on private cookies, false to work on
+ * non-private cookies.
+ * @param aCallback Methods on the cookie manager interface will work on
+ * private or non-private cookies for the duration of this
+ * callback.
+ */
+ void usePrivateMode(in boolean aIsPrivate, in nsIPrivateModeCallback aCallback);
};