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
This commit is contained in:
parent
bdb20d53cb
commit
4eee71ffbf
3 changed files with 35 additions and 13 deletions
|
@ -11,8 +11,10 @@
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
#include "native_mate/object_template_builder.h"
|
#include "native_mate/object_template_builder.h"
|
||||||
#include "net/http/http_util.h"
|
#include "net/http/http_util.h"
|
||||||
|
#include "services/network/public/cpp/wrapper_shared_url_loader_factory.h"
|
||||||
#include "services/network/public/mojom/chunked_data_pipe_getter.mojom.h"
|
#include "services/network/public/mojom/chunked_data_pipe_getter.mojom.h"
|
||||||
#include "shell/browser/api/atom_api_session.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/browser/atom_browser_context.h"
|
||||||
#include "shell/common/native_mate_converters/gurl_converter.h"
|
#include "shell/common/native_mate_converters/gurl_converter.h"
|
||||||
#include "shell/common/native_mate_converters/net_converter.h"
|
#include "shell/common/native_mate_converters/net_converter.h"
|
||||||
|
@ -180,9 +182,36 @@ URLRequestNS::URLRequestNS(mate::Arguments* args) : weak_factory_(this) {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* browser_context = session->browser_context();
|
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,
|
||||||
|
content::ContentBrowserClient::URLLoaderFactoryType::kNavigation,
|
||||||
|
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_trusted = true;
|
||||||
|
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_ =
|
url_loader_factory_ =
|
||||||
content::BrowserContext::GetDefaultStoragePartition(browser_context)
|
base::MakeRefCounted<network::WrapperSharedURLLoaderFactory>(
|
||||||
->GetURLLoaderFactoryForBrowserProcess();
|
std::move(network_factory));
|
||||||
|
|
||||||
InitWith(args->isolate(), args->GetThis());
|
InitWith(args->isolate(), args->GetThis());
|
||||||
}
|
}
|
||||||
|
|
|
@ -988,18 +988,11 @@ bool AtomBrowserClient::WillCreateURLLoaderFactory(
|
||||||
mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
|
mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
|
||||||
network::mojom::TrustedURLLoaderHeaderClientPtrInfo* header_client,
|
network::mojom::TrustedURLLoaderHeaderClientPtrInfo* header_client,
|
||||||
bool* bypass_redirect_checks) {
|
bool* bypass_redirect_checks) {
|
||||||
content::WebContents* web_contents =
|
|
||||||
content::WebContents::FromRenderFrameHost(frame_host);
|
|
||||||
// For service workers there might be no WebContents.
|
|
||||||
if (!web_contents)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||||
api::ProtocolNS* protocol = api::ProtocolNS::FromWrappedClass(
|
api::ProtocolNS* protocol =
|
||||||
isolate, web_contents->GetBrowserContext());
|
api::ProtocolNS::FromWrappedClass(isolate, browser_context);
|
||||||
DCHECK(protocol);
|
DCHECK(protocol);
|
||||||
auto web_request = api::WebRequestNS::FromOrCreate(
|
auto web_request = api::WebRequestNS::FromOrCreate(isolate, browser_context);
|
||||||
isolate, web_contents->GetBrowserContext());
|
|
||||||
DCHECK(web_request.get());
|
DCHECK(web_request.get());
|
||||||
|
|
||||||
auto proxied_receiver = std::move(*factory_receiver);
|
auto proxied_receiver = std::move(*factory_receiver);
|
||||||
|
|
|
@ -628,7 +628,7 @@ describe('net module', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe.skip('webRequest', () => {
|
describe('webRequest', () => {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
session.defaultSession.webRequest.onBeforeRequest(null)
|
session.defaultSession.webRequest.onBeforeRequest(null)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue