Bug 579744. Extract the actual content type from the attribute value before using it as a type hint for the channel. r=jst
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 22 Jul 2010 17:34:21 -0400
changeset 34447 ad35ca56728931eb312d6fe10d06d9f0e6279af3
parent 34442 96ae337c41fbff7c1c96ddca599ee5997ffed406
child 34448 57fa88b806c5a3e93d03f1f2519436fc0a928fff
push id1473
push userbzbarsky@mozilla.com
push dateThu, 22 Jul 2010 22:43:49 +0000
reviewersjst
bugs579744
milestone1.9.2.8pre
Bug 579744. Extract the actual content type from the attribute value before using it as a type hint for the channel. r=jst
content/base/src/nsObjectLoadingContent.cpp
docshell/base/nsDocShell.cpp
--- a/content/base/src/nsObjectLoadingContent.cpp
+++ b/content/base/src/nsObjectLoadingContent.cpp
@@ -540,17 +540,21 @@ nsObjectLoadingContent::OnStartRequest(n
       // because otherwise the default plug-in's catch-all behavior would
       // confuse things.
       (IsSupportedPlugin(mContentType) && 
        GetTypeOfContent(mContentType) == eType_Plugin)) {
     // 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
 
-    chan->SetContentType(mContentType);
+    nsCAutoString typeHint, dummy;
+    NS_ParseContentType(mContentType, typeHint, dummy);
+    if (!typeHint.IsEmpty()) {
+      chan->SetContentType(typeHint);
+    }
   } else {
     mContentType = channelType;
   }
 
   nsCOMPtr<nsIURI> uri;
   chan->GetURI(getter_AddRefs(uri));
 
   if (mContentType.EqualsASCII(APPLICATION_OCTET_STREAM)) {
@@ -1414,17 +1418,21 @@ nsObjectLoadingContent::LoadObject(nsIUR
   // Referrer
   nsCOMPtr<nsIHttpChannel> httpChan(do_QueryInterface(chan));
   if (httpChan) {
     httpChan->SetReferrer(doc->GetDocumentURI());
   }
 
   // MIME Type hint
   if (!aTypeHint.IsEmpty()) {
-    chan->SetContentType(aTypeHint);
+    nsCAutoString typeHint, dummy;
+    NS_ParseContentType(aTypeHint, typeHint, dummy);
+    if (!typeHint.IsEmpty()) {
+      chan->SetContentType(typeHint);
+    }
   }
 
   // Set up the channel's principal and such, like nsDocShell::DoURILoad does
   PRBool inheritPrincipal;
   rv = NS_URIChainHasFlags(aURI,
                            nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT,
                            &inheritPrincipal);
   NS_ENSURE_SUCCESS(rv, rv);
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -10886,16 +10886,20 @@ nsDocShell::OnLinkClickSync(nsIContent *
 
   nsAutoString target(aTargetSpec);
 
   // If this is an anchor element, grab its type property to use as a hint
   nsAutoString typeHint;
   nsCOMPtr<nsIDOMHTMLAnchorElement> anchor(do_QueryInterface(aContent));
   if (anchor) {
     anchor->GetType(typeHint);
+    NS_ConvertUTF16toUTF8 utf8Hint(typeHint);
+    nsCAutoString type, dummy;
+    NS_ParseContentType(utf8Hint, type, dummy);
+    CopyUTF8toUTF16(type, typeHint);
   }
   
   nsresult rv = InternalLoad(aURI,                      // New URI
                              referer,                   // Referer URI
                              aContent->NodePrincipal(), // Owner is our node's
                                                         // principal
                              INTERNAL_LOAD_FLAGS_NONE,
                              target.get(),              // Window target