diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2004-07-05 07:50:52 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2004-07-05 07:50:52 +0800 |
commit | cb2cadac4196048e1caf47bb9a876d6edc2cfa34 (patch) | |
tree | a83c2fe824f66da443a44bf2cb0b3d7d30a24af5 /embed/mozilla/EventContext.cpp | |
parent | 1448306a534067e474d26a2e590c96c45cc6d40d (diff) | |
download | gsoc2013-epiphany-cb2cadac4196048e1caf47bb9a876d6edc2cfa34.tar gsoc2013-epiphany-cb2cadac4196048e1caf47bb9a876d6edc2cfa34.tar.gz gsoc2013-epiphany-cb2cadac4196048e1caf47bb9a876d6edc2cfa34.tar.bz2 gsoc2013-epiphany-cb2cadac4196048e1caf47bb9a876d6edc2cfa34.tar.lz gsoc2013-epiphany-cb2cadac4196048e1caf47bb9a876d6edc2cfa34.tar.xz gsoc2013-epiphany-cb2cadac4196048e1caf47bb9a876d6edc2cfa34.tar.zst gsoc2013-epiphany-cb2cadac4196048e1caf47bb9a876d6edc2cfa34.zip |
Unescape the mailto: address, fixes bug #144462.
2004-07-05 Christian Persch <chpe@cvs.gnome.org>
* embed/mozilla/EventContext.cpp:
* embed/mozilla/EventContext.h:
Unescape the mailto: address, fixes bug #144462.
Diffstat (limited to 'embed/mozilla/EventContext.cpp')
-rw-r--r-- | embed/mozilla/EventContext.cpp | 36 |
1 files changed, 34 insertions, 2 deletions
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()) |