Bug 767639 - nsObjectLoadingContent - Remove activeX stubs and simpify classid/java handling. r=josh
authorJohn Schoenick <jschoenick@mozilla.com>
Tue, 07 Aug 2012 11:42:56 -0700
changeset 102675 471f34ddcceb9622a4e630ed87d1e7fcfc268640
parent 102674 66e1e2f6f108dcd6c78462a0499a205767ca51cf
child 102676 882ce0d4a2946952ff96f5f9d5596ce72e1bec31
push id23301
push userryanvm@gmail.com
push dateSat, 18 Aug 2012 02:17:26 +0000
treeherdermozilla-central@812ea773f166 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjosh
bugs767639
milestone17.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 767639 - nsObjectLoadingContent - Remove activeX stubs and simpify classid/java handling. r=josh
content/base/src/nsObjectLoadingContent.cpp
content/base/src/nsObjectLoadingContent.h
--- a/content/base/src/nsObjectLoadingContent.cpp
+++ b/content/base/src/nsObjectLoadingContent.cpp
@@ -1164,16 +1164,17 @@ nsObjectLoadingContent::UpdateObjectPara
   PRUint32 caps = GetCapabilities();
   LOG(("OBJLC [%p]: Updating object parameters", this));
 
   nsresult rv;
   nsCAutoString newMime;
   nsCOMPtr<nsIURI> newURI;
   nsCOMPtr<nsIURI> newBaseURI;
   ObjectType newType;
+  bool isJava = false;
   // Set if this state can't be used to load anything, forces eType_Null
   bool stateInvalid = false;
   // Indicates what parameters changed.
   // eParamChannelChanged - means parameters that affect channel opening
   //                        decisions changed
   // eParamStateChanged -   means anything that affects what content we load
   //                        changed, even if the channel we'd open remains the
   //                        same.
@@ -1184,35 +1185,41 @@ nsObjectLoadingContent::UpdateObjectPara
   // that far.
   nsObjectLoadingContent::ParameterUpdateFlags retval = eParamNoChange;
 
   ///
   /// Initial MIME Type
   ///
   if (thisContent->NodeInfo()->Equals(nsGkAtoms::applet)) {
     newMime.AssignLiteral("application/x-java-vm");
+    isJava = true;
   } else {
     nsAutoString typeAttr;
     thisContent->GetAttr(kNameSpaceID_None, nsGkAtoms::type, typeAttr);
     if (!typeAttr.IsEmpty()) {
       CopyUTF16toUTF8(typeAttr, newMime);
+      isJava = nsPluginHost::IsJavaMIMEType(newMime.get());
     }
   }
 
   ///
   /// classID
   ///
 
-  bool usingClassID = false;
   if (caps & eSupportClassID) {
     nsAutoString classIDAttr;
     thisContent->GetAttr(kNameSpaceID_None, nsGkAtoms::classid, classIDAttr);
     if (!classIDAttr.IsEmpty()) {
-      usingClassID = true;
-      if (NS_FAILED(TypeForClassID(classIDAttr, newMime))) {
+      // Our classid support is limited to 'java:' ids
+      rv = IsPluginEnabledForType(NS_LITERAL_CSTRING("application/x-java-vm"));
+      if (NS_SUCCEEDED(rv) &&
+          StringBeginsWith(classIDAttr, NS_LITERAL_STRING("java:"))) {
+        newMime.Assign("application/x-java-vm");
+        isJava = true;
+      } else {
         // XXX(johns): Our de-facto behavior since forever was to refuse to load
         // Objects who don't have a classid we support, regardless of other type
         // or uri info leads to a valid plugin.
         newMime.Assign("");
         stateInvalid = true;
       }
     }
   }
@@ -1256,23 +1263,26 @@ nsObjectLoadingContent::UpdateObjectPara
   }
 
   ///
   /// URI
   ///
 
   nsAutoString uriStr;
   // Different elements keep this in various locations
-  if (thisContent->NodeInfo()->Equals(nsGkAtoms::object)) {
+  if (isJava) {
+    // Applet tags and embed/object with explicit java MIMEs have
+    // src/data attributes that are not parsed as URIs, so we will
+    // act as if URI is null
+  } else if (thisContent->NodeInfo()->Equals(nsGkAtoms::object)) {
     thisContent->GetAttr(kNameSpaceID_None, nsGkAtoms::data, uriStr);
   } else if (thisContent->NodeInfo()->Equals(nsGkAtoms::embed)) {
     thisContent->GetAttr(kNameSpaceID_None, nsGkAtoms::src, uriStr);
-  } else if (thisContent->NodeInfo()->Equals(nsGkAtoms::applet)) {
-    // Applet tags have no URI, and their 'code=' parameter is not parsed as one
   } else {
+    // Applet tags should always have a java MIME type at this point
     NS_NOTREACHED("Unrecognized plugin-loading tag");
   }
 
   // Note that the baseURI changing could affect the newURI, even if uriStr did
   // not change.
   if (!uriStr.IsEmpty()) {
     rv = nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(newURI),
                                                    uriStr,
@@ -1364,69 +1374,65 @@ nsObjectLoadingContent::UpdateObjectPara
         if (!typeHint.IsEmpty()) {
           mChannel->SetContentType(typeHint);
         }
     } else if (binaryChannelType
                && IsPluginEnabledByExtension(newURI, newMime)) {
       mChannel->SetContentType(newMime);
     } else {
       newMime = channelType;
+      if (nsPluginHost::IsJavaMIMEType(newMime.get())) {
+        //   Java does not load with a channel, and being java retroactively changes
+        //   how we may have interpreted the codebase to construct this URI above.
+        //   Because the behavior here is more or less undefined, play it safe and
+        //   reject the load.
+        LOG(("OBJLC [%p]: Refusing to load with channel with java MIME",
+             this));
+        stateInvalid = true;
+      }
     }
   }
 
-  bool isJava = nsPluginHost::IsJavaMIMEType(newMime.get());
-  if (useChannel && (!mChannel || isJava)) {
-    // Sanity checks
-    // - Java does not load with a channel, and being java retroactively changes
-    //   how we may have interpreted the codebase to construct this URI above.
-    //   Because the behavior here is more or less undefined, play it safe and
-    //   reject the load.
-    //
-    // - (useChannel && !mChannel) is true if a channel was opened but was
-    //   subsequently invalidated
-    //   in that case.
+  if (useChannel && !mChannel) {
+    // - (useChannel && !mChannel) is true if a channel was opened but
+    //   is no longer around, in which case we can't load.
     stateInvalid = true;
   }
 
   ///
   /// Determine final type
   ///
   //  1) If we have attempted channel load, or set stateInvalid above, the type
   //     is always null (fallback)
   //  2) Otherwise, If we have a loaded channel, we grabbed its mimeType above,
   //     use that type.
   //  3) Otherwise, See if we can load this as a plugin without a channel
   //     (image/document types always need a channel).
-  //     - If we have indication this is a plugin (mime, extension, or classID)
+  //     - If we have indication this is a plugin (mime, extension)
   //       AND:
   //       - We have eAllowPluginSkipChannel OR
-  //       - We have no URI in the first place OR
-  //       - We're loading based on classID
-  //         XXX(johns): Legacy behavior is to skip channel loading if we have
-  //                     a classID. I don't know why.
+  //       - We have no URI in the first place (including java)
   //  3) Otherwise, if we have a URI, set type to loading to indicate
   //     we'd need a channel to proceed.
   //  4) Otherwise, type null to indicate unloadable content (fallback)
   //
   // XXX(johns): <embed> tags both support URIs and have
   //   eAllowPluginSkipChannel, meaning it is possible that we have a URI, but
   //   are not going to open a channel for it. The old objLC code did this (in a
   //   less obviously-intended way), so it's probably best not to change our
   //   behavior at this point.
-  //   We ALSO skip channel loading for objects whose type is found by ClassID
-  //   (We only support a tiny subset of classid: java and ActiveX, above)
   //
 
   if (stateInvalid) {
     newType = eType_Null;
   } else if (useChannel) {
       // If useChannel is set above, we considered it in setting newMime
       newType = GetTypeOfContent(newMime);
       LOG(("OBJLC [%p]: Using channel type", this));
-  } else if (((caps & eAllowPluginSkipChannel) || !newURI || usingClassID) &&
+  } else if (((caps & eAllowPluginSkipChannel) || !newURI) &&
              (GetTypeOfContent(newMime) == eType_Plugin)) {
     newType = eType_Plugin;
     LOG(("OBJLC [%p]: Skipping loading channel, type plugin", this));
   } else if (newURI) {
     // We could potentially load this if we opened a channel on mURI, indicate
     // This by leaving type as loading
     newType = eType_Loading;
   } else {
@@ -2046,44 +2052,16 @@ nsObjectLoadingContent::GetTypeOfContent
 
   if ((caps & eSupportPlugins) && NS_SUCCEEDED(IsPluginEnabledForType(aMIMEType))) {
     return eType_Plugin;
   }
 
   return eType_Null;
 }
 
-nsresult
-nsObjectLoadingContent::TypeForClassID(const nsAString& aClassID,
-                                       nsACString& aType)
-{
-  if (StringBeginsWith(aClassID, NS_LITERAL_STRING("java:"))) {
-    // Supported if we have a java plugin
-    aType.AssignLiteral("application/x-java-vm");
-    nsresult rv = IsPluginEnabledForType(NS_LITERAL_CSTRING("application/x-java-vm"));
-    return NS_SUCCEEDED(rv) ? NS_OK : NS_ERROR_NOT_AVAILABLE;
-  }
-
-  // If it starts with "clsid:", this is ActiveX content
-  if (StringBeginsWith(aClassID, NS_LITERAL_STRING("clsid:"), nsCaseInsensitiveStringComparator())) {
-    // Check if we have a plugin for that
-
-    if (NS_SUCCEEDED(IsPluginEnabledForType(NS_LITERAL_CSTRING("application/x-oleobject")))) {
-      aType.AssignLiteral("application/x-oleobject");
-      return NS_OK;
-    }
-    if (NS_SUCCEEDED(IsPluginEnabledForType(NS_LITERAL_CSTRING("application/oleobject")))) {
-      aType.AssignLiteral("application/oleobject");
-      return NS_OK;
-    }
-  }
-
-  return NS_ERROR_NOT_AVAILABLE;
-}
-
 nsObjectFrame*
 nsObjectLoadingContent::GetExistingFrame()
 {
   nsCOMPtr<nsIContent> thisContent = do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
   nsIFrame* frame = thisContent->GetPrimaryFrame();
   nsIObjectFrame* objFrame = do_QueryFrame(frame);
   return static_cast<nsObjectFrame*>(objFrame);
 }
--- a/content/base/src/nsObjectLoadingContent.h
+++ b/content/base/src/nsObjectLoadingContent.h
@@ -358,26 +358,16 @@ class nsObjectLoadingContent : public ns
      * into account
      * 
      * NOTE this does not consider whether the content would be suppressed by
      *      click-to-play or other content policy checks
      */
     ObjectType GetTypeOfContent(const nsCString& aMIMEType);
 
     /**
-     * For a classid, returns the MIME type that can be used to instantiate
-     * a plugin for this ID.
-     *
-     * @param aClassID The class ID in question
-     * @param aType    [out] The corresponding type, if the call is successful
-     * @return NS_ERROR_NOT_AVAILABLE Unsupported class ID.
-     */
-    nsresult TypeForClassID(const nsAString& aClassID, nsACString& aType);
-
-    /**
      * Gets the frame that's associated with this content node.
      * Does not flush.
      */
     nsObjectFrame* GetExistingFrame();
 
     // The final listener for mChannel (uriloader, pluginstreamlistener, etc.)
     nsCOMPtr<nsIStreamListener> mFinalListener;