Bug 822040 - Cleanup the channel when plugins reject their initial stream. r=josh
authorJohn Schoenick <jschoenick@mozilla.com>
Sun, 16 Dec 2012 00:25:04 -0800
changeset 125343 aba8a2ef62253e0fe8d6807d591300ab8af2e46c
parent 125342 4b1328bd377ce7c1d667df83e75a355fdb15af8d
child 125344 8d66bb18b4a309ead5506630fa8c44c9553065a9
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjosh
bugs822040
milestone20.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 822040 - Cleanup the channel when plugins reject their initial stream. r=josh
content/base/src/nsObjectLoadingContent.cpp
dom/plugins/test/mochitest/test_pluginstream_err.html
--- a/content/base/src/nsObjectLoadingContent.cpp
+++ b/content/base/src/nsObjectLoadingContent.cpp
@@ -1957,22 +1957,24 @@ nsObjectLoadingContent::LoadObject(bool 
 
   rv = NS_OK;
   if (doSpawnPlugin) {
     rv = InstantiatePluginInstance(true);
     NS_ENSURE_TRUE(mIsLoading, NS_OK);
     // Create the final listener if we're loading with a channel. We can't do
     // this in the loading block above as it requires an instance.
     if (aLoadingChannel && NS_SUCCEEDED(rv)) {
-      // Plugins can continue to run even if their initial stream dies. Some
-      // plugins will even return failure codes to reject the stream, but expect
-      // to continue running, so ignore the error code. rv is thus the result of
-      // spawning the plugin above
       if (NS_SUCCEEDED(rv) && MakePluginListener()) {
-        mFinalListener->OnStartRequest(mChannel, nullptr);
+        rv = mFinalListener->OnStartRequest(mChannel, nullptr);
+        if (NS_FAILED(rv)) {
+          // Plugins can reject their initial stream, but continue to run.
+          CloseChannel();
+          NS_ENSURE_TRUE(mIsLoading, NS_OK);
+          rv = NS_OK;
+        }
       }
     }
   } else if (finalListener) {
     NS_ASSERTION(mType != eType_Null && mType != eType_Loading,
                  "We should not have a final listener with a non-loaded type");
     mFinalListener = finalListener;
     rv = finalListener->OnStartRequest(mChannel, nullptr);
   }
--- a/dom/plugins/test/mochitest/test_pluginstream_err.html
+++ b/dom/plugins/test/mochitest/test_pluginstream_err.html
@@ -36,57 +36,57 @@ SimpleTest.waitForExplicitFinish();
 
 var tests = [
   {
     "src": "loremipsum.txt",
     "streammode": "normal",
     "functiontofail": "npp_newstream",
     "failurecode": "1",
     "frame": "testframe"
-  }, 
+  },
   {
     "src": "loremipsum.txt",
     "streammode": "normal",
     "functiontofail": "npp_newstream",
     "failurecode": "3",
     "frame": "testframe"
-  }, 
+  },
   {
     "src": "loremipsum.txt",
     "streammode": "normal",
     "functiontofail": "npp_newstream",
     "failurecode": "5",
     "frame": "testframe"
-  }, 
+  },
   {
     "geturl": "loremipsum.txt",
     "streammode": "normal",
     "functiontofail": "npp_newstream",
     "failurecode": "1",
     "frame": "testframe"
-  }, 
+  },
   {
     "src": "loremipsum.txt",
     "streammode": "normal",
     "functiontofail": "npp_write",
     "frame": "testframe"
-  }, 
+  },
   {
     "src": "loremipsum.txt",
     "streammode": "asfile",
     "functiontofail": "npp_write",
     "frame": "testframe"
-  }, 
+  },
   {
     "src": "loremipsum.txt",
     "streammode": "normal",
     "functiontofail": "npp_destroystream",
     "failurecode": "1",
     "frame": "testframe"
-  }, 
+  },
 ];
 
 function iframeonload(evt) {
   var contentLength = evt.target.contentDocument.body.innerHTML.length;
   var plugin = gTestWindow.document.getElementById("embedtest");
   var functionToFail = plugin.getAttribute("functiontofail");
   if (contentLength > 0) {
     is(evt.target.contentDocument.body.innerHTML, "pass",
@@ -99,52 +99,64 @@ function iframeonload(evt) {
       setTimeout(runNextTest, 10);
     }, functionToFail == "npp_newstream" ? 500 : 10);
   }
 }
 
 var index = 0;
 var gTestWindow;
 function runNextTest() {
-  if (index == tests.length) {
+  if (index == tests.length * 2) {
     SimpleTest.finish();
     return;
   }
 
-  gTestWindow = window.open("plugin_window.html", 
-                            "", 
+  gTestWindow = window.open("plugin_window.html",
+                            "",
                             "width=620,height=320");
 }
 
 function continueTest() {
-  var test = tests[index];
-  
+  // We run each test as an embed and an object, as their initial stream
+  // handling differs.
+  var tag = index % 2 ? "embed" : "object";
+  var test = tests[Math.floor(index / 2)];
+
   var p = gTestWindow.document.createElement("p");
   p.innerHTML = "Plugin Stream Test " + index;
   gTestWindow.document.getElementById("test").appendChild(p);
-  
+
   if (test.frame) {
     var iframe = gTestWindow.document.createElement("iframe");
     iframe.name = test.frame;
     iframe.onload = iframeonload;
     gTestWindow.document.getElementById("test").appendChild(iframe);
   }
-  
-  var embed = gTestWindow.document.createElement("embed");
-  embed.setAttribute("id", "embedtest");
-  embed.setAttribute("style", "width: 400px; height: 100px;");
-  embed.setAttribute("type", "application/x-test");
+
+  var plugin = gTestWindow.document.createElement(tag);
+  plugin.setAttribute("id", "embedtest");
+  plugin.setAttribute("style", "width: 400px; height: 100px;");
+  plugin.setAttribute("type", "application/x-test");
   for (var name in test) {
-    embed.setAttribute(name, test[name]);
+    if (tag == "embed") {
+      plugin.setAttribute(name, test[name]);
+    } else if (name == "src") {
+      plugin.setAttribute("data", test[name]);
+    } else {
+      var param = document.createElement("param");
+      param.name = name;
+      param.value = test[name];
+      plugin.appendChild(param);
+    }
   }
-  gTestWindow.document.getElementById("test").appendChild(embed);
-  
+  gTestWindow.document.getElementById("test").appendChild(plugin);
+
   gTestWindow.document.getElementById("test")
                       .appendChild(document.createElement("br"));
-  
-  index++; 
+
+  index++;
 }
 
 </script>
 </div>
 </body>
 </html>