From 056e78ca2904f2a8f7eaa200098f36f0029c4425 Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Sun, 17 Jul 2005 16:06:04 +0000 Subject: A embed/mozilla/EphyAboutModule.cpp: A embed/mozilla/EphyAboutModule.h: R 2005-07-17 Christian Persch A embed/mozilla/EphyAboutModule.cpp: A embed/mozilla/EphyAboutModule.h: R embed/mozilla/EphyProtocolHandler.cpp: R embed/mozilla/EphyProtocolHandler.h: * embed/mozilla/Makefile.am: * embed/mozilla/MozRegisterComponents.cpp: * po/POTFILES.in: Yet another mozilla API change. * src/bookmarks/ephy-bookmarks.c: (ephy_bookmarks_get_smart_bookmark_width): Remove stray g_print, and clamp entry width to sane values. --- embed/mozilla/EphyAboutModule.cpp | 520 +++++++++++++++++++++++++++ embed/mozilla/EphyAboutModule.h | 60 ++++ embed/mozilla/EphyProtocolHandler.cpp | 599 -------------------------------- embed/mozilla/EphyProtocolHandler.h | 64 ---- embed/mozilla/Makefile.am | 4 +- embed/mozilla/MozRegisterComponents.cpp | 20 +- 6 files changed, 592 insertions(+), 675 deletions(-) create mode 100644 embed/mozilla/EphyAboutModule.cpp create mode 100644 embed/mozilla/EphyAboutModule.h delete mode 100644 embed/mozilla/EphyProtocolHandler.cpp delete mode 100644 embed/mozilla/EphyProtocolHandler.h (limited to 'embed') diff --git a/embed/mozilla/EphyAboutModule.cpp b/embed/mozilla/EphyAboutModule.cpp new file mode 100644 index 000000000..f6247eec3 --- /dev/null +++ b/embed/mozilla/EphyAboutModule.cpp @@ -0,0 +1,520 @@ +/* + * Copyright (C) 2001 Matt Aubury, Philip Langdale + * Copyright (C) 2004 Crispin Flowerday + * Copyright (C) 2005 Christian Persch + * Copyright (C) 2005 Adam Hooper + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + */ + +#include "mozilla-config.h" + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "EphyAboutModule.h" +#include "EphyUtils.h" + +#include "ephy-debug.h" + +#include + +EphyAboutModule::EphyAboutModule() +{ + LOG ("EphyAboutModule ctor [%p]\n", this); +} + +EphyAboutModule::~EphyAboutModule() +{ + LOG ("EphyAboutModule dtor [%p]\n", this); +} + +NS_IMPL_ISUPPORTS1 (EphyAboutModule, nsIAboutModule) + +/* nsIChannel newChannel (in nsIURI aURI); */ +NS_IMETHODIMP +EphyAboutModule::NewChannel(nsIURI *aURI, + nsIChannel **_retval) +{ + NS_ENSURE_ARG(aURI); + + nsCAutoString path; + aURI->GetPath (path); + + if (strncmp (path.get(), "neterror", strlen ("neterror")) == 0) + { + return CreateErrorPage (aURI, _retval); + } + + if (strncmp (path.get (), "epiphany", strlen ("epiphany")) == 0) + { + return Redirect (nsDependentCString ("file://" SHARE_DIR "/epiphany.xhtml"), _retval); + } + + return NS_ERROR_ILLEGAL_VALUE; +} + +/* private functions */ + +nsresult +EphyAboutModule::Redirect(const nsACString &aURL, + nsIChannel **_retval) +{ + nsresult rv; + nsCOMPtr ioService; + rv = EphyUtils::GetIOService (getter_AddRefs (ioService)); + NS_ENSURE_SUCCESS (rv, rv); + + nsCOMPtr tempChannel; + rv = ioService->NewChannel(aURL, nsnull, nsnull, getter_AddRefs(tempChannel)); + NS_ENSURE_SUCCESS (rv, rv); + + nsCOMPtr uri; + rv = ioService->NewURI(aURL, nsnull, nsnull, getter_AddRefs(uri)); + NS_ENSURE_SUCCESS (rv, rv); + + tempChannel->SetOriginalURI (uri); + + nsCOMPtr securityManager = + do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); + NS_ENSURE_SUCCESS (rv, rv); + + nsCOMPtr principal; + rv = securityManager->GetCodebasePrincipal(uri, getter_AddRefs(principal)); + NS_ENSURE_SUCCESS (rv, rv); + + rv = tempChannel->SetOwner(principal); + NS_ENSURE_SUCCESS (rv, rv); + + NS_ADDREF(*_retval = tempChannel); + return rv; +} + +nsresult +EphyAboutModule::ParseErrorURL(const char *aURL, + nsACString &aError, + nsACString &aRawOriginURL, + nsACString &aOriginURL, + nsACString &aOriginCharset) +{ + /* The error page URL is of the form "epiphany:error?e=&u=&c=&d=" */ + const char *query = strstr (aURL, "?"); + if (!query) return NS_ERROR_FAILURE; + + /* skip the '?' */ + ++query; + + char **params = g_strsplit (query, "&", -1); + if (!params) return NS_ERROR_FAILURE; + + for (PRUint32 i = 0; params[i] != NULL; ++i) + { + char *param = params[i]; + + if (strlen (param) <= 2) continue; + + switch (param[0]) + { + case 'e': + aError.Assign (nsUnescape (param + 2)); + break; + case 'u': + aRawOriginURL.Assign (param + 2); + aOriginURL.Assign (nsUnescape (param + 2)); + break; + case 'c': + aOriginCharset.Assign (nsUnescape (param + 2)); + break; + case 'd': + /* we don't need mozilla's description parameter */ + default: + break; + } + } + + g_strfreev (params); + + return NS_OK; +} + +nsresult +EphyAboutModule::GetErrorMessage(nsIURI *aURI, + const char *aError, + char **aPrimary, + char **aSecondary, + char **aTertiary, + char **aLinkIntro) +{ + if (strcmp (aError, "protocolNotFound") == 0) + { + nsCAutoString scheme; + aURI->GetScheme (scheme); + + /* Translators: %s is the name of a protocol, like "http" etc. */ + *aPrimary = g_strdup_printf (_("“%s” protocol is not supported."), scheme.get()); + /* FIXME: get the list of supported protocols from necko */ + *aSecondary = _("Supported protocols are “http”, “https”, “ftp”, “file”, “smb” " + "and “sftp”."); + } + else if (strcmp (aError, "fileNotFound") == 0) + { + nsCAutoString path; + aURI->GetPath (path); + + /* Translators: %s is the path and filename, for example "/home/user/test.html" */ + *aPrimary = g_markup_printf_escaped (_("File “%s” not found."), path.get()); + *aSecondary = _("Check the location of the file and try again."); + } + else if (strcmp (aError, "dnsNotFound") == 0) + { + nsCAutoString host; + aURI->GetHost (host); + + /* Translators: %s is the hostname, like "www.example.com" */ + *aPrimary = g_markup_printf_escaped (_("“%s” could not be found."), + host.get()); + *aSecondary = _("Check that you are connected to the internet, and " + "that the address is correct."); + *aLinkIntro = _("If this page used to exist, you may find an archived version:"); + } + else if (strcmp (aError, "connectionFailure") == 0) + { + nsCAutoString host; + aURI->GetHost (host); + + /* Translators: %s is the hostname, like "www.example.com" */ + *aPrimary = g_markup_printf_escaped + (_("“%s” refused the connection."), + host.get()); + *aSecondary = _("The server may be busy or you may have a " + "network connection problem. Try again later."); + *aLinkIntro = _("There may be an old version of the page you wanted:"); + } + else if (strcmp (aError, "netInterrupt") == 0) + { + nsCAutoString host; + aURI->GetHost (host); + + /* Translators: %s is the hostname, like "www.example.com" */ + *aPrimary = g_markup_printf_escaped + (_("“%s” interrupted the connection."), + host.get()); + *aSecondary = _("The server may be busy or you may have a " + "network connection problem. Try again later."); + *aLinkIntro = _("There may be an old version of the page you wanted:"); + } + else if (strcmp (aError, "netTimeout") == 0) + { + nsCAutoString host; + aURI->GetHost (host); + + /* Translators: %s is the hostname, like "www.example.com" */ + *aPrimary = g_markup_printf_escaped + (_("“%s” is not responding."), + host.get()); + *aSecondary = _("The connection was lost because the " + "server took too long to respond."); + *aTertiary = _("The server may be busy or you may have a network " + "connection problem. Try again later."); + *aLinkIntro = _("There may be an old version of the page you wanted:"); + } + else if (strcmp (aError, "malformedURI") == 0) + { + *aPrimary = g_strdup (_("Invalid address.")); + *aSecondary = g_strdup (_("The address you entered is not valid.")); + } + else if (strcmp (aError, "redirectLoop") == 0) + { + nsCAutoString host; + aURI->GetHost (host); + + /* Translators: %s is the hostname, like "www.example.com" */ + *aPrimary = g_markup_printf_escaped + (_("“%s” redirected too many times."), + host.get()); + *aSecondary = _("The redirection has been stopped for security reasons."); + *aLinkIntro = _("There may be an old version of the page you wanted:"); + } + else if (strcmp (aError, "unknownSocketType") == 0) + { + nsCAutoString host; + aURI->GetHost (host); + + /* Translators: %s is the hostname, like "www.example.com" */ + *aPrimary = g_markup_printf_escaped + (_("“%s” requires an encrypted connection."), + host.get()); + *aSecondary = _("The document could not be loaded because " + "encryption support is not installed."); + *aLinkIntro = _("There may be an old version of the page you wanted:"); + } + else if (strcmp (aError, "netReset") == 0) + { + nsCAutoString host; + aURI->GetHost (host); + + /* Translators: %s is the hostname, like "www.example.com" */ + *aPrimary = g_markup_printf_escaped + (_("“%s” dropped the connection."), + host.get()); + *aSecondary = _("The server dropped the connection " + "before any data could be read."); + *aTertiary = _("The server may be busy or you may have a " + "network connection problem. Try again later."); + *aLinkIntro = _("There may be an old version of the page you wanted:"); + } + else if (strcmp (aError, "netOffline") == 0) + { + *aPrimary = g_strdup (_("Cannot load document in offline mode.")); + *aSecondary = _("This document cannot be viewed in offline " + "mode. Set Epiphany to “online” " + "and try again."); + } + else if (strcmp (aError, "deniedPortAccess") == 0) + { + nsCAutoString host; + aURI->GetHost (host); + + PRInt32 port = -1; + aURI->GetPort (&port); + + /* Translators: %s is the hostname, like "www.example.com" */ + *aPrimary = g_markup_printf_escaped + (_("“%s” denied access to port “%d”."), + host.get(), port > 0 ? port : 80); + *aSecondary = g_strdup (_("The server dropped the connection " + "before any data could be read.")); + *aTertiary = _("The server may be busy or you may have a " + "network connection problem. Try again later."); + *aLinkIntro = _("There may be an old version of the page you wanted:"); + } + else if (strcmp (aError, "proxyResolveFailure") == 0 || + strcmp (aError, "proxyConnectFailure") == 0) + { + *aPrimary = g_strdup (_("Could not connect to proxy server.")); + *aSecondary = _("Check the proxy server settings in Control Center. " + "If the connection still fails, there may be " + "a problem with your proxy server or your " + "network connection."); + } + else + { + return NS_ERROR_ILLEGAL_VALUE; + } + + return NS_OK; +} + +nsresult +EphyAboutModule::CreateErrorPage(nsIURI *aErrorURI, + nsIChannel **_retval) +{ + /* First parse the arguments */ + nsresult rv = NS_ERROR_ILLEGAL_VALUE; + nsCAutoString spec; + rv = aErrorURI->GetSpec (spec); + NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && !spec.IsEmpty(), rv); + + nsCAutoString error, rawurl, url, charset; + rv = ParseErrorURL (spec.get (), error, rawurl, url, charset); + if (NS_FAILED (rv) || error.IsEmpty () || url.IsEmpty()) return rv; + + nsCOMPtr uri; + rv = EphyUtils::NewURI(getter_AddRefs (uri), url, charset.get()); + /* FIXME can uri be NULL if the original url was invalid? */ + NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && uri, rv); + + char *primary = nsnull, *secondary = nsnull, *tertiary = nsnull, *linkintro = nsnull; + rv = GetErrorMessage (uri, error.get(), &primary, &secondary, &tertiary, &linkintro); + + /* we don't know about this error code. + * FIXME: We'd like to forward to mozilla's about:neterror handler, + * but I don't know how to. So just redirect to the same page that + * mozilla's handler redirects to. + */ + if (rv == NS_ERROR_ILLEGAL_VALUE) + { + nsCAutoString url(spec); + + /* remove "about:neterror" part and insert mozilla's error page url */ + url.Cut(0, strlen ("about:neterror")); + url.Insert("chrome://global/content/netError.xhtml", 0); + + return Redirect (url, _retval); + } + + NS_ENSURE_TRUE (primary && secondary, NS_ERROR_FAILURE); + + /* open the rendering stream */ + nsCOMPtr storageStream; + rv = NS_NewStorageStream(16384, (PRUint32) -1, getter_AddRefs (storageStream)); + NS_ENSURE_SUCCESS (rv, rv); + + nsCOMPtr stream; + rv = storageStream->GetOutputStream(0, getter_AddRefs (stream)); + NS_ENSURE_SUCCESS (rv, rv); + + char *language = g_strdup (pango_language_to_string (gtk_get_default_language ())); + g_strdelimit (language, "_-@", '\0'); + + Write (stream, + "\n" + "\n" + "\n" + "\n" + ""); + Write (stream, primary); + /* no favicon for now, it would pollute the favicon cache */ + /* "<link rel=\"icon\" type=\"image/png\" href=\"moz-icon://stock/gtk-dialog-error?size=16\" />\n" */ + Write (stream, + "\n" + "\n" + "\n" + "\n" + "
" + "

"); + Write (stream, primary); + Write (stream, + "

\n" + "

"); + Write (stream, secondary); + if (tertiary) + { + Write (stream, " "); + Write (stream, tertiary); + } + Write (stream, + "

\n"); + + PRBool isHttp = PR_FALSE, isHttps = PR_FALSE; + uri->SchemeIs ("http", &isHttp); + uri->SchemeIs ("https", &isHttps); + if (linkintro && (isHttp || isHttps)) + { + Write (stream, "

"); + Write (stream, linkintro); + Write (stream, "

\n" + "

"); + } + + Write (stream, + "
\n" + "\n" + "\n"); + + g_free (language); + g_free (primary); + + /* finish the rendering */ + nsCOMPtr inputStream; + rv = storageStream->NewInputStream(0, getter_AddRefs (inputStream)); + NS_ENSURE_SUCCESS (rv, rv); + + nsCOMPtr channel (do_CreateInstance ("@mozilla.org/network/input-stream-channel;1", &rv)); + NS_ENSURE_SUCCESS (rv, rv); + + rv |= channel->SetURI (aErrorURI); + rv |= channel->SetContentStream (inputStream); + rv |= channel->SetContentType (NS_LITERAL_CSTRING ("application/xhtml+xml")); + rv |= channel->SetContentCharset (NS_LITERAL_CSTRING ("utf-8")); + NS_ENSURE_SUCCESS (rv, rv); + + nsCOMPtr securityManager + (do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv)); + NS_ENSURE_SUCCESS (rv, rv); + + nsCOMPtr principal; + rv = securityManager->GetCodebasePrincipal (aErrorURI, getter_AddRefs (principal)); + NS_ENSURE_SUCCESS (rv, rv); + + rv = channel->SetOwner(principal); + NS_ENSURE_SUCCESS (rv, rv); + + NS_ADDREF(*_retval = channel); + return rv; +} + +nsresult +EphyAboutModule::Write(nsIOutputStream *aStream, + const char *aText) +{ + PRUint32 bytesWritten; + return aStream->Write (aText, strlen (aText), &bytesWritten); +} diff --git a/embed/mozilla/EphyAboutModule.h b/embed/mozilla/EphyAboutModule.h new file mode 100644 index 000000000..7b9f2f0e9 --- /dev/null +++ b/embed/mozilla/EphyAboutModule.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2001 Matt Aubury, Philip Langdale + * Copyright (C) 2004 Crispin Flowerday + * Copyright (C) 2005 Christian Persch + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + */ + +#ifndef EPHY_PROTOCOL_HANDLER_H +#define EPHY_PROTOCOL_HANDLER_H + +#include +#include + +/* a9aea13e-21de-4be8-a07e-a05f11658c55 */ +#define EPHY_ABOUT_MODULE_CID \ +{ 0xa9aea13e, 0x21de, 0x4be8, \ + { 0xa0, 0x7e, 0xa0, 0x5f, 0x11, 0x65, 0x8c, 0x55 } } + +#define EPHY_ABOUT_NETERROR_CONTRACTID NS_ABOUT_MODULE_CONTRACTID_PREFIX "neterror" +#define EPHY_ABOUT_NETERROR_CLASSNAME "Epiphany about:neterror module" +#define EPHY_ABOUT_EPIPHANY_CONTRACTID NS_ABOUT_MODULE_CONTRACTID_PREFIX "epiphany" +#define EPHY_ABOUT_EPIPHANY_CLASSNAME "Epiphany about:epiphany module" + +class nsIChannel; +class nsIOutputStream; +class nsIURI; + +class EphyAboutModule : public nsIAboutModule +{ + public: + NS_DECL_ISUPPORTS + NS_DECL_NSIABOUTMODULE + + EphyAboutModule(); + virtual ~EphyAboutModule(); + + private: + nsresult Redirect(const nsACString&, nsIChannel**); + nsresult ParseErrorURL(const char*, nsACString&, nsACString&, nsACString&, nsACString&); + nsresult GetErrorMessage(nsIURI*, const char*, char**, char**, char**, char**); + nsresult CreateErrorPage(nsIURI*, nsIChannel**); + nsresult Write(nsIOutputStream*, const char*); +}; + +#endif /* EPHY_PROTOCOL_HANDLER_H */ diff --git a/embed/mozilla/EphyProtocolHandler.cpp b/embed/mozilla/EphyProtocolHandler.cpp deleted file mode 100644 index 9c6184849..000000000 --- a/embed/mozilla/EphyProtocolHandler.cpp +++ /dev/null @@ -1,599 +0,0 @@ -/* - * Copyright (C) 2001 Matt Aubury, Philip Langdale - * Copyright (C) 2004 Crispin Flowerday - * Copyright (C) 2005 Christian Persch - * Copyright (C) 2005 Adam Hooper - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ - */ - -#include "mozilla-config.h" - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "EphyProtocolHandler.h" -#include "EphyUtils.h" - -#include "ephy-debug.h" - -#include - -EphyProtocolHandler::EphyProtocolHandler() -{ - LOG ("EphyProtocolHandler ctor [%p]\n", this); -} - -EphyProtocolHandler::~EphyProtocolHandler() -{ - LOG ("EphyProtocolHandler dtor [%p]\n", this); -} - -NS_IMPL_ISUPPORTS2 (EphyProtocolHandler, nsIProtocolHandler, nsIAboutModule) - -/* readonly attribute string scheme; */ -NS_IMETHODIMP -EphyProtocolHandler::GetScheme(nsACString &aScheme) -{ - aScheme.Assign("epiphany"); - return NS_OK; -} - -/* readonly attribute long defaultPort; */ -NS_IMETHODIMP -EphyProtocolHandler::GetDefaultPort(PRInt32 *aDefaultPort) -{ - NS_ENSURE_ARG_POINTER (aDefaultPort); - - *aDefaultPort = -1; - return NS_OK; -} - -/* readonly attribute short protocolFlags; */ -NS_IMETHODIMP -EphyProtocolHandler::GetProtocolFlags(PRUint32 *aProtocolFlags) -{ - NS_ENSURE_ARG_POINTER (aProtocolFlags); - - *aProtocolFlags = nsIProtocolHandler::URI_NORELATIVE | nsIProtocolHandler::URI_NOAUTH; - return NS_OK; -} - -/* nsIURI newURI (in string aSpec, in nsIURI aBaseURI); */ -NS_IMETHODIMP -EphyProtocolHandler::NewURI(const nsACString &aSpec, - const char *aOriginCharset, - nsIURI *aBaseURI, - nsIURI **_retval) -{ - nsresult rv; - nsCOMPtr uri (do_CreateInstance("@mozilla.org/network/simple-uri;1", &rv)); - NS_ENSURE_SUCCESS (rv, rv); - - rv = uri->SetSpec (aSpec); - NS_ENSURE_SUCCESS (rv, rv); - - NS_ADDREF(*_retval = uri); - return NS_OK; -} - -/* nsIChannel newChannel (in nsIURI aURI); */ -NS_IMETHODIMP -EphyProtocolHandler::NewChannel(nsIURI *aURI, - nsIChannel **_retval) -{ - NS_ENSURE_ARG(aURI); - - PRBool isEpiphany = PR_FALSE; - if (NS_SUCCEEDED (aURI->SchemeIs ("epiphany", &isEpiphany)) && isEpiphany) - { - return HandleEpiphany (aURI, _retval); - } - - PRBool isAbout = PR_FALSE; - if (NS_SUCCEEDED (aURI->SchemeIs ("about", &isAbout)) && isAbout) - { - return Redirect (nsDependentCString ("file://" SHARE_DIR "/epiphany.xhtml"), _retval); - } - - return NS_ERROR_ILLEGAL_VALUE; -} - -/* boolean allowPort (in long port, in string scheme); */ -NS_IMETHODIMP -EphyProtocolHandler::AllowPort(PRInt32 port, - const char *scheme, - PRBool *_retval) -{ - *_retval = PR_FALSE; - return NS_OK; -} - -/* private functions */ - -nsresult -EphyProtocolHandler::Redirect(const nsACString &aURL, - nsIChannel **_retval) -{ - nsresult rv; - nsCOMPtr ioService; - rv = EphyUtils::GetIOService (getter_AddRefs (ioService)); - NS_ENSURE_SUCCESS (rv, rv); - - nsCOMPtr tempChannel; - rv = ioService->NewChannel(aURL, nsnull, nsnull, getter_AddRefs(tempChannel)); - NS_ENSURE_SUCCESS (rv, rv); - - nsCOMPtr uri; - rv = ioService->NewURI(aURL, nsnull, nsnull, getter_AddRefs(uri)); - NS_ENSURE_SUCCESS (rv, rv); - - tempChannel->SetOriginalURI (uri); - - nsCOMPtr securityManager = - do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); - NS_ENSURE_SUCCESS (rv, rv); - - nsCOMPtr principal; - rv = securityManager->GetCodebasePrincipal(uri, getter_AddRefs(principal)); - NS_ENSURE_SUCCESS (rv, rv); - - rv = tempChannel->SetOwner(principal); - NS_ENSURE_SUCCESS (rv, rv); - - NS_ADDREF(*_retval = tempChannel); - return rv; -} - -nsresult -EphyProtocolHandler::ParseErrorURL(const char *aURL, - nsACString &aError, - nsACString &aRawOriginURL, - nsACString &aOriginURL, - nsACString &aOriginCharset) -{ - /* The error page URL is of the form "epiphany:error?e=&u=&c=&d=" */ - const char *query = strstr (aURL, "?"); - if (!query) return NS_ERROR_FAILURE; - - /* skip the '?' */ - ++query; - - char **params = g_strsplit (query, "&", -1); - if (!params) return NS_ERROR_FAILURE; - - for (PRUint32 i = 0; params[i] != NULL; ++i) - { - char *param = params[i]; - - if (strlen (param) <= 2) continue; - - switch (param[0]) - { - case 'e': - aError.Assign (nsUnescape (param + 2)); - break; - case 'u': - aRawOriginURL.Assign (param + 2); - aOriginURL.Assign (nsUnescape (param + 2)); - break; - case 'c': - aOriginCharset.Assign (nsUnescape (param + 2)); - break; - case 'd': - /* we don't need mozilla's description parameter */ - default: - break; - } - } - - g_strfreev (params); - - return NS_OK; -} - -nsresult -EphyProtocolHandler::GetErrorMessage(nsIURI *aURI, - const char *aError, - char **aPrimary, - char **aSecondary, - char **aTertiary, - char **aLinkIntro) -{ - if (strcmp (aError, "protocolNotFound") == 0) - { - nsCAutoString scheme; - aURI->GetScheme (scheme); - - /* Translators: %s is the name of a protocol, like "http" etc. */ - *aPrimary = g_strdup_printf (_("“%s” protocol is not supported."), scheme.get()); - /* FIXME: get the list of supported protocols from necko */ - *aSecondary = _("Supported protocols are “http”, “https”, “ftp”, “file”, “smb” " - "and “sftp”."); - } - else if (strcmp (aError, "fileNotFound") == 0) - { - nsCAutoString path; - aURI->GetPath (path); - - /* Translators: %s is the path and filename, for example "/home/user/test.html" */ - *aPrimary = g_markup_printf_escaped (_("File “%s” not found."), path.get()); - *aSecondary = _("Check the location of the file and try again."); - } - else if (strcmp (aError, "dnsNotFound") == 0) - { - nsCAutoString host; - aURI->GetHost (host); - - /* Translators: %s is the hostname, like "www.example.com" */ - *aPrimary = g_markup_printf_escaped (_("“%s” could not be found."), - host.get()); - *aSecondary = _("Check that you are connected to the internet, and " - "that the address is correct."); - *aLinkIntro = _("If this page used to exist, you may find an archived version:"); - } - else if (strcmp (aError, "connectionFailure") == 0) - { - nsCAutoString host; - aURI->GetHost (host); - - /* Translators: %s is the hostname, like "www.example.com" */ - *aPrimary = g_markup_printf_escaped - (_("“%s” refused the connection."), - host.get()); - *aSecondary = _("The server may be busy or you may have a " - "network connection problem. Try again later."); - *aLinkIntro = _("There may be an old version of the page you wanted:"); - } - else if (strcmp (aError, "netInterrupt") == 0) - { - nsCAutoString host; - aURI->GetHost (host); - - /* Translators: %s is the hostname, like "www.example.com" */ - *aPrimary = g_markup_printf_escaped - (_("“%s” interrupted the connection."), - host.get()); - *aSecondary = _("The server may be busy or you may have a " - "network connection problem. Try again later."); - *aLinkIntro = _("There may be an old version of the page you wanted:"); - } - else if (strcmp (aError, "netTimeout") == 0) - { - nsCAutoString host; - aURI->GetHost (host); - - /* Translators: %s is the hostname, like "www.example.com" */ - *aPrimary = g_markup_printf_escaped - (_("“%s” is not responding."), - host.get()); - *aSecondary = _("The connection was lost because the " - "server took too long to respond."); - *aTertiary = _("The server may be busy or you may have a network " - "connection problem. Try again later."); - *aLinkIntro = _("There may be an old version of the page you wanted:"); - } - else if (strcmp (aError, "malformedURI") == 0) - { - *aPrimary = g_strdup (_("Invalid address.")); - *aSecondary = g_strdup (_("The address you entered is not valid.")); - } - else if (strcmp (aError, "redirectLoop") == 0) - { - nsCAutoString host; - aURI->GetHost (host); - - /* Translators: %s is the hostname, like "www.example.com" */ - *aPrimary = g_markup_printf_escaped - (_("“%s” redirected too many times."), - host.get()); - *aSecondary = _("The redirection has been stopped for security reasons."); - *aLinkIntro = _("There may be an old version of the page you wanted:"); - } - else if (strcmp (aError, "unknownSocketType") == 0) - { - nsCAutoString host; - aURI->GetHost (host); - - /* Translators: %s is the hostname, like "www.example.com" */ - *aPrimary = g_markup_printf_escaped - (_("“%s” requires an encrypted connection."), - host.get()); - *aSecondary = _("The document could not be loaded because " - "encryption support is not installed."); - *aLinkIntro = _("There may be an old version of the page you wanted:"); - } - else if (strcmp (aError, "netReset") == 0) - { - nsCAutoString host; - aURI->GetHost (host); - - /* Translators: %s is the hostname, like "www.example.com" */ - *aPrimary = g_markup_printf_escaped - (_("“%s” dropped the connection."), - host.get()); - *aSecondary = _("The server dropped the connection " - "before any data could be read."); - *aTertiary = _("The server may be busy or you may have a " - "network connection problem. Try again later."); - *aLinkIntro = _("There may be an old version of the page you wanted:"); - } - else if (strcmp (aError, "netOffline") == 0) - { - *aPrimary = g_strdup (_("Cannot load document in offline mode.")); - *aSecondary = _("This document cannot be viewed in offline " - "mode. Set Epiphany to “online” " - "and try again."); - } - else if (strcmp (aError, "deniedPortAccess") == 0) - { - nsCAutoString host; - aURI->GetHost (host); - - PRInt32 port = -1; - aURI->GetPort (&port); - - /* Translators: %s is the hostname, like "www.example.com" */ - *aPrimary = g_markup_printf_escaped - (_("“%s” denied access to port “%d”."), - host.get(), port > 0 ? port : 80); - *aSecondary = g_strdup (_("The server dropped the connection " - "before any data could be read.")); - *aTertiary = _("The server may be busy or you may have a " - "network connection problem. Try again later."); - *aLinkIntro = _("There may be an old version of the page you wanted:"); - } - else if (strcmp (aError, "proxyResolveFailure") == 0 || - strcmp (aError, "proxyConnectFailure") == 0) - { - *aPrimary = g_strdup (_("Could not connect to proxy server.")); - *aSecondary = _("Check the proxy server settings in Control Center. " - "If the connection still fails, there may be " - "a problem with your proxy server or your " - "network connection."); - } - else - { - return NS_ERROR_ILLEGAL_VALUE; - } - - return NS_OK; -} - -nsresult -EphyProtocolHandler::HandleEpiphany(nsIURI *aErrorURI, - nsIChannel **_retval) -{ - NS_ENSURE_ARG (aErrorURI); - - nsCAutoString spec; - aErrorURI->GetSpec (spec); - - if (g_str_has_prefix (spec.get(), "epiphany:error?")) - { - return CreateErrorPage (aErrorURI, _retval); - } - - return NS_ERROR_ILLEGAL_VALUE; -} - -nsresult -EphyProtocolHandler::CreateErrorPage(nsIURI *aErrorURI, - nsIChannel **_retval) -{ - /* First parse the arguments */ - nsresult rv = NS_ERROR_ILLEGAL_VALUE; - nsCAutoString spec; - rv = aErrorURI->GetSpec (spec); - NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && !spec.IsEmpty(), rv); - - nsCAutoString error, rawurl, url, charset; - rv = ParseErrorURL (spec.get (), error, rawurl, url, charset); - if (NS_FAILED (rv) || error.IsEmpty () || url.IsEmpty()) return rv; - - nsCOMPtr uri; - rv = EphyUtils::NewURI(getter_AddRefs (uri), url, charset.get()); - /* FIXME can uri be NULL if the original url was invalid? */ - NS_ENSURE_TRUE (NS_SUCCEEDED (rv) && uri, rv); - - char *primary = nsnull, *secondary = nsnull, *tertiary = nsnull, *linkintro = nsnull; - rv = GetErrorMessage (uri, error.get(), &primary, &secondary, &tertiary, &linkintro); - - /* we don't know about this error code; forward to mozilla's impl */ - if (rv == NS_ERROR_ILLEGAL_VALUE) - { - nsCAutoString url(spec); - - /* remove "epiphany:error" part and insert mozilla's error page url */ - url.Cut(0, strlen ("epiphany:error")); - url.Insert("chrome://global/content/netError.xhtml", 0); - - return Redirect (url, _retval); - } - - NS_ENSURE_TRUE (primary && secondary, NS_ERROR_FAILURE); - - /* open the rendering stream */ - nsCOMPtr storageStream; - rv = NS_NewStorageStream(16384, (PRUint32) -1, getter_AddRefs (storageStream)); - NS_ENSURE_SUCCESS (rv, rv); - - nsCOMPtr stream; - rv = storageStream->GetOutputStream(0, getter_AddRefs (stream)); - NS_ENSURE_SUCCESS (rv, rv); - - char *language = g_strdup (pango_language_to_string (gtk_get_default_language ())); - g_strdelimit (language, "_-@", '\0'); - - Write (stream, - "\n" - "\n" - "\n" - "\n" - ""); - Write (stream, primary); - /* no favicon for now, it would pollute the favicon cache */ - /* "<link rel=\"icon\" type=\"image/png\" href=\"moz-icon://stock/gtk-dialog-error?size=16\" />\n" */ - Write (stream, - "\n" - "\n" - "\n" - "\n" - "
" - "

"); - Write (stream, primary); - Write (stream, - "

\n" - "

"); - Write (stream, secondary); - if (tertiary) - { - Write (stream, " "); - Write (stream, tertiary); - } - Write (stream, - "

\n"); - - PRBool isHttp = PR_FALSE, isHttps = PR_FALSE; - uri->SchemeIs ("http", &isHttp); - uri->SchemeIs ("https", &isHttps); - if (linkintro && (isHttp || isHttps)) - { - Write (stream, "

"); - Write (stream, linkintro); - Write (stream, "

\n" - "

"); - } - - Write (stream, - "
\n" - "\n" - "\n"); - - g_free (language); - g_free (primary); - - /* finish the rendering */ - nsCOMPtr inputStream; - rv = storageStream->NewInputStream(0, getter_AddRefs (inputStream)); - NS_ENSURE_SUCCESS (rv, rv); - - nsCOMPtr channel (do_CreateInstance ("@mozilla.org/network/input-stream-channel;1", &rv)); - NS_ENSURE_SUCCESS (rv, rv); - - rv |= channel->SetURI (aErrorURI); - rv |= channel->SetContentStream (inputStream); - rv |= channel->SetContentType (NS_LITERAL_CSTRING ("application/xhtml+xml")); - rv |= channel->SetContentCharset (NS_LITERAL_CSTRING ("utf-8")); - NS_ENSURE_SUCCESS (rv, rv); - - nsCOMPtr securityManager - (do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv)); - NS_ENSURE_SUCCESS (rv, rv); - - nsCOMPtr principal; - rv = securityManager->GetCodebasePrincipal (aErrorURI, getter_AddRefs (principal)); - NS_ENSURE_SUCCESS (rv, rv); - - rv = channel->SetOwner(principal); - NS_ENSURE_SUCCESS (rv, rv); - - NS_ADDREF(*_retval = channel); - return rv; -} - -nsresult -EphyProtocolHandler::Write(nsIOutputStream *aStream, - const char *aText) -{ - PRUint32 bytesWritten; - return aStream->Write (aText, strlen (aText), &bytesWritten); -} - -nsresult -EphyProtocolHandler::WriteHTMLEscape(nsIOutputStream *aStream, - const char *aText) -{ - char *text = g_markup_escape_text (aText, strlen (aText)); - nsresult rv = Write (aStream, text); - g_free (text); - - return rv; -} diff --git a/embed/mozilla/EphyProtocolHandler.h b/embed/mozilla/EphyProtocolHandler.h deleted file mode 100644 index 915d704cb..000000000 --- a/embed/mozilla/EphyProtocolHandler.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2001 Matt Aubury, Philip Langdale - * Copyright (C) 2004 Crispin Flowerday - * Copyright (C) 2005 Christian Persch - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ - */ - -#ifndef EPHY_PROTOCOL_HANDLER_H -#define EPHY_PROTOCOL_HANDLER_H - -#include -#include -#include - -/* a9aea13e-21de-4be8-a07e-a05f11658c55 */ -#define EPHY_PROTOCOL_HANDLER_CID \ -{ 0xa9aea13e, 0x21de, 0x4be8, \ - { 0xa0, 0x7e, 0xa0, 0x5f, 0x11, 0x65, 0x8c, 0x55 } } - -#define EPHY_PROTOCOL_HANDLER_CONTRACTID NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "epiphany" -#define EPHY_PROTOCOL_HANDLER_CLASSNAME "Epiphany Protocol Handler" -#define EPHY_ABOUT_CONTRACTID NS_ABOUT_MODULE_CONTRACTID_PREFIX "epiphany" -#define EPHY_ABOUT_CLASSNAME "Epiphany's about:epiphany" - -class nsIChannel; -class nsIOutputStream; -class nsIURI; - -class EphyProtocolHandler : public nsIProtocolHandler, - public nsIAboutModule -{ - public: - NS_DECL_ISUPPORTS - NS_DECL_NSIPROTOCOLHANDLER - - EphyProtocolHandler(); - virtual ~EphyProtocolHandler(); - - private: - nsresult Redirect(const nsACString&, nsIChannel**); - nsresult ParseErrorURL(const char*, nsACString&, nsACString&, nsACString&, nsACString&); - nsresult GetErrorMessage(nsIURI*, const char*, char**, char**, char**, char**); - nsresult HandleEpiphany(nsIURI*, nsIChannel**); - nsresult CreateErrorPage(nsIURI*, nsIChannel**); - nsresult Write(nsIOutputStream*, const char*); - nsresult WriteHTMLEscape(nsIOutputStream*, const char*); -}; - -#endif /* EPHY_PROTOCOL_HANDLER_H */ diff --git a/embed/mozilla/Makefile.am b/embed/mozilla/Makefile.am index 30a05f0fb..385a39b81 100644 --- a/embed/mozilla/Makefile.am +++ b/embed/mozilla/Makefile.am @@ -66,8 +66,8 @@ endif if HAVE_GECKO_1_8 libephymozillaembed_la_SOURCES += \ - EphyProtocolHandler.cpp \ - EphyProtocolHandler.h + EphyAboutModule.cpp \ + EphyAboutModule.h endif mozilla_include_subdirs = \ diff --git a/embed/mozilla/MozRegisterComponents.cpp b/embed/mozilla/MozRegisterComponents.cpp index f52226616..bc7ee4709 100644 --- a/embed/mozilla/MozRegisterComponents.cpp +++ b/embed/mozilla/MozRegisterComponents.cpp @@ -43,7 +43,7 @@ #endif #ifdef HAVE_GECKO_1_8 -#include "EphyProtocolHandler.h" +#include "EphyAboutModule.h" #endif #include @@ -76,7 +76,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(GtkNSSSecurityWarningDialogs) #endif #ifdef HAVE_GECKO_1_8 -NS_GENERIC_FACTORY_CONSTRUCTOR(EphyProtocolHandler) +NS_GENERIC_FACTORY_CONSTRUCTOR(EphyAboutModule) #endif /* class information */ @@ -207,16 +207,16 @@ static const nsModuleComponentInfo sAppComps[] = { }, #ifdef HAVE_GECKO_1_8 { - EPHY_ABOUT_CLASSNAME, - EPHY_PROTOCOL_HANDLER_CID, - EPHY_ABOUT_CONTRACTID, - EphyProtocolHandlerConstructor + EPHY_ABOUT_EPIPHANY_CLASSNAME, + EPHY_ABOUT_MODULE_CID, + EPHY_ABOUT_EPIPHANY_CONTRACTID, + EphyAboutModuleConstructor }, { - EPHY_PROTOCOL_HANDLER_CLASSNAME, - EPHY_PROTOCOL_HANDLER_CID, - EPHY_PROTOCOL_HANDLER_CONTRACTID, - EphyProtocolHandlerConstructor + EPHY_ABOUT_NETERROR_CLASSNAME, + EPHY_ABOUT_MODULE_CID, + EPHY_ABOUT_NETERROR_CONTRACTID, + EphyAboutModuleConstructor }, #endif }; -- cgit v1.2.3