2014-05-17 20:05:46 -07: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-10 20:35:56 -07:00
|
|
|
#include "nsString.h"
|
2014-05-17 20:05:46 -07:00
|
|
|
#include "mozIGeckoMediaPluginService.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsTArray.h"
|
2014-08-31 20:50:23 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-08-17 14:41:56 -07:00
|
|
|
#include "mozilla/Monitor.h"
|
2014-05-17 20:05:46 -07:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIThread.h"
|
2014-07-10 11:48:11 -07:00
|
|
|
#include "nsThreadUtils.h"
|
2014-08-17 14:41:56 -07:00
|
|
|
#include "nsITimer.h"
|
2014-05-17 20:05:46 -07:00
|
|
|
|
2014-06-17 07:57:23 -07:00
|
|
|
template <class> struct already_AddRefed;
|
2014-05-17 20:05:46 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gmp {
|
|
|
|
|
|
|
|
class GMPParent;
|
|
|
|
|
|
|
|
class GeckoMediaPluginService MOZ_FINAL : public mozIGeckoMediaPluginService
|
|
|
|
, public nsIObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static already_AddRefed<GeckoMediaPluginService> GetGeckoMediaPluginService();
|
|
|
|
|
|
|
|
GeckoMediaPluginService();
|
2014-10-12 15:53:44 -07:00
|
|
|
nsresult Init();
|
2014-05-17 20:05:46 -07:00
|
|
|
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
NS_DECL_MOZIGECKOMEDIAPLUGINSERVICE
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
2014-08-17 14:41:56 -07:00
|
|
|
void AsyncShutdownNeeded(GMPParent* aParent);
|
|
|
|
void AsyncShutdownComplete(GMPParent* aParent);
|
|
|
|
void AbortAsyncShutdown();
|
|
|
|
|
2014-05-17 20:05:46 -07:00
|
|
|
private:
|
|
|
|
~GeckoMediaPluginService();
|
|
|
|
|
2014-10-12 15:53:43 -07:00
|
|
|
GMPParent* SelectPluginForAPI(const nsACString& aNodeId,
|
2014-06-29 16:02:39 -07:00
|
|
|
const nsCString& aAPI,
|
2014-09-23 15:04:47 -07:00
|
|
|
const nsTArray<nsCString>& aTags,
|
2014-10-12 15:53:43 -07:00
|
|
|
bool aCloneCrossNodeIds = true);
|
2014-07-10 11:48:11 -07:00
|
|
|
|
2014-05-17 20:05:46 -07:00
|
|
|
void UnloadPlugins();
|
2014-07-30 14:40:43 -07:00
|
|
|
void CrashPlugins();
|
2014-08-17 14:41:56 -07:00
|
|
|
void SetAsyncShutdownComplete();
|
2014-05-17 20:05:46 -07:00
|
|
|
|
2014-07-10 11:48:11 -07:00
|
|
|
void LoadFromEnvironment();
|
2014-05-17 20:05:46 -07:00
|
|
|
void ProcessPossiblePlugin(nsIFile* aDir);
|
2014-07-10 11:48:11 -07:00
|
|
|
|
|
|
|
void AddOnGMPThread(const nsAString& aSearchDir);
|
|
|
|
void RemoveOnGMPThread(const nsAString& aSearchDir);
|
2014-08-17 14:41:56 -07:00
|
|
|
|
|
|
|
nsresult SetAsyncShutdownTimeout();
|
|
|
|
|
2014-07-28 08:42:55 -07:00
|
|
|
protected:
|
|
|
|
friend class GMPParent;
|
|
|
|
void ReAddOnGMPThread(nsRefPtr<GMPParent>& aOld);
|
|
|
|
private:
|
|
|
|
GMPParent* ClonePlugin(const GMPParent* aOriginal);
|
2014-07-10 11:48:11 -07:00
|
|
|
|
|
|
|
class PathRunnable : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PathRunnable(GeckoMediaPluginService* service, const nsAString& path,
|
|
|
|
bool add)
|
|
|
|
: mService(service)
|
|
|
|
, mPath(path)
|
|
|
|
, mAdd(add)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsRefPtr<GeckoMediaPluginService> mService;
|
|
|
|
nsString mPath;
|
|
|
|
bool mAdd;
|
|
|
|
};
|
2014-05-17 20:05:46 -07:00
|
|
|
|
2014-07-16 19:59:17 -07:00
|
|
|
Mutex mMutex; // Protects mGMPThread and mShuttingDown and mPlugins
|
2014-05-17 20:05:46 -07:00
|
|
|
nsTArray<nsRefPtr<GMPParent>> mPlugins;
|
|
|
|
nsCOMPtr<nsIThread> mGMPThread;
|
|
|
|
bool mShuttingDown;
|
|
|
|
bool mShuttingDownOnGMPThread;
|
2014-08-17 14:41:56 -07:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class MainThreadOnly {
|
|
|
|
public:
|
2014-08-31 20:50:23 -07:00
|
|
|
MOZ_IMPLICIT MainThreadOnly(T aValue)
|
2014-08-17 14:41:56 -07:00
|
|
|
: mValue(aValue)
|
|
|
|
{}
|
|
|
|
operator T&() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
return mValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
T mValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
MainThreadOnly<bool> mWaitingForPluginsAsyncShutdown;
|
|
|
|
|
|
|
|
nsTArray<nsRefPtr<GMPParent>> mAsyncShutdownPlugins; // GMP Thread only.
|
|
|
|
nsCOMPtr<nsITimer> mAsyncShutdownTimeout; // GMP Thread only.
|
2014-10-12 15:53:44 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> mStorageBaseDir;
|
2014-05-17 20:05:46 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace gmp
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // GMPService_h_
|