From c951555722d4933277a1d468c6508f5ad34711b1 Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Wed, 25 May 2005 22:08:01 +0000 Subject: Add protocol handler, which I'll use for our custom error pages. Since 2005-05-26 Christian Persch * embed/mozilla/ContentHandler.cpp: * embed/mozilla/EphyProtocolHandler.cpp: * embed/mozilla/EphyProtocolHandler.h: * embed/mozilla/EphyUtils.cpp: * embed/mozilla/EphyUtils.h: * embed/mozilla/GtkNSSClientAuthDialogs.cpp: * embed/mozilla/GtkNSSDialogs.cpp: * embed/mozilla/GtkNSSKeyPairDialogs.cpp: * embed/mozilla/Makefile.am: * embed/mozilla/MozDownload.cpp: * embed/mozilla/MozRegisterComponents.cpp: Add protocol handler, which I'll use for our custom error pages. Since it's almost gratis, add about:epiphany back. --- embed/mozilla/ContentHandler.cpp | 1 + embed/mozilla/EphyProtocolHandler.cpp | 181 ++++++++++++++++++++++++++++++ embed/mozilla/EphyProtocolHandler.h | 58 ++++++++++ embed/mozilla/EphyUtils.cpp | 3 + embed/mozilla/EphyUtils.h | 9 +- embed/mozilla/GtkNSSClientAuthDialogs.cpp | 1 + embed/mozilla/GtkNSSDialogs.cpp | 1 + embed/mozilla/GtkNSSKeyPairDialogs.cpp | 4 +- embed/mozilla/Makefile.am | 6 + embed/mozilla/MozDownload.cpp | 2 + embed/mozilla/MozRegisterComponents.cpp | 22 ++++ 11 files changed, 283 insertions(+), 5 deletions(-) create mode 100644 embed/mozilla/EphyProtocolHandler.cpp create mode 100644 embed/mozilla/EphyProtocolHandler.h (limited to 'embed') diff --git a/embed/mozilla/ContentHandler.cpp b/embed/mozilla/ContentHandler.cpp index db4edb9f5..91ca2b88d 100644 --- a/embed/mozilla/ContentHandler.cpp +++ b/embed/mozilla/ContentHandler.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #ifdef ALLOW_PRIVATE_API diff --git a/embed/mozilla/EphyProtocolHandler.cpp b/embed/mozilla/EphyProtocolHandler.cpp new file mode 100644 index 000000000..334e261b4 --- /dev/null +++ b/embed/mozilla/EphyProtocolHandler.cpp @@ -0,0 +1,181 @@ +/* + * 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$ + */ + +#include "mozilla-config.h" + +#include "config.h" + +#include +#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 + +static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID); +static NS_DEFINE_CID(kInputStreamChannelCID, NS_INPUTSTREAMCHANNEL_CID); + +EphyProtocolHandler::EphyProtocolHandler (void) +{ + 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(kSimpleURICID, &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); + +#if 0 + PRBool isEpiphany = PR_FALSE; + if (NS_SUCCEEDED (aURI->SchemeIs ("epiphany", &isEpiphany)) && isEpiphany) + { + return HandleEpiphany (aURI, _retval); + } +#endif + + 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); + + nsCOMPtr owner (do_QueryInterface(principal)); + rv = tempChannel->SetOwner(owner); + + NS_ADDREF(*_retval = tempChannel); + return rv; +} diff --git a/embed/mozilla/EphyProtocolHandler.h b/embed/mozilla/EphyProtocolHandler.h new file mode 100644 index 000000000..332a20a5c --- /dev/null +++ b/embed/mozilla/EphyProtocolHandler.h @@ -0,0 +1,58 @@ +/* + * 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 (void); + virtual ~EphyProtocolHandler(); + + private: + nsresult Redirect (const nsACString&, nsIChannel**); +}; + +#endif /* EPHY_PROTOCOL_HANDLER_H */ diff --git a/embed/mozilla/EphyUtils.cpp b/embed/mozilla/EphyUtils.cpp index 0888ed674..fb3bfabca 100644 --- a/embed/mozilla/EphyUtils.cpp +++ b/embed/mozilla/EphyUtils.cpp @@ -27,6 +27,9 @@ #include "ephy-embed-single.h" #include "print-dialog.h" +#include +#include +#include #include #undef MOZILLA_INTERNAL_API #include diff --git a/embed/mozilla/EphyUtils.h b/embed/mozilla/EphyUtils.h index 2977dda74..8cc6706ab 100644 --- a/embed/mozilla/EphyUtils.h +++ b/embed/mozilla/EphyUtils.h @@ -21,12 +21,15 @@ #ifndef EPHY_UTILS_H #define EPHY_UTILS_H -#include -#include -#include +#include #include +class nsAString; +class nsACString; +class nsIDOMWindow; +class nsIIOService; class nsIPrintSettings; +class nsIURI; struct _EmbedPrintInfo; namespace EphyUtils diff --git a/embed/mozilla/GtkNSSClientAuthDialogs.cpp b/embed/mozilla/GtkNSSClientAuthDialogs.cpp index f047872be..290f57ed3 100644 --- a/embed/mozilla/GtkNSSClientAuthDialogs.cpp +++ b/embed/mozilla/GtkNSSClientAuthDialogs.cpp @@ -26,6 +26,7 @@ #include "EphyUtils.h" +#include #include #include #include diff --git a/embed/mozilla/GtkNSSDialogs.cpp b/embed/mozilla/GtkNSSDialogs.cpp index e2a412014..1bd70552a 100644 --- a/embed/mozilla/GtkNSSDialogs.cpp +++ b/embed/mozilla/GtkNSSDialogs.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #undef MOZILLA_INTERNAL_API #include #define MOZILLA_INTERNAL_API 1 diff --git a/embed/mozilla/GtkNSSKeyPairDialogs.cpp b/embed/mozilla/GtkNSSKeyPairDialogs.cpp index 83744ba6e..5931a4e22 100644 --- a/embed/mozilla/GtkNSSKeyPairDialogs.cpp +++ b/embed/mozilla/GtkNSSKeyPairDialogs.cpp @@ -45,13 +45,13 @@ #include #include #include +#include #ifdef HAVE_GECKO_1_8 #include #else /* !HAVE_GECKO_1_8 */ -#include #ifdef ALLOW_PRIVATE_API -#include "nsIDOMWindowInternal.h" +#include #endif /* ALLOW_PRIVATE_API */ #endif /* HAVE_GECKO_1_8 */ diff --git a/embed/mozilla/Makefile.am b/embed/mozilla/Makefile.am index 15ae03888..63868e6af 100644 --- a/embed/mozilla/Makefile.am +++ b/embed/mozilla/Makefile.am @@ -60,6 +60,12 @@ libephymozillaembed_la_SOURCES += \ GtkNSSSecurityWarningDialogs.h endif +if HAVE_GECKO_1_8 +libephymozillaembed_la_SOURCES += \ + EphyProtocolHandler.cpp \ + EphyProtocolHandler.h +endif + mozilla_include_subdirs = \ caps \ chardet \ diff --git a/embed/mozilla/MozDownload.cpp b/embed/mozilla/MozDownload.cpp index 7ad66d274..08e515e03 100644 --- a/embed/mozilla/MozDownload.cpp +++ b/embed/mozilla/MozDownload.cpp @@ -56,6 +56,8 @@ #include #include +#include +#include #include #include #include diff --git a/embed/mozilla/MozRegisterComponents.cpp b/embed/mozilla/MozRegisterComponents.cpp index d6f83da95..f52226616 100644 --- a/embed/mozilla/MozRegisterComponents.cpp +++ b/embed/mozilla/MozRegisterComponents.cpp @@ -42,6 +42,10 @@ #include #endif +#ifdef HAVE_GECKO_1_8 +#include "EphyProtocolHandler.h" +#endif + #include #include #include @@ -71,6 +75,10 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(GtkNSSKeyPairDialogs) NS_GENERIC_FACTORY_CONSTRUCTOR(GtkNSSSecurityWarningDialogs) #endif +#ifdef HAVE_GECKO_1_8 +NS_GENERIC_FACTORY_CONSTRUCTOR(EphyProtocolHandler) +#endif + /* class information */ NS_DECL_CLASSINFO(EphySidebar) @@ -197,6 +205,20 @@ static const nsModuleComponentInfo sAppComps[] = { &NS_CLASSINFO_NAME(EphySidebar), nsIClassInfo::DOM_OBJECT }, +#ifdef HAVE_GECKO_1_8 +{ + EPHY_ABOUT_CLASSNAME, + EPHY_PROTOCOL_HANDLER_CID, + EPHY_ABOUT_CONTRACTID, + EphyProtocolHandlerConstructor +}, +{ + EPHY_PROTOCOL_HANDLER_CLASSNAME, + EPHY_PROTOCOL_HANDLER_CID, + EPHY_PROTOCOL_HANDLER_CONTRACTID, + EphyProtocolHandlerConstructor +}, +#endif }; #if defined(HAVE_MOZILLA_PSM) && !defined(HAVE_GECKO_1_8) -- cgit v1.2.3