Bug 777620 - Support access to private prowsing cookies in nsICookieManager draft
authorJesper Kristensen <mail@jesperkristensen.dk>
Thu, 31 Mar 2016 18:29:27 +0200
changeset 417406 92a6bb84240464f8ea5f0d30057c9ecfde17c6d5
parent 417383 29beaebdfaccbdaeb4c1ee5a43a9795ab015ef49
child 417407 439756bf71490136a1c29badf14cd72967b825fc
child 419084 d98d67dba2dcba87c2800a8e6f71d2bc460f5c4e
push id30398
push usermail@jesperkristensen.dk
push dateSun, 25 Sep 2016 10:35:31 +0000
bugs777620
milestone52.0a1
Bug 777620 - Support access to private prowsing cookies in nsICookieManager MozReview-Commit-ID: G97YHqCOpM6
netwerk/cookie/nsCookieService.cpp
netwerk/cookie/nsICookieManager.idl
--- 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);
 };