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-07-05 23:31:46 +04:00
|
|
|
friend class nsProtocolRedirect;
|
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();
|
2007-07-05 23:31:46 +04:00
|
|
|
void Finish(nsresult aResult);
|
|
|
|
|
2004-09-11 03:24:49 +04:00
|
|
|
nsCOMPtr<nsIURI> mUrl;
|
|
|
|
nsCOMPtr<nsIURI> mOriginalURI;
|
|
|
|
nsresult mStatus;
|
2007-05-25 19:17:45 +04:00
|
|
|
nsLoadFlags mLoadFlags;
|
2007-07-05 23:31:46 +04:00
|
|
|
PRBool mIsPending;
|
|
|
|
PRBool mWasOpened;
|
|
|
|
|
2004-09-11 03:24:49 +04:00
|
|
|
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
|
2004-11-15 23:16:52 +03:00
|
|
|
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
2007-07-05 23:31:46 +04:00
|
|
|
nsCOMPtr<nsIStreamListener> mListener;
|
|
|
|
nsCOMPtr<nsISupports> mContext;
|
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-07-05 23:31:46 +04:00
|
|
|
nsExtProtocolChannel::nsExtProtocolChannel() : mStatus(NS_OK),
|
|
|
|
mIsPending(PR_FALSE),
|
|
|
|
mWasOpened(PR_FALSE)
|
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-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
|
|
|
|
2007-07-26 10:44:43 +04:00
|
|
|
rv = extProtService->LoadURI(mUrl, mCallbacks);
|
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-07-05 23:31:46 +04:00
|
|
|
class nsProtocolRedirect : public nsRunnable {
|
2007-05-25 19:17:45 +04:00
|
|
|
public:
|
2007-07-05 23:31:46 +04:00
|
|
|
nsProtocolRedirect(nsIURI *aURI, nsIHandlerInfo *aHandlerInfo,
|
|
|
|
nsIStreamListener *aListener, nsISupports *aContext,
|
|
|
|
nsExtProtocolChannel *aOriginalChannel)
|
|
|
|
: mURI(aURI), mHandlerInfo(aHandlerInfo), mListener(aListener),
|
2007-05-25 19:17:45 +04:00
|
|
|
mContext(aContext), mOriginalChannel(aOriginalChannel) {}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
2007-07-05 23:31:46 +04:00
|
|
|
// for now, this code path is only take for a web-based protocol handler
|
|
|
|
nsCOMPtr<nsIHandlerApp> handlerApp;
|
|
|
|
nsresult rv =
|
|
|
|
mHandlerInfo->GetPreferredApplicationHandler(getter_AddRefs(handlerApp));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mOriginalChannel->Finish(rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebHandlerApp> webHandlerApp = do_QueryInterface(handlerApp,
|
|
|
|
&rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mOriginalChannel->Finish(rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCAutoString uriTemplate;
|
|
|
|
rv = webHandlerApp->GetUriTemplate(uriTemplate);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mOriginalChannel->Finish(rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-05-25 19:17:45 +04:00
|
|
|
// get the URI spec so we can escape it for insertion into the template
|
|
|
|
nsCAutoString uriSpecToHandle;
|
2007-07-05 23:31:46 +04:00
|
|
|
rv = mURI->GetSpec(uriSpecToHandle);
|
2007-05-25 19:17:45 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2007-07-05 23:31:46 +04:00
|
|
|
mOriginalChannel->Finish(rv);
|
2007-05-25 19:17:45 +04:00
|
|
|
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).
|
2007-07-05 23:31:46 +04:00
|
|
|
uriTemplate.ReplaceSubstring(NS_LITERAL_CSTRING("%s"),
|
|
|
|
escapedUriSpecToHandle);
|
|
|
|
|
2007-05-25 19:17:45 +04:00
|
|
|
// convert spec to URI; no original charset needed since there's no way
|
|
|
|
// to communicate that information to any handler
|
|
|
|
nsCOMPtr<nsIURI> uriToSend;
|
2007-07-05 23:31:46 +04:00
|
|
|
rv = NS_NewURI(getter_AddRefs(uriToSend), uriTemplate);
|
2007-05-25 19:17:45 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2007-07-05 23:31:46 +04:00
|
|
|
mOriginalChannel->Finish(rv);
|
2007-05-25 19:17:45 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create a channel
|
|
|
|
nsCOMPtr<nsIChannel> newChannel;
|
|
|
|
rv = NS_NewChannel(getter_AddRefs(newChannel), uriToSend, nsnull,
|
|
|
|
mOriginalChannel->mLoadGroup,
|
|
|
|
mOriginalChannel->mCallbacks,
|
2007-07-05 23:31:46 +04:00
|
|
|
mOriginalChannel->mLoadFlags
|
|
|
|
| nsIChannel::LOAD_REPLACE);
|
2007-05-25 19:17:45 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2007-07-05 23:31:46 +04:00
|
|
|
mOriginalChannel->Finish(rv);
|
2007-05-25 19:17:45 +04:00
|
|
|
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)) {
|
2007-07-05 23:31:46 +04:00
|
|
|
mOriginalChannel->Finish(rv);
|
2007-05-25 19:17:45 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = newChannel->AsyncOpen(mListener, mContext);
|
|
|
|
if (NS_FAILED(rv)) {
|
2007-07-05 23:31:46 +04:00
|
|
|
mOriginalChannel->Finish(rv);
|
2007-05-25 19:17:45 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-05 23:31:46 +04:00
|
|
|
mOriginalChannel->Finish(NS_BINDING_REDIRECTED);
|
2007-05-25 19:17:45 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIURI> mURI;
|
2007-07-05 23:31:46 +04:00
|
|
|
nsCOMPtr<nsIHandlerInfo> mHandlerInfo;
|
2007-05-25 19:17:45 +04:00
|
|
|
nsCOMPtr<nsIStreamListener> mListener;
|
|
|
|
nsCOMPtr<nsISupports> mContext;
|
|
|
|
nsCOMPtr<nsExtProtocolChannel> mOriginalChannel;
|
|
|
|
};
|
|
|
|
|
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-07-05 23:31:46 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(listener);
|
|
|
|
NS_ENSURE_TRUE(!mIsPending, NS_ERROR_IN_PROGRESS);
|
|
|
|
NS_ENSURE_TRUE(!mWasOpened, NS_ERROR_ALREADY_OPENED);
|
|
|
|
|
|
|
|
mWasOpened = PR_TRUE;
|
|
|
|
mListener = listener;
|
|
|
|
mContext = ctxt;
|
|
|
|
|
|
|
|
if (!gExtProtSvc) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2007-05-25 19:17:45 +04:00
|
|
|
nsCAutoString urlScheme;
|
|
|
|
nsresult rv = mUrl->GetScheme(urlScheme);
|
2007-07-05 23:31:46 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2007-05-25 19:17:45 +04:00
|
|
|
|
2007-07-05 23:31:46 +04:00
|
|
|
// check whether the scheme is one that we have a web handler for
|
|
|
|
nsCOMPtr<nsIHandlerInfo> handlerInfo;
|
|
|
|
rv = gExtProtSvc->GetProtocolHandlerInfo(urlScheme,
|
|
|
|
getter_AddRefs(handlerInfo));
|
2007-07-28 00:20:54 +04:00
|
|
|
// TODO all this code should be moved to nsIHandlerInfo::LaunchWithURI
|
2007-07-05 23:31:46 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
PRInt32 preferredAction;
|
|
|
|
rv = handlerInfo->GetPreferredAction(&preferredAction);
|
|
|
|
|
|
|
|
if (preferredAction == nsIHandlerInfo::useHelperApp) {
|
|
|
|
|
2007-07-28 00:20:54 +04:00
|
|
|
nsCOMPtr<nsIHandlerApp> handler;
|
|
|
|
rv = handlerInfo->GetPreferredApplicationHandler(getter_AddRefs(handler));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Now we check to see if this is a local handler or not
|
|
|
|
nsCOMPtr<nsILocalHandlerApp> localHandler =
|
|
|
|
do_QueryInterface(handler, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
OpenURL();
|
|
|
|
return NS_ERROR_NO_CONTENT; // force caller to abort
|
|
|
|
}
|
|
|
|
|
|
|
|
// We must have a web handler
|
2007-07-05 23:31:46 +04:00
|
|
|
// redirecting to the web handler involves calling OnChannelRedirect
|
|
|
|
// (which is supposed to happen after AsyncOpen completes) or possibly
|
|
|
|
// opening a dialog, so we do it in an event
|
|
|
|
nsCOMPtr<nsIRunnable> event = new nsProtocolRedirect(mUrl, handlerInfo,
|
|
|
|
listener, ctxt,
|
|
|
|
this);
|
|
|
|
|
|
|
|
// We don't check if |event| was successfully created because
|
|
|
|
// |NS_DispatchToCurrentThread| will do that for us.
|
|
|
|
rv = NS_DispatchToCurrentThread(event);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mIsPending = PR_TRUE;
|
|
|
|
|
|
|
|
// add ourselves to the load group, since this isn't going to finish
|
|
|
|
// immediately
|
|
|
|
if (mLoadGroup)
|
|
|
|
(void)mLoadGroup->AddRequest(this, nsnull);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2007-05-25 19:17:45 +04:00
|
|
|
}
|
|
|
|
}
|
2007-07-05 23:31:46 +04:00
|
|
|
|
|
|
|
// no protocol info found, just fall back on whatever the OS has to offer
|
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
|
|
|
}
|
|
|
|
|
2007-07-05 23:31:46 +04:00
|
|
|
/**
|
|
|
|
* Finish out what was started in AsyncOpen. This can be called in either the
|
|
|
|
* success or the failure case.
|
|
|
|
*
|
|
|
|
* @param aStatus used to set the channel's status, and, if this set to
|
|
|
|
* anything other than NS_BINDING_REDIRECTED, OnStartRequest
|
|
|
|
* and OnStopRequest will be called, since Necko guarantees
|
|
|
|
* this will happen unless the redirect took place.
|
|
|
|
*/
|
|
|
|
void nsExtProtocolChannel::Finish(nsresult aStatus)
|
|
|
|
{
|
|
|
|
mStatus = aStatus;
|
|
|
|
|
|
|
|
if (aStatus != NS_BINDING_REDIRECTED && mListener) {
|
|
|
|
(void)mListener->OnStartRequest(this, mContext);
|
|
|
|
(void)mListener->OnStopRequest(this, mContext, aStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
mIsPending = PR_FALSE;
|
|
|
|
|
|
|
|
if (mLoadGroup) {
|
|
|
|
(void)mLoadGroup->RemoveRequest(this, nsnull, aStatus);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2007-07-05 23:31:46 +04:00
|
|
|
*result = mIsPending;
|
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";
|
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 |
|
2007-07-25 21:21:42 +04:00
|
|
|
URI_NON_PERSISTABLE | URI_DOES_NOT_RETURN_DATA;
|
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-07-27 22:31:13 +04:00
|
|
|
// Only try to return a channel if we have a protocol handler for the url.
|
|
|
|
// nsOSHelperAppService::LoadUriInternal relies on this to check trustedness
|
|
|
|
// for some platforms at least. (win uses ::ShellExecute and unix uses
|
|
|
|
// gnome_url_show.)
|
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;
|
|
|
|
}
|