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-08-03 01:29:26 +04:00
|
|
|
#include "GMPAudioDecoderParent.h"
|
2014-07-28 03:20:34 +04:00
|
|
|
#include "GMPDecryptorParent.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"
|
2014-07-11 07:36:38 +04:00
|
|
|
#include "ThreadSafeRefcountingWithMainThreadDestruction.h"
|
2014-05-18 07:05:46 +04:00
|
|
|
|
|
|
|
class nsIThread;
|
|
|
|
|
2014-07-18 21:35:44 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
#include "nsExceptionHandler.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class PCrashReporterParent;
|
|
|
|
class CrashReporterParent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-05-18 07:05:46 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gmp {
|
|
|
|
|
|
|
|
class GMPCapability
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsCString mAPIName;
|
|
|
|
nsTArray<nsCString> mAPITags;
|
|
|
|
};
|
|
|
|
|
|
|
|
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 GetGMPContentParentCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GetGMPContentParentCallback()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(GetGMPContentParentCallback);
|
|
|
|
};
|
|
|
|
virtual ~GetGMPContentParentCallback()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(GetGMPContentParentCallback);
|
|
|
|
};
|
|
|
|
virtual void Done(GMPContentParent* aGMPContentParent) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class GMPParent final : public PGMPParent
|
2014-05-18 07:05:46 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-07-11 07:36:38 +04:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING_WITH_MAIN_THREAD_DESTRUCTION(GMPParent)
|
2014-05-18 07:05:46 +04:00
|
|
|
|
|
|
|
GMPParent();
|
|
|
|
|
2015-02-09 23:54:12 +03:00
|
|
|
nsresult Init(GeckoMediaPluginServiceParent* aService, nsIFile* aPluginDir);
|
2014-07-28 19:42:55 +04:00
|
|
|
nsresult CloneFrom(const GMPParent* aOther);
|
|
|
|
|
2014-07-31 01:40:43 +04:00
|
|
|
void Crash();
|
|
|
|
|
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
|
|
|
bool SupportsAPI(const nsCString& aAPI, const nsCString& aTag);
|
2014-07-28 03:20:34 +04:00
|
|
|
|
2014-05-18 07:05:46 +04:00
|
|
|
GMPState State() const;
|
|
|
|
nsIThread* GMPThread();
|
|
|
|
|
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;
|
2015-05-04 22:40:29 +03:00
|
|
|
const uint32_t GetPluginId() 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();
|
|
|
|
|
2015-02-10 13:48:42 +03:00
|
|
|
bool GetGMPContentParent(UniquePtr<GetGMPContentParentCallback>&& aCallback);
|
|
|
|
already_AddRefed<GMPContentParent> ForgetGMPContentParent();
|
|
|
|
|
2015-02-10 13:49:03 +03:00
|
|
|
bool EnsureProcessLoaded(base::ProcessId* aID);
|
|
|
|
|
|
|
|
bool Bridge(GMPServiceParent* aGMPServiceParent);
|
|
|
|
|
2014-05-18 07:05:46 +04:00
|
|
|
private:
|
|
|
|
~GMPParent();
|
2015-02-09 23:54:12 +03:00
|
|
|
nsRefPtr<GeckoMediaPluginServiceParent> mService;
|
2014-05-18 07:05:46 +04:00
|
|
|
bool EnsureProcessLoaded();
|
|
|
|
nsresult ReadGMPMetaData();
|
2014-07-18 21:35:44 +04:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
void WriteExtraDataForMinidump(CrashReporter::AnnotationTable& notes);
|
|
|
|
void GetCrashID(nsString& aResult);
|
|
|
|
#endif
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
|
2014-07-18 21:35:44 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual PCrashReporterParent* AllocPCrashReporterParent(const NativeThreadId& aThread) override;
|
|
|
|
virtual bool DeallocPCrashReporterParent(PCrashReporterParent* aCrashReporter) override;
|
2014-07-28 03:20:34 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool RecvPGMPStorageConstructor(PGMPStorageParent* actor) override;
|
|
|
|
virtual PGMPStorageParent* AllocPGMPStorageParent() override;
|
|
|
|
virtual bool DeallocPGMPStorageParent(PGMPStorageParent* aActor) override;
|
2014-08-19 12:56:33 +04:00
|
|
|
|
2015-02-10 13:48:42 +03:00
|
|
|
virtual PGMPContentParent* AllocPGMPContentParent(Transport* aTransport,
|
|
|
|
ProcessId aOtherPid) override;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool RecvPGMPTimerConstructor(PGMPTimerParent* actor) override;
|
|
|
|
virtual PGMPTimerParent* AllocPGMPTimerParent() override;
|
|
|
|
virtual bool DeallocPGMPTimerParent(PGMPTimerParent* aActor) override;
|
2014-08-05 11:56:05 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool RecvAsyncShutdownComplete() override;
|
|
|
|
virtual bool RecvAsyncShutdownRequired() override;
|
2014-08-18 01:41:56 +04:00
|
|
|
|
2015-02-10 13:48:42 +03:00
|
|
|
virtual bool RecvPGMPContentChildDestroyed() override;
|
|
|
|
bool IsUsed()
|
|
|
|
{
|
|
|
|
return mGMPContentChildCount > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-22 00:45:18 +04:00
|
|
|
nsresult EnsureAsyncShutdownTimeoutSet();
|
|
|
|
|
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;
|
2015-05-04 22:40:29 +03:00
|
|
|
uint32_t mPluginId;
|
2014-05-18 07:05:46 +04:00
|
|
|
nsTArray<nsAutoPtr<GMPCapability>> mCapabilities;
|
|
|
|
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;
|
|
|
|
|
2014-08-18 01:41:56 +04:00
|
|
|
nsTArray<nsRefPtr<GMPTimerParent>> mTimers;
|
2014-08-19 12:56:33 +04:00
|
|
|
nsTArray<nsRefPtr<GMPStorageParent>> mStorage;
|
2014-05-18 07:05:46 +04:00
|
|
|
nsCOMPtr<nsIThread> mGMPThread;
|
2014-10-22 00:45:18 +04:00
|
|
|
nsCOMPtr<nsITimer> mAsyncShutdownTimeout; // GMP Thread only.
|
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.
|
|
|
|
nsAutoCString 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.
|
|
|
|
nsRefPtr<GMPContentParent> mGMPContentParent;
|
|
|
|
nsTArray<UniquePtr<GetGMPContentParentCallback>> mCallbacks;
|
|
|
|
uint32_t mGMPContentChildCount;
|
2014-08-18 01:41:56 +04:00
|
|
|
|
|
|
|
bool mAsyncShutdownRequired;
|
|
|
|
bool mAsyncShutdownInProgress;
|
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;
|
2014-05-18 07:05:46 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace gmp
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // GMPParent_h_
|