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
This commit is contained in:
Cheng Zhao 2019-08-13 14:47:35 +09:00 committed by GitHub
parent 9713fa09e7
commit 69eac0d9d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 365 additions and 46 deletions

View file

@ -52,6 +52,7 @@
#include "shell/browser/api/atom_api_app.h"
#include "shell/browser/api/atom_api_protocol_ns.h"
#include "shell/browser/api/atom_api_web_contents.h"
#include "shell/browser/api/atom_api_web_request_ns.h"
#include "shell/browser/atom_browser_context.h"
#include "shell/browser/atom_browser_main_parts.h"
#include "shell/browser/atom_navigation_throttle.h"
@ -979,13 +980,17 @@ bool AtomBrowserClient::WillCreateURLLoaderFactory(
bool* bypass_redirect_checks) {
content::WebContents* web_contents =
content::WebContents::FromRenderFrameHost(frame_host);
if (!web_contents) {
// For service workers there might be no WebContents.
if (!web_contents)
return false;
}
v8::Isolate* isolate = v8::Isolate::GetCurrent();
api::ProtocolNS* protocol = api::ProtocolNS::FromWrappedClass(
v8::Isolate::GetCurrent(), web_contents->GetBrowserContext());
if (!protocol)
return false;
isolate, web_contents->GetBrowserContext());
DCHECK(protocol);
auto web_request = api::WebRequestNS::FromOrCreate(
isolate, web_contents->GetBrowserContext());
DCHECK(web_request.get());
auto proxied_receiver = std::move(*factory_receiver);
network::mojom::URLLoaderFactoryPtrInfo target_factory_info;
@ -996,8 +1001,9 @@ bool AtomBrowserClient::WillCreateURLLoaderFactory(
header_client_request = mojo::MakeRequest(header_client);
new ProxyingURLLoaderFactory(
protocol->intercept_handlers(), std::move(proxied_receiver),
std::move(target_factory_info), std::move(header_client_request));
web_request.get(), protocol->intercept_handlers(), render_process_id,
std::move(proxied_receiver), std::move(target_factory_info),
std::move(header_client_request));
if (bypass_redirect_checks)
*bypass_redirect_checks = true;