Bug 1433193 - Follow-up: misc. code improvements. r=bz
authorJorg K <jorgk@jorgk.com>
Tue, 30 Jan 2018 20:45:30 +0100
changeset 31005 4007d551bf7a114ab2ec74d4ab823bbb926a1757
parent 31004 b0aca2abe97ce7f3ac1edc832747c0246c9d94e1
child 31006 22d78d1bbe82d8a2038cbb104386c8e7363c13b0
push id383
push userclokep@gmail.com
push dateMon, 07 May 2018 21:52:48 +0000
reviewersbz
bugs1433193
Bug 1433193 - Follow-up: misc. code improvements. r=bz
mailnews/base/src/nsMsgMailSession.cpp
mailnews/compose/src/nsMsgCompose.cpp
mailnews/compose/src/nsMsgCompose.h
mailnews/news/src/nsNntpIncomingServer.cpp
--- a/mailnews/base/src/nsMsgMailSession.cpp
+++ b/mailnews/base/src/nsMsgMailSession.cpp
@@ -275,44 +275,38 @@ nsresult nsMsgMailSession::GetTopmostMsg
     rv = windowMediator->GetZOrderDOMWindowEnumerator(nullptr, true,
                                                       getter_AddRefs(windowEnum));
 #endif
 
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsISupports> windowSupports;
     nsCOMPtr<nsPIDOMWindowOuter> topMostWindow;
-    nsCOMPtr<nsIDOMDocument> domDocument;
-    nsCOMPtr<nsIDOMElement> domElement;
     nsAutoString windowType;
     bool more;
 
     // loop to get the top most with attibute "mail:3pane" or "mail:messageWindow"
     windowEnum->HasMoreElements(&more);
     while (more)
     {
       rv = windowEnum->GetNext(getter_AddRefs(windowSupports));
       NS_ENSURE_SUCCESS(rv, rv);
       NS_ENSURE_TRUE(windowSupports, NS_ERROR_FAILURE);
 
       topMostWindow = do_QueryInterface(windowSupports, &rv);
       NS_ENSURE_SUCCESS(rv, rv);
       NS_ENSURE_TRUE(topMostWindow, NS_ERROR_FAILURE);
 
-      domDocument = do_QueryInterface(topMostWindow->GetDoc());
-      NS_ENSURE_SUCCESS(rv, rv);
+      nsIDocument* domDocument = topMostWindow->GetDoc();
       NS_ENSURE_TRUE(domDocument, NS_ERROR_FAILURE);
 
-      rv = domDocument->GetDocumentElement(getter_AddRefs(domElement));
-      NS_ENSURE_SUCCESS(rv, rv);
+      Element* domElement = domDocument->GetDocumentElement();
       NS_ENSURE_TRUE(domElement, NS_ERROR_FAILURE);
 
-      nsCOMPtr<Element> domElement2 = do_QueryInterface(domElement);
-      domElement2->GetAttribute(NS_LITERAL_STRING("windowtype"), windowType);
-
+      domElement->GetAttribute(NS_LITERAL_STRING("windowtype"), windowType);
       if (windowType.EqualsLiteral("mail:3pane") ||
           windowType.EqualsLiteral("mail:messageWindow"))
         break;
 
       windowEnum->HasMoreElements(&more);
     }
 
     // identified the top most window
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -238,31 +238,30 @@ GetNodeLocation(nsIDOMNode *inChild, nsC
       result = GetChildOffset(inChild2, *outParent, *outOffset);
     }
   }
 
   return result;
 }
 
 bool nsMsgCompose::IsEmbeddedObjectSafe(const char * originalScheme,
-                                          const char * originalHost,
-                                          const char * originalPath,
-                                          nsIDOMNode * object)
+                                        const char * originalHost,
+                                        const char * originalPath,
+                                        Element * element)
 {
   nsresult rv;
 
   nsAutoString objURL;
 
-  if (!object || !originalScheme || !originalPath) //having a null host is ok...
+  if (!originalScheme || !originalPath) // Having a null host is OK.
     return false;
 
-  nsCOMPtr<Element> objectAsElement = do_QueryInterface(object);
-  RefPtr<HTMLImageElement>  image  = HTMLImageElement::FromContentOrNull(objectAsElement);
-  RefPtr<HTMLLinkElement>   link   = HTMLLinkElement::FromContentOrNull(objectAsElement);
-  RefPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::FromContentOrNull(objectAsElement);
+  RefPtr<HTMLImageElement>  image  = HTMLImageElement::FromContent(element);
+  RefPtr<HTMLLinkElement>   link   = HTMLLinkElement::FromContent(element);
+  RefPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::FromContent(element);
 
   if (image)
     image->GetSrc(objURL);
   else if (link)
     link->GetHref(objURL);
   else if (anchor)
     anchor->GetHref(objURL);
   else
@@ -284,17 +283,17 @@ bool nsMsgCompose::IsEmbeddedObjectSafe(
         if (NS_SUCCEEDED(rv) && (host.IsEmpty() || originalHost || host.Equals(originalHost, nsCaseInsensitiveCStringComparator())))
         {
           nsAutoCString path;
           rv = uri->GetPathQueryRef(path);
           if (NS_SUCCEEDED(rv))
           {
             const char * query = strrchr(path.get(), '?');
             if (query && PL_strncasecmp(path.get(), originalPath, query - path.get()) == 0)
-                return true; //This object is a part of the original message, we can send it safely.
+              return true; // This object is a part of the original message, we can send it safely.
           }
         }
       }
     }
   }
 
   return false;
 }
@@ -481,32 +480,28 @@ nsresult nsMsgCompose::TagEmbeddedObject
     }
   }
 
   // Then compare the url of each embedded objects with the original message.
   // If they a not coming from the original message, they should not be sent
   // with the message.
   for (i = 0; i < count; i ++)
   {
-    nsCOMPtr<nsIDOMNode> node = do_QueryElementAt(aNodeList, i);
-    if (!node)
+    nsCOMPtr<Element> domElement = do_QueryElementAt(aNodeList, i);
+    if (!domElement)
       continue;
     if (IsEmbeddedObjectSafe(originalScheme.get(), originalHost.get(),
-                             originalPath.get(), node))
-      continue; //Don't need to tag this object, it safe to send it.
-
-    //The source of this object should not be sent with the message
-    nsCOMPtr<Element> domElement = do_QueryInterface(node);
-    if (domElement) {
-      IgnoredErrorResult rv2;
-      domElement->SetAttribute(NS_LITERAL_STRING("moz-do-not-send"),
-                               NS_LITERAL_STRING("true"),
-                               nullptr,
-                               rv2);
-    }
+                             originalPath.get(), domElement))
+      continue; // Don't need to tag this object, it's safe to send it.
+
+    // The source of this object should not be sent with the message.
+    IgnoredErrorResult rv2;
+    domElement->SetAttribute(NS_LITERAL_STRING("moz-do-not-send"),
+                             NS_LITERAL_STRING("true"),
+                             rv2);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgCompose::GetInsertingQuotedContent(bool * aInsertingQuotedText)
 {
@@ -598,17 +593,17 @@ nsMsgCompose::InsertDivWrappedTextAtSele
     m_editor->GetSelection(getter_AddRefs(selection));
 
     if (selection)
       selection->CollapseNative(parent, offset + 1);
   }
   if (divElem) {
     nsCOMPtr<Element> divElem2 = do_QueryInterface(divElem);
     IgnoredErrorResult rv2;
-    divElem2->SetAttribute(NS_LITERAL_STRING("class"), classStr, nullptr, rv2);
+    divElem2->SetAttribute(NS_LITERAL_STRING("class"), classStr, rv2);
   }
 }
 
 NS_IMETHODIMP
 nsMsgCompose::ConvertAndLoadComposeWindow(nsString& aPrefix,
                                           nsString& aBuf,
                                           nsString& aSignature,
                                           bool aQuoted,
@@ -801,17 +796,17 @@ nsMsgCompose::ConvertAndLoadComposeWindo
           NS_ENSURE_SUCCESS(rv, rv);
           divElem2 = do_QueryInterface(divElem);
 
           nsAutoString attributeName;
           nsAutoString attributeValue;
           attributeName.AssignLiteral("class");
           attributeValue.AssignLiteral("moz-forward-container");
           IgnoredErrorResult rv1;
-          divElem2->SetAttribute(attributeName, attributeValue, nullptr, rv1);
+          divElem2->SetAttribute(attributeName, attributeValue, rv1);
 
           // We can't insert an empty <div>, so fill it with something.
           rv = htmlEditor->CreateElementWithDefaults(NS_LITERAL_STRING("br"),
                                                      getter_AddRefs(extraBr));
           NS_ENSURE_SUCCESS(rv, rv);
 
           nsCOMPtr<nsINode> extraBr2 = do_QueryInterface(extraBr);
           ErrorResult rv2;
--- a/mailnews/compose/src/nsMsgCompose.h
+++ b/mailnews/compose/src/nsMsgCompose.h
@@ -52,17 +52,17 @@ protected:
  // Deal with quoting issues...
   nsresult                      QuoteOriginalMessage(); // New template
   nsresult                      SetQuotingToFollow(bool aVal);
   nsresult                      ConvertHTMLToText(nsIFile *aSigFile, nsString &aSigData);
   nsresult                      ConvertTextToHTML(nsIFile *aSigFile, nsString &aSigData);
   bool                          IsEmbeddedObjectSafe(const char * originalScheme,
                                                      const char * originalHost,
                                                      const char * originalPath,
-                                                     nsIDOMNode * object);
+                                                     mozilla::dom::Element * element);
   nsresult                      ResetUrisForEmbeddedObjects();
   nsresult                      TagEmbeddedObjects(nsIEditorMailSupport *aMailEditor);
 
   nsCString                     mQuoteCharset;
   nsCString                     mOriginalMsgURI; // used so we can mark message disposition flags after we send the message
 
   int32_t                       mWhatHolder;
 
--- a/mailnews/news/src/nsNntpIncomingServer.cpp
+++ b/mailnews/news/src/nsNntpIncomingServer.cpp
@@ -1929,17 +1929,16 @@ nsNntpIncomingServer::CycleHeader(nsITre
     col->GetElement(getter_AddRefs(element));
     mSearchResultSortDescending = !mSearchResultSortDescending;
     nsCOMPtr<Element> element2 = do_QueryInterface(element);
     mozilla::IgnoredErrorResult rv2;
     element2->SetAttribute(dir,
                            mSearchResultSortDescending ?
                              NS_LITERAL_STRING("descending") :
                              NS_LITERAL_STRING("ascending"),
-                           nullptr,
                            rv2);
     mTree->Invalidate();
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsNntpIncomingServer::SelectionChanged()