diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | embed/mozilla/EventContext.cpp | 36 | ||||
-rw-r--r-- | embed/mozilla/EventContext.h | 1 |
3 files changed, 42 insertions, 2 deletions
@@ -1,5 +1,12 @@ 2004-07-05 Christian Persch <chpe@cvs.gnome.org> + * embed/mozilla/EventContext.cpp: + * embed/mozilla/EventContext.h: + + Unescape the mailto: address, fixes bug #144462. + +2004-07-05 Christian Persch <chpe@cvs.gnome.org> + * lib/widgets/ephy-spinner.c: (ephy_spinner_cache_get_type), (ephy_spinner_images_free), (ephy_spinner_images_copy), (ephy_spinner_cache_unload), (extract_frame), diff --git a/embed/mozilla/EventContext.cpp b/embed/mozilla/EventContext.cpp index f3fac4740..dde8d040a 100644 --- a/embed/mozilla/EventContext.cpp +++ b/embed/mozilla/EventContext.cpp @@ -30,6 +30,7 @@ #include <gdk/gdkkeysyms.h> #include <nsIInterfaceRequestor.h> +#include <nsIServiceManager.h> #include <nsEmbedString.h> #include <nsIDOMEventTarget.h> #include <nsIDOMHTMLInputElement.h> @@ -51,6 +52,7 @@ #include <nsIDOMAbstractView.h> #ifdef ALLOW_PRIVATE_API +#include <nsITextToSubURI.h> #include <nsIDOMXULDocument.h> #include <nsIDOMNSEvent.h> #include <nsIDOMNSHTMLElement.h> @@ -172,6 +174,28 @@ nsresult EventContext::ResolveBaseURL (const nsAString &relurl, nsACString &url) return base->Resolve (cRelURL, url); } +nsresult EventContext::Unescape (const nsACString &aEscaped, nsACString &aUnescaped) +{ + if (!aEscaped.Length()) return NS_ERROR_FAILURE; + + nsCOMPtr<nsITextToSubURI> escaper + (do_CreateInstance ("@mozilla.org/intl/texttosuburi;1")); + NS_ENSURE_TRUE (escaper, NS_ERROR_FAILURE); + + nsresult rv; + nsEmbedCString encoding; + rv = mBrowser->GetEncoding (encoding); + NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); + + nsEmbedString unescaped; + rv = escaper->UnEscapeNonAsciiURI (encoding, aEscaped, unescaped); + NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && unescaped.Length(), NS_ERROR_FAILURE); + + NS_UTF16ToCString (unescaped, NS_CSTRING_ENCODING_UTF8, aUnescaped); + + return NS_OK; +} + nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget, MozillaEmbedEvent *info) { @@ -377,9 +401,17 @@ nsresult EventContext::GetEventContext (nsIDOMEventTarget *EventTarget, if (g_str_has_prefix (href.get(), "mailto:")) { - info->context |= EMBED_CONTEXT_EMAIL_LINK; + /* cut "mailto:" */ href.Cut (0, 7); - SetStringProperty ("email", href.get()); + // FIXME: cut any chars after "?" + + nsEmbedCString unescapedHref; + rv = Unescape (href, unescapedHref); + if (NS_SUCCEEDED (rv) && unescapedHref.Length()) + { + SetStringProperty ("email", unescapedHref.get()); + info->context |= EMBED_CONTEXT_EMAIL_LINK; + } } if (anchor && tmp.Length()) diff --git a/embed/mozilla/EventContext.h b/embed/mozilla/EventContext.h index 56ac96c58..5a2564e3f 100644 --- a/embed/mozilla/EventContext.h +++ b/embed/mozilla/EventContext.h @@ -53,6 +53,7 @@ private: nsresult GatherTextUnder (nsIDOMNode* aNode, nsAString& aResult); nsresult ResolveBaseURL (const nsAString &relurl, nsACString &url); + nsresult Unescape (const nsACString &aEscaped, nsACString &aUnescaped); nsresult GetEventContext (nsIDOMEventTarget *EventTarget, MozillaEmbedEvent *info); nsresult GetCSSBackground (nsIDOMNode *node, nsAString& url); |