author Benjamin Smedberg <>
Tue, 25 Nov 2014 15:13:01 -0800
changeset 226152 e350081598fa3b51e19f5ba64dd5680a2aab7ec1
parent 224551 4165ed00dc3b0b73dbb846a2f13f693cca043ca7
child 408018 3d64bdd31c155ee1d57f7a1bb98de239aa31ee01
permissions -rw-r--r--
Bug 1104823 - Fix packaging of UITour FHR recording (modules.manifest renamed to browsermodules.manifest for clarity), r=felipe, a=gavin

/* 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 */

#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
  explicit nsHtml5StreamListener(nsHtml5StreamParser* aDelegate);


  inline nsHtml5StreamParser* GetDelegate()
    return mDelegate;

  void DropDelegate();

  virtual ~nsHtml5StreamListener();

  nsHtml5RefPtr<nsHtml5StreamParser> mDelegate;

#endif // nsHtml5StreamListener_h