зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1646592 - P3 Sending endpoint of stream filter via PHttpBackgroundChannel, r=mayhemer,necko-reviewers
Endpoint would be passed by a series of std::move via nsHttpChannel -> HttpChannelParent -> HttpBackgroundChannelParent ---> HttpBackgroundChannelChild -> HttpChannelChild | | Resolve promise after successfully send IPC<-/ Depends on D81273 Differential Revision: https://phabricator.services.mozilla.com/D81274
This commit is contained in:
Родитель
cea21a8121
Коммит
069f0d6456
|
@ -411,6 +411,20 @@ IPCResult HttpBackgroundChannelChild::RecvSetClassifierMatchedTrackingInfo(
|
|||
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
IPCResult HttpBackgroundChannelChild::RecvAttachStreamFilter(
|
||||
Endpoint<extensions::PStreamFilterParent>&& aEndpoint) {
|
||||
LOG(("HttpBackgroundChannelChild::RecvAttachStreamFilter [this=%p]\n", this));
|
||||
MOZ_ASSERT(OnSocketThread());
|
||||
|
||||
if (NS_WARN_IF(!mChannelChild)) {
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mChannelChild->ProcessAttachStreamFilter(std::move(aEndpoint));
|
||||
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()
|
||||
|
|
|
@ -90,6 +90,9 @@ class HttpBackgroundChannelChild final : public PHttpBackgroundChannelChild {
|
|||
|
||||
IPCResult RecvSetClassifierMatchedTrackingInfo(const ClassifierInfo& info);
|
||||
|
||||
IPCResult RecvAttachStreamFilter(
|
||||
Endpoint<extensions::PStreamFilterParent>&& aEndpoint);
|
||||
|
||||
void ActorDestroy(ActorDestroyReason aWhy) override;
|
||||
|
||||
void CreateDataBridge();
|
||||
|
|
|
@ -478,6 +478,22 @@ nsISerialEventTarget* HttpBackgroundChannelParent::GetBackgroundTarget() {
|
|||
return mBackgroundThread.get();
|
||||
}
|
||||
|
||||
auto HttpBackgroundChannelParent::AttachStreamFilter(
|
||||
Endpoint<extensions::PStreamFilterParent>&& aParentEndpoint,
|
||||
Endpoint<extensions::PStreamFilterChild>&& aChildEndpoint)
|
||||
-> RefPtr<ChildEndpointPromise> {
|
||||
LOG(("HttpBackgroundChannelParent::AttachStreamFilter [this=%p]\n", this));
|
||||
MOZ_ASSERT(IsOnBackgroundThread());
|
||||
|
||||
if (NS_WARN_IF(!mIPCOpened) ||
|
||||
!SendAttachStreamFilter(std::move(aParentEndpoint))) {
|
||||
return ChildEndpointPromise::CreateAndReject(false, __func__);
|
||||
}
|
||||
|
||||
return ChildEndpointPromise::CreateAndResolve(std::move(aChildEndpoint),
|
||||
__func__);
|
||||
}
|
||||
|
||||
void HttpBackgroundChannelParent::ActorDestroy(ActorDestroyReason aWhy) {
|
||||
LOG(("HttpBackgroundChannelParent::ActorDestroy [this=%p]\n", this));
|
||||
AssertIsInMainProcess();
|
||||
|
|
|
@ -88,6 +88,12 @@ class HttpBackgroundChannelParent final : public PHttpBackgroundChannelParent {
|
|||
|
||||
nsISerialEventTarget* GetBackgroundTarget();
|
||||
|
||||
using ChildEndpointPromise =
|
||||
MozPromise<ipc::Endpoint<extensions::PStreamFilterChild>, bool, true>;
|
||||
[[nodiscard]] RefPtr<ChildEndpointPromise> AttachStreamFilter(
|
||||
Endpoint<extensions::PStreamFilterParent>&& aParentEndpoint,
|
||||
Endpoint<extensions::PStreamFilterChild>&& aChildEndpoint);
|
||||
|
||||
protected:
|
||||
void ActorDestroy(ActorDestroyReason aWhy) override;
|
||||
|
||||
|
|
|
@ -3874,10 +3874,39 @@ mozilla::ipc::IPCResult HttpChannelChild::RecvSetPriority(
|
|||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult HttpChannelChild::RecvAttachStreamFilter(
|
||||
// We don't have a copyable Endpoint and NeckoTargetChannelFunctionEvent takes
|
||||
// std::function<void()>. It's not possible to avoid the copy from the type of
|
||||
// lambda to std::function, so does the capture list. Hence, we're forced to
|
||||
// use the old-fashioned channel event inheritance.
|
||||
class AttachStreamFilterEvent : public ChannelEvent {
|
||||
public:
|
||||
AttachStreamFilterEvent(HttpChannelChild* aChild,
|
||||
already_AddRefed<nsIEventTarget> aTarget,
|
||||
Endpoint<extensions::PStreamFilterParent>&& aEndpoint)
|
||||
: mChild(aChild), mTarget(aTarget), mEndpoint(std::move(aEndpoint)) {}
|
||||
|
||||
already_AddRefed<nsIEventTarget> GetEventTarget() override {
|
||||
nsCOMPtr<nsIEventTarget> target = mTarget;
|
||||
return target.forget();
|
||||
}
|
||||
|
||||
void Run() override {
|
||||
extensions::StreamFilterParent::Attach(mChild, std::move(mEndpoint));
|
||||
}
|
||||
|
||||
private:
|
||||
HttpChannelChild* mChild;
|
||||
nsCOMPtr<nsIEventTarget> mTarget;
|
||||
Endpoint<extensions::PStreamFilterParent> mEndpoint;
|
||||
};
|
||||
|
||||
void HttpChannelChild::ProcessAttachStreamFilter(
|
||||
Endpoint<extensions::PStreamFilterParent>&& aEndpoint) {
|
||||
extensions::StreamFilterParent::Attach(this, std::move(aEndpoint));
|
||||
return IPC_OK();
|
||||
LOG(("HttpChannelChild::ProcessAttachStreamFilter [this=%p]\n", this));
|
||||
MOZ_ASSERT(OnSocketThread());
|
||||
|
||||
mEventQ->RunOrEnqueue(new AttachStreamFilterEvent(this, GetNeckoTarget(),
|
||||
std::move(aEndpoint)));
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult HttpChannelChild::RecvCancelDiversion() {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "mozilla/Mutex.h"
|
||||
#include "mozilla/Telemetry.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "mozilla/extensions/StreamFilterParent.h"
|
||||
#include "mozilla/net/HttpBaseChannel.h"
|
||||
#include "mozilla/net/NeckoTargetHolder.h"
|
||||
#include "mozilla/net/PHttpChannelChild.h"
|
||||
|
@ -154,9 +155,6 @@ class HttpChannelChild final : public PHttpChannelChild,
|
|||
|
||||
mozilla::ipc::IPCResult RecvSetPriority(const int16_t& aPriority) override;
|
||||
|
||||
mozilla::ipc::IPCResult RecvAttachStreamFilter(
|
||||
Endpoint<extensions::PStreamFilterParent>&& aEndpoint) override;
|
||||
|
||||
mozilla::ipc::IPCResult RecvCancelDiversion() override;
|
||||
|
||||
mozilla::ipc::IPCResult RecvOriginalCacheInputStreamAvailable(
|
||||
|
@ -267,6 +265,9 @@ class HttpChannelChild final : public PHttpChannelChild,
|
|||
|
||||
void ProcessOnStatus(const nsresult& aStatus);
|
||||
|
||||
void ProcessAttachStreamFilter(
|
||||
Endpoint<extensions::PStreamFilterParent>&& aEndpoint);
|
||||
|
||||
// Return true if we need to tell the parent the size of unreported received
|
||||
// data
|
||||
bool NeedToReportBytesRead();
|
||||
|
|
|
@ -2669,11 +2669,24 @@ void HttpChannelParent::OverrideReferrerInfoDuringBeginConnect(
|
|||
mOverrideReferrerInfo = aReferrerInfo;
|
||||
}
|
||||
|
||||
bool HttpChannelParent::AttachStreamFilter(
|
||||
Endpoint<extensions::PStreamFilterParent>&& aEndpoint) {
|
||||
auto HttpChannelParent::AttachStreamFilter(
|
||||
Endpoint<extensions::PStreamFilterParent>&& aParentEndpoint,
|
||||
Endpoint<extensions::PStreamFilterChild>&& aChildEndpoint)
|
||||
-> RefPtr<ChildEndpointPromise> {
|
||||
LOG(("HttpChannelParent::AttachStreamFilter [this=%p]", this));
|
||||
MOZ_ASSERT(!mAfterOnStartRequestBegun);
|
||||
mStreamFilterAttached = true;
|
||||
return SendAttachStreamFilter(std::move(aEndpoint));
|
||||
|
||||
if (mIPCClosed) {
|
||||
return ChildEndpointPromise::CreateAndReject(false, __func__);
|
||||
}
|
||||
|
||||
// If IPC channel is open, background channel should be ready to send
|
||||
// SendAttachStreamFilter.
|
||||
MOZ_ASSERT(mBgParent);
|
||||
return InvokeAsync(mBgParent->GetBackgroundTarget(), mBgParent.get(),
|
||||
__func__, &HttpBackgroundChannelParent::AttachStreamFilter,
|
||||
std::move(aParentEndpoint), std::move(aChildEndpoint));
|
||||
}
|
||||
|
||||
} // namespace net
|
||||
|
|
|
@ -134,8 +134,11 @@ class HttpChannelParent final : public nsIInterfaceRequestor,
|
|||
// BeginConnect.
|
||||
void OverrideReferrerInfoDuringBeginConnect(nsIReferrerInfo* aReferrerInfo);
|
||||
|
||||
bool AttachStreamFilter(
|
||||
Endpoint<extensions::PStreamFilterParent>&& aEndpoint);
|
||||
using ChildEndpointPromise =
|
||||
MozPromise<ipc::Endpoint<extensions::PStreamFilterChild>, bool, true>;
|
||||
[[nodiscard]] RefPtr<ChildEndpointPromise> AttachStreamFilter(
|
||||
Endpoint<extensions::PStreamFilterParent>&& aParentEndpoint,
|
||||
Endpoint<extensions::PStreamFilterChild>&& aChildEndpoint);
|
||||
|
||||
protected:
|
||||
// used to connect redirected-to channel in parent with just created
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
include protocol PBackground;
|
||||
include protocol PStreamFilter;
|
||||
include NeckoChannelParams;
|
||||
include HttpChannelParams;
|
||||
include PURLClassifierInfo;
|
||||
|
@ -73,6 +74,8 @@ child:
|
|||
// Tell the child information of matched URL againts SafeBrowsing tracking list
|
||||
async SetClassifierMatchedTrackingInfo(ClassifierInfo info);
|
||||
|
||||
async AttachStreamFilter(Endpoint<PStreamFilterParent> aEndpoint);
|
||||
|
||||
async __delete__();
|
||||
|
||||
};
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
include protocol PNecko;
|
||||
include protocol PStreamFilter;
|
||||
include InputStreamParams;
|
||||
include URIParams;
|
||||
include PBackgroundSharedTypes;
|
||||
|
@ -148,8 +147,6 @@ child:
|
|||
nsString url,
|
||||
nsString contentType);
|
||||
|
||||
async AttachStreamFilter(Endpoint<PStreamFilterParent> aEndpoint);
|
||||
|
||||
// See ADivertableParentChannel::CancelDiversion
|
||||
async CancelDiversion();
|
||||
|
||||
|
|
|
@ -7085,10 +7085,7 @@ auto nsHttpChannel::AttachStreamFilter(base::ProcessId aChildProcessId)
|
|||
}
|
||||
|
||||
if (RefPtr<HttpChannelParent> httpParent = do_QueryObject(parentChannel)) {
|
||||
if (httpParent->AttachStreamFilter(std::move(parent))) {
|
||||
return ChildEndpointPromise::CreateAndResolve(std::move(child), __func__);
|
||||
}
|
||||
return ChildEndpointPromise::CreateAndReject(false, __func__);
|
||||
return httpParent->AttachStreamFilter(std::move(parent), std::move(child));
|
||||
}
|
||||
|
||||
extensions::StreamFilterParent::Attach(this, std::move(parent));
|
||||
|
|
Загрузка…
Ссылка в новой задаче