Bug 1174461 - [e10s] Return a cached result from SendGetNativePluginPort (r=jimm) a=kwierso
authorBill McCloskey <billm@mozilla.com>
Fri, 11 Mar 2016 20:25:59 -0800
changeset 314816 da683f5c0a43b8ee64b604406d784667b474f6d1
parent 314815 2f39deb1b3e2865ced9cead27a03e97d729fbcfb
child 314817 c91015c43d5556059210a2cffac02e7a5c547ed5
push id9480
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 17:12:58 +0000
treeherdermozilla-aurora@0d6a91c76a9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm, kwierso
bugs1174461
milestone48.0a1
Bug 1174461 - [e10s] Return a cached result from SendGetNativePluginPort (r=jimm) a=kwierso MozReview-Commit-ID: FyeWtg0Py5p
widget/PluginWidgetProxy.cpp
widget/PluginWidgetProxy.h
widget/nsBaseWidget.cpp
--- a/widget/PluginWidgetProxy.cpp
+++ b/widget/PluginWidgetProxy.cpp
@@ -30,17 +30,18 @@ NS_IMPL_ISUPPORTS_INHERITED(PluginWidget
     NS_WARNING("called on an invalid channel.");              \
     return NS_ERROR_FAILURE;                                  \
   }                                                           \
 } while (0)
 
 PluginWidgetProxy::PluginWidgetProxy(dom::TabChild* aTabChild,
                                      mozilla::plugins::PluginWidgetChild* aActor) :
   PuppetWidget(aTabChild),
-  mActor(aActor)
+  mActor(aActor),
+  mCachedPluginPort(0)
 {
   // See ChannelDestroyed() in the header
   mActor->SetWidget(this);
 }
 
 PluginWidgetProxy::~PluginWidgetProxy()
 {
   PWLOG("PluginWidgetProxy::~PluginWidgetProxy()\n");
@@ -58,37 +59,37 @@ PluginWidgetProxy::Create(nsIWidget* aPa
   nsresult rv = NS_ERROR_UNEXPECTED;
   mActor->SendCreate(&rv);
   if (NS_FAILED(rv)) {
     NS_WARNING("failed to create chrome widget, plugins won't paint.");
     return rv;
   }
 
   BaseCreate(aParent, aInitData);
+  mParent = aParent;
 
   mBounds = aRect;
   mEnabled = true;
   mVisible = true;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PluginWidgetProxy::SetParent(nsIWidget* aNewParent)
 {
-  mParent = aNewParent;
-
   nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
   nsIWidget* parent = GetParent();
   if (parent) {
     parent->RemoveChild(this);
   }
   if (aNewParent) {
     aNewParent->AddChild(this);
   }
+  mParent = aNewParent;
   return NS_OK;
 }
 
 nsIWidget*
 PluginWidgetProxy::GetParent(void)
 {
   return mParent.get();
 }
@@ -130,20 +131,24 @@ PluginWidgetProxy::GetNativeData(uint32_
     case NS_NATIVE_PLUGIN_PORT:
     case NS_NATIVE_WINDOW:
     case NS_NATIVE_SHAREABLE_WINDOW:
       break;
     default:
       NS_WARNING("PluginWidgetProxy::GetNativeData received request for unsupported data type.");
       return nullptr;
   }
-  uintptr_t value = 0;
-  mActor->SendGetNativePluginPort(&value);
-  PWLOG("PluginWidgetProxy::GetNativeData %p\n", (void*)value);
-  return (void*)value;
+  // The parent side window handle or xid never changes so we can
+  // cache this for our lifetime.
+  if (mCachedPluginPort) {
+    return (void*)mCachedPluginPort;
+  }
+  mActor->SendGetNativePluginPort(&mCachedPluginPort);
+  PWLOG("PluginWidgetProxy::GetNativeData %p\n", (void*)mCachedPluginPort);
+  return (void*)mCachedPluginPort;
 }
 
 #if defined(XP_WIN)
 void
 PluginWidgetProxy::SetNativeData(uint32_t aDataType, uintptr_t aVal)
 {
   if (!mActor) {
     return;
--- a/widget/PluginWidgetProxy.h
+++ b/widget/PluginWidgetProxy.h
@@ -62,14 +62,15 @@ public:
   void ChannelDestroyed() { mActor = nullptr; }
 
 private:
   // Our connection with the chrome widget, created on PBrowser.
   mozilla::plugins::PluginWidgetChild* mActor;
   // PuppetWidget does not implement parent apis, but we need
   // them for plugin widgets.
   nsCOMPtr<nsIWidget> mParent;
+  uintptr_t mCachedPluginPort;
 };
 
 } // namespace widget
 } // namespace mozilla
 
 #endif
--- a/widget/nsBaseWidget.cpp
+++ b/widget/nsBaseWidget.cpp
@@ -587,25 +587,25 @@ double nsIWidget::DefaultScaleOverride()
 
 //-------------------------------------------------------------------------
 //
 // Add a child to the list of children
 //
 //-------------------------------------------------------------------------
 void nsBaseWidget::AddChild(nsIWidget* aChild)
 {
-  NS_PRECONDITION(!aChild->GetNextSibling() && !aChild->GetPrevSibling(),
-                  "aChild not properly removed from its old child list");
+  MOZ_RELEASE_ASSERT(!aChild->GetNextSibling() && !aChild->GetPrevSibling(),
+                     "aChild not properly removed from its old child list");
 
   if (!mFirstChild) {
     mFirstChild = mLastChild = aChild;
   } else {
     // append to the list
-    NS_ASSERTION(mLastChild, "Bogus state");
-    NS_ASSERTION(!mLastChild->GetNextSibling(), "Bogus state");
+    MOZ_RELEASE_ASSERT(mLastChild);
+    MOZ_RELEASE_ASSERT(!mLastChild->GetNextSibling());
     mLastChild->SetNextSibling(aChild);
     aChild->SetPrevSibling(mLastChild);
     mLastChild = aChild;
   }
 }
 
 
 //-------------------------------------------------------------------------
@@ -617,17 +617,17 @@ void nsBaseWidget::RemoveChild(nsIWidget
 {
 #ifdef DEBUG
 #ifdef XP_MACOSX
   // nsCocoaWindow doesn't implement GetParent, so in that case parent will be
   // null and we'll just have to do without this assertion.
   nsIWidget* parent = aChild->GetParent();
   NS_ASSERTION(!parent || parent == this, "Not one of our kids!");
 #else
-  NS_ASSERTION(aChild->GetParent() == this, "Not one of our kids!");
+  MOZ_RELEASE_ASSERT(aChild->GetParent() == this, "Not one of our kids!");
 #endif
 #endif
 
   if (mLastChild == aChild) {
     mLastChild = mLastChild->GetPrevSibling();
   }
   if (mFirstChild == aChild) {
     mFirstChild = mFirstChild->GetNextSibling();