From e5f48c33b6508d8ce7a930c2a76d1a3404e25f5d Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Sat, 29 May 2004 19:17:20 +0000 Subject: Filter unwanted urls (unused protocols, redirects, non-toplevel loads). 2004-05-29 Christian Persch * embed/mozilla/GlobalHistory.cpp: Filter unwanted urls (unused protocols, redirects, non-toplevel loads). Should fix bug #142143. --- ChangeLog | 7 ++++++ embed/mozilla/GlobalHistory.cpp | 49 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 172761488..cb336e38e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2004-05-29 Christian Persch + + * embed/mozilla/GlobalHistory.cpp: + + Filter unwanted urls (unused protocols, redirects, non-toplevel + loads). Should fix bug #142143. + 2004-05-29 Christian Persch * src/window-commands.c: (window_cmd_view_reload): diff --git a/embed/mozilla/GlobalHistory.cpp b/embed/mozilla/GlobalHistory.cpp index a612fb3b6..3cd801d37 100644 --- a/embed/mozilla/GlobalHistory.cpp +++ b/embed/mozilla/GlobalHistory.cpp @@ -50,8 +50,51 @@ MozGlobalHistory::~MozGlobalHistory () /* void addURI (in nsIURI aURI, in boolean aRedirect, in boolean aToplevel); */ NS_IMETHODIMP MozGlobalHistory::AddURI(nsIURI *aURI, PRBool aRedirect, PRBool aToplevel) { + nsresult rv; + NS_ENSURE_ARG_POINTER(aURI); + + PRBool isJavascript; + rv = aURI->SchemeIs("javascript", &isJavascript); + NS_ENSURE_SUCCESS(rv, rv); + + if (isJavascript || aRedirect || !aTopLevel) + { + return NS_OK; + } + + // filter out unwanted URIs such as chrome: etc + // The model is really if we don't know differently then add which basically + // means we are suppose to try all the things we know not to allow in and + // then if we don't bail go on and allow it in. But here lets compare + // against the most common case we know to allow in and go on and say yes + // to it. + + PRBool isHTTP = PR_FALSE; + PRBool isHTTPS = PR_FALSE; + + rv = aURI->SchemeIs("http", &isHTTP); + rv |= aURI->SchemeIs("https", &isHTTPS); + NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); + + if (!isHTTP && !isHTTPS) + { + PRBool isAbout, isViewSource, isChrome, isData; + + rv = aURI->SchemeIs("about", &isAbout); + rv |= aURI->SchemeIs("view-source", &isViewSource); + rv |= aURI->SchemeIs("chrome", &isChrome); + rv |= aURI->SchemeIs("data", &isData); + NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); + + if (isAbout || isViewSource || isChrome || isData) + { + return NS_OK; + } + } + nsCAutoString spec; - aURI->GetSpec(spec); + rv = aURI->GetSpec(spec); + NS_ENSURE_SUCCESS(rv, rv); ephy_history_add_page (mGlobalHistory, spec.get()); @@ -61,6 +104,8 @@ NS_IMETHODIMP MozGlobalHistory::AddURI(nsIURI *aURI, PRBool aRedirect, PRBool aT /* boolean isVisited (in nsIURI aURI); */ NS_IMETHODIMP MozGlobalHistory::IsVisited(nsIURI *aURI, PRBool *_retval) { + NS_ENSURE_ARG_POINTER(aURI); + nsCAutoString spec; aURI->GetSpec(spec); @@ -72,6 +117,8 @@ NS_IMETHODIMP MozGlobalHistory::IsVisited(nsIURI *aURI, PRBool *_retval) /* void setPageTitle (in nsIURI aURI, in AString aTitle); */ NS_IMETHODIMP MozGlobalHistory::SetPageTitle(nsIURI *aURI, const nsAString & aTitle) { + NS_ENSURE_ARG_POINTER(aURI); + const nsACString &title = NS_ConvertUTF16toUTF8(aTitle); nsCAutoString spec; -- cgit v1.2.3