2004-07-16 00:20:50 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2004-10-03 21:06:57 +04:00
|
|
|
* vim:set ts=2 sts=2 sw=2 et cin:
|
2001-02-07 04:21:58 +03:00
|
|
|
*
|
2004-04-17 20:52:41 +04:00
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2001-02-07 04:21:58 +03:00
|
|
|
*
|
2004-04-17 20:52:41 +04:00
|
|
|
* 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
|
2001-02-07 04:21:58 +03:00
|
|
|
* for the specific language governing rights and limitations under the
|
2004-04-17 20:52:41 +04:00
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org Code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Scott MacGregor <mscott@netscape.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of 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 ***** */
|
2001-02-07 04:21:58 +03:00
|
|
|
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsExternalProtocolHandler.h"
|
|
|
|
#include "nsXPIDLString.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2001-02-07 04:21:58 +03:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2004-11-25 01:48:45 +03:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2004-09-11 03:24:49 +04:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2004-10-03 21:06:57 +04:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2004-09-11 03:24:49 +04:00
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "nsIPrompt.h"
|
2004-11-15 23:16:52 +03:00
|
|
|
#include "nsNetUtil.h"
|
2001-02-07 04:21:58 +03:00
|
|
|
|
|
|
|
// used to dispatch urls to default protocol handlers
|
|
|
|
#include "nsCExternalHandlerService.h"
|
|
|
|
#include "nsIExternalProtocolService.h"
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// a stub channel implemenation which will map calls to AsyncRead and OpenInputStream
|
|
|
|
// to calls in the OS for loading the url.
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class nsExtProtocolChannel : public nsIChannel
|
|
|
|
{
|
2007-05-25 19:17:45 +04:00
|
|
|
public:
|
2007-03-23 02:01:14 +03:00
|
|
|
|
2002-11-20 03:44:26 +03:00
|
|
|
NS_DECL_ISUPPORTS
|
2001-02-07 04:21:58 +03:00
|
|
|
NS_DECL_NSICHANNEL
|
|
|
|
NS_DECL_NSIREQUEST
|
2004-09-11 03:24:49 +04:00
|
|
|
|
2001-02-07 04:21:58 +03:00
|
|
|
nsExtProtocolChannel();
|
2002-11-20 03:44:26 +03:00
|
|
|
virtual ~nsExtProtocolChannel();
|
2001-02-07 04:21:58 +03:00
|
|
|
|
2001-04-10 10:01:08 +04:00
|
|
|
nsresult SetURI(nsIURI*);
|
|
|
|
|
2004-10-25 11:46:01 +04:00
|
|
|
private:
|
2004-09-11 03:24:49 +04:00
|
|
|
nsresult OpenURL();
|
2007-03-23 02:01:14 +03:00
|
|
|
|
2004-09-11 03:24:49 +04:00
|
|
|
nsCOMPtr<nsIURI> mUrl;
|
|
|
|
nsCOMPtr<nsIURI> mOriginalURI;
|
|
|
|
nsresult mStatus;
|
2007-03-23 02:01:14 +03:00
|
|
|
|
2004-09-11 03:24:49 +04:00
|
|
|
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
|
2004-11-15 23:16:52 +03:00
|
|
|
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
2001-02-07 04:21:58 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_THREADSAFE_ADDREF(nsExtProtocolChannel)
|
|
|
|
NS_IMPL_THREADSAFE_RELEASE(nsExtProtocolChannel)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsExtProtocolChannel)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIChannel)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIChannel)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIRequest)
|
|
|
|
NS_INTERFACE_MAP_END_THREADSAFE
|
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
nsExtProtocolChannel::nsExtProtocolChannel() : mStatus(NS_OK)
|
2001-02-07 04:21:58 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsExtProtocolChannel::~nsExtProtocolChannel()
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetLoadGroup(nsILoadGroup * *aLoadGroup)
|
|
|
|
{
|
2004-11-15 23:16:52 +03:00
|
|
|
NS_IF_ADDREF(*aLoadGroup = mLoadGroup);
|
|
|
|
return NS_OK;
|
2001-02-07 04:21:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::SetLoadGroup(nsILoadGroup * aLoadGroup)
|
|
|
|
{
|
2004-11-15 23:16:52 +03:00
|
|
|
mLoadGroup = aLoadGroup;
|
2004-09-11 03:24:49 +04:00
|
|
|
return NS_OK;
|
2001-02-07 04:21:58 +03:00
|
|
|
}
|
|
|
|
|
2004-11-15 23:16:52 +03:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetNotificationCallbacks(nsIInterfaceRequestor* *aCallbacks)
|
2001-02-07 04:21:58 +03:00
|
|
|
{
|
2004-11-15 23:16:52 +03:00
|
|
|
NS_IF_ADDREF(*aCallbacks = mCallbacks);
|
2001-02-07 04:21:58 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-11-15 23:16:52 +03:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aCallbacks)
|
2001-02-07 04:21:58 +03:00
|
|
|
{
|
2004-11-15 23:16:52 +03:00
|
|
|
mCallbacks = aCallbacks;
|
2004-10-03 21:06:57 +04:00
|
|
|
return NS_OK;
|
2001-02-07 04:21:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExtProtocolChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
|
|
|
|
{
|
|
|
|
*aSecurityInfo = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetOriginalURI(nsIURI* *aURI)
|
|
|
|
{
|
2004-07-16 00:20:50 +04:00
|
|
|
NS_IF_ADDREF(*aURI = mOriginalURI);
|
2001-02-07 04:21:58 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::SetOriginalURI(nsIURI* aURI)
|
|
|
|
{
|
2004-07-16 00:20:50 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
|
|
|
mOriginalURI = aURI;
|
2001-02-07 04:21:58 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetURI(nsIURI* *aURI)
|
|
|
|
{
|
|
|
|
*aURI = mUrl;
|
|
|
|
NS_IF_ADDREF(*aURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-10 11:10:30 +04:00
|
|
|
nsresult nsExtProtocolChannel::SetURI(nsIURI* aURI)
|
2001-02-07 04:21:58 +03:00
|
|
|
{
|
|
|
|
mUrl = aURI;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-23 02:01:14 +03:00
|
|
|
|
2001-02-07 04:21:58 +03:00
|
|
|
nsresult nsExtProtocolChannel::OpenURL()
|
|
|
|
{
|
2005-08-13 02:53:22 +04:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2001-02-07 04:21:58 +03:00
|
|
|
nsCOMPtr<nsIExternalProtocolService> extProtService (do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID));
|
|
|
|
|
|
|
|
if (extProtService)
|
|
|
|
{
|
2002-11-20 03:44:26 +03:00
|
|
|
#ifdef DEBUG
|
2004-10-25 11:46:01 +04:00
|
|
|
nsCAutoString urlScheme;
|
|
|
|
mUrl->GetScheme(urlScheme);
|
2002-11-20 03:44:26 +03:00
|
|
|
PRBool haveHandler = PR_FALSE;
|
2002-03-06 10:48:55 +03:00
|
|
|
extProtService->ExternalProtocolHandlerExists(urlScheme.get(), &haveHandler);
|
2002-11-20 03:44:26 +03:00
|
|
|
NS_ASSERTION(haveHandler, "Why do we have a channel for this url if we don't support the protocol?");
|
|
|
|
#endif
|
2004-09-11 03:24:49 +04:00
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
// get an nsIPrompt from the channel if we can
|
|
|
|
nsCOMPtr<nsIPrompt> prompt;
|
|
|
|
NS_QueryNotificationCallbacks(mCallbacks, mLoadGroup, prompt);
|
|
|
|
rv = extProtService->LoadURI(mUrl, prompt);
|
2001-02-07 04:21:58 +03:00
|
|
|
}
|
2005-08-13 02:53:22 +04:00
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
// Drop notification callbacks to prevent cycles.
|
2005-08-13 02:53:22 +04:00
|
|
|
mCallbacks = 0;
|
2007-03-23 02:01:14 +03:00
|
|
|
|
2005-08-13 02:53:22 +04:00
|
|
|
return rv;
|
2001-02-07 04:21:58 +03:00
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::Open(nsIInputStream **_retval)
|
2001-02-07 04:21:58 +03:00
|
|
|
{
|
2007-03-23 02:01:14 +03:00
|
|
|
OpenURL();
|
|
|
|
return NS_ERROR_NO_CONTENT; // force caller to abort.
|
2001-02-07 04:21:58 +03:00
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt)
|
2001-02-07 04:21:58 +03:00
|
|
|
{
|
2007-03-23 02:01:14 +03:00
|
|
|
OpenURL();
|
|
|
|
return NS_ERROR_NO_CONTENT; // force caller to abort.
|
2007-07-05 23:31:46 +04:00
|
|
|
}
|
|
|
|
|
2001-04-10 10:01:08 +04:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetLoadFlags(nsLoadFlags *aLoadFlags)
|
2001-02-07 04:21:58 +03:00
|
|
|
{
|
2007-03-23 02:01:14 +03:00
|
|
|
*aLoadFlags = 0;
|
2004-09-11 03:24:49 +04:00
|
|
|
return NS_OK;
|
2001-02-07 04:21:58 +03:00
|
|
|
}
|
|
|
|
|
2001-04-10 10:01:08 +04:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::SetLoadFlags(nsLoadFlags aLoadFlags)
|
2001-02-07 04:21:58 +03:00
|
|
|
{
|
2004-09-11 03:24:49 +04:00
|
|
|
return NS_OK;
|
2001-02-07 04:21:58 +03:00
|
|
|
}
|
|
|
|
|
2002-03-21 01:50:33 +03:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetContentType(nsACString &aContentType)
|
2001-02-07 04:21:58 +03:00
|
|
|
{
|
2004-09-11 03:24:49 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2001-02-07 04:21:58 +03:00
|
|
|
}
|
|
|
|
|
2002-03-21 01:50:33 +03:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::SetContentType(const nsACString &aContentType)
|
2001-02-07 04:21:58 +03:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2002-03-21 01:50:33 +03:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetContentCharset(nsACString &aContentCharset)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::SetContentCharset(const nsACString &aContentCharset)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2001-02-07 04:21:58 +03:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetContentLength(PRInt32 * aContentLength)
|
|
|
|
{
|
|
|
|
*aContentLength = -1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExtProtocolChannel::SetContentLength(PRInt32 aContentLength)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("SetContentLength");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetOwner(nsISupports * *aPrincipal)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("GetOwner");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::SetOwner(nsISupports * aPrincipal)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("SetOwner");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// From nsIRequest
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2002-03-21 01:50:33 +03:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetName(nsACString &result)
|
2001-02-07 04:21:58 +03:00
|
|
|
{
|
2007-03-23 02:01:14 +03:00
|
|
|
NS_NOTREACHED("nsExtProtocolChannel::GetName");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2001-02-07 04:21:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::IsPending(PRBool *result)
|
|
|
|
{
|
2007-03-23 02:01:14 +03:00
|
|
|
*result = PR_TRUE;
|
2001-02-07 04:21:58 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetStatus(nsresult *status)
|
|
|
|
{
|
|
|
|
*status = mStatus;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::Cancel(nsresult status)
|
|
|
|
{
|
|
|
|
mStatus = status;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::Suspend()
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Suspend");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::Resume()
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Resume");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// the default protocol handler implementation
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsExternalProtocolHandler::nsExternalProtocolHandler()
|
|
|
|
{
|
2004-09-11 03:24:49 +04:00
|
|
|
m_schemeName = "default";
|
2007-03-23 02:01:14 +03:00
|
|
|
m_extProtService = do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID);
|
2001-02-07 04:21:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsExternalProtocolHandler::~nsExternalProtocolHandler()
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMPL_THREADSAFE_ADDREF(nsExternalProtocolHandler)
|
|
|
|
NS_IMPL_THREADSAFE_RELEASE(nsExternalProtocolHandler)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsExternalProtocolHandler)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIProtocolHandler)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIProtocolHandler)
|
2003-02-28 01:46:42 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIExternalProtocolHandler)
|
2001-02-07 04:21:58 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
|
|
NS_INTERFACE_MAP_END_THREADSAFE
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
NS_IMETHODIMP nsExternalProtocolHandler::GetScheme(nsACString &aScheme)
|
2001-02-07 04:21:58 +03:00
|
|
|
{
|
2004-09-11 03:24:49 +04:00
|
|
|
aScheme = m_schemeName;
|
|
|
|
return NS_OK;
|
2001-02-07 04:21:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExternalProtocolHandler::GetDefaultPort(PRInt32 *aDefaultPort)
|
|
|
|
{
|
2004-09-11 03:24:49 +04:00
|
|
|
*aDefaultPort = 0;
|
2001-02-07 04:21:58 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-06-06 04:10:09 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExternalProtocolHandler::AllowPort(PRInt32 port, const char *scheme, PRBool *_retval)
|
|
|
|
{
|
|
|
|
// don't override anything.
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-02-07 08:24:27 +03:00
|
|
|
// returns TRUE if the OS can handle this protocol scheme and false otherwise.
|
2007-03-23 02:01:14 +03:00
|
|
|
PRBool nsExternalProtocolHandler::HaveProtocolHandler(nsIURI * aURI)
|
2001-02-07 08:24:27 +03:00
|
|
|
{
|
|
|
|
PRBool haveHandler = PR_FALSE;
|
|
|
|
if (aURI)
|
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCAutoString scheme;
|
|
|
|
aURI->GetScheme(scheme);
|
2007-03-23 02:01:14 +03:00
|
|
|
if (m_extProtService)
|
|
|
|
m_extProtService->ExternalProtocolHandlerExists(scheme.get(), &haveHandler);
|
2001-02-07 08:24:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return haveHandler;
|
|
|
|
}
|
|
|
|
|
2001-09-13 06:21:05 +04:00
|
|
|
NS_IMETHODIMP nsExternalProtocolHandler::GetProtocolFlags(PRUint32 *aUritype)
|
2001-08-08 00:42:57 +04:00
|
|
|
{
|
|
|
|
// Make it norelative since it is a simple uri
|
2007-04-15 16:31:18 +04:00
|
|
|
*aUritype = URI_NORELATIVE | URI_NOAUTH | URI_LOADABLE_BY_ANYONE |
|
|
|
|
URI_NON_PERSISTABLE;
|
2001-08-08 00:42:57 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
NS_IMETHODIMP nsExternalProtocolHandler::NewURI(const nsACString &aSpec,
|
|
|
|
const char *aCharset, // ignore charset info
|
|
|
|
nsIURI *aBaseURI,
|
|
|
|
nsIURI **_retval)
|
2001-02-07 04:21:58 +03:00
|
|
|
{
|
2002-11-20 03:44:26 +03:00
|
|
|
nsresult rv;
|
2006-06-19 01:18:22 +04:00
|
|
|
nsCOMPtr<nsIURI> uri = do_CreateInstance(NS_SIMPLEURI_CONTRACTID, &rv);
|
2002-11-20 03:44:26 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2003-01-08 23:32:14 +03:00
|
|
|
rv = uri->SetSpec(aSpec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-11-20 03:44:26 +03:00
|
|
|
NS_ADDREF(*_retval = uri);
|
|
|
|
return NS_OK;
|
2001-02-07 04:21:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExternalProtocolHandler::NewChannel(nsIURI *aURI, nsIChannel **_retval)
|
|
|
|
{
|
2007-03-23 02:01:14 +03:00
|
|
|
// only try to return a channel if we have a protocol handler for the url
|
|
|
|
|
|
|
|
PRBool haveHandler = HaveProtocolHandler(aURI);
|
|
|
|
if (haveHandler)
|
2001-02-07 04:21:58 +03:00
|
|
|
{
|
2001-02-07 08:24:27 +03:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
NS_NEWXPCOM(channel, nsExtProtocolChannel);
|
|
|
|
if (!channel) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2001-04-10 10:01:08 +04:00
|
|
|
((nsExtProtocolChannel*) channel.get())->SetURI(aURI);
|
2004-07-16 00:20:50 +04:00
|
|
|
channel->SetOriginalURI(aURI);
|
2001-02-07 08:24:27 +03:00
|
|
|
|
|
|
|
if (_retval)
|
|
|
|
{
|
|
|
|
*_retval = channel;
|
|
|
|
NS_IF_ADDREF(*_retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-02-07 04:21:58 +03:00
|
|
|
}
|
|
|
|
|
2001-02-07 08:24:27 +03:00
|
|
|
return NS_ERROR_UNKNOWN_PROTOCOL;
|
2001-02-07 04:21:58 +03:00
|
|
|
}
|
2003-02-28 01:46:42 +03:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// External protocol handler interface implementation
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
NS_IMETHODIMP nsExternalProtocolHandler::ExternalAppExistsForScheme(const nsACString& aScheme, PRBool *_retval)
|
|
|
|
{
|
2007-03-23 02:01:14 +03:00
|
|
|
if (m_extProtService)
|
|
|
|
return m_extProtService->ExternalProtocolHandlerExists(PromiseFlatCString(aScheme).get(), _retval);
|
2003-02-28 01:46:42 +03:00
|
|
|
|
|
|
|
// In case we don't have external protocol service.
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-23 02:01:14 +03:00
|
|
|
|
|
|
|
nsBlockedExternalProtocolHandler::nsBlockedExternalProtocolHandler()
|
|
|
|
{
|
|
|
|
m_schemeName = "default-blocked";
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBlockedExternalProtocolHandler::NewChannel(nsIURI *aURI,
|
|
|
|
nsIChannel **_retval)
|
|
|
|
{
|
|
|
|
*_retval = nsnull;
|
|
|
|
return NS_ERROR_UNKNOWN_PROTOCOL;
|
|
|
|
}
|