Bug 1241377 - Part 1: Implement nsIFormPOSTActionChannel for the channel accepts form POST. r=mayhemer

This commit is contained in:
Michael Madsen 2016-01-28 19:38:34 +09:00
Родитель 4d6aaf2f25
Коммит 150b645ebb
8 изменённых файлов: 72 добавлений и 47 удалений

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

@ -106,6 +106,7 @@
#include "nsEscape.h"
// Interfaces Needed
#include "nsIFormPOSTActionChannel.h"
#include "nsIUploadChannel.h"
#include "nsIUploadChannel2.h"
#include "nsIWebProgress.h"
@ -10766,23 +10767,21 @@ nsDocShell::DoURILoad(nsIURI* aURI,
aReferrerURI);
}
//
// If this is a HTTP channel, then set up the HTTP specific information
// (ie. POST data, referrer, ...)
//
if (httpChannel) {
nsCOMPtr<nsICacheInfoChannel> cacheChannel(do_QueryInterface(httpChannel));
/* Get the cache Key from SH */
nsCOMPtr<nsISupports> cacheKey;
nsCOMPtr<nsICacheInfoChannel> cacheChannel(do_QueryInterface(channel));
/* Get the cache Key from SH */
nsCOMPtr<nsISupports> cacheKey;
if (cacheChannel) {
if (mLSHE) {
mLSHE->GetCacheKey(getter_AddRefs(cacheKey));
} else if (mOSHE) { // for reload cases
mOSHE->GetCacheKey(getter_AddRefs(cacheKey));
}
}
// figure out if we need to set the post data stream on the channel...
// right now, this is only done for http channels.....
if (aPostData) {
// figure out if we need to set the post data stream on the channel...
if (aPostData) {
nsCOMPtr<nsIFormPOSTActionChannel> postChannel(do_QueryInterface(channel));
if (postChannel) {
// XXX it's a bit of a hack to rewind the postdata stream here but
// it has to be done in case the post data is being reused multiple
// times.
@ -10793,44 +10792,45 @@ nsDocShell::DoURILoad(nsIURI* aURI,
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr<nsIUploadChannel> uploadChannel(do_QueryInterface(httpChannel));
NS_ASSERTION(uploadChannel, "http must support nsIUploadChannel");
// we really need to have a content type associated with this stream!!
uploadChannel->SetUploadStream(aPostData, EmptyCString(), -1);
/* If there is a valid postdata *and* it is a History Load,
* set up the cache key on the channel, to retrieve the
* data *only* from the cache. If it is a normal reload, the
* cache is free to go to the server for updated postdata.
*/
if (cacheChannel && cacheKey) {
if (mLoadType == LOAD_HISTORY ||
mLoadType == LOAD_RELOAD_CHARSET_CHANGE) {
cacheChannel->SetCacheKey(cacheKey);
uint32_t loadFlags;
if (NS_SUCCEEDED(channel->GetLoadFlags(&loadFlags))) {
channel->SetLoadFlags(
loadFlags | nsICachingChannel::LOAD_ONLY_FROM_CACHE);
}
} else if (mLoadType == LOAD_RELOAD_NORMAL) {
cacheChannel->SetCacheKey(cacheKey);
}
}
} else {
/* If there is no postdata, set the cache key on the channel, and
* do not set the LOAD_ONLY_FROM_CACHE flag, so that the channel
* will be free to get it from net if it is not found in cache.
* New cache may use it creatively on CGI pages with GET
* method and even on those that say "no-cache"
*/
postChannel->SetUploadStream(aPostData, EmptyCString(), -1);
}
/* If there is a valid postdata *and* it is a History Load,
* set up the cache key on the channel, to retrieve the
* data *only* from the cache. If it is a normal reload, the
* cache is free to go to the server for updated postdata.
*/
if (cacheChannel && cacheKey) {
if (mLoadType == LOAD_HISTORY ||
mLoadType == LOAD_RELOAD_NORMAL ||
mLoadType == LOAD_RELOAD_CHARSET_CHANGE) {
if (cacheChannel && cacheKey) {
cacheChannel->SetCacheKey(cacheKey);
cacheChannel->SetCacheKey(cacheKey);
uint32_t loadFlags;
if (NS_SUCCEEDED(channel->GetLoadFlags(&loadFlags))) {
channel->SetLoadFlags(
loadFlags | nsICachingChannel::LOAD_ONLY_FROM_CACHE);
}
} else if (mLoadType == LOAD_RELOAD_NORMAL) {
cacheChannel->SetCacheKey(cacheKey);
}
}
} else {
/* If there is no postdata, set the cache key on the channel, and
* do not set the LOAD_ONLY_FROM_CACHE flag, so that the channel
* will be free to get it from net if it is not found in cache.
* New cache may use it creatively on CGI pages with GET
* method and even on those that say "no-cache"
*/
if (mLoadType == LOAD_HISTORY ||
mLoadType == LOAD_RELOAD_NORMAL ||
mLoadType == LOAD_RELOAD_CHARSET_CHANGE) {
if (cacheChannel && cacheKey) {
cacheChannel->SetCacheKey(cacheKey);
}
}
}
if (httpChannel) {
if (aHeadersData) {
rv = AddHeadersToChannel(aHeadersData, httpChannel);
}

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

@ -46,6 +46,7 @@ XPIDL_SOURCES += [
'nsIFileStreams.idl',
'nsIFileURL.idl',
'nsIForcePendingChannel.idl',
'nsIFormPOSTActionChannel.idl',
'nsIHttpPushListener.idl',
'nsIIncrementalDownload.idl',
'nsIIncrementalStreamLoader.idl',

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

@ -0,0 +1,17 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "nsIUploadChannel.idl"
/**
* nsIFormPOSTActionChannel
*
* Channel classes that want to be allowed for HTML form POST action must
* implement this interface.
*/
[scriptable, uuid(fc826b53-0db8-42b4-aa6a-5dd2cfca52a4)]
interface nsIFormPOSTActionChannel : nsIUploadChannel
{
};

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

@ -212,6 +212,7 @@ NS_INTERFACE_MAP_BEGIN(HttpBaseChannel)
NS_INTERFACE_MAP_ENTRY(nsIHttpChannelInternal)
NS_INTERFACE_MAP_ENTRY(nsIForcePendingChannel)
NS_INTERFACE_MAP_ENTRY(nsIUploadChannel)
NS_INTERFACE_MAP_ENTRY(nsIFormPOSTActionChannel)
NS_INTERFACE_MAP_ENTRY(nsIUploadChannel2)
NS_INTERFACE_MAP_ENTRY(nsISupportsPriority)
NS_INTERFACE_MAP_ENTRY(nsITraceableChannel)

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

@ -21,7 +21,7 @@
#include "nsHttpHandler.h"
#include "nsIHttpChannelInternal.h"
#include "nsIForcePendingChannel.h"
#include "nsIUploadChannel.h"
#include "nsIFormPOSTActionChannel.h"
#include "nsIUploadChannel2.h"
#include "nsIProgressEventSink.h"
#include "nsIURI.h"
@ -66,7 +66,7 @@ class HttpBaseChannel : public nsHashPropertyBag
, public nsIEncodedChannel
, public nsIHttpChannel
, public nsIHttpChannelInternal
, public nsIUploadChannel
, public nsIFormPOSTActionChannel
, public nsIUploadChannel2
, public nsISupportsPriority
, public nsIClassOfService
@ -83,6 +83,7 @@ protected:
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIUPLOADCHANNEL
NS_DECL_NSIFORMPOSTACTIONCHANNEL
NS_DECL_NSIUPLOADCHANNEL2
NS_DECL_NSITRACEABLECHANNEL
NS_DECL_NSITIMEDCHANNEL

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

@ -4780,6 +4780,7 @@ NS_INTERFACE_MAP_BEGIN(nsHttpChannel)
NS_INTERFACE_MAP_ENTRY(nsICachingChannel)
NS_INTERFACE_MAP_ENTRY(nsIClassOfService)
NS_INTERFACE_MAP_ENTRY(nsIUploadChannel)
NS_INTERFACE_MAP_ENTRY(nsIFormPOSTActionChannel)
NS_INTERFACE_MAP_ENTRY(nsIUploadChannel2)
NS_INTERFACE_MAP_ENTRY(nsICacheEntryOpenCallback)
NS_INTERFACE_MAP_ENTRY(nsIHttpChannelInternal)

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

@ -32,6 +32,7 @@ NS_INTERFACE_MAP_BEGIN(nsViewSourceChannel)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsICacheInfoChannel, mCacheInfoChannel)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIApplicationCacheChannel, mApplicationCacheChannel)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIUploadChannel, mUploadChannel)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIFormPOSTActionChannel, mPostChannel)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIRequest, nsIViewSourceChannel)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIChannel, nsIViewSourceChannel)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIViewSourceChannel)
@ -88,6 +89,7 @@ nsViewSourceChannel::Init(nsIURI* uri)
mCacheInfoChannel = do_QueryInterface(mChannel);
mApplicationCacheChannel = do_QueryInterface(mChannel);
mUploadChannel = do_QueryInterface(mChannel);
mPostChannel = do_QueryInterface(mChannel);
return NS_OK;
}

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

@ -15,7 +15,7 @@
#include "nsIHttpChannelInternal.h"
#include "nsICachingChannel.h"
#include "nsIApplicationCacheChannel.h"
#include "nsIUploadChannel.h"
#include "nsIFormPOSTActionChannel.h"
#include "mozilla/Attributes.h"
class nsViewSourceChannel final : public nsIViewSourceChannel,
@ -24,7 +24,7 @@ class nsViewSourceChannel final : public nsIViewSourceChannel,
public nsIHttpChannelInternal,
public nsICachingChannel,
public nsIApplicationCacheChannel,
public nsIUploadChannel
public nsIFormPOSTActionChannel
{
public:
@ -40,6 +40,7 @@ public:
NS_FORWARD_SAFE_NSIAPPLICATIONCACHECHANNEL(mApplicationCacheChannel)
NS_FORWARD_SAFE_NSIAPPLICATIONCACHECONTAINER(mApplicationCacheChannel)
NS_FORWARD_SAFE_NSIUPLOADCHANNEL(mUploadChannel)
NS_FORWARD_SAFE_NSIFORMPOSTACTIONCHANNEL(mPostChannel)
NS_FORWARD_SAFE_NSIHTTPCHANNELINTERNAL(mHttpChannelInternal)
// nsViewSourceChannel methods:
@ -68,6 +69,7 @@ protected:
nsCOMPtr<nsICacheInfoChannel> mCacheInfoChannel;
nsCOMPtr<nsIApplicationCacheChannel> mApplicationCacheChannel;
nsCOMPtr<nsIUploadChannel> mUploadChannel;
nsCOMPtr<nsIFormPOSTActionChannel> mPostChannel;
nsCOMPtr<nsIStreamListener> mListener;
nsCOMPtr<nsIURI> mOriginalURI;
nsCOMPtr<nsIURI> mBaseURI;