fixes bug 99410 "further res protocol cleanup" r=dougt, sr=mscott

This commit is contained in:
darin%netscape.com 2001-09-20 01:32:16 +00:00
Родитель bf5d6a446a
Коммит e8db2d99ac
10 изменённых файлов: 156 добавлений и 378 удалений

Просмотреть файл

@ -43,7 +43,6 @@
#include "nsIJARURI.h"
#include "nsILoadGroup.h"
#include "nsIObjectOutputStream.h"
#include "nsIResChannel.h"
#include "nsIScriptSecurityManager.h"
#include "nsIServiceManager.h"
#include "nsIStreamListener.h"
@ -617,15 +616,11 @@ nsChromeProtocolHandler::NewChannel(nsIURI* aURI,
// XXX Will be removed someday when we handle remote chrome.
nsCOMPtr<nsIFileChannel> fileChan;
nsCOMPtr<nsIResChannel> resChan;
nsCOMPtr<nsIJARChannel> jarChan;
fileChan = do_QueryInterface(result);
if (!fileChan) {
resChan = do_QueryInterface(result);
if (!resChan)
if (!fileChan)
jarChan = do_QueryInterface(result);
}
if (!fileChan && !resChan && !jarChan) {
if (!fileChan && !jarChan) {
NS_WARNING("Remote chrome not allowed! Only file:, resource:, and jar: are valid.\n");
result = nsnull;
return NS_ERROR_FAILURE;

Просмотреть файл

@ -239,4 +239,17 @@
}
/******************************************************************************
* netwerk/protocol/res/ classes
*/
#define NS_RESPROTOCOLHANDLER_CID \
{ /* e64f152a-9f07-11d3-8cda-0060b0fc14a3 */ \
0xe64f152a, \
0x9f07, \
0x11d3, \
{0x8c, 0xda, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
}
#endif // nsNetCID_h__

Просмотреть файл

@ -95,13 +95,16 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsStorageTransport)
///////////////////////////////////////////////////////////////////////////////
#include "nsHttpHandler.h"
//NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsHttpHandler, Init)
#include "nsHttpBasicAuth.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHttpBasicAuth)
///////////////////////////////////////////////////////////////////////////////
#include "nsResProtocolHandler.h"
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsResProtocolHandler, Init)
///////////////////////////////////////////////////////////////////////////////
static NS_METHOD
RegisterBuiltInURLParsers(nsIComponentManager *aCompMgr,
@ -158,65 +161,12 @@ UnregisterBuiltInURLParsers(nsIComponentManager *aCompMgr,
return NS_OK;
}
#if 0
#include "nsIHTTPProtocolHandler.h"
#include "nsHTTPHandler.h"
#include "nsHTTPSHandler.h"
#include "nsBasicAuth.h"
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsHTTPHandler, Init);
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsHTTPSHandler, Init);
#define NS_HTTPS_HANDLER_FACTORY_CID { 0xd2771480, 0xcac4, 0x11d3, { 0x8c, 0xaf, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBasicAuth);
#define NS_BASICAUTH_CID { 0xd5c9bc48, 0x1dd1, 0x11b2, { 0x9a, 0x0b, 0xf7, 0x3f, 0x59, 0x53, 0x19, 0xae } }
#define NS_BASICAUTH_CONTRACTID "@mozilla.org/network/http-basic-auth;1"
/* XXX this should all be data-driven, via NS_IMPL_GETMODULE_WITH_CATEGORIES */
static NS_METHOD
RegisterBasicAuth(nsIComponentManager *aCompMgr, nsIFile *aPath,
const char *registryLocation, const char *componentType,
const nsModuleComponentInfo *info)
{
nsresult rv;
nsCOMPtr<nsICategoryManager> catman =
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
nsXPIDLCString previous;
return catman->AddCategoryEntry("http-auth", "basic", NS_BASICAUTH_CONTRACTID,
PR_TRUE, PR_TRUE, getter_Copies(previous));
}
static NS_METHOD
UnregisterBasicAuth(nsIComponentManager *aCompMgr, nsIFile *aPath,
const char *registryLocation,
const nsModuleComponentInfo *info)
{
nsresult rv;
nsCOMPtr<nsICategoryManager> catman =
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
nsXPIDLCString basicAuth;
rv = catman->GetCategoryEntry("http-auth", "basic",
getter_Copies(basicAuth));
if (NS_FAILED(rv)) return rv;
// only unregister if we're the current Basic-auth handler
if (!strcmp(basicAuth, NS_BASICAUTH_CONTRACTID))
return catman->DeleteCategoryEntry("http-auth", "basic", PR_TRUE);
return NS_OK;
}
#endif
///////////////////////////////////////////////////////////////////////////////
#include "nsFileChannel.h"
#include "nsFileProtocolHandler.h"
#include "nsDataHandler.h"
#include "nsJARProtocolHandler.h"
#include "nsResProtocolHandler.h"
#include "nsAboutProtocolHandler.h"
#include "nsAboutBlank.h"
@ -883,25 +833,6 @@ static nsModuleComponentInfo gNetModuleInfo[] = {
nsFileChannel::Create
},
#if 0
// from netwerk/protocol/http:
{ "HTTP Handler",
NS_IHTTPHANDLER_CID,
NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http",
nsHTTPHandlerConstructor },
{ "HTTPS Handler",
NS_HTTPS_HANDLER_FACTORY_CID,
NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "https",
nsHTTPSHandlerConstructor },
{ "Basic Auth Encoder",
NS_BASICAUTH_CID,
NS_BASICAUTH_CONTRACTID,
nsBasicAuthConstructor,
RegisterBasicAuth,
UnregisterBasicAuth
},
#endif
{ "HTTP Handler",
NS_HTTPPROTOCOLHANDLER_CID,
NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http",
@ -931,10 +862,10 @@ static nsModuleComponentInfo gNetModuleInfo[] = {
},
// from netwerk/protocol/res:
{ "The Resource Protocol Handler",
{ "Resource Protocol Handler",
NS_RESPROTOCOLHANDLER_CID,
NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "resource",
nsResProtocolHandler::Create
nsResProtocolHandlerConstructor
},
// from netwerk/protocol/about:

Просмотреть файл

@ -1,2 +0,0 @@
nsIResChannel.idl
nsIResProtocolHandler.idl

Просмотреть файл

@ -30,7 +30,6 @@ MODULE = necko
XPIDL_MODULE = necko_res
XPIDLSRCS = \
nsIResChannel.idl \
nsIResProtocolHandler.idl \
$(NULL)

Просмотреть файл

@ -1,35 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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 mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
MODULE = necko
DEPTH = ..\..\..\..
include <$(DEPTH)/config/config.mak>
XPIDL_MODULE = necko_res
XPIDLSRCS = \
.\nsIResChannel.idl \
.\nsIResProtocolHandler.idl \
$(NULL)
include <$(DEPTH)/config/rules.mak>

Просмотреть файл

@ -18,66 +18,43 @@
* Rights Reserved.
*
* Contributor(s):
* Darin Fisher <darin@netscape.com>
*/
#include "nsIProtocolHandler.idl"
interface nsISimpleEnumerator;
interface nsISupportsArray;
%{C++
#define NS_RESPROTOCOLHANDLER_CID \
{ /* e64f152a-9f07-11d3-8cda-0060b0fc14a3 */ \
0xe64f152a, \
0x9f07, \
0x11d3, \
{0x8c, 0xda, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
}
%}
[scriptable, uuid(d12c08c6-9ef6-11d3-8cda-0060b0fc14a3)]
interface nsIResProtocolHandler : nsIProtocolHandler
{
/**
* Registers a new substitution for root key, e.g.:
* res://<root>/<path> ==> <url>/<path>
* This substitution is put at the beginning of the list
* so that it overrides existing substitutions.
* Sets the substitution for the root key:
* resource://root/path ==> baseURI.resolve(path)
*
* A null baseURI removes the specified substitution.
*
* A root key should always be lowercase; however, this may not be
* enforced.
*/
void prependSubstitution(in string root, in string url);
void setSubstitution(in string root, in nsIURI baseURI);
/**
* Registers a new substitution for root key, e.g.:
* res://<root>/<path> ==> <url>/<path>
* This substitution is put at the end of the list
* so that it doesn't override existing substitutions.
* Gets the substitution for the root key.
*
* @returns NS_ERROR_NOT_AVAILABLE if none exists.
*/
void appendSubstitution(in string root, in string url);
nsIURI getSubstitution(in string root);
/**
* Unregisters a previously registered substitution. If the
* specified root is not found, or if the url string doesn't match
* any registered entries, an error is returned.
* Returns TRUE if the substitution exists and FALSE otherwise.
*/
void removeSubstitution(in string root, in string url);
boolean hasSubstitution(in string root);
/**
* Returns an nsISupportsArray of nsIURIs containing all substitutions
* currently registered for the root. This array is a snapshot of the
* registered entries so it can be iterated over without fear of
* thread-safety concerns.
* Utility function to resolve a resource URI. A resolved URI is not
* guaranteed to reference a resource that exists (ie. opening a channel to
* the resolved URI may fail).
*
* @returns NS_ERROR_NOT_AVAILABLE if resURI.host() is an unknown root key.
*/
nsISupportsArray getSubstitutions(in string root);
/**
* Returns true if substitutions are already defined for the specified root.
*/
boolean hasSubstitutions(in string root);
/**
* Resolution utility function.
*/
string resolveURI(in nsIURI resourceURI);
string resolveURI(in nsIURI resURI);
};

Просмотреть файл

@ -37,9 +37,27 @@
#include "nsNetUtil.h"
static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
static nsResProtocolHandler *gResHandler = nsnull;
////////////////////////////////////////////////////////////////////////////////
#if defined(PR_LOGGING)
//
// Log module for Resource Protocol logging...
//
// To enable logging (see prlog.h for full details):
//
// set NSPR_LOG_MODULES=nsResProtocol:5
// set NSPR_LOG_FILE=log.txt
//
// this enables PR_LOG_ALWAYS level information and places all output in
// the file log.txt
//
static PRLogModuleInfo *gResLog;
#endif
#define LOG(args) PR_LOG(gResLog, PR_LOG_DEBUG, args)
//----------------------------------------------------------------------------
// nsResURL : overrides nsStdURL::GetFile to provide nsIFile resolution
//----------------------------------------------------------------------------
#include "nsStdURL.h"
@ -54,10 +72,10 @@ nsResURL::GetFile(nsIFile **result)
{
nsresult rv;
NS_ENSURE_TRUE(nsResProtocolHandler::get(), NS_ERROR_NOT_AVAILABLE);
NS_ENSURE_TRUE(gResHandler, NS_ERROR_NOT_AVAILABLE);
nsXPIDLCString spec;
rv = nsResProtocolHandler::get()->ResolveURI(this, getter_Copies(spec));
rv = gResHandler->ResolveURI(this, getter_Copies(spec));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsILocalFile> localFile =
@ -70,37 +88,26 @@ nsResURL::GetFile(nsIFile **result)
return CallQueryInterface(localFile, result);
}
////////////////////////////////////////////////////////////////////////////////
nsResProtocolHandler *nsResProtocolHandler::mGlobalInstance = nsnull;
//----------------------------------------------------------------------------
// nsResProtocolHandler <public>
//----------------------------------------------------------------------------
nsResProtocolHandler::nsResProtocolHandler()
: mSubstitutions(32)
{
NS_INIT_REFCNT();
NS_ASSERTION(!mGlobalInstance, "res handler already created!");
mGlobalInstance = this;
#if defined(PR_LOGGING)
gResLog = PR_NewLogModule("nsResProtocol");
#endif
NS_ASSERTION(!gResHandler, "res handler already created!");
gResHandler = this;
}
nsResProtocolHandler::~nsResProtocolHandler()
{
mGlobalInstance = nsnull;
}
nsresult
nsResProtocolHandler::SetSpecialDir(const char* rootName, const char* sysDir)
{
nsresult rv;
nsCOMPtr<nsIFile> file;
rv = NS_GetSpecialDirectory(sysDir, getter_AddRefs(file));
if (NS_FAILED(rv)) return rv;
nsXPIDLCString spec;
rv = file->GetURL(getter_Copies(spec));
if (NS_FAILED(rv)) return rv;
return AppendSubstitution(rootName, spec);
gResHandler = nsnull;
}
nsresult
@ -112,26 +119,26 @@ nsResProtocolHandler::Init()
if (NS_FAILED(rv)) return rv;
// set up initial mappings
rv = SetSpecialDir("ProgramDir", NS_OS_CURRENT_PROCESS_DIR);
rv = SetSpecialDir("programdir", NS_OS_CURRENT_PROCESS_DIR);
if (NS_FAILED(rv)) return rv;
// make "res:///" == "resource:/"
rv = SetSpecialDir("", NS_XPCOM_CURRENT_PROCESS_DIR);
if (NS_FAILED(rv)) return rv;
rv = SetSpecialDir("CurrentDir", NS_OS_CURRENT_WORKING_DIR);
rv = SetSpecialDir("currentdir", NS_OS_CURRENT_WORKING_DIR);
if (NS_FAILED(rv)) return rv;
rv = SetSpecialDir("CurrentDrive", NS_OS_DRIVE_DIR);
rv = SetSpecialDir("currentdrive", NS_OS_DRIVE_DIR);
if (NS_FAILED(rv)) return rv;
rv = SetSpecialDir("TempDir", NS_OS_TEMP_DIR);
rv = SetSpecialDir("tempdir", NS_OS_TEMP_DIR);
if (NS_FAILED(rv)) return rv;
rv = SetSpecialDir("ComponentsDir", NS_XPCOM_COMPONENT_DIR);
rv = SetSpecialDir("componentsdir", NS_XPCOM_COMPONENT_DIR);
if (NS_FAILED(rv)) return rv;
rv = SetSpecialDir("SystemDir",
rv = SetSpecialDir("systemdir",
#ifdef XP_MAC
NS_OS_SYSTEM_DIR
#elif XP_OS2
@ -149,38 +156,55 @@ nsResProtocolHandler::Init()
// Set up the "Resource" root to point to the old resource location
// such that:
// resource://<path> == res://Resource/<path>
rv = SetSpecialDir("Resource", NS_XPCOM_CURRENT_PROCESS_DIR);
rv = SetSpecialDir("resource", NS_XPCOM_CURRENT_PROCESS_DIR);
if (NS_FAILED(rv)) return rv;
return rv;
}
NS_IMPL_THREADSAFE_ISUPPORTS3(nsResProtocolHandler, nsIResProtocolHandler, nsIProtocolHandler, nsISupportsWeakReference)
//----------------------------------------------------------------------------
// nsResProtocolHandler <private>
//----------------------------------------------------------------------------
NS_METHOD
nsResProtocolHandler::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
nsresult
nsResProtocolHandler::SetSpecialDir(const char *root, const char *dir)
{
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
LOG(("nsResProtocolHandler::SetSpecialDir [root=\"%s\" dir=%s]\n", root, dir));
nsResProtocolHandler* ph = new nsResProtocolHandler();
if (ph == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(ph);
nsresult rv = ph->Init();
if (NS_SUCCEEDED(rv)) {
rv = ph->QueryInterface(aIID, aResult);
}
NS_RELEASE(ph);
return rv;
nsresult rv;
nsCOMPtr<nsIFile> file;
rv = NS_GetSpecialDirectory(dir, getter_AddRefs(file));
if (NS_FAILED(rv)) return rv;
nsXPIDLCString spec;
rv = file->GetURL(getter_Copies(spec));
if (NS_FAILED(rv)) return rv;
LOG(("root=\"%s\" -> baseURI=%s\n", root, spec.get()));
nsCOMPtr<nsIURI> uri;
mIOService->NewURI(spec, nsnull, getter_AddRefs(uri));
return SetSubstitution(root, uri);
}
////////////////////////////////////////////////////////////////////////////////
// nsIProtocolHandler methods:
//----------------------------------------------------------------------------
// nsResProtocolHandler::nsISupports
//----------------------------------------------------------------------------
NS_IMPL_THREADSAFE_ISUPPORTS3(nsResProtocolHandler,
nsIResProtocolHandler,
nsIProtocolHandler,
nsISupportsWeakReference)
//----------------------------------------------------------------------------
// nsResProtocolHandler::nsIProtocolHandler
//----------------------------------------------------------------------------
NS_IMETHODIMP
nsResProtocolHandler::GetScheme(char **result)
{
NS_ENSURE_ARG_POINTER(result);
*result = nsCRT::strdup("resource");
if (*result == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
@ -242,148 +266,41 @@ nsResProtocolHandler::AllowPort(PRInt32 port, const char *scheme, PRBool *_retva
*_retval = PR_FALSE;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------
// nsResProtocolHandler::nsIResProtocolHandler
//----------------------------------------------------------------------------
NS_IMETHODIMP
nsResProtocolHandler::PrependSubstitution(const char *root, const char *urlStr)
nsResProtocolHandler::SetSubstitution(const char *root, nsIURI *baseURI)
{
nsresult rv;
nsCOMPtr<nsIURI> url;
rv = mIOService->NewURI(urlStr, nsnull, getter_AddRefs(url));
if (NS_FAILED(rv)) return rv;
NS_ENSURE_ARG_POINTER(root);
nsCStringKey key(root);
nsCOMPtr<nsISupportsArray> strings;
nsCOMPtr<nsISupportsArray> newStrings;
strings = dont_AddRef(NS_STATIC_CAST(nsISupportsArray*,
mSubstitutions.Get(&key)));
if (strings) {
// we have to snapshot the array when inserting a new element because
// someone could be iterating over the existing array
rv = strings->Clone(getter_AddRefs(newStrings));
if (NS_FAILED(rv)) return rv;
}
else {
rv = NS_NewISupportsArray(getter_AddRefs(newStrings));
if (NS_FAILED(rv)) return rv;
}
rv = newStrings->InsertElementAt(url, 0) ? NS_OK : NS_ERROR_FAILURE;
if (NS_SUCCEEDED(rv)) {
// replace existing array
(void)mSubstitutions.Put(&key, newStrings);
}
return rv;
}
NS_IMETHODIMP
nsResProtocolHandler::AppendSubstitution(const char *root, const char *urlStr)
{
nsresult rv;
nsCOMPtr<nsIURI> url;
rv = mIOService->NewURI(urlStr, nsnull, getter_AddRefs(url));
if (NS_FAILED(rv)) return rv;
nsCStringKey key(root);
nsCOMPtr<nsISupportsArray> strings;
nsCOMPtr<nsISupportsArray> newStrings;
strings = getter_AddRefs((nsISupportsArray*)mSubstitutions.Get(&key));
if (strings) {
// we have to snapshot the array when inserting a new element because
// someone could be iterating over the existing array
rv = strings->Clone(getter_AddRefs(newStrings));
if (NS_FAILED(rv)) return rv;
}
else {
rv = NS_NewISupportsArray(getter_AddRefs(newStrings));
if (NS_FAILED(rv)) return rv;
}
rv = newStrings->AppendElement(url) ? NS_OK : NS_ERROR_FAILURE;
if (NS_SUCCEEDED(rv)) {
// replace existing array
(void)mSubstitutions.Put(&key, newStrings);
}
return rv;
}
struct CopyMostArgs {
nsISupportsArray* mNewArray;
nsIURI* mRemoveURL;
};
static PRBool
CopyMost(nsISupports* aElement, void *aData)
{
nsresult rv = NS_OK;
CopyMostArgs* args = (CopyMostArgs*)aData;
nsIURI* thisURL = (nsIURI*)aElement;
PRBool eq;
rv = thisURL->Equals(args->mRemoveURL, &eq);
if (NS_FAILED(rv)) return PR_FALSE;
if (!eq) {
rv = args->mNewArray->AppendElement(thisURL) ? NS_OK : NS_ERROR_FAILURE;
}
return NS_SUCCEEDED(rv);
}
NS_IMETHODIMP
nsResProtocolHandler::RemoveSubstitution(const char *root, const char *urlStr)
{
nsresult rv;
nsCOMPtr<nsIURI> url;
rv = mIOService->NewURI(urlStr, nsnull, getter_AddRefs(url));
if (NS_FAILED(rv)) return rv;
nsCStringKey key(root);
nsCOMPtr<nsISupportsArray> strings;
nsCOMPtr<nsISupportsArray> newStrings;
strings = getter_AddRefs((nsISupportsArray*)mSubstitutions.Get(&key));
if (strings == nsnull) {
// can't remove element if it doesn't exist
return NS_ERROR_FAILURE;
}
rv = NS_NewISupportsArray(getter_AddRefs(newStrings));
if (NS_FAILED(rv)) return rv;
CopyMostArgs args;
args.mNewArray = newStrings;
args.mRemoveURL = url;
PRBool ok = strings->EnumerateForwards(CopyMost, &args);
rv = ok ? NS_OK : NS_ERROR_FAILURE;
if (NS_SUCCEEDED(rv)) {
// replace existing array
(void)mSubstitutions.Put(&key, newStrings);
}
return rv;
}
NS_IMETHODIMP
nsResProtocolHandler::GetSubstitutions(const char *root, nsISupportsArray* *result)
{
nsresult rv;
nsCStringKey key(root);
nsISupportsArray* strings = (nsISupportsArray*)mSubstitutions.Get(&key);
if (strings == nsnull) {
rv = NS_NewISupportsArray(&strings);
if (NS_FAILED(rv)) return rv;
(void)mSubstitutions.Put(&key, strings);
}
*result = strings;
if (baseURI)
mSubstitutions.Put(&key, baseURI);
else
mSubstitutions.Remove(&key);
return NS_OK;
}
NS_IMETHODIMP
nsResProtocolHandler::HasSubstitutions(const char *root, PRBool *result)
nsResProtocolHandler::GetSubstitution(const char *root, nsIURI **result)
{
NS_ENSURE_ARG_POINTER(root);
NS_ENSURE_ARG_POINTER(result);
nsCStringKey key(root);
*result = NS_STATIC_CAST(nsIURI *, mSubstitutions.Get(&key));
return *result ? NS_OK : NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP
nsResProtocolHandler::HasSubstitution(const char *root, PRBool *result)
{
NS_ENSURE_ARG_POINTER(root);
NS_ENSURE_ARG_POINTER(result);
nsCStringKey key(root);
*result = mSubstitutions.Exists(&key);
return NS_OK;
@ -401,24 +318,19 @@ nsResProtocolHandler::ResolveURI(nsIURI *uri, char **result)
rv = uri->GetPath(getter_Copies(path));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsISupportsArray> substitutions;
rv = GetSubstitutions(host.get() ?
host.get() : "", getter_AddRefs(substitutions));
nsCOMPtr<nsIURI> baseURI;
rv = GetSubstitution(host.get() ? host.get() : "", getter_AddRefs(baseURI));
if (NS_FAILED(rv)) return rv;
// always use the first substitution
nsCOMPtr<nsIURI> substURI;
substitutions->GetElementAt(0, getter_AddRefs(substURI));
if (!substURI) return NS_ERROR_NOT_AVAILABLE;
const char *p = path.get(); // be nice to the AIX and OS/2 compilers
rv = baseURI->Resolve(p[0] == '/' ? p+1 : p, result);
const char *p = path.get(); // be nice to the AIX and OS/2 compiler
rv = substURI->Resolve(p[0] == '/' ? p+1 : p, result);
#if 0
#if defined(PR_LOGGING)
if (PR_LOG_TEST(gResLog, PR_LOG_DEBUG)) {
nsXPIDLCString spec;
uri->GetSpec(getter_Copies(spec));
printf("%s\n -> %s\n", spec.get(), *result);
LOG(("%s\n -> %s\n", spec.get(), *result));
}
#endif
return rv;
}
////////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -37,20 +37,13 @@ public:
NS_DECL_NSIPROTOCOLHANDLER
NS_DECL_NSIRESPROTOCOLHANDLER
// nsResProtocolHandler methods:
nsResProtocolHandler();
virtual ~nsResProtocolHandler();
static NS_METHOD
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
nsresult Init();
nsresult SetSpecialDir(const char* rootName, const char* specialDir);
static nsResProtocolHandler *get() { return mGlobalInstance; }
private:
static nsResProtocolHandler *mGlobalInstance;
nsresult SetSpecialDir(const char* rootName, const char* specialDir);
nsSupportsHashtable mSubstitutions;
nsCOMPtr<nsIIOService> mIOService;

Просмотреть файл

@ -43,7 +43,6 @@
#include "nsIJARURI.h"
#include "nsILoadGroup.h"
#include "nsIObjectOutputStream.h"
#include "nsIResChannel.h"
#include "nsIScriptSecurityManager.h"
#include "nsIServiceManager.h"
#include "nsIStreamListener.h"
@ -617,15 +616,11 @@ nsChromeProtocolHandler::NewChannel(nsIURI* aURI,
// XXX Will be removed someday when we handle remote chrome.
nsCOMPtr<nsIFileChannel> fileChan;
nsCOMPtr<nsIResChannel> resChan;
nsCOMPtr<nsIJARChannel> jarChan;
fileChan = do_QueryInterface(result);
if (!fileChan) {
resChan = do_QueryInterface(result);
if (!resChan)
if (!fileChan)
jarChan = do_QueryInterface(result);
}
if (!fileChan && !resChan && !jarChan) {
if (!fileChan && !jarChan) {
NS_WARNING("Remote chrome not allowed! Only file:, resource:, and jar: are valid.\n");
result = nsnull;
return NS_ERROR_FAILURE;