Bug 681206 removeDelayedFrameScript, r=jst
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Wed, 24 Aug 2011 13:16:29 +0300
changeset 75799 e0acef471ab29856f4c7883dc2d1bb31afdfff77
parent 75798 5d9989c3bff69691e88ea139b18bb72ec836c6dd
child 75800 4599be47c692263897ab82272469fb7045e2b70c
child 75809 d79e6c3c0616982736bd8044d089d7487367deb4
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersjst
bugs681206
milestone9.0a1
Bug 681206 removeDelayedFrameScript, r=jst
content/base/public/nsIFrameMessageManager.idl
content/base/src/nsFrameMessageManager.cpp
content/base/test/chrome/file_bug549682.xul
--- a/content/base/public/nsIFrameMessageManager.idl
+++ b/content/base/public/nsIFrameMessageManager.idl
@@ -120,21 +120,26 @@ interface nsIInProcessContentFrameMessag
 
 [scriptable, uuid(6331bbca-2c9f-4766-b3c7-ae75554bf1ec)]
 interface nsITreeItemFrameMessageManager : nsIFrameMessageManager
 {
   readonly attribute unsigned long childCount;
   nsITreeItemFrameMessageManager getChildAt(in unsigned long aIndex);
 };
 
-[scriptable, uuid(23e6ef7b-8cc5-4e8b-9391-453440a3b858)]
+[scriptable, uuid(9e5c0526-aa4c-49f0-afbb-57f489cd9b59)]
 interface nsIChromeFrameMessageManager : nsITreeItemFrameMessageManager
 {
-  /*
+  /**
    * Load a script in the (remote) frame. aURL must be the absolute URL.
    * data: URLs are also supported. For example data:,dump("foo\n");
    * If aAllowDelayedLoad is true, script will be loaded when the
    * remote frame becomes available. Otherwise the script will be loaded
    * only if the frame is already available.
    */
   void loadFrameScript(in AString aURL, in boolean aAllowDelayedLoad);
+
+  /**
+   * Removes aURL from the list of scripts which support delayed load.
+   */
+  void removeDelayedFrameScript(in AString aURL);
 };
 
--- a/content/base/src/nsFrameMessageManager.cpp
+++ b/content/base/src/nsFrameMessageManager.cpp
@@ -172,16 +172,23 @@ nsFrameMessageManager::LoadFrameScript(c
       // Use PR_FALSE here, so that child managers don't cache the script, which
       // is already cached in the parent.
       mm->LoadFrameScript(aURL, PR_FALSE);
     }
   }
   return NS_OK;
 }
 
+NS_IMETHODIMP
+nsFrameMessageManager::RemoveDelayedFrameScript(const nsAString& aURL)
+{
+  mPendingScripts.RemoveElement(aURL);
+  return NS_OK;
+}
+
 static JSBool
 JSONCreator(const jschar* aBuf, uint32 aLen, void* aData)
 {
   nsAString* result = static_cast<nsAString*>(aData);
   result->Append((PRUnichar*)aBuf, (PRUint32)aLen);
   return JS_TRUE;
 }
 
--- a/content/base/test/chrome/file_bug549682.xul
+++ b/content/base/test/chrome/file_bug549682.xul
@@ -62,16 +62,26 @@ https://bugzilla.mozilla.org/show_bug.cg
     localmm.loadFrameScript("data:,sendAsyncMessage('lasync', { data: 2345 })", false);
 
     messageManager.addMessageListener("async", asyncL);
     messageManager.addMessageListener("sync", syncL);
     global.addMessageListener("async", globalListener);
     global.addMessageListener("sync", globalListener);
     global.addMessageListener("global-sync", globalListener);
     global.loadFrameScript("data:,sendSyncMessage('global-sync', { data: 1234 });", true);
+    var toBeRemovedScript = "data:,sendAsyncMessage('toberemoved', { data: 2345 })";
+    var c = 0;
+    messageManager.addMessageListener("toberemoved", function() {
+      ++c;
+      opener.wrappedJSObject.is(c, 1, "Should be called only once!");
+    });
+    // This loads the script in the existing <browser>
+    messageManager.loadFrameScript(toBeRemovedScript, true);
+    // But it won't be loaded in the dynamically created <browser>
+    messageManager.removeDelayedFrameScript(toBeRemovedScript);
 
     var oldValue = globalListenerCallCount;
     var b = document.createElement("browser");
     b.setAttribute("type", "content");
     document.documentElement.appendChild(b);
     opener.wrappedJSObject.is(globalListenerCallCount, oldValue + 1,
                               "Wrong message count");