diff --git a/mozilla/caps/src/nsScriptSecurityManager.cpp b/mozilla/caps/src/nsScriptSecurityManager.cpp index 923ae69466d..c6a73329bba 100644 --- a/mozilla/caps/src/nsScriptSecurityManager.cpp +++ b/mozilla/caps/src/nsScriptSecurityManager.cpp @@ -80,6 +80,7 @@ #include "nsIObserverService.h" #include "nsIContent.h" #include "nsAutoPtr.h" +#include "nsAboutProtocolUtils.h" static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID); @@ -1152,9 +1153,9 @@ nsScriptSecurityManager::GetBaseURIScheme(nsIURI* aURI, if (NS_FAILED(rv)) return rv; //-- If aURI is a view-source URI, drill down to the base URI - nsCAutoString path; if (aScheme.EqualsLiteral("view-source")) { + nsCAutoString path; rv = aURI->GetPath(path); if (NS_FAILED(rv)) return rv; nsCOMPtr innerURI; @@ -1178,15 +1179,15 @@ nsScriptSecurityManager::GetBaseURIScheme(nsIURI* aURI, if(aScheme.EqualsLiteral("about")) { nsCAutoString path; - if(NS_FAILED(aURI->GetPath(path))) - return NS_ERROR_FAILURE; + rv = NS_GetAboutModuleName(aURI, path); + NS_ENSURE_SUCCESS(rv, rv); if (path.EqualsLiteral("blank") || path.EqualsLiteral("mozilla") || path.EqualsLiteral("logo") || path.EqualsLiteral("license") || path.EqualsLiteral("licence") || path.EqualsLiteral("credits") || - Substring(path,0,9).EqualsLiteral("neterror?")) + path.EqualsLiteral("neterror")) { aScheme = NS_LITERAL_CSTRING("about safe"); return NS_OK; diff --git a/mozilla/netwerk/protocol/about/public/Makefile.in b/mozilla/netwerk/protocol/about/public/Makefile.in index 6f887ac3151..0d4e6d53f23 100644 --- a/mozilla/netwerk/protocol/about/public/Makefile.in +++ b/mozilla/netwerk/protocol/about/public/Makefile.in @@ -48,6 +48,8 @@ GRE_MODULE = 1 XPIDLSRCS = nsIAboutModule.idl +EXPORTS = nsAboutProtocolUtils.h + include $(topsrcdir)/config/rules.mk DEFINES += -DIMPL_NS_NET diff --git a/mozilla/netwerk/protocol/about/public/nsAboutProtocolUtils.h b/mozilla/netwerk/protocol/about/public/nsAboutProtocolUtils.h new file mode 100644 index 00000000000..20301a00b9f --- /dev/null +++ b/mozilla/netwerk/protocol/about/public/nsAboutProtocolUtils.h @@ -0,0 +1,64 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is nsAboutProtocolUtils. + * + * The Initial Developer of the Original Code is the Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2005 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * L. David Baron (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsIURI.h" +#include "nsString.h" +#include "nsReadableUtils.h" + +inline nsresult +NS_GetAboutModuleName(nsIURI *aAboutURI, nsCString& aModule) +{ +#ifdef DEBUG + { + PRBool isAbout; + NS_ASSERTION(NS_SUCCEEDED(aAboutURI->SchemeIs("about", &isAbout)) && + isAbout, + "should be used only on about: URIs"); + } +#endif + + nsresult rv = aAboutURI->GetPath(aModule); + NS_ENSURE_SUCCESS(rv, rv); + + PRInt32 f = aModule.FindCharInSet(NS_LITERAL_CSTRING("#?")); + if (f != kNotFound) { + aModule.Truncate(f); + } + + // convert to lowercase, as all about: modules are lowercase + ToLowerCase(aModule); + return NS_OK; +} diff --git a/mozilla/netwerk/protocol/about/src/nsAboutProtocolHandler.cpp b/mozilla/netwerk/protocol/about/src/nsAboutProtocolHandler.cpp index d8a396612f4..7263e9f654c 100644 --- a/mozilla/netwerk/protocol/about/src/nsAboutProtocolHandler.cpp +++ b/mozilla/netwerk/protocol/about/src/nsAboutProtocolHandler.cpp @@ -46,6 +46,7 @@ #include "nsString.h" #include "nsReadableUtils.h" #include "nsNetCID.h" +#include "nsAboutProtocolUtils.h" static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID); @@ -131,29 +132,15 @@ nsAboutProtocolHandler::NewURI(const nsACString &aSpec, return rv; } -void -nsAboutProtocolHandler::StripQueryAndHash(nsCString& aPath) -{ - PRInt32 f = aPath.FindCharInSet(NS_LITERAL_CSTRING("#?")); - if (f != kNotFound) { - aPath.Truncate(f); - } - - // convert to lowercase, as all about: modules are lowercase - ToLowerCase(aPath); -} - NS_IMETHODIMP nsAboutProtocolHandler::NewChannel(nsIURI* uri, nsIChannel* *result) { // about:what you ask? nsresult rv; nsCAutoString contractID; - rv = uri->GetPath(contractID); + rv = NS_GetAboutModuleName(uri, contractID); if (NS_FAILED(rv)) return rv; - StripQueryAndHash(contractID); - // look up a handler to deal with "what" contractID.Insert(NS_LITERAL_CSTRING(NS_ABOUT_MODULE_CONTRACTID_PREFIX), 0); diff --git a/mozilla/netwerk/protocol/about/src/nsAboutProtocolHandler.h b/mozilla/netwerk/protocol/about/src/nsAboutProtocolHandler.h index c6a02eeb040..516258152eb 100644 --- a/mozilla/netwerk/protocol/about/src/nsAboutProtocolHandler.h +++ b/mozilla/netwerk/protocol/about/src/nsAboutProtocolHandler.h @@ -66,10 +66,6 @@ public: Create(nsISupports *aOuter, REFNSIID aIID, void **aResult); nsresult Init(); - - static void StripQueryAndHash(nsCString& aPath); - -protected: }; #endif /* nsAboutProtocolHandler_h___ */ diff --git a/mozilla/netwerk/protocol/about/src/nsAboutRedirector.cpp b/mozilla/netwerk/protocol/about/src/nsAboutRedirector.cpp index 2c9d0db846f..80f69951ada 100644 --- a/mozilla/netwerk/protocol/about/src/nsAboutRedirector.cpp +++ b/mozilla/netwerk/protocol/about/src/nsAboutRedirector.cpp @@ -42,6 +42,7 @@ #include "nsNetUtil.h" #include "plstr.h" #include "nsIScriptSecurityManager.h" +#include "nsAboutProtocolUtils.h" NS_IMPL_ISUPPORTS1(nsAboutRedirector, nsIAboutModule) @@ -81,12 +82,10 @@ nsAboutRedirector::NewChannel(nsIURI *aURI, nsIChannel **result) nsresult rv; nsCAutoString path; - rv = aURI->GetPath(path); + rv = NS_GetAboutModuleName(aURI, path); if (NS_FAILED(rv)) return rv; - nsAboutProtocolHandler::StripQueryAndHash(path); - nsCOMPtr ioService = do_GetIOService(&rv); if (NS_FAILED(rv)) return rv;