author Nathan Froyd <>
Sun, 18 Oct 2015 01:24:48 -0400
changeset 268184 e8c7dfe727cd970e2c3294934e2927b14143c205
parent 266639 41dea9df27ed995f8315ab4318c187a617937664
child 272110 1e5f3d1151d60a1edd6424a35a2e38b5ab17adad
permissions -rw-r--r--
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/ \ ipc/ipdl/ipdl/ \ dom/bindings/ \ python/lldbutils/lldbutils/ # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 GMPService_h_
#define GMPService_h_

#include "nsString.h"
#include "mozIGeckoMediaPluginService.h"
#include "nsIObserver.h"
#include "nsTArray.h"
#include "mozilla/Attributes.h"
#include "mozilla/Monitor.h"
#include "nsString.h"
#include "nsCOMPtr.h"
#include "nsIThread.h"
#include "nsThreadUtils.h"
#include "nsPIDOMWindow.h"
#include "nsIDocument.h"
#include "nsIWeakReference.h"

template <class> struct already_AddRefed;

namespace mozilla {

extern PRLogModuleInfo* GetGMPLog();

namespace gmp {

class GetGMPContentParentCallback;


class GeckoMediaPluginService : public mozIGeckoMediaPluginService
                              , public nsIObserver
  static already_AddRefed<GeckoMediaPluginService> GetGeckoMediaPluginService();

  virtual nsresult Init();


  // mozIGeckoMediaPluginService
  NS_IMETHOD GetThread(nsIThread** aThread) override;
  NS_IMETHOD HasPluginForAPI(const nsACString& aAPI, nsTArray<nsCString>* aTags,
                             bool *aRetVal) override;
  NS_IMETHOD GetGMPVideoDecoder(nsTArray<nsCString>* aTags,
                                const nsACString& aNodeId,
                                UniquePtr<GetGMPVideoDecoderCallback>&& aCallback)
  NS_IMETHOD GetGMPVideoEncoder(nsTArray<nsCString>* aTags,
                                const nsACString& aNodeId,
                                UniquePtr<GetGMPVideoEncoderCallback>&& aCallback)
  NS_IMETHOD GetGMPAudioDecoder(nsTArray<nsCString>* aTags,
                                const nsACString& aNodeId,
                                UniquePtr<GetGMPAudioDecoderCallback>&& aCallback)
  NS_IMETHOD GetGMPDecryptor(nsTArray<nsCString>* aTags,
                             const nsACString& aNodeId,
                             UniquePtr<GetGMPDecryptorCallback>&& aCallback)

  int32_t AsyncShutdownTimeoutMs();

  void RunPluginCrashCallbacks(const uint32_t aPluginId,
                               const nsACString& aPluginName);

  // Sets the window to which 'PluginCrashed' chromeonly event is dispatched.
  // Note: if the plugin has crashed before the target window has been set,
  // the 'PluginCrashed' event is dispatched as soon as a target window is set.
  void AddPluginCrashedEventTarget(const uint32_t aPluginId,
                                   nsPIDOMWindow* aParentWindow);

  virtual ~GeckoMediaPluginService();

  void RemoveObsoletePluginCrashCallbacks(); // Called from add/run.

  virtual void InitializePlugins() = 0;
  virtual bool GetContentParentFrom(const nsACString& aNodeId,
                                    const nsCString& aAPI,
                                    const nsTArray<nsCString>& aTags,
                                    UniquePtr<GetGMPContentParentCallback>&& aCallback) = 0;

  nsresult GMPDispatch(nsIRunnable* event, uint32_t flags = NS_DISPATCH_NORMAL);
  void ShutdownGMPThread();

  Mutex mMutex; // Protects mGMPThread and mGMPThreadShutdown and some members
                // in derived classes.
  nsCOMPtr<nsIThread> mGMPThread;
  bool mGMPThreadShutdown;
  bool mShuttingDownOnGMPThread;

  class GMPCrashCallback

    GMPCrashCallback(const uint32_t aPluginId,
                     nsPIDOMWindow* aParentWindow,
                     nsIDocument* aDocument);
    void Run(const nsACString& aPluginName);
    bool IsStillValid();
    const uint32_t GetPluginId() const { return mPluginId; }
    virtual ~GMPCrashCallback() { MOZ_ASSERT(NS_IsMainThread()); }

    bool GetParentWindowAndDocumentIfValid(nsCOMPtr<nsPIDOMWindow>& parentWindow,
                                           nsCOMPtr<nsIDocument>& document);
    const uint32_t mPluginId;
    nsWeakPtr mParentWindowWeakPtr;
    nsWeakPtr mDocumentWeakPtr;

  struct PluginCrash
    PluginCrash(uint32_t aPluginId,
                const nsACString& aPluginName)
      : mPluginId(aPluginId)
      , mPluginName(aPluginName)
    uint32_t mPluginId;
    nsCString mPluginName;

    bool operator==(const PluginCrash& aOther) const {
      return mPluginId == aOther.mPluginId &&
             mPluginName == aOther.mPluginName;

  static const size_t MAX_PLUGIN_CRASHES = 100;
  nsTArray<PluginCrash> mPluginCrashes;

  nsTArray<RefPtr<GMPCrashCallback>> mPluginCrashCallbacks;

} // namespace gmp
} // namespace mozilla

#endif // GMPService_h_