Commit 9fc30684 authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

[Fuchsia] Enable web::Context implementation in web context service

1. Added ContextProviderMain() that instantiates ContentProviderImpl.
2. Updated WebRunnerMainDelegate to run WebRunnerBrowserMain() only
   when process is started with --type=web-context
3. Updated WebRunnerBrowserMainParts to instantiate ContextImpl.
4. Updated ContextProviderImpl to pass --type=web-context to the
   web context process.

Bug: 852145
Change-Id: I9740162ad9006df5e254e6ca3d4bed24640c94ce
Reviewed-on: https://chromium-review.googlesource.com/1134585
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575378}
parent 508cc6b1
......@@ -81,6 +81,7 @@ component("service_lib") {
"//content/public/common",
"//content/public/renderer",
"//services/network/public/cpp",
"//services/service_manager/embedder:embedder_switches",
"//ui/display",
]
......@@ -113,14 +114,16 @@ component("service_lib") {
"common/webrunner_content_client.cc",
"common/webrunner_content_client.h",
"common/webrunner_export.h",
"service/common.cc",
"service/common.h",
"service/context_impl.cc",
"service/context_impl.h",
"service/context_provider_impl.cc",
"service/context_provider_impl.h",
"service/context_provider_main.cc",
"service/context_provider_main.h",
"service/frame_impl.cc",
"service/frame_impl.h",
"service/switches.cc",
"service/switches.h",
"service/webrunner_main_delegate.cc",
"service/webrunner_main_delegate.h",
]
......
......@@ -6,6 +6,8 @@
#include "webrunner/browser/webrunner_browser_context.h"
#include "webrunner/browser/webrunner_screen.h"
#include "webrunner/service/common.h"
#include "webrunner/service/context_impl.h"
namespace webrunner {
......@@ -19,6 +21,26 @@ void WebRunnerBrowserMainParts::PreMainMessageLoopRun() {
DCHECK(!browser_context_);
browser_context_ = std::make_unique<WebRunnerBrowserContext>();
// Get the Context InterfaceRequest which was passed to the process by
// the ContextProvider.
zx::channel context_handle{zx_take_startup_handle(kContextRequestHandleId)};
CHECK(context_handle) << "Could not find the Context request startup handle.";
fidl::InterfaceRequest<chromium::web::Context> context_request(
std::move(context_handle));
context_impl_ = std::make_unique<ContextImpl>();
context_binding_ = std::make_unique<fidl::Binding<chromium::web::Context>>(
context_impl_.get(), std::move(context_request));
// Quit the context process as soon as context is disconnected.
context_binding_->set_error_handler(
[this]() { std::move(quit_closure_).Run(); });
}
void WebRunnerBrowserMainParts::PreDefaultMainMessageLoopRun(
base::OnceClosure quit_closure) {
quit_closure_ = std::move(quit_closure);
}
} // namespace webrunner
......@@ -5,13 +5,16 @@
#ifndef WEBRUNNER_BROWSER_WEBRUNNER_BROWSER_MAIN_PARTS_H_
#define WEBRUNNER_BROWSER_WEBRUNNER_BROWSER_MAIN_PARTS_H_
#include <lib/fidl/cpp/binding.h>
#include <memory>
#include "base/macros.h"
#include "content/public/browser/browser_main_parts.h"
#include "webrunner/fidl/chromium/web/cpp/fidl.h"
namespace webrunner {
class ContextImpl;
class WebRunnerBrowserContext;
class WebRunnerScreen;
......@@ -22,11 +25,17 @@ class WebRunnerBrowserMainParts : public content::BrowserMainParts {
// content::BrowserMainParts overrides.
void PreMainMessageLoopRun() override;
void PreDefaultMainMessageLoopRun(base::OnceClosure quit_closure) override;
private:
std::unique_ptr<WebRunnerScreen> screen_;
std::unique_ptr<WebRunnerBrowserContext> browser_context_;
std::unique_ptr<ContextImpl> context_impl_;
std::unique_ptr<fidl::Binding<chromium::web::Context>> context_binding_;
base::OnceClosure quit_closure_;
DISALLOW_COPY_AND_ASSIGN(WebRunnerBrowserMainParts);
};
......
include_rules = [
"+chromium/web/cpp", # FIDL generated headers
"+content/public/app",
"+services/service_manager",
"+ui/base",
]
......@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "webrunner/service/switches.h"
#include "webrunner/service/common.h"
namespace webrunner {
const char kContextProcess[] = "context-process";
constexpr const char kProcessTypeWebContext[] = "web-context";
} // namespace webrunner
......@@ -9,7 +9,11 @@
namespace webrunner {
const uint32_t kContextRequestHandleId = PA_HND(PA_USER0, 0);
constexpr uint32_t kContextRequestHandleId = PA_HND(PA_USER0, 0);
// Process type value used for the web::Context process. It is equivalent to
// the main browser process in chrome.
extern const char kProcessTypeWebContext[];
} // namespace webrunner
......
......@@ -17,8 +17,8 @@
#include "base/fuchsia/fuchsia_logging.h"
#include "base/logging.h"
#include "base/process/launch.h"
#include "services/service_manager/embedder/switches.h"
#include "webrunner/service/common.h"
#include "webrunner/service/switches.h"
namespace webrunner {
namespace {
......@@ -26,8 +26,9 @@ namespace {
// Relaunches the current executable as a Context process.
base::Process LaunchContextProcess(const base::LaunchOptions& launch_options) {
base::CommandLine launch_command = *base::CommandLine::ForCurrentProcess();
DCHECK(!launch_command.HasSwitch(kContextProcess));
launch_command.AppendSwitch(kContextProcess);
DCHECK(!launch_command.HasSwitch(service_manager::switches::kProcessType));
launch_command.AppendSwitchASCII(service_manager::switches::kProcessType,
kProcessTypeWebContext);
return base::LaunchProcess(launch_command, launch_options);
}
......
// 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/service/context_provider_main.h"
#include "base/fuchsia/scoped_service_binding.h"
#include "base/fuchsia/service_directory.h"
#include "base/logging.h"
#include "base/run_loop.h"
#include "webrunner/service/context_provider_impl.h"
namespace webrunner {
int ContextProviderMain() {
base::fuchsia::ServiceDirectory* directory =
base::fuchsia::ServiceDirectory::GetDefault();
ContextProviderImpl context_provider;
base::fuchsia::ScopedServiceBinding<chromium::web::ContextProvider> binding(
directory, &context_provider);
// TODO(crbug.com/852145): Currently the process will run until it's killed.
base::RunLoop().Run();
return 0;
}
} // namespace webrunner
......@@ -2,18 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WEBRUNNER_SERVICE_SWITCHES_H_
#define WEBRUNNER_SERVICE_SWITCHES_H_
#ifndef WEBRUNNER_SERVICE_CONTEXT_PROVIDER_MAIN_H_
#define WEBRUNNER_SERVICE_CONTEXT_PROVIDER_MAIN_H_
#include "webrunner/common/webrunner_export.h"
#include "webrunner/service/context_provider_main.h"
namespace webrunner {
// "--context-process" signifies the process should be launched as a Context
// service.
// Omitting the switch signifies that the process should be a ContextProvider.
extern WEBRUNNER_EXPORT const char kContextProcess[];
// Main function for the process that implements web::ContextProvider interface.
// Called by WebRunnerMainDelegate when the process is started without --type
// argument.
int ContextProviderMain();
} // namespace webrunner
#endif // WEBRUNNER_SERVICE_SWITCHES_H_
#endif // WEBRUNNER_SERVICE_CONTEXT_PROVIDER_MAIN_H_
\ No newline at end of file
......@@ -12,6 +12,8 @@
#include "webrunner/browser/webrunner_browser_main.h"
#include "webrunner/browser/webrunner_content_browser_client.h"
#include "webrunner/common/webrunner_content_client.h"
#include "webrunner/service/common.h"
#include "webrunner/service/context_provider_main.h"
namespace webrunner {
......@@ -64,10 +66,13 @@ void WebRunnerMainDelegate::PreSandboxStartup() {
int WebRunnerMainDelegate::RunProcess(
const std::string& process_type,
const content::MainFunctionParams& main_function_params) {
if (process_type == kProcessTypeWebContext)
return WebRunnerBrowserMain(main_function_params);
if (!process_type.empty())
return -1;
return WebRunnerBrowserMain(main_function_params);
return ContextProviderMain();
}
content::ContentBrowserClient*
......
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