Bug 749455 - Use mContentType for click-to-play plugins in nsObjectLoadingContent::OnStartRequest. r=josh
authorDavid Keeler <dkeeler@mozilla.com>
Fri, 27 Apr 2012 17:01:07 -0700
changeset 101066 62c03a248faaa3600cd601d43a5c8d52a7c91384
parent 101065 c88602e44a5bb7a214c1b4a089c7044b701ce14e
child 101067 700a03cd53d41c7795b3a3ad2ecba9d36c91eb1d
push id1316
push userakeybl@mozilla.com
push dateMon, 27 Aug 2012 22:37:00 +0000
treeherdermozilla-beta@db4b09302ee2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjosh
bugs749455
milestone16.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 749455 - Use mContentType for click-to-play plugins in nsObjectLoadingContent::OnStartRequest. r=josh
browser/base/content/test/Makefile.in
browser/base/content/test/browser_pluginnotification.js
browser/base/content/test/plugin_bug749455.html
content/base/src/nsObjectLoadingContent.cpp
--- a/browser/base/content/test/Makefile.in
+++ b/browser/base/content/test/Makefile.in
@@ -223,16 +223,17 @@ endif
                  plugin_test2.html \
                  plugin_test3.html \
                  plugin_alternate_content.html \
                  plugin_both.html \
                  plugin_both2.html \
                  plugin_bug743421.html \
                  plugin_clickToPlayAllow.html \
                  plugin_clickToPlayDeny.html \
+                 plugin_bug749455.html \
                  alltabslistener.html \
                  zoom_test.html \
                  dummy_page.html \
                  browser_tabMatchesInAwesomebar.js \
                  file_bug550565_popup.html \
                  file_bug550565_favicon.ico \
                  browser_aboutHome.js \
                  app_bug575561.html \
--- a/browser/base/content/test/browser_pluginnotification.js
+++ b/browser/base/content/test/browser_pluginnotification.js
@@ -497,10 +497,21 @@ function test16c() {
 // 4/4
 function test16d() {
   var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
   ok(popupNotification, "Test 16d, Should have a click-to-play notification");
   var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[1];
   var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
   ok(!objLoadingContent.activated, "Test 16d, Plugin should not be activated");
 
+  prepareTest(test17, gTestRoot + "plugin_bug749455.html");
+}
+
+// Tests that mContentType is used for click-to-play plugins, and not the
+// inspected type.
+function test17() {
+  var clickToPlayNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
+  ok(clickToPlayNotification, "Test 17, Should have a click-to-play notification");
+  var missingNotification = PopupNotifications.getNotification("missing-plugins", gTestBrowser);
+  ok(!missingNotification, "Test 17, Should not have a missing plugin notification");
+
   finishTest();
 }
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/plugin_bug749455.html
@@ -0,0 +1,8 @@
+<!-- bug 749455 -->
+<html>
+<head><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
+</head>
+<body>
+<embed src="plugin_bug749455.html" type="application/x-test" width="100px" height="100px"></embed>
+</body>
+</html>
--- a/content/base/src/nsObjectLoadingContent.cpp
+++ b/content/base/src/nsObjectLoadingContent.cpp
@@ -772,30 +772,41 @@ nsObjectLoadingContent::OnStartRequest(n
   rv = chan->GetContentType(channelType);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (channelType.EqualsASCII(APPLICATION_GUESS_FROM_EXT)) {
     channelType = APPLICATION_OCTET_STREAM;
     chan->SetContentType(channelType);
   }
 
-  // We want to use the channel type unless one of the following is true:
+  // We want to ignore the channel type if one of the following is true:
   //
-  // 1) The channel type is application/octet-stream and we have a
-  //    type hint and the type hint is not a document type.
-  // 2) Our type hint is a type that we support with a plugin.
-  if (((channelType.EqualsASCII(APPLICATION_OCTET_STREAM) ||
-        channelType.EqualsASCII(BINARY_OCTET_STREAM)) && 
-       !mContentType.IsEmpty() &&
-       GetTypeOfContent(mContentType) != eType_Document) ||
-      // Need to check IsPluginEnabledForType() in addition to GetTypeOfContent()
-      // because otherwise the default plug-in's catch-all behavior would
-      // confuse things.
-      (NS_SUCCEEDED(IsPluginEnabledForType(mContentType)) && 
-       GetTypeOfContent(mContentType) == eType_Plugin)) {
+  // 1) The channel type is application/octet-stream or binary/octet-stream 
+  //    and we have a type hint (in mContentType) and the type hint is not a
+  //    document type.
+  // 2) Our type hint is a type that we support with a plugin
+  //    (where "support" means it is enabled or it is click-to-play)
+  //    and this object loading content has the capability to load a plugin.
+  //    We have to be careful here - there might be a plugin that supports
+  //    image types, so make sure the type of the content is not an image.
+  bool isOctetStream = (channelType.EqualsASCII(APPLICATION_OCTET_STREAM) ||
+                        channelType.EqualsASCII(BINARY_OCTET_STREAM));
+  ObjectType typeOfContent = GetTypeOfContent(mContentType);
+  bool caseOne = (isOctetStream &&
+                  !mContentType.IsEmpty() &&
+                  typeOfContent != eType_Document);
+  nsresult pluginState = IsPluginEnabledForType(mContentType);
+  bool pluginSupported = (NS_SUCCEEDED(pluginState) || 
+                          pluginState == NS_ERROR_PLUGIN_CLICKTOPLAY);
+  PRUint32 caps = GetCapabilities();
+  bool caseTwo = (pluginSupported && 
+                  (caps & eSupportPlugins) &&
+                  typeOfContent != eType_Image &&
+                  typeOfContent != eType_Document);
+  if (caseOne || caseTwo) {
     // Set the type we'll use for dispatch on the channel.  Otherwise we could
     // end up trying to dispatch to a nsFrameLoader, which will complain that
     // it couldn't find a way to handle application/octet-stream
     nsCAutoString typeHint, dummy;
     NS_ParseContentType(mContentType, typeHint, dummy);
     if (!typeHint.IsEmpty()) {
       chan->SetContentType(typeHint);
     }