Bug 1215140 P10 Avoid AddRef'ing the nsIChannel OMT. r=bz

This commit is contained in:
Ben Kelly 2015-10-29 19:53:25 -07:00
Родитель e3bee41820
Коммит 69c8a55480
6 изменённых файлов: 54 добавлений и 4 удалений

Просмотреть файл

@ -109,9 +109,11 @@ AsyncLog(nsIInterceptedChannel *aInterceptedChannel,
const nsACString& aMessageName, const nsTArray<nsString>& aParams)
{
MOZ_ASSERT(aInterceptedChannel);
nsCOMPtr<nsIChannel> inner;
aInterceptedChannel->GetChannel(getter_AddRefs(inner));
nsCOMPtr<nsIConsoleReportCollector> reporter = do_QueryInterface(inner);
// Since the intercepted channel is kept alive and paused while handling
// the FetchEvent, we are guaranteed the reporter is stable on the worker
// thread.
nsIConsoleReportCollector* reporter =
aInterceptedChannel->GetConsoleReportCollector();
if (reporter) {
reporter->AddConsoleReport(nsIScriptError::errorFlag,
NS_LITERAL_CSTRING("Service Worker Interception"),

Просмотреть файл

@ -146,3 +146,9 @@ InterceptedJARChannel::NotifyController()
}
mController = nullptr;
}
nsIConsoleReportCollector*
InterceptedJARChannel::GetConsoleReportCollector() const
{
return nullptr;
}

Просмотреть файл

@ -53,6 +53,9 @@ public:
NS_DECL_NSIINTERCEPTEDCHANNEL
void NotifyController();
virtual nsIConsoleReportCollector*
GetConsoleReportCollector() const override;
};
} // namespace net

Просмотреть файл

@ -11,6 +11,7 @@ interface nsIOutputStream;
interface nsIURI;
%{C++
#include "nsIConsoleReportCollector.h"
namespace mozilla {
namespace dom {
class ChannelInfo;
@ -27,7 +28,7 @@ class ChannelInfo;
* which do not implement nsIChannel.
*/
[scriptable, uuid(afe6aae6-a80d-405b-856e-df36c19bf3c8)]
[scriptable, uuid(ea78e439-cc42-4b2d-a42b-85ab55a149d1)]
interface nsIInterceptedChannel : nsISupports
{
/**
@ -85,6 +86,18 @@ interface nsIInterceptedChannel : nsISupports
*/
[noscript]
readonly attribute nsContentPolicyType internalContentPolicyType;
%{C++
// Allow access to the inner channel as a ConsoleReportCollector off
// the main thread. Pure C++ method here to avoid requiring an
// AddRef() during QI. Callers should not save the returned pointer.
// May return nullptr.
//
// Note: Only safe to use OMT prior to resetInterception(),
// finishSynthesizedResponse(), and cancel().
virtual nsIConsoleReportCollector*
GetConsoleReportCollector() const = 0;
%}
};
/**

Просмотреть файл

@ -134,6 +134,16 @@ InterceptedChannelChrome::NotifyController()
DoNotifyController();
}
nsIConsoleReportCollector*
InterceptedChannelChrome::GetConsoleReportCollector() const
{
// The ConsoleReportCollector should only be used when the inner channel is
// stable. Nothing should try to use it once we return to the main thread
// and clear the inner channel.
MOZ_ASSERT(mChannel);
return mChannel;
}
NS_IMETHODIMP
InterceptedChannelChrome::GetChannel(nsIChannel** aChannel)
{
@ -312,6 +322,16 @@ InterceptedChannelContent::NotifyController()
DoNotifyController();
}
nsIConsoleReportCollector*
InterceptedChannelContent::GetConsoleReportCollector() const
{
// The ConsoleReportCollector should only be used when the inner channel is
// stable. Nothing should try to use it once we return to the main thread
// and clear the inner channel.
MOZ_ASSERT(mChannel);
return mChannel;
}
NS_IMETHODIMP
InterceptedChannelContent::GetChannel(nsIChannel** aChannel)
{

Просмотреть файл

@ -82,6 +82,9 @@ public:
NS_IMETHOD GetInternalContentPolicyType(nsContentPolicyType *aInternalContentPolicyType) override;
virtual void NotifyController() override;
virtual nsIConsoleReportCollector*
GetConsoleReportCollector() const override;
};
class InterceptedChannelContent : public InterceptedChannelBase
@ -110,6 +113,9 @@ public:
NS_IMETHOD GetInternalContentPolicyType(nsContentPolicyType *aInternalContentPolicyType) override;
virtual void NotifyController() override;
virtual nsIConsoleReportCollector*
GetConsoleReportCollector() const override;
};
} // namespace net