Bug 1776414 - Change nsIHttpChannelInternal corsMode to requestMode. r=kershaw,necko-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D150243
This commit is contained in:
Tom Schuster
2022-06-29 14:09:57 +00:00
parent f646e0e09a
commit 8c312c62fb
12 changed files with 42 additions and 50 deletions

View File

@@ -719,10 +719,10 @@ nsresult FetchDriver::HttpFetch(
nsCOMPtr<nsIHttpChannelInternal> internalChan = do_QueryInterface(httpChan); nsCOMPtr<nsIHttpChannelInternal> internalChan = do_QueryInterface(httpChan);
rv = internalChan->SetRequestMode(mRequest->Mode());
MOZ_ASSERT(NS_SUCCEEDED(rv));
// Conversion between enumerations is safe due to static asserts in // Conversion between enumerations is safe due to static asserts in
// dom/workers/ServiceWorkerManager.cpp // dom/workers/ServiceWorkerManager.cpp
rv = internalChan->SetCorsMode(static_cast<uint32_t>(mRequest->Mode()));
MOZ_ASSERT(NS_SUCCEEDED(rv));
rv = internalChan->SetRedirectMode( rv = internalChan->SetRedirectMode(
static_cast<uint32_t>(mRequest->GetRedirectMode())); static_cast<uint32_t>(mRequest->GetRedirectMode()));
MOZ_ASSERT(NS_SUCCEEDED(rv)); MOZ_ASSERT(NS_SUCCEEDED(rv));

View File

@@ -25,6 +25,7 @@
#include "mozilla/net/HttpBaseChannel.h" #include "mozilla/net/HttpBaseChannel.h"
#include "mozilla/dom/Document.h" #include "mozilla/dom/Document.h"
#include "mozilla/dom/Element.h" #include "mozilla/dom/Element.h"
#include "mozilla/dom/RequestBinding.h"
#include "mozilla/StaticPrefs_network.h" #include "mozilla/StaticPrefs_network.h"
#include "mozilla/StorageAccess.h" #include "mozilla/StorageAccess.h"
#include "mozilla/StyleSheet.h" #include "mozilla/StyleSheet.h"
@@ -431,9 +432,9 @@ bool ReferrerInfo::ShouldSetNullOriginHeader(net::HttpBaseChannel* aChannel,
// This code should not really be here, but we always need to send an Origin // This code should not really be here, but we always need to send an Origin
// header for CORS requests that aren't GET or HEAD. Also see the comment // header for CORS requests that aren't GET or HEAD. Also see the comment
// in nsHttpChannel::SetOriginHeader. // in nsHttpChannel::SetOriginHeader.
uint32_t corsMode = nsIHttpChannelInternal::CORS_MODE_NO_CORS; RequestMode requestMode = RequestMode::No_cors;
MOZ_ALWAYS_SUCCEEDS(aChannel->GetCorsMode(&corsMode)); MOZ_ALWAYS_SUCCEEDS(aChannel->GetRequestMode(&requestMode));
if (corsMode == nsIHttpChannelInternal::CORS_MODE_CORS) { if (requestMode == RequestMode::Cors) {
return false; return false;
} }

View File

@@ -115,23 +115,6 @@ namespace mozilla::dom {
uint32_t gServiceWorkersRegistered = 0; uint32_t gServiceWorkersRegistered = 0;
uint32_t gServiceWorkersRegisteredFetch = 0; uint32_t gServiceWorkersRegisteredFetch = 0;
static_assert(
nsIHttpChannelInternal::CORS_MODE_SAME_ORIGIN ==
static_cast<uint32_t>(RequestMode::Same_origin),
"RequestMode enumeration value should match Necko CORS mode value.");
static_assert(
nsIHttpChannelInternal::CORS_MODE_NO_CORS ==
static_cast<uint32_t>(RequestMode::No_cors),
"RequestMode enumeration value should match Necko CORS mode value.");
static_assert(
nsIHttpChannelInternal::CORS_MODE_CORS ==
static_cast<uint32_t>(RequestMode::Cors),
"RequestMode enumeration value should match Necko CORS mode value.");
static_assert(
nsIHttpChannelInternal::CORS_MODE_NAVIGATE ==
static_cast<uint32_t>(RequestMode::Navigate),
"RequestMode enumeration value should match Necko CORS mode value.");
static_assert( static_assert(
nsIHttpChannelInternal::REDIRECT_MODE_FOLLOW == nsIHttpChannelInternal::REDIRECT_MODE_FOLLOW ==
static_cast<uint32_t>(RequestRedirect::Follow), static_cast<uint32_t>(RequestRedirect::Follow),

View File

@@ -14,6 +14,7 @@ include PBackgroundSharedTypes;
include DOMTypes; include DOMTypes;
include ProtocolTypes; include ProtocolTypes;
include "mozilla/dom/FetchIPCTypes.h";
include "mozilla/dom/PropertyBagUtils.h"; include "mozilla/dom/PropertyBagUtils.h";
include "mozilla/dom/ReferrerInfoUtils.h"; include "mozilla/dom/ReferrerInfoUtils.h";
include "mozilla/ipc/URIUtils.h"; include "mozilla/ipc/URIUtils.h";
@@ -33,6 +34,7 @@ using mozilla::net::PreferredAlternativeDataDeliveryTypeIPC from "nsICacheInfoCh
using nsILoadInfo::CrossOriginEmbedderPolicy from "nsILoadInfo.h"; using nsILoadInfo::CrossOriginEmbedderPolicy from "nsILoadInfo.h";
using nsILoadInfo::StoragePermissionState from "nsILoadInfo.h"; using nsILoadInfo::StoragePermissionState from "nsILoadInfo.h";
using struct mozilla::dom::LoadingSessionHistoryInfo from "mozilla/dom/SessionHistoryEntry.h"; using struct mozilla::dom::LoadingSessionHistoryInfo from "mozilla/dom/SessionHistoryEntry.h";
using mozilla::dom::RequestMode from "mozilla/dom/RequestBinding.h";
namespace mozilla { namespace mozilla {
namespace net { namespace net {
@@ -313,7 +315,7 @@ struct HttpChannelOpenArgs
bool forceValidateCacheContent; bool forceValidateCacheContent;
bool preferCacheLoadOverBypass; bool preferCacheLoadOverBypass;
nsCString contentTypeHint; nsCString contentTypeHint;
uint32_t corsMode; RequestMode requestMode;
uint32_t redirectMode; uint32_t redirectMode;
uint64_t channelId; uint64_t channelId;
nsString integrityMetadata; nsString integrityMetadata;

View File

@@ -560,12 +560,12 @@ ClassifierDummyChannel::SetCorsIncludeCredentials(
} }
NS_IMETHODIMP NS_IMETHODIMP
ClassifierDummyChannel::GetCorsMode(uint32_t* aCorsMode) { ClassifierDummyChannel::GetRequestMode(dom::RequestMode* aRequestMode) {
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
} }
NS_IMETHODIMP NS_IMETHODIMP
ClassifierDummyChannel::SetCorsMode(uint32_t aCorsMode) { ClassifierDummyChannel::SetRequestMode(dom::RequestMode aRequestMode) {
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
} }

View File

@@ -40,6 +40,7 @@
#include "mozilla/dom/Performance.h" #include "mozilla/dom/Performance.h"
#include "mozilla/dom/PerformanceStorage.h" #include "mozilla/dom/PerformanceStorage.h"
#include "mozilla/dom/ProcessIsolation.h" #include "mozilla/dom/ProcessIsolation.h"
#include "mozilla/dom/RequestBinding.h"
#include "mozilla/dom/WindowGlobalParent.h" #include "mozilla/dom/WindowGlobalParent.h"
#include "mozilla/net/OpaqueResponseUtils.h" #include "mozilla/net/OpaqueResponseUtils.h"
#include "mozilla/net/UrlClassifierCommon.h" #include "mozilla/net/UrlClassifierCommon.h"
@@ -100,6 +101,8 @@
#include "mozilla/dom/ContentChild.h" #include "mozilla/dom/ContentChild.h"
#include "nsQueryObject.h" #include "nsQueryObject.h"
using mozilla::dom::RequestMode;
namespace mozilla { namespace mozilla {
namespace net { namespace net {
@@ -204,7 +207,7 @@ HttpBaseChannel::HttpBaseChannel()
mInitialRwin(0), mInitialRwin(0),
mProxyResolveFlags(0), mProxyResolveFlags(0),
mContentDispositionHint(UINT32_MAX), mContentDispositionHint(UINT32_MAX),
mCorsMode(nsIHttpChannelInternal::CORS_MODE_NO_CORS), mRequestMode(RequestMode::No_cors),
mRedirectMode(nsIHttpChannelInternal::REDIRECT_MODE_FOLLOW), mRedirectMode(nsIHttpChannelInternal::REDIRECT_MODE_FOLLOW),
mLastRedirectFlags(0), mLastRedirectFlags(0),
mPriority(PRIORITY_NORMAL), mPriority(PRIORITY_NORMAL),
@@ -2417,9 +2420,10 @@ nsresult HttpBaseChannel::ProcessCrossOriginEmbedderPolicyHeader() {
// https://mikewest.github.io/corpp/#corp-check // https://mikewest.github.io/corpp/#corp-check
nsresult HttpBaseChannel::ProcessCrossOriginResourcePolicyHeader() { nsresult HttpBaseChannel::ProcessCrossOriginResourcePolicyHeader() {
// Fetch 4.5.9 // Fetch 4.5.9
uint32_t corsMode; dom::RequestMode requestMode;
MOZ_ALWAYS_SUCCEEDS(GetCorsMode(&corsMode)); MOZ_ALWAYS_SUCCEEDS(GetRequestMode(&requestMode));
if (corsMode != nsIHttpChannelInternal::CORS_MODE_NO_CORS) { // XXX this seems wrong per spec? What about navigate
if (requestMode != RequestMode::No_cors) {
return NS_OK; return NS_OK;
} }
@@ -3612,14 +3616,15 @@ HttpBaseChannel::SetCorsIncludeCredentials(bool aInclude) {
} }
NS_IMETHODIMP NS_IMETHODIMP
HttpBaseChannel::GetCorsMode(uint32_t* aMode) { HttpBaseChannel::GetRequestMode(RequestMode* aMode) {
*aMode = mCorsMode; *aMode = mRequestMode;
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
HttpBaseChannel::SetCorsMode(uint32_t aMode) { HttpBaseChannel::SetRequestMode(RequestMode aMode) {
mCorsMode = aMode; MOZ_ASSERT(aMode != RequestMode::EndGuard_);
mRequestMode = aMode;
return NS_OK; return NS_OK;
} }
@@ -4665,7 +4670,7 @@ nsresult HttpBaseChannel::SetupReplacementChannel(nsIURI* newURI,
// convey the User-Agent header value // convey the User-Agent header value
// since we might be setting custom user agent from DevTools. // since we might be setting custom user agent from DevTools.
if (httpInternal && mCorsMode == CORS_MODE_NO_CORS && if (httpInternal && mRequestMode == RequestMode::No_cors &&
redirectType == ReplacementReason::Redirect) { redirectType == ReplacementReason::Redirect) {
nsAutoCString oldUserAgent; nsAutoCString oldUserAgent;
nsresult hasHeader = nsresult hasHeader =
@@ -4750,8 +4755,8 @@ nsresult HttpBaseChannel::SetupReplacementChannel(nsIURI* newURI,
MOZ_ASSERT(NS_SUCCEEDED(rv)); MOZ_ASSERT(NS_SUCCEEDED(rv));
} }
// Preserve CORS mode flag. // Preserve Request mode.
rv = httpInternal->SetCorsMode(mCorsMode); rv = httpInternal->SetRequestMode(mRequestMode);
MOZ_ASSERT(NS_SUCCEEDED(rv)); MOZ_ASSERT(NS_SUCCEEDED(rv));
// Preserve Redirect mode flag. // Preserve Redirect mode flag.

View File

@@ -294,8 +294,8 @@ class HttpBaseChannel : public nsHashPropertyBag,
NS_IMETHOD GetLastModifiedTime(PRTime* lastModifiedTime) override; NS_IMETHOD GetLastModifiedTime(PRTime* lastModifiedTime) override;
NS_IMETHOD GetCorsIncludeCredentials(bool* aInclude) override; NS_IMETHOD GetCorsIncludeCredentials(bool* aInclude) override;
NS_IMETHOD SetCorsIncludeCredentials(bool aInclude) override; NS_IMETHOD SetCorsIncludeCredentials(bool aInclude) override;
NS_IMETHOD GetCorsMode(uint32_t* aCorsMode) override; NS_IMETHOD GetRequestMode(dom::RequestMode* aRequestMode) override;
NS_IMETHOD SetCorsMode(uint32_t aCorsMode) override; NS_IMETHOD SetRequestMode(dom::RequestMode aRequestMode) override;
NS_IMETHOD GetRedirectMode(uint32_t* aRedirectMode) override; NS_IMETHOD GetRedirectMode(uint32_t* aRedirectMode) override;
NS_IMETHOD SetRedirectMode(uint32_t aRedirectMode) override; NS_IMETHOD SetRedirectMode(uint32_t aRedirectMode) override;
NS_IMETHOD GetFetchCacheMode(uint32_t* aFetchCacheMode) override; NS_IMETHOD GetFetchCacheMode(uint32_t* aFetchCacheMode) override;
@@ -868,7 +868,7 @@ class HttpBaseChannel : public nsHashPropertyBag,
uint32_t mContentDispositionHint; uint32_t mContentDispositionHint;
uint32_t mCorsMode; dom::RequestMode mRequestMode;
uint32_t mRedirectMode; uint32_t mRedirectMode;
// If this channel was created as the result of a redirect, then this value // If this channel was created as the result of a redirect, then this value

View File

@@ -2168,7 +2168,7 @@ nsresult HttpChannelChild::ContinueAsyncOpen() {
EnsureRequestContextID(); EnsureRequestContextID();
openArgs.requestContextID() = mRequestContextID; openArgs.requestContextID() = mRequestContextID;
openArgs.corsMode() = mCorsMode; openArgs.requestMode() = mRequestMode;
openArgs.redirectMode() = mRedirectMode; openArgs.redirectMode() = mRedirectMode;
openArgs.channelId() = mChannelId; openArgs.channelId() = mChannelId;

View File

@@ -133,7 +133,7 @@ bool HttpChannelParent::Init(const HttpChannelCreationArgs& aArgs) {
a.bypassProxy(), a.tlsFlags(), a.loadInfo(), a.cacheKey(), a.bypassProxy(), a.tlsFlags(), a.loadInfo(), a.cacheKey(),
a.requestContextID(), a.preflightArgs(), a.initialRwin(), a.requestContextID(), a.preflightArgs(), a.initialRwin(),
a.blockAuthPrompt(), a.allowStaleCacheContent(), a.blockAuthPrompt(), a.allowStaleCacheContent(),
a.preferCacheLoadOverBypass(), a.contentTypeHint(), a.corsMode(), a.preferCacheLoadOverBypass(), a.contentTypeHint(), a.requestMode(),
a.redirectMode(), a.channelId(), a.integrityMetadata(), a.redirectMode(), a.channelId(), a.integrityMetadata(),
a.contentWindowId(), a.preferredAlternativeTypes(), a.contentWindowId(), a.preferredAlternativeTypes(),
a.topBrowsingContextId(), a.launchServiceWorkerStart(), a.topBrowsingContextId(), a.launchServiceWorkerStart(),
@@ -371,7 +371,7 @@ bool HttpChannelParent::DoAsyncOpen(
const Maybe<CorsPreflightArgs>& aCorsPreflightArgs, const Maybe<CorsPreflightArgs>& aCorsPreflightArgs,
const uint32_t& aInitialRwin, const bool& aBlockAuthPrompt, const uint32_t& aInitialRwin, const bool& aBlockAuthPrompt,
const bool& aAllowStaleCacheContent, const bool& aPreferCacheLoadOverBypass, const bool& aAllowStaleCacheContent, const bool& aPreferCacheLoadOverBypass,
const nsCString& aContentTypeHint, const uint32_t& aCorsMode, const nsCString& aContentTypeHint, const dom::RequestMode& aRequestMode,
const uint32_t& aRedirectMode, const uint64_t& aChannelId, const uint32_t& aRedirectMode, const uint64_t& aChannelId,
const nsString& aIntegrityMetadata, const uint64_t& aContentWindowId, const nsString& aIntegrityMetadata, const uint64_t& aContentWindowId,
const nsTArray<PreferredAlternativeDataTypeParams>& const nsTArray<PreferredAlternativeDataTypeParams>&
@@ -425,7 +425,7 @@ bool HttpChannelParent::DoAsyncOpen(
} }
// Set attributes needed to create a FetchEvent from this channel. // Set attributes needed to create a FetchEvent from this channel.
httpChannel->SetCorsMode(aCorsMode); httpChannel->SetRequestMode(aRequestMode);
httpChannel->SetRedirectMode(aRedirectMode); httpChannel->SetRedirectMode(aRedirectMode);
// Set the channelId allocated in child to the parent instance // Set the channelId allocated in child to the parent instance

View File

@@ -150,7 +150,7 @@ class HttpChannelParent final : public nsIInterfaceRequestor,
const uint32_t& aInitialRwin, const bool& aBlockAuthPrompt, const uint32_t& aInitialRwin, const bool& aBlockAuthPrompt,
const bool& aAllowStaleCacheContent, const bool& aAllowStaleCacheContent,
const bool& aPreferCacheLoadOverBypass, const nsCString& aContentTypeHint, const bool& aPreferCacheLoadOverBypass, const nsCString& aContentTypeHint,
const uint32_t& aCorsMode, const uint32_t& aRedirectMode, const dom::RequestMode& aRequestMode, const uint32_t& aRedirectMode,
const uint64_t& aChannelId, const nsString& aIntegrityMetadata, const uint64_t& aChannelId, const nsString& aIntegrityMetadata,
const uint64_t& aContentWindowId, const uint64_t& aContentWindowId,
const nsTArray<PreferredAlternativeDataTypeParams>& const nsTArray<PreferredAlternativeDataTypeParams>&

View File

@@ -51,6 +51,7 @@
#include "mozilla/StaticPrefs_dom.h" #include "mozilla/StaticPrefs_dom.h"
#include "mozilla/dom/nsHTTPSOnlyUtils.h" #include "mozilla/dom/nsHTTPSOnlyUtils.h"
#include "mozilla/dom/ReferrerInfo.h" #include "mozilla/dom/ReferrerInfo.h"
#include "mozilla/dom/RequestBinding.h"
#include <algorithm> #include <algorithm>
using namespace mozilla; using namespace mozilla;
@@ -928,7 +929,7 @@ nsresult nsCORSListenerProxy::UpdateChannel(nsIChannel* aChannel,
// can't return early on failure. // can't return early on failure.
nsCOMPtr<nsIHttpChannelInternal> internal = do_QueryInterface(aChannel); nsCOMPtr<nsIHttpChannelInternal> internal = do_QueryInterface(aChannel);
if (internal) { if (internal) {
rv = internal->SetCorsMode(nsIHttpChannelInternal::CORS_MODE_CORS); rv = internal->SetRequestMode(dom::RequestMode::Cors);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = internal->SetCorsIncludeCredentials(mWithCredentials); rv = internal->SetCorsIncludeCredentials(mWithCredentials);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);

View File

@@ -16,6 +16,9 @@ namespace net {
class nsHttpConnectionInfo; class nsHttpConnectionInfo;
class WebSocketConnectionBase; class WebSocketConnectionBase;
} }
namespace dom {
enum class RequestMode : uint8_t;
}
} }
%} %}
[ptr] native StringArray(nsTArray<nsCString>); [ptr] native StringArray(nsTArray<nsCString>);
@@ -23,6 +26,7 @@ class WebSocketConnectionBase;
[ref] native securityMessagesArray(nsCOMArray<nsISecurityConsoleMessage>); [ref] native securityMessagesArray(nsCOMArray<nsISecurityConsoleMessage>);
native TimeStamp(mozilla::TimeStamp); native TimeStamp(mozilla::TimeStamp);
native RequestMode(mozilla::dom::RequestMode);
interface nsIAsyncInputStream; interface nsIAsyncInputStream;
interface nsIAsyncOutputStream; interface nsIAsyncOutputStream;
@@ -305,14 +309,10 @@ interface nsIHttpChannelInternal : nsISupports
*/ */
[must_use] attribute boolean corsIncludeCredentials; [must_use] attribute boolean corsIncludeCredentials;
const unsigned long CORS_MODE_SAME_ORIGIN = 0;
const unsigned long CORS_MODE_NO_CORS = 1;
const unsigned long CORS_MODE_CORS = 2;
const unsigned long CORS_MODE_NAVIGATE = 3;
/** /**
* Set by nsCORSListenerProxy to indicate CORS load type. Defaults to CORS_MODE_NO_CORS. * Set by nsCORSListenerProxy to indicate CORS load type. Defaults to CORS_MODE_NO_CORS.
*/ */
[must_use] attribute unsigned long corsMode; [must_use, noscript] attribute RequestMode requestMode;
const unsigned long REDIRECT_MODE_FOLLOW = 0; const unsigned long REDIRECT_MODE_FOLLOW = 0;
const unsigned long REDIRECT_MODE_ERROR = 1; const unsigned long REDIRECT_MODE_ERROR = 1;