Commit 80b08e93 authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

[content-service] Introduce NavigableContentsView

Adds a new NavigableContentsView type to the Content Service's
client library. This is meant to be a platform-agnostic encapsulation
of all business relevant to the display of renderered web contents (i.e.
a navigated NavigableContents object) within a client application's UI.

This also enables NavigableContentsView embedding on all desktop Aura
platforms in addition to Chrome OS, which is the only supported platform
before this CL.

For non-Mash non-Chrome OS builds, NavigableContentsView usage is
restricted to the browser process, where Content Service instances
are hosted. Support for remote NavigableContentsViews will expand as
support for the UI service expands.

For testing, this enables --launch-in-process-simple-browser in all
desktop Aura developer builds, running an in-process Simple Browser
application which consumes NavigableContentsView to display web contents
via the Content Service. The out-of-process version
(--launch-simple-browser) still works on Chrome OS with Mash enabled.

Follow-up patches will enable local NavigableContentsView usage on
non-Aura platforms (e.g. Android, Mac, etc) so that we can start
converting WebContents uses to NavigableContents uses.

Bug: 855092
Test: Run chrome --launch-in-process-simple-browser (with DCHECKS enabled) on Chrome OS, Linux or Windows and watch it go!
Change-Id: Id091017a1656f078ea87fa3a9d6a6f4049fb4f13
Reviewed-on: https://chromium-review.googlesource.com/1171668Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Ken Rockot <rockot@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583166}
parent 50f490e3
...@@ -428,7 +428,8 @@ service_manifest("chrome_content_packaged_services_manifest_overlay") { ...@@ -428,7 +428,8 @@ service_manifest("chrome_content_packaged_services_manifest_overlay") {
if (enable_extensions || is_android) { if (enable_extensions || is_android) {
packaged_services += [ "//chrome/services/media_gallery_util:manifest" ] packaged_services += [ "//chrome/services/media_gallery_util:manifest" ]
} }
if (enable_simple_browser_service) { if (enable_simple_browser_service_in_process ||
enable_simple_browser_service_out_of_process) {
packaged_services += [ "//services/content/simple_browser:manifest" ] packaged_services += [ "//services/content/simple_browser:manifest" ]
} }
if (is_win) { if (is_win) {
......
...@@ -4217,10 +4217,17 @@ jumbo_split_static_library("browser") { ...@@ -4217,10 +4217,17 @@ jumbo_split_static_library("browser") {
} }
} }
if (enable_simple_browser_service) { if (enable_simple_browser_service_out_of_process) {
deps += [ "//services/content/simple_browser/public/mojom" ] deps += [ "//services/content/simple_browser/public/mojom" ]
} }
if (enable_simple_browser_service_in_process) {
deps += [
"//services/content/simple_browser",
"//services/content/simple_browser/public/mojom",
]
}
if (enable_supervised_users) { if (enable_supervised_users) {
sources += [ sources += [
"content_settings/content_settings_supervised_provider.cc", "content_settings/content_settings_supervised_provider.cc",
......
...@@ -57,7 +57,7 @@ include_rules = [ ...@@ -57,7 +57,7 @@ include_rules = [
"+rlz", "+rlz",
"+sandbox/win/src", # The path doesn't say it, but this is the Windows sandbox. "+sandbox/win/src", # The path doesn't say it, but this is the Windows sandbox.
"+services/audio/public", "+services/audio/public",
"+services/content/simple_browser/public", "+services/content/simple_browser",
"+services/data_decoder/public", "+services/data_decoder/public",
"+services/device/public", "+services/device/public",
"+services/identity/public", "+services/identity/public",
......
...@@ -308,7 +308,8 @@ ...@@ -308,7 +308,8 @@
#include "ui/aura/env.h" #include "ui/aura/env.h"
#endif #endif
#if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE) #if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE_IN_PROCESS) || \
BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE_OUT_OF_PROCESS)
#include "services/content/simple_browser/public/mojom/constants.mojom.h" #include "services/content/simple_browser/public/mojom/constants.mojom.h"
#endif #endif
...@@ -2020,13 +2021,15 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { ...@@ -2020,13 +2021,15 @@ int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
base::TimeTicks::Now() - start_time_step3); base::TimeTicks::Now() - start_time_step3);
#endif // !defined(OS_ANDROID) #endif // !defined(OS_ANDROID)
#if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE) #if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE_OUT_OF_PROCESS) || \
const char kLaunchSimpleBrowserSwitch[] = "launch-simple-browser"; BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE_IN_PROCESS)
if (parsed_command_line().HasSwitch(kLaunchSimpleBrowserSwitch)) { if (parsed_command_line().HasSwitch(switches::kLaunchSimpleBrowserSwitch) ||
parsed_command_line().HasSwitch(
switches::kLaunchInProcessSimpleBrowserSwitch)) {
content::BrowserContext::GetConnectorFor(profile_)->StartService( content::BrowserContext::GetConnectorFor(profile_)->StartService(
service_manager::Identity(simple_browser::mojom::kServiceName)); service_manager::Identity(simple_browser::mojom::kServiceName));
} }
#endif // BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE) #endif
return result_code_; return result_code_;
} }
......
...@@ -511,7 +511,12 @@ ...@@ -511,7 +511,12 @@
#include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h" #include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h"
#endif #endif
#if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE) #if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE_IN_PROCESS)
#include "services/content/simple_browser/public/mojom/constants.mojom.h"
#include "services/content/simple_browser/simple_browser_service.h"
#endif
#if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE_OUT_OF_PROCESS)
#include "services/content/simple_browser/public/mojom/constants.mojom.h" #include "services/content/simple_browser/public/mojom/constants.mojom.h"
#endif #endif
...@@ -3626,6 +3631,21 @@ void ChromeContentBrowserClient::RegisterInProcessServices( ...@@ -3626,6 +3631,21 @@ void ChromeContentBrowserClient::RegisterInProcessServices(
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
ash_service_registry::RegisterInProcessServices(services, connection); ash_service_registry::RegisterInProcessServices(services, connection);
#endif #endif
#if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE_IN_PROCESS)
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kLaunchInProcessSimpleBrowserSwitch)) {
service_manager::EmbeddedServiceInfo info;
info.factory =
base::BindRepeating([]() -> std::unique_ptr<service_manager::Service> {
return std::make_unique<simple_browser::SimpleBrowserService>(
simple_browser::SimpleBrowserService::UIInitializationMode::
kUseEnvironmentUI);
});
info.task_runner = base::SequencedTaskRunnerHandle::Get();
services->emplace(simple_browser::mojom::kServiceName, std::move(info));
}
#endif
} }
void ChromeContentBrowserClient::RegisterOutOfProcessServices( void ChromeContentBrowserClient::RegisterOutOfProcessServices(
...@@ -3706,9 +3726,14 @@ void ChromeContentBrowserClient::RegisterOutOfProcessServices( ...@@ -3706,9 +3726,14 @@ void ChromeContentBrowserClient::RegisterOutOfProcessServices(
ash_service_registry::RegisterOutOfProcessServices(services); ash_service_registry::RegisterOutOfProcessServices(services);
#endif #endif
#if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE) #if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE_OUT_OF_PROCESS)
(*services)[simple_browser::mojom::kServiceName] = base::BindRepeating( if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[]() -> base::string16 { return base::ASCIIToUTF16("Simple Browser"); }); switches::kLaunchSimpleBrowserSwitch)) {
(*services)[simple_browser::mojom::kServiceName] =
base::BindRepeating([]() -> base::string16 {
return base::ASCIIToUTF16("Simple Browser");
});
}
#endif #endif
} }
......
...@@ -45,7 +45,8 @@ buildflag_header("buildflags") { ...@@ -45,7 +45,8 @@ buildflag_header("buildflags") {
"ENABLE_NATIVE_NOTIFICATIONS=$enable_native_notifications", "ENABLE_NATIVE_NOTIFICATIONS=$enable_native_notifications",
"ENABLE_SERVICE_DISCOVERY=$enable_service_discovery", "ENABLE_SERVICE_DISCOVERY=$enable_service_discovery",
"ENABLE_SESSION_SERVICE=$enable_session_service", "ENABLE_SESSION_SERVICE=$enable_session_service",
"ENABLE_SIMPLE_BROWSER_SERVICE=$enable_simple_browser_service", "ENABLE_SIMPLE_BROWSER_SERVICE_IN_PROCESS=$enable_simple_browser_service_in_process",
"ENABLE_SIMPLE_BROWSER_SERVICE_OUT_OF_PROCESS=$enable_simple_browser_service_out_of_process",
"ENABLE_SUPERVISED_USERS=$enable_supervised_users", "ENABLE_SUPERVISED_USERS=$enable_supervised_users",
"ENABLE_WAYLAND_SERVER=$enable_wayland_server", "ENABLE_WAYLAND_SERVER=$enable_wayland_server",
"PGO_BUILD=$pgo_build", "PGO_BUILD=$pgo_build",
......
...@@ -420,6 +420,17 @@ const char kKioskMode[] = "kiosk"; ...@@ -420,6 +420,17 @@ const char kKioskMode[] = "kiosk";
// Enable automatically pressing the print button in print preview. // Enable automatically pressing the print button in print preview.
const char kKioskModePrinting[] = "kiosk-printing"; const char kKioskModePrinting[] = "kiosk-printing";
// Launches an in-process instance of the simple_browser service on startup if
// this Chrome build supports it. See |enable_simple_browser_service_in_process|
// in chrome/common/features.gni.
const char kLaunchInProcessSimpleBrowserSwitch[] =
"launch-in-process-simple-browser";
// Launches a sandboxed out-of-process instance of the simple_browser service on
// startup if this Chrome build supports it. See
// |enable_simple_browser_service_out_of_process| in chrome/common/features.gni.
const char kLaunchSimpleBrowserSwitch[] = "launch-simple-browser";
// Loads the Media Router component extension on startup. // Loads the Media Router component extension on startup.
const char kLoadMediaRouterComponentExtension[] = const char kLoadMediaRouterComponentExtension[] =
"load-media-router-component-extension"; "load-media-router-component-extension";
......
...@@ -130,6 +130,8 @@ extern const char kInstantProcess[]; ...@@ -130,6 +130,8 @@ extern const char kInstantProcess[];
extern const char kKeepAliveForTest[]; extern const char kKeepAliveForTest[];
extern const char kKioskMode[]; extern const char kKioskMode[];
extern const char kKioskModePrinting[]; extern const char kKioskModePrinting[];
extern const char kLaunchInProcessSimpleBrowserSwitch[];
extern const char kLaunchSimpleBrowserSwitch[];
extern const char kLoadMediaRouterComponentExtension[]; extern const char kLoadMediaRouterComponentExtension[];
extern const char kMakeDefaultBrowser[]; extern const char kMakeDefaultBrowser[];
extern const char kMediaCacheSize[]; extern const char kMediaCacheSize[];
......
...@@ -53,7 +53,10 @@ declare_args() { ...@@ -53,7 +53,10 @@ declare_args() {
# Enables embedding of the simple_browser service, a lightweight browser # Enables embedding of the simple_browser service, a lightweight browser
# application which consumes the Content Service. Useful primarily for # application which consumes the Content Service. Useful primarily for
# developer testing. # developer testing.
enable_simple_browser_service = is_chromeos && (is_debug || dcheck_always_on) enable_simple_browser_service_in_process =
use_aura && (is_debug || dcheck_always_on)
enable_simple_browser_service_out_of_process =
is_chromeos && (is_debug || dcheck_always_on)
enable_supervised_users = !is_chromecast enable_supervised_users = !is_chromecast
......
...@@ -213,7 +213,7 @@ static_library("utility") { ...@@ -213,7 +213,7 @@ static_library("utility") {
] ]
} }
if (enable_simple_browser_service) { if (enable_simple_browser_service_out_of_process) {
deps += [ deps += [
"//services/content/simple_browser", "//services/content/simple_browser",
"//services/content/simple_browser/public/mojom", "//services/content/simple_browser/public/mojom",
......
...@@ -96,9 +96,9 @@ ...@@ -96,9 +96,9 @@
#include "chrome/services/file_util/public/mojom/constants.mojom.h" // nogncheck #include "chrome/services/file_util/public/mojom/constants.mojom.h" // nogncheck
#endif #endif
#if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE) #if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE_OUT_OF_PROCESS)
#include "services/content/simple_browser/public/mojom/constants.mojom.h" #include "services/content/simple_browser/public/mojom/constants.mojom.h" // nogncheck
#include "services/content/simple_browser/simple_browser_service.h" #include "services/content/simple_browser/simple_browser_service.h" // nogncheck
#endif #endif
namespace { namespace {
...@@ -296,12 +296,14 @@ void ChromeContentUtilityClient::RegisterServices( ...@@ -296,12 +296,14 @@ void ChromeContentUtilityClient::RegisterServices(
mash_service_factory_->RegisterOutOfProcessServices(services); mash_service_factory_->RegisterOutOfProcessServices(services);
#endif #endif
#if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE) #if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE_OUT_OF_PROCESS)
{ {
service_manager::EmbeddedServiceInfo service_info; service_manager::EmbeddedServiceInfo service_info;
service_info.factory = service_info.factory =
base::BindRepeating([]() -> std::unique_ptr<service_manager::Service> { base::BindRepeating([]() -> std::unique_ptr<service_manager::Service> {
return std::make_unique<simple_browser::SimpleBrowserService>(); return std::make_unique<simple_browser::SimpleBrowserService>(
simple_browser::SimpleBrowserService::UIInitializationMode::
kInitializeUI);
}); });
services->emplace(simple_browser::mojom::kServiceName, service_info); services->emplace(simple_browser::mojom::kServiceName, service_info);
} }
......
...@@ -125,6 +125,7 @@ jumbo_source_set("browser") { ...@@ -125,6 +125,7 @@ jumbo_source_set("browser") {
"//services/catalog/public/cpp", "//services/catalog/public/cpp",
"//services/catalog/public/mojom:constants", "//services/catalog/public/mojom:constants",
"//services/content:impl", "//services/content:impl",
"//services/content/public/cpp",
"//services/content/public/mojom", "//services/content/public/mojom",
"//services/data_decoder/public/cpp", "//services/data_decoder/public/cpp",
"//services/data_decoder/public/mojom", "//services/data_decoder/public/mojom",
......
...@@ -129,6 +129,7 @@ ...@@ -129,6 +129,7 @@
#include "ppapi/buildflags/buildflags.h" #include "ppapi/buildflags/buildflags.h"
#include "services/audio/public/cpp/audio_system_factory.h" #include "services/audio/public/cpp/audio_system_factory.h"
#include "services/audio/public/mojom/constants.mojom.h" #include "services/audio/public/mojom/constants.mojom.h"
#include "services/content/public/cpp/navigable_contents_view.h"
#include "services/network/transitional_url_loader_factory_owner.h" #include "services/network/transitional_url_loader_factory_owner.h"
#include "services/resource_coordinator/public/cpp/memory_instrumentation/client_process_impl.h" #include "services/resource_coordinator/public/cpp/memory_instrumentation/client_process_impl.h"
#include "services/resource_coordinator/public/mojom/memory_instrumentation/memory_instrumentation.mojom.h" #include "services/resource_coordinator/public/mojom/memory_instrumentation/memory_instrumentation.mojom.h"
...@@ -1609,6 +1610,10 @@ void BrowserMainLoop::InitializeMojo() { ...@@ -1609,6 +1610,10 @@ void BrowserMainLoop::InitializeMojo() {
GetContentClient()->OnServiceManagerConnected( GetContentClient()->OnServiceManagerConnected(
ServiceManagerConnection::GetForProcess()); ServiceManagerConnection::GetForProcess());
// Ensure that any NavigableContentsViews constructed in the browser process
// know they're running in the same process as the service.
content::NavigableContentsView::SetClientRunningInServiceProcess();
tracing_controller_ = std::make_unique<content::TracingControllerImpl>(); tracing_controller_ = std::make_unique<content::TracingControllerImpl>();
content::BackgroundTracingManagerImpl::GetInstance() content::BackgroundTracingManagerImpl::GetInstance()
->AddMetadataGeneratorFunction(); ->AddMetadataGeneratorFunction();
......
...@@ -38,12 +38,16 @@ source_set("impl") { ...@@ -38,12 +38,16 @@ source_set("impl") {
"//services/content/public/mojom", "//services/content/public/mojom",
] ]
if (enable_aura_content_view_embedding) { if (enable_navigable_contents_view_aura) {
deps += [ deps += [
"//ui/aura", "//ui/aura",
"//ui/base",
"//ui/views", "//ui/views",
"//ui/views/mus/remote_view:remote_view_provider",
] ]
if (enable_remote_navigable_contents_view) {
deps += [ "//ui/views/mus/remote_view:remote_view_provider" ]
}
} }
} }
......
include_rules = [ include_rules = [
"+ui/aura", "+ui/aura",
"+ui/base",
"+ui/gfx", "+ui/gfx",
"+ui/views", "+ui/views",
] ]
...@@ -7,13 +7,19 @@ ...@@ -7,13 +7,19 @@
#include "base/bind.h" #include "base/bind.h"
#include "services/content/navigable_contents_delegate.h" #include "services/content/navigable_contents_delegate.h"
#include "services/content/public/cpp/buildflags.h" #include "services/content/public/cpp/buildflags.h"
#include "services/content/public/cpp/navigable_contents_view.h"
#include "services/content/service.h" #include "services/content/service.h"
#include "services/content/service_delegate.h" #include "services/content/service_delegate.h"
#if BUILDFLAG(ENABLE_AURA_CONTENT_VIEW_EMBEDDING) #if BUILDFLAG(ENABLE_NAVIGABLE_CONTENTS_VIEW_AURA)
#include "ui/aura/window.h" // nogncheck #include "ui/aura/window.h" // nogncheck
#include "ui/views/controls/native/native_view_host.h" // nogncheck
#if BUILDFLAG(ENABLE_REMOTE_NAVIGABLE_CONTENTS_VIEW)
#include "ui/base/ui_base_features.h" // nogncheck
#include "ui/views/mus/remote_view/remote_view_provider.h" // nogncheck #include "ui/views/mus/remote_view/remote_view_provider.h" // nogncheck
#endif #endif
#endif // BUILDFLAG(ENABLE_NAVIGABLE_CONTENTS_VIEW_AURA)
namespace content { namespace content {
...@@ -30,14 +36,6 @@ NavigableContentsImpl::NavigableContentsImpl( ...@@ -30,14 +36,6 @@ NavigableContentsImpl::NavigableContentsImpl(
native_content_view_(delegate_->GetNativeView()) { native_content_view_(delegate_->GetNativeView()) {
binding_.set_connection_error_handler(base::BindRepeating( binding_.set_connection_error_handler(base::BindRepeating(
&Service::RemoveNavigableContents, base::Unretained(service_), this)); &Service::RemoveNavigableContents, base::Unretained(service_), this));
#if BUILDFLAG(ENABLE_AURA_CONTENT_VIEW_EMBEDDING)
if (native_content_view_) {
DCHECK(!remote_view_provider_);
remote_view_provider_ =
std::make_unique<views::RemoteViewProvider>(native_content_view_);
}
#endif
} }
NavigableContentsImpl::~NavigableContentsImpl() = default; NavigableContentsImpl::~NavigableContentsImpl() = default;
...@@ -50,28 +48,64 @@ void NavigableContentsImpl::Navigate(const GURL& url) { ...@@ -50,28 +48,64 @@ void NavigableContentsImpl::Navigate(const GURL& url) {
delegate_->Navigate(url); delegate_->Navigate(url);
} }
void NavigableContentsImpl::CreateView(CreateViewCallback callback) { void NavigableContentsImpl::CreateView(bool in_service_process,
#if BUILDFLAG(ENABLE_AURA_CONTENT_VIEW_EMBEDDING) CreateViewCallback callback) {
if (remote_view_provider_) { DCHECK(native_content_view_);
#if BUILDFLAG(ENABLE_REMOTE_NAVIGABLE_CONTENTS_VIEW)
if (!in_service_process) {
remote_view_provider_ =
std::make_unique<views::RemoteViewProvider>(native_content_view_);
remote_view_provider_->GetEmbedToken( remote_view_provider_->GetEmbedToken(
base::BindOnce(&NavigableContentsImpl::OnEmbedTokenReceived, base::BindOnce(&NavigableContentsImpl::OnEmbedTokenReceived,
base::Unretained(this), std::move(callback))); base::Unretained(this), std::move(callback)));
return; return;
} }
#else
if (!in_service_process) {
DLOG(ERROR) << "Remote NavigableContentsView clients are not supported on "
<< "this platform.";
return;
}
#endif #endif
DLOG(ERROR) << "View embedding not yet supported on this platform."; // Create and stash a new callback (indexed by token) which the in-process
std::move(callback).Run(base::UnguessableToken::Create()); // client library can use to establish an "embedding" of the contents' view.
auto token = base::UnguessableToken::Create();
NavigableContentsView::RegisterInProcessEmbedCallback(
token, base::BindOnce(&NavigableContentsImpl::EmbedInProcessClientView,
weak_ptr_factory_.GetWeakPtr()));
std::move(callback).Run(token);
} }
#if BUILDFLAG(ENABLE_REMOTE_NAVIGABLE_CONTENTS_VIEW)
void NavigableContentsImpl::OnEmbedTokenReceived( void NavigableContentsImpl::OnEmbedTokenReceived(
CreateViewCallback callback, CreateViewCallback callback,
const base::UnguessableToken& token) { const base::UnguessableToken& token) {
#if BUILDFLAG(ENABLE_AURA_CONTENT_VIEW_EMBEDDING) #if BUILDFLAG(ENABLE_NAVIGABLE_CONTENTS_VIEW_AURA)
if (native_content_view_) if (native_content_view_)
native_content_view_->Show(); native_content_view_->Show();
#endif #endif // BUILDFLAG(ENABLE_NAVIGABLE_CONTENTS_VIEW_AURA)
std::move(callback).Run(token); std::move(callback).Run(token);
} }
#endif // BUILDFLAG(ENABLE_REMOTE_NAVIGABLE_CONTENTS_VIEW)
void NavigableContentsImpl::EmbedInProcessClientView(
NavigableContentsView* view) {
DCHECK(native_content_view_);
#if BUILDFLAG(ENABLE_NAVIGABLE_CONTENTS_VIEW_AURA)
DCHECK(!local_view_host_);
local_view_host_ = std::make_unique<views::NativeViewHost>();
local_view_host_->set_owned_by_client();
view->view()->AddChildView(local_view_host_.get());
view->view()->Layout();
local_view_host_->Attach(native_content_view_);
#else
// TODO(https://crbug.com/855092): Support embedding of other native client
// views without Views + Aura.
NOTREACHED()
<< "NavigableContents views are currently only supported on Aura.";
#endif
}
} // namespace content } // namespace content
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define SERVICES_CONTENT_NAVIGABLE_CONTENTS_IMPL_H_ #define SERVICES_CONTENT_NAVIGABLE_CONTENTS_IMPL_H_
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/unguessable_token.h" #include "base/unguessable_token.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
#include "services/content/public/cpp/buildflags.h" #include "services/content/public/cpp/buildflags.h"
...@@ -14,6 +15,7 @@ ...@@ -14,6 +15,7 @@
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
namespace views { namespace views {
class NativeViewHost;
class RemoteViewProvider; class RemoteViewProvider;
} }
...@@ -21,6 +23,7 @@ namespace content { ...@@ -21,6 +23,7 @@ namespace content {
class Service; class Service;
class NavigableContentsDelegate; class NavigableContentsDelegate;
class NavigableContentsView;
// This is the state which backs an individual NavigableContents owned by some // This is the state which backs an individual NavigableContents owned by some
// client of the Content Service. In terms of the classical Content API, this is // client of the Content Service. In terms of the classical Content API, this is
...@@ -36,10 +39,17 @@ class NavigableContentsImpl : public mojom::NavigableContents { ...@@ -36,10 +39,17 @@ class NavigableContentsImpl : public mojom::NavigableContents {
private: private:
// mojom::NavigableContents: // mojom::NavigableContents:
void Navigate(const GURL& url) override; void Navigate(const GURL& url) override;
void CreateView(CreateViewCallback callback) override; void CreateView(bool in_service_process,
CreateViewCallback callback) override;
#if BUILDFLAG(ENABLE_REMOTE_NAVIGABLE_CONTENTS_VIEW)
void OnEmbedTokenReceived(CreateViewCallback callback, void OnEmbedTokenReceived(CreateViewCallback callback,
const base::UnguessableToken& token); const base::UnguessableToken& token);
#endif
// Used (indirectly) by the client library when run in the same process as the
// service. See the |CreateView()| implementation for details.
void EmbedInProcessClientView(NavigableContentsView* view);
Service* const service_; Service* const service_;
...@@ -48,10 +58,19 @@ class NavigableContentsImpl : public mojom::NavigableContents { ...@@ -48,10 +58,19 @@ class NavigableContentsImpl : public mojom::NavigableContents {
std::unique_ptr<NavigableContentsDelegate> delegate_; std::unique_ptr<NavigableContentsDelegate> delegate_;
gfx::NativeView native_content_view_; gfx::NativeView native_content_view_;
#if BUILDFLAG(ENABLE_AURA_CONTENT_VIEW_EMBEDDING) #if BUILDFLAG(ENABLE_REMOTE_NAVIGABLE_CONTENTS_VIEW)
std::unique_ptr<views::RemoteViewProvider> remote_view_provider_; std::unique_ptr<views::RemoteViewProvider> remote_view_provider_;
#endif #endif
#if BUILDFLAG(ENABLE_NAVIGABLE_CONTENTS_VIEW_AURA)
// Used to support local view embedding in cases where remote embedding is
// not supported and the client controlling this NavigableContents is running
// within the same process as the Content Service.
std::unique_ptr<views::NativeViewHost> local_view_host_;
#endif
base::WeakPtrFactory<NavigableContentsImpl> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(NavigableContentsImpl); DISALLOW_COPY_AND_ASSIGN(NavigableContentsImpl);
}; };
......
...@@ -7,7 +7,8 @@ import("//services/content/public/features.gni") ...@@ -7,7 +7,8 @@ import("//services/content/public/features.gni")
buildflag_header("buildflags") { buildflag_header("buildflags") {
header = "buildflags.h" header = "buildflags.h"
flags = [ flags = [
"ENABLE_AURA_CONTENT_VIEW_EMBEDDING=$enable_aura_content_view_embedding", "ENABLE_NAVIGABLE_CONTENTS_VIEW_AURA=$enable_navigable_contents_view_aura",
"ENABLE_REMOTE_NAVIGABLE_CONTENTS_VIEW=$enable_remote_navigable_contents_view",
] ]
} }
...@@ -16,10 +17,12 @@ component("cpp") { ...@@ -16,10 +17,12 @@ component("cpp") {
public = [ public = [
"navigable_contents.h", "navigable_contents.h",
"navigable_contents_view.h",
] ]
sources = [ sources = [
"navigable_contents.cc", "navigable_contents.cc",
"navigable_contents_view.cc",
] ]
defines = [ "IS_CONTENT_SERVICE_CPP_IMPL" ] defines = [ "IS_CONTENT_SERVICE_CPP_IMPL" ]
...@@ -32,11 +35,17 @@ component("cpp") { ...@@ -32,11 +35,17 @@ component("cpp") {
] ]
deps = [] deps = []
if (enable_aura_content_view_embedding) { if (enable_navigable_contents_view_aura) {
deps += [ deps += [
"//services/ui/public/interfaces", "//ui/base",
"//ui/views", "//ui/views",
"//ui/views/mus/remote_view:remote_view_host",
] ]
if (enable_remote_navigable_contents_view) {
deps += [
"//services/ui/public/interfaces",
"//ui/views/mus/remote_view:remote_view_host",
]
}
} }
} }
...@@ -4,14 +4,8 @@ ...@@ -4,14 +4,8 @@
#include "services/content/public/cpp/navigable_contents.h" #include "services/content/public/cpp/navigable_contents.h"
#include "services/content/public/cpp/buildflags.h" #include "base/memory/ptr_util.h"
#include "services/content/public/cpp/navigable_contents_view.h"
#if BUILDFLAG(ENABLE_AURA_CONTENT_VIEW_EMBEDDING)
#include "services/ui/public/interfaces/window_tree_constants.mojom.h" // nogncheck
#include "ui/views/layout/fill_layout.h" // nogncheck
#include "ui/views/mus/remote_view/remote_view_host.h" // nogncheck
#include "ui/views/view.h" // nogncheck
#endif
namespace content { namespace content {
...@@ -25,24 +19,15 @@ NavigableContents::NavigableContents(mojom::NavigableContentsFactory* factory) ...@@ -25,24 +19,15 @@ NavigableContents::NavigableContents(mojom::NavigableContentsFactory* factory)
NavigableContents::~NavigableContents() = default; NavigableContents::~NavigableContents() = default;
views::View* NavigableContents::GetView() { NavigableContentsView* NavigableContents::GetView() {
#if BUILDFLAG(ENABLE_AURA_CONTENT_VIEW_EMBEDDING)
if (!view_) { if (!view_) {
view_ = std::make_unique<views::View>(); view_ = base::WrapUnique(new NavigableContentsView);
view_->set_owned_by_client(); contents_->CreateView(
view_->SetLayoutManager(std::make_unique<views::FillLayout>()); NavigableContentsView::IsClientRunningInServiceProcess(),
base::BindOnce(&NavigableContents::OnEmbedTokenReceived,
DCHECK(!remote_view_host_); base::Unretained(this)));
remote_view_host_ = new views::RemoteViewHost;
view_->AddChildView(remote_view_host_);
contents_->CreateView(base::BindOnce(
&NavigableContents::OnEmbedTokenReceived, base::Unretained(this)));
} }
return view_.get(); return view_.get();
#else
return nullptr;
#endif
} }
void NavigableContents::Navigate(const GURL& url) { void NavigableContents::Navigate(const GURL& url) {
...@@ -56,11 +41,8 @@ void NavigableContents::DidStopLoading() { ...@@ -56,11 +41,8 @@ void NavigableContents::DidStopLoading() {
void NavigableContents::OnEmbedTokenReceived( void NavigableContents::OnEmbedTokenReceived(
const base::UnguessableToken& token) { const base::UnguessableToken& token) {
#if BUILDFLAG(ENABLE_AURA_CONTENT_VIEW_EMBEDDING) DCHECK(view_);
const uint32_t kEmbedFlags = ui::mojom::kEmbedFlagEmbedderInterceptsEvents | view_->EmbedUsingToken(token);
ui::mojom::kEmbedFlagEmbedderControlsVisibility;
remote_view_host_->EmbedUsingToken(token, kEmbedFlags, base::DoNothing());
#endif // defined(USE_AURA)
} }
} // namespace content } // namespace content
...@@ -11,21 +11,17 @@ ...@@ -11,21 +11,17 @@
#include "base/component_export.h" #include "base/component_export.h"
#include "base/macros.h" #include "base/macros.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
#include "services/content/public/cpp/buildflags.h"
#include "services/content/public/mojom/navigable_contents.mojom.h" #include "services/content/public/mojom/navigable_contents.mojom.h"
#include "services/content/public/mojom/navigable_contents_factory.mojom.h" #include "services/content/public/mojom/navigable_contents_factory.mojom.h"
namespace views {
class RemoteViewHost;
class View;
} // namespace views
namespace content { namespace content {
class NavigableContentsView;
// A NavigableContents controls a single dedicated instance of a top-level, // A NavigableContents controls a single dedicated instance of a top-level,
// navigable content frame hosted by the Content Service. In addition to // navigable content frame hosted by the Content Service. In addition to
// maintaining its own navigation state, a NavigableContents may be used to // maintaining its own navigation state, a NavigableContents may be used to
// acquire an embeddable Views widget to display renderered content within a // acquire an embeddable native UI object to display renderered content within a
// client application's own UI. // client application's own UI.
class COMPONENT_EXPORT(CONTENT_SERVICE_CPP) NavigableContents class COMPONENT_EXPORT(CONTENT_SERVICE_CPP) NavigableContents
: public mojom::NavigableContentsClient { : public mojom::NavigableContentsClient {
...@@ -34,13 +30,14 @@ class COMPONENT_EXPORT(CONTENT_SERVICE_CPP) NavigableContents ...@@ -34,13 +30,14 @@ class COMPONENT_EXPORT(CONTENT_SERVICE_CPP) NavigableContents
explicit NavigableContents(mojom::NavigableContentsFactory* factory); explicit NavigableContents(mojom::NavigableContentsFactory* factory);
~NavigableContents() override; ~NavigableContents() override;
// Returns a View which renders this NavigableContents's currently navigated // Returns a NavigableContentsView which renders this NavigableContents's
// contents. This widget can be parented and displayed anywhere within the // currently navigated contents. This widget can be parented and displayed
// application's own window tree. // anywhere within the application's own window tree.
// //
// Note that this View is created lazily on first call, and by default // Note that this NavigableContentsView is created lazily on first call, and
// NavigableContents does not otherwise create or manipulate UI objects. // by default NavigableContents does not otherwise create or manipulate UI
views::View* GetView(); // objects.
NavigableContentsView* GetView();
// Begins an attempt to asynchronously navigate this NavigableContents to // Begins an attempt to asynchronously navigate this NavigableContents to
// |url|. // |url|.
...@@ -59,13 +56,7 @@ class COMPONENT_EXPORT(CONTENT_SERVICE_CPP) NavigableContents ...@@ -59,13 +56,7 @@ class COMPONENT_EXPORT(CONTENT_SERVICE_CPP) NavigableContents
mojom::NavigableContentsPtr contents_; mojom::NavigableContentsPtr contents_;
mojo::Binding<mojom::NavigableContentsClient> client_binding_; mojo::Binding<mojom::NavigableContentsClient> client_binding_;
std::unique_ptr<NavigableContentsView> view_;
#if BUILDFLAG(ENABLE_AURA_CONTENT_VIEW_EMBEDDING)
// This NavigableContents's View. Only initialized if |GetView()| is called,
// and only on platforms which support View embedding via Aura.
std::unique_ptr<views::View> view_;
views::RemoteViewHost* remote_view_host_ = nullptr;
#endif
base::RepeatingClosure did_stop_loading_callback_; base::RepeatingClosure did_stop_loading_callback_;
......
// 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 "services/content/public/cpp/navigable_contents_view.h"
#include <map>
#include "base/callback.h"
#include "base/no_destructor.h"
#include "base/synchronization/atomic_flag.h"
#include "base/unguessable_token.h"
#include "services/content/public/cpp/buildflags.h"
#if BUILDFLAG(ENABLE_NAVIGABLE_CONTENTS_VIEW_AURA)
#include "ui/views/layout/fill_layout.h" // nogncheck
#include "ui/views/view.h" // nogncheck
#if BUILDFLAG(ENABLE_REMOTE_NAVIGABLE_CONTENTS_VIEW)
#include "services/ui/public/interfaces/window_tree_constants.mojom.h" // nogncheck
#include "ui/base/ui_base_features.h" // nogncheck
#include "ui/views/mus/remote_view/remote_view_host.h" // nogncheck
#endif // BUILDFLAG(ENABLE_REMOTE_NAVIGABLE_CONTENTS_VIEW)
#endif // BUILDFLAG(ENABLE_NAVIGABLE_CONTENTS_VIEW_AURA)
namespace content {
namespace {
using InProcessEmbeddingMap =
std::map<base::UnguessableToken,
base::OnceCallback<void(NavigableContentsView*)>>;
InProcessEmbeddingMap& GetInProcessEmbeddingMap() {
static base::NoDestructor<InProcessEmbeddingMap> embedding_map;
return *embedding_map;
}
base::AtomicFlag& GetInServiceProcessFlag() {
static base::NoDestructor<base::AtomicFlag> in_service_process;
return *in_service_process;
}
} // namespace
NavigableContentsView::~NavigableContentsView() = default;
// static
void NavigableContentsView::SetClientRunningInServiceProcess() {
GetInServiceProcessFlag().Set();
}
// static
bool NavigableContentsView::IsClientRunningInServiceProcess() {
return GetInServiceProcessFlag().IsSet();
}
NavigableContentsView::NavigableContentsView() {
#if BUILDFLAG(ENABLE_NAVIGABLE_CONTENTS_VIEW_AURA)
view_ = std::make_unique<views::View>();
view_->set_owned_by_client();
view_->SetLayoutManager(std::make_unique<views::FillLayout>());
#if BUILDFLAG(ENABLE_REMOTE_NAVIGABLE_CONTENTS_VIEW)
if (!IsClientRunningInServiceProcess()) {
DCHECK(!remote_view_host_);
remote_view_host_ = new views::RemoteViewHost;
view_->AddChildView(remote_view_host_);
}
#endif // BUILDFLAG(ENABLE_REMOTE_NAVIGABLE_CONTENTS_VIEW)
#endif // BUILDFLAG(ENABLE_NAVIGABLE_CONTENTS_VIEW_AURA)
}
void NavigableContentsView::EmbedUsingToken(
const base::UnguessableToken& token) {
#if BUILDFLAG(ENABLE_NAVIGABLE_CONTENTS_VIEW_AURA)
#if BUILDFLAG(ENABLE_REMOTE_NAVIGABLE_CONTENTS_VIEW)
if (remote_view_host_) {
const uint32_t kEmbedFlags =
ui::mojom::kEmbedFlagEmbedderInterceptsEvents |
ui::mojom::kEmbedFlagEmbedderControlsVisibility;
remote_view_host_->EmbedUsingToken(token, kEmbedFlags, base::DoNothing());
return;
}
#endif // BUILDFLAG(ENABLE_REMOTE_NAVIGABLE_CONTENTS_VIEW)
DCHECK(IsClientRunningInServiceProcess());
// |token| should already have an embed callback entry in the in-process
// callback map, injected by the in-process Content Service implementation.
auto& embeddings = GetInProcessEmbeddingMap();
auto it = embeddings.find(token);
if (it == embeddings.end()) {
DLOG(ERROR) << "Unable to embed with unknown token " << token.ToString();
return;
}
auto callback = std::move(it->second);
embeddings.erase(it);
std::move(callback).Run(this);
#endif // BUILDFLAG(ENABLE_NAVIGABLE_CONTENTS_VIEW_AURA)
}
// static
void NavigableContentsView::RegisterInProcessEmbedCallback(
const base::UnguessableToken& token,
base::OnceCallback<void(NavigableContentsView*)> callback) {
GetInProcessEmbeddingMap()[token] = std::move(callback);
}
} // namespace content
// 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 SERVICES_CONTENT_PUBLIC_CPP_NAVIGABLE_CONTENTS_VIEW_H_
#define SERVICES_CONTENT_PUBLIC_CPP_NAVIGABLE_CONTENTS_VIEW_H_
#include <memory>
#include "base/component_export.h"
#include "base/unguessable_token.h"
#include "services/content/public/cpp/buildflags.h"
namespace views {
class RemoteViewHost;
class View;
} // namespace views
namespace content {
class NavigableContents;
class NavigableContentsImpl;
// NavigableContentsView encapsulates cross-platform manipulation and
// presentation of a NavigableContents within a native application UI based on
// either Aura, UIKit, AppKit, or the Android Framework.
//
// TODO(https://crbug.com/855092): Actually support UI frameworks other than
// Aura.
class COMPONENT_EXPORT(CONTENT_SERVICE_CPP) NavigableContentsView {
public:
~NavigableContentsView();
// Used to set/query whether the calling process is the same process in which
// all Content Service instances are running. This should be used sparingly,
// and in general is only here to support internal sanity checks when
// performing, e.g., UI embedding operations on platforms where remote
// NavigableContentsViews are not yet supported.
static void SetClientRunningInServiceProcess();
static bool IsClientRunningInServiceProcess();
#if BUILDFLAG(ENABLE_NAVIGABLE_CONTENTS_VIEW_AURA)
views::View* view() const { return view_.get(); }
#endif
private:
friend class NavigableContents;
friend class NavigableContentsImpl;
NavigableContentsView();
// Establishes a hierarchical relationship between this view's native UI
// object and another native UI object within the Content Service.
void EmbedUsingToken(const base::UnguessableToken& token);
// Used by the service directly when running in the same process. Establishes
// a way for an embed token to be used without the UI service.
static void RegisterInProcessEmbedCallback(
const base::UnguessableToken& token,
base::OnceCallback<void(NavigableContentsView*)> callback);
#if BUILDFLAG(ENABLE_NAVIGABLE_CONTENTS_VIEW_AURA)
// This NavigableContents's View. Only initialized if |GetView()| is called,
// and only on platforms which support View embedding via Aura.
std::unique_ptr<views::View> view_;
#if BUILDFLAG(ENABLE_REMOTE_NAVIGABLE_CONTENTS_VIEW)
views::RemoteViewHost* remote_view_host_ = nullptr;
#endif
#endif // BUILDFLAG(ENABLE_NAVIGABLE_CONTENTS_VIEW_AURA)
DISALLOW_COPY_AND_ASSIGN(NavigableContentsView);
};
} // namespace content
#endif // SERVICES_CONTENT_PUBLIC_CPP_NAVIGABLE_CONTENTS_VIEW_H_
...@@ -7,7 +7,23 @@ import("//build/config/chromecast_build.gni") ...@@ -7,7 +7,23 @@ import("//build/config/chromecast_build.gni")
import("//build/config/ui.gni") import("//build/config/ui.gni")
declare_args() { declare_args() {
# Determines whether or not Aura-based view embedding should be supported by # Determines whether or not the Content Service should support a
# the Content Service. # NavigableContentsView based on the Aura framework. For platforms which
enable_aura_content_view_embedding = use_aura && !is_fuchsia && !is_chromecast # only support Aura-based UI, setting this to |false| means that
# NavigableContentsView will have no actual UI presence.
enable_navigable_contents_view_aura =
use_aura && !is_fuchsia && !is_chromecast
# Determines whether or not the Content Service should support remote
# (i.e., out-of-process) clients embedding NavigableContentsViews within their
# UI. If this is false, only clients in the same process as the Content
# Service may use NavigableContentsView.
#
# Currently only supported on Chrome OS, where
# |enable_navigable_contents_view_aura| is implied and the UI service
# (i.e. Mus) is available.
enable_remote_navigable_contents_view = is_chromeos
} }
assert(!enable_remote_navigable_contents_view ||
enable_navigable_contents_view_aura)
...@@ -19,7 +19,16 @@ interface NavigableContents { ...@@ -19,7 +19,16 @@ interface NavigableContents {
// maintained by the Content Service. Responds with a |embed_token| which can // maintained by the Content Service. Responds with a |embed_token| which can
// be given to Mus in order to authorize embedding of that visual // be given to Mus in order to authorize embedding of that visual
// representation within the client application's own window tree. // representation within the client application's own window tree.
CreateView() => (mojo_base.mojom.UnguessableToken embed_token); //
// |in_service_process| must be true iff the client calling this method is
// running in the same process as the Content Service. This can be known in
// the client by calling
// |NavigableContentsView::IsClientRunningInServiceProcess()|.
//
// TODO(https://crbug.com/874143): Remove the |in_service_process| flag once
// we have more widely available UI Service support.
CreateView(bool in_service_process)
=> (mojo_base.mojom.UnguessableToken embed_token);
}; };
// A client interface used by the Content Service to push contents-scoped events // A client interface used by the Content Service to push contents-scoped events
......
This directory contains an implementation of a simple, sandboxed, Content This directory contains an implementation of a simple Content Service client
Service client application which serves as a tool for manual developer testing application which serves as a tool for manual developer testing of the Content
of the Content Service, a straightforward example browser application consuming Service, a straightforward example browser application consuming the Content
the Content Service, and potentially as a target for driving automated Service, and potentially as a target for driving automated Content Service
Content Service integration tests. integration tests.
To play around with simple_browser today, build Chrome with The simple_browser application can run in an isolated sandboxed process on
`target_os = "chromeos"` and run with `--enable-features=Mash` and platforms which support the UI Service (currently only Chrome OS), or within the
`--launch-simple-browser`. browser process on platforms which otherwise support NavigableContentsView
embedding (currently Chrome OS, Linux, and Windows).
To play around with simple_browser today, run a DCHECK-enabled build of Chrome
with `--launch-in-process-simple-browser` on any supported platform listed
above.
To test the sandboxed, out-of-process version, use a DCHECK-enabled Chrome OS
build and run with both `--enable-features=Mash` and `--launch-simple-browser`
flags.
...@@ -10,27 +10,31 @@ ...@@ -10,27 +10,31 @@
#include "ui/views/mus/aura_init.h" #include "ui/views/mus/aura_init.h"
#if defined(OS_LINUX) #if defined(OS_LINUX)
#include "third_party/skia/include/ports/SkFontConfigInterface.h" #include "third_party/skia/include/ports/SkFontConfigInterface.h" // nogncheck
#endif #endif
namespace simple_browser { namespace simple_browser {
SimpleBrowserService::SimpleBrowserService() = default; SimpleBrowserService::SimpleBrowserService(
UIInitializationMode ui_initialization_mode)
: ui_initialization_mode_(ui_initialization_mode) {}
SimpleBrowserService::~SimpleBrowserService() = default; SimpleBrowserService::~SimpleBrowserService() = default;
void SimpleBrowserService::OnStart() { void SimpleBrowserService::OnStart() {
if (ui_initialization_mode_ == UIInitializationMode::kInitializeUI) {
#if defined(OS_LINUX) #if defined(OS_LINUX)
font_loader_ = sk_make_sp<font_service::FontLoader>(context()->connector()); font_loader_ = sk_make_sp<font_service::FontLoader>(context()->connector());
SkFontConfigInterface::SetGlobal(font_loader_); SkFontConfigInterface::SetGlobal(font_loader_);
#endif #endif
views::AuraInit::InitParams params; views::AuraInit::InitParams params;
params.connector = context()->connector(); params.connector = context()->connector();
params.identity = context()->identity(); params.identity = context()->identity();
params.register_path_provider = false; params.register_path_provider = false;
aura_init_ = views::AuraInit::Create(params); aura_init_ = views::AuraInit::Create(params);
CHECK(aura_init_); CHECK(aura_init_);
}
window_ = std::make_unique<Window>(context()->connector()); window_ = std::make_unique<Window>(context()->connector());
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "services/service_manager/public/cpp/service.h" #include "services/service_manager/public/cpp/service.h"
#if defined(OS_LINUX) #if defined(OS_LINUX)
#include "components/services/font/public/cpp/font_loader.h" #include "components/services/font/public/cpp/font_loader.h" // nogncheck
#endif #endif
namespace views { namespace views {
...@@ -28,7 +28,18 @@ class Window; ...@@ -28,7 +28,18 @@ class Window;
class COMPONENT_EXPORT(SIMPLE_BROWSER) SimpleBrowserService class COMPONENT_EXPORT(SIMPLE_BROWSER) SimpleBrowserService
: public service_manager::Service { : public service_manager::Service {
public: public:
SimpleBrowserService(); // Determines how a SimpleBrowserService instance is initialized.
enum class UIInitializationMode {
// The service is being run in an isolated process which has not yet
// initialized a UI framework.
kInitializeUI,
// The service is being run in a process which has already initialized a
// UI framework. No need to do that.
kUseEnvironmentUI,
};
explicit SimpleBrowserService(UIInitializationMode mode);
~SimpleBrowserService() override; ~SimpleBrowserService() override;
private: private:
...@@ -39,6 +50,7 @@ class COMPONENT_EXPORT(SIMPLE_BROWSER) SimpleBrowserService ...@@ -39,6 +50,7 @@ class COMPONENT_EXPORT(SIMPLE_BROWSER) SimpleBrowserService
sk_sp<font_service::FontLoader> font_loader_; sk_sp<font_service::FontLoader> font_loader_;
#endif #endif
const UIInitializationMode ui_initialization_mode_;
std::unique_ptr<views::AuraInit> aura_init_; std::unique_ptr<views::AuraInit> aura_init_;
std::unique_ptr<Window> window_; std::unique_ptr<Window> window_;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "services/content/public/cpp/navigable_contents.h" #include "services/content/public/cpp/navigable_contents.h"
#include "services/content/public/cpp/navigable_contents_view.h"
#include "services/content/public/mojom/constants.mojom.h" #include "services/content/public/mojom/constants.mojom.h"
#include "services/content/public/mojom/navigable_contents_factory.mojom.h" #include "services/content/public/mojom/navigable_contents_factory.mojom.h"
#include "services/service_manager/public/cpp/connector.h" #include "services/service_manager/public/cpp/connector.h"
...@@ -38,9 +39,9 @@ class SimpleBrowserUI : public views::WidgetDelegateView, ...@@ -38,9 +39,9 @@ class SimpleBrowserUI : public views::WidgetDelegateView,
MakeRequest(&navigable_contents_factory_)); MakeRequest(&navigable_contents_factory_));
navigable_contents_ = std::make_unique<content::NavigableContents>( navigable_contents_ = std::make_unique<content::NavigableContents>(
navigable_contents_factory_.get()); navigable_contents_factory_.get());
content_view_ = navigable_contents_->GetView(); navigable_contents_view_ = navigable_contents_->GetView();
content_view_->SetBorder(views::CreateSolidBorder(2, SK_ColorGREEN));
AddChildView(content_view_); AddChildView(navigable_contents_view_->view());
} }
~SimpleBrowserUI() override = default; ~SimpleBrowserUI() override = default;
...@@ -59,7 +60,7 @@ class SimpleBrowserUI : public views::WidgetDelegateView, ...@@ -59,7 +60,7 @@ class SimpleBrowserUI : public views::WidgetDelegateView,
gfx::Rect content_view_bounds = GetLocalBounds(); gfx::Rect content_view_bounds = GetLocalBounds();
content_view_bounds.Inset(5, 25, 5, 5); content_view_bounds.Inset(5, 25, 5, 5);
content_view_->SetBoundsRect(content_view_bounds); navigable_contents_view_->view()->SetBoundsRect(content_view_bounds);
} }
gfx::Size CalculatePreferredSize() const override { gfx::Size CalculatePreferredSize() const override {
...@@ -84,9 +85,9 @@ class SimpleBrowserUI : public views::WidgetDelegateView, ...@@ -84,9 +85,9 @@ class SimpleBrowserUI : public views::WidgetDelegateView,
content::mojom::NavigableContentsFactoryPtr navigable_contents_factory_; content::mojom::NavigableContentsFactoryPtr navigable_contents_factory_;
std::unique_ptr<content::NavigableContents> navigable_contents_; std::unique_ptr<content::NavigableContents> navigable_contents_;
content::NavigableContentsView* navigable_contents_view_ = nullptr;
views::Textfield* location_bar_; views::Textfield* location_bar_;
views::View* content_view_;
DISALLOW_COPY_AND_ASSIGN(SimpleBrowserUI); DISALLOW_COPY_AND_ASSIGN(SimpleBrowserUI);
}; };
......
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