chore: remove _ns suffixes (#20691)

* chore: remove _ns suffixes

* lint
This commit is contained in:
Jeremy Apthorp 2019-10-23 17:51:06 -07:00 committed by Cheng Zhao
parent cc278cea00
commit 77414813b4
11 changed files with 237 additions and 240 deletions

View file

@ -79,8 +79,8 @@ filenames = {
"shell/browser/api/atom_api_power_monitor.h", "shell/browser/api/atom_api_power_monitor.h",
"shell/browser/api/atom_api_power_save_blocker.cc", "shell/browser/api/atom_api_power_save_blocker.cc",
"shell/browser/api/atom_api_power_save_blocker.h", "shell/browser/api/atom_api_power_save_blocker.h",
"shell/browser/api/atom_api_protocol_ns.cc", "shell/browser/api/atom_api_protocol.cc",
"shell/browser/api/atom_api_protocol_ns.h", "shell/browser/api/atom_api_protocol.h",
"shell/browser/api/atom_api_screen.cc", "shell/browser/api/atom_api_screen.cc",
"shell/browser/api/atom_api_screen.h", "shell/browser/api/atom_api_screen.h",
"shell/browser/api/atom_api_session.cc", "shell/browser/api/atom_api_session.cc",
@ -93,8 +93,8 @@ filenames = {
"shell/browser/api/atom_api_top_level_window.h", "shell/browser/api/atom_api_top_level_window.h",
"shell/browser/api/atom_api_tray.cc", "shell/browser/api/atom_api_tray.cc",
"shell/browser/api/atom_api_tray.h", "shell/browser/api/atom_api_tray.h",
"shell/browser/api/atom_api_url_request_ns.cc", "shell/browser/api/atom_api_url_request.cc",
"shell/browser/api/atom_api_url_request_ns.h", "shell/browser/api/atom_api_url_request.h",
"shell/browser/api/atom_api_view.cc", "shell/browser/api/atom_api_view.cc",
"shell/browser/api/atom_api_view.h", "shell/browser/api/atom_api_view.h",
"shell/browser/api/atom_api_web_contents.cc", "shell/browser/api/atom_api_web_contents.cc",
@ -103,8 +103,8 @@ filenames = {
"shell/browser/api/atom_api_web_contents_mac.mm", "shell/browser/api/atom_api_web_contents_mac.mm",
"shell/browser/api/atom_api_web_contents_view.cc", "shell/browser/api/atom_api_web_contents_view.cc",
"shell/browser/api/atom_api_web_contents_view.h", "shell/browser/api/atom_api_web_contents_view.h",
"shell/browser/api/atom_api_web_request_ns.cc", "shell/browser/api/atom_api_web_request.cc",
"shell/browser/api/atom_api_web_request_ns.h", "shell/browser/api/atom_api_web_request.h",
"shell/browser/api/atom_api_web_view_manager.cc", "shell/browser/api/atom_api_web_view_manager.cc",
"shell/browser/api/atom_api_browser_window.cc", "shell/browser/api/atom_api_browser_window.cc",
"shell/browser/api/atom_api_browser_window.h", "shell/browser/api/atom_api_browser_window.h",

View file

@ -7,7 +7,7 @@
#include "native_mate/dictionary.h" #include "native_mate/dictionary.h"
#include "native_mate/handle.h" #include "native_mate/handle.h"
#include "services/network/public/cpp/features.h" #include "services/network/public/cpp/features.h"
#include "shell/browser/api/atom_api_url_request_ns.h" #include "shell/browser/api/atom_api_url_request.h"
#include "shell/common/node_includes.h" #include "shell/common/node_includes.h"
@ -36,7 +36,7 @@ void Net::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::Value> Net::URLRequest(v8::Isolate* isolate) { v8::Local<v8::Value> Net::URLRequest(v8::Isolate* isolate) {
v8::Local<v8::FunctionTemplate> constructor; v8::Local<v8::FunctionTemplate> constructor;
constructor = URLRequestNS::GetConstructor(isolate); constructor = URLRequest::GetConstructor(isolate);
return constructor->GetFunction(isolate->GetCurrentContext()) return constructor->GetFunction(isolate->GetCurrentContext())
.ToLocalChecked(); .ToLocalChecked();
} }
@ -48,7 +48,7 @@ v8::Local<v8::Value> Net::URLRequest(v8::Isolate* isolate) {
namespace { namespace {
using electron::api::Net; using electron::api::Net;
using electron::api::URLRequestNS; using electron::api::URLRequest;
void Initialize(v8::Local<v8::Object> exports, void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused, v8::Local<v8::Value> unused,
@ -56,7 +56,7 @@ void Initialize(v8::Local<v8::Object> exports,
void* priv) { void* priv) {
v8::Isolate* isolate = context->GetIsolate(); v8::Isolate* isolate = context->GetIsolate();
URLRequestNS::SetConstructor(isolate, base::BindRepeating(URLRequestNS::New)); URLRequest::SetConstructor(isolate, base::BindRepeating(URLRequest::New));
mate::Dictionary dict(isolate, exports); mate::Dictionary dict(isolate, exports);
dict.Set("net", Net::Create(isolate)); dict.Set("net", Net::Create(isolate));

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by the MIT license that can be // Use of this source code is governed by the MIT license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "shell/browser/api/atom_api_protocol_ns.h" #include "shell/browser/api/atom_api_protocol.h"
#include <memory> #include <memory>
#include <utility> #include <utility>
@ -159,15 +159,14 @@ std::string ErrorCodeToString(ProtocolError error) {
} // namespace } // namespace
ProtocolNS::ProtocolNS(v8::Isolate* isolate, Protocol::Protocol(v8::Isolate* isolate, AtomBrowserContext* browser_context) {
AtomBrowserContext* browser_context) {
Init(isolate); Init(isolate);
AttachAsUserData(browser_context); AttachAsUserData(browser_context);
} }
ProtocolNS::~ProtocolNS() = default; Protocol::~Protocol() = default;
void ProtocolNS::RegisterURLLoaderFactories( void Protocol::RegisterURLLoaderFactories(
content::ContentBrowserClient::NonNetworkURLLoaderFactoryMap* factories) { content::ContentBrowserClient::NonNetworkURLLoaderFactoryMap* factories) {
for (const auto& it : handlers_) { for (const auto& it : handlers_) {
factories->emplace(it.first, std::make_unique<AtomURLLoaderFactory>( factories->emplace(it.first, std::make_unique<AtomURLLoaderFactory>(
@ -175,14 +174,14 @@ void ProtocolNS::RegisterURLLoaderFactories(
} }
} }
ProtocolError ProtocolNS::RegisterProtocol(ProtocolType type, ProtocolError Protocol::RegisterProtocol(ProtocolType type,
const std::string& scheme, const std::string& scheme,
const ProtocolHandler& handler) { const ProtocolHandler& handler) {
const bool added = base::TryEmplace(handlers_, scheme, type, handler).second; const bool added = base::TryEmplace(handlers_, scheme, type, handler).second;
return added ? ProtocolError::OK : ProtocolError::REGISTERED; return added ? ProtocolError::OK : ProtocolError::REGISTERED;
} }
void ProtocolNS::UnregisterProtocol(const std::string& scheme, void Protocol::UnregisterProtocol(const std::string& scheme,
gin::Arguments* args) { gin::Arguments* args) {
const bool removed = handlers_.erase(scheme) != 0; const bool removed = handlers_.erase(scheme) != 0;
const auto error = const auto error =
@ -190,11 +189,11 @@ void ProtocolNS::UnregisterProtocol(const std::string& scheme,
HandleOptionalCallback(args, error); HandleOptionalCallback(args, error);
} }
bool ProtocolNS::IsProtocolRegistered(const std::string& scheme) { bool Protocol::IsProtocolRegistered(const std::string& scheme) {
return base::Contains(handlers_, scheme); return base::Contains(handlers_, scheme);
} }
ProtocolError ProtocolNS::InterceptProtocol(ProtocolType type, ProtocolError Protocol::InterceptProtocol(ProtocolType type,
const std::string& scheme, const std::string& scheme,
const ProtocolHandler& handler) { const ProtocolHandler& handler) {
const bool added = const bool added =
@ -202,7 +201,7 @@ ProtocolError ProtocolNS::InterceptProtocol(ProtocolType type,
return added ? ProtocolError::OK : ProtocolError::INTERCEPTED; return added ? ProtocolError::OK : ProtocolError::INTERCEPTED;
} }
void ProtocolNS::UninterceptProtocol(const std::string& scheme, void Protocol::UninterceptProtocol(const std::string& scheme,
gin::Arguments* args) { gin::Arguments* args) {
const bool removed = intercept_handlers_.erase(scheme) != 0; const bool removed = intercept_handlers_.erase(scheme) != 0;
const auto error = const auto error =
@ -210,11 +209,11 @@ void ProtocolNS::UninterceptProtocol(const std::string& scheme,
HandleOptionalCallback(args, error); HandleOptionalCallback(args, error);
} }
bool ProtocolNS::IsProtocolIntercepted(const std::string& scheme) { bool Protocol::IsProtocolIntercepted(const std::string& scheme) {
return base::Contains(intercept_handlers_, scheme); return base::Contains(intercept_handlers_, scheme);
} }
v8::Local<v8::Promise> ProtocolNS::IsProtocolHandled(const std::string& scheme, v8::Local<v8::Promise> Protocol::IsProtocolHandled(const std::string& scheme,
gin::Arguments* args) { gin::Arguments* args) {
node::Environment* env = node::Environment::GetCurrent(args->isolate()); node::Environment* env = node::Environment::GetCurrent(args->isolate());
EmitDeprecationWarning( EmitDeprecationWarning(
@ -236,7 +235,7 @@ v8::Local<v8::Promise> ProtocolNS::IsProtocolHandled(const std::string& scheme,
base::Contains(kBuiltinSchemes, scheme)); base::Contains(kBuiltinSchemes, scheme));
} }
void ProtocolNS::HandleOptionalCallback(gin::Arguments* args, void Protocol::HandleOptionalCallback(gin::Arguments* args,
ProtocolError error) { ProtocolError error) {
CompletionCallback callback; CompletionCallback callback;
if (args->GetNext(&callback)) { if (args->GetNext(&callback)) {
@ -254,46 +253,45 @@ void ProtocolNS::HandleOptionalCallback(gin::Arguments* args,
} }
// static // static
gin::Handle<ProtocolNS> ProtocolNS::Create( gin::Handle<Protocol> Protocol::Create(v8::Isolate* isolate,
v8::Isolate* isolate,
AtomBrowserContext* browser_context) { AtomBrowserContext* browser_context) {
return gin::CreateHandle(isolate, new ProtocolNS(isolate, browser_context)); return gin::CreateHandle(isolate, new Protocol(isolate, browser_context));
} }
// static // static
void ProtocolNS::BuildPrototype(v8::Isolate* isolate, void Protocol::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) { v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(gin::StringToV8(isolate, "Protocol")); prototype->SetClassName(gin::StringToV8(isolate, "Protocol"));
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("registerStringProtocol", .SetMethod("registerStringProtocol",
&ProtocolNS::RegisterProtocolFor<ProtocolType::kString>) &Protocol::RegisterProtocolFor<ProtocolType::kString>)
.SetMethod("registerBufferProtocol", .SetMethod("registerBufferProtocol",
&ProtocolNS::RegisterProtocolFor<ProtocolType::kBuffer>) &Protocol::RegisterProtocolFor<ProtocolType::kBuffer>)
.SetMethod("registerFileProtocol", .SetMethod("registerFileProtocol",
&ProtocolNS::RegisterProtocolFor<ProtocolType::kFile>) &Protocol::RegisterProtocolFor<ProtocolType::kFile>)
.SetMethod("registerHttpProtocol", .SetMethod("registerHttpProtocol",
&ProtocolNS::RegisterProtocolFor<ProtocolType::kHttp>) &Protocol::RegisterProtocolFor<ProtocolType::kHttp>)
.SetMethod("registerStreamProtocol", .SetMethod("registerStreamProtocol",
&ProtocolNS::RegisterProtocolFor<ProtocolType::kStream>) &Protocol::RegisterProtocolFor<ProtocolType::kStream>)
.SetMethod("registerProtocol", .SetMethod("registerProtocol",
&ProtocolNS::RegisterProtocolFor<ProtocolType::kFree>) &Protocol::RegisterProtocolFor<ProtocolType::kFree>)
.SetMethod("unregisterProtocol", &ProtocolNS::UnregisterProtocol) .SetMethod("unregisterProtocol", &Protocol::UnregisterProtocol)
.SetMethod("isProtocolRegistered", &ProtocolNS::IsProtocolRegistered) .SetMethod("isProtocolRegistered", &Protocol::IsProtocolRegistered)
.SetMethod("isProtocolHandled", &ProtocolNS::IsProtocolHandled) .SetMethod("isProtocolHandled", &Protocol::IsProtocolHandled)
.SetMethod("interceptStringProtocol", .SetMethod("interceptStringProtocol",
&ProtocolNS::InterceptProtocolFor<ProtocolType::kString>) &Protocol::InterceptProtocolFor<ProtocolType::kString>)
.SetMethod("interceptBufferProtocol", .SetMethod("interceptBufferProtocol",
&ProtocolNS::InterceptProtocolFor<ProtocolType::kBuffer>) &Protocol::InterceptProtocolFor<ProtocolType::kBuffer>)
.SetMethod("interceptFileProtocol", .SetMethod("interceptFileProtocol",
&ProtocolNS::InterceptProtocolFor<ProtocolType::kFile>) &Protocol::InterceptProtocolFor<ProtocolType::kFile>)
.SetMethod("interceptHttpProtocol", .SetMethod("interceptHttpProtocol",
&ProtocolNS::InterceptProtocolFor<ProtocolType::kHttp>) &Protocol::InterceptProtocolFor<ProtocolType::kHttp>)
.SetMethod("interceptStreamProtocol", .SetMethod("interceptStreamProtocol",
&ProtocolNS::InterceptProtocolFor<ProtocolType::kStream>) &Protocol::InterceptProtocolFor<ProtocolType::kStream>)
.SetMethod("interceptProtocol", .SetMethod("interceptProtocol",
&ProtocolNS::InterceptProtocolFor<ProtocolType::kFree>) &Protocol::InterceptProtocolFor<ProtocolType::kFree>)
.SetMethod("uninterceptProtocol", &ProtocolNS::UninterceptProtocol) .SetMethod("uninterceptProtocol", &Protocol::UninterceptProtocol)
.SetMethod("isProtocolIntercepted", &ProtocolNS::IsProtocolIntercepted); .SetMethod("isProtocolIntercepted", &Protocol::IsProtocolIntercepted);
} }
} // namespace api } // namespace api

View file

@ -2,8 +2,8 @@
// Use of this source code is governed by the MIT license that can be // Use of this source code is governed by the MIT license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_PROTOCOL_NS_H_ #ifndef SHELL_BROWSER_API_ATOM_API_PROTOCOL_H_
#define SHELL_BROWSER_API_ATOM_API_PROTOCOL_NS_H_ #define SHELL_BROWSER_API_ATOM_API_PROTOCOL_H_
#include <string> #include <string>
#include <vector> #include <vector>
@ -35,9 +35,9 @@ enum class ProtocolError {
}; };
// Protocol implementation based on network services. // Protocol implementation based on network services.
class ProtocolNS : public mate::TrackableObject<ProtocolNS> { class Protocol : public mate::TrackableObject<Protocol> {
public: public:
static gin::Handle<ProtocolNS> Create(v8::Isolate* isolate, static gin::Handle<Protocol> Create(v8::Isolate* isolate,
AtomBrowserContext* browser_context); AtomBrowserContext* browser_context);
static void BuildPrototype(v8::Isolate* isolate, static void BuildPrototype(v8::Isolate* isolate,
@ -50,8 +50,8 @@ class ProtocolNS : public mate::TrackableObject<ProtocolNS> {
const HandlersMap& intercept_handlers() const { return intercept_handlers_; } const HandlersMap& intercept_handlers() const { return intercept_handlers_; }
private: private:
ProtocolNS(v8::Isolate* isolate, AtomBrowserContext* browser_context); Protocol(v8::Isolate* isolate, AtomBrowserContext* browser_context);
~ProtocolNS() override; ~Protocol() override;
// Callback types. // Callback types.
using CompletionCallback = using CompletionCallback =
@ -99,4 +99,4 @@ class ProtocolNS : public mate::TrackableObject<ProtocolNS> {
} // namespace electron } // namespace electron
#endif // SHELL_BROWSER_API_ATOM_API_PROTOCOL_NS_H_ #endif // SHELL_BROWSER_API_ATOM_API_PROTOCOL_H_

View file

@ -45,8 +45,8 @@
#include "shell/browser/api/atom_api_data_pipe_holder.h" #include "shell/browser/api/atom_api_data_pipe_holder.h"
#include "shell/browser/api/atom_api_download_item.h" #include "shell/browser/api/atom_api_download_item.h"
#include "shell/browser/api/atom_api_net_log.h" #include "shell/browser/api/atom_api_net_log.h"
#include "shell/browser/api/atom_api_protocol_ns.h" #include "shell/browser/api/atom_api_protocol.h"
#include "shell/browser/api/atom_api_web_request_ns.h" #include "shell/browser/api/atom_api_web_request.h"
#include "shell/browser/atom_browser_context.h" #include "shell/browser/atom_browser_context.h"
#include "shell/browser/atom_browser_main_parts.h" #include "shell/browser/atom_browser_main_parts.h"
#include "shell/browser/atom_permission_manager.h" #include "shell/browser/atom_permission_manager.h"
@ -588,7 +588,7 @@ v8::Local<v8::Value> Session::Cookies(v8::Isolate* isolate) {
v8::Local<v8::Value> Session::Protocol(v8::Isolate* isolate) { v8::Local<v8::Value> Session::Protocol(v8::Isolate* isolate) {
if (protocol_.IsEmpty()) { if (protocol_.IsEmpty()) {
v8::Local<v8::Value> handle; v8::Local<v8::Value> handle;
handle = ProtocolNS::Create(isolate, browser_context()).ToV8(); handle = Protocol::Create(isolate, browser_context()).ToV8();
protocol_.Reset(isolate, handle); protocol_.Reset(isolate, handle);
} }
return v8::Local<v8::Value>::New(isolate, protocol_); return v8::Local<v8::Value>::New(isolate, protocol_);
@ -596,7 +596,7 @@ v8::Local<v8::Value> Session::Protocol(v8::Isolate* isolate) {
v8::Local<v8::Value> Session::WebRequest(v8::Isolate* isolate) { v8::Local<v8::Value> Session::WebRequest(v8::Isolate* isolate) {
if (web_request_.IsEmpty()) { if (web_request_.IsEmpty()) {
auto handle = WebRequestNS::Create(isolate, browser_context()); auto handle = WebRequest::Create(isolate, browser_context());
web_request_.Reset(isolate, handle.ToV8()); web_request_.Reset(isolate, handle.ToV8());
} }
return v8::Local<v8::Value>::New(isolate, web_request_); return v8::Local<v8::Value>::New(isolate, web_request_);
@ -732,7 +732,7 @@ namespace {
using electron::api::Cookies; using electron::api::Cookies;
using electron::api::NetLog; using electron::api::NetLog;
using electron::api::ProtocolNS; using electron::api::Protocol;
using electron::api::Session; using electron::api::Session;
v8::Local<v8::Value> FromPartition(const std::string& partition, v8::Local<v8::Value> FromPartition(const std::string& partition,
@ -761,9 +761,9 @@ void Initialize(v8::Local<v8::Object> exports,
dict.Set( dict.Set(
"NetLog", "NetLog",
NetLog::GetConstructor(isolate)->GetFunction(context).ToLocalChecked()); NetLog::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
dict.Set("Protocol", ProtocolNS::GetConstructor(isolate) dict.Set(
->GetFunction(context) "Protocol",
.ToLocalChecked()); Protocol::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
dict.SetMethod("fromPartition", &FromPartition); dict.SetMethod("fromPartition", &FromPartition);
} }

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by the MIT license that can be // Use of this source code is governed by the MIT license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "shell/browser/api/atom_api_url_request_ns.h" #include "shell/browser/api/atom_api_url_request.h"
#include <utility> #include <utility>
@ -84,7 +84,7 @@ const net::NetworkTrafficAnnotationTag kTrafficAnnotation =
// Common class for streaming data. // Common class for streaming data.
class UploadDataPipeGetter { class UploadDataPipeGetter {
public: public:
explicit UploadDataPipeGetter(URLRequestNS* request) : request_(request) {} explicit UploadDataPipeGetter(URLRequest* request) : request_(request) {}
virtual ~UploadDataPipeGetter() = default; virtual ~UploadDataPipeGetter() = default;
virtual void AttachToRequestBody(network::ResourceRequestBody* body) = 0; virtual void AttachToRequestBody(network::ResourceRequestBody* body) = 0;
@ -101,7 +101,7 @@ class UploadDataPipeGetter {
} }
private: private:
URLRequestNS* request_; URLRequest* request_;
DISALLOW_COPY_AND_ASSIGN(UploadDataPipeGetter); DISALLOW_COPY_AND_ASSIGN(UploadDataPipeGetter);
}; };
@ -110,7 +110,7 @@ class UploadDataPipeGetter {
class MultipartDataPipeGetter : public UploadDataPipeGetter, class MultipartDataPipeGetter : public UploadDataPipeGetter,
public network::mojom::DataPipeGetter { public network::mojom::DataPipeGetter {
public: public:
explicit MultipartDataPipeGetter(URLRequestNS* request) explicit MultipartDataPipeGetter(URLRequest* request)
: UploadDataPipeGetter(request) {} : UploadDataPipeGetter(request) {}
~MultipartDataPipeGetter() override = default; ~MultipartDataPipeGetter() override = default;
@ -141,7 +141,7 @@ class MultipartDataPipeGetter : public UploadDataPipeGetter,
class ChunkedDataPipeGetter : public UploadDataPipeGetter, class ChunkedDataPipeGetter : public UploadDataPipeGetter,
public network::mojom::ChunkedDataPipeGetter { public network::mojom::ChunkedDataPipeGetter {
public: public:
explicit ChunkedDataPipeGetter(URLRequestNS* request) explicit ChunkedDataPipeGetter(URLRequest* request)
: UploadDataPipeGetter(request) {} : UploadDataPipeGetter(request) {}
~ChunkedDataPipeGetter() override = default; ~ChunkedDataPipeGetter() override = default;
@ -166,7 +166,7 @@ class ChunkedDataPipeGetter : public UploadDataPipeGetter,
mojo::ReceiverSet<network::mojom::ChunkedDataPipeGetter> receiver_set_; mojo::ReceiverSet<network::mojom::ChunkedDataPipeGetter> receiver_set_;
}; };
URLRequestNS::URLRequestNS(gin::Arguments* args) : weak_factory_(this) { URLRequest::URLRequest(gin::Arguments* args) : weak_factory_(this) {
request_ = std::make_unique<network::ResourceRequest>(); request_ = std::make_unique<network::ResourceRequest>();
gin_helper::Dictionary dict; gin_helper::Dictionary dict;
if (args->GetNext(&dict)) { if (args->GetNext(&dict)) {
@ -190,17 +190,17 @@ URLRequestNS::URLRequestNS(gin::Arguments* args) : weak_factory_(this) {
InitWithArgs(args); InitWithArgs(args);
} }
URLRequestNS::~URLRequestNS() = default; URLRequest::~URLRequest() = default;
bool URLRequestNS::NotStarted() const { bool URLRequest::NotStarted() const {
return request_state_ == 0; return request_state_ == 0;
} }
bool URLRequestNS::Finished() const { bool URLRequest::Finished() const {
return request_state_ & STATE_FINISHED; return request_state_ & STATE_FINISHED;
} }
void URLRequestNS::Cancel() { void URLRequest::Cancel() {
// Cancel only once. // Cancel only once.
if (request_state_ & (STATE_CANCELED | STATE_CLOSED)) if (request_state_ & (STATE_CANCELED | STATE_CLOSED))
return; return;
@ -215,7 +215,7 @@ void URLRequestNS::Cancel() {
Close(); Close();
} }
void URLRequestNS::Close() { void URLRequest::Close() {
if (!(request_state_ & STATE_CLOSED)) { if (!(request_state_ & STATE_CLOSED)) {
request_state_ |= STATE_CLOSED; request_state_ |= STATE_CLOSED;
if (response_state_ & STATE_STARTED) { if (response_state_ & STATE_STARTED) {
@ -228,7 +228,7 @@ void URLRequestNS::Close() {
loader_.reset(); loader_.reset();
} }
bool URLRequestNS::Write(v8::Local<v8::Value> data, bool is_last) { bool URLRequest::Write(v8::Local<v8::Value> data, bool is_last) {
if (request_state_ & (STATE_FINISHED | STATE_ERROR)) if (request_state_ & (STATE_FINISHED | STATE_ERROR))
return false; return false;
@ -243,12 +243,12 @@ bool URLRequestNS::Write(v8::Local<v8::Value> data, bool is_last) {
network::ResourceRequest* request_ref = request_.get(); network::ResourceRequest* request_ref = request_.get();
loader_ = network::SimpleURLLoader::Create(std::move(request_), loader_ = network::SimpleURLLoader::Create(std::move(request_),
kTrafficAnnotation); kTrafficAnnotation);
loader_->SetOnResponseStartedCallback(base::Bind( loader_->SetOnResponseStartedCallback(
&URLRequestNS::OnResponseStarted, weak_factory_.GetWeakPtr())); base::Bind(&URLRequest::OnResponseStarted, weak_factory_.GetWeakPtr()));
loader_->SetOnRedirectCallback( loader_->SetOnRedirectCallback(
base::Bind(&URLRequestNS::OnRedirect, weak_factory_.GetWeakPtr())); base::Bind(&URLRequest::OnRedirect, weak_factory_.GetWeakPtr()));
loader_->SetOnUploadProgressCallback(base::Bind( loader_->SetOnUploadProgressCallback(
&URLRequestNS::OnUploadProgress, weak_factory_.GetWeakPtr())); base::Bind(&URLRequest::OnUploadProgress, weak_factory_.GetWeakPtr()));
// Create upload data pipe if we have data to write. // Create upload data pipe if we have data to write.
if (length > 0) { if (length > 0) {
@ -286,13 +286,13 @@ bool URLRequestNS::Write(v8::Local<v8::Value> data, bool is_last) {
return true; return true;
} }
void URLRequestNS::FollowRedirect() { void URLRequest::FollowRedirect() {
if (request_state_ & (STATE_CANCELED | STATE_CLOSED)) if (request_state_ & (STATE_CANCELED | STATE_CLOSED))
return; return;
follow_redirect_ = true; follow_redirect_ = true;
} }
bool URLRequestNS::SetExtraHeader(const std::string& name, bool URLRequest::SetExtraHeader(const std::string& name,
const std::string& value) { const std::string& value) {
if (!request_) if (!request_)
return false; return false;
@ -304,17 +304,17 @@ bool URLRequestNS::SetExtraHeader(const std::string& name,
return true; return true;
} }
void URLRequestNS::RemoveExtraHeader(const std::string& name) { void URLRequest::RemoveExtraHeader(const std::string& name) {
if (request_) if (request_)
request_->headers.RemoveHeader(name); request_->headers.RemoveHeader(name);
} }
void URLRequestNS::SetChunkedUpload(bool is_chunked_upload) { void URLRequest::SetChunkedUpload(bool is_chunked_upload) {
if (request_) if (request_)
is_chunked_upload_ = is_chunked_upload; is_chunked_upload_ = is_chunked_upload;
} }
gin::Dictionary URLRequestNS::GetUploadProgress() { gin::Dictionary URLRequest::GetUploadProgress() {
gin::Dictionary progress = gin::Dictionary::CreateEmpty(isolate()); gin::Dictionary progress = gin::Dictionary::CreateEmpty(isolate());
if (loader_) { if (loader_) {
if (request_) if (request_)
@ -330,35 +330,35 @@ gin::Dictionary URLRequestNS::GetUploadProgress() {
return progress; return progress;
} }
int URLRequestNS::StatusCode() const { int URLRequest::StatusCode() const {
if (response_headers_) if (response_headers_)
return response_headers_->response_code(); return response_headers_->response_code();
return -1; return -1;
} }
std::string URLRequestNS::StatusMessage() const { std::string URLRequest::StatusMessage() const {
if (response_headers_) if (response_headers_)
return response_headers_->GetStatusText(); return response_headers_->GetStatusText();
return ""; return "";
} }
net::HttpResponseHeaders* URLRequestNS::RawResponseHeaders() const { net::HttpResponseHeaders* URLRequest::RawResponseHeaders() const {
return response_headers_.get(); return response_headers_.get();
} }
uint32_t URLRequestNS::ResponseHttpVersionMajor() const { uint32_t URLRequest::ResponseHttpVersionMajor() const {
if (response_headers_) if (response_headers_)
return response_headers_->GetHttpVersion().major_value(); return response_headers_->GetHttpVersion().major_value();
return 0; return 0;
} }
uint32_t URLRequestNS::ResponseHttpVersionMinor() const { uint32_t URLRequest::ResponseHttpVersionMinor() const {
if (response_headers_) if (response_headers_)
return response_headers_->GetHttpVersion().minor_value(); return response_headers_->GetHttpVersion().minor_value();
return 0; return 0;
} }
void URLRequestNS::OnDataReceived(base::StringPiece data, void URLRequest::OnDataReceived(base::StringPiece data,
base::OnceClosure resume) { base::OnceClosure resume) {
// In case we received an unexpected event from Chromium net, don't emit any // In case we received an unexpected event from Chromium net, don't emit any
// data event after request cancel/error/close. // data event after request cancel/error/close.
@ -372,9 +372,9 @@ void URLRequestNS::OnDataReceived(base::StringPiece data,
std::move(resume).Run(); std::move(resume).Run();
} }
void URLRequestNS::OnRetry(base::OnceClosure start_retry) {} void URLRequest::OnRetry(base::OnceClosure start_retry) {}
void URLRequestNS::OnComplete(bool success) { void URLRequest::OnComplete(bool success) {
if (success) { if (success) {
// In case we received an unexpected event from Chromium net, don't emit any // In case we received an unexpected event from Chromium net, don't emit any
// data event after request cancel/error/close. // data event after request cancel/error/close.
@ -400,7 +400,7 @@ void URLRequestNS::OnComplete(bool success) {
Close(); Close();
} }
void URLRequestNS::OnResponseStarted( void URLRequest::OnResponseStarted(
const GURL& final_url, const GURL& final_url,
const network::mojom::URLResponseHead& response_head) { const network::mojom::URLResponseHead& response_head) {
// Don't emit any event after request cancel. // Don't emit any event after request cancel.
@ -412,7 +412,7 @@ void URLRequestNS::OnResponseStarted(
Emit("response"); Emit("response");
} }
void URLRequestNS::OnRedirect( void URLRequest::OnRedirect(
const net::RedirectInfo& redirect_info, const net::RedirectInfo& redirect_info,
const network::mojom::URLResponseHead& response_head, const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* to_be_removed_headers) { std::vector<std::string>* to_be_removed_headers) {
@ -455,12 +455,12 @@ void URLRequestNS::OnRedirect(
} }
} }
void URLRequestNS::OnUploadProgress(uint64_t position, uint64_t total) { void URLRequest::OnUploadProgress(uint64_t position, uint64_t total) {
upload_position_ = position; upload_position_ = position;
upload_total_ = total; upload_total_ = total;
} }
void URLRequestNS::OnWrite(MojoResult result) { void URLRequest::OnWrite(MojoResult result) {
if (result != MOJO_RESULT_OK) if (result != MOJO_RESULT_OK)
return; return;
@ -470,17 +470,17 @@ void URLRequestNS::OnWrite(MojoResult result) {
DoWrite(); DoWrite();
} }
void URLRequestNS::DoWrite() { void URLRequest::DoWrite() {
DCHECK(producer_); DCHECK(producer_);
DCHECK(!pending_writes_.empty()); DCHECK(!pending_writes_.empty());
producer_->Write( producer_->Write(
std::make_unique<mojo::StringDataSource>( std::make_unique<mojo::StringDataSource>(
pending_writes_.front(), mojo::StringDataSource::AsyncWritingMode:: pending_writes_.front(), mojo::StringDataSource::AsyncWritingMode::
STRING_STAYS_VALID_UNTIL_COMPLETION), STRING_STAYS_VALID_UNTIL_COMPLETION),
base::BindOnce(&URLRequestNS::OnWrite, weak_factory_.GetWeakPtr())); base::BindOnce(&URLRequest::OnWrite, weak_factory_.GetWeakPtr()));
} }
void URLRequestNS::StartWriting() { void URLRequest::StartWriting() {
if (!last_chunk_written_ || size_callback_.is_null()) if (!last_chunk_written_ || size_callback_.is_null())
return; return;
@ -491,17 +491,17 @@ void URLRequestNS::StartWriting() {
DoWrite(); DoWrite();
} }
void URLRequestNS::Pin() { void URLRequest::Pin() {
if (wrapper_.IsEmpty()) { if (wrapper_.IsEmpty()) {
wrapper_.Reset(isolate(), GetWrapper()); wrapper_.Reset(isolate(), GetWrapper());
} }
} }
void URLRequestNS::Unpin() { void URLRequest::Unpin() {
wrapper_.Reset(); wrapper_.Reset();
} }
void URLRequestNS::EmitError(EventType type, base::StringPiece message) { void URLRequest::EmitError(EventType type, base::StringPiece message) {
if (type == EventType::kRequest) if (type == EventType::kRequest)
request_state_ |= STATE_FAILED; request_state_ |= STATE_FAILED;
else else
@ -512,7 +512,7 @@ void URLRequestNS::EmitError(EventType type, base::StringPiece message) {
} }
template <typename... Args> template <typename... Args>
void URLRequestNS::EmitEvent(EventType type, Args... args) { void URLRequest::EmitEvent(EventType type, Args... args) {
const char* method = const char* method =
type == EventType::kRequest ? "_emitRequestEvent" : "_emitResponseEvent"; type == EventType::kRequest ? "_emitRequestEvent" : "_emitResponseEvent";
v8::HandleScope handle_scope(isolate()); v8::HandleScope handle_scope(isolate());
@ -520,30 +520,30 @@ void URLRequestNS::EmitEvent(EventType type, Args... args) {
} }
// static // static
mate::WrappableBase* URLRequestNS::New(gin::Arguments* args) { mate::WrappableBase* URLRequest::New(gin::Arguments* args) {
return new URLRequestNS(args); return new URLRequest(args);
} }
// static // static
void URLRequestNS::BuildPrototype(v8::Isolate* isolate, void URLRequest::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) { v8::Local<v8::FunctionTemplate> prototype) {
prototype->SetClassName(gin::StringToV8(isolate, "URLRequest")); prototype->SetClassName(gin::StringToV8(isolate, "URLRequest"));
gin_helper::Destroyable::MakeDestroyable(isolate, prototype); gin_helper::Destroyable::MakeDestroyable(isolate, prototype);
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("write", &URLRequestNS::Write) .SetMethod("write", &URLRequest::Write)
.SetMethod("cancel", &URLRequestNS::Cancel) .SetMethod("cancel", &URLRequest::Cancel)
.SetMethod("setExtraHeader", &URLRequestNS::SetExtraHeader) .SetMethod("setExtraHeader", &URLRequest::SetExtraHeader)
.SetMethod("removeExtraHeader", &URLRequestNS::RemoveExtraHeader) .SetMethod("removeExtraHeader", &URLRequest::RemoveExtraHeader)
.SetMethod("setChunkedUpload", &URLRequestNS::SetChunkedUpload) .SetMethod("setChunkedUpload", &URLRequest::SetChunkedUpload)
.SetMethod("followRedirect", &URLRequestNS::FollowRedirect) .SetMethod("followRedirect", &URLRequest::FollowRedirect)
.SetMethod("getUploadProgress", &URLRequestNS::GetUploadProgress) .SetMethod("getUploadProgress", &URLRequest::GetUploadProgress)
.SetProperty("notStarted", &URLRequestNS::NotStarted) .SetProperty("notStarted", &URLRequest::NotStarted)
.SetProperty("finished", &URLRequestNS::Finished) .SetProperty("finished", &URLRequest::Finished)
.SetProperty("statusCode", &URLRequestNS::StatusCode) .SetProperty("statusCode", &URLRequest::StatusCode)
.SetProperty("statusMessage", &URLRequestNS::StatusMessage) .SetProperty("statusMessage", &URLRequest::StatusMessage)
.SetProperty("rawResponseHeaders", &URLRequestNS::RawResponseHeaders) .SetProperty("rawResponseHeaders", &URLRequest::RawResponseHeaders)
.SetProperty("httpVersionMajor", &URLRequestNS::ResponseHttpVersionMajor) .SetProperty("httpVersionMajor", &URLRequest::ResponseHttpVersionMajor)
.SetProperty("httpVersionMinor", &URLRequestNS::ResponseHttpVersionMinor); .SetProperty("httpVersionMinor", &URLRequest::ResponseHttpVersionMinor);
} }
} // namespace api } // namespace api

View file

@ -2,8 +2,8 @@
// Use of this source code is governed by the MIT license that can be // Use of this source code is governed by the MIT license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_URL_REQUEST_NS_H_ #ifndef SHELL_BROWSER_API_ATOM_API_URL_REQUEST_H_
#define SHELL_BROWSER_API_ATOM_API_URL_REQUEST_NS_H_ #define SHELL_BROWSER_API_ATOM_API_URL_REQUEST_H_
#include <list> #include <list>
#include <memory> #include <memory>
@ -25,7 +25,7 @@ namespace api {
class UploadDataPipeGetter; class UploadDataPipeGetter;
class URLRequestNS : public mate::EventEmitter<URLRequestNS>, class URLRequest : public mate::EventEmitter<URLRequest>,
public network::SimpleURLLoaderStreamConsumer { public network::SimpleURLLoaderStreamConsumer {
public: public:
static mate::WrappableBase* New(gin::Arguments* args); static mate::WrappableBase* New(gin::Arguments* args);
@ -34,8 +34,8 @@ class URLRequestNS : public mate::EventEmitter<URLRequestNS>,
v8::Local<v8::FunctionTemplate> prototype); v8::Local<v8::FunctionTemplate> prototype);
protected: protected:
explicit URLRequestNS(gin::Arguments* args); explicit URLRequest(gin::Arguments* args);
~URLRequestNS() override; ~URLRequest() override;
bool NotStarted() const; bool NotStarted() const;
bool Finished() const; bool Finished() const;
@ -132,13 +132,13 @@ class URLRequestNS : public mate::EventEmitter<URLRequestNS>,
// Used by pin/unpin to manage lifetime. // Used by pin/unpin to manage lifetime.
v8::Global<v8::Object> wrapper_; v8::Global<v8::Object> wrapper_;
base::WeakPtrFactory<URLRequestNS> weak_factory_; base::WeakPtrFactory<URLRequest> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(URLRequestNS); DISALLOW_COPY_AND_ASSIGN(URLRequest);
}; };
} // namespace api } // namespace api
} // namespace electron } // namespace electron
#endif // SHELL_BROWSER_API_ATOM_API_URL_REQUEST_NS_H_ #endif // SHELL_BROWSER_API_ATOM_API_URL_REQUEST_H_

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by the MIT license that can be // Use of this source code is governed by the MIT license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "shell/browser/api/atom_api_web_request_ns.h" #include "shell/browser/api/atom_api_web_request.h"
#include <memory> #include <memory>
#include <string> #include <string>
@ -79,12 +79,12 @@ namespace api {
namespace { namespace {
const char* kUserDataKey = "WebRequestNS"; const char* kUserDataKey = "WebRequest";
// BrowserContext <=> WebRequestNS relationship. // BrowserContext <=> WebRequest relationship.
struct UserData : public base::SupportsUserData::Data { struct UserData : public base::SupportsUserData::Data {
explicit UserData(WebRequestNS* data) : data(data) {} explicit UserData(WebRequest* data) : data(data) {}
WebRequestNS* data; WebRequest* data;
}; };
// Test whether the URL of |request| matches |patterns|. // Test whether the URL of |request| matches |patterns|.
@ -212,61 +212,61 @@ void ReadFromResponse(v8::Isolate* isolate,
} // namespace } // namespace
gin::WrapperInfo WebRequestNS::kWrapperInfo = {gin::kEmbedderNativeGin}; gin::WrapperInfo WebRequest::kWrapperInfo = {gin::kEmbedderNativeGin};
WebRequestNS::SimpleListenerInfo::SimpleListenerInfo( WebRequest::SimpleListenerInfo::SimpleListenerInfo(
std::set<URLPattern> patterns_, std::set<URLPattern> patterns_,
SimpleListener listener_) SimpleListener listener_)
: url_patterns(std::move(patterns_)), listener(listener_) {} : url_patterns(std::move(patterns_)), listener(listener_) {}
WebRequestNS::SimpleListenerInfo::SimpleListenerInfo() = default; WebRequest::SimpleListenerInfo::SimpleListenerInfo() = default;
WebRequestNS::SimpleListenerInfo::~SimpleListenerInfo() = default; WebRequest::SimpleListenerInfo::~SimpleListenerInfo() = default;
WebRequestNS::ResponseListenerInfo::ResponseListenerInfo( WebRequest::ResponseListenerInfo::ResponseListenerInfo(
std::set<URLPattern> patterns_, std::set<URLPattern> patterns_,
ResponseListener listener_) ResponseListener listener_)
: url_patterns(std::move(patterns_)), listener(listener_) {} : url_patterns(std::move(patterns_)), listener(listener_) {}
WebRequestNS::ResponseListenerInfo::ResponseListenerInfo() = default; WebRequest::ResponseListenerInfo::ResponseListenerInfo() = default;
WebRequestNS::ResponseListenerInfo::~ResponseListenerInfo() = default; WebRequest::ResponseListenerInfo::~ResponseListenerInfo() = default;
WebRequestNS::WebRequestNS(v8::Isolate* isolate, WebRequest::WebRequest(v8::Isolate* isolate,
content::BrowserContext* browser_context) content::BrowserContext* browser_context)
: browser_context_(browser_context) { : browser_context_(browser_context) {
browser_context_->SetUserData(kUserDataKey, std::make_unique<UserData>(this)); browser_context_->SetUserData(kUserDataKey, std::make_unique<UserData>(this));
} }
WebRequestNS::~WebRequestNS() { WebRequest::~WebRequest() {
browser_context_->RemoveUserData(kUserDataKey); browser_context_->RemoveUserData(kUserDataKey);
} }
gin::ObjectTemplateBuilder WebRequestNS::GetObjectTemplateBuilder( gin::ObjectTemplateBuilder WebRequest::GetObjectTemplateBuilder(
v8::Isolate* isolate) { v8::Isolate* isolate) {
return gin::Wrappable<WebRequestNS>::GetObjectTemplateBuilder(isolate) return gin::Wrappable<WebRequest>::GetObjectTemplateBuilder(isolate)
.SetMethod("onBeforeRequest", .SetMethod("onBeforeRequest",
&WebRequestNS::SetResponseListener<kOnBeforeRequest>) &WebRequest::SetResponseListener<kOnBeforeRequest>)
.SetMethod("onBeforeSendHeaders", .SetMethod("onBeforeSendHeaders",
&WebRequestNS::SetResponseListener<kOnBeforeSendHeaders>) &WebRequest::SetResponseListener<kOnBeforeSendHeaders>)
.SetMethod("onHeadersReceived", .SetMethod("onHeadersReceived",
&WebRequestNS::SetResponseListener<kOnHeadersReceived>) &WebRequest::SetResponseListener<kOnHeadersReceived>)
.SetMethod("onSendHeaders", .SetMethod("onSendHeaders",
&WebRequestNS::SetSimpleListener<kOnSendHeaders>) &WebRequest::SetSimpleListener<kOnSendHeaders>)
.SetMethod("onBeforeRedirect", .SetMethod("onBeforeRedirect",
&WebRequestNS::SetSimpleListener<kOnBeforeRedirect>) &WebRequest::SetSimpleListener<kOnBeforeRedirect>)
.SetMethod("onResponseStarted", .SetMethod("onResponseStarted",
&WebRequestNS::SetSimpleListener<kOnResponseStarted>) &WebRequest::SetSimpleListener<kOnResponseStarted>)
.SetMethod("onErrorOccurred", .SetMethod("onErrorOccurred",
&WebRequestNS::SetSimpleListener<kOnErrorOccurred>) &WebRequest::SetSimpleListener<kOnErrorOccurred>)
.SetMethod("onCompleted", &WebRequestNS::SetSimpleListener<kOnCompleted>); .SetMethod("onCompleted", &WebRequest::SetSimpleListener<kOnCompleted>);
} }
const char* WebRequestNS::GetTypeName() { const char* WebRequest::GetTypeName() {
return "WebRequest"; return "WebRequest";
} }
bool WebRequestNS::HasListener() const { bool WebRequest::HasListener() const {
return !(simple_listeners_.empty() && response_listeners_.empty()); return !(simple_listeners_.empty() && response_listeners_.empty());
} }
int WebRequestNS::OnBeforeRequest(extensions::WebRequestInfo* info, int WebRequest::OnBeforeRequest(extensions::WebRequestInfo* info,
const network::ResourceRequest& request, const network::ResourceRequest& request,
net::CompletionOnceCallback callback, net::CompletionOnceCallback callback,
GURL* new_url) { GURL* new_url) {
@ -274,7 +274,7 @@ int WebRequestNS::OnBeforeRequest(extensions::WebRequestInfo* info,
new_url, request); new_url, request);
} }
int WebRequestNS::OnBeforeSendHeaders(extensions::WebRequestInfo* info, int WebRequest::OnBeforeSendHeaders(extensions::WebRequestInfo* info,
const network::ResourceRequest& request, const network::ResourceRequest& request,
BeforeSendHeadersCallback callback, BeforeSendHeadersCallback callback,
net::HttpRequestHeaders* headers) { net::HttpRequestHeaders* headers) {
@ -285,7 +285,7 @@ int WebRequestNS::OnBeforeSendHeaders(extensions::WebRequestInfo* info,
headers, request, *headers); headers, request, *headers);
} }
int WebRequestNS::OnHeadersReceived( int WebRequest::OnHeadersReceived(
extensions::WebRequestInfo* info, extensions::WebRequestInfo* info,
const network::ResourceRequest& request, const network::ResourceRequest& request,
net::CompletionOnceCallback callback, net::CompletionOnceCallback callback,
@ -299,24 +299,24 @@ int WebRequestNS::OnHeadersReceived(
request); request);
} }
void WebRequestNS::OnSendHeaders(extensions::WebRequestInfo* info, void WebRequest::OnSendHeaders(extensions::WebRequestInfo* info,
const network::ResourceRequest& request, const network::ResourceRequest& request,
const net::HttpRequestHeaders& headers) { const net::HttpRequestHeaders& headers) {
HandleSimpleEvent(kOnSendHeaders, info, request, headers); HandleSimpleEvent(kOnSendHeaders, info, request, headers);
} }
void WebRequestNS::OnBeforeRedirect(extensions::WebRequestInfo* info, void WebRequest::OnBeforeRedirect(extensions::WebRequestInfo* info,
const network::ResourceRequest& request, const network::ResourceRequest& request,
const GURL& new_location) { const GURL& new_location) {
HandleSimpleEvent(kOnBeforeRedirect, info, request, new_location); HandleSimpleEvent(kOnBeforeRedirect, info, request, new_location);
} }
void WebRequestNS::OnResponseStarted(extensions::WebRequestInfo* info, void WebRequest::OnResponseStarted(extensions::WebRequestInfo* info,
const network::ResourceRequest& request) { const network::ResourceRequest& request) {
HandleSimpleEvent(kOnResponseStarted, info, request); HandleSimpleEvent(kOnResponseStarted, info, request);
} }
void WebRequestNS::OnErrorOccurred(extensions::WebRequestInfo* info, void WebRequest::OnErrorOccurred(extensions::WebRequestInfo* info,
const network::ResourceRequest& request, const network::ResourceRequest& request,
int net_error) { int net_error) {
callbacks_.erase(info->id); callbacks_.erase(info->id);
@ -324,7 +324,7 @@ void WebRequestNS::OnErrorOccurred(extensions::WebRequestInfo* info,
HandleSimpleEvent(kOnErrorOccurred, info, request, net_error); HandleSimpleEvent(kOnErrorOccurred, info, request, net_error);
} }
void WebRequestNS::OnCompleted(extensions::WebRequestInfo* info, void WebRequest::OnCompleted(extensions::WebRequestInfo* info,
const network::ResourceRequest& request, const network::ResourceRequest& request,
int net_error) { int net_error) {
callbacks_.erase(info->id); callbacks_.erase(info->id);
@ -332,18 +332,18 @@ void WebRequestNS::OnCompleted(extensions::WebRequestInfo* info,
HandleSimpleEvent(kOnCompleted, info, request, net_error); HandleSimpleEvent(kOnCompleted, info, request, net_error);
} }
template <WebRequestNS::SimpleEvent event> template <WebRequest::SimpleEvent event>
void WebRequestNS::SetSimpleListener(gin::Arguments* args) { void WebRequest::SetSimpleListener(gin::Arguments* args) {
SetListener<SimpleListener>(event, &simple_listeners_, args); SetListener<SimpleListener>(event, &simple_listeners_, args);
} }
template <WebRequestNS::ResponseEvent event> template <WebRequest::ResponseEvent event>
void WebRequestNS::SetResponseListener(gin::Arguments* args) { void WebRequest::SetResponseListener(gin::Arguments* args) {
SetListener<ResponseListener>(event, &response_listeners_, args); SetListener<ResponseListener>(event, &response_listeners_, args);
} }
template <typename Listener, typename Listeners, typename Event> template <typename Listener, typename Listeners, typename Event>
void WebRequestNS::SetListener(Event event, void WebRequest::SetListener(Event event,
Listeners* listeners, Listeners* listeners,
gin::Arguments* args) { gin::Arguments* args) {
v8::Local<v8::Value> arg; v8::Local<v8::Value> arg;
@ -393,7 +393,7 @@ void WebRequestNS::SetListener(Event event,
} }
template <typename... Args> template <typename... Args>
void WebRequestNS::HandleSimpleEvent(SimpleEvent event, void WebRequest::HandleSimpleEvent(SimpleEvent event,
extensions::WebRequestInfo* request_info, extensions::WebRequestInfo* request_info,
Args... args) { Args... args) {
const auto iter = simple_listeners_.find(event); const auto iter = simple_listeners_.find(event);
@ -412,7 +412,7 @@ void WebRequestNS::HandleSimpleEvent(SimpleEvent event,
} }
template <typename Out, typename... Args> template <typename Out, typename... Args>
int WebRequestNS::HandleResponseEvent(ResponseEvent event, int WebRequest::HandleResponseEvent(ResponseEvent event,
extensions::WebRequestInfo* request_info, extensions::WebRequestInfo* request_info,
net::CompletionOnceCallback callback, net::CompletionOnceCallback callback,
Out out, Out out,
@ -433,14 +433,14 @@ int WebRequestNS::HandleResponseEvent(ResponseEvent event,
FillDetails(&details, request_info, args...); FillDetails(&details, request_info, args...);
ResponseCallback response = ResponseCallback response =
base::BindOnce(&WebRequestNS::OnListenerResult<Out>, base::BindOnce(&WebRequest::OnListenerResult<Out>, base::Unretained(this),
base::Unretained(this), request_info->id, out); request_info->id, out);
info.listener.Run(gin::ConvertToV8(isolate, details), std::move(response)); info.listener.Run(gin::ConvertToV8(isolate, details), std::move(response));
return net::ERR_IO_PENDING; return net::ERR_IO_PENDING;
} }
template <typename T> template <typename T>
void WebRequestNS::OnListenerResult(uint64_t id, void WebRequest::OnListenerResult(uint64_t id,
T out, T out,
v8::Local<v8::Value> response) { v8::Local<v8::Value> response) {
const auto iter = callbacks_.find(id); const auto iter = callbacks_.find(id);
@ -468,10 +468,10 @@ void WebRequestNS::OnListenerResult(uint64_t id,
} }
// static // static
gin::Handle<WebRequestNS> WebRequestNS::FromOrCreate( gin::Handle<WebRequest> WebRequest::FromOrCreate(
v8::Isolate* isolate, v8::Isolate* isolate,
content::BrowserContext* browser_context) { content::BrowserContext* browser_context) {
gin::Handle<WebRequestNS> handle = From(isolate, browser_context); gin::Handle<WebRequest> handle = From(isolate, browser_context);
if (handle.IsEmpty()) { if (handle.IsEmpty()) {
// Make sure the |Session| object has the |webRequest| property created. // Make sure the |Session| object has the |webRequest| property created.
v8::Local<v8::Value> web_request = v8::Local<v8::Value> web_request =
@ -485,24 +485,24 @@ gin::Handle<WebRequestNS> WebRequestNS::FromOrCreate(
} }
// static // static
gin::Handle<WebRequestNS> WebRequestNS::Create( gin::Handle<WebRequest> WebRequest::Create(
v8::Isolate* isolate, v8::Isolate* isolate,
content::BrowserContext* browser_context) { content::BrowserContext* browser_context) {
DCHECK(From(isolate, browser_context).IsEmpty()) DCHECK(From(isolate, browser_context).IsEmpty())
<< "WebRequestNS already created"; << "WebRequest already created";
return gin::CreateHandle(isolate, new WebRequestNS(isolate, browser_context)); return gin::CreateHandle(isolate, new WebRequest(isolate, browser_context));
} }
// static // static
gin::Handle<WebRequestNS> WebRequestNS::From( gin::Handle<WebRequest> WebRequest::From(
v8::Isolate* isolate, v8::Isolate* isolate,
content::BrowserContext* browser_context) { content::BrowserContext* browser_context) {
if (!browser_context) if (!browser_context)
return gin::Handle<WebRequestNS>(); return gin::Handle<WebRequest>();
auto* user_data = auto* user_data =
static_cast<UserData*>(browser_context->GetUserData(kUserDataKey)); static_cast<UserData*>(browser_context->GetUserData(kUserDataKey));
if (!user_data) if (!user_data)
return gin::Handle<WebRequestNS>(); return gin::Handle<WebRequest>();
return gin::CreateHandle(isolate, user_data->data); return gin::CreateHandle(isolate, user_data->data);
} }

View file

@ -2,8 +2,8 @@
// Use of this source code is governed by the MIT license that can be // Use of this source code is governed by the MIT license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef SHELL_BROWSER_API_ATOM_API_WEB_REQUEST_NS_H_ #ifndef SHELL_BROWSER_API_ATOM_API_WEB_REQUEST_H_
#define SHELL_BROWSER_API_ATOM_API_WEB_REQUEST_NS_H_ #define SHELL_BROWSER_API_ATOM_API_WEB_REQUEST_H_
#include <map> #include <map>
#include <set> #include <set>
@ -23,7 +23,7 @@ namespace electron {
namespace api { namespace api {
class WebRequestNS : public gin::Wrappable<WebRequestNS>, public WebRequestAPI { class WebRequest : public gin::Wrappable<WebRequest>, public WebRequestAPI {
public: public:
static gin::WrapperInfo kWrapperInfo; static gin::WrapperInfo kWrapperInfo;
@ -31,18 +31,17 @@ class WebRequestNS : public gin::Wrappable<WebRequestNS>, public WebRequestAPI {
// is no one. // is no one.
// Note that the lifetime of WebRequest object is managed by Session, instead // Note that the lifetime of WebRequest object is managed by Session, instead
// of the caller. // of the caller.
static gin::Handle<WebRequestNS> FromOrCreate( static gin::Handle<WebRequest> FromOrCreate(
v8::Isolate* isolate, v8::Isolate* isolate,
content::BrowserContext* browser_context); content::BrowserContext* browser_context);
// Return a new WebRequest object, this should only be called by Session. // Return a new WebRequest object, this should only be called by Session.
static gin::Handle<WebRequestNS> Create( static gin::Handle<WebRequest> Create(
v8::Isolate* isolate, v8::Isolate* isolate,
content::BrowserContext* browser_context); content::BrowserContext* browser_context);
// Find the WebRequest object attached to |browser_context|. // Find the WebRequest object attached to |browser_context|.
static gin::Handle<WebRequestNS> From( static gin::Handle<WebRequest> From(v8::Isolate* isolate,
v8::Isolate* isolate,
content::BrowserContext* browser_context); content::BrowserContext* browser_context);
// gin::Wrappable: // gin::Wrappable:
@ -51,8 +50,8 @@ class WebRequestNS : public gin::Wrappable<WebRequestNS>, public WebRequestAPI {
const char* GetTypeName() override; const char* GetTypeName() override;
private: private:
WebRequestNS(v8::Isolate* isolate, content::BrowserContext* browser_context); WebRequest(v8::Isolate* isolate, content::BrowserContext* browser_context);
~WebRequestNS() override; ~WebRequest() override;
// WebRequestAPI: // WebRequestAPI:
bool HasListener() const override; bool HasListener() const override;
@ -155,4 +154,4 @@ class WebRequestNS : public gin::Wrappable<WebRequestNS>, public WebRequestAPI {
} // namespace electron } // namespace electron
#endif // SHELL_BROWSER_API_ATOM_API_WEB_REQUEST_NS_H_ #endif // SHELL_BROWSER_API_ATOM_API_WEB_REQUEST_H_

View file

@ -50,10 +50,10 @@
#include "services/network/public/cpp/resource_request_body.h" #include "services/network/public/cpp/resource_request_body.h"
#include "shell/app/manifests.h" #include "shell/app/manifests.h"
#include "shell/browser/api/atom_api_app.h" #include "shell/browser/api/atom_api_app.h"
#include "shell/browser/api/atom_api_protocol_ns.h" #include "shell/browser/api/atom_api_protocol.h"
#include "shell/browser/api/atom_api_session.h" #include "shell/browser/api/atom_api_session.h"
#include "shell/browser/api/atom_api_web_contents.h" #include "shell/browser/api/atom_api_web_contents.h"
#include "shell/browser/api/atom_api_web_request_ns.h" #include "shell/browser/api/atom_api_web_request.h"
#include "shell/browser/atom_autofill_driver_factory.h" #include "shell/browser/atom_autofill_driver_factory.h"
#include "shell/browser/atom_browser_context.h" #include "shell/browser/atom_browser_context.h"
#include "shell/browser/atom_browser_main_parts.h" #include "shell/browser/atom_browser_main_parts.h"
@ -956,7 +956,7 @@ void AtomBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories(
NonNetworkURLLoaderFactoryMap* factories) { NonNetworkURLLoaderFactoryMap* factories) {
content::WebContents* web_contents = content::WebContents* web_contents =
content::WebContents::FromFrameTreeNodeId(frame_tree_node_id); content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
api::ProtocolNS* protocol = api::ProtocolNS::FromWrappedClass( api::Protocol* protocol = api::Protocol::FromWrappedClass(
v8::Isolate::GetCurrent(), web_contents->GetBrowserContext()); v8::Isolate::GetCurrent(), web_contents->GetBrowserContext());
if (protocol) if (protocol)
protocol->RegisterURLLoaderFactories(factories); protocol->RegisterURLLoaderFactories(factories);
@ -972,7 +972,7 @@ void AtomBrowserClient::RegisterNonNetworkSubresourceURLLoaderFactories(
content::WebContents* web_contents = content::WebContents* web_contents =
content::WebContents::FromRenderFrameHost(frame_host); content::WebContents::FromRenderFrameHost(frame_host);
if (web_contents) { if (web_contents) {
api::ProtocolNS* protocol = api::ProtocolNS::FromWrappedClass( api::Protocol* protocol = api::Protocol::FromWrappedClass(
v8::Isolate::GetCurrent(), web_contents->GetBrowserContext()); v8::Isolate::GetCurrent(), web_contents->GetBrowserContext());
if (protocol) if (protocol)
protocol->RegisterURLLoaderFactories(factories); protocol->RegisterURLLoaderFactories(factories);
@ -990,10 +990,10 @@ bool AtomBrowserClient::WillCreateURLLoaderFactory(
header_client, header_client,
bool* bypass_redirect_checks) { bool* bypass_redirect_checks) {
v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Isolate* isolate = v8::Isolate::GetCurrent();
api::ProtocolNS* protocol = api::Protocol* protocol =
api::ProtocolNS::FromWrappedClass(isolate, browser_context); api::Protocol::FromWrappedClass(isolate, browser_context);
DCHECK(protocol); DCHECK(protocol);
auto web_request = api::WebRequestNS::FromOrCreate(isolate, browser_context); auto web_request = api::WebRequest::FromOrCreate(isolate, browser_context);
DCHECK(web_request.get()); DCHECK(web_request.get());
auto proxied_receiver = std::move(*factory_receiver); auto proxied_receiver = std::move(*factory_receiver);

View file

@ -23,7 +23,7 @@
namespace electron { namespace electron {
// Defines the interface for WebRequest API, implemented by api::WebRequestNS. // Defines the interface for WebRequest API, implemented by api::WebRequest.
class WebRequestAPI { class WebRequestAPI {
public: public:
virtual ~WebRequestAPI() {} virtual ~WebRequestAPI() {}
@ -236,12 +236,12 @@ class ProxyingURLLoaderFactory
void RemoveRequest(int32_t network_service_request_id, uint64_t request_id); void RemoveRequest(int32_t network_service_request_id, uint64_t request_id);
void MaybeDeleteThis(); void MaybeDeleteThis();
// Passed from api::WebRequestNS. // Passed from api::WebRequest.
WebRequestAPI* web_request_api_; WebRequestAPI* web_request_api_;
// This is passed from api::ProtocolNS. // This is passed from api::Protocol.
// //
// The ProtocolNS instance lives through the lifetime of BrowserContenxt, // The Protocol instance lives through the lifetime of BrowserContenxt,
// which is guarenteed to cover the lifetime of URLLoaderFactory, so the // which is guarenteed to cover the lifetime of URLLoaderFactory, so the
// reference is guarenteed to be valid. // reference is guarenteed to be valid.
// //