Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 4 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsIToolkitProfileService.h" |
michael@0 | 7 | #include "nsIFile.h" |
michael@0 | 8 | #include "nsThreadUtils.h" |
michael@0 | 9 | |
michael@0 | 10 | static bool gProfileResetCleanupCompleted = false; |
michael@0 | 11 | static const char kResetProgressURL[] = "chrome://global/content/resetProfileProgress.xul"; |
michael@0 | 12 | |
michael@0 | 13 | nsresult CreateResetProfile(nsIToolkitProfileService* aProfileSvc, |
michael@0 | 14 | nsIToolkitProfile* *aNewProfile); |
michael@0 | 15 | |
michael@0 | 16 | nsresult ProfileResetCleanup(nsIToolkitProfile* aOldProfile); |
michael@0 | 17 | |
michael@0 | 18 | class ProfileResetCleanupResultTask : public nsRunnable |
michael@0 | 19 | { |
michael@0 | 20 | public: |
michael@0 | 21 | ProfileResetCleanupResultTask() |
michael@0 | 22 | : mWorkerThread(do_GetCurrentThread()) |
michael@0 | 23 | { |
michael@0 | 24 | MOZ_ASSERT(!NS_IsMainThread()); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | NS_IMETHOD Run() { |
michael@0 | 28 | MOZ_ASSERT(NS_IsMainThread()); |
michael@0 | 29 | mWorkerThread->Shutdown(); |
michael@0 | 30 | return NS_OK; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | private: |
michael@0 | 34 | nsCOMPtr<nsIThread> mWorkerThread; |
michael@0 | 35 | }; |
michael@0 | 36 | |
michael@0 | 37 | class ProfileResetCleanupAsyncTask : public nsRunnable |
michael@0 | 38 | { |
michael@0 | 39 | public: |
michael@0 | 40 | ProfileResetCleanupAsyncTask(nsIFile* aProfileDir, nsIFile* aProfileLocalDir, |
michael@0 | 41 | nsIFile* aTargetDir, const nsAString &aLeafName) |
michael@0 | 42 | : mProfileDir(aProfileDir) |
michael@0 | 43 | , mProfileLocalDir(aProfileLocalDir) |
michael@0 | 44 | , mTargetDir(aTargetDir) |
michael@0 | 45 | , mLeafName(aLeafName) |
michael@0 | 46 | { } |
michael@0 | 47 | |
michael@0 | 48 | /** |
michael@0 | 49 | * Copy a root profile to a backup folder before deleting it. Then delete the local profile dir. |
michael@0 | 50 | */ |
michael@0 | 51 | NS_IMETHOD Run() |
michael@0 | 52 | { |
michael@0 | 53 | // Copy to the destination then delete the profile. A move doesn't follow links. |
michael@0 | 54 | nsresult rv = mProfileDir->CopyToFollowingLinks(mTargetDir, mLeafName); |
michael@0 | 55 | if (NS_SUCCEEDED(rv)) |
michael@0 | 56 | rv = mProfileDir->Remove(true); |
michael@0 | 57 | else |
michael@0 | 58 | NS_WARNING("Could not backup the root profile directory"); |
michael@0 | 59 | |
michael@0 | 60 | // If we have a separate local cache profile directory, just delete it. |
michael@0 | 61 | // Don't return an error if this fails so that reset can proceed if it can't be deleted. |
michael@0 | 62 | bool sameDir; |
michael@0 | 63 | nsresult rvLocal = mProfileDir->Equals(mProfileLocalDir, &sameDir); |
michael@0 | 64 | if (NS_SUCCEEDED(rvLocal) && !sameDir) { |
michael@0 | 65 | rvLocal = mProfileLocalDir->Remove(true); |
michael@0 | 66 | if (NS_FAILED(rvLocal)) NS_WARNING("Could not remove the old local profile directory (cache)"); |
michael@0 | 67 | } |
michael@0 | 68 | gProfileResetCleanupCompleted = true; |
michael@0 | 69 | |
michael@0 | 70 | nsCOMPtr<nsIRunnable> resultRunnable = new ProfileResetCleanupResultTask(); |
michael@0 | 71 | NS_DispatchToMainThread(resultRunnable); |
michael@0 | 72 | return NS_OK; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | private: |
michael@0 | 76 | nsCOMPtr<nsIFile> mProfileDir; |
michael@0 | 77 | nsCOMPtr<nsIFile> mProfileLocalDir; |
michael@0 | 78 | nsCOMPtr<nsIFile> mTargetDir; |
michael@0 | 79 | nsAutoString mLeafName; |
michael@0 | 80 | }; |