2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim:set ts=2 sts=2 sw=2 et cin:
|
|
|
|
*
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsExternalProtocolHandler.h"
|
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "nsIPrompt.h"
|
|
|
|
#include "nsNetUtil.h"
|
2007-05-25 08:17:44 -07:00
|
|
|
#include "nsExternalHelperAppService.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// used to dispatch urls to default protocol handlers
|
|
|
|
#include "nsCExternalHandlerService.h"
|
|
|
|
#include "nsIExternalProtocolService.h"
|
|
|
|
|
2014-07-09 23:56:36 -07:00
|
|
|
class nsILoadInfo;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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 08:17:44 -07:00
|
|
|
public:
|
2013-07-18 19:24:15 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DECL_NSICHANNEL
|
|
|
|
NS_DECL_NSIREQUEST
|
|
|
|
|
|
|
|
nsExtProtocolChannel();
|
|
|
|
|
|
|
|
nsresult SetURI(nsIURI*);
|
|
|
|
|
|
|
|
private:
|
2014-06-23 11:49:09 -07:00
|
|
|
virtual ~nsExtProtocolChannel();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult OpenURL();
|
2007-07-05 12:31:44 -07:00
|
|
|
void Finish(nsresult aResult);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIURI> mUrl;
|
|
|
|
nsCOMPtr<nsIURI> mOriginalURI;
|
|
|
|
nsresult mStatus;
|
2007-05-25 08:17:44 -07:00
|
|
|
nsLoadFlags mLoadFlags;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mWasOpened;
|
2007-07-05 12:31:44 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
|
|
|
|
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
|
|
|
};
|
|
|
|
|
2013-07-18 19:24:15 -07:00
|
|
|
NS_IMPL_ADDREF(nsExtProtocolChannel)
|
|
|
|
NS_IMPL_RELEASE(nsExtProtocolChannel)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
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 12:31:44 -07:00
|
|
|
nsExtProtocolChannel::nsExtProtocolChannel() : mStatus(NS_OK),
|
2011-10-17 07:59:28 -07:00
|
|
|
mWasOpened(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsExtProtocolChannel::~nsExtProtocolChannel()
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetLoadGroup(nsILoadGroup * *aLoadGroup)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aLoadGroup = mLoadGroup);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::SetLoadGroup(nsILoadGroup * aLoadGroup)
|
|
|
|
{
|
|
|
|
mLoadGroup = aLoadGroup;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetNotificationCallbacks(nsIInterfaceRequestor* *aCallbacks)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aCallbacks = mCallbacks);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aCallbacks)
|
|
|
|
{
|
|
|
|
mCallbacks = aCallbacks;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExtProtocolChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aSecurityInfo = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetOriginalURI(nsIURI* *aURI)
|
|
|
|
{
|
2008-10-15 13:05:23 -07:00
|
|
|
NS_ADDREF(*aURI = mOriginalURI);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::SetOriginalURI(nsIURI* aURI)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
|
|
|
mOriginalURI = aURI;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetURI(nsIURI* *aURI)
|
|
|
|
{
|
|
|
|
*aURI = mUrl;
|
|
|
|
NS_IF_ADDREF(*aURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsExtProtocolChannel::SetURI(nsIURI* aURI)
|
|
|
|
{
|
|
|
|
mUrl = aURI;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-05-25 08:17:44 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult nsExtProtocolChannel::OpenURL()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
nsCOMPtr<nsIExternalProtocolService> extProtService (do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID));
|
|
|
|
|
|
|
|
if (extProtService)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString urlScheme;
|
2007-03-22 10:30:00 -07:00
|
|
|
mUrl->GetScheme(urlScheme);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool haveHandler = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
extProtService->ExternalProtocolHandlerExists(urlScheme.get(), &haveHandler);
|
|
|
|
NS_ASSERTION(haveHandler, "Why do we have a channel for this url if we don't support the protocol?");
|
|
|
|
#endif
|
|
|
|
|
2007-09-02 21:44:25 -07: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;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-09-02 21:44:25 -07:00
|
|
|
finish:
|
2007-03-22 10:30:00 -07:00
|
|
|
mCallbacks = 0;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::Open(nsIInputStream **_retval)
|
|
|
|
{
|
2007-09-02 21:44:25 -07:00
|
|
|
return OpenURL();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt)
|
|
|
|
{
|
2007-07-05 12:31:44 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(listener);
|
|
|
|
NS_ENSURE_TRUE(!mWasOpened, NS_ERROR_ALREADY_OPENED);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mWasOpened = true;
|
2007-07-05 12:31:44 -07:00
|
|
|
|
2007-09-02 21:44:25 -07:00
|
|
|
return OpenURL();
|
2007-07-05 12:31:44 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetLoadFlags(nsLoadFlags *aLoadFlags)
|
|
|
|
{
|
2007-05-25 08:17:44 -07:00
|
|
|
*aLoadFlags = mLoadFlags;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::SetLoadFlags(nsLoadFlags aLoadFlags)
|
|
|
|
{
|
2007-05-25 08:17:44 -07:00
|
|
|
mLoadFlags = aLoadFlags;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetContentType(nsACString &aContentType)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::SetContentType(const nsACString &aContentType)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 08:56:38 -07:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetContentDisposition(uint32_t *aContentDisposition)
|
2011-09-09 15:41:04 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2012-10-02 09:43:00 -07:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::SetContentDisposition(uint32_t aContentDisposition)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2011-09-09 15:41:04 -07:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetContentDispositionFilename(nsAString &aContentDispositionFilename)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2012-10-02 09:43:00 -07:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::SetContentDispositionFilename(const nsAString &aContentDispositionFilename)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2011-09-09 15:41:04 -07:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetContentDispositionHeader(nsACString &aContentDispositionHeader)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2012-10-22 10:51:07 -07:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetContentLength(int64_t * aContentLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aContentLength = -1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-10-22 10:51:07 -07:00
|
|
|
nsExtProtocolChannel::SetContentLength(int64_t aContentLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("SetContentLength");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetOwner(nsISupports * *aPrincipal)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::SetOwner(nsISupports * aPrincipal)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2014-07-09 23:56:36 -07:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetLoadInfo(nsILoadInfo * *aLoadInfo)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::SetLoadInfo(nsILoadInfo * aLoadInfo)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// From nsIRequest
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetName(nsACString &result)
|
|
|
|
{
|
2007-05-25 08:17:44 -07:00
|
|
|
return mUrl->GetSpec(result);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::IsPending(bool *result)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
*result = false;
|
2007-03-22 10:30:00 -07: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()
|
|
|
|
{
|
|
|
|
m_schemeName = "default";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsExternalProtocolHandler::~nsExternalProtocolHandler()
|
|
|
|
{}
|
|
|
|
|
2013-07-18 19:24:15 -07:00
|
|
|
NS_IMPL_ADDREF(nsExternalProtocolHandler)
|
|
|
|
NS_IMPL_RELEASE(nsExternalProtocolHandler)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsExternalProtocolHandler)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIProtocolHandler)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIProtocolHandler)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIExternalProtocolHandler)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
|
|
NS_INTERFACE_MAP_END_THREADSAFE
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExternalProtocolHandler::GetScheme(nsACString &aScheme)
|
|
|
|
{
|
|
|
|
aScheme = m_schemeName;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHODIMP nsExternalProtocolHandler::GetDefaultPort(int32_t *aDefaultPort)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aDefaultPort = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsExternalProtocolHandler::AllowPort(int32_t port, const char *scheme, bool *_retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// don't override anything.
|
2011-10-17 07:59:28 -07:00
|
|
|
*_retval = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
// returns TRUE if the OS can handle this protocol scheme and false otherwise.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsExternalProtocolHandler::HaveExternalProtocolHandler(nsIURI * aURI)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool haveHandler = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aURI)
|
|
|
|
{
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString scheme;
|
2007-03-22 10:30:00 -07:00
|
|
|
aURI->GetScheme(scheme);
|
2012-01-15 19:55:13 -08:00
|
|
|
nsCOMPtr<nsIExternalProtocolService> extProtSvc(do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID));
|
|
|
|
if (extProtSvc)
|
|
|
|
extProtSvc->ExternalProtocolHandlerExists(scheme.get(), &haveHandler);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return haveHandler;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHODIMP nsExternalProtocolHandler::GetProtocolFlags(uint32_t *aUritype)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Make it norelative since it is a simple uri
|
2007-04-15 05:31:18 -07:00
|
|
|
*aUritype = URI_NORELATIVE | URI_NOAUTH | URI_LOADABLE_BY_ANYONE |
|
2007-07-25 10:21:41 -07:00
|
|
|
URI_NON_PERSISTABLE | URI_DOES_NOT_RETURN_DATA;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExternalProtocolHandler::NewURI(const nsACString &aSpec,
|
|
|
|
const char *aCharset, // ignore charset info
|
|
|
|
nsIURI *aBaseURI,
|
|
|
|
nsIURI **_retval)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIURI> uri = do_CreateInstance(NS_SIMPLEURI_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = uri->SetSpec(aSpec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
NS_ADDREF(*_retval = uri);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-10-22 17:16:57 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExternalProtocolHandler::NewChannel2(nsIURI* aURI,
|
|
|
|
nsILoadInfo* aLoadInfo,
|
|
|
|
nsIChannel** _retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-27 11:31:13 -07: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-28 23:19:26 -07:00
|
|
|
bool haveExternalHandler = HaveExternalProtocolHandler(aURI);
|
2007-06-15 14:43:51 -07:00
|
|
|
if (haveExternalHandler)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-07-05 02:42:18 -07:00
|
|
|
nsCOMPtr<nsIChannel> channel = new nsExtProtocolChannel();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!channel) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
((nsExtProtocolChannel*) channel.get())->SetURI(aURI);
|
|
|
|
channel->SetOriginalURI(aURI);
|
|
|
|
|
|
|
|
if (_retval)
|
|
|
|
{
|
|
|
|
*_retval = channel;
|
|
|
|
NS_IF_ADDREF(*_retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_UNKNOWN_PROTOCOL;
|
|
|
|
}
|
|
|
|
|
2014-10-22 17:16:57 -07:00
|
|
|
NS_IMETHODIMP nsExternalProtocolHandler::NewChannel(nsIURI *aURI, nsIChannel **_retval)
|
|
|
|
{
|
|
|
|
return NewChannel2(aURI, nullptr, _retval);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// External protocol handler interface implementation
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsExternalProtocolHandler::ExternalAppExistsForScheme(const nsACString& aScheme, bool *_retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-01-15 19:55:13 -08:00
|
|
|
nsCOMPtr<nsIExternalProtocolService> extProtSvc(do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID));
|
|
|
|
if (extProtSvc)
|
|
|
|
return extProtSvc->ExternalProtocolHandlerExists(
|
2007-05-25 08:17:44 -07:00
|
|
|
PromiseFlatCString(aScheme).get(), _retval);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// In case we don't have external protocol service.
|
2011-10-17 07:59:28 -07:00
|
|
|
*_retval = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|