Commit 4ff116fd authored by Nate Fischer's avatar Nate Fischer Committed by Commit Bot

AW: configure cookies for Network Service

This configures cookie settings in the NetworkContext, based on
non-service code path (defined in WebView's CookieManager). This
refactors the cookie-path logic to a shared location in
AwBrowserContext.

Specifically, this configures the following:

 * save and restore session cookies
 * cookies should persist to disk

This also does some minor refactoring for the HTTP cache, for
consistency.

Bug: 933456, 933457, 902641
Test: None
Cq-Include-Trybots: master.tryserver.chromium.android:android_mojo
Change-Id: Ib53d4cbab8ccdf2f916a256f6d549bea644b6611
Reviewed-on: https://chromium-review.googlesource.com/c/1385492
Auto-Submit: Nate Fischer <ntfschr@chromium.org>
Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635625}
parent 2919f408
...@@ -130,12 +130,24 @@ AwBrowserContext* AwBrowserContext::FromWebContents( ...@@ -130,12 +130,24 @@ AwBrowserContext* AwBrowserContext::FromWebContents(
// static // static
base::FilePath AwBrowserContext::GetCacheDir() { base::FilePath AwBrowserContext::GetCacheDir() {
FilePath cache_path; FilePath cache_path;
base::PathService::Get(base::DIR_CACHE, &cache_path); if (!base::PathService::Get(base::DIR_CACHE, &cache_path)) {
NOTREACHED() << "Failed to get app cache directory for Android WebView";
}
cache_path = cache_path =
cache_path.Append(FILE_PATH_LITERAL("org.chromium.android_webview")); cache_path.Append(FILE_PATH_LITERAL("org.chromium.android_webview"));
return cache_path; return cache_path;
} }
// static
base::FilePath AwBrowserContext::GetCookieStorePath() {
FilePath cookie_store_path;
if (!base::PathService::Get(base::DIR_ANDROID_APP_DATA, &cookie_store_path)) {
NOTREACHED() << "Failed to get app data directory for Android WebView";
}
cookie_store_path = cookie_store_path.Append(FILE_PATH_LITERAL("Cookies"));
return cookie_store_path;
}
void AwBrowserContext::PreMainMessageLoopRun(net::NetLog* net_log) { void AwBrowserContext::PreMainMessageLoopRun(net::NetLog* net_log) {
FilePath cache_path = GetCacheDir(); FilePath cache_path = GetCacheDir();
......
...@@ -83,7 +83,10 @@ class AwBrowserContext : public content::BrowserContext, ...@@ -83,7 +83,10 @@ class AwBrowserContext : public content::BrowserContext,
static AwBrowserContext* FromWebContents( static AwBrowserContext* FromWebContents(
content::WebContents* web_contents); content::WebContents* web_contents);
// TODO(ntfschr): consider moving these into our PathService in
// common/aw_paths.h (http://crbug.com/934184).
static base::FilePath GetCacheDir(); static base::FilePath GetCacheDir();
static base::FilePath GetCookieStorePath();
// Maps to BrowserMainParts::PreMainMessageLoopRun. // Maps to BrowserMainParts::PreMainMessageLoopRun.
void PreMainMessageLoopRun(net::NetLog* net_log); void PreMainMessageLoopRun(net::NetLog* net_log);
......
...@@ -342,10 +342,17 @@ AwContentBrowserClient::GetNetworkContextParams() { ...@@ -342,10 +342,17 @@ AwContentBrowserClient::GetNetworkContextParams() {
context_params->accept_language = "en-US,en"; context_params->accept_language = "en-US,en";
context_params->enable_data_url_support = true; context_params->enable_data_url_support = true;
// HTTP cache
context_params->http_cache_enabled = true; context_params->http_cache_enabled = true;
context_params->http_cache_max_size = GetHttpCacheSize(); context_params->http_cache_max_size = GetHttpCacheSize();
context_params->http_cache_path = AwBrowserContext::GetCacheDir(); context_params->http_cache_path = AwBrowserContext::GetCacheDir();
// WebView should persist and restore cookies between app sessions (including
// session cookies).
context_params->cookie_path = AwBrowserContext::GetCookieStorePath();
context_params->restore_old_session_cookies = true;
context_params->persist_session_cookies = true;
context_params->initial_ssl_config = network::mojom::SSLConfig::New(); context_params->initial_ssl_config = network::mojom::SSLConfig::New();
// Allow SHA-1 to be used for locally-installed trust anchors, as WebView // Allow SHA-1 to be used for locally-installed trust anchors, as WebView
// should behave like the Android system would. // should behave like the Android system would.
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "android_webview/browser/aw_browser_context.h"
#include "android_webview/browser/aw_cookie_access_policy.h" #include "android_webview/browser/aw_cookie_access_policy.h"
#include "android_webview/browser/net/init_native_callback.h" #include "android_webview/browser/net/init_native_callback.h"
#include "android_webview/browser/net_network_service/aw_cookie_manager_wrapper.h" #include "android_webview/browser/net_network_service/aw_cookie_manager_wrapper.h"
...@@ -18,8 +19,6 @@ ...@@ -18,8 +19,6 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/location.h" #include "base/location.h"
#include "base/logging.h" #include "base/logging.h"
...@@ -47,7 +46,6 @@ ...@@ -47,7 +46,6 @@
#include "services/network/public/mojom/cookie_manager.mojom.h" #include "services/network/public/mojom/cookie_manager.mojom.h"
#include "url/url_constants.h" #include "url/url_constants.h"
using base::FilePath;
using base::WaitableEvent; using base::WaitableEvent;
using base::android::ConvertJavaStringToUTF8; using base::android::ConvertJavaStringToUTF8;
using base::android::ConvertJavaStringToUTF16; using base::android::ConvertJavaStringToUTF16;
...@@ -157,12 +155,6 @@ static base::RepeatingCallback<void(int)> IntCallbackAdapter( ...@@ -157,12 +155,6 @@ static base::RepeatingCallback<void(int)> IntCallbackAdapter(
// Are cookies allowed for file:// URLs by default? // Are cookies allowed for file:// URLs by default?
const bool kDefaultFileSchemeAllowed = false; const bool kDefaultFileSchemeAllowed = false;
void GetUserDataDir(FilePath* user_data_dir) {
if (!base::PathService::Get(base::DIR_ANDROID_APP_DATA, user_data_dir)) {
NOTREACHED() << "Failed to get app data directory for Android WebView";
}
}
net::CookieStore::SetCookiesCallback StatusToBool( net::CookieStore::SetCookiesCallback StatusToBool(
base::OnceCallback<void(bool)> callback) { base::OnceCallback<void(bool)> callback) {
return base::BindOnce( return base::BindOnce(
...@@ -258,13 +250,10 @@ net::CookieStore* CookieManager::GetCookieStore() { ...@@ -258,13 +250,10 @@ net::CookieStore* CookieManager::GetCookieStore() {
DCHECK(cookie_store_task_runner_->RunsTasksInCurrentSequence()); DCHECK(cookie_store_task_runner_->RunsTasksInCurrentSequence());
if (!cookie_store_) { if (!cookie_store_) {
FilePath user_data_dir; content::CookieStoreConfig cookie_config(
GetUserDataDir(&user_data_dir); AwBrowserContext::GetCookieStorePath(),
FilePath cookie_store_path = true /* restore_old_session_cookies */,
user_data_dir.Append(FILE_PATH_LITERAL("Cookies")); true /* persist_session_cookies */, nullptr /* storage_policy */);
content::CookieStoreConfig cookie_config(cookie_store_path, true, true,
nullptr);
cookie_config.client_task_runner = cookie_store_task_runner_; cookie_config.client_task_runner = cookie_store_task_runner_;
cookie_config.background_task_runner = cookie_config.background_task_runner =
cookie_store_backend_thread_.task_runner(); cookie_store_backend_thread_.task_runner();
......
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