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>
|
2007-05-25 19:17:45 +04:00
|
|
|
* Dan Mosedale <dmose@mozilla.org>
|
2004-04-17 20:52:41 +04:00
|
|
|
*
|
|
|
|
* 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"
|
2007-05-25 19:17:45 +04:00
|
|
|
#include "nsIChannelEventSink.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsEscape.h"
|
|
|
|
#include "nsExternalHelperAppService.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
|
|
|
friend class nsWebProtocolRedirect;
|
2001-02-07 04:21:58 +03:00
|
|
|
|
2007-05-25 19:17:45 +04:00
|
|
|
public:
|
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();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> mUrl;
|
|
|
|
nsCOMPtr<nsIURI> mOriginalURI;
|
|
|
|
nsresult mStatus;
|
2007-05-25 19:17:45 +04:00
|
|
|
nsLoadFlags mLoadFlags;
|
2001-02-07 04:21:58 +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
|
|
|
|
|
|
|
|
nsExtProtocolChannel::nsExtProtocolChannel() : mStatus(NS_OK)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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-05-25 19:17:45 +04: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
|
|
|
|
2004-10-25 11:46:01 +04:00
|
|
|
// get an nsIPrompt from the channel if we can
|
|
|
|
nsCOMPtr<nsIPrompt> prompt;
|
2004-11-15 23:16:52 +03:00
|
|
|
NS_QueryNotificationCallbacks(mCallbacks, mLoadGroup, prompt);
|
2005-08-13 02:53:22 +04:00
|
|
|
rv = extProtService->LoadURI(mUrl, prompt);
|
2001-02-07 04:21:58 +03:00
|
|
|
}
|
2005-08-13 02:53:22 +04:00
|
|
|
|
|
|
|
// Drop notification callbacks to prevent cycles.
|
|
|
|
mCallbacks = 0;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2004-07-30 03:58:59 +04:00
|
|
|
OpenURL();
|
|
|
|
return NS_ERROR_NO_CONTENT; // force caller to abort.
|
2001-02-07 04:21:58 +03:00
|
|
|
}
|
|
|
|
|
2007-05-25 19:17:45 +04:00
|
|
|
class nsWebProtocolRedirect : public nsRunnable {
|
|
|
|
public:
|
|
|
|
nsWebProtocolRedirect(nsIURI *aURI, const nsACString & aUriTemplate,
|
|
|
|
nsIStreamListener *aListener, nsISupports *aContext,
|
|
|
|
nsExtProtocolChannel *aOriginalChannel)
|
|
|
|
: mURI(aURI), mUriTemplate(aUriTemplate), mListener(aListener),
|
|
|
|
mContext(aContext), mOriginalChannel(aOriginalChannel) {}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
// get the URI spec so we can escape it for insertion into the template
|
|
|
|
nsCAutoString uriSpecToHandle;
|
|
|
|
nsresult rv = mURI->GetSpec(uriSpecToHandle);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
AbandonOriginalChannel(rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX need to strip passwd & username from URI to handle, as per the
|
|
|
|
// WhatWG HTML5 draft. nsSimpleURL, which is what we're going to get,
|
|
|
|
// can't do this directly. Ideally, we'd fix nsStandardURL to make it
|
|
|
|
// possible to turn off all of its quirks handling, and use that...
|
|
|
|
|
|
|
|
// XXX this doesn't exactly match how the HTML5 draft is requesting us to
|
|
|
|
// escape; at the very least, it should be escaping @ signs, and there
|
|
|
|
// may well be more issues. However, this code will probably be thrown
|
|
|
|
// out when we do the front-end work, as we'll be using a refactored
|
|
|
|
// nsIWebContentConverterInfo to do this work for us
|
|
|
|
nsCAutoString escapedUriSpecToHandle;
|
|
|
|
NS_EscapeURL(uriSpecToHandle, esc_Minimal | esc_Forced | esc_Colon,
|
|
|
|
escapedUriSpecToHandle);
|
|
|
|
|
|
|
|
// Note that this replace all occurrences of %s with the URL to be
|
|
|
|
// handled. The HTML5 draft doesn't prohibit %s from occurring more than
|
|
|
|
// once, and if it does, I can't think of any problems that could
|
|
|
|
// cause, (though I don't know why anyone would need or want to do it).
|
|
|
|
mUriTemplate.ReplaceSubstring(NS_LITERAL_CSTRING("%s"),
|
|
|
|
escapedUriSpecToHandle);
|
|
|
|
|
|
|
|
// convert spec to URI; no original charset needed since there's no way
|
|
|
|
// to communicate that information to any handler
|
|
|
|
nsCOMPtr<nsIURI> uriToSend;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uriToSend), mUriTemplate);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
AbandonOriginalChannel(rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create a channel
|
|
|
|
nsCOMPtr<nsIChannel> newChannel;
|
|
|
|
rv = NS_NewChannel(getter_AddRefs(newChannel), uriToSend, nsnull,
|
|
|
|
mOriginalChannel->mLoadGroup,
|
|
|
|
mOriginalChannel->mCallbacks,
|
|
|
|
mOriginalChannel->mLoadFlags);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
AbandonOriginalChannel(rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIChannelEventSink> eventSink;
|
|
|
|
NS_QueryNotificationCallbacks(mOriginalChannel->mCallbacks,
|
|
|
|
mOriginalChannel->mLoadGroup, eventSink);
|
|
|
|
|
|
|
|
if (eventSink) {
|
|
|
|
// XXX decide on and audit for correct session & global hist behavior
|
|
|
|
rv = eventSink->OnChannelRedirect(mOriginalChannel, newChannel,
|
|
|
|
nsIChannelEventSink::REDIRECT_TEMPORARY |
|
|
|
|
nsIChannelEventSink::REDIRECT_INTERNAL);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
AbandonOriginalChannel(rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = newChannel->AsyncOpen(mListener, mContext);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
AbandonOriginalChannel(rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mOriginalChannel->mStatus = NS_BINDING_REDIRECTED;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIURI> mURI;
|
|
|
|
nsCString mUriTemplate;
|
|
|
|
nsCOMPtr<nsIStreamListener> mListener;
|
|
|
|
nsCOMPtr<nsISupports> mContext;
|
|
|
|
nsCOMPtr<nsExtProtocolChannel> mOriginalChannel;
|
|
|
|
|
|
|
|
// necko guarantees that after an AsyncOpen has succeeded, OnStartRequest
|
|
|
|
// and OnStopRequest will get called
|
|
|
|
void AbandonOriginalChannel(const nsresult aStatus)
|
|
|
|
{
|
|
|
|
mOriginalChannel->mStatus = aStatus;
|
|
|
|
(void)mListener->OnStartRequest(mOriginalChannel, mContext);
|
|
|
|
(void)mListener->OnStopRequest(mOriginalChannel, mContext, aStatus);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
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-05-25 19:17:45 +04:00
|
|
|
// check whether the scheme is one that we have a web handler for
|
|
|
|
nsCAutoString urlScheme;
|
|
|
|
nsresult rv = mUrl->GetScheme(urlScheme);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIExternalProtocolService> extProtService =
|
|
|
|
do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCAutoString uriTemplate;
|
|
|
|
rv = nsExternalHelperAppService::GetWebProtocolHandlerURITemplate(urlScheme,
|
|
|
|
uriTemplate);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
|
|
|
|
// redirecting to the web handler involvegs calling OnChannelRedirect,
|
|
|
|
// which is supposed to happen after AsyncOpen completes, so we do it in an
|
|
|
|
// event
|
|
|
|
nsCOMPtr<nsIRunnable> event = new nsWebProtocolRedirect(mUrl, uriTemplate,
|
|
|
|
listener, ctxt,
|
|
|
|
this);
|
2007-06-12 22:31:54 +04:00
|
|
|
// We don't check if |event| was successfully created because
|
|
|
|
// |NS_DispatchToCurrentThread| will do that for us.
|
2007-05-25 19:17:45 +04:00
|
|
|
rv = NS_DispatchToCurrentThread(event);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// try for an OS-provided handler
|
2004-10-25 11:46:01 +04:00
|
|
|
OpenURL();
|
2004-07-30 03:58:59 +04:00
|
|
|
return NS_ERROR_NO_CONTENT; // force caller to abort.
|
2001-02-07 04:21:58 +03:00
|
|
|
}
|
|
|
|
|
2001-04-10 10:01:08 +04:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetLoadFlags(nsLoadFlags *aLoadFlags)
|
2001-02-07 04:21:58 +03:00
|
|
|
{
|
2007-05-25 19:17:45 +04:00
|
|
|
*aLoadFlags = mLoadFlags;
|
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
|
|
|
{
|
2007-05-25 19:17:45 +04:00
|
|
|
mLoadFlags = aLoadFlags;
|
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-05-25 19:17:45 +04:00
|
|
|
return mUrl->GetSpec(result);
|
2001-02-07 04:21:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::IsPending(PRBool *result)
|
|
|
|
{
|
|
|
|
*result = PR_TRUE;
|
|
|
|
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";
|
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-06-16 01:43:51 +04:00
|
|
|
PRBool nsExternalProtocolHandler::HaveExternalProtocolHandler(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-05-25 19:17:45 +04:00
|
|
|
if (gExtProtSvc)
|
2007-06-16 01:43:51 +04:00
|
|
|
gExtProtSvc->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)
|
|
|
|
{
|
2001-02-07 08:24:27 +03:00
|
|
|
// only try to return a channel if we have a protocol handler for the url
|
2001-02-07 04:21:58 +03:00
|
|
|
|
2007-06-16 01:43:51 +04:00
|
|
|
PRBool haveExternalHandler = HaveExternalProtocolHandler(aURI);
|
|
|
|
if (haveExternalHandler)
|
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-05-25 19:17:45 +04:00
|
|
|
if (gExtProtSvc)
|
|
|
|
return gExtProtSvc->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;
|
|
|
|
}
|
2004-05-21 04:28:52 +04:00
|
|
|
|
|
|
|
nsBlockedExternalProtocolHandler::nsBlockedExternalProtocolHandler()
|
|
|
|
{
|
|
|
|
m_schemeName = "default-blocked";
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBlockedExternalProtocolHandler::NewChannel(nsIURI *aURI,
|
|
|
|
nsIChannel **_retval)
|
|
|
|
{
|
|
|
|
*_retval = nsnull;
|
|
|
|
return NS_ERROR_UNKNOWN_PROTOCOL;
|
|
|
|
}
|