Bug 1314530 Part3 - Instantiate MediaDrmCDMProxy if it is widevine on fennec. r=cpearce
authorJames Cheng <jacheng@mozilla.com>
Mon, 07 Nov 2016 14:03:44 +0800
changeset 351571 971aaa1646ed6eaa1ea4e0c678cad615e143c6d6
parent 351570 13f6bd96aa7805497d31ab9d9543232a31637a38
child 351572 ab0995a0dc10eba235acf5ca1eb331a58bebdfa8
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1314530
milestone52.0a1
Bug 1314530 Part3 - Instantiate MediaDrmCDMProxy if it is widevine on fennec. r=cpearce MozReview-Commit-ID: AhNBaO5LPwe
dom/media/eme/MediaKeys.cpp
dom/media/eme/MediaKeys.h
--- a/dom/media/eme/MediaKeys.cpp
+++ b/dom/media/eme/MediaKeys.cpp
@@ -10,16 +10,19 @@
 #include "mozilla/dom/MediaKeysBinding.h"
 #include "mozilla/dom/MediaKeyMessageEvent.h"
 #include "mozilla/dom/MediaKeyError.h"
 #include "mozilla/dom/MediaKeySession.h"
 #include "mozilla/dom/DOMException.h"
 #include "mozilla/dom/UnionTypes.h"
 #include "mozilla/Telemetry.h"
 #include "GMPCDMProxy.h"
+#ifdef MOZ_WIDGET_ANDROID
+#include "mozilla/MediaDrmCDMProxy.h"
+#endif
 #include "mozilla/EMEUtils.h"
 #include "nsContentUtils.h"
 #include "nsIScriptObjectPrincipal.h"
 #include "nsContentTypeParser.h"
 #ifdef MOZ_FMP4
 #include "MP4Decoder.h"
 #endif
 #ifdef XP_WIN
@@ -320,30 +323,48 @@ public:
     EME_LOG("MediaKeysGMPCrashHelper::GetPluginCrashedEventTarget()");
     return (mMediaKeys && mMediaKeys->GetParentObject()) ?
       do_AddRef(mMediaKeys->GetParentObject()) : nullptr;
   }
 private:
   WeakPtr<MediaKeys> mMediaKeys;
 };
 
+already_AddRefed<CDMProxy>
+MediaKeys::CreateCDMProxy()
+{
+  RefPtr<CDMProxy> proxy;
+#ifdef MOZ_WIDGET_ANDROID
+  if (IsWidevineKeySystem(mKeySystem)) {
+    proxy = new MediaDrmCDMProxy(this,
+                                 mKeySystem,
+                                 mConfig.mDistinctiveIdentifier == MediaKeysRequirement::Required,
+                                 mConfig.mPersistentState == MediaKeysRequirement::Required);
+  } else
+#endif
+  {
+    proxy = new GMPCDMProxy(this,
+                            mKeySystem,
+                            new MediaKeysGMPCrashHelper(this),
+                            mConfig.mDistinctiveIdentifier == MediaKeysRequirement::Required,
+                            mConfig.mPersistentState == MediaKeysRequirement::Required);
+  }
+  return proxy.forget();
+}
+
 already_AddRefed<DetailedPromise>
 MediaKeys::Init(ErrorResult& aRv)
 {
   RefPtr<DetailedPromise> promise(MakePromise(aRv,
     NS_LITERAL_CSTRING("MediaKeys::Init()")));
   if (aRv.Failed()) {
     return nullptr;
   }
 
-  mProxy = new GMPCDMProxy(this,
-                           mKeySystem,
-                           new MediaKeysGMPCrashHelper(this),
-                           mConfig.mDistinctiveIdentifier == MediaKeysRequirement::Required,
-                           mConfig.mPersistentState == MediaKeysRequirement::Required);
+  mProxy = CreateCDMProxy();
 
   // Determine principal (at creation time) of the MediaKeys object.
   nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(GetParentObject());
   if (!sop) {
     promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR,
                          NS_LITERAL_CSTRING("Couldn't get script principal in MediaKeys::Init"));
     return promise.forget();
   }
--- a/dom/media/eme/MediaKeys.h
+++ b/dom/media/eme/MediaKeys.h
@@ -128,16 +128,20 @@ public:
   // Shutdown which is called from the script/dom side.
   void Terminated();
 
   // Returns true if this MediaKeys has been bound to a media element.
   bool IsBoundToMediaElement() const;
 
 private:
 
+  // Instantiate CDMProxy instance.
+  // It could be MediaDrmCDMProxy (Widevine on Fennec) or GMPCDMProxy (the rest).
+  already_AddRefed<CDMProxy> CreateCDMProxy();
+
   // Removes promise from mPromises, and returns it.
   already_AddRefed<DetailedPromise> RetrievePromise(PromiseId aId);
 
   // Owning ref to proxy. The proxy has a weak reference back to the MediaKeys,
   // and the MediaKeys destructor clears the proxy's reference to the MediaKeys.
   RefPtr<CDMProxy> mProxy;
 
   RefPtr<HTMLMediaElement> mElement;