Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 31 additions & 2 deletions shell/browser/api/atom_api_url_request_ns.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.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 "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 @@ -180,9 +182,36 @@ 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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a follow-up improvement would be to have a getter class for the proxy url loader class similar to content::URLLoaderGetter https://cs.chromium.org/chromium/src/content/browser/url_loader_factory_getter.h , which would allow us to avoid calling the content api here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I plan to also replace the GetURLLoaderFactoryForBrowserProcess call in AtomURLLoaderFactory as it has the same problem with net module here, I will separate the code to a getter class as part of refactoring.

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_ =
content::BrowserContext::GetDefaultStoragePartition(browser_context)
->GetURLLoaderFactoryForBrowserProcess();
base::MakeRefCounted<network::WrapperSharedURLLoaderFactory>(
std::move(network_factory));

InitWith(args->isolate(), args->GetThis());
}
Expand Down
13 changes: 3 additions & 10 deletions shell/browser/atom_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -988,18 +988,11 @@ bool AtomBrowserClient::WillCreateURLLoaderFactory(
mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver,
network::mojom::TrustedURLLoaderHeaderClientPtrInfo* header_client,
bool* bypass_redirect_checks) {
content::WebContents* web_contents =
content::WebContents::FromRenderFrameHost(frame_host);
// For service workers there might be no WebContents.
if (!web_contents)
deepak1556 marked this conversation as resolved.
Show resolved Hide resolved
return false;

v8::Isolate* isolate = v8::Isolate::GetCurrent();
api::ProtocolNS* protocol = api::ProtocolNS::FromWrappedClass(
isolate, web_contents->GetBrowserContext());
api::ProtocolNS* protocol =
api::ProtocolNS::FromWrappedClass(isolate, browser_context);
DCHECK(protocol);
auto web_request = api::WebRequestNS::FromOrCreate(
isolate, web_contents->GetBrowserContext());
auto web_request = api::WebRequestNS::FromOrCreate(isolate, browser_context);
DCHECK(web_request.get());

auto proxied_receiver = std::move(*factory_receiver);
Expand Down
2 changes: 1 addition & 1 deletion spec-main/api-net-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ describe('net module', () => {
})
})

describe.skip('webRequest', () => {
describe('webRequest', () => {
afterEach(() => {
session.defaultSession.webRequest.onBeforeRequest(null)
})
Expand Down