Bug 1199049 - Part 2: Add a channel API for requesting CORS preflights; r=jduell

This commit is contained in:
Ehsan Akhgari 2015-08-21 17:31:56 -04:00
parent a4ac3ec0b4
commit 25a1bb1191
3 changed files with 36 additions and 2 deletions

View File

@ -90,6 +90,8 @@ HttpBaseChannel::HttpBaseChannel()
, mCorsMode(nsIHttpChannelInternal::CORS_MODE_NO_CORS)
, mRedirectMode(nsIHttpChannelInternal::REDIRECT_MODE_FOLLOW)
, mOnStartRequestCalled(false)
, mRequireCORSPreflight(false)
, mWithCredentials(false)
{
LOG(("Creating HttpBaseChannel @%x\n", this));
@ -2826,6 +2828,20 @@ HttpBaseChannel::EnsureSchedulingContextID()
return true;
}
NS_IMETHODIMP
HttpBaseChannel::SetCorsPreflightParameters(const nsTArray<nsCString>& aUnsafeHeaders,
bool aWithCredentials,
nsIPrincipal* aPrincipal)
{
ENSURE_CALLED_BEFORE_CONNECT();
mRequireCORSPreflight = true;
mUnsafeHeaders = aUnsafeHeaders;
mWithCredentials = aWithCredentials;
mPreflightPrincipal = aPrincipal;
return NS_OK;
}
} // namespace net
} // namespace mozilla

View File

@ -201,6 +201,9 @@ public:
NS_IMETHOD SetRedirectMode(uint32_t aRedirectMode) override;
NS_IMETHOD GetTopWindowURI(nsIURI **aTopWindowURI) override;
NS_IMETHOD GetProxyURI(nsIURI **proxyURI) override;
NS_IMETHOD SetCorsPreflightParameters(const nsTArray<nsCString>& unsafeHeaders,
bool aWithCredentials,
nsIPrincipal* aPrincipal) override;
inline void CleanRedirectCacheChainIfNecessary()
{
@ -444,6 +447,11 @@ protected:
nsID mSchedulingContextID;
bool EnsureSchedulingContextID();
bool mRequireCORSPreflight;
bool mWithCredentials;
nsTArray<nsCString> mUnsafeHeaders;
nsCOMPtr<nsIPrincipal> mPreflightPrincipal;
};
// Share some code while working around C++'s absurd inability to handle casting

View File

@ -11,6 +11,7 @@ template<class T> class nsCOMArray;
class nsCString;
%}
[ptr] native StringArray(nsTArray<nsCString>);
[ref] native StringArrayRef(const nsTArray<nsCString>);
[ref] native securityMessagesArray(nsCOMArray<nsISecurityConsoleMessage>);
interface nsIAsyncInputStream;
@ -25,7 +26,7 @@ interface nsIURI;
* The callback interface for nsIHttpChannelInternal::HTTPUpgrade()
*/
[scriptable, uuid(7b48d081-1dc1-4d08-b7a5-81491bf28c0e)]
[scriptable, uuid(5b515449-ab64-4dba-b3cd-da8fc2f83064)]
interface nsIHttpUpgradeListener : nsISupports
{
void onTransportAvailable(in nsISocketTransport aTransport,
@ -38,7 +39,7 @@ interface nsIHttpUpgradeListener : nsISupports
* using any feature exposed by this interface, be aware that this interface
* will change and you will be broken. You have been warned.
*/
[scriptable, uuid(e2eebad8-e51f-473a-bbb7-8e2829376625)]
[scriptable, uuid(46ef729f-4c9b-4084-b9e2-498992a31aee)]
interface nsIHttpChannelInternal : nsISupports
{
@ -264,4 +265,13 @@ interface nsIHttpChannelInternal : nsISupports
* proxies for this channel.
*/
readonly attribute nsIURI proxyURI;
/**
* Make cross-origin CORS loads happen with a CORS preflight, and specify
* the CORS preflight parameters.
*/
[noscript]
void setCorsPreflightParameters(in StringArrayRef unsafeHeaders,
in boolean withCredentials,
in nsIPrincipal preflightPrincipal);
};