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 GMPParent_h_
|
|
|
|
#define GMPParent_h_
|
|
|
|
|
|
|
|
#include "GMPProcessParent.h"
|
2015-02-09 23:54:12 +03:00
|
|
|
#include "GMPServiceParent.h"
|
2014-05-18 07:05:46 +04:00
|
|
|
#include "GMPVideoDecoderParent.h"
|
|
|
|
#include "GMPVideoEncoderParent.h"
|
2014-08-05 11:56:05 +04:00
|
|
|
#include "GMPTimerParent.h"
|
2014-08-19 12:56:33 +04:00
|
|
|
#include "GMPStorageParent.h"
|
2014-05-18 07:05:46 +04:00
|
|
|
#include "mozilla/gmp/PGMPParent.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsTArray.h"
|
2014-07-10 22:48:11 +04:00
|
|
|
#include "nsIFile.h"
|
2016-04-12 07:12:21 +03:00
|
|
|
#include "mozilla/MozPromise.h"
|
2014-05-18 07:05:46 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2017-02-12 22:39:44 +03:00
|
|
|
namespace ipc {
|
|
|
|
class CrashReporterHost;
|
|
|
|
} // namespace ipc
|
2014-05-18 07:05:46 +04:00
|
|
|
namespace gmp {
|
|
|
|
|
|
|
|
class GMPCapability
|
|
|
|
{
|
|
|
|
public:
|
2016-04-12 07:12:21 +03:00
|
|
|
explicit GMPCapability() {}
|
|
|
|
GMPCapability(GMPCapability&& aOther)
|
|
|
|
: mAPIName(Move(aOther.mAPIName))
|
|
|
|
, mAPITags(Move(aOther.mAPITags))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
explicit GMPCapability(const nsCString& aAPIName)
|
2016-04-12 07:12:21 +03:00
|
|
|
: mAPIName(aAPIName)
|
|
|
|
{}
|
2016-04-12 07:12:21 +03:00
|
|
|
explicit GMPCapability(const GMPCapability& aOther) = default;
|
2014-05-18 07:05:46 +04:00
|
|
|
nsCString mAPIName;
|
|
|
|
nsTArray<nsCString> mAPITags;
|
2016-11-01 06:55:08 +03:00
|
|
|
|
|
|
|
static bool Supports(const nsTArray<GMPCapability>& aCapabilities,
|
|
|
|
const nsCString& aAPI,
|
|
|
|
const nsTArray<nsCString>& aTags);
|
|
|
|
|
|
|
|
static bool Supports(const nsTArray<GMPCapability>& aCapabilities,
|
|
|
|
const nsCString& aAPI,
|
|
|
|
const nsCString& aTag);
|
2014-05-18 07:05:46 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
enum GMPState {
|
|
|
|
GMPStateNotLoaded,
|
2014-07-18 21:37:06 +04:00
|
|
|
GMPStateLoaded,
|
2014-07-20 03:14:03 +04:00
|
|
|
GMPStateUnloading,
|
2014-07-18 21:37:06 +04:00
|
|
|
GMPStateClosing
|
2014-05-18 07:05:46 +04:00
|
|
|
};
|
|
|
|
|
2015-02-10 13:48:42 +03:00
|
|
|
class GMPContentParent;
|
|
|
|
|
|
|
|
class GMPParent final : public PGMPParent
|
2014-05-18 07:05:46 +04:00
|
|
|
{
|
|
|
|
public:
|
2015-12-13 16:26:00 +03:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GMPParent)
|
2014-05-18 07:05:46 +04:00
|
|
|
|
2017-03-09 10:31:11 +03:00
|
|
|
explicit GMPParent(AbstractThread* aMainThread);
|
2014-05-18 07:05:46 +04:00
|
|
|
|
2016-04-12 07:12:22 +03:00
|
|
|
RefPtr<GenericPromise> Init(GeckoMediaPluginServiceParent* aService, nsIFile* aPluginDir);
|
2014-07-28 19:42:55 +04:00
|
|
|
nsresult CloneFrom(const GMPParent* aOther);
|
|
|
|
|
2015-10-14 09:42:25 +03:00
|
|
|
void Crash();
|
2014-07-31 01:40:43 +04:00
|
|
|
|
2014-05-18 07:05:46 +04:00
|
|
|
nsresult LoadProcess();
|
2014-07-18 21:37:06 +04:00
|
|
|
|
|
|
|
// Called internally to close this if we don't need it
|
|
|
|
void CloseIfUnused();
|
|
|
|
|
|
|
|
// Notify all active de/encoders that we are closing, either because of
|
|
|
|
// normal shutdown or unexpected shutdown/crash.
|
2014-07-25 05:47:41 +04:00
|
|
|
void CloseActive(bool aDieWhenUnloaded);
|
2014-07-18 21:37:06 +04:00
|
|
|
|
2015-04-04 07:03:16 +03:00
|
|
|
// Tell the plugin to die after shutdown.
|
|
|
|
void MarkForDeletion();
|
|
|
|
bool IsMarkedForDeletion();
|
|
|
|
|
2014-07-18 21:37:06 +04:00
|
|
|
// Called by the GMPService to forcibly close active de/encoders at shutdown
|
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
// This must not be called while we're in the middle of abnormal ActorDestroy
|
|
|
|
void DeleteProcess();
|
|
|
|
|
2014-05-18 07:05:46 +04:00
|
|
|
GMPState State() const;
|
2017-06-01 23:41:18 +03:00
|
|
|
nsCOMPtr<nsISerialEventTarget> GMPEventTarget();
|
2014-05-18 07:05:46 +04:00
|
|
|
|
2014-10-13 02:53:43 +04:00
|
|
|
// A GMP can either be a single instance shared across all NodeIds (like
|
2014-06-30 03:02:39 +04:00
|
|
|
// in the OpenH264 case), or we can require a new plugin instance for every
|
2014-10-13 02:53:43 +04:00
|
|
|
// NodeIds running the plugin (as in the EME plugin case).
|
2014-06-30 03:02:39 +04:00
|
|
|
//
|
2014-10-13 02:53:43 +04:00
|
|
|
// A NodeId is a hash of the ($urlBarOrigin, $ownerDocOrigin) pair.
|
|
|
|
//
|
|
|
|
// Plugins are associated with an NodeIds by calling SetNodeId() before
|
2014-06-30 03:02:39 +04:00
|
|
|
// loading.
|
|
|
|
//
|
2014-10-13 02:53:43 +04:00
|
|
|
// If a plugin has no NodeId specified and it is loaded, it is assumed to
|
|
|
|
// be shared across NodeIds.
|
2014-06-30 03:02:39 +04:00
|
|
|
|
2014-10-13 02:53:43 +04:00
|
|
|
// Specifies that a GMP can only work with the specified NodeIds.
|
|
|
|
void SetNodeId(const nsACString& aNodeId);
|
2014-12-29 06:18:00 +03:00
|
|
|
const nsACString& GetNodeId() const { return mNodeId; }
|
2014-06-30 03:02:39 +04:00
|
|
|
|
2015-03-20 07:52:10 +03:00
|
|
|
const nsCString& GetDisplayName() const;
|
2015-02-20 04:37:49 +03:00
|
|
|
const nsCString& GetVersion() const;
|
2016-01-08 02:43:37 +03:00
|
|
|
uint32_t GetPluginId() const;
|
2015-11-27 00:53:32 +03:00
|
|
|
nsString GetPluginBaseName() const;
|
2015-02-20 04:37:49 +03:00
|
|
|
|
2014-10-13 02:53:43 +04:00
|
|
|
// Returns true if a plugin can be or is being used across multiple NodeIds.
|
|
|
|
bool CanBeSharedCrossNodeIds() const;
|
2014-06-30 03:02:39 +04:00
|
|
|
|
2014-10-13 02:53:43 +04:00
|
|
|
// A GMP can be used from a NodeId if it's already been set to work with
|
|
|
|
// that NodeId, or if it's not been set to work with any NodeId and has
|
|
|
|
// not yet been loaded (i.e. it's not shared across NodeIds).
|
|
|
|
bool CanBeUsedFrom(const nsACString& aNodeId) const;
|
2014-06-30 03:02:39 +04:00
|
|
|
|
2014-07-10 22:48:11 +04:00
|
|
|
already_AddRefed<nsIFile> GetDirectory() {
|
|
|
|
return nsCOMPtr<nsIFile>(mDirectory).forget();
|
|
|
|
}
|
|
|
|
|
2014-08-18 01:41:56 +04:00
|
|
|
void AbortAsyncShutdown();
|
|
|
|
|
2015-04-04 07:03:16 +03:00
|
|
|
// Called when the child process has died.
|
|
|
|
void ChildTerminated();
|
|
|
|
|
2017-01-05 23:55:27 +03:00
|
|
|
bool OpenPGMPContent();
|
|
|
|
|
2016-11-09 05:52:22 +03:00
|
|
|
void GetGMPContentParent(UniquePtr<MozPromiseHolder<GetGMPContentParentPromise>>&& aPromiseHolder);
|
2015-02-10 13:48:42 +03:00
|
|
|
already_AddRefed<GMPContentParent> ForgetGMPContentParent();
|
|
|
|
|
2015-02-10 13:49:03 +03:00
|
|
|
bool EnsureProcessLoaded(base::ProcessId* aID);
|
|
|
|
|
2017-01-05 23:55:27 +03:00
|
|
|
void IncrementGMPContentChildCount();
|
2015-02-10 13:49:03 +03:00
|
|
|
|
2016-11-01 06:25:19 +03:00
|
|
|
const nsTArray<GMPCapability>& GetCapabilities() const { return mCapabilities; }
|
|
|
|
|
2014-05-18 07:05:46 +04:00
|
|
|
private:
|
|
|
|
~GMPParent();
|
2016-04-12 07:12:21 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GeckoMediaPluginServiceParent> mService;
|
2014-05-18 07:05:46 +04:00
|
|
|
bool EnsureProcessLoaded();
|
2016-04-12 07:12:22 +03:00
|
|
|
RefPtr<GenericPromise> ReadGMPMetaData();
|
|
|
|
RefPtr<GenericPromise> ReadGMPInfoFile(nsIFile* aFile);
|
2016-11-13 08:53:05 +03:00
|
|
|
RefPtr<GenericPromise> ParseChromiumManifest(const nsAString& aJSON); // Main thread.
|
2016-04-12 07:12:22 +03:00
|
|
|
RefPtr<GenericPromise> ReadChromiumManifestFile(nsIFile* aFile); // GMP thread.
|
2014-07-18 21:35:44 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2017-02-16 01:44:29 +03:00
|
|
|
void WriteExtraDataForMinidump();
|
2017-02-12 22:39:44 +03:00
|
|
|
bool GetCrashID(nsString& aResult);
|
2014-07-18 21:35:44 +04:00
|
|
|
#endif
|
2016-01-18 06:40:49 +03:00
|
|
|
void ActorDestroy(ActorDestroyReason aWhy) override;
|
2014-07-18 21:35:44 +04:00
|
|
|
|
2017-02-16 01:44:29 +03:00
|
|
|
mozilla::ipc::IPCResult RecvInitCrashReporter(Shmem&& shmem, const NativeThreadId& aThreadId) override;
|
2014-07-28 03:20:34 +04:00
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult RecvPGMPStorageConstructor(PGMPStorageParent* actor) override;
|
2016-01-18 06:40:49 +03:00
|
|
|
PGMPStorageParent* AllocPGMPStorageParent() override;
|
|
|
|
bool DeallocPGMPStorageParent(PGMPStorageParent* aActor) override;
|
2014-08-19 12:56:33 +04:00
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult RecvPGMPTimerConstructor(PGMPTimerParent* actor) override;
|
2016-01-18 06:40:49 +03:00
|
|
|
PGMPTimerParent* AllocPGMPTimerParent() override;
|
|
|
|
bool DeallocPGMPTimerParent(PGMPTimerParent* aActor) override;
|
2014-08-05 11:56:05 +04:00
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult RecvPGMPContentChildDestroyed() override;
|
2015-02-10 13:48:42 +03:00
|
|
|
bool IsUsed()
|
|
|
|
{
|
2016-11-18 02:37:14 +03:00
|
|
|
return mGMPContentChildCount > 0 ||
|
|
|
|
!mGetContentParentPromises.IsEmpty();
|
2015-02-10 13:48:42 +03:00
|
|
|
}
|
|
|
|
|
2016-11-09 05:52:22 +03:00
|
|
|
void ResolveGetContentParentPromises();
|
|
|
|
void RejectGetContentParentPromises();
|
2015-02-10 13:48:42 +03:00
|
|
|
|
2014-05-18 07:05:46 +04:00
|
|
|
GMPState mState;
|
|
|
|
nsCOMPtr<nsIFile> mDirectory; // plugin directory on disk
|
|
|
|
nsString mName; // base name of plugin on disk, UTF-16 because used for paths
|
|
|
|
nsCString mDisplayName; // name of plugin displayed to users
|
|
|
|
nsCString mDescription; // description of plugin for display to users
|
|
|
|
nsCString mVersion;
|
2016-02-23 21:21:47 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
nsCString mLibs;
|
|
|
|
#endif
|
2016-04-12 07:12:21 +03:00
|
|
|
nsString mAdapter;
|
2015-05-04 22:40:29 +03:00
|
|
|
uint32_t mPluginId;
|
2016-04-12 07:12:21 +03:00
|
|
|
nsTArray<GMPCapability> mCapabilities;
|
2014-05-18 07:05:46 +04:00
|
|
|
GMPProcessParent* mProcess;
|
2014-07-28 19:42:55 +04:00
|
|
|
bool mDeleteProcessOnlyOnUnload;
|
|
|
|
bool mAbnormalShutdownInProgress;
|
2015-04-04 07:03:16 +03:00
|
|
|
bool mIsBlockingDeletion;
|
2014-05-18 07:05:46 +04:00
|
|
|
|
2015-04-30 07:52:29 +03:00
|
|
|
bool mCanDecrypt;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<GMPTimerParent>> mTimers;
|
|
|
|
nsTArray<RefPtr<GMPStorageParent>> mStorage;
|
2014-10-13 02:53:43 +04:00
|
|
|
// NodeId the plugin is assigned to, or empty if the the plugin is not
|
|
|
|
// assigned to a NodeId.
|
2015-11-19 12:00:39 +03:00
|
|
|
nsCString mNodeId;
|
2015-02-10 13:48:42 +03:00
|
|
|
// This is used for GMP content in the parent, there may be more of these in
|
|
|
|
// the content processes.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GMPContentParent> mGMPContentParent;
|
2016-11-09 05:52:22 +03:00
|
|
|
nsTArray<UniquePtr<MozPromiseHolder<GetGMPContentParentPromise>>> mGetContentParentPromises;
|
2015-02-10 13:48:42 +03:00
|
|
|
uint32_t mGMPContentChildCount;
|
2014-08-18 01:41:56 +04:00
|
|
|
|
2015-03-16 01:30:00 +03:00
|
|
|
int mChildPid;
|
2015-06-05 12:55:52 +03:00
|
|
|
|
|
|
|
// We hold a self reference to ourself while the child process is alive.
|
|
|
|
// This ensures that if the GMPService tries to shut us down and drops
|
|
|
|
// its reference to us, we stay alive long enough for the child process
|
|
|
|
// to terminate gracefully.
|
|
|
|
bool mHoldingSelfRef;
|
2017-02-12 22:39:44 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
UniquePtr<ipc::CrashReporterHost> mCrashReporter;
|
|
|
|
#endif
|
2017-03-09 10:31:11 +03:00
|
|
|
|
|
|
|
const RefPtr<AbstractThread> mMainThread;
|
2014-05-18 07:05:46 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace gmp
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // GMPParent_h_
|