Skip to content
Permalink
Browse files

feat: implement net module with NetworkService (#19094)

* Stub class for NetworkService-based URLRequest

* Create SimpleURLLoader

* Implement downloading

* Implement response event

* Only write data afte previous one finished

* Use DataPipeGetter for uploading data

* Support chunked upload data

* Call size callback at last

* Simplify UploadDataPipeGetter

* Implement cancelling and closing

* Handle redirection

* Fix uploading large data

* Emit error when request fails

* Emit error for redirection error

* Simplify emitting error

* "follow" should also emit "redirect" event

* SetLoadFlags is not really used

* Implement GetUploadProgress

* Implement FollowRedirect

* Fix exception with multiple redirections

* Reduce number of EmitEvent methods

* Emit response errors

* FetchRedirectMode => RedirectMode
  • Loading branch information...
zcbenz committed Jul 4, 2019
1 parent 4b674c1 commit 2a3793485f71b8ec102a324ab61804c8c093a21e
@@ -93,6 +93,8 @@ filenames = {
"shell/browser/api/atom_api_tray.h",
"shell/browser/api/atom_api_url_request.cc",
"shell/browser/api/atom_api_url_request.h",
"shell/browser/api/atom_api_url_request_ns.cc",
"shell/browser/api/atom_api_url_request_ns.h",
"shell/browser/api/atom_api_view.cc",
"shell/browser/api/atom_api_view.h",
"shell/browser/api/atom_api_web_contents.cc",
@@ -3,8 +3,12 @@
// found in the LICENSE file.

#include "shell/browser/api/atom_api_net.h"

#include "native_mate/dictionary.h"
#include "services/network/public/cpp/features.h"
#include "shell/browser/api/atom_api_url_request.h"
#include "shell/browser/api/atom_api_url_request_ns.h"

#include "shell/common/node_includes.h"

namespace electron {
@@ -31,8 +35,12 @@ void Net::BuildPrototype(v8::Isolate* isolate,
}

v8::Local<v8::Value> Net::URLRequest(v8::Isolate* isolate) {
return URLRequest::GetConstructor(isolate)
->GetFunction(isolate->GetCurrentContext())
v8::Local<v8::FunctionTemplate> constructor;
if (base::FeatureList::IsEnabled(network::features::kNetworkService))
constructor = URLRequestNS::GetConstructor(isolate);
else
constructor = URLRequest::GetConstructor(isolate);
return constructor->GetFunction(isolate->GetCurrentContext())
.ToLocalChecked();
}

@@ -44,19 +52,26 @@ namespace {

using electron::api::Net;
using electron::api::URLRequest;
using electron::api::URLRequestNS;

void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();

URLRequest::SetConstructor(isolate, base::BindRepeating(URLRequest::New));
if (base::FeatureList::IsEnabled(network::features::kNetworkService))
URLRequestNS::SetConstructor(isolate,
base::BindRepeating(URLRequestNS::New));
else
URLRequest::SetConstructor(isolate, base::BindRepeating(URLRequest::New));

mate::Dictionary dict(isolate, exports);
dict.Set("net", Net::Create(isolate));
dict.Set("Net",
Net::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
dict.Set("isNetworkServiceEnabled",
base::FeatureList::IsEnabled(network::features::kNetworkService));
}

} // namespace
@@ -25,7 +25,6 @@ class AtomURLRequest;

namespace api {

//
// The URLRequest class implements the V8 binding between the JavaScript API
// and Chromium native net library. It is responsible for handling HTTP/HTTPS
// requests.
@@ -114,7 +113,7 @@ class URLRequest : public mate::EventEmitter<URLRequest> {
mate::Dictionary GetUploadProgress(v8::Isolate* isolate);

protected:
explicit URLRequest(v8::Isolate* isolate, v8::Local<v8::Object> wrapper);
URLRequest(v8::Isolate* isolate, v8::Local<v8::Object> wrapper);
~URLRequest() override;

private:

0 comments on commit 2a37934

Please sign in to comment.
You can’t perform that action at this time.