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
|
|
|
*
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
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:44 +04:00
|
|
|
#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:44 +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:44 +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:44 +04:00
|
|
|
nsLoadFlags mLoadFlags;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mWasOpened;
|
2007-07-05 23:31:44 +04: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-07-05 23:31:44 +04:00
|
|
|
nsExtProtocolChannel::nsExtProtocolChannel() : mStatus(NS_OK),
|
2011-10-17 18:59:28 +04:00
|
|
|
mWasOpened(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)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aSecurityInfo = nullptr;
|
2001-02-07 04:21:58 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetOriginalURI(nsIURI* *aURI)
|
|
|
|
{
|
2008-10-16 00:05:23 +04:00
|
|
|
NS_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:44 +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
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString urlScheme;
|
2004-10-25 11:46:01 +04:00
|
|
|
mUrl->GetScheme(urlScheme);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool haveHandler = 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-09-03 08:44:25 +04:00
|
|
|
nsCOMPtr<nsIInterfaceRequestor> aggCallbacks;
|
|
|
|
rv = NS_NewNotificationCallbacksAggregation(mCallbacks, mLoadGroup,
|
|
|
|
getter_AddRefs(aggCallbacks));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = extProtService->LoadURI(mUrl, aggCallbacks);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// despite success, we need to abort this channel, at the very least
|
|
|
|
// to make it clear to the caller that no on{Start,Stop}Request
|
|
|
|
// should be expected.
|
|
|
|
rv = NS_ERROR_NO_CONTENT;
|
|
|
|
}
|
2001-02-07 04:21:58 +03:00
|
|
|
}
|
2005-08-13 02:53:22 +04:00
|
|
|
|
2007-09-03 08:44:25 +04:00
|
|
|
finish:
|
2005-08-13 02:53:22 +04:00
|
|
|
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
|
|
|
{
|
2007-09-03 08:44:25 +04:00
|
|
|
return OpenURL();
|
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-07-05 23:31:44 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(listener);
|
|
|
|
NS_ENSURE_TRUE(!mWasOpened, NS_ERROR_ALREADY_OPENED);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mWasOpened = true;
|
2007-07-05 23:31:44 +04:00
|
|
|
|
2007-09-03 08:44:25 +04:00
|
|
|
return OpenURL();
|
2007-07-05 23:31:44 +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-05-25 19:17:44 +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:44 +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;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetContentDisposition(uint32_t *aContentDisposition)
|
2011-09-10 02:41:04 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2012-10-02 20:43:00 +04:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::SetContentDisposition(uint32_t aContentDisposition)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2011-09-10 02:41:04 +04:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetContentDispositionFilename(nsAString &aContentDispositionFilename)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2012-10-02 20:43:00 +04:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::SetContentDispositionFilename(const nsAString &aContentDispositionFilename)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2011-09-10 02:41:04 +04:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetContentDispositionHeader(nsACString &aContentDispositionHeader)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2012-10-22 21:51:07 +04:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetContentLength(int64_t * aContentLength)
|
2001-02-07 04:21:58 +03:00
|
|
|
{
|
|
|
|
*aContentLength = -1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-10-22 21:51:07 +04:00
|
|
|
nsExtProtocolChannel::SetContentLength(int64_t aContentLength)
|
2001-02-07 04:21:58 +03:00
|
|
|
{
|
|
|
|
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:44 +04:00
|
|
|
return mUrl->GetSpec(result);
|
2001-02-07 04:21:58 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::IsPending(bool *result)
|
2001-02-07 04:21:58 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
*result = false;
|
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
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHODIMP nsExternalProtocolHandler::GetDefaultPort(int32_t *aDefaultPort)
|
2001-02-07 04:21:58 +03:00
|
|
|
{
|
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
|
2012-08-22 19:56:38 +04:00
|
|
|
nsExternalProtocolHandler::AllowPort(int32_t port, const char *scheme, bool *_retval)
|
2001-06-06 04:10:09 +04:00
|
|
|
{
|
|
|
|
// don't override anything.
|
2011-10-17 18:59:28 +04:00
|
|
|
*_retval = false;
|
2001-06-06 04:10:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-02-07 08:24:27 +03:00
|
|
|
// returns TRUE if the OS can handle this protocol scheme and false otherwise.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsExternalProtocolHandler::HaveExternalProtocolHandler(nsIURI * aURI)
|
2001-02-07 08:24:27 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool haveHandler = false;
|
2001-02-07 08:24:27 +03:00
|
|
|
if (aURI)
|
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString scheme;
|
2002-03-06 10:48:55 +03:00
|
|
|
aURI->GetScheme(scheme);
|
2012-01-16 07:55:13 +04:00
|
|
|
nsCOMPtr<nsIExternalProtocolService> extProtSvc(do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID));
|
|
|
|
if (extProtSvc)
|
|
|
|
extProtSvc->ExternalProtocolHandlerExists(scheme.get(), &haveHandler);
|
2001-02-07 08:24:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return haveHandler;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHODIMP nsExternalProtocolHandler::GetProtocolFlags(uint32_t *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:41 +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.)
|
2011-09-29 10:19:26 +04:00
|
|
|
bool haveExternalHandler = HaveExternalProtocolHandler(aURI);
|
2007-06-16 01:43:51 +04:00
|
|
|
if (haveExternalHandler)
|
2001-02-07 04:21:58 +03:00
|
|
|
{
|
2010-07-05 13:42:18 +04:00
|
|
|
nsCOMPtr<nsIChannel> channel = new nsExtProtocolChannel();
|
2001-02-07 08:24:27 +03:00
|
|
|
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
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP nsExternalProtocolHandler::ExternalAppExistsForScheme(const nsACString& aScheme, bool *_retval)
|
2003-02-28 01:46:42 +03:00
|
|
|
{
|
2012-01-16 07:55:13 +04:00
|
|
|
nsCOMPtr<nsIExternalProtocolService> extProtSvc(do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID));
|
|
|
|
if (extProtSvc)
|
|
|
|
return extProtSvc->ExternalProtocolHandlerExists(
|
2007-05-25 19:17:44 +04:00
|
|
|
PromiseFlatCString(aScheme).get(), _retval);
|
2003-02-28 01:46:42 +03:00
|
|
|
|
|
|
|
// In case we don't have external protocol service.
|
2011-10-17 18:59:28 +04:00
|
|
|
*_retval = false;
|
2003-02-28 01:46:42 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|