aboutsummaryrefslogtreecommitdiffstats
path: root/embed
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2003-11-27 02:43:05 +0800
committerChristian Persch <chpe@src.gnome.org>2003-11-27 02:43:05 +0800
commit91166cf4b149a3c5fbaba16529788420954d4fab (patch)
tree083834cca3274d3b5a60eb181197b268da636a06 /embed
parented7795be783b4f49314834b9c71813ce37f17280 (diff)
downloadgsoc2013-epiphany-91166cf4b149a3c5fbaba16529788420954d4fab.tar
gsoc2013-epiphany-91166cf4b149a3c5fbaba16529788420954d4fab.tar.gz
gsoc2013-epiphany-91166cf4b149a3c5fbaba16529788420954d4fab.tar.bz2
gsoc2013-epiphany-91166cf4b149a3c5fbaba16529788420954d4fab.tar.lz
gsoc2013-epiphany-91166cf4b149a3c5fbaba16529788420954d4fab.tar.xz
gsoc2013-epiphany-91166cf4b149a3c5fbaba16529788420954d4fab.tar.zst
gsoc2013-epiphany-91166cf4b149a3c5fbaba16529788420954d4fab.zip
Implement disabling unsafe protocols for lock-down mode.
2003-11-26 Christian Persch <chpe@cvs.gnome.org> * embed/mozilla/EphyContentPolicy.cpp: * embed/mozilla/EphyContentPolicy.h: * embed/mozilla/Makefile.am: * embed/mozilla/MozRegisterComponents.cpp: Implement disabling unsafe protocols for lock-down mode.
Diffstat (limited to 'embed')
-rw-r--r--embed/mozilla/EphyContentPolicy.cpp118
-rw-r--r--embed/mozilla/EphyContentPolicy.h54
-rw-r--r--embed/mozilla/Makefile.am2
-rw-r--r--embed/mozilla/MozRegisterComponents.cpp13
4 files changed, 186 insertions, 1 deletions
diff --git a/embed/mozilla/EphyContentPolicy.cpp b/embed/mozilla/EphyContentPolicy.cpp
new file mode 100644
index 000000000..e84e7d73b
--- /dev/null
+++ b/embed/mozilla/EphyContentPolicy.cpp
@@ -0,0 +1,118 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2003 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$
+ */
+
+/* Relevant Mozilla bug numbers:
+ *
+ * The API will change soon:
+ * http://bugzilla.mozilla.org/show_bug.cgi?id=191839
+ * "Content Policy API sucks rock"
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "EphyContentPolicy.h"
+
+#include "eel-gconf-extensions.h"
+#include "ephy-debug.h"
+
+#include <nsCOMPtr.h>
+#include <nsIURI.h>
+#include <nsString.h>
+
+#define CONF_LOCKDOWN_DISABLE_UNSAFE_PROTOCOLS "/apps/epiphany/lockdown/disable_unsafe_protocols"
+#define CONF_LOCKDOWN_ADDITIONAL_SAFE_PROTOCOLS "/apps/epiphany/lockdown/additional_safe_protocols"
+
+NS_IMPL_ISUPPORTS1(EphyContentPolicy, nsIContentPolicy)
+
+EphyContentPolicy::EphyContentPolicy()
+{
+ LOG ("EphyContentPolicy constructor")
+
+ mLocked = eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_UNSAFE_PROTOCOLS);
+ mSafeProtocols = eel_gconf_get_string_list (CONF_LOCKDOWN_ADDITIONAL_SAFE_PROTOCOLS);
+
+ mSafeProtocols = g_slist_prepend (mSafeProtocols, g_strdup ("https"));
+ mSafeProtocols = g_slist_prepend (mSafeProtocols, g_strdup ("http"));
+}
+
+EphyContentPolicy::~EphyContentPolicy()
+{
+ LOG ("EphyContentPolicy destructor")
+
+ g_slist_foreach (mSafeProtocols, (GFunc) g_free, NULL);
+ g_slist_free (mSafeProtocols);
+}
+
+/* boolean shouldLoad (in PRInt32 contentType, in nsIURI contentLocation, in nsISupports ctxt, in nsIDOMWindow window); */
+NS_IMETHODIMP EphyContentPolicy::ShouldLoad(PRInt32 contentType,
+ nsIURI *contentLocation,
+ nsISupports *ctxt,
+ nsIDOMWindow *window,
+ PRBool *_retval)
+{
+ if (!mLocked)
+ {
+ LOG ("Not locked!")
+
+ *_retval = PR_TRUE;
+
+ return NS_OK;
+ }
+
+ nsCAutoString scheme;
+ contentLocation->GetScheme (scheme);
+
+ nsCAutoString spec;
+ contentLocation->GetSpec (spec);
+
+ LOG ("ShouldLoad type=%d location=%s (scheme %s)", contentType, spec.get(), scheme.get())
+
+ *_retval = PR_FALSE;
+
+ /* Allow the load if the protocol is in safe list, or it's about:blank */
+ if (g_slist_find_custom (mSafeProtocols, scheme.get(), (GCompareFunc) strcmp)
+ || spec.Equals ("about:blank"))
+ {
+ *_retval = PR_TRUE;
+ }
+
+ LOG ("Decision: %sallowing load", *_retval == PR_TRUE ? "" : "NOT ")
+
+ return NS_OK;
+}
+
+/* boolean shouldProcess (in PRInt32 contentType, in nsIURI documentLocation, in nsISupports ctxt, in nsIDOMWindow window); */
+NS_IMETHODIMP EphyContentPolicy::ShouldProcess(PRInt32 contentType,
+ nsIURI *documentLocation,
+ nsISupports *ctxt,
+ nsIDOMWindow *window,
+ PRBool *_retval)
+{
+ /* As far as I can tell from reading mozilla code, this is never called. */
+
+ LOG ("ShouldProcess: this is quite unexpected!")
+
+ *_retval = PR_TRUE;
+
+ return NS_OK;
+}
diff --git a/embed/mozilla/EphyContentPolicy.h b/embed/mozilla/EphyContentPolicy.h
new file mode 100644
index 000000000..3742b8d53
--- /dev/null
+++ b/embed/mozilla/EphyContentPolicy.h
@@ -0,0 +1,54 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2003 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_CONTENT_POLICY_H
+#define EPHY_CONTENT_POLICY_H
+
+#include <glib.h>
+
+#include "nsISupports.h"
+#include "nsIContentPolicy.h"
+
+#define EPHY_CONTENT_POLICY_CONTRACTID "@mozilla.org/embedding/browser/content-policy;1"
+#define EPHY_CONTENT_POLICY_CLASSNAME "Epiphany Content Policy Class"
+
+#define EPHY_CONTENT_POLICY_CID \
+{ /* 6bb60b15-b7bd-4023-a19e-ab691bc3fb43 */ \
+ 0x6bb60b15, \
+ 0xb7bd, \
+ 0x4023, \
+ { 0xa1, 0x9e, 0xab, 0x69, 0x1b, 0xc3, 0xfb, 0x43 } \
+}
+
+class EphyContentPolicy : public nsIContentPolicy
+{
+public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSICONTENTPOLICY
+
+ EphyContentPolicy();
+ virtual ~EphyContentPolicy();
+private:
+ gboolean mLocked;
+ GSList *mSafeProtocols;
+};
+
+#endif
diff --git a/embed/mozilla/Makefile.am b/embed/mozilla/Makefile.am
index ba3b78439..19b35ee29 100644
--- a/embed/mozilla/Makefile.am
+++ b/embed/mozilla/Makefile.am
@@ -51,6 +51,8 @@ libephymozillaembed_la_SOURCES = \
ContentHandler.h \
EphyAboutRedirector.cpp \
EphyAboutRedirector.h \
+ EphyContentPolicy.cpp \
+ EphyContentPolicy.h \
EphyEventListener.cpp \
EphyEventListener.h \
EphyHeaderSniffer.cpp \
diff --git a/embed/mozilla/MozRegisterComponents.cpp b/embed/mozilla/MozRegisterComponents.cpp
index 1ddc46978..57010a22a 100644
--- a/embed/mozilla/MozRegisterComponents.cpp
+++ b/embed/mozilla/MozRegisterComponents.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2001,2002,2003 Philip Langdale
+ * Copyright (C) 2003 Marco Pesenti Gritti
*
* 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
@@ -14,10 +15,12 @@
* 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$
*/
#ifdef HAVE_CONFIG_H
-#include <config.h>
+#include "config.h"
#endif
#include "ContentHandler.h"
@@ -28,6 +31,7 @@
#include "MozDownload.h"
#include "ExternalProtocolService.h"
#include "EphyAboutRedirector.h"
+#include "EphyContentPolicy.h"
#ifdef HAVE_MOZILLA_PSM
#include "GtkNSSClientAuthDialogs.h"
@@ -53,6 +57,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(GIRCProtocolHandler)
NS_GENERIC_FACTORY_CONSTRUCTOR(GFtpProtocolHandler)
NS_GENERIC_FACTORY_CONSTRUCTOR(GNewsProtocolHandler)
NS_GENERIC_FACTORY_CONSTRUCTOR(GMailtoProtocolHandler)
+NS_GENERIC_FACTORY_CONSTRUCTOR(EphyContentPolicy)
#if MOZILLA_SNAPSHOT < 12
NS_GENERIC_FACTORY_CONSTRUCTOR(GExternalProtocolService)
@@ -194,6 +199,12 @@ static const nsModuleComponentInfo sAppComps[] = {
G_MAILTO_PROTOCOL_CID,
G_MAILTO_CONTENT_CONTRACTID,
GMailtoProtocolHandlerConstructor
+ },
+ {
+ EPHY_CONTENT_POLICY_CLASSNAME,
+ EPHY_CONTENT_POLICY_CID,
+ EPHY_CONTENT_POLICY_CONTRACTID,
+ EphyContentPolicyConstructor
}
};