Bug 1172396 - Update GMP trial creation pref from chrome process - r=cpearce

This commit is contained in:
Edwin Flores 2015-09-01 17:31:48 +12:00
parent 76a380c796
commit 88d7197c80
8 changed files with 109 additions and 10 deletions

View File

@ -77,6 +77,36 @@ GMPVideoDecoderTrialCreator::GetCreateTrialState(const nsAString& aKeySystem)
}
}
/* static */ void
GMPVideoDecoderTrialCreator::UpdateTrialCreateState(const nsAString& aKeySystem,
uint32_t aState)
{
UpdateTrialCreateState(aKeySystem, (TrialCreateState)aState);
}
/* static */ void
GMPVideoDecoderTrialCreator::UpdateTrialCreateState(const nsAString& aKeySystem,
TrialCreateState aState)
{
MOZ_ASSERT(NS_IsMainThread());
if (XRE_GetProcessType() == GeckoProcessType_Content) {
// Pref has to be set from the chrome process. Dispatch to chrome via
// GMPService.
nsCOMPtr<mozIGeckoMediaPluginService> service =
do_GetService("@mozilla.org/gecko-media-plugin-service;1");
NS_ENSURE_TRUE_VOID(service);
service->UpdateTrialCreateState(aKeySystem, (uint32_t)aState);
return;
}
const char* pref = TrialCreatePrefName(aKeySystem);
if (pref) {
Preferences::SetInt(pref, (int)aState);
}
}
void
GMPVideoDecoderTrialCreator::TrialCreateGMPVideoDecoderFailed(const nsAString& aKeySystem,
const nsACString& aReason)
@ -91,10 +121,8 @@ GMPVideoDecoderTrialCreator::TrialCreateGMPVideoDecoderFailed(const nsAString& a
return;
}
data->mStatus = Failed;
const char* pref = TrialCreatePrefName(aKeySystem);
if (pref) {
Preferences::SetInt(pref, (int)Failed);
}
UpdateTrialCreateState(aKeySystem, Failed);
for (nsRefPtr<AbstractPromiseLike>& promise: data->mPending) {
promise->Reject(NS_ERROR_DOM_NOT_SUPPORTED_ERR, aReason);
}
@ -115,10 +143,8 @@ GMPVideoDecoderTrialCreator::TrialCreateGMPVideoDecoderSucceeded(const nsAString
return;
}
data->mStatus = Succeeded;
const char* pref = TrialCreatePrefName(aKeySystem);
if (pref) {
Preferences::SetInt(pref, (int)Succeeded);
}
UpdateTrialCreateState(aKeySystem, Succeeded);
for (nsRefPtr<AbstractPromiseLike>& promise : data->mPending) {
promise->Resolve();
}

View File

@ -39,6 +39,8 @@ public:
MaybeAwaitTrialCreate(aKeySystem, p, aParent);
}
static void UpdateTrialCreateState(const nsAString& aKeySystem, uint32_t aState);
private:
class AbstractPromiseLike {
@ -88,6 +90,8 @@ private:
};
static TrialCreateState GetCreateTrialState(const nsAString& aKeySystem);
static void UpdateTrialCreateState(const nsAString& aKeySystem,
TrialCreateState aState);
struct TrialCreateData {
explicit TrialCreateData(const nsAString& aKeySystem)
@ -172,4 +176,4 @@ private:
} // namespace dom
} // namespace mozilla
#endif
#endif

View File

@ -181,6 +181,40 @@ GeckoMediaPluginServiceChild::GetNodeId(const nsAString& aOrigin,
return NS_OK;
}
NS_IMETHODIMP
GeckoMediaPluginServiceChild::UpdateTrialCreateState(const nsAString& aKeySystem,
uint32_t aState)
{
if (NS_GetCurrentThread() != mGMPThread) {
mGMPThread->Dispatch(NS_NewRunnableMethodWithArgs<nsString, uint32_t>(
this, &GeckoMediaPluginServiceChild::UpdateTrialCreateState,
aKeySystem, aState), NS_DISPATCH_NORMAL);
return NS_OK;
}
class Callback : public GetServiceChildCallback
{
public:
Callback(const nsAString& aKeySystem, uint32_t aState)
: mKeySystem(aKeySystem)
, mState(aState)
{ }
virtual void Done(GMPServiceChild* aService) override
{
aService->SendUpdateGMPTrialCreateState(mKeySystem, mState);
}
private:
nsString mKeySystem;
uint32_t mState;
};
UniquePtr<GetServiceChildCallback> callback(new Callback(aKeySystem, aState));
GetServiceChild(Move(callback));
return NS_OK;
}
NS_IMETHODIMP
GeckoMediaPluginServiceChild::Observe(nsISupports* aSubject,
const char* aTopic,

View File

@ -49,6 +49,8 @@ public:
const nsAString& aTopLevelOrigin,
bool aInPrivateBrowsingMode,
UniquePtr<GetNodeIdCallback>&& aCallback) override;
NS_IMETHOD UpdateTrialCreateState(const nsAString& aKeySystem,
uint32_t aState) override;
NS_DECL_NSIOBSERVER

View File

@ -9,6 +9,7 @@
#include "mozilla/Logging.h"
#include "GMPParent.h"
#include "GMPVideoDecoderParent.h"
#include "mozilla/dom/GMPVideoDecoderTrialCreator.h"
#include "nsIObserverService.h"
#include "GeckoChildProcessHost.h"
#include "mozilla/Preferences.h"
@ -1202,6 +1203,18 @@ GeckoMediaPluginServiceParent::GetNodeId(const nsAString& aOrigin,
return rv;
}
NS_IMETHODIMP
GeckoMediaPluginServiceParent::UpdateTrialCreateState(const nsAString& aKeySystem,
uint32_t aState)
{
nsString keySystem(aKeySystem);
NS_DispatchToMainThread(NS_NewRunnableFunction([keySystem, aState] {
mozilla::dom::GMPVideoDecoderTrialCreator::UpdateTrialCreateState(keySystem, aState);
}));
return NS_OK;
}
static bool
ExtractHostName(const nsACString& aOrigin, nsACString& aOutData)
{
@ -1571,6 +1584,14 @@ GMPServiceParent::RecvGetGMPNodeId(const nsString& aOrigin,
return NS_SUCCEEDED(rv);
}
bool
GMPServiceParent::RecvUpdateGMPTrialCreateState(const nsString& aKeySystem,
const uint32_t& aState)
{
mService->UpdateTrialCreateState(aKeySystem, aState);
return true;
}
/* static */
bool
GMPServiceParent::RecvGetGMPPluginVersionForAPI(const nsCString& aAPI,

View File

@ -43,6 +43,8 @@ public:
const nsAString& aTopLevelOrigin,
bool aInPrivateBrowsingMode,
UniquePtr<GetNodeIdCallback>&& aCallback) override;
NS_IMETHOD UpdateTrialCreateState(const nsAString& aKeySystem,
uint32_t aState) override;
NS_DECL_MOZIGECKOMEDIAPLUGINCHROMESERVICE
NS_DECL_NSIOBSERVER
@ -219,6 +221,8 @@ public:
nsTArray<nsCString>&& aTags,
bool* aHasPlugin,
nsCString* aVersion);
virtual bool RecvUpdateGMPTrialCreateState(const nsString& aKeySystem,
const uint32_t& aState) override;
virtual void ActorDestroy(ActorDestroyReason aWhy) override;

View File

@ -21,6 +21,8 @@ parent:
sync GetGMPNodeId(nsString origin, nsString topLevelOrigin,
bool inPrivateBrowsing)
returns (nsCString id);
async UpdateGMPTrialCreateState(nsString keySystem, uint32_t status);
};
} // namespace gmp

View File

@ -52,7 +52,7 @@ native GetGMPVideoDecoderCallback(mozilla::UniquePtr<GetGMPVideoDecoderCallback>
native GetGMPVideoEncoderCallback(mozilla::UniquePtr<GetGMPVideoEncoderCallback>&&);
native GetNodeIdCallback(mozilla::UniquePtr<GetNodeIdCallback>&&);
[scriptable, uuid(787cf744-eea8-48c8-b692-376e0485ef97)]
[scriptable, uuid(661492d6-726b-4ba0-8e6e-14bfaf2b62e4)]
interface mozIGeckoMediaPluginService : nsISupports
{
@ -147,4 +147,10 @@ interface mozIGeckoMediaPluginService : nsISupports
in AString topLevelOrigin,
in bool inPrivateBrowsingMode,
in GetNodeIdCallback callback);
/**
* Stores the result of trying to create a decoder for the given keysystem.
*/
[noscript]
void updateTrialCreateState(in AString keySystem, in uint32_t status);
};