mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-03 14:28:39 +09:00
Issue #1587 - Part 5: Hook FetchObserver up to the Fetch API
This commit is contained in:
parent
6722d7f4b4
commit
3d2ca85edd
11 changed files with 399 additions and 75 deletions
|
|
@ -667,6 +667,31 @@ FetchDriver::OnStartRequest(nsIRequest* aRequest,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// Runnable to call the observer OnDataAvailable on the main-thread.
|
||||
class DataAvailableRunnable final : public Runnable
|
||||
{
|
||||
RefPtr<FetchDriverObserver> mObserver;
|
||||
|
||||
public:
|
||||
explicit DataAvailableRunnable(FetchDriverObserver* aObserver)
|
||||
: mObserver(aObserver)
|
||||
{
|
||||
MOZ_ASSERT(aObserver);
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
Run() override
|
||||
{
|
||||
mObserver->OnDataAvailable();
|
||||
mObserver = nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
NS_IMETHODIMP
|
||||
FetchDriver::OnDataAvailable(nsIRequest* aRequest,
|
||||
nsISupports* aContext,
|
||||
|
|
@ -678,6 +703,18 @@ FetchDriver::OnDataAvailable(nsIRequest* aRequest,
|
|||
// called between OnStartRequest and OnStopRequest, so we don't need to worry
|
||||
// about races.
|
||||
|
||||
if (mObserver) {
|
||||
if (NS_IsMainThread()) {
|
||||
mObserver->OnDataAvailable();
|
||||
} else {
|
||||
RefPtr<Runnable> runnable = new DataAvailableRunnable(mObserver);
|
||||
nsresult rv = NS_DispatchToMainThread(runnable);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t aRead;
|
||||
MOZ_ASSERT(mResponse);
|
||||
MOZ_ASSERT(mPipeOutputStream);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue