Skip to content

Commit

Permalink
feat: migrate webRequest module to NetworkService (#19979)
Browse files Browse the repository at this point in the history
* feat: associate InProgressRequest with requests (#19648)

* feat: migrate webRequest module to NetworkService (Part 4) (#19679)

* chore: use gin in WebRequest

* Add stubs for APIs

* feat: migrate webRequest module to NetworkService (Part 5) (#19714)

* Pass WebRequest to ProxyingURLLoaderFactory

* Call WebRequestAPI in InProgressRequest

* Store the listeners

* Pass the request and response

* Add stub to handle the events

* Use extensions::WebRequestInfo

* Make sure webRequest is managed by Session

* chore: make creation of WebRequestNS more clear

* fix: check WebContents for service workers

* feat: migrate webRequest module to NetworkService (Part 6) (#19752)

* Implement OnBeforeSendHeaders

* Pass the request

* Handle simple listeners

* Handle response listeners

* Read responses from listener

* feat: migrate webRequest module to NetworkService (Part 7) (#19820)

* fix: gin treats Function as Dictionary when doing convertions

* fix: check if listener exists

* fix: listener callback should be executed in next tick

* feat: make InProgressRequest work

* test: re-enable protocol test that relies on webRequest

* chore: merge conditions

* feat: migrate webRequest module to NetworkService (Part 8) (#19841)

* fix: fill uploadData property

* fix: requestHeaders in onBeforeSendHeaders

* fix: responseHeaders in onHeadersReceived

* fix: header keys should not be lowercased

* fix: gin::Dictionary::Get succeeds even though key does not exist...

* fix: throw for invalid filters

* test: re-enable api-web-request-spec

* chore: do not use deprecated base::Value API

* feat: migrate webRequest module to NetworkService (Part 9) (#19976)

* no need to get WebContents for URLLoaderFactory

* consult embedder for network_factory created in net module

* set disable_web_security to false

* re-enable webRequest tests in net module
  • Loading branch information
deepak1556 authored and John Kleinschmidt committed Aug 27, 2019
1 parent b09a1c7 commit d3e0c46
Show file tree
Hide file tree
Showing 16 changed files with 1,143 additions and 102 deletions.
5 changes: 5 additions & 0 deletions filenames.gni
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,11 @@ filenames = {
"shell/common/crash_reporter/linux/crash_dump_handler.h",
"shell/common/crash_reporter/win/crash_service_main.cc",
"shell/common/crash_reporter/win/crash_service_main.h",
"shell/common/gin_converters/callback_converter_gin_adapter.h",
"shell/common/gin_converters/gurl_converter_gin_adapter.h",
"shell/common/gin_converters/net_converter_gin_adapter.h",
"shell/common/gin_converters/std_converter.h",
"shell/common/gin_converters/value_converter_gin_adapter.h",
"shell/common/gin_util.h",
"shell/common/heap_snapshot.cc",
"shell/common/heap_snapshot.h",
Expand Down
4 changes: 3 additions & 1 deletion shell/browser/api/atom_api_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,10 @@ Session::Session(v8::Isolate* isolate, AtomBrowserContext* browser_context)
Session::~Session() {
content::BrowserContext::GetDownloadManager(browser_context())
->RemoveObserver(this);
// TODO(zcbenz): Now since URLRequestContextGetter is gone, is this still
// needed?
// Refs https://github.com/electron/electron/pull/12305.
DestroyGlobalHandle(isolate(), cookies_);
DestroyGlobalHandle(isolate(), web_request_);
DestroyGlobalHandle(isolate(), protocol_);
DestroyGlobalHandle(isolate(), net_log_);
g_sessions.erase(weak_map_id());
Expand Down
6 changes: 4 additions & 2 deletions shell/browser/api/atom_api_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,14 @@ class Session : public mate::TrackableObject<Session>,
download::DownloadItem* item) override;

private:
// Cached object.
// Cached mate::Wrappable objects.
v8::Global<v8::Value> cookies_;
v8::Global<v8::Value> protocol_;
v8::Global<v8::Value> web_request_;
v8::Global<v8::Value> net_log_;

// Cached object.
v8::Global<v8::Value> web_request_;

// The client id to enable the network throttler.
base::UnguessableToken network_emulation_token_;

Expand Down
32 changes: 30 additions & 2 deletions shell/browser/api/atom_api_url_request_ns.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include "mojo/public/cpp/system/string_data_source.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
#include "services/network/public/cpp/wrapper_shared_url_loader_factory.h"
#include "shell/browser/api/atom_api_session.h"
#include "shell/browser/atom_browser_client.h"
#include "shell/browser/atom_browser_context.h"
#include "shell/common/native_mate_converters/gurl_converter.h"
#include "shell/common/native_mate_converters/net_converter.h"
Expand Down Expand Up @@ -178,9 +180,35 @@ URLRequestNS::URLRequestNS(mate::Arguments* args) : weak_factory_(this) {
}

auto* browser_context = session->browser_context();
auto* storage_partition =
content::BrowserContext::GetDefaultStoragePartition(browser_context);

network::mojom::URLLoaderFactoryPtr network_factory;
mojo::PendingReceiver<network::mojom::URLLoaderFactory> factory_request =
mojo::MakeRequest(&network_factory);

// Consult the embedder.
network::mojom::TrustedURLLoaderHeaderClientPtrInfo header_client;
static_cast<content::ContentBrowserClient*>(AtomBrowserClient::Get())
->WillCreateURLLoaderFactory(browser_context, nullptr, -1,
true /* is_navigation */,
false /* is_download */, url::Origin(),
&factory_request, &header_client, nullptr);

network::mojom::URLLoaderFactoryParamsPtr params =
network::mojom::URLLoaderFactoryParams::New();
params->header_client = std::move(header_client);
params->process_id = network::mojom::kBrowserProcessId;
params->is_corb_enabled = false;
// The tests of net module would fail if this setting is true, it seems that
// the non-NetworkService implementation always has web security enabled.
params->disable_web_security = false;

storage_partition->GetNetworkContext()->CreateURLLoaderFactory(
std::move(factory_request), std::move(params));
url_loader_factory_ =
content::BrowserContext::GetDefaultStoragePartition(browser_context)
->GetURLLoaderFactoryForBrowserProcess();
base::MakeRefCounted<network::WrapperSharedURLLoaderFactory>(
std::move(network_factory));

InitWith(args->isolate(), args->GetThis());
}
Expand Down

0 comments on commit d3e0c46

Please sign in to comment.