Commit e53b0174 authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

[Fuchsia] Add basic content::BrowserContext implementation for WebRunner

Added simple BrowserContext, NetLog and UrlRequestContextGetter
implementations for WebRunner on Fuchsia.

Bug: 822474
Change-Id: I15e894b9909253146ab6bb2450ec3ffea2c8ea10
Reviewed-on: https://chromium-review.googlesource.com/988933
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547499}
parent 4b2b22de
......@@ -18,6 +18,7 @@ executable("webrunner") {
"//content/public/child",
"//content/public/common",
"//content/public/renderer",
"//services/network/public/cpp",
"//ui/display",
]
......@@ -32,14 +33,20 @@ executable("webrunner") {
"app/webrunner_main.cc",
"app/webrunner_main_delegate.cc",
"app/webrunner_main_delegate.h",
"browser/webrunner_browser_context.cc",
"browser/webrunner_browser_context.h",
"browser/webrunner_browser_main.cc",
"browser/webrunner_browser_main.h",
"browser/webrunner_browser_main_parts.cc",
"browser/webrunner_browser_main_parts.h",
"browser/webrunner_content_browser_client.cc",
"browser/webrunner_content_browser_client.h",
"browser/webrunner_net_log.cc",
"browser/webrunner_net_log.h",
"browser/webrunner_screen.cc",
"browser/webrunner_screen.h",
"browser/webrunner_url_request_context_getter.cc",
"browser/webrunner_url_request_context_getter.h",
"common/webrunner_content_client.cc",
"common/webrunner_content_client.h",
]
......
include_rules = [
"+content/public/common",
"+net",
"+services/network/public",
]
\ No newline at end of file
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "webrunner/browser/webrunner_browser_context.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_context.h"
#include "net/url_request/url_request_context.h"
#include "services/network/public/cpp/network_switches.h"
#include "webrunner/browser/webrunner_net_log.h"
#include "webrunner/browser/webrunner_url_request_context_getter.h"
namespace webrunner {
class WebRunnerBrowserContext::ResourceContext
: public content::ResourceContext {
public:
ResourceContext() = default;
~ResourceContext() override = default;
// ResourceContext implementation.
net::HostResolver* GetHostResolver() override {
DCHECK(getter_);
return getter_->GetURLRequestContext()->host_resolver();
}
net::URLRequestContext* GetRequestContext() override {
DCHECK(getter_);
return getter_->GetURLRequestContext();
}
void set_url_request_context_getter(
scoped_refptr<WebRunnerURLRequestContextGetter> getter) {
getter_ = std::move(getter);
}
private:
scoped_refptr<WebRunnerURLRequestContextGetter> getter_;
DISALLOW_COPY_AND_ASSIGN(ResourceContext);
};
std::unique_ptr<WebRunnerNetLog> CreateNetLog() {
std::unique_ptr<WebRunnerNetLog> result;
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(network::switches::kLogNetLog)) {
base::FilePath log_path =
command_line->GetSwitchValuePath(network::switches::kLogNetLog);
result = std::make_unique<WebRunnerNetLog>(log_path);
}
return result;
}
WebRunnerBrowserContext::WebRunnerBrowserContext()
: net_log_(CreateNetLog()), resource_context_(new ResourceContext()) {
// TODO(sergeyu): Pass a valid path.
BrowserContext::Initialize(this, base::FilePath());
}
WebRunnerBrowserContext::~WebRunnerBrowserContext() {
if (resource_context_) {
content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE,
std::move(resource_context_));
}
}
std::unique_ptr<content::ZoomLevelDelegate>
WebRunnerBrowserContext::CreateZoomLevelDelegate(
const base::FilePath& partition_path) {
return nullptr;
}
base::FilePath WebRunnerBrowserContext::GetPath() const {
NOTIMPLEMENTED();
return base::FilePath();
}
bool WebRunnerBrowserContext::IsOffTheRecord() const {
return false;
}
content::ResourceContext* WebRunnerBrowserContext::GetResourceContext() {
return resource_context_.get();
}
content::DownloadManagerDelegate*
WebRunnerBrowserContext::GetDownloadManagerDelegate() {
NOTIMPLEMENTED();
return nullptr;
}
content::BrowserPluginGuestManager* WebRunnerBrowserContext::GetGuestManager() {
return nullptr;
}
storage::SpecialStoragePolicy*
WebRunnerBrowserContext::GetSpecialStoragePolicy() {
return nullptr;
}
content::PushMessagingService*
WebRunnerBrowserContext::GetPushMessagingService() {
return nullptr;
}
content::SSLHostStateDelegate*
WebRunnerBrowserContext::GetSSLHostStateDelegate() {
return nullptr;
}
content::PermissionManager* WebRunnerBrowserContext::GetPermissionManager() {
return nullptr;
}
content::BackgroundFetchDelegate*
WebRunnerBrowserContext::GetBackgroundFetchDelegate() {
return nullptr;
}
content::BackgroundSyncController*
WebRunnerBrowserContext::GetBackgroundSyncController() {
return nullptr;
}
content::BrowsingDataRemoverDelegate*
WebRunnerBrowserContext::GetBrowsingDataRemoverDelegate() {
return nullptr;
}
net::URLRequestContextGetter* WebRunnerBrowserContext::CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) {
DCHECK(!url_request_getter_);
url_request_getter_ = new WebRunnerURLRequestContextGetter(
content::BrowserThread::GetTaskRunnerForThread(
content::BrowserThread::IO),
net_log_.get(), std::move(*protocol_handlers),
std::move(request_interceptors));
resource_context_->set_url_request_context_getter(url_request_getter_);
return url_request_getter_.get();
}
net::URLRequestContextGetter*
WebRunnerBrowserContext::CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) {
return nullptr;
}
net::URLRequestContextGetter*
WebRunnerBrowserContext::CreateMediaRequestContext() {
DCHECK(url_request_getter_.get());
return url_request_getter_.get();
}
net::URLRequestContextGetter*
WebRunnerBrowserContext::CreateMediaRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory) {
return nullptr;
}
} // namespace webrunner
\ No newline at end of file
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WEBRUNNER_BROWSER_WEBRUNNER_BROWSER_CONTEXT_H_
#define WEBRUNNER_BROWSER_WEBRUNNER_BROWSER_CONTEXT_H_
#include "base/macros.h"
#include "content/public/browser/browser_context.h"
namespace webrunner {
class WebRunnerNetLog;
class WebRunnerURLRequestContextGetter;
class WebRunnerBrowserContext : public content::BrowserContext {
public:
WebRunnerBrowserContext();
~WebRunnerBrowserContext() override;
// BrowserContext implementation.
std::unique_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate(
const base::FilePath& partition_path) override;
base::FilePath GetPath() const override;
bool IsOffTheRecord() const override;
content::ResourceContext* GetResourceContext() override;
content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;
content::BrowserPluginGuestManager* GetGuestManager() override;
storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override;
content::PushMessagingService* GetPushMessagingService() override;
content::SSLHostStateDelegate* GetSSLHostStateDelegate() override;
content::PermissionManager* GetPermissionManager() override;
content::BackgroundFetchDelegate* GetBackgroundFetchDelegate() override;
content::BackgroundSyncController* GetBackgroundSyncController() override;
content::BrowsingDataRemoverDelegate* GetBrowsingDataRemoverDelegate()
override;
net::URLRequestContextGetter* CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) override;
net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory,
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) override;
net::URLRequestContextGetter* CreateMediaRequestContext() override;
net::URLRequestContextGetter* CreateMediaRequestContextForStoragePartition(
const base::FilePath& partition_path,
bool in_memory) override;
private:
// Contains URLRequestContextGetter required for resource loading.
class ResourceContext;
std::unique_ptr<WebRunnerNetLog> net_log_;
scoped_refptr<WebRunnerURLRequestContextGetter> url_request_getter_;
std::unique_ptr<ResourceContext> resource_context_;
DISALLOW_COPY_AND_ASSIGN(WebRunnerBrowserContext);
};
} // namespace webrunner
#endif // WEBRUNNER_BROWSER_WEBRUNNER_BROWSER_CONTEXT_H_
......@@ -4,6 +4,7 @@
#include "webrunner/browser/webrunner_browser_main_parts.h"
#include "webrunner/browser/webrunner_browser_context.h"
#include "webrunner/browser/webrunner_screen.h"
namespace webrunner {
......@@ -15,6 +16,9 @@ void WebRunnerBrowserMainParts::PreMainMessageLoopRun() {
DCHECK(!screen_);
screen_ = std::make_unique<WebRunnerScreen>();
display::Screen::SetScreenInstance(screen_.get());
DCHECK(!browser_context_);
browser_context_ = std::make_unique<WebRunnerBrowserContext>();
}
} // namespace webrunner
......@@ -12,6 +12,7 @@
namespace webrunner {
class WebRunnerBrowserContext;
class WebRunnerScreen;
class WebRunnerBrowserMainParts : public content::BrowserMainParts {
......@@ -24,6 +25,7 @@ class WebRunnerBrowserMainParts : public content::BrowserMainParts {
private:
std::unique_ptr<WebRunnerScreen> screen_;
std::unique_ptr<WebRunnerBrowserContext> browser_context_;
DISALLOW_COPY_AND_ASSIGN(WebRunnerBrowserMainParts);
};
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "webrunner/browser/webrunner_net_log.h"
#include <string>
#include <utility>
#include "base/bind.h"
#include "base/callback.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/values.h"
#include "net/log/file_net_log_observer.h"
#include "net/log/net_log_util.h"
namespace webrunner {
namespace {
std::unique_ptr<base::DictionaryValue> GetWebRunnerConstants() {
std::unique_ptr<base::DictionaryValue> constants_dict =
net::GetNetConstants();
base::DictionaryValue dict;
dict.SetKey("name", base::Value("webrunner"));
dict.SetKey(
"command_line",
base::Value(
base::CommandLine::ForCurrentProcess()->GetCommandLineString()));
constants_dict->SetKey("clientInfo", std::move(dict));
return constants_dict;
}
} // namespace
WebRunnerNetLog::WebRunnerNetLog(const base::FilePath& log_path) {
if (!log_path.empty()) {
net::NetLogCaptureMode capture_mode = net::NetLogCaptureMode::Default();
file_net_log_observer_ = net::FileNetLogObserver::CreateUnbounded(
log_path, GetWebRunnerConstants());
file_net_log_observer_->StartObserving(this, capture_mode);
}
}
WebRunnerNetLog::~WebRunnerNetLog() {
if (file_net_log_observer_)
file_net_log_observer_->StopObserving(nullptr, base::OnceClosure());
}
} // namespace webrunner
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WEBRUNNER_BROWSER_WEBRUNNER_NET_LOG_H_
#define WEBRUNNER_BROWSER_WEBRUNNER_NET_LOG_H_
#include <memory>
#include "base/macros.h"
#include "net/log/net_log.h"
namespace base {
class FilePath;
} // namespace base
namespace net {
class FileNetLogObserver;
} // namespace net
namespace webrunner {
class WebRunnerNetLog : public net::NetLog {
public:
explicit WebRunnerNetLog(const base::FilePath& log_path);
~WebRunnerNetLog() override;
private:
std::unique_ptr<net::FileNetLogObserver> file_net_log_observer_;
DISALLOW_COPY_AND_ASSIGN(WebRunnerNetLog);
};
} // namespace webrunner
#endif // WEBRUNNER_BROWSER_WEBRUNNER_NET_LOG_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "webrunner/browser/webrunner_url_request_context_getter.h"
#include <utility>
#include "base/single_thread_task_runner.h"
#include "net/proxy_resolution/proxy_config_service.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_builder.h"
namespace webrunner {
WebRunnerURLRequestContextGetter::WebRunnerURLRequestContextGetter(
scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
net::NetLog* net_log,
content::ProtocolHandlerMap protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors)
: network_task_runner_(std::move(network_task_runner)),
net_log_(net_log),
protocol_handlers_(std::move(protocol_handlers)),
request_interceptors_(std::move(request_interceptors)) {}
WebRunnerURLRequestContextGetter::~WebRunnerURLRequestContextGetter() = default;
net::URLRequestContext*
WebRunnerURLRequestContextGetter::GetURLRequestContext() {
if (!url_request_context_) {
net::URLRequestContextBuilder builder;
builder.set_net_log(net_log_);
for (auto& protocol_handler : protocol_handlers_) {
builder.SetProtocolHandler(
protocol_handler.first,
base::WrapUnique(protocol_handler.second.release()));
}
protocol_handlers_.clear();
builder.SetInterceptors(std::move(request_interceptors_));
// TODO(sergeyu): Configure CookieStore, cache and proxy resolver.
url_request_context_ = builder.Build();
}
return url_request_context_.get();
}
scoped_refptr<base::SingleThreadTaskRunner>
WebRunnerURLRequestContextGetter::GetNetworkTaskRunner() const {
return network_task_runner_;
}
} // namespace webrunner
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WEBRUNNER_BROWSER_WEBRUNNER_URL_REQUEST_CONTEXT_GETTER_H_
#define WEBRUNNER_BROWSER_WEBRUNNER_URL_REQUEST_CONTEXT_GETTER_H_
#include <memory>
#include "base/macros.h"
#include "content/public/browser/browser_context.h"
#include "net/url_request/url_request_context_getter.h"
namespace base {
class SingleThreadTaskRunner;
} // namespace base
namespace net {
class NetLog;
class ProxyConfigService;
} // namespace net
namespace webrunner {
class WebRunnerURLRequestContextGetter : public net::URLRequestContextGetter {
public:
WebRunnerURLRequestContextGetter(
scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
net::NetLog* net_log,
content::ProtocolHandlerMap protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors);
// net::URLRequestContextGetter overrides.
net::URLRequestContext* GetURLRequestContext() override;
scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner()
const override;
protected:
~WebRunnerURLRequestContextGetter() override;
private:
scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
net::NetLog* net_log_;
std::unique_ptr<net::ProxyConfigService> proxy_config_service_;
std::unique_ptr<net::URLRequestContext> url_request_context_;
content::ProtocolHandlerMap protocol_handlers_;
content::URLRequestInterceptorScopedVector request_interceptors_;
DISALLOW_COPY_AND_ASSIGN(WebRunnerURLRequestContextGetter);
};
} // namespace webrunner
#endif // WEBRUNNER_BROWSER_WEBRUNNER_URL_REQUEST_CONTEXT_GETTER_H_
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