feat: add protocol.handle (#36674)
This commit is contained in:
parent
6a6908c4c8
commit
fda8ea9277
25 changed files with 1254 additions and 89 deletions
|
@ -85,7 +85,10 @@ void NodeStreamLoader::NotifyComplete(int result) {
|
|||
return;
|
||||
}
|
||||
|
||||
client_->OnComplete(network::URLLoaderCompletionStatus(result));
|
||||
network::URLLoaderCompletionStatus status(result);
|
||||
status.completion_time = base::TimeTicks::Now();
|
||||
status.decoded_body_length = bytes_written_;
|
||||
client_->OnComplete(status);
|
||||
delete this;
|
||||
}
|
||||
|
||||
|
@ -126,6 +129,8 @@ void NodeStreamLoader::ReadMore() {
|
|||
// Hold the buffer until the write is done.
|
||||
buffer_.Reset(isolate_, buffer);
|
||||
|
||||
bytes_written_ += node::Buffer::Length(buffer);
|
||||
|
||||
// Write buffer to mojo pipe asynchronously.
|
||||
is_reading_ = false;
|
||||
is_writing_ = true;
|
||||
|
|
|
@ -81,6 +81,8 @@ class NodeStreamLoader : public network::mojom::URLLoader {
|
|||
// Whether we are in the middle of a stream.read().
|
||||
bool is_reading_ = false;
|
||||
|
||||
size_t bytes_written_ = 0;
|
||||
|
||||
// When NotifyComplete is called while writing, we will save the result and
|
||||
// quit with it after the write is done.
|
||||
bool ended_ = false;
|
||||
|
|
|
@ -806,18 +806,23 @@ void ProxyingURLLoaderFactory::CreateLoaderAndStart(
|
|||
}
|
||||
|
||||
// Check if user has intercepted this scheme.
|
||||
auto it = intercepted_handlers_.find(request.url.scheme());
|
||||
if (it != intercepted_handlers_.end()) {
|
||||
mojo::PendingRemote<network::mojom::URLLoaderFactory> loader_remote;
|
||||
this->Clone(loader_remote.InitWithNewPipeAndPassReceiver());
|
||||
bool bypass_custom_protocol_handlers =
|
||||
options & kBypassCustomProtocolHandlers;
|
||||
if (!bypass_custom_protocol_handlers) {
|
||||
auto it = intercepted_handlers_.find(request.url.scheme());
|
||||
if (it != intercepted_handlers_.end()) {
|
||||
mojo::PendingRemote<network::mojom::URLLoaderFactory> loader_remote;
|
||||
this->Clone(loader_remote.InitWithNewPipeAndPassReceiver());
|
||||
|
||||
// <scheme, <type, handler>>
|
||||
it->second.second.Run(
|
||||
request, base::BindOnce(&ElectronURLLoaderFactory::StartLoading,
|
||||
std::move(loader), request_id, options, request,
|
||||
std::move(client), traffic_annotation,
|
||||
std::move(loader_remote), it->second.first));
|
||||
return;
|
||||
// <scheme, <type, handler>>
|
||||
it->second.second.Run(
|
||||
request,
|
||||
base::BindOnce(&ElectronURLLoaderFactory::StartLoading,
|
||||
std::move(loader), request_id, options, request,
|
||||
std::move(client), traffic_annotation,
|
||||
std::move(loader_remote), it->second.first));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// The loader of ServiceWorker forbids loading scripts from file:// URLs, and
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
|
||||
namespace electron {
|
||||
|
||||
const uint32_t kBypassCustomProtocolHandlers = 1 << 30;
|
||||
|
||||
// This class is responsible for following tasks when NetworkService is enabled:
|
||||
// 1. handling intercepted protocols;
|
||||
// 2. implementing webRequest module;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue