Bug 1354349 - Add nsIChannel.isDocument that checks if LOAD_DOCUMENT_URI is set, or if LOAD_HTML_OBJECT_DATA and the channel has the appropriate MIME type r=mcmanus,mystor

MozReview-Commit-ID: K28Opd9JTr2

--HG--
extra : rebase_source : d1a786d9b4318be15f195fdc330489121ebd6ece
This commit is contained in:
Valentin Gosu 2017-04-20 10:15:06 +08:00
Родитель 166138d469
Коммит 0a4d506e21
21 изменённых файлов: 150 добавлений и 1 удалений

Просмотреть файл

@ -2956,6 +2956,7 @@ public:
NS_IMETHOD SetLoadGroup(nsILoadGroup*) NO_IMPL
NS_IMETHOD SetLoadFlags(nsLoadFlags) NO_IMPL
NS_IMETHOD GetLoadFlags(nsLoadFlags*) NO_IMPL
NS_IMETHOD GetIsDocument(bool *) NO_IMPL
NS_IMETHOD GetOriginalURI(nsIURI**) NO_IMPL
NS_IMETHOD SetOriginalURI(nsIURI*) NO_IMPL
NS_IMETHOD GetURI(nsIURI** aUri) override

Просмотреть файл

@ -442,6 +442,12 @@ nsresult nsJSChannel::Init(nsIURI* aURI, nsILoadInfo* aLoadInfo)
return rv;
}
NS_IMETHODIMP
nsJSChannel::GetIsDocument(bool *aIsDocument)
{
return NS_GetIsDocumentChannel(this, aIsDocument);
}
//
// nsISupports implementation...
//

Просмотреть файл

@ -19,6 +19,7 @@
#include "nsIInputStreamPump.h"
#include "nsIStreamListener.h"
#include "nsIURI.h"
#include "nsNetUtil.h"
class nsIFile;

Просмотреть файл

@ -27,6 +27,7 @@
#include "nsObjCExceptions.h"
#include "nsProxyRelease.h"
#include "nsContentSecurityManager.h"
#include "nsNetUtil.h"
#include <Cocoa/Cocoa.h>
@ -429,6 +430,12 @@ nsIconChannel::SetLoadFlags(uint32_t aLoadAttributes)
return mPump->SetLoadFlags(aLoadAttributes);
}
NS_IMETHODIMP
nsIconChannel::GetIsDocument(bool *aIsDocument)
{
return NS_GetIsDocumentChannel(this, aIsDocument);
}
NS_IMETHODIMP
nsIconChannel::GetContentType(nsACString& aContentType)
{

Просмотреть файл

@ -28,6 +28,7 @@
#include "nsProxyRelease.h"
#include "nsContentSecurityManager.h"
#include "nsContentUtils.h"
#include "nsNetUtil.h"
// we need windows.h to read out registry information...
#include <windows.h>
@ -157,6 +158,12 @@ nsIconChannel::SetLoadFlags(uint32_t aLoadAttributes)
return mPump->SetLoadFlags(aLoadAttributes);
}
NS_IMETHODIMP
nsIconChannel::GetIsDocument(bool *aIsDocument)
{
return NS_GetIsDocumentChannel(this, aIsDocument);
}
////////////////////////////////////////////////////////////////////////////////
// nsIChannel methods:

Просмотреть файл

@ -486,6 +486,12 @@ nsJARChannel::SetLoadFlags(nsLoadFlags aLoadFlags)
return NS_OK;
}
NS_IMETHODIMP
nsJARChannel::GetIsDocument(bool *aIsDocument)
{
return NS_GetIsDocumentChannel(this, aIsDocument);
}
NS_IMETHODIMP
nsJARChannel::GetLoadGroup(nsILoadGroup **aLoadGroup)
{

Просмотреть файл

@ -503,6 +503,12 @@ nsBaseChannel::GetLoadInfo(nsILoadInfo** aLoadInfo)
return NS_OK;
}
NS_IMETHODIMP
nsBaseChannel::GetIsDocument(bool *aIsDocument)
{
return NS_GetIsDocumentChannel(this, aIsDocument);
}
NS_IMETHODIMP
nsBaseChannel::GetNotificationCallbacks(nsIInterfaceRequestor **aCallbacks)
{

Просмотреть файл

@ -208,6 +208,9 @@ interface nsIChannel : nsIRequest
/**
* Set (e.g., by the docshell) to indicate whether or not the channel
* corresponds to a document URI.
* While setting this flag is sufficient to mark a channel as a document
* load, _checking_ whether the channel is a document load requires the use
* of the new channel.isDocument
*/
const unsigned long LOAD_DOCUMENT_URI = 1 << 16;
@ -344,7 +347,26 @@ interface nsIChannel : nsIRequest
*/
attribute nsILoadInfo loadInfo;
/**
* Returns true if the channel is used to create a document.
* It returns true if the loadFlags have LOAD_DOCUMENT_URI set, or if
* LOAD_HTML_OBJECT_DATA is set and the channel has the appropriate
* MIME type.
* Note: May have the wrong value if called before OnStartRequest as we
* don't know the MIME type yet.
*/
readonly attribute bool isDocument;
%{ C++
inline bool IsDocument()
{
bool isDocument = false;
if (NS_SUCCEEDED(GetIsDocument(&isDocument)) && isDocument) {
return true;
}
return false;
}
inline already_AddRefed<nsILoadInfo> GetLoadInfo()
{
nsCOMPtr<nsILoadInfo> result;

Просмотреть файл

@ -36,6 +36,7 @@
#include "nsIMIMEHeaderParam.h"
#include "nsIMutable.h"
#include "nsINode.h"
#include "nsIObjectLoadingContent.h"
#include "nsIOfflineCacheUpdate.h"
#include "nsIPersistentProperties2.h"
#include "nsIPrivateBrowsingChannel.h"
@ -357,6 +358,45 @@ NS_NewChannel(nsIChannel **outChannel,
aIoService);
}
nsresult
NS_GetIsDocumentChannel(nsIChannel * aChannel, bool *aIsDocument)
{
// Check if this channel is going to be used to create a document. If it has
// LOAD_DOCUMENT_URI set it is trivially creating a document. If
// LOAD_HTML_OBJECT_DATA is set it may or may not be used to create a
// document, depending on its MIME type.
*aIsDocument = false;
if (!aChannel || !aIsDocument) {
return NS_ERROR_NULL_POINTER;
}
nsLoadFlags loadFlags;
nsresult rv = aChannel->GetLoadFlags(&loadFlags);
if (NS_FAILED(rv)) {
return rv;
}
if (loadFlags & nsIChannel::LOAD_DOCUMENT_URI) {
*aIsDocument = true;
return NS_OK;
}
if (!(loadFlags & nsIRequest::LOAD_HTML_OBJECT_DATA)) {
*aIsDocument = false;
return NS_OK;
}
nsAutoCString mimeType;
rv = aChannel->GetContentType(mimeType);
if (NS_FAILED(rv)) {
return rv;
}
if (nsContentUtils::HtmlObjectContentTypeForMIMEType(mimeType, nullptr) ==
nsIObjectLoadingContent::TYPE_DOCUMENT) {
*aIsDocument = true;
return NS_OK;
}
*aIsDocument = false;
return NS_OK;
}
nsresult
NS_MakeAbsoluteURI(nsACString &result,
const nsACString &spec,

Просмотреть файл

@ -190,6 +190,8 @@ NS_NewChannel(nsIChannel **outChannel,
nsLoadFlags aLoadFlags = nsIRequest::LOAD_NORMAL,
nsIIOService *aIoService = nullptr);
nsresult NS_GetIsDocumentChannel(nsIChannel * aChannel, bool *aIsDocument);
nsresult NS_MakeAbsoluteURI(nsACString &result,
const nsACString &spec,
nsIURI *baseURI);

Просмотреть файл

@ -39,6 +39,7 @@
NS_IMETHOD GetContentDispositionHeader(nsACString & aContentDispositionHeader) override { return !_to ? NS_ERROR_NULL_POINTER : _to->GetContentDispositionHeader(aContentDispositionHeader); } \
NS_IMETHOD GetLoadInfo(nsILoadInfo * *aLoadInfo) override { return !_to ? NS_ERROR_NULL_POINTER : _to->GetLoadInfo(aLoadInfo); } \
NS_IMETHOD SetLoadInfo(nsILoadInfo *aLoadInfo) override { return !_to ? NS_ERROR_NULL_POINTER : _to->SetLoadInfo(aLoadInfo); } \
NS_IMETHOD GetIsDocument(bool *aIsDocument) override { return !_to ? NS_ERROR_NULL_POINTER : _to->GetIsDocument(aIsDocument); }; \
class nsAboutCache final : public nsIAboutModule
{

Просмотреть файл

@ -535,6 +535,12 @@ HttpBaseChannel::GetLoadInfo(nsILoadInfo **aLoadInfo)
return NS_OK;
}
NS_IMETHODIMP
HttpBaseChannel::GetIsDocument(bool *aIsDocument)
{
return NS_GetIsDocumentChannel(this, aIsDocument);
}
NS_IMETHODIMP
HttpBaseChannel::GetNotificationCallbacks(nsIInterfaceRequestor **aCallbacks)
{

Просмотреть файл

@ -135,6 +135,7 @@ public:
NS_IMETHOD SetOwner(nsISupports *aOwner) override;
NS_IMETHOD GetLoadInfo(nsILoadInfo **aLoadInfo) override;
NS_IMETHOD SetLoadInfo(nsILoadInfo *aLoadInfo) override;
NS_IMETHOD GetIsDocument(bool *aIsDocument) override;
NS_IMETHOD GetNotificationCallbacks(nsIInterfaceRequestor **aCallbacks) override;
NS_IMETHOD SetNotificationCallbacks(nsIInterfaceRequestor *aCallbacks) override;
NS_IMETHOD GetContentType(nsACString& aContentType) override;

Просмотреть файл

@ -539,6 +539,12 @@ NullHttpChannel::SetLoadFlags(nsLoadFlags aLoadFlags)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
NullHttpChannel::GetIsDocument(bool *aIsDocument)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//-----------------------------------------------------------------------------
// NullHttpChannel::nsITimedChannel
//-----------------------------------------------------------------------------

Просмотреть файл

@ -286,7 +286,7 @@ interface nsIHttpChannel : nsIChannel
/** Indicates whether channel should be treated as the main one for the
* current document. If manually set to true, will always remain true. Otherwise,
* will be true iff LOAD_DOCUMENT_URI is set in the channel's loadflags.
* will be true if LOAD_DOCUMENT_URI is set in the channel's loadflags.
*/
[must_use] attribute boolean isMainDocumentChannel;

Просмотреть файл

@ -573,6 +573,14 @@ nsViewSourceChannel::SetLoadInfo(nsILoadInfo* aLoadInfo)
return mChannel->SetLoadInfo(aLoadInfo);
}
NS_IMETHODIMP
nsViewSourceChannel::GetIsDocument(bool *aIsDocument)
{
NS_ENSURE_TRUE(mChannel, NS_ERROR_FAILURE);
return mChannel->GetIsDocument(aIsDocument);
}
NS_IMETHODIMP
nsViewSourceChannel::GetNotificationCallbacks(nsIInterfaceRequestor* *aNotificationCallbacks)
{

Просмотреть файл

@ -493,6 +493,12 @@ WyciwygChannelChild::SetLoadInfo(nsILoadInfo* aLoadInfo)
return NS_OK;
}
NS_IMETHODIMP
WyciwygChannelChild::GetIsDocument(bool *aIsDocument)
{
return NS_GetIsDocumentChannel(this, aIsDocument);
}
NS_IMETHODIMP
WyciwygChannelChild::GetNotificationCallbacks(nsIInterfaceRequestor * *aCallbacks)
{

Просмотреть файл

@ -166,6 +166,12 @@ nsWyciwygChannel::GetLoadFlags(uint32_t * aLoadFlags)
return NS_OK;
}
NS_IMETHODIMP
nsWyciwygChannel::GetIsDocument(bool *aIsDocument)
{
return NS_GetIsDocumentChannel(this, aIsDocument);
}
////////////////////////////////////////////////////////////////////////////////
// nsIChannel methods:
///////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -227,6 +227,12 @@ nsPartChannel::SetLoadFlags(nsLoadFlags aLoadFlags)
return NS_OK;
}
NS_IMETHODIMP
nsPartChannel::GetIsDocument(bool *aIsDocument)
{
return NS_GetIsDocumentChannel(this, aIsDocument);
}
NS_IMETHODIMP
nsPartChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
{

Просмотреть файл

@ -350,6 +350,12 @@ ExternalHelperAppParent::SetLoadFlags(nsLoadFlags aLoadFlags)
return NS_OK;
}
NS_IMETHODIMP
ExternalHelperAppParent::GetIsDocument(bool *aIsDocument)
{
return NS_GetIsDocumentChannel(this, aIsDocument);
}
NS_IMETHODIMP
ExternalHelperAppParent::GetLoadGroup(nsILoadGroup* *aLoadGroup)
{

Просмотреть файл

@ -245,6 +245,11 @@ NS_IMETHODIMP nsExtProtocolChannel::SetLoadFlags(nsLoadFlags aLoadFlags)
return NS_OK;
}
NS_IMETHODIMP nsExtProtocolChannel::GetIsDocument(bool *aIsDocument)
{
return NS_GetIsDocumentChannel(this, aIsDocument);
}
NS_IMETHODIMP nsExtProtocolChannel::GetContentType(nsACString &aContentType)
{
return NS_ERROR_NOT_IMPLEMENTED;