Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -r ee134c770558 netwerk/protocol/http/HttpChannelChild.cpp
- --- a/netwerk/protocol/http/HttpChannelChild.cpp Wed Dec 05 12:32:09 2012 -0800
- +++ b/netwerk/protocol/http/HttpChannelChild.cpp Wed Dec 05 21:51:49 2012 +0000
- @@ -1054,15 +1054,16 @@
- URIParams uri;
- SerializeURI(mURI, uri);
- - OptionalURIParams originalURI, documentURI, referrer;
- + OptionalURIParams originalURI, documentURI, referrer, redirectURI;
- SerializeURI(mOriginalURI, originalURI);
- SerializeURI(mDocumentURI, documentURI);
- SerializeURI(mReferrer, referrer);
- + SerializeURI(mInternalRedirectURI, redirectURI);
- OptionalInputStreamParams uploadStream;
- SerializeInputStream(mUploadStream, uploadStream);
- - SendAsyncOpen(uri, originalURI, documentURI, referrer, mLoadFlags,
- + SendAsyncOpen(uri, originalURI, documentURI, referrer, redirectURI, mLoadFlags,
- mClientSetRequestHeaders, mRequestHead.Method(), uploadStream,
- mUploadStreamHasHeaders, mPriority, mRedirectionLimit,
- mAllowPipelining, mForceAllowThirdPartyCookie, mSendResumeAt,
- @@ -1105,6 +1106,18 @@
- DROP_DEAD();
- }
- +NS_IMETHODIMP
- +HttpChannelChild::RedirectTo(nsIURI *uri)
- +{
- + // We can only redirect unopened channels
- + NS_ENSURE_TRUE(!mIPCOpen, NS_ERROR_ALREADY_OPENED);
- +
- + // The redirect is stored internally for use in AsyncOpen
- + mInternalRedirectURI = uri;
- +
- + return NS_OK;
- +}
- +
- // The next four _should_ be implemented, but we need to figure out how
- // to transfer the data from the chrome process first.
- diff -r ee134c770558 netwerk/protocol/http/HttpChannelChild.h
- --- a/netwerk/protocol/http/HttpChannelChild.h Wed Dec 05 12:32:09 2012 -0800
- +++ b/netwerk/protocol/http/HttpChannelChild.h Wed Dec 05 21:51:49 2012 +0000
- @@ -75,6 +75,7 @@
- NS_IMETHOD GetLocalPort(int32_t* port);
- NS_IMETHOD GetRemoteAddress(nsACString& addr);
- NS_IMETHOD GetRemotePort(int32_t* port);
- + NS_IMETHOD RedirectTo(nsIURI *uri);
- // nsISupportsPriority
- NS_IMETHOD SetPriority(int32_t value);
- // nsIResumableChannel
- @@ -125,6 +126,7 @@
- RequestHeaderTuples mClientSetRequestHeaders;
- nsCOMPtr<nsIChildChannel> mRedirectChannelChild;
- nsCOMPtr<nsISupports> mSecurityInfo;
- + nsCOMPtr<nsIURI> mInternalRedirectURI;
- bool mIsFromCache;
- bool mCacheEntryAvailable;
- diff -r ee134c770558 netwerk/protocol/http/HttpChannelParent.cpp
- --- a/netwerk/protocol/http/HttpChannelParent.cpp Wed Dec 05 12:32:09 2012 -0800
- +++ b/netwerk/protocol/http/HttpChannelParent.cpp Wed Dec 05 21:51:49 2012 +0000
- @@ -124,6 +124,7 @@
- const OptionalURIParams& aOriginalURI,
- const OptionalURIParams& aDocURI,
- const OptionalURIParams& aReferrerURI,
- + const OptionalURIParams& aInternalRedirectURI,
- const uint32_t& loadFlags,
- const RequestHeaderTuples& requestHeaders,
- const nsHttpAtom& requestMethod,
- @@ -144,6 +145,7 @@
- nsCOMPtr<nsIURI> originalUri = DeserializeURI(aOriginalURI);
- nsCOMPtr<nsIURI> docUri = DeserializeURI(aDocURI);
- nsCOMPtr<nsIURI> referrerUri = DeserializeURI(aReferrerURI);
- + nsCOMPtr<nsIURI> internalRedirectUri = DeserializeURI(aInternalRedirectURI);
- nsCString uriSpec;
- uri->GetSpec(uriSpec);
- @@ -174,6 +176,8 @@
- httpChan->SetDocumentURI(docUri);
- if (referrerUri)
- httpChan->SetReferrerInternal(referrerUri);
- + if (internalRedirectUri)
- + httpChan->RedirectTo(internalRedirectUri);
- if (loadFlags != nsIRequest::LOAD_NORMAL)
- httpChan->SetLoadFlags(loadFlags);
- diff -r ee134c770558 netwerk/protocol/http/HttpChannelParent.h
- --- a/netwerk/protocol/http/HttpChannelParent.h Wed Dec 05 12:32:09 2012 -0800
- +++ b/netwerk/protocol/http/HttpChannelParent.h Wed Dec 05 21:51:49 2012 +0000
- @@ -52,6 +52,7 @@
- const OptionalURIParams& originalUri,
- const OptionalURIParams& docUri,
- const OptionalURIParams& referrerUri,
- + const OptionalURIParams& internalRedirectUri,
- const uint32_t& loadFlags,
- const RequestHeaderTuples& requestHeaders,
- const nsHttpAtom& requestMethod,
- diff -r ee134c770558 netwerk/protocol/http/PHttpChannel.ipdl
- --- a/netwerk/protocol/http/PHttpChannel.ipdl Wed Dec 05 12:32:09 2012 -0800
- +++ b/netwerk/protocol/http/PHttpChannel.ipdl Wed Dec 05 21:51:49 2012 +0000
- @@ -37,6 +37,7 @@
- OptionalURIParams original,
- OptionalURIParams doc,
- OptionalURIParams referrer,
- + OptionalURIParams internalRedirect,
- uint32_t loadFlags,
- RequestHeaderTuples requestHeaders,
- nsHttpAtom requestMethod,
- diff -r ee134c770558 netwerk/protocol/http/nsHttpChannel.cpp
- --- a/netwerk/protocol/http/nsHttpChannel.cpp Wed Dec 05 12:32:09 2012 -0800
- +++ b/netwerk/protocol/http/nsHttpChannel.cpp Wed Dec 05 21:51:49 2012 +0000
- @@ -35,6 +35,7 @@
- #include "base/compiler_specific.h"
- #include "NullHttpTransaction.h"
- #include "mozilla/Attributes.h"
- +#include "mozilla/net/HttpBaseChannel.h"
- namespace mozilla { namespace net {
- @@ -1545,18 +1546,17 @@
- return;
- }
- - nsresult rv = AsyncRedirectChannelToHttps();
- + nsresult rv = InternalRedirectChannelToHttps();
- if (NS_FAILED(rv))
- - ContinueAsyncRedirectChannelToHttps(rv);
- + ContinueInternalRedirectChannelToURI(rv);
- }
- nsresult
- -nsHttpChannel::AsyncRedirectChannelToHttps()
- +nsHttpChannel::InternalRedirectChannelToHttps()
- {
- nsresult rv = NS_OK;
- LOG(("nsHttpChannel::HandleAsyncRedirectChannelToHttps() [STS]\n"));
- - nsCOMPtr<nsIChannel> newChannel;
- nsCOMPtr<nsIURI> upgradedURI;
- rv = mURI->Clone(getter_AddRefs(upgradedURI));
- @@ -1578,6 +1578,48 @@
- else
- upgradedURI->SetPort(oldPort);
- + return InternalRedirectChannelToURI(upgradedURI);
- +}
- +
- +NS_IMETHODIMP
- +nsHttpChannel::RedirectTo(nsIURI *newURI)
- +{
- + // We can only redirect unopened channels
- + NS_ENSURE_TRUE(!mRequestObserversCalled, NS_ERROR_ALREADY_OPENED);
- +
- + // The redirect is stored internally for use in AsyncOpen
- + mInternalRedirectURI = newURI;
- +
- + return NS_OK;
- +}
- +
- +void
- +nsHttpChannel::HandleAsyncInternalRedirect()
- +{
- + NS_PRECONDITION(!mCallOnResume, "How did that happen?");
- + NS_PRECONDITION(mInternalRedirectURI, "How did that happen?");
- +
- + if (mSuspendCount) {
- + LOG(("Waiting until resume to do async API redirect [this=%p]\n", this));
- + mCallOnResume = &nsHttpChannel::HandleAsyncInternalRedirect;
- + return;
- + }
- +
- + nsresult rv = InternalRedirectChannelToURI(mInternalRedirectURI);
- + if (NS_FAILED(rv))
- + ContinueInternalRedirectChannelToURI(rv);
- +
- + return;
- +}
- +
- +nsresult
- +nsHttpChannel::InternalRedirectChannelToURI(nsIURI *upgradedURI)
- +{
- + nsresult rv = NS_OK;
- + LOG(("nsHttpChannel::InternalRedirectChannelToURI()\n"));
- +
- + nsCOMPtr<nsIChannel> newChannel;
- +
- nsCOMPtr<nsIIOService> ioService;
- rv = gHttpHandler->GetIOService(getter_AddRefs(ioService));
- NS_ENSURE_SUCCESS(rv, rv);
- @@ -1593,7 +1635,7 @@
- uint32_t flags = nsIChannelEventSink::REDIRECT_PERMANENT;
- PushRedirectAsyncFunc(
- - &nsHttpChannel::ContinueAsyncRedirectChannelToHttps);
- + &nsHttpChannel::ContinueInternalRedirectChannelToURI);
- rv = gHttpHandler->AsyncOnChannelRedirect(this, newChannel, flags);
- if (NS_SUCCEEDED(rv))
- @@ -1601,15 +1643,18 @@
- if (NS_FAILED(rv)) {
- AutoRedirectVetoNotifier notifier(this);
- +
- + /* Remove the async call to ContinueInternalRedirectChannelToURI().
- + * It is called directly by our callers upon return (to clean up
- + * the failed redirect). */
- PopRedirectAsyncFunc(
- - &nsHttpChannel::ContinueAsyncRedirectChannelToHttps);
- + &nsHttpChannel::ContinueInternalRedirectChannelToURI);
- }
- return rv;
- }
- -
- nsresult
- -nsHttpChannel::ContinueAsyncRedirectChannelToHttps(nsresult rv)
- +nsHttpChannel::ContinueInternalRedirectChannelToURI(nsresult rv)
- {
- if (NS_SUCCEEDED(rv))
- rv = OpenRedirectChannel(rv);
- @@ -4337,6 +4382,12 @@
- if (mLoadGroup)
- mLoadGroup->AddRequest(this, nullptr);
- + // Check to see if we should redirect this channel elsewhere by
- + // nsIHttpChannel.redirectTo API request
- + if (mInternalRedirectURI) {
- + return AsyncCall(&nsHttpChannel::HandleAsyncInternalRedirect);
- + }
- +
- // record asyncopen time unconditionally and clear it if we
- // don't want it after OnModifyRequest() weighs in. But waiting for
- // that to complete would mean we don't include proxy resolution in the
- diff -r ee134c770558 netwerk/protocol/http/nsHttpChannel.h
- --- a/netwerk/protocol/http/nsHttpChannel.h Wed Dec 05 12:32:09 2012 -0800
- +++ b/netwerk/protocol/http/nsHttpChannel.h Wed Dec 05 21:51:49 2012 +0000
- @@ -108,6 +108,8 @@
- // nsIChannel
- NS_IMETHOD GetSecurityInfo(nsISupports **aSecurityInfo);
- NS_IMETHOD AsyncOpen(nsIStreamListener *listener, nsISupports *aContext);
- + // nsIHttpChannel
- + NS_IMETHOD RedirectTo(nsIURI *newURI);
- // nsIHttpChannelInternal
- NS_IMETHOD SetupFallbackChannel(const char *aFallbackKey);
- // nsISupportsPriority
- @@ -182,12 +184,14 @@
- // redirection specific methods
- void HandleAsyncRedirect();
- + void HandleAsyncInternalRedirect();
- nsresult ContinueHandleAsyncRedirect(nsresult);
- void HandleAsyncNotModified();
- void HandleAsyncFallback();
- nsresult ContinueHandleAsyncFallback(nsresult);
- nsresult PromptTempRedirect();
- - virtual nsresult SetupReplacementChannel(nsIURI *, nsIChannel *, bool preserveMethod);
- + nsresult InternalRedirectChannelToURI(nsIURI *);
- + virtual nsresult SetupReplacementChannel(nsIURI *, nsIChannel *, bool preserveMethod);
- // proxy specific methods
- nsresult ProxyFailover();
- @@ -242,8 +246,8 @@
- nsresult DoAuthRetry(nsAHttpConnection *);
- void HandleAsyncRedirectChannelToHttps();
- - nsresult AsyncRedirectChannelToHttps();
- - nsresult ContinueAsyncRedirectChannelToHttps(nsresult rv);
- + nsresult InternalRedirectChannelToHttps();
- + nsresult ContinueInternalRedirectChannelToURI(nsresult rv);
- nsresult OpenRedirectChannel(nsresult rv);
- /**
- @@ -323,6 +327,7 @@
- friend class HttpCacheQuery;
- nsCOMPtr<nsIURI> mRedirectURI;
- uint32_t mRedirectType;
- diff -r ee134c770558 netwerk/protocol/http/nsIHttpChannel.idl
- --- a/netwerk/protocol/http/nsIHttpChannel.idl Wed Dec 05 12:32:09 2012 -0800
- +++ b/netwerk/protocol/http/nsIHttpChannel.idl Wed Dec 05 21:51:49 2012 +0000
- @@ -257,4 +257,16 @@
- * has been received (before onStartRequest).
- */
- boolean isNoCacheResponse();
- +
- + /**
- + * Instructs the channel to immediately redirect to a new destination.
- + * Can only be called on channels not yet opened.
- + *
- + * This method provides no explicit conflict resolution. The last
- + * caller to call it wins.
- + *
- + * @throws NS_ERROR_ALREADY_OPENED if called after the channel
- + * has been opened.
- + */
- + void redirectTo(in nsIURI aNewURI);
- };
- diff -r ee134c770558 netwerk/protocol/viewsource/nsViewSourceChannel.cpp
- --- a/netwerk/protocol/viewsource/nsViewSourceChannel.cpp Wed Dec 05 12:32:09 2012 -0800
- +++ b/netwerk/protocol/viewsource/nsViewSourceChannel.cpp Wed Dec 05 21:51:49 2012 +0000
- @@ -680,4 +680,12 @@
- {
- return !mHttpChannel ? NS_ERROR_NULL_POINTER :
- mHttpChannel->IsNoCacheResponse(_retval);
- -}
- +}
- +
- +NS_IMETHODIMP
- +nsViewSourceChannel::RedirectTo(nsIURI *uri)
- +{
- + return !mHttpChannel ? NS_ERROR_NULL_POINTER :
- + mHttpChannel->RedirectTo(uri);
- +}
- +
- diff -r ee134c770558 netwerk/test/unit/xpcshell.ini
- --- a/netwerk/test/unit/xpcshell.ini Wed Dec 05 12:32:09 2012 -0800
- +++ b/netwerk/test/unit/xpcshell.ini Wed Dec 05 21:51:49 2012 +0000
- @@ -174,6 +174,7 @@
- [test_redirect-caching_passing.js]
- [test_redirect_canceled.js]
- [test_redirect_failure.js]
- +[test_redirect_from_script.js]
- [test_redirect_passing.js]
- [test_redirect_loop.js]
- [test_redirect_baduri.js]
- diff -r ee134c770558 netwerk/test/unit_ipc/xpcshell.ini
- --- a/netwerk/test/unit_ipc/xpcshell.ini Wed Dec 05 12:32:09 2012 -0800
- +++ b/netwerk/test/unit_ipc/xpcshell.ini Wed Dec 05 21:51:49 2012 +0000
- @@ -19,6 +19,7 @@
- [test_redirect-caching_passing_wrap.js]
- [test_redirect_canceled_wrap.js]
- [test_redirect_failure_wrap.js]
- +[test_redirect_from_script_wrap.js]
- [test_redirect_passing_wrap.js]
- [test_reentrancy_wrap.js]
- [test_resumable_channel_wrap.js]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement