Bug 1214305 - Part 3: Add a nsIInterceptedChannel.secureUpgradedChannelURI helper; r=jdm

This commit is contained in:
Ehsan Akhgari 2015-11-02 11:27:00 -05:00
parent 1295fc0d03
commit 03d8835f92
4 changed files with 50 additions and 1 deletions

View File

@ -45,6 +45,12 @@ InterceptedJARChannel::GetChannel(nsIChannel** aChannel)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
InterceptedJARChannel::GetSecureUpgradedChannelURI(nsIURI** aURI)
{
return mChannel->GetURI(aURI);
}
NS_IMETHODIMP NS_IMETHODIMP
InterceptedJARChannel::ResetInterception() InterceptedJARChannel::ResetInterception()
{ {

View File

@ -29,7 +29,7 @@ class ChannelInfo;
* which do not implement nsIChannel. * which do not implement nsIChannel.
*/ */
[scriptable, uuid(231bb567-90e1-4973-9728-7dab93ab29a8)] [scriptable, uuid(f4b82975-6a86-4cc4-87fe-9a1fd430c86d)]
interface nsIInterceptedChannel : nsISupports interface nsIInterceptedChannel : nsISupports
{ {
/** /**
@ -76,6 +76,12 @@ interface nsIInterceptedChannel : nsISupports
*/ */
readonly attribute nsIChannel channel; readonly attribute nsIChannel channel;
/**
* The URL of the underlying channel object, corrected for a potential
* secure upgrade.
*/
readonly attribute nsIURI secureUpgradedChannelURI;
/** /**
* This method allows to override the channel info for the channel. * This method allows to override the channel info for the channel.
*/ */

View File

@ -118,6 +118,21 @@ InterceptedChannelBase::GetConsoleReportCollector(nsIConsoleReportCollector** aC
return NS_OK; return NS_OK;
} }
/* static */
already_AddRefed<nsIURI>
InterceptedChannelBase::SecureUpgradeChannelURI(nsIChannel* aChannel)
{
nsCOMPtr<nsIURI> uri;
nsresult rv = aChannel->GetURI(getter_AddRefs(uri));
NS_ENSURE_SUCCESS(rv, nullptr);
nsCOMPtr<nsIURI> upgradedURI;
rv = HttpBaseChannel::GetSecureUpgradedURI(uri, getter_AddRefs(upgradedURI));
NS_ENSURE_SUCCESS(rv, nullptr);
return upgradedURI.forget();
}
InterceptedChannelChrome::InterceptedChannelChrome(nsHttpChannel* aChannel, InterceptedChannelChrome::InterceptedChannelChrome(nsHttpChannel* aChannel,
nsINetworkInterceptController* aController, nsINetworkInterceptController* aController,
nsICacheEntry* aEntry) nsICacheEntry* aEntry)
@ -309,6 +324,12 @@ InterceptedChannelChrome::GetInternalContentPolicyType(nsContentPolicyType* aPol
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
InterceptedChannelChrome::GetSecureUpgradedChannelURI(nsIURI** aURI)
{
return mChannel->GetURI(aURI);
}
InterceptedChannelContent::InterceptedChannelContent(HttpChannelChild* aChannel, InterceptedChannelContent::InterceptedChannelContent(HttpChannelChild* aChannel,
nsINetworkInterceptController* aController, nsINetworkInterceptController* aController,
InterceptStreamListener* aListener) InterceptStreamListener* aListener)
@ -455,5 +476,16 @@ InterceptedChannelContent::GetInternalContentPolicyType(nsContentPolicyType* aPo
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
InterceptedChannelContent::GetSecureUpgradedChannelURI(nsIURI** aURI)
{
nsCOMPtr<nsIURI> uri = SecureUpgradeChannelURI(mChannel);
if (uri) {
uri.forget(aURI);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
} // namespace net } // namespace net
} // namespace mozilla } // namespace mozilla

View File

@ -55,6 +55,9 @@ public:
NS_IMETHOD GetResponseBody(nsIOutputStream** aOutput) override; NS_IMETHOD GetResponseBody(nsIOutputStream** aOutput) override;
NS_IMETHOD GetConsoleReportCollector(nsIConsoleReportCollector** aCollectorOut) override; NS_IMETHOD GetConsoleReportCollector(nsIConsoleReportCollector** aCollectorOut) override;
static already_AddRefed<nsIURI>
SecureUpgradeChannelURI(nsIChannel* aChannel);
}; };
class InterceptedChannelChrome : public InterceptedChannelBase class InterceptedChannelChrome : public InterceptedChannelBase
@ -78,6 +81,7 @@ public:
NS_IMETHOD ResetInterception() override; NS_IMETHOD ResetInterception() override;
NS_IMETHOD FinishSynthesizedResponse(const nsACString& aFinalURLSpec) override; NS_IMETHOD FinishSynthesizedResponse(const nsACString& aFinalURLSpec) override;
NS_IMETHOD GetChannel(nsIChannel** aChannel) override; NS_IMETHOD GetChannel(nsIChannel** aChannel) override;
NS_IMETHOD GetSecureUpgradedChannelURI(nsIURI** aURI) override;
NS_IMETHOD SynthesizeStatus(uint16_t aStatus, const nsACString& aReason) override; NS_IMETHOD SynthesizeStatus(uint16_t aStatus, const nsACString& aReason) override;
NS_IMETHOD SynthesizeHeader(const nsACString& aName, const nsACString& aValue) override; NS_IMETHOD SynthesizeHeader(const nsACString& aName, const nsACString& aValue) override;
NS_IMETHOD Cancel(nsresult aStatus) override; NS_IMETHOD Cancel(nsresult aStatus) override;
@ -106,6 +110,7 @@ public:
NS_IMETHOD ResetInterception() override; NS_IMETHOD ResetInterception() override;
NS_IMETHOD FinishSynthesizedResponse(const nsACString& aFinalURLSpec) override; NS_IMETHOD FinishSynthesizedResponse(const nsACString& aFinalURLSpec) override;
NS_IMETHOD GetChannel(nsIChannel** aChannel) override; NS_IMETHOD GetChannel(nsIChannel** aChannel) override;
NS_IMETHOD GetSecureUpgradedChannelURI(nsIURI** aURI) override;
NS_IMETHOD SynthesizeStatus(uint16_t aStatus, const nsACString& aReason) override; NS_IMETHOD SynthesizeStatus(uint16_t aStatus, const nsACString& aReason) override;
NS_IMETHOD SynthesizeHeader(const nsACString& aName, const nsACString& aValue) override; NS_IMETHOD SynthesizeHeader(const nsACString& aName, const nsACString& aValue) override;
NS_IMETHOD Cancel(nsresult aStatus) override; NS_IMETHOD Cancel(nsresult aStatus) override;