Bug 1381011 - Port bug 1380413 to mailnews: Use HTMLImageElement. rs=bustage-fix
authorJorg K <jorgk@jorgk.com>
Fri, 14 Jul 2017 19:03:46 +0200
changeset 28447 130d043e685055c682059c92dc582acb2a65afd2
parent 28446 61107603efab124c3214304aca1467649862e870
child 28448 ca430d5ac1be6b6418066639b7d59f7cd77ce9b0
push id1986
push userclokep@gmail.com
push dateWed, 02 Aug 2017 14:43:31 +0000
treeherdercomm-beta@b51c9adf2c9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbustage-fix
bugs1381011, 1380413
Bug 1381011 - Port bug 1380413 to mailnews: Use HTMLImageElement. rs=bustage-fix
mailnews/compose/src/nsMsgCompose.cpp
mailnews/compose/src/nsMsgSend.cpp
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -71,16 +71,17 @@
 #include "nsIMsgWindow.h"
 #include "nsITextToSubURI.h"
 #include "nsIAbManager.h"
 #include "nsCRT.h"
 #include "mozilla/Services.h"
 #include "mozilla/mailnews/MimeHeaderParser.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/ErrorResult.h"
+#include "mozilla/dom/HTMLImageElement.h"
 #include "nsStreamConverter.h"
 #include "nsISelection.h"
 #include "nsJSEnvironment.h"
 #include "nsIObserverService.h"
 #include "nsIProtocolHandler.h"
 #include "nsContentUtils.h"
 #include "nsIFileURL.h"
 
@@ -257,28 +258,29 @@ GetNodeLocation(nsIDOMNode *inChild, nsC
 
 bool nsMsgCompose::IsEmbeddedObjectSafe(const char * originalScheme,
                                           const char * originalHost,
                                           const char * originalPath,
                                           nsIDOMNode * object)
 {
   nsresult rv;
 
-  nsCOMPtr<nsIDOMHTMLImageElement> image;
   nsCOMPtr<nsIDOMHTMLLinkElement> link;
   nsCOMPtr<nsIDOMHTMLAnchorElement> anchor;
   nsAutoString objURL;
 
   if (!object || !originalScheme || !originalPath) //having a null host is ok...
     return false;
 
-  if ((image = do_QueryInterface(object)))
+  nsCOMPtr<Element> imageElement = do_QueryInterface(object);
+  RefPtr<mozilla::dom::HTMLImageElement> image =
+    mozilla::dom::HTMLImageElement::FromContentOrNull(imageElement);
+  if (image)
   {
-    if (NS_FAILED(image->GetSrc(objURL)))
-      return false;
+    image->GetSrc(objURL);
   }
   else if ((link = do_QueryInterface(object)))
   {
     if (NS_FAILED(link->GetHref(objURL)))
       return false;
   }
   else if ((anchor = do_QueryInterface(object)))
   {
@@ -369,17 +371,19 @@ nsresult nsMsgCompose::ResetUrisForEmbed
 
       nsCOMPtr<nsIDOMElement> domElement;
       for (i = 0; i < numNodes; i ++)
       {
         domElement = do_QueryElementAt(aNodeList, i);
         if (!domElement)
           continue;
 
-        nsCOMPtr<nsIDOMHTMLImageElement> image = do_QueryInterface(domElement);
+        nsCOMPtr<Element> imageElement = do_QueryInterface(domElement);
+        RefPtr<mozilla::dom::HTMLImageElement> image =
+          mozilla::dom::HTMLImageElement::FromContentOrNull(imageElement);
         if (!image)
           continue;
         nsCString partNum;
         mMsgSend->GetPartForDomIndex(i, partNum);
         // do we care about anything besides images?
         nsAutoString objURL;
         image->GetSrc(objURL);
 
@@ -443,17 +447,18 @@ nsresult nsMsgCompose::ResetUrisForEmbed
         // and the destination drafts folder.
         bool specHasQ = (spec.FindChar('?') != kNotFound);
         if (specHasQ && restOfUrl.CharAt(0) == '?')
           restOfUrl.SetCharAt('&', 0);
         else if (!specHasQ && restOfUrl.CharAt(0) == '&')
           restOfUrl.SetCharAt('?', 0);
         AppendUTF8toUTF16(spec, newSrc);
         newSrc.Append(restOfUrl);
-        image->SetSrc(newSrc);
+        IgnoredErrorResult rv2;
+        image->SetSrc(newSrc, rv2);
       }
     }
   }
 
   return NS_OK;
 }
 
 
--- a/mailnews/compose/src/nsMsgSend.cpp
+++ b/mailnews/compose/src/nsMsgSend.cpp
@@ -73,16 +73,17 @@
 #include "nsString.h"
 #include "nsMsgUtils.h"
 #include "nsIArray.h"
 #include "nsArrayUtils.h"
 #include "mozilla/Services.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/mailnews/MimeEncoder.h"
 #include "mozilla/mailnews/MimeHeaderParser.h"
+#include "mozilla/dom/HTMLImageElement.h"
 #include "nsIMutableArray.h"
 #include "nsIMsgFilterService.h"
 #include "nsIMsgProtocolInfo.h"
 #include "mozIDOMWindow.h"
 #include "mozilla/Preferences.h"
 
 using namespace mozilla;
 using namespace mozilla::mailnews;
@@ -1287,17 +1288,19 @@ nsMsgComposeAndSend::GetEmbeddedObjectIn
   // Only empty or moz-do-not-send="false" may be accepted later.
   if (!(mozDoNotSendAttr.IsEmpty() || mozDoNotSendAttr.LowerCaseEqualsLiteral("false")))
     return NS_OK;
 
   // Now, we know the types of objects this node can be, so we will do
   // our query interface here and see what we come up with
   nsCOMPtr<nsIDOMHTMLBodyElement>     body = (do_QueryInterface(node));
   // XXX convert to use nsIImageLoadingContent?
-  nsCOMPtr<nsIDOMHTMLImageElement>    image = (do_QueryInterface(node));
+  nsCOMPtr<Element> imageElement = do_QueryInterface(node);
+  RefPtr<mozilla::dom::HTMLImageElement> image =
+    mozilla::dom::HTMLImageElement::FromContentOrNull(imageElement);
   nsCOMPtr<nsIDOMHTMLLinkElement>     link = (do_QueryInterface(node));
   nsCOMPtr<nsIDOMHTMLAnchorElement>   anchor = (do_QueryInterface(node));
 
   // First, try to see if the body as a background image
   if (body)
   {
     nsAutoString    tUrl;
     if (NS_SUCCEEDED(body->GetBackground(tUrl)))
@@ -1311,18 +1314,17 @@ nsMsgComposeAndSend::GetEmbeddedObjectIn
   }
   else if (image)        // Is this an image?
   {
     nsString    tUrl;
     nsString    tName;
     nsString    tDesc;
 
     // Create the URI
-    if (NS_FAILED(image->GetSrc(tUrl)))
-      return NS_ERROR_FAILURE;
+    image->GetSrc(tUrl);
     if (tUrl.IsEmpty())
       return NS_OK;
 
     nsAutoCString turlC;
     CopyUTF16toUTF8(tUrl, turlC);
     if (NS_FAILED(nsMsgNewURL(getter_AddRefs(attachment->m_url), turlC.get())))
     {
       // Well, the first time failed...which means we probably didn't get
@@ -1355,22 +1357,20 @@ nsMsgComposeAndSend::GetEmbeddedObjectIn
         workURL.Append(tUrl);
         NS_ConvertUTF16toUTF8 workurlC(workURL);
         if (NS_FAILED(nsMsgNewURL(getter_AddRefs(attachment->m_url), workurlC.get())))
           return NS_OK; // Continue and send it without this image.
       }
     }
     isImage = true;
 
-    rv = image->GetName(tName);
-    NS_ENSURE_SUCCESS(rv, rv);
+    image->GetName(tName);
 
     LossyCopyUTF16toASCII(tName, attachment->m_realName);
-    rv = image->GetLongDesc(tDesc);
-    NS_ENSURE_SUCCESS(rv, rv);
+    image->GetLongDesc(tDesc);
     attachment->m_description = NS_LossyConvertUTF16toASCII(tDesc); // XXX i18n
   }
   else if (link)        // Is this a link?
   {
     nsString    tUrl;
 
     // Create the URI
     rv = link->GetHref(tUrl);
@@ -1837,34 +1837,37 @@ nsMsgComposeAndSend::ProcessMultipartRel
     if (!m_attachments[duplicateOf == -1 ? i : duplicateOf]->m_contentId.IsEmpty())
     {
       nsString   newSpec(NS_LITERAL_STRING("cid:"));
       newSpec.AppendASCII(m_attachments[duplicateOf == -1 ? i : duplicateOf]->m_contentId.get());
 
       // Now, we know the types of objects this node can be, so we will do
       // our query interface here and see what we come up with
       nsCOMPtr<nsIDOMHTMLBodyElement>     body = (do_QueryInterface(domSaveArray[j].node));
-      nsCOMPtr<nsIDOMHTMLImageElement>    image = (do_QueryInterface(domSaveArray[j].node));
+      nsCOMPtr<Element> imageElement = do_QueryInterface(domSaveArray[j].node);
+      RefPtr<mozilla::dom::HTMLImageElement> image =
+        mozilla::dom::HTMLImageElement::FromContentOrNull(imageElement);
       nsCOMPtr<nsIDOMHTMLLinkElement>     link = (do_QueryInterface(domSaveArray[j].node));
       nsCOMPtr<nsIDOMHTMLAnchorElement>   anchor = (do_QueryInterface(domSaveArray[j].node));
 
       if (anchor)
       {
         anchor->GetHref(domURL);
         anchor->SetHref(newSpec);
       }
       else if (link)
       {
         link->GetHref(domURL);
         link->SetHref(newSpec);
       }
       else if (image)
       {
         image->GetSrc(domURL);
-        image->SetSrc(newSpec);
+        IgnoredErrorResult rv2;
+        image->SetSrc(newSpec, rv2);
       }
       else if (body)
       {
         body->GetBackground(domURL);
         body->SetBackground(newSpec);
       }
 
       if (!domURL.IsEmpty())
@@ -1882,28 +1885,32 @@ nsMsgComposeAndSend::ProcessMultipartRel
   for (i = 0; i < multipartCount; i++)
   {
     if ( (!domSaveArray[i].node) || (!domSaveArray[i].url) )
       continue;
 
     // Now, we know the types of objects this node can be, so we will do
     // our query interface here and see what we come up with
     nsCOMPtr<nsIDOMHTMLBodyElement>     body = (do_QueryInterface(domSaveArray[i].node));
-    nsCOMPtr<nsIDOMHTMLImageElement>    image = (do_QueryInterface(domSaveArray[i].node));
+    nsCOMPtr<Element> imageElement = do_QueryInterface(domSaveArray[i].node);
+    RefPtr<mozilla::dom::HTMLImageElement> image =
+      mozilla::dom::HTMLImageElement::FromContentOrNull(imageElement);
     nsCOMPtr<nsIDOMHTMLLinkElement>     link = (do_QueryInterface(domSaveArray[i].node));
     nsCOMPtr<nsIDOMHTMLAnchorElement>   anchor = (do_QueryInterface(domSaveArray[i].node));
 
       // STRING USE WARNING: hoisting the following conversion might save code-space, since it happens along every path
 
     if (anchor)
       anchor->SetHref(NS_ConvertASCIItoUTF16(domSaveArray[i].url));
     else if (link)
       link->SetHref(NS_ConvertASCIItoUTF16(domSaveArray[i].url));
-    else if (image)
-      image->SetSrc(NS_ConvertASCIItoUTF16(domSaveArray[i].url));
+    else if (image) {
+      IgnoredErrorResult rv2;
+      image->SetSrc(NS_ConvertASCIItoUTF16(domSaveArray[i].url), rv2);
+    }
     else if (body)
       body->SetBackground(NS_ConvertASCIItoUTF16(domSaveArray[i].url));
 
     free(domSaveArray[i].url);
   }
 
   PR_FREEIF(domSaveArray);