Bug 1174461 - Cache NS_NATIVE_PLUGIN_PORT on the content side since it never changes. r=aklotz, a=kglazko
☠☠ backed out by 28deff24e5f9 ☠ ☠
authorJim Mathies <jmathies@mozilla.com>
Thu, 09 Jul 2015 19:07:48 -0500
changeset 281481 c3e5e5213726c7b24bd199eccd942b9b6ce5096c
parent 281480 d1d1000403e50799bfcdc9c65dc18738095a5ef9
child 281482 40139fab6775b70b64d0c6ea5555a229f0b35194
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaklotz, kglazko
bugs1174461
milestone41.0a2
Bug 1174461 - Cache NS_NATIVE_PLUGIN_PORT on the content side since it never changes. r=aklotz, a=kglazko
widget/PluginWidgetProxy.cpp
widget/PluginWidgetProxy.h
--- 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");
@@ -69,26 +70,25 @@ PluginWidgetProxy::Create(nsIWidget*    
   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 +130,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
@@ -61,13 +61,14 @@ 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