xpcom/glue/nsProxyRelease.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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 /* vim:set ts=4 sw=4 sts=4 et cin: */
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
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "nsProxyRelease.h"
michael@0 7 #include "nsThreadUtils.h"
michael@0 8 #include "nsAutoPtr.h"
michael@0 9
michael@0 10 class nsProxyReleaseEvent : public nsRunnable
michael@0 11 {
michael@0 12 public:
michael@0 13 nsProxyReleaseEvent(nsISupports *doomed)
michael@0 14 : mDoomed(doomed) {
michael@0 15 }
michael@0 16
michael@0 17 NS_IMETHOD Run()
michael@0 18 {
michael@0 19 mDoomed->Release();
michael@0 20 return NS_OK;
michael@0 21 }
michael@0 22
michael@0 23 private:
michael@0 24 nsISupports *mDoomed;
michael@0 25 };
michael@0 26
michael@0 27 nsresult
michael@0 28 NS_ProxyRelease(nsIEventTarget *target, nsISupports *doomed,
michael@0 29 bool alwaysProxy)
michael@0 30 {
michael@0 31 nsresult rv;
michael@0 32
michael@0 33 if (!doomed) {
michael@0 34 // nothing to do
michael@0 35 return NS_OK;
michael@0 36 }
michael@0 37
michael@0 38 if (!target) {
michael@0 39 NS_RELEASE(doomed);
michael@0 40 return NS_OK;
michael@0 41 }
michael@0 42
michael@0 43 if (!alwaysProxy) {
michael@0 44 bool onCurrentThread = false;
michael@0 45 rv = target->IsOnCurrentThread(&onCurrentThread);
michael@0 46 if (NS_SUCCEEDED(rv) && onCurrentThread) {
michael@0 47 NS_RELEASE(doomed);
michael@0 48 return NS_OK;
michael@0 49 }
michael@0 50 }
michael@0 51
michael@0 52 nsRefPtr<nsIRunnable> ev = new nsProxyReleaseEvent(doomed);
michael@0 53 if (!ev) {
michael@0 54 // we do not release doomed here since it may cause a delete on the
michael@0 55 // wrong thread. better to leak than crash.
michael@0 56 return NS_ERROR_OUT_OF_MEMORY;
michael@0 57 }
michael@0 58
michael@0 59 rv = target->Dispatch(ev, NS_DISPATCH_NORMAL);
michael@0 60 if (NS_FAILED(rv)) {
michael@0 61 NS_WARNING("failed to post proxy release event");
michael@0 62 // again, it is better to leak the doomed object than risk crashing as
michael@0 63 // a result of deleting it on the wrong thread.
michael@0 64 }
michael@0 65 return rv;
michael@0 66 }

mercurial