From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- parser/html/nsHtml5StreamListener.h | 55 +++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 parser/html/nsHtml5StreamListener.h (limited to 'parser/html/nsHtml5StreamListener.h') diff --git a/parser/html/nsHtml5StreamListener.h b/parser/html/nsHtml5StreamListener.h new file mode 100644 index 000000000..966765fb5 --- /dev/null +++ b/parser/html/nsHtml5StreamListener.h @@ -0,0 +1,55 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef nsHtml5StreamListener_h +#define nsHtml5StreamListener_h + +#include "nsIStreamListener.h" +#include "nsIThreadRetargetableStreamListener.h" +#include "nsHtml5RefPtr.h" +#include "nsHtml5StreamParser.h" + +/** + * The purpose of this class is to reconcile the problem that + * nsHtml5StreamParser is a cycle collection participant, which means that it + * can only be refcounted on the main thread, but + * nsIThreadRetargetableStreamListener can be refcounted from another thread, + * so nsHtml5StreamParser being an nsIThreadRetargetableStreamListener was + * a memory corruption problem. + * + * mDelegate is an nsHtml5RefPtr, which releases the object that it points + * to from a runnable on the main thread. DropDelegate() is only called on + * the main thread. This call will finish before the main-thread derefs the + * nsHtml5StreamListener itself, so there is no risk of another thread making + * the refcount of nsHtml5StreamListener go to zero and running the destructor + * concurrently. Other than that, the thread-safe nsISupports implementation + * takes care of the destructor not running concurrently from different + * threads, so there is no need to have a mutex around nsHtml5RefPtr to + * prevent it from double-releasing nsHtml5StreamParser. + */ +class nsHtml5StreamListener : public nsIStreamListener, + public nsIThreadRetargetableStreamListener +{ +public: + explicit nsHtml5StreamListener(nsHtml5StreamParser* aDelegate); + + NS_DECL_THREADSAFE_ISUPPORTS + NS_DECL_NSIREQUESTOBSERVER + NS_DECL_NSISTREAMLISTENER + NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER + + inline nsHtml5StreamParser* GetDelegate() + { + return mDelegate; + } + + void DropDelegate(); + +private: + virtual ~nsHtml5StreamListener(); + + nsHtml5RefPtr mDelegate; +}; + +#endif // nsHtml5StreamListener_h -- cgit v1.2.3