Bug 1633935 - P11 Move classification IPC methods back to PHttpChannel. r=mayhemer,necko-reviewers

Bug 1015466 move them from PContent to Pbg since it believes those events are fine
to received before OnStopRequest. Bug 1588241 move it back to PContent since those
events are before OnStartRequest.

Now we're moving OnStartRequest to pBg, so here's another ping-pong time :)

Differential Revision: https://phabricator.services.mozilla.com/D79587
This commit is contained in:
Junior Hsu 2020-06-23 16:58:38 +00:00
Родитель 73b5a6dc72
Коммит c95a90a842
9 изменённых файлов: 289 добавлений и 72 удалений

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

@ -331,6 +331,82 @@ IPCResult HttpBackgroundChannelChild::RecvDivertMessages() {
return IPC_OK();
}
IPCResult HttpBackgroundChannelChild::RecvNotifyClassificationFlags(
const uint32_t& aClassificationFlags, const bool& aIsThirdParty) {
LOG(
("HttpBackgroundChannelChild::RecvNotifyClassificationFlags "
"classificationFlags=%" PRIu32 ", thirdparty=%d [this=%p]\n",
aClassificationFlags, static_cast<int>(aIsThirdParty), this));
MOZ_ASSERT(OnSocketThread());
if (NS_WARN_IF(!mChannelChild)) {
return IPC_OK();
}
// NotifyClassificationFlags has no order dependency to OnStartRequest.
// It this be handled as soon as possible
mChannelChild->ProcessNotifyClassificationFlags(aClassificationFlags,
aIsThirdParty);
return IPC_OK();
}
IPCResult HttpBackgroundChannelChild::RecvNotifyFlashPluginStateChanged(
const nsIHttpChannel::FlashPluginState& aState) {
LOG(
("HttpBackgroundChannelChild::RecvNotifyFlashPluginStateChanged "
"[this=%p]\n",
this));
MOZ_ASSERT(OnSocketThread());
if (NS_WARN_IF(!mChannelChild)) {
return IPC_OK();
}
// NotifyFlashPluginStateChanged has no order dependency to OnStartRequest.
// It this be handled as soon as possible
mChannelChild->ProcessNotifyFlashPluginStateChanged(aState);
return IPC_OK();
}
IPCResult HttpBackgroundChannelChild::RecvSetClassifierMatchedInfo(
const ClassifierInfo& info) {
LOG(("HttpBackgroundChannelChild::RecvSetClassifierMatchedInfo [this=%p]\n",
this));
MOZ_ASSERT(OnSocketThread());
if (NS_WARN_IF(!mChannelChild)) {
return IPC_OK();
}
// SetClassifierMatchedInfo has no order dependency to OnStartRequest.
// It this be handled as soon as possible
mChannelChild->ProcessSetClassifierMatchedInfo(info.list(), info.provider(),
info.fullhash());
return IPC_OK();
}
IPCResult HttpBackgroundChannelChild::RecvSetClassifierMatchedTrackingInfo(
const ClassifierInfo& info) {
LOG(
("HttpBackgroundChannelChild::RecvSetClassifierMatchedTrackingInfo "
"[this=%p]\n",
this));
MOZ_ASSERT(OnSocketThread());
if (NS_WARN_IF(!mChannelChild)) {
return IPC_OK();
}
// SetClassifierMatchedTrackingInfo has no order dependency to OnStartRequest.
// It this be handled as soon as possible
mChannelChild->ProcessSetClassifierMatchedTrackingInfo(info.list(),
info.fullhash());
return IPC_OK();
}
void HttpBackgroundChannelChild::ActorDestroy(ActorDestroyReason aWhy) {
LOG(("HttpBackgroundChannelChild::ActorDestroy[this=%p]\n", this));
// This function might be called during shutdown phase, so OnSocketThread()

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

@ -80,6 +80,16 @@ class HttpBackgroundChannelChild final : public PHttpBackgroundChannelChild {
IPCResult RecvDivertMessages();
IPCResult RecvNotifyClassificationFlags(const uint32_t& aClassificationFlags,
const bool& aIsThirdParty);
IPCResult RecvNotifyFlashPluginStateChanged(
const nsIHttpChannel::FlashPluginState& aState);
IPCResult RecvSetClassifierMatchedInfo(const ClassifierInfo& info);
IPCResult RecvSetClassifierMatchedTrackingInfo(const ClassifierInfo& info);
void ActorDestroy(ActorDestroyReason aWhy) override;
void CreateDataBridge();

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

@ -345,6 +345,133 @@ bool HttpBackgroundChannelParent::OnDiversion() {
return true;
}
bool HttpBackgroundChannelParent::OnNotifyClassificationFlags(
uint32_t aClassificationFlags, bool aIsThirdParty) {
LOG(
("HttpBackgroundChannelParent::OnNotifyClassificationFlags "
"classificationFlags=%" PRIu32 ", thirdparty=%d [this=%p]\n",
aClassificationFlags, static_cast<int>(aIsThirdParty), this));
AssertIsInMainProcess();
if (NS_WARN_IF(!mIPCOpened)) {
return false;
}
if (!IsOnBackgroundThread()) {
MutexAutoLock lock(mBgThreadMutex);
nsresult rv = mBackgroundThread->Dispatch(
NewRunnableMethod<uint32_t, bool>(
"net::HttpBackgroundChannelParent::OnNotifyClassificationFlags",
this, &HttpBackgroundChannelParent::OnNotifyClassificationFlags,
aClassificationFlags, aIsThirdParty),
NS_DISPATCH_NORMAL);
MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
return NS_SUCCEEDED(rv);
}
return SendNotifyClassificationFlags(aClassificationFlags, aIsThirdParty);
}
bool HttpBackgroundChannelParent::OnNotifyFlashPluginStateChanged(
nsIHttpChannel::FlashPluginState aState) {
LOG(
("HttpBackgroundChannelParent::OnNotifyFlashPluginStateChanged "
"[this=%p]\n",
this));
AssertIsInMainProcess();
if (NS_WARN_IF(!mIPCOpened)) {
return false;
}
if (!IsOnBackgroundThread()) {
MutexAutoLock lock(mBgThreadMutex);
RefPtr<HttpBackgroundChannelParent> self = this;
nsresult rv = mBackgroundThread->Dispatch(
NS_NewRunnableFunction(
"net::HttpBackgroundChannelParent::OnNotifyFlashPluginStateChanged",
[self, aState]() {
self->OnNotifyFlashPluginStateChanged(aState);
}),
NS_DISPATCH_NORMAL);
MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
return NS_SUCCEEDED(rv);
}
return SendNotifyFlashPluginStateChanged(aState);
}
bool HttpBackgroundChannelParent::OnSetClassifierMatchedInfo(
const nsACString& aList, const nsACString& aProvider,
const nsACString& aFullHash) {
LOG(("HttpBackgroundChannelParent::OnSetClassifierMatchedInfo [this=%p]\n",
this));
AssertIsInMainProcess();
if (NS_WARN_IF(!mIPCOpened)) {
return false;
}
if (!IsOnBackgroundThread()) {
MutexAutoLock lock(mBgThreadMutex);
nsresult rv = mBackgroundThread->Dispatch(
NewRunnableMethod<const nsCString, const nsCString, const nsCString>(
"net::HttpBackgroundChannelParent::OnSetClassifierMatchedInfo",
this, &HttpBackgroundChannelParent::OnSetClassifierMatchedInfo,
aList, aProvider, aFullHash),
NS_DISPATCH_NORMAL);
MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
return NS_SUCCEEDED(rv);
}
ClassifierInfo info;
info.list() = aList;
info.fullhash() = aFullHash;
info.provider() = aProvider;
return SendSetClassifierMatchedInfo(info);
}
bool HttpBackgroundChannelParent::OnSetClassifierMatchedTrackingInfo(
const nsACString& aLists, const nsACString& aFullHashes) {
LOG(
("HttpBackgroundChannelParent::OnSetClassifierMatchedTrackingInfo "
"[this=%p]\n",
this));
AssertIsInMainProcess();
if (NS_WARN_IF(!mIPCOpened)) {
return false;
}
if (!IsOnBackgroundThread()) {
MutexAutoLock lock(mBgThreadMutex);
nsresult rv = mBackgroundThread->Dispatch(
NewRunnableMethod<const nsCString, const nsCString>(
"net::HttpBackgroundChannelParent::"
"OnSetClassifierMatchedTrackingInfo",
this,
&HttpBackgroundChannelParent::OnSetClassifierMatchedTrackingInfo,
aLists, aFullHashes),
NS_DISPATCH_NORMAL);
MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
return NS_SUCCEEDED(rv);
}
ClassifierInfo info;
info.list() = aLists;
info.fullhash() = aFullHashes;
return SendSetClassifierMatchedTrackingInfo(info);
}
void HttpBackgroundChannelParent::ActorDestroy(ActorDestroyReason aWhy) {
LOG(("HttpBackgroundChannelParent::ActorDestroy [this=%p]\n", this));
AssertIsInMainProcess();

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

@ -70,6 +70,22 @@ class HttpBackgroundChannelParent final : public PHttpBackgroundChannelParent {
// over background channel.
bool OnDiversion();
// To send NotifyClassificationFlags message over background channel.
bool OnNotifyClassificationFlags(uint32_t aClassificationFlags,
bool aIsThirdParty);
// To send NotifyFlashPluginStateChanged message over background channel.
bool OnNotifyFlashPluginStateChanged(nsIHttpChannel::FlashPluginState aState);
// To send SetClassifierMatchedInfo message over background channel.
bool OnSetClassifierMatchedInfo(const nsACString& aList,
const nsACString& aProvider,
const nsACString& aFullHash);
// To send SetClassifierMatchedTrackingInfo message over background channel.
bool OnSetClassifierMatchedTrackingInfo(const nsACString& aLists,
const nsACString& aFullHashes);
protected:
void ActorDestroy(ActorDestroyReason aWhy) override;

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

@ -1804,35 +1804,31 @@ void HttpChannelChild::ProcessFlushedForDiversion() {
true);
}
mozilla::ipc::IPCResult HttpChannelChild::RecvNotifyClassificationFlags(
const uint32_t& aClassificationFlags, const bool& aIsThirdParty) {
void HttpChannelChild::ProcessNotifyClassificationFlags(
uint32_t aClassificationFlags, bool aIsThirdParty) {
LOG(
("HttpChannelChild::RecvNotifyClassificationFlags thirdparty=%d "
("HttpChannelChild::ProcessNotifyClassificationFlags thirdparty=%d "
"flags=%" PRIu32 " [this=%p]\n",
static_cast<int>(aIsThirdParty), aClassificationFlags, this));
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(OnSocketThread());
mEventQ->RunOrEnqueue(new NeckoTargetChannelFunctionEvent(
this, [self = UnsafePtr<HttpChannelChild>(this), aClassificationFlags,
aIsThirdParty] {
aIsThirdParty]() {
self->AddClassificationFlags(aClassificationFlags, aIsThirdParty);
}));
return IPC_OK();
}
mozilla::ipc::IPCResult HttpChannelChild::RecvNotifyFlashPluginStateChanged(
const nsIHttpChannel::FlashPluginState& aState) {
LOG(("HttpChannelChild::RecvNotifyFlashPluginStateChanged [this=%p]\n",
void HttpChannelChild::ProcessNotifyFlashPluginStateChanged(
nsIHttpChannel::FlashPluginState aState) {
LOG(("HttpChannelChild::ProcessNotifyFlashPluginStateChanged [this=%p]\n",
this));
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(OnSocketThread());
mEventQ->RunOrEnqueue(new NeckoTargetChannelFunctionEvent(
this, [self = UnsafePtr<HttpChannelChild>(this), aState] {
this, [self = UnsafePtr<HttpChannelChild>(this), aState]() {
self->SetFlashPluginState(aState);
}));
return IPC_OK();
}
void HttpChannelChild::FlushedForDiversion() {
@ -1851,30 +1847,29 @@ void HttpChannelChild::FlushedForDiversion() {
}
}
mozilla::ipc::IPCResult HttpChannelChild::RecvSetClassifierMatchedInfo(
const ClassifierInfo& aInfo) {
LOG(("HttpChannelChild::RecvSetClassifierMatchedInfo [this=%p]\n", this));
MOZ_ASSERT(NS_IsMainThread());
void HttpChannelChild::ProcessSetClassifierMatchedInfo(
const nsCString& aList, const nsCString& aProvider,
const nsCString& aFullHash) {
LOG(("HttpChannelChild::ProcessSetClassifierMatchedInfo [this=%p]\n", this));
MOZ_ASSERT(OnSocketThread());
mEventQ->RunOrEnqueue(new NeckoTargetChannelFunctionEvent(
this, [self = UnsafePtr<HttpChannelChild>(this), aInfo]() {
self->SetMatchedInfo(aInfo.list(), aInfo.provider(), aInfo.fullhash());
}));
return IPC_OK();
this,
[self = UnsafePtr<HttpChannelChild>(this), aList, aProvider,
aFullHash]() { self->SetMatchedInfo(aList, aProvider, aFullHash); }));
}
mozilla::ipc::IPCResult HttpChannelChild::RecvSetClassifierMatchedTrackingInfo(
const ClassifierInfo& aInfo) {
LOG(("HttpChannelChild::RecvSetClassifierMatchedTrackingInfo [this=%p]\n",
void HttpChannelChild::ProcessSetClassifierMatchedTrackingInfo(
const nsCString& aLists, const nsCString& aFullHashes) {
LOG(("HttpChannelChild::ProcessSetClassifierMatchedTrackingInfo [this=%p]\n",
this));
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(OnSocketThread());
nsTArray<nsCString> lists, fullhashes;
for (const nsACString& token : aInfo.list().Split(',')) {
for (const nsACString& token : aLists.Split(',')) {
lists.AppendElement(token);
}
for (const nsACString& token : aInfo.fullhash().Split(',')) {
for (const nsACString& token : aFullHashes.Split(',')) {
fullhashes.AppendElement(token);
}
@ -1884,8 +1879,6 @@ mozilla::ipc::IPCResult HttpChannelChild::RecvSetClassifierMatchedTrackingInfo(
fullhashes = CopyableTArray{std::move(fullhashes)}]() {
self->SetMatchedTrackingInfo(lists, fullhashes);
}));
return IPC_OK();
}
void HttpChannelChild::ProcessDivertMessages() {

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

@ -165,18 +165,6 @@ class HttpChannelChild final : public PHttpChannelChild,
mozilla::ipc::IPCResult RecvAltDataCacheInputStreamAvailable(
const Maybe<IPCStream>& aStream) override;
mozilla::ipc::IPCResult RecvNotifyClassificationFlags(
const uint32_t& aClassificationFlags, const bool& aIsThirdParty) override;
mozilla::ipc::IPCResult RecvNotifyFlashPluginStateChanged(
const nsIHttpChannel::FlashPluginState& aState) override;
mozilla::ipc::IPCResult RecvSetClassifierMatchedInfo(
const ClassifierInfo& info) override;
mozilla::ipc::IPCResult RecvSetClassifierMatchedTrackingInfo(
const ClassifierInfo& info) override;
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
virtual void DoNotifyListenerCleanup() override;
@ -265,6 +253,15 @@ class HttpChannelChild final : public PHttpChannelChild,
const nsTArray<ConsoleReportCollected>& aConsoleReports);
void ProcessFlushedForDiversion();
void ProcessDivertMessages();
void ProcessNotifyClassificationFlags(uint32_t aClassificationFlags,
bool aIsThirdParty);
void ProcessNotifyFlashPluginStateChanged(
nsIHttpChannel::FlashPluginState aState);
void ProcessSetClassifierMatchedInfo(const nsCString& aList,
const nsCString& aProvider,
const nsCString& aFullHash);
void ProcessSetClassifierMatchedTrackingInfo(const nsCString& aLists,
const nsCString& aFullHashes);
void ProcessOnAfterLastPart(const nsresult& aStatus);
void ProcessOnProgress(const int64_t& aProgress, const int64_t& aProgressMax);

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

@ -1937,12 +1937,9 @@ HttpChannelParent::SetClassifierMatchedInfo(const nsACString& aList,
const nsACString& aFullHash) {
LOG(("HttpChannelParent::SetClassifierMatchedInfo [this=%p]\n", this));
if (!mIPCClosed) {
ClassifierInfo info;
info.list() = aList;
info.provider() = aProvider;
info.fullhash() = aFullHash;
Unused << SendSetClassifierMatchedInfo(info);
MOZ_ASSERT(mBgParent);
Unused << mBgParent->OnSetClassifierMatchedInfo(aList, aProvider,
aFullHash);
}
return NS_OK;
}
@ -1953,11 +1950,9 @@ HttpChannelParent::SetClassifierMatchedTrackingInfo(
LOG(("HttpChannelParent::SetClassifierMatchedTrackingInfo [this=%p]\n",
this));
if (!mIPCClosed) {
ClassifierInfo info;
info.list() = aLists;
info.fullhash() = aFullHashes;
Unused << SendSetClassifierMatchedTrackingInfo(info);
MOZ_ASSERT(mBgParent);
Unused << mBgParent->OnSetClassifierMatchedTrackingInfo(aLists,
aFullHashes);
}
return NS_OK;
}
@ -1970,8 +1965,9 @@ HttpChannelParent::NotifyClassificationFlags(uint32_t aClassificationFlags,
"classificationFlags=%" PRIu32 ", thirdparty=%d [this=%p]\n",
aClassificationFlags, static_cast<int>(aIsThirdParty), this));
if (!mIPCClosed) {
Unused << SendNotifyClassificationFlags(aClassificationFlags,
aIsThirdParty);
MOZ_ASSERT(mBgParent);
Unused << mBgParent->OnNotifyClassificationFlags(aClassificationFlags,
aIsThirdParty);
}
return NS_OK;
}
@ -1981,7 +1977,8 @@ HttpChannelParent::NotifyFlashPluginStateChanged(
nsIHttpChannel::FlashPluginState aState) {
LOG(("HttpChannelParent::NotifyFlashPluginStateChanged [this=%p]\n", this));
if (!mIPCClosed) {
Unused << SendNotifyFlashPluginStateChanged(aState);
MOZ_ASSERT(mBgParent);
Unused << mBgParent->OnNotifyFlashPluginStateChanged(aState);
}
return NS_OK;
}

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

@ -8,9 +8,12 @@
include protocol PBackground;
include NeckoChannelParams;
include HttpChannelParams;
include PURLClassifierInfo;
include "mozilla/net/NeckoMessageUtils.h";
using nsIHttpChannel::FlashPluginState from "mozilla/net/NeckoMessageUtils.h";
namespace mozilla {
namespace net {
@ -57,6 +60,19 @@ child:
// OnDataAvailable and OnStopRequest messages in the queue back to the parent.
async DivertMessages();
// Tell the child that the resource being loaded has been classified.
async NotifyClassificationFlags(uint32_t aClassificationFlags, bool aIsThirdParty);
// Tell the child that the current channel's document is not allowed to load
// flash content.
async NotifyFlashPluginStateChanged(FlashPluginState aState);
// Tell the child information of matched URL againts SafeBrowsing list
async SetClassifierMatchedInfo(ClassifierInfo info);
// Tell the child information of matched URL againts SafeBrowsing tracking list
async SetClassifierMatchedTrackingInfo(ClassifierInfo info);
async __delete__();
};

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

@ -14,12 +14,9 @@ include NeckoChannelParams;
include IPCServiceWorkerDescriptor;
include IPCStream;
include HttpChannelParams;
include PURLClassifierInfo;
include "mozilla/net/NeckoMessageUtils.h";
using nsIHttpChannel::FlashPluginState from "mozilla/net/NeckoMessageUtils.h";
namespace mozilla {
namespace net {
@ -160,18 +157,6 @@ child:
async AltDataCacheInputStreamAvailable(IPCStream? stream);
// Tell the child that the resource being loaded has been classified.
async NotifyClassificationFlags(uint32_t aClassificationFlags, bool aIsThirdParty);
// Tell the child that the current channel's document is not allowed to load
// flash content.
async NotifyFlashPluginStateChanged(FlashPluginState aState);
// Tell the child information of matched URL againts SafeBrowsing list
async SetClassifierMatchedInfo(ClassifierInfo info);
// Tell the child information of matched URL againts SafeBrowsing tracking list
async SetClassifierMatchedTrackingInfo(ClassifierInfo info);
both:
// After receiving this message, the parent also calls