Commit 070ceff1 authored by Nate Fischer's avatar Nate Fischer Committed by Commit Bot

AW: create networkcontext for net service

This creates a mostly default NetworkContext. This duplicates the work
provided by the content-layer implementation, but will later be extended
to provide more functionality.

The main addition beyond content layer is this configures WebView's
HTTP cache.

R=changwan@chromium.org, mmenke@chromium.org

Cq-Include-Trybots: master.tryserver.chromium.android:android_mojo
Bug: 887538
Test: No major issues with NetworkService feature enabled.
Change-Id: I9cc1823f144d9ffc96fca917b0763b74e36a53d7
Reviewed-on: https://chromium-review.googlesource.com/c/1314133
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605508}
parent dc7a451a
......@@ -27,6 +27,7 @@ include_rules = [
"+media/media_buildflags.h",
"+mojo/public/cpp/bindings",
"+net",
"+services/network/network_service.h",
"+services/network/public/cpp",
"+services/preferences/tracked",
"+services/service_manager/public",
......
......@@ -140,6 +140,9 @@ base::FilePath AwBrowserContext::GetCacheDir() {
void AwBrowserContext::PreMainMessageLoopRun(net::NetLog* net_log) {
FilePath cache_path = GetCacheDir();
// TODO(ntfschr): set this to nullptr when the NetworkService is disabled,
// once we remove a dependency on url_request_context_getter_
// (http://crbug.com/887538).
url_request_context_getter_ = new AwURLRequestContextGetter(
cache_path, context_storage_path_.Append(kChannelIDFilename),
CreateProxyConfigService(), user_pref_service_.get(), net_log);
......
......@@ -26,6 +26,7 @@
#include "android_webview/browser/net/aw_url_request_context_getter.h"
#include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_delegate.h"
#include "android_webview/browser/tracing/aw_tracing_delegate.h"
#include "android_webview/common/aw_content_client.h"
#include "android_webview/common/aw_descriptors.h"
#include "android_webview/common/aw_switches.h"
#include "android_webview/common/crash_reporter/aw_crash_reporter_client.h"
......@@ -64,6 +65,7 @@
#include "content/public/browser/client_certificate_delegate.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/navigation_throttle.h"
#include "content/public/browser/network_service_instance.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
......@@ -78,6 +80,7 @@
#include "net/log/net_log.h"
#include "net/ssl/ssl_cert_request_info.h"
#include "net/ssl/ssl_info.h"
#include "services/network/network_service.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/service_manager/public/cpp/binder_registry.h"
......@@ -230,6 +233,34 @@ AwContentBrowserClient::AwContentBrowserClient(
AwContentBrowserClient::~AwContentBrowserClient() {}
network::mojom::NetworkContextPtr AwContentBrowserClient::CreateNetworkContext(
content::BrowserContext* context,
bool in_memory,
const base::FilePath& relative_partition_path) {
DCHECK(context);
if (!base::FeatureList::IsEnabled(network::features::kNetworkService))
return nullptr;
network::mojom::NetworkContextPtr network_context;
network::mojom::NetworkContextParamsPtr context_params =
network::mojom::NetworkContextParams::New();
context_params->user_agent = GetUserAgent();
// TODO(ntfschr): set this value to a proper value based on the user's
// preferred locales (http://crbug.com/898555). For now, set this to
// "en-US,en" instead of "en-us,en", since Android guarantees region codes
// will be uppercase.
context_params->accept_language = "en-US,en";
context_params->enable_data_url_support = true;
context_params->http_cache_enabled = true;
context_params->http_cache_max_size = 20 * 1024 * 1024; // 20M
context_params->http_cache_path = AwBrowserContext::GetCacheDir();
content::GetNetworkService()->CreateNetworkContext(
MakeRequest(&network_context), std::move(context_params));
return network_context;
}
AwBrowserContext* AwContentBrowserClient::InitBrowserContext() {
base::FilePath user_data_dir;
if (!base::PathService::Get(base::DIR_ANDROID_APP_DATA, &user_data_dir)) {
......
......@@ -51,6 +51,11 @@ class AwContentBrowserClient : public content::ContentBrowserClient {
// moment during startup. AwContentBrowserClient owns the result.
AwBrowserContext* InitBrowserContext();
network::mojom::NetworkContextPtr CreateNetworkContext(
content::BrowserContext* context,
bool in_memory,
const base::FilePath& relative_partition_path) override;
content::BrowserMainParts* CreateBrowserMainParts(
const content::MainFunctionParams& parameters) override;
content::WebContentsViewDelegate* GetWebContentsViewDelegate(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment