Bug 771202 - Implement post-transplant plugin behavior. r=bsmedberg
authorBobby Holley <bobbyholley@gmail.com>
Fri, 13 Jul 2012 10:55:14 +0200
changeset 101887 101bc799fc73aa2cfb98297111e0fdc4585c92ba
parent 101886 0d561abceeb30d041ae0700e460f2f2862368a64
child 101888 ff73dacf8eb303427185448d5b0dbee9db246151
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg
bugs771202
milestone16.0a1
Bug 771202 - Implement post-transplant plugin behavior. r=bsmedberg
dom/base/nsDOMClassInfo.cpp
dom/plugins/base/nsJSNPRuntime.cpp
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -9885,17 +9885,23 @@ nsHTMLPluginObjElementSH::PostCreate(nsI
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLPluginObjElementSH::PostTransplant(nsIXPConnectWrappedNative *wrapper,
                                          JSContext *cx, JSObject *obj)
 {
-  // XXXbholley - Implement me!
+  // Call through to PostCreate to do the prototype setup all over again. We
+  // may reuse the same prototype, in which case our prototype will be a wrapped
+  // version of the original.
+  nsresult rv = PostCreate(wrapper, cx, obj);
+  if (NS_FAILED(rv)) {
+      NS_WARNING("Calling PostCreate during PostTransplant for plugin element failed.");
+  }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLPluginObjElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
                                       JSContext *cx, JSObject *obj, jsid id,
                                       jsval *vp, bool *_retval)
 {
--- a/dom/plugins/base/nsJSNPRuntime.cpp
+++ b/dom/plugins/base/nsJSNPRuntime.cpp
@@ -1807,18 +1807,23 @@ nsNPObjWrapper::GetNewOrUsed(NPP npp, JS
   if (!entry) {
     // Out of memory
     JS_ReportOutOfMemory(cx);
 
     return nsnull;
   }
 
   if (PL_DHASH_ENTRY_IS_BUSY(entry) && entry->mJSObj) {
-    // Found a live NPObject wrapper, return it.
-    return entry->mJSObj;
+    // Found a live NPObject wrapper. It may not be in the same compartment
+    // as cx, so we need to wrap it before returning it.
+    JSObject *obj = entry->mJSObj;
+    if (!JS_WrapObject(cx, &obj)) {
+      return NULL;
+    }
+    return obj;
   }
 
   entry->mNPObj = npobj;
   entry->mNpp = npp;
 
   JSAutoRequest ar(cx);
 
   PRUint32 generation = sNPObjWrappers.generation;