Bug 1350359 - Part 1: Set alternative data type from InterceptedChannel to InternalRequest. r=bkelly

This commit is contained in:
Eden Chuang 2017-12-04 14:39:10 +08:00
parent 2a280abe08
commit 7211e8c25c
6 changed files with 50 additions and 0 deletions

View File

@ -52,6 +52,8 @@ InternalRequest::GetRequestConstructorCopy(nsIGlobalObject* aGlobal, ErrorResult
copy->mRedirectMode = mRedirectMode;
copy->mCreatedByFetchEvent = mCreatedByFetchEvent;
copy->mContentPolicyTypeOverridden = mContentPolicyTypeOverridden;
copy->mPreferredAlternativeDataType = mPreferredAlternativeDataType;
return copy.forget();
}

View File

@ -552,6 +552,18 @@ public:
return mPrincipalInfo;
}
const nsCString&
GetPreferredAlternativeDataType() const
{
return mPreferredAlternativeDataType;
}
void
SetPreferredAlternativeDataType(const nsACString& aDataType)
{
mPreferredAlternativeDataType = aDataType;
}
private:
// Does not copy mBodyStream. Use fallible Clone() for complete copy.
explicit InternalRequest(const InternalRequest& aOther);
@ -574,6 +586,8 @@ private:
nsCOMPtr<nsIInputStream> mBodyStream;
int64_t mBodyLength;
nsCString mPreferredAlternativeDataType;
nsContentPolicyType mContentPolicyType;
// Empty string: no-referrer

View File

@ -9,6 +9,7 @@
#include "ServiceWorkerManager.h"
#include "ServiceWorkerWindowClient.h"
#include "nsContentUtils.h"
#include "nsICacheInfoChannel.h"
#include "nsIHttpChannelInternal.h"
#include "nsIHttpHeaderVisitor.h"
#include "nsINamed.h"
@ -1608,6 +1609,18 @@ private:
// For Telemetry, note that this Request object was created by a Fetch event.
internalReq->SetCreatedByFetchEvent();
nsCOMPtr<nsIChannel> channel;
nsresult rv = mInterceptedChannel->GetChannel(getter_AddRefs(channel));
NS_ENSURE_SUCCESS(rv, false);
nsAutoCString alternativeDataType;
nsCOMPtr<nsICacheInfoChannel> cic = do_QueryInterface(channel);
if (cic &&
NS_SUCCEEDED(cic->GetPreferredAlternativeDataType(alternativeDataType)) &&
!alternativeDataType.IsEmpty()) {
internalReq->SetPreferredAlternativeDataType(alternativeDataType);
}
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(globalObj.GetAsSupports());
if (NS_WARN_IF(!global)) {
return false;

View File

@ -84,6 +84,13 @@ interface nsICacheInfoChannel : nsISupports
*/
void preferAlternativeDataType(in ACString type);
/**
* Get the preferred alternative data type set by preferAlternativeDataType().
* This attribute stands for the desired data type instead of the type of the
* information retrieved from the network stack.
*/
readonly attribute ACString preferredAlternativeDataType;
/**
* Holds the type of the alternative data representation that the channel
* is returning.

View File

@ -2957,6 +2957,13 @@ HttpChannelChild::PreferAlternativeDataType(const nsACString & aType)
return NS_OK;
}
NS_IMETHODIMP
HttpChannelChild::GetPreferredAlternativeDataType(nsACString & aType)
{
aType = mPreferredCachedAltDataType;
return NS_OK;
}
NS_IMETHODIMP
HttpChannelChild::GetAlternativeDataType(nsACString & aType)
{

View File

@ -7885,6 +7885,13 @@ nsHttpChannel::PreferAlternativeDataType(const nsACString & aType)
return NS_OK;
}
NS_IMETHODIMP
nsHttpChannel::GetPreferredAlternativeDataType(nsACString & aType)
{
aType = mPreferredCachedAltDataType;
return NS_OK;
}
NS_IMETHODIMP
nsHttpChannel::GetAlternativeDataType(nsACString & aType)
{