michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsCORSListenerProxy_h__ michael@0: #define nsCORSListenerProxy_h__ michael@0: michael@0: #include "nsIStreamListener.h" michael@0: #include "nsIInterfaceRequestor.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsString.h" michael@0: #include "nsIURI.h" michael@0: #include "nsTArray.h" michael@0: #include "nsIInterfaceRequestor.h" michael@0: #include "nsIChannelEventSink.h" michael@0: #include "nsIAsyncVerifyRedirectCallback.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: class nsIURI; michael@0: class nsIParser; michael@0: class nsIPrincipal; michael@0: michael@0: extern bool michael@0: IsValidHTTPToken(const nsCSubstring& aToken); michael@0: michael@0: nsresult michael@0: NS_StartCORSPreflight(nsIChannel* aRequestChannel, michael@0: nsIStreamListener* aListener, michael@0: nsIPrincipal* aPrincipal, michael@0: bool aWithCredentials, michael@0: nsTArray& aACUnsafeHeaders, michael@0: nsIChannel** aPreflightChannel); michael@0: michael@0: class nsCORSListenerProxy MOZ_FINAL : public nsIStreamListener, michael@0: public nsIInterfaceRequestor, michael@0: public nsIChannelEventSink, michael@0: public nsIAsyncVerifyRedirectCallback michael@0: { michael@0: public: michael@0: nsCORSListenerProxy(nsIStreamListener* aOuter, michael@0: nsIPrincipal* aRequestingPrincipal, michael@0: bool aWithCredentials); michael@0: nsCORSListenerProxy(nsIStreamListener* aOuter, michael@0: nsIPrincipal* aRequestingPrincipal, michael@0: bool aWithCredentials, michael@0: const nsCString& aPreflightMethod, michael@0: const nsTArray& aPreflightHeaders); michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIREQUESTOBSERVER michael@0: NS_DECL_NSISTREAMLISTENER michael@0: NS_DECL_NSIINTERFACEREQUESTOR michael@0: NS_DECL_NSICHANNELEVENTSINK michael@0: NS_DECL_NSIASYNCVERIFYREDIRECTCALLBACK michael@0: michael@0: // Must be called at startup. michael@0: static void Startup(); michael@0: michael@0: static void Shutdown(); michael@0: michael@0: nsresult Init(nsIChannel* aChannel, bool aAllowDataURI = false); michael@0: michael@0: private: michael@0: nsresult UpdateChannel(nsIChannel* aChannel, bool aAllowDataURI = false); michael@0: nsresult CheckRequestApproved(nsIRequest* aRequest); michael@0: michael@0: nsCOMPtr mOuterListener; michael@0: // The principal that originally kicked off the request michael@0: nsCOMPtr mRequestingPrincipal; michael@0: // The principal to use for our Origin header ("source origin" in spec terms). michael@0: // This can get changed during redirects, unlike mRequestingPrincipal. michael@0: nsCOMPtr mOriginHeaderPrincipal; michael@0: nsCOMPtr mOuterNotificationCallbacks; michael@0: bool mWithCredentials; michael@0: bool mRequestApproved; michael@0: bool mHasBeenCrossSite; michael@0: bool mIsPreflight; michael@0: nsCString mPreflightMethod; michael@0: nsTArray mPreflightHeaders; michael@0: nsCOMPtr mRedirectCallback; michael@0: nsCOMPtr mOldRedirectChannel; michael@0: nsCOMPtr mNewRedirectChannel; michael@0: }; michael@0: michael@0: #endif