2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
1999-10-29 21:46:18 +00:00
|
|
|
|
1999-11-02 19:36:43 +00:00
|
|
|
#ifndef nsURILoader_h__
|
|
|
|
#define nsURILoader_h__
|
1999-10-29 21:46:18 +00:00
|
|
|
|
1999-11-02 19:36:43 +00:00
|
|
|
#include "nsCURILoader.h"
|
1999-11-05 06:01:05 +00:00
|
|
|
#include "nsISupportsUtils.h"
|
2002-12-11 00:15:19 +00:00
|
|
|
#include "nsCOMArray.h"
|
1999-10-29 21:46:18 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2000-05-07 02:01:10 +00:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-09-05 21:28:38 +00:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2000-10-19 10:25:49 +00:00
|
|
|
#include "nsString.h"
|
2002-12-11 00:15:19 +00:00
|
|
|
#include "nsIWeakReference.h"
|
2012-06-13 03:53:09 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2019-12-17 03:01:50 +00:00
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsIThreadRetargetableStreamListener.h"
|
2019-12-17 03:02:15 +00:00
|
|
|
#include "nsIExternalHelperAppService.h"
|
1999-10-29 21:46:18 +00:00
|
|
|
|
2015-05-19 18:15:34 +00:00
|
|
|
#include "mozilla/Logging.h"
|
2003-10-30 02:03:41 +00:00
|
|
|
|
2003-10-09 04:00:01 +00:00
|
|
|
class nsDocumentOpenInfo;
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class nsURILoader final : public nsIURILoader {
|
1999-10-29 21:46:18 +00:00
|
|
|
public:
|
1999-11-02 19:36:43 +00:00
|
|
|
NS_DECL_NSIURILOADER
|
1999-10-29 21:46:18 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
1999-11-02 19:36:43 +00:00
|
|
|
nsURILoader();
|
1999-10-29 21:46:18 +00:00
|
|
|
|
|
|
|
protected:
|
2014-06-23 18:49:09 +00:00
|
|
|
~nsURILoader();
|
|
|
|
|
2006-01-28 14:06:31 +00:00
|
|
|
/**
|
|
|
|
* Equivalent to nsIURILoader::openChannel, but allows specifying whether the
|
|
|
|
* channel is opened already.
|
|
|
|
*/
|
2020-04-14 06:41:42 +00:00
|
|
|
[[nodiscard]] nsresult OpenChannel(nsIChannel* channel, uint32_t aFlags,
|
|
|
|
nsIInterfaceRequestor* aWindowContext,
|
|
|
|
bool aChannelOpen,
|
|
|
|
nsIStreamListener** aListener);
|
2006-01-28 14:06:31 +00:00
|
|
|
|
2004-04-16 21:06:07 +00:00
|
|
|
/**
|
|
|
|
* we shouldn't need to have an owning ref count on registered
|
|
|
|
* content listeners because they are supposed to unregister themselves
|
|
|
|
* when they go away. This array stores weak references
|
|
|
|
*/
|
2002-12-11 00:15:19 +00:00
|
|
|
nsCOMArray<nsIWeakReference> m_listeners;
|
1999-10-29 21:46:18 +00:00
|
|
|
|
2003-10-30 02:03:41 +00:00
|
|
|
/**
|
2016-01-30 00:30:00 +00:00
|
|
|
* Logging. The module is called "URILoader"
|
2003-10-30 02:03:41 +00:00
|
|
|
*/
|
2016-01-30 00:30:00 +00:00
|
|
|
static mozilla::LazyLogModule mLog;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2003-10-09 04:00:01 +00:00
|
|
|
friend class nsDocumentOpenInfo;
|
1999-10-29 21:46:18 +00:00
|
|
|
};
|
|
|
|
|
2019-12-17 03:01:50 +00:00
|
|
|
/**
|
|
|
|
* The nsDocumentOpenInfo contains the state required when a single
|
|
|
|
* document is being opened in order to discover the content type...
|
|
|
|
* Each instance remains alive until its target URL has been loaded
|
|
|
|
* (or aborted).
|
|
|
|
*/
|
2019-12-17 03:02:15 +00:00
|
|
|
class nsDocumentOpenInfo : public nsIStreamListener,
|
|
|
|
public nsIThreadRetargetableStreamListener {
|
2019-12-17 03:01:50 +00:00
|
|
|
public:
|
|
|
|
// Real constructor
|
|
|
|
// aFlags is a combination of the flags on nsIURILoader
|
|
|
|
nsDocumentOpenInfo(nsIInterfaceRequestor* aWindowContext, uint32_t aFlags,
|
|
|
|
nsURILoader* aURILoader);
|
2019-12-17 03:02:15 +00:00
|
|
|
nsDocumentOpenInfo(uint32_t aFlags, bool aAllowListenerConversions);
|
2019-12-17 03:01:50 +00:00
|
|
|
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepares this object for receiving data. The stream
|
|
|
|
* listener methods of this class must not be called before calling this
|
|
|
|
* method.
|
|
|
|
*/
|
|
|
|
nsresult Prepare();
|
|
|
|
|
|
|
|
// Call this (from OnStartRequest) to attempt to find an nsIStreamListener to
|
|
|
|
// take the data off our hands.
|
|
|
|
nsresult DispatchContent(nsIRequest* request, nsISupports* aCtxt);
|
|
|
|
|
|
|
|
// Call this if we need to insert a stream converter from aSrcContentType to
|
|
|
|
// aOutContentType into the StreamListener chain. DO NOT call it if the two
|
|
|
|
// types are the same, since no conversion is needed in that case.
|
|
|
|
nsresult ConvertData(nsIRequest* request, nsIURIContentListener* aListener,
|
|
|
|
const nsACString& aSrcContentType,
|
|
|
|
const nsACString& aOutContentType);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to attempt to use aListener to handle the load. If
|
|
|
|
* true is returned, nothing else needs to be done; if false
|
|
|
|
* is returned, then a different way of handling the load should be
|
|
|
|
* tried.
|
|
|
|
*/
|
|
|
|
bool TryContentListener(nsIURIContentListener* aListener,
|
|
|
|
nsIChannel* aChannel);
|
|
|
|
|
2019-12-17 03:02:15 +00:00
|
|
|
/**
|
|
|
|
* Virtual helper functions for content that we expect to be
|
|
|
|
* overriden when running in the parent process on behalf of
|
|
|
|
* a content process docshell.
|
|
|
|
* We also expect nsIStreamListener functions to be overriden
|
|
|
|
* to add functionality.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to create a steam converter converting from the
|
|
|
|
* current mContentType into something else.
|
|
|
|
* Sets m_targetStreamListener if it succeeds.
|
|
|
|
*/
|
|
|
|
virtual nsresult TryStreamConversion(nsIChannel* aChannel);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to use the default content listener as our stream
|
|
|
|
* listener.
|
|
|
|
* Sets m_targetStreamListener if it succeeds.
|
|
|
|
*/
|
|
|
|
virtual bool TryDefaultContentListener(nsIChannel* aChannel);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to pass aChannel onto the external helper app service.
|
|
|
|
* Sets m_targetStreamListener if it succeeds.
|
|
|
|
*/
|
|
|
|
virtual nsresult TryExternalHelperApp(
|
|
|
|
nsIExternalHelperAppService* aHelperAppService, nsIChannel* aChannel);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create another nsDocumentOpenInfo like this one, so that we can chain
|
|
|
|
* them together when we use a stream converter and don't know what the
|
|
|
|
* converted content type is until the converter outputs OnStartRequest.
|
|
|
|
*/
|
|
|
|
virtual nsDocumentOpenInfo* Clone() {
|
|
|
|
return new nsDocumentOpenInfo(m_originalContext, mFlags, mURILoader);
|
|
|
|
}
|
|
|
|
|
2019-12-17 03:01:50 +00:00
|
|
|
// nsIRequestObserver methods:
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
|
|
|
|
// nsIStreamListener methods:
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
|
|
|
|
|
|
|
// nsIThreadRetargetableStreamListener
|
|
|
|
NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
|
2019-12-17 03:02:15 +00:00
|
|
|
|
2019-12-17 03:01:50 +00:00
|
|
|
protected:
|
2019-12-17 03:02:15 +00:00
|
|
|
virtual ~nsDocumentOpenInfo();
|
2019-12-17 03:01:50 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* The first content listener to try dispatching data to. Typically
|
|
|
|
* the listener associated with the entity that originated the load.
|
2019-12-17 03:02:15 +00:00
|
|
|
* This can be nullptr when running in the parent process for a content
|
|
|
|
* process docshell.
|
2019-12-17 03:01:50 +00:00
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIURIContentListener> m_contentListener;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The stream listener to forward nsIStreamListener notifications
|
|
|
|
* to. This is set once the load is dispatched.
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIStreamListener> m_targetStreamListener;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A pointer to the entity that originated the load. We depend on getting
|
|
|
|
* things like nsIURIContentListeners, nsIDOMWindows, etc off of it.
|
2019-12-17 03:02:15 +00:00
|
|
|
* This can be nullptr when running in the parent process for a content
|
|
|
|
* process docshell.
|
2019-12-17 03:01:50 +00:00
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> m_originalContext;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IS_CONTENT_PREFERRED is used for the boolean to pass to CanHandleContent
|
|
|
|
* (also determines whether we use CanHandleContent or IsPreferred).
|
|
|
|
* DONT_RETARGET means that we will only try m_originalContext, no other
|
|
|
|
* listeners.
|
|
|
|
*/
|
|
|
|
uint32_t mFlags;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the data we will be trying to dispatch.
|
|
|
|
*/
|
|
|
|
nsCString mContentType;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reference to the URILoader service so we can access its list of
|
|
|
|
* nsIURIContentListeners.
|
2019-12-17 03:02:15 +00:00
|
|
|
* This can be nullptr when running in the parent process for a content
|
|
|
|
* process docshell.
|
2019-12-17 03:01:50 +00:00
|
|
|
*/
|
|
|
|
RefPtr<nsURILoader> mURILoader;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Limit of data conversion depth to prevent infinite conversion loops
|
|
|
|
*/
|
|
|
|
uint32_t mDataConversionDepthLimit;
|
2019-12-17 03:02:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set to true if OnStartRequest handles the content using an
|
|
|
|
* nsIContentHandler, and the content is consumed despite
|
|
|
|
* m_targetStreamListener being nullptr.
|
|
|
|
*/
|
|
|
|
bool mUsedContentHandler = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* True if we allow nsIURIContentListeners to return a requested
|
|
|
|
* input typeToUse, and attempt to create a matching stream converter.
|
|
|
|
* This is false when running in the parent process for a content process
|
|
|
|
* docshell
|
|
|
|
*/
|
|
|
|
bool mAllowListenerConversions = true;
|
2019-12-17 03:01:50 +00:00
|
|
|
};
|
|
|
|
|
1999-11-02 19:36:43 +00:00
|
|
|
#endif /* nsURILoader_h__ */
|