2014-05-18 07:05:46 +04:00
|
|
|
/* -*- 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 http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef GMPService_h_
|
|
|
|
#define GMPService_h_
|
|
|
|
|
2014-07-11 07:35:56 +04:00
|
|
|
#include "nsString.h"
|
2014-05-18 07:05:46 +04:00
|
|
|
#include "mozIGeckoMediaPluginService.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsTArray.h"
|
2014-09-01 07:50:23 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-08-18 01:41:56 +04:00
|
|
|
#include "mozilla/Monitor.h"
|
2014-05-18 07:05:46 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIThread.h"
|
2015-05-29 05:07:22 +03:00
|
|
|
#include "nsThreadUtils.h"
|
2015-06-05 12:55:51 +03:00
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIWeakReference.h"
|
2014-05-18 07:05:46 +04:00
|
|
|
|
2014-06-17 18:57:23 +04:00
|
|
|
template <class> struct already_AddRefed;
|
2014-05-18 07:05:46 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2015-02-09 23:54:12 +03:00
|
|
|
|
2015-11-11 20:36:56 +03:00
|
|
|
extern PRLogModuleInfo* GetGMPLog();
|
2015-02-09 23:54:12 +03:00
|
|
|
|
2014-05-18 07:05:46 +04:00
|
|
|
namespace gmp {
|
|
|
|
|
2015-02-10 13:48:42 +03:00
|
|
|
class GetGMPContentParentCallback;
|
2014-05-18 07:05:46 +04:00
|
|
|
|
2014-10-22 00:45:18 +04:00
|
|
|
#define GMP_DEFAULT_ASYNC_SHUTDONW_TIMEOUT 3000
|
|
|
|
|
2015-02-09 23:54:12 +03:00
|
|
|
class GeckoMediaPluginService : public mozIGeckoMediaPluginService
|
|
|
|
, public nsIObserver
|
2014-05-18 07:05:46 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static already_AddRefed<GeckoMediaPluginService> GetGeckoMediaPluginService();
|
|
|
|
|
2015-02-09 23:54:12 +03:00
|
|
|
virtual nsresult Init();
|
2014-05-18 07:05:46 +04:00
|
|
|
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
|
2015-02-09 23:54:12 +03:00
|
|
|
// 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,
|
2015-02-10 13:48:29 +03:00
|
|
|
UniquePtr<GetGMPVideoDecoderCallback>&& aCallback)
|
|
|
|
override;
|
2015-02-09 23:54:12 +03:00
|
|
|
NS_IMETHOD GetGMPVideoEncoder(nsTArray<nsCString>* aTags,
|
|
|
|
const nsACString& aNodeId,
|
2015-02-10 13:48:29 +03:00
|
|
|
UniquePtr<GetGMPVideoEncoderCallback>&& aCallback)
|
|
|
|
override;
|
2015-02-09 23:54:12 +03:00
|
|
|
NS_IMETHOD GetGMPAudioDecoder(nsTArray<nsCString>* aTags,
|
|
|
|
const nsACString& aNodeId,
|
2015-02-10 13:48:29 +03:00
|
|
|
UniquePtr<GetGMPAudioDecoderCallback>&& aCallback)
|
|
|
|
override;
|
2015-02-09 23:54:12 +03:00
|
|
|
NS_IMETHOD GetGMPDecryptor(nsTArray<nsCString>* aTags,
|
|
|
|
const nsACString& aNodeId,
|
2015-02-10 13:48:29 +03:00
|
|
|
UniquePtr<GetGMPDecryptorCallback>&& aCallback)
|
|
|
|
override;
|
2014-08-18 01:41:56 +04:00
|
|
|
|
2014-10-22 00:45:18 +04:00
|
|
|
int32_t AsyncShutdownTimeoutMs();
|
|
|
|
|
2015-05-04 22:40:29 +03:00
|
|
|
void RunPluginCrashCallbacks(const uint32_t aPluginId,
|
|
|
|
const nsACString& aPluginName);
|
2015-03-26 09:55:30 +03:00
|
|
|
|
2015-06-05 12:55:51 +03:00
|
|
|
// 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);
|
|
|
|
|
2015-02-09 23:54:12 +03:00
|
|
|
protected:
|
|
|
|
GeckoMediaPluginService();
|
|
|
|
virtual ~GeckoMediaPluginService();
|
2014-10-21 05:53:30 +04:00
|
|
|
|
2015-06-05 12:55:51 +03:00
|
|
|
void RemoveObsoletePluginCrashCallbacks(); // Called from add/run.
|
|
|
|
|
2015-02-09 23:54:12 +03:00
|
|
|
virtual void InitializePlugins() = 0;
|
2015-02-10 13:48:42 +03:00
|
|
|
virtual bool GetContentParentFrom(const nsACString& aNodeId,
|
|
|
|
const nsCString& aAPI,
|
|
|
|
const nsTArray<nsCString>& aTags,
|
|
|
|
UniquePtr<GetGMPContentParentCallback>&& aCallback) = 0;
|
2014-07-10 22:48:11 +04:00
|
|
|
|
2015-02-09 23:54:12 +03:00
|
|
|
nsresult GMPDispatch(nsIRunnable* event, uint32_t flags = NS_DISPATCH_NORMAL);
|
|
|
|
void ShutdownGMPThread();
|
2015-01-06 03:00:00 +03:00
|
|
|
|
2015-02-09 23:54:12 +03:00
|
|
|
Mutex mMutex; // Protects mGMPThread and mGMPThreadShutdown and some members
|
|
|
|
// in derived classes.
|
2014-05-18 07:05:46 +04:00
|
|
|
nsCOMPtr<nsIThread> mGMPThread;
|
2015-02-09 23:54:12 +03:00
|
|
|
bool mGMPThreadShutdown;
|
2014-05-18 07:05:46 +04:00
|
|
|
bool mShuttingDownOnGMPThread;
|
2014-08-18 01:41:56 +04:00
|
|
|
|
2015-06-05 12:55:51 +03:00
|
|
|
class GMPCrashCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_REFCOUNTING(GMPCrashCallback)
|
|
|
|
|
|
|
|
GMPCrashCallback(const uint32_t aPluginId,
|
|
|
|
nsPIDOMWindow* aParentWindow,
|
|
|
|
nsIDocument* aDocument);
|
|
|
|
void Run(const nsACString& aPluginName);
|
|
|
|
bool IsStillValid();
|
|
|
|
const uint32_t GetPluginId() const { return mPluginId; }
|
|
|
|
private:
|
|
|
|
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;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<GMPCrashCallback>> mPluginCrashCallbacks;
|
2014-05-18 07:05:46 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace gmp
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // GMPService_h_
|