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"
|
2017-08-17 08:29:03 +03:00
|
|
|
#include "nsString.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2001-02-07 04:21:58 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2015-12-02 05:49:38 +03:00
|
|
|
#include "nsContentUtils.h"
|
2001-02-07 04:21:58 +03:00
|
|
|
#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"
|
2015-05-15 23:21:20 +03:00
|
|
|
#include "nsContentSecurityManager.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"
|
2016-07-01 06:16:00 +03:00
|
|
|
#include "nsIChildChannel.h"
|
|
|
|
#include "nsIParentChannel.h"
|
2001-02-07 04:21:58 +03:00
|
|
|
|
2014-07-10 10:56:36 +04:00
|
|
|
class nsILoadInfo;
|
|
|
|
|
2001-02-07 04:21:58 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// a stub channel implemenation which will map calls to AsyncRead and OpenInputStream
|
|
|
|
// to calls in the OS for loading the url.
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-07-01 06:16:00 +03:00
|
|
|
class nsExtProtocolChannel : public nsIChannel,
|
|
|
|
public nsIChildChannel,
|
|
|
|
public nsIParentChannel
|
2001-02-07 04:21:58 +03:00
|
|
|
{
|
2007-05-25 19:17:44 +04:00
|
|
|
public:
|
2013-07-19 06:24:15 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2001-02-07 04:21:58 +03:00
|
|
|
NS_DECL_NSICHANNEL
|
2016-07-01 06:16:00 +03:00
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
2001-02-07 04:21:58 +03:00
|
|
|
NS_DECL_NSIREQUEST
|
2016-07-01 06:16:00 +03:00
|
|
|
NS_DECL_NSICHILDCHANNEL
|
|
|
|
NS_DECL_NSIPARENTCHANNEL
|
2004-09-11 03:24:49 +04:00
|
|
|
|
2016-03-25 11:17:43 +03:00
|
|
|
nsExtProtocolChannel(nsIURI* aURI, nsILoadInfo* aLoadInfo);
|
2001-04-10 10:01:08 +04:00
|
|
|
|
2004-10-25 11:46:01 +04:00
|
|
|
private:
|
2014-06-23 22:49:09 +04:00
|
|
|
virtual ~nsExtProtocolChannel();
|
|
|
|
|
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;
|
2016-07-01 06:16:00 +03:00
|
|
|
// Set true (as a result of ConnectParent invoked from child process)
|
|
|
|
// when this channel is on the parent process and is being used as
|
|
|
|
// a redirect target channel. It turns AsyncOpen into a no-op since
|
|
|
|
// we do it on the child.
|
|
|
|
bool mConnectedParent;
|
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;
|
2014-12-12 20:08:01 +03:00
|
|
|
nsCOMPtr<nsILoadInfo> mLoadInfo;
|
2017-08-16 16:45:27 +03:00
|
|
|
nsCOMPtr<nsIStreamListener> mListener;
|
2001-02-07 04:21:58 +03:00
|
|
|
};
|
|
|
|
|
2013-07-19 06:24:15 +04:00
|
|
|
NS_IMPL_ADDREF(nsExtProtocolChannel)
|
|
|
|
NS_IMPL_RELEASE(nsExtProtocolChannel)
|
2001-02-07 04:21:58 +03:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsExtProtocolChannel)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIChannel)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIChannel)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIRequest)
|
2016-07-01 06:16:00 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIChildChannel)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIParentChannel)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
|
2001-02-07 04:21:58 +03:00
|
|
|
NS_INTERFACE_MAP_END_THREADSAFE
|
|
|
|
|
2016-03-25 11:17:43 +03:00
|
|
|
nsExtProtocolChannel::nsExtProtocolChannel(nsIURI* aURI,
|
|
|
|
nsILoadInfo* aLoadInfo)
|
|
|
|
: mUrl(aURI)
|
|
|
|
, mOriginalURI(aURI)
|
|
|
|
, mStatus(NS_OK)
|
2017-03-23 12:17:00 +03:00
|
|
|
, mLoadFlags(nsIRequest::LOAD_NORMAL)
|
2016-03-25 11:17:43 +03:00
|
|
|
, mWasOpened(false)
|
2016-07-01 06:16:00 +03:00
|
|
|
, mConnectedParent(false)
|
2016-03-25 11:17:43 +03:00
|
|
|
, mLoadInfo(aLoadInfo)
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2017-08-16 16:45:27 +03:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && mListener) {
|
2017-08-18 15:07:35 +03:00
|
|
|
Cancel(NS_ERROR_NO_CONTENT);
|
|
|
|
|
2017-08-16 16:45:27 +03:00
|
|
|
RefPtr<nsExtProtocolChannel> self = this;
|
|
|
|
nsCOMPtr<nsIStreamListener> listener = mListener;
|
|
|
|
MessageLoop::current()->PostTask(
|
|
|
|
NS_NewRunnableFunction(
|
|
|
|
"nsExtProtocolChannel::OpenURL",
|
|
|
|
[self, listener]() {
|
|
|
|
listener->OnStartRequest(self, nullptr);
|
|
|
|
listener->OnStopRequest(self, nullptr, self->mStatus);
|
|
|
|
}));
|
2007-09-03 08:44:25 +04:00
|
|
|
}
|
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:
|
2016-11-10 06:11:27 +03:00
|
|
|
mCallbacks = nullptr;
|
2017-08-16 16:45:27 +03:00
|
|
|
mListener = nullptr;
|
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-09-03 08:44:25 +04:00
|
|
|
return OpenURL();
|
2001-02-07 04:21:58 +03:00
|
|
|
}
|
|
|
|
|
2015-05-15 23:21:20 +03:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::Open2(nsIInputStream** aStream)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIStreamListener> listener;
|
|
|
|
nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return Open(aStream);
|
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt)
|
2001-02-07 04:21:58 +03:00
|
|
|
{
|
2016-07-01 06:16:00 +03:00
|
|
|
if (mConnectedParent) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-11-18 04:35:30 +03:00
|
|
|
MOZ_ASSERT(!mLoadInfo ||
|
|
|
|
mLoadInfo->GetSecurityMode() == 0 ||
|
|
|
|
mLoadInfo->GetInitialSecurityCheckDone() ||
|
|
|
|
(mLoadInfo->GetSecurityMode() == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL &&
|
|
|
|
nsContentUtils::IsSystemPrincipal(mLoadInfo->LoadingPrincipal())),
|
2015-08-13 07:36:33 +03:00
|
|
|
"security flags in loadInfo but asyncOpen2() not called");
|
|
|
|
|
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;
|
2017-08-16 16:45:27 +03:00
|
|
|
mListener = listener;
|
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
|
|
|
}
|
|
|
|
|
2015-05-15 23:21:20 +03:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::AsyncOpen2(nsIStreamListener *aListener)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIStreamListener> listener = aListener;
|
|
|
|
nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
|
2017-02-08 20:55:15 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mCallbacks = nullptr;
|
|
|
|
return rv;
|
|
|
|
}
|
2015-05-15 23:21:20 +03:00
|
|
|
return AsyncOpen(listener, nullptr);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-04-20 05:15:06 +03:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetIsDocument(bool *aIsDocument)
|
|
|
|
{
|
|
|
|
return NS_GetIsDocumentChannel(this, aIsDocument);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::SetOwner(nsISupports * aPrincipal)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2014-12-12 20:08:01 +03:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::GetLoadInfo(nsILoadInfo **aLoadInfo)
|
2014-07-10 10:56:36 +04:00
|
|
|
{
|
2014-12-12 20:08:01 +03:00
|
|
|
NS_IF_ADDREF(*aLoadInfo = mLoadInfo);
|
|
|
|
return NS_OK;
|
2014-07-10 10:56:36 +04:00
|
|
|
}
|
|
|
|
|
2014-12-12 20:08:01 +03:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::SetLoadInfo(nsILoadInfo *aLoadInfo)
|
2014-07-10 10:56:36 +04:00
|
|
|
{
|
2014-12-12 20:08:01 +03:00
|
|
|
mLoadInfo = aLoadInfo;
|
|
|
|
return NS_OK;
|
2014-07-10 10:56:36 +04:00
|
|
|
}
|
|
|
|
|
2001-02-07 04:21:58 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2016-07-01 06:16:00 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// From nsIChildChannel
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::ConnectParent(uint32_t registrarId)
|
|
|
|
{
|
|
|
|
mozilla::dom::ContentChild::GetSingleton()->
|
|
|
|
SendExtProtocolChannelConnectParent(registrarId);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::CompleteRedirectSetup(nsIStreamListener *listener,
|
|
|
|
nsISupports *context)
|
|
|
|
{
|
|
|
|
// For redirects to external protocols we AsyncOpen on the child
|
|
|
|
// (not the parent) because child channel has the right docshell
|
|
|
|
// (which is needed for the select dialog).
|
|
|
|
return AsyncOpen(listener, context);
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// From nsIParentChannel (derives from nsIStreamListener)
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::SetParentListener(HttpChannelParentListener* aListener)
|
|
|
|
{
|
|
|
|
// This is called as part of the connect parent operation from
|
|
|
|
// ContentParent::RecvExtProtocolChannelConnectParent. Setting
|
|
|
|
// this flag tells this channel to not proceed and makes AsyncOpen
|
|
|
|
// just no-op. Actual operation will happen from the child process
|
|
|
|
// via CompleteRedirectSetup call on the child channel.
|
|
|
|
mConnectedParent = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::NotifyTrackingProtectionDisabled()
|
|
|
|
{
|
|
|
|
// nothing to do
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-02-21 04:46:36 +03:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::SetClassifierMatchedInfo(const nsACString& aList,
|
|
|
|
const nsACString& aProvider,
|
2017-08-04 13:20:13 +03:00
|
|
|
const nsACString& aFullHash)
|
2017-02-21 04:46:36 +03:00
|
|
|
{
|
|
|
|
// nothing to do
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-12-16 23:19:19 +03:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::NotifyTrackingResource()
|
|
|
|
{
|
|
|
|
// nothing to do
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-07-01 06:16:00 +03:00
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::Delete()
|
|
|
|
{
|
|
|
|
// nothing to do
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::OnStartRequest(nsIRequest *aRequest,
|
|
|
|
nsISupports *aContext)
|
|
|
|
{
|
|
|
|
// no data is expected
|
|
|
|
MOZ_CRASH("No data expected from external protocol channel");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::OnStopRequest(nsIRequest *aRequest,
|
|
|
|
nsISupports *aContext,
|
|
|
|
nsresult aStatusCode)
|
|
|
|
{
|
|
|
|
// no data is expected
|
|
|
|
MOZ_CRASH("No data expected from external protocol channel");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExtProtocolChannel::OnDataAvailable(nsIRequest *aRequest,
|
|
|
|
nsISupports *aContext,
|
|
|
|
nsIInputStream *aInputStream,
|
|
|
|
uint64_t aOffset,
|
|
|
|
uint32_t aCount)
|
|
|
|
{
|
|
|
|
// no data is expected
|
|
|
|
MOZ_CRASH("No data expected from external protocol channel");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2001-02-07 04:21:58 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// 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()
|
|
|
|
{}
|
|
|
|
|
2013-07-19 06:24:15 +04:00
|
|
|
NS_IMPL_ADDREF(nsExternalProtocolHandler)
|
|
|
|
NS_IMPL_RELEASE(nsExternalProtocolHandler)
|
2001-02-07 04:21:58 +03:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2016-03-25 11:17:37 +03:00
|
|
|
MOZ_ASSERT(aURI);
|
|
|
|
nsAutoCString scheme;
|
|
|
|
aURI->GetScheme(scheme);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIExternalProtocolService> extProtSvc(do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID));
|
|
|
|
if (!extProtSvc) {
|
|
|
|
return false;
|
2001-02-07 08:24:27 +03:00
|
|
|
}
|
|
|
|
|
2016-03-25 11:17:37 +03:00
|
|
|
bool haveHandler = false;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-10-23 04:16:57 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsExternalProtocolHandler::NewChannel2(nsIURI* aURI,
|
|
|
|
nsILoadInfo* aLoadInfo,
|
2016-03-25 11:17:32 +03:00
|
|
|
nsIChannel** aRetval)
|
2001-02-07 04:21:58 +03:00
|
|
|
{
|
2016-03-25 11:17:37 +03:00
|
|
|
NS_ENSURE_TRUE(aURI, NS_ERROR_UNKNOWN_PROTOCOL);
|
2016-03-25 11:17:32 +03:00
|
|
|
NS_ENSURE_TRUE(aRetval, NS_ERROR_UNKNOWN_PROTOCOL);
|
|
|
|
|
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.)
|
2016-03-25 11:17:32 +03:00
|
|
|
if (!HaveExternalProtocolHandler(aURI)) {
|
|
|
|
return NS_ERROR_UNKNOWN_PROTOCOL;
|
|
|
|
}
|
2001-02-07 08:24:27 +03:00
|
|
|
|
2016-03-25 11:17:43 +03:00
|
|
|
nsCOMPtr<nsIChannel> channel = new nsExtProtocolChannel(aURI, aLoadInfo);
|
|
|
|
channel.forget(aRetval);
|
2016-03-25 11:17:32 +03:00
|
|
|
return NS_OK;
|
2001-02-07 04:21:58 +03:00
|
|
|
}
|
2003-02-28 01:46:42 +03:00
|
|
|
|
2014-10-23 04:16:57 +04:00
|
|
|
NS_IMETHODIMP nsExternalProtocolHandler::NewChannel(nsIURI *aURI, nsIChannel **_retval)
|
|
|
|
{
|
|
|
|
return NewChannel2(aURI, nullptr, _retval);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|