Bug 1403516 - Port
bug 1389650 to mailnews: Replace use of nsIDOMHTMLAnchorElement and nsIDOMHTMLLinkElement. r=bz
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -4,18 +4,16 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsMsgCompose.h"
#include "nsIDOMDocument.h"
#include "nsIDOMNode.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMText.h"
#include "nsIDOMHTMLImageElement.h"
-#include "nsIDOMHTMLLinkElement.h"
-#include "nsIDOMHTMLAnchorElement.h"
#include "nsPIDOMWindow.h"
#include "mozIDOMWindow.h"
#include "nsISelectionController.h"
#include "nsMsgI18N.h"
#include "nsMsgCompCID.h"
#include "nsMsgQuote.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
@@ -70,26 +68,29 @@
#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/HTMLAnchorElement.h"
#include "mozilla/dom/HTMLImageElement.h"
+#include "mozilla/dom/HTMLLinkElement.h"
#include "nsStreamConverter.h"
#include "nsISelection.h"
#include "nsJSEnvironment.h"
#include "nsIObserverService.h"
#include "nsIProtocolHandler.h"
#include "nsContentUtils.h"
#include "nsIFileURL.h"
using namespace mozilla;
+using namespace mozilla::dom;
using namespace mozilla::mailnews;
static nsresult GetReplyHeaderInfo(int32_t* reply_header_type,
nsString& reply_header_authorwrote,
nsString& reply_header_ondateauthorwrote,
nsString& reply_header_authorwroteondate,
nsString& reply_header_originalmessage)
{
@@ -255,40 +256,32 @@ GetNodeLocation(nsIDOMNode *inChild, nsC
bool nsMsgCompose::IsEmbeddedObjectSafe(const char * originalScheme,
const char * originalHost,
const char * originalPath,
nsIDOMNode * object)
{
nsresult rv;
- nsCOMPtr<nsIDOMHTMLLinkElement> link;
- nsCOMPtr<nsIDOMHTMLAnchorElement> anchor;
nsAutoString objURL;
if (!object || !originalScheme || !originalPath) //having a null host is ok...
return false;
- nsCOMPtr<Element> imageElement = do_QueryInterface(object);
- RefPtr<mozilla::dom::HTMLImageElement> image =
- mozilla::dom::HTMLImageElement::FromContentOrNull(imageElement);
+ nsCOMPtr<Element> objectAsElement = do_QueryInterface(object);
+ RefPtr<HTMLImageElement> image = HTMLImageElement::FromContentOrNull(objectAsElement);
+ RefPtr<HTMLLinkElement> link = HTMLLinkElement::FromContentOrNull(objectAsElement);
+ RefPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::FromContentOrNull(objectAsElement);
+
if (image)
- {
image->GetSrc(objURL);
- }
- else if ((link = do_QueryInterface(object)))
- {
- if (NS_FAILED(link->GetHref(objURL)))
- return false;
- }
- else if ((anchor = do_QueryInterface(object)))
- {
- if (NS_FAILED(anchor->GetHref(objURL)))
- return false;
- }
+ else if (link)
+ link->GetHref(objURL);
+ else if (anchor)
+ anchor->GetHref(objURL);
else
return false;
if (!objURL.IsEmpty())
{
nsCOMPtr<nsIURI> uri;
rv = NS_NewURI(getter_AddRefs(uri), objURL);
if (NS_SUCCEEDED(rv) && uri)
--- a/mailnews/compose/src/nsMsgSend.cpp
+++ b/mailnews/compose/src/nsMsgSend.cpp
@@ -23,18 +23,16 @@
#include "nsIFile.h"
#include "nsIURL.h"
#include "nsNetUtil.h"
#include "nsIFileURL.h"
#include "nsMsgCopy.h"
#include "nsUnicharUtils.h"
#include "nsMsgPrompts.h"
#include "nsIDOMHTMLImageElement.h"
-#include "nsIDOMHTMLLinkElement.h"
-#include "nsIDOMHTMLAnchorElement.h"
#include "nsCExternalHandlerService.h"
#include "nsIMIMEService.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
#include "nsMsgCompCID.h"
#include "nsIAbAddressCollector.h"
#include "nsAbBaseCID.h"
#include "nsCOMPtr.h"
@@ -72,25 +70,28 @@
#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/HTMLAnchorElement.h"
+#include "mozilla/dom/HTMLBodyElement.h"
#include "mozilla/dom/HTMLImageElement.h"
-#include "mozilla/dom/HTMLBodyElement.h"
+#include "mozilla/dom/HTMLLinkElement.h"
#include "nsIMutableArray.h"
#include "nsIMsgFilterService.h"
#include "nsIMsgProtocolInfo.h"
#include "mozIDOMWindow.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
+using namespace mozilla::dom;
using namespace mozilla::mailnews;
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
#define PREF_MAIL_SEND_STRUCT "mail.send_struct"
#define PREF_MAIL_STRICTLY_MIME "mail.strictly_mime"
#define PREF_MAIL_MESSAGE_WARNING_SIZE "mailnews.message_warning_size"
#define PREF_MAIL_COLLECT_EMAIL_ADDRESS_OUTGOING "mail.collect_email_address_outgoing"
@@ -1294,32 +1295,33 @@ nsMsgComposeAndSend::GetEmbeddedObjectIn
// like we do for images. So we do things the hard way.
#define getHTMLBodyElement(n) \
(n->IsHTMLElement(nsGkAtoms::body) ? static_cast<mozilla::dom::HTMLBodyElement*>(n.get()) : nullptr)
// 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<nsINode> tempNode = do_QueryInterface(node);
RefPtr<mozilla::dom::HTMLBodyElement> body = getHTMLBodyElement(tempNode);
- // XXX convert to use nsIImageLoadingContent?
- 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);
+
+ nsCOMPtr<Element> nodeAsElement = do_QueryInterface(node);
+ RefPtr<HTMLImageElement> image = HTMLImageElement::FromContentOrNull(nodeAsElement);
+ RefPtr<HTMLLinkElement> link = HTMLLinkElement::FromContentOrNull(nodeAsElement);
+ RefPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::FromContentOrNull(nodeAsElement);
// First, try to see if the body as a background image
if (body)
{
- mozilla::dom::DOMString tUrl;
- body->GetBackground(tUrl);
- if (tUrl.AsAString().IsEmpty())
+ DOMString tUrl;
+ body->GetBackground(tUrl); // XXX Todo: Need overload here.
+ nsString tUrl2;
+ tUrl.ToString(tUrl2);
+ if (tUrl2.IsEmpty())
return NS_OK;
nsAutoCString turlC;
- CopyUTF16toUTF8(tUrl.AsAString(), turlC);
+ CopyUTF16toUTF8(tUrl2, turlC);
if (NS_FAILED(nsMsgNewURL(getter_AddRefs(attachment->m_url), turlC)))
return NS_OK;
isImage = true;
}
else if (image) // Is this an image?
{
nsString tUrl;
nsString tName;
@@ -1375,44 +1377,43 @@ nsMsgComposeAndSend::GetEmbeddedObjectIn
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);
- NS_ENSURE_SUCCESS(rv, rv);
+ link->GetHref(tUrl);
if (tUrl.IsEmpty())
return NS_OK;
nsAutoCString turlC;
CopyUTF16toUTF8(tUrl, turlC);
if (NS_FAILED(nsMsgNewURL(getter_AddRefs(attachment->m_url), turlC)))
return NS_OK;
}
else if (anchor)
{
nsString tUrl;
- nsString tName;
// Create the URI
- rv = anchor->GetHref(tUrl);
- NS_ENSURE_SUCCESS(rv, rv);
+ anchor->GetHref(tUrl);
if (tUrl.IsEmpty())
return NS_OK;
nsAutoCString turlC;
CopyUTF16toUTF8(tUrl, turlC);
// This can fail since the URL might not be recognised, for example:
// <a href="skype:some-name?call" title="Skype">Some Name</a>
if (NS_FAILED(nsMsgNewURL(getter_AddRefs(attachment->m_url), turlC)))
return NS_OK;
- rv = anchor->GetName(tName);
- NS_ENSURE_SUCCESS(rv, rv);
- LossyCopyUTF16toASCII(tName, attachment->m_realName);
+ DOMString tName;
+ anchor->GetName(tName); // XXX Todo: Need overload here.
+ nsString tName2;
+ tName.ToString(tName2);
+ LossyCopyUTF16toASCII(tName2, attachment->m_realName);
}
else
{
// If we get here, we got something we didn't expect!
// Just try to continue and send it without this thing.
return NS_OK;
}
@@ -1835,44 +1836,43 @@ nsMsgComposeAndSend::ProcessMultipartRel
{
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<nsINode> tempNode = do_QueryInterface(domSaveArray[j].node);
RefPtr<mozilla::dom::HTMLBodyElement> body = getHTMLBodyElement(tempNode);
- 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);
-
+
+ nsCOMPtr<Element> nodeAsElement = do_QueryInterface(domSaveArray[j].node);
+ RefPtr<HTMLImageElement> image = HTMLImageElement::FromContentOrNull(nodeAsElement);
+ RefPtr<HTMLLinkElement> link = HTMLLinkElement::FromContentOrNull(nodeAsElement);
+ RefPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::FromContentOrNull(nodeAsElement);
+
+ IgnoredErrorResult rv2;
if (anchor)
{
anchor->GetHref(domURL);
- anchor->SetHref(newSpec);
+ anchor->SetHref(newSpec, rv2);
}
else if (link)
{
link->GetHref(domURL);
- link->SetHref(newSpec);
+ link->SetHref(newSpec, rv2);
}
else if (image)
{
image->GetSrc(domURL);
- IgnoredErrorResult rv2;
image->SetSrc(newSpec, rv2);
}
else if (body)
{
- mozilla::dom::DOMString background;
- body->GetBackground(background);
- domURL = background.AsAString();
- IgnoredErrorResult rv2;
+ DOMString background;
+ body->GetBackground(background); // XXX Todo: Need overload here.
+ background.ToString(domURL);
body->SetBackground(newSpec, rv2);
}
if (!domURL.IsEmpty())
domSaveArray[j].url = ToNewCString(NS_LossyConvertUTF16toASCII(domURL));
}
i++;
}
@@ -1887,34 +1887,33 @@ nsMsgComposeAndSend::ProcessMultipartRel
{
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<nsINode> tempNode = do_QueryInterface(domSaveArray[i].node);
RefPtr<mozilla::dom::HTMLBodyElement> body = getHTMLBodyElement(tempNode);
- 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);
+
+ nsCOMPtr<Element> nodeAsElement = do_QueryInterface(domSaveArray[i].node);
+ RefPtr<HTMLImageElement> image = HTMLImageElement::FromContentOrNull(nodeAsElement);
+ RefPtr<HTMLLinkElement> link = HTMLLinkElement::FromContentOrNull(nodeAsElement);
+ RefPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::FromContentOrNull(nodeAsElement);
// 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) {
- IgnoredErrorResult rv2;
+ IgnoredErrorResult rv2;
+ if (anchor) {
+ anchor->SetHref(NS_ConvertASCIItoUTF16(domSaveArray[i].url), rv2);
+ } else if (link) {
+ link->SetHref(NS_ConvertASCIItoUTF16(domSaveArray[i].url), rv2);
+ } else if (image) {
image->SetSrc(NS_ConvertASCIItoUTF16(domSaveArray[i].url), rv2);
}
else if (body) {
- IgnoredErrorResult rv2;
body->SetBackground(NS_ConvertASCIItoUTF16(domSaveArray[i].url), rv2);
}
free(domSaveArray[i].url);
}
PR_FREEIF(domSaveArray);