Bug 1267918 - Remove obsolete GMP crash handling code. r=gerald
authorChris Pearce <cpearce@mozilla.com>
Wed, 29 Jun 2016 11:42:14 +1200
changeset 303411 7c72118d085a5cd547f83371435aad8fc7a96335
parent 303410 86d9f7174e213b464f179eb5effd5c61a7ffa85d
child 303412 456f9b45d6d6529974864253973a2fcf1be41cdd
push id30405
push usercbook@mozilla.com
push dateSat, 02 Jul 2016 09:16:44 +0000
treeherderautoland@73c0a2bba6db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1267918
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1267918 - Remove obsolete GMP crash handling code. r=gerald MozReview-Commit-ID: EqzJagCHk7n
dom/media/eme/MediaKeys.cpp
dom/media/gmp/GMPService.cpp
dom/media/gmp/GMPService.h
--- a/dom/media/eme/MediaKeys.cpp
+++ b/dom/media/eme/MediaKeys.cpp
@@ -406,31 +406,16 @@ MediaKeys::OnCDMCreated(PromiseId aId, c
   promise->MaybeResolve(keys);
   if (mCreatePromiseId == aId) {
     Release();
   }
 
   MediaKeySystemAccess::NotifyObservers(mParent,
                                         mKeySystem,
                                         MediaKeySystemStatus::Cdm_created);
-
-  if (aPluginId) {
-    // Prepare plugin crash reporter.
-    RefPtr<gmp::GeckoMediaPluginService> service =
-      gmp::GeckoMediaPluginService::GetGeckoMediaPluginService();
-    if (NS_WARN_IF(!service)) {
-      return;
-    }
-    if (NS_WARN_IF(!mParent)) {
-      return;
-    }
-    service->AddPluginCrashedEventTarget(aPluginId, mParent);
-    EME_LOG("MediaKeys[%p]::OnCDMCreated() registered crash handler for pluginId '%i'",
-            this, aPluginId);
-  }
 }
 
 already_AddRefed<MediaKeySession>
 MediaKeys::CreateSession(JSContext* aCx,
                          SessionType aSessionType,
                          ErrorResult& aRv)
 {
   if (!mProxy) {
--- a/dom/media/gmp/GMPService.cpp
+++ b/dom/media/gmp/GMPService.cpp
@@ -151,132 +151,16 @@ GeckoMediaPluginService::GeckoMediaPlugi
 {
   MOZ_ASSERT(NS_IsMainThread());
 }
 
 GeckoMediaPluginService::~GeckoMediaPluginService()
 {
 }
 
-void
-GeckoMediaPluginService::RemoveObsoletePluginCrashCallbacks()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  for (size_t i = mPluginCrashCallbacks.Length(); i != 0; --i) {
-    RefPtr<GMPCrashCallback>& callback = mPluginCrashCallbacks[i - 1];
-    if (!callback->IsStillValid()) {
-      LOGD(("%s::%s - Removing obsolete callback for pluginId %i",
-            __CLASS__, __FUNCTION__, callback->GetPluginId()));
-      mPluginCrashCallbacks.RemoveElementAt(i - 1);
-    }
-  }
-}
-
-GeckoMediaPluginService::GMPCrashCallback::GMPCrashCallback(const uint32_t aPluginId,
-                                                            nsPIDOMWindowInner* aParentWindow,
-                                                            nsIDocument* aDocument)
-  : mPluginId(aPluginId)
-  , mParentWindowWeakPtr(do_GetWeakReference(aParentWindow))
-  , mDocumentWeakPtr(do_GetWeakReference(aDocument))
-{
-  MOZ_ASSERT(NS_IsMainThread());
-}
-
-void
-GeckoMediaPluginService::GMPCrashCallback::Run(const nsACString& aPluginName)
-{
-  dom::PluginCrashedEventInit init;
-  init.mPluginID = mPluginId;
-  init.mBubbles = true;
-  init.mCancelable = true;
-  init.mGmpPlugin = true;
-  CopyUTF8toUTF16(aPluginName, init.mPluginName);
-  init.mSubmittedCrashReport = false;
-
-  // The following PluginCrashedEvent fields stay empty:
-  // init.mBrowserDumpID
-  // init.mPluginFilename
-  // TODO: Can/should we fill them?
-
-  nsCOMPtr<nsPIDOMWindowInner> parentWindow;
-  nsCOMPtr<nsIDocument> document;
-  if (!GetParentWindowAndDocumentIfValid(parentWindow, document)) {
-    return;
-  }
-
-  RefPtr<dom::PluginCrashedEvent> event =
-    dom::PluginCrashedEvent::Constructor(document, NS_LITERAL_STRING("PluginCrashed"), init);
-  event->SetTrusted(true);
-  event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true;
-
-  EventDispatcher::DispatchDOMEvent(parentWindow, nullptr, event, nullptr, nullptr);
-}
-
-bool
-GeckoMediaPluginService::GMPCrashCallback::IsStillValid()
-{
-  nsCOMPtr<nsPIDOMWindowInner> parentWindow;
-  nsCOMPtr<nsIDocument> document;
-  return GetParentWindowAndDocumentIfValid(parentWindow, document);
-}
-
-bool
-GeckoMediaPluginService::GMPCrashCallback::GetParentWindowAndDocumentIfValid(
-  nsCOMPtr<nsPIDOMWindowInner>& parentWindow,
-  nsCOMPtr<nsIDocument>& document)
-{
-  parentWindow = do_QueryReferent(mParentWindowWeakPtr);
-  if (!parentWindow) {
-    return false;
-  }
-  document = do_QueryReferent(mDocumentWeakPtr);
-  if (!document) {
-    return false;
-  }
-  nsCOMPtr<nsIDocument> parentWindowDocument = parentWindow->GetExtantDoc();
-  if (!parentWindowDocument || document.get() != parentWindowDocument.get()) {
-    return false;
-  }
-  return true;
-}
-
-void
-GeckoMediaPluginService::AddPluginCrashedEventTarget(const uint32_t aPluginId,
-                                                     nsPIDOMWindowInner* aParentWindow)
-{
-  LOGD(("%s::%s(%i)", __CLASS__, __FUNCTION__, aPluginId));
-
-  if (NS_WARN_IF(!aParentWindow)) {
-    return;
-  }
-  nsCOMPtr<nsIDocument> doc = aParentWindow->GetExtantDoc();
-  if (NS_WARN_IF(!doc)) {
-    return;
-  }
-  RefPtr<GMPCrashCallback> callback(new GMPCrashCallback(aPluginId, aParentWindow, doc));
-  RemoveObsoletePluginCrashCallbacks();
-
-  // If the plugin with that ID has already crashed without being handled,
-  // just run the handler now.
-  for (size_t i = mPluginCrashes.Length(); i != 0; --i) {
-    size_t index = i - 1;
-    const PluginCrash& crash = mPluginCrashes[index];
-    if (crash.mPluginId == aPluginId) {
-      LOGD(("%s::%s(%i) - added crash handler for crashed plugin, running handler #%u",
-        __CLASS__, __FUNCTION__, aPluginId, index));
-      callback->Run(crash.mPluginName);
-      mPluginCrashes.RemoveElementAt(index);
-    }
-  }
-
-  // Remember crash, so if a handler is added for it later, we report the
-  // crash to that window too.
-  mPluginCrashCallbacks.AppendElement(callback);
-}
-
 NS_IMETHODIMP
 GeckoMediaPluginService::RunPluginCrashCallbacks(uint32_t aPluginId,
                                                  const nsACString& aPluginName)
 {
   MOZ_ASSERT(NS_IsMainThread());
   LOGD(("%s::%s(%i)", __CLASS__, __FUNCTION__, aPluginId));
 
   nsAutoPtr<nsTArray<RefPtr<GMPCrashHelper>>> helpers;
--- a/dom/media/gmp/GMPService.h
+++ b/dom/media/gmp/GMPService.h
@@ -92,33 +92,25 @@ public:
                              UniquePtr<GetGMPDecryptorCallback>&& aCallback)
     override;
 
   int32_t AsyncShutdownTimeoutMs();
 
   NS_IMETHOD RunPluginCrashCallbacks(uint32_t aPluginId,
                                      const nsACString& aPluginName) override;
 
-  // Sets the window to which 'PluginCrashed' chromeonly event is dispatched.
-  // Note: if the plugin has crashed before the target window has been set,
-  // the 'PluginCrashed' event is dispatched as soon as a target window is set.
-  void AddPluginCrashedEventTarget(const uint32_t aPluginId,
-                                   nsPIDOMWindowInner* aParentWindow);
-
   RefPtr<AbstractThread> GetAbstractGMPThread();
 
   void ConnectCrashHelper(uint32_t aPluginId, GMPCrashHelper* aHelper);
   void DisconnectCrashHelper(GMPCrashHelper* aHelper);
 
 protected:
   GeckoMediaPluginService();
   virtual ~GeckoMediaPluginService();
 
-  void RemoveObsoletePluginCrashCallbacks(); // Called from add/run.
-
   virtual void InitializePlugins(AbstractThread* aAbstractGMPThread) = 0;
   virtual bool GetContentParentFrom(GMPCrashHelper* aHelper,
                                     const nsACString& aNodeId,
                                     const nsCString& aAPI,
                                     const nsTArray<nsCString>& aTags,
                                     UniquePtr<GetGMPContentParentCallback>&& aCallback) = 0;
 
   nsresult GMPDispatch(nsIRunnable* event, uint32_t flags = NS_DISPATCH_NORMAL);
@@ -127,58 +119,15 @@ protected:
 
   Mutex mMutex; // Protects mGMPThread, mAbstractGMPThread, mPluginCrashHelpers,
                 // mGMPThreadShutdown and some members in derived classes.
   nsCOMPtr<nsIThread> mGMPThread;
   RefPtr<AbstractThread> mAbstractGMPThread;
   bool mGMPThreadShutdown;
   bool mShuttingDownOnGMPThread;
 
-  class GMPCrashCallback
-  {
-  public:
-    NS_INLINE_DECL_REFCOUNTING(GMPCrashCallback)
-
-    GMPCrashCallback(const uint32_t aPluginId,
-                     nsPIDOMWindowInner* aParentWindow,
-                     nsIDocument* aDocument);
-    void Run(const nsACString& aPluginName);
-    bool IsStillValid();
-    uint32_t GetPluginId() const { return mPluginId; }
-  private:
-    virtual ~GMPCrashCallback() { MOZ_ASSERT(NS_IsMainThread()); }
-
-    bool GetParentWindowAndDocumentIfValid(nsCOMPtr<nsPIDOMWindowInner>& parentWindow,
-                                           nsCOMPtr<nsIDocument>& document);
-    const uint32_t mPluginId;
-    nsWeakPtr mParentWindowWeakPtr;
-    nsWeakPtr mDocumentWeakPtr;
-  };
-
-  struct PluginCrash
-  {
-    PluginCrash(uint32_t aPluginId,
-                const nsACString& aPluginName)
-      : mPluginId(aPluginId)
-      , mPluginName(aPluginName)
-    {
-    }
-    uint32_t mPluginId;
-    nsCString mPluginName;
-
-    bool operator==(const PluginCrash& aOther) const {
-      return mPluginId == aOther.mPluginId &&
-             mPluginName == aOther.mPluginName;
-    }
-  };
-
-  static const size_t MAX_PLUGIN_CRASHES = 100;
-  nsTArray<PluginCrash> mPluginCrashes;
-
-  nsTArray<RefPtr<GMPCrashCallback>> mPluginCrashCallbacks;
-
   nsClassHashtable<nsUint32HashKey, nsTArray<RefPtr<GMPCrashHelper>>> mPluginCrashHelpers;
 };
 
 } // namespace gmp
 } // namespace mozilla
 
 #endif // GMPService_h_