dom/base/nsWrapperCache.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 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=8 sts=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
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "nsWrapperCacheInlines.h"
michael@0 8
michael@0 9 #include "jsproxy.h"
michael@0 10 #include "mozilla/dom/DOMJSProxyHandler.h"
michael@0 11 #include "mozilla/HoldDropJSObjects.h"
michael@0 12 #include "nsCycleCollectionTraversalCallback.h"
michael@0 13 #include "nsCycleCollector.h"
michael@0 14
michael@0 15 using namespace mozilla;
michael@0 16 using namespace mozilla::dom;
michael@0 17
michael@0 18 /* static */ void
michael@0 19 nsWrapperCache::HoldJSObjects(void* aScriptObjectHolder,
michael@0 20 nsScriptObjectTracer* aTracer)
michael@0 21 {
michael@0 22 cyclecollector::HoldJSObjectsImpl(aScriptObjectHolder, aTracer);
michael@0 23 }
michael@0 24
michael@0 25 void
michael@0 26 nsWrapperCache::ReleaseWrapper(void* aScriptObjectHolder)
michael@0 27 {
michael@0 28 if (PreservingWrapper()) {
michael@0 29 // PreserveWrapper puts new DOM bindings in the JS holders hash, but they
michael@0 30 // can also be in the DOM expando hash, so we need to try to remove them
michael@0 31 // from both here.
michael@0 32 JSObject* obj = GetWrapperPreserveColor();
michael@0 33 if (IsDOMBinding() && obj && js::IsProxy(obj)) {
michael@0 34 DOMProxyHandler::GetAndClearExpandoObject(obj);
michael@0 35 }
michael@0 36 SetPreservingWrapper(false);
michael@0 37 cyclecollector::DropJSObjectsImpl(aScriptObjectHolder);
michael@0 38 }
michael@0 39 }
michael@0 40
michael@0 41 #ifdef DEBUG
michael@0 42
michael@0 43 class DebugWrapperTraversalCallback : public nsCycleCollectionTraversalCallback
michael@0 44 {
michael@0 45 public:
michael@0 46 DebugWrapperTraversalCallback(void* aWrapper)
michael@0 47 : mFound(false)
michael@0 48 , mWrapper(aWrapper)
michael@0 49 {
michael@0 50 mFlags = WANT_ALL_TRACES;
michael@0 51 }
michael@0 52
michael@0 53 NS_IMETHOD_(void) DescribeRefCountedNode(nsrefcnt aRefCount,
michael@0 54 const char* aObjName)
michael@0 55 {
michael@0 56 }
michael@0 57 NS_IMETHOD_(void) DescribeGCedNode(bool aIsMarked,
michael@0 58 const char* aObjName,
michael@0 59 uint64_t aCompartmentAddress)
michael@0 60 {
michael@0 61 }
michael@0 62
michael@0 63 NS_IMETHOD_(void) NoteJSChild(void* aChild)
michael@0 64 {
michael@0 65 if (aChild == mWrapper) {
michael@0 66 mFound = true;
michael@0 67 }
michael@0 68 }
michael@0 69 NS_IMETHOD_(void) NoteXPCOMChild(nsISupports* aChild)
michael@0 70 {
michael@0 71 }
michael@0 72 NS_IMETHOD_(void) NoteNativeChild(void* aChild,
michael@0 73 nsCycleCollectionParticipant* aHelper)
michael@0 74 {
michael@0 75 }
michael@0 76
michael@0 77 NS_IMETHOD_(void) NoteNextEdgeName(const char* aName)
michael@0 78 {
michael@0 79 }
michael@0 80
michael@0 81 bool mFound;
michael@0 82
michael@0 83 private:
michael@0 84 void* mWrapper;
michael@0 85 };
michael@0 86
michael@0 87 static void
michael@0 88 DebugWrapperTraceCallback(void* aP, const char* aName, void* aClosure)
michael@0 89 {
michael@0 90 DebugWrapperTraversalCallback* callback =
michael@0 91 static_cast<DebugWrapperTraversalCallback*>(aClosure);
michael@0 92 callback->NoteJSChild(aP);
michael@0 93 }
michael@0 94
michael@0 95 void
michael@0 96 nsWrapperCache::CheckCCWrapperTraversal(void* aScriptObjectHolder,
michael@0 97 nsScriptObjectTracer* aTracer)
michael@0 98 {
michael@0 99 JSObject* wrapper = GetWrapper();
michael@0 100 if (!wrapper) {
michael@0 101 return;
michael@0 102 }
michael@0 103
michael@0 104 DebugWrapperTraversalCallback callback(wrapper);
michael@0 105
michael@0 106 aTracer->Traverse(aScriptObjectHolder, callback);
michael@0 107 MOZ_ASSERT(callback.mFound,
michael@0 108 "Cycle collection participant didn't traverse to preserved "
michael@0 109 "wrapper! This will probably crash.");
michael@0 110
michael@0 111 callback.mFound = false;
michael@0 112 aTracer->Trace(aScriptObjectHolder,
michael@0 113 TraceCallbackFunc(DebugWrapperTraceCallback), &callback);
michael@0 114 MOZ_ASSERT(callback.mFound,
michael@0 115 "Cycle collection participant didn't trace preserved wrapper! "
michael@0 116 "This will probably crash.");
michael@0 117 }
michael@0 118
michael@0 119 #endif // DEBUG

mercurial