Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 5 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "AsyncHelper.h" |
michael@0 | 8 | |
michael@0 | 9 | #include "nsIRequestObserver.h" |
michael@0 | 10 | |
michael@0 | 11 | #include "nsNetUtil.h" |
michael@0 | 12 | |
michael@0 | 13 | #include "FileService.h" |
michael@0 | 14 | |
michael@0 | 15 | USING_FILE_NAMESPACE |
michael@0 | 16 | |
michael@0 | 17 | NS_IMPL_ISUPPORTS(AsyncHelper, nsIRunnable, nsIRequest) |
michael@0 | 18 | |
michael@0 | 19 | nsresult |
michael@0 | 20 | AsyncHelper::AsyncWork(nsIRequestObserver* aObserver, nsISupports* aCtxt) |
michael@0 | 21 | { |
michael@0 | 22 | nsresult rv; |
michael@0 | 23 | |
michael@0 | 24 | if (aObserver) { |
michael@0 | 25 | // build proxy for observer events |
michael@0 | 26 | rv = NS_NewRequestObserverProxy(getter_AddRefs(mObserver), aObserver, aCtxt); |
michael@0 | 27 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | FileService* service = FileService::GetOrCreate(); |
michael@0 | 31 | NS_ENSURE_TRUE(service, NS_ERROR_FAILURE); |
michael@0 | 32 | |
michael@0 | 33 | nsIEventTarget* target = service->StreamTransportTarget(); |
michael@0 | 34 | |
michael@0 | 35 | rv = target->Dispatch(this, NS_DISPATCH_NORMAL); |
michael@0 | 36 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 37 | |
michael@0 | 38 | return NS_OK; |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | NS_IMETHODIMP |
michael@0 | 42 | AsyncHelper::Run() |
michael@0 | 43 | { |
michael@0 | 44 | NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!"); |
michael@0 | 45 | |
michael@0 | 46 | if (mObserver) { |
michael@0 | 47 | mObserver->OnStartRequest(this, nullptr); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | mStatus = DoStreamWork(mStream); |
michael@0 | 51 | |
michael@0 | 52 | if (mObserver) { |
michael@0 | 53 | mObserver->OnStopRequest(this, nullptr, mStatus); |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | return NS_OK; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | NS_IMETHODIMP |
michael@0 | 60 | AsyncHelper::GetName(nsACString& aName) |
michael@0 | 61 | { |
michael@0 | 62 | NS_WARNING("Shouldn't be called!"); |
michael@0 | 63 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | NS_IMETHODIMP |
michael@0 | 67 | AsyncHelper::IsPending(bool* _retval) |
michael@0 | 68 | { |
michael@0 | 69 | NS_WARNING("Shouldn't be called!"); |
michael@0 | 70 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | NS_IMETHODIMP |
michael@0 | 74 | AsyncHelper::GetStatus(nsresult* aStatus) |
michael@0 | 75 | { |
michael@0 | 76 | *aStatus = mStatus; |
michael@0 | 77 | return NS_OK; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | NS_IMETHODIMP |
michael@0 | 81 | AsyncHelper::Cancel(nsresult aStatus) |
michael@0 | 82 | { |
michael@0 | 83 | return NS_OK; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | NS_IMETHODIMP |
michael@0 | 87 | AsyncHelper::Suspend() |
michael@0 | 88 | { |
michael@0 | 89 | NS_WARNING("Shouldn't be called!"); |
michael@0 | 90 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | NS_IMETHODIMP |
michael@0 | 94 | AsyncHelper::Resume() |
michael@0 | 95 | { |
michael@0 | 96 | NS_WARNING("Shouldn't be called!"); |
michael@0 | 97 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | NS_IMETHODIMP |
michael@0 | 101 | AsyncHelper::GetLoadGroup(nsILoadGroup** aLoadGroup) |
michael@0 | 102 | { |
michael@0 | 103 | NS_WARNING("Shouldn't be called!"); |
michael@0 | 104 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | NS_IMETHODIMP |
michael@0 | 108 | AsyncHelper::SetLoadGroup(nsILoadGroup* aLoadGroup) |
michael@0 | 109 | { |
michael@0 | 110 | NS_WARNING("Shouldn't be called!"); |
michael@0 | 111 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | NS_IMETHODIMP |
michael@0 | 115 | AsyncHelper::GetLoadFlags(nsLoadFlags* aLoadFlags) |
michael@0 | 116 | { |
michael@0 | 117 | NS_WARNING("Shouldn't be called!"); |
michael@0 | 118 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | NS_IMETHODIMP |
michael@0 | 122 | AsyncHelper::SetLoadFlags(nsLoadFlags aLoadFlags) |
michael@0 | 123 | { |
michael@0 | 124 | NS_WARNING("Shouldn't be called!"); |
michael@0 | 125 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 126 | } |