[go: nahoru, domu]

[Fuchsia] Add top-level webrunner directory and webrunner skeleton.

WebRunner will be used on Fuchsia to run web applications.

Bug: 822474
Change-Id: I56b2fd4bf653bb2c77a013b3134f6dba8065289a
Reviewed-on: https://chromium-review.googlesource.com/965255
Reviewed-by: Wez <wez@chromium.org>
Reviewed-by: Ben Goodger <ben@chromium.org>
Reviewed-by: Kevin Marshall <kmarshall@chromium.org>
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547039}
diff --git a/BUILD.gn b/BUILD.gn
index fccc380..5a3538c 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -742,6 +742,7 @@
       "//headless",
       "//headless:headless_shell",
       "//headless:headless_tests",
+      "//webrunner",
     ]
   }
 }
diff --git a/webrunner/BUILD.gn b/webrunner/BUILD.gn
new file mode 100644
index 0000000..e95ab9b
--- /dev/null
+++ b/webrunner/BUILD.gn
@@ -0,0 +1,29 @@
+# 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.
+
+assert(is_fuchsia)
+
+import("//build/config/fuchsia/rules.gni")
+
+executable("webrunner") {
+  public_deps = [
+    "//content/public/app:both",
+    "//content/public/browser",
+    "//content/public/child",
+    "//content/public/common",
+    "//content/public/renderer",
+  ]
+
+  sources = [
+    "app/webrunner_main.cc",
+    "app/webrunner_main_delegate.cc",
+    "app/webrunner_main_delegate.h",
+    "browser/webrunner_browser_main.cc",
+    "browser/webrunner_browser_main.h",
+  ]
+}
+
+fuchsia_executable_runner("webrunner_fuchsia") {
+  exe_target = ":webrunner"
+}
diff --git a/webrunner/DEPS b/webrunner/DEPS
new file mode 100644
index 0000000..7891ede
--- /dev/null
+++ b/webrunner/DEPS
@@ -0,0 +1,3 @@
+include_rules = [
+  "+content/public/common",
+]
\ No newline at end of file
diff --git a/webrunner/OWNERS b/webrunner/OWNERS
new file mode 100644
index 0000000..e7034ea
--- /dev/null
+++ b/webrunner/OWNERS
@@ -0,0 +1 @@
+file://build/fuchsia/OWNERS
diff --git a/webrunner/README.md b/webrunner/README.md
new file mode 100644
index 0000000..01e6e680
--- /dev/null
+++ b/webrunner/README.md
@@ -0,0 +1,2 @@
+This directory contains WebRunner implementation. WebRunner allows to run
+web applications on Fuchsia.
\ No newline at end of file
diff --git a/webrunner/app/DEPS b/webrunner/app/DEPS
new file mode 100644
index 0000000..e7cb291
--- /dev/null
+++ b/webrunner/app/DEPS
@@ -0,0 +1,4 @@
+include_rules = [
+  "+content/public/app",
+  "+ui/base",
+]
\ No newline at end of file
diff --git a/webrunner/app/webrunner_main.cc b/webrunner/app/webrunner_main.cc
new file mode 100644
index 0000000..eed0edf
--- /dev/null
+++ b/webrunner/app/webrunner_main.cc
@@ -0,0 +1,14 @@
+// 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 "content/public/app/content_main.h"
+#include "webrunner/app/webrunner_main_delegate.h"
+
+int main(int argc, const char** argv) {
+  webrunner::WebRunnerMainDelegate delegate;
+  content::ContentMainParams params(&delegate);
+  params.argc = argc;
+  params.argv = argv;
+  return content::ContentMain(params);
+}
diff --git a/webrunner/app/webrunner_main_delegate.cc b/webrunner/app/webrunner_main_delegate.cc
new file mode 100644
index 0000000..97b5b18
--- /dev/null
+++ b/webrunner/app/webrunner_main_delegate.cc
@@ -0,0 +1,69 @@
+// 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/app/webrunner_main_delegate.h"
+
+#include "base/base_paths.h"
+#include "base/command_line.h"
+#include "base/path_service.h"
+#include "content/public/common/content_switches.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "webrunner/browser/webrunner_browser_main.h"
+
+namespace webrunner {
+
+namespace {
+
+void InitLoggingFromCommandLine(const base::CommandLine& command_line) {
+  base::FilePath log_filename;
+  std::string filename = command_line.GetSwitchValueASCII(switches::kLogFile);
+  if (filename.empty()) {
+    PathService::Get(base::DIR_EXE, &log_filename);
+    log_filename = log_filename.AppendASCII("webrunner.log");
+  } else {
+    log_filename = base::FilePath::FromUTF8Unsafe(filename);
+  }
+
+  logging::LoggingSettings settings;
+  settings.logging_dest = logging::LOG_TO_ALL;
+  settings.log_file = log_filename.value().c_str();
+  settings.delete_old = logging::DELETE_OLD_LOG_FILE;
+  logging::InitLogging(settings);
+  logging::SetLogItems(true /* Process ID */, true /* Thread ID */,
+                       true /* Timestamp */, false /* Tick count */);
+}
+
+void InitializeResourceBundle() {
+  base::FilePath pak_file;
+  bool result = base::PathService::Get(base::DIR_ASSETS, &pak_file);
+  DCHECK(result);
+  pak_file = pak_file.Append(FILE_PATH_LITERAL("webrunner.pak"));
+  ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file);
+}
+
+}  // namespace
+
+WebRunnerMainDelegate::WebRunnerMainDelegate() = default;
+WebRunnerMainDelegate::~WebRunnerMainDelegate() = default;
+
+bool WebRunnerMainDelegate::BasicStartupComplete(int* exit_code) {
+  base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
+  InitLoggingFromCommandLine(*command_line);
+  return false;
+}
+
+void WebRunnerMainDelegate::PreSandboxStartup() {
+  InitializeResourceBundle();
+}
+
+int WebRunnerMainDelegate::RunProcess(
+    const std::string& process_type,
+    const content::MainFunctionParams& main_function_params) {
+  if (!process_type.empty())
+    return -1;
+
+  return WebRunnerBrowserMain(main_function_params);
+}
+
+}  // namespace webrunner
diff --git a/webrunner/app/webrunner_main_delegate.h b/webrunner/app/webrunner_main_delegate.h
new file mode 100644
index 0000000..4b88a08
--- /dev/null
+++ b/webrunner/app/webrunner_main_delegate.h
@@ -0,0 +1,33 @@
+// 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_APP_WEBRUNNER_MAIN_DELEGATE_H_
+#define WEBRUNNER_APP_WEBRUNNER_MAIN_DELEGATE_H_
+
+#include <memory>
+
+#include "base/macros.h"
+#include "content/public/app/content_main_delegate.h"
+
+namespace webrunner {
+
+class WebRunnerMainDelegate : public content::ContentMainDelegate {
+ public:
+  WebRunnerMainDelegate();
+  ~WebRunnerMainDelegate() override;
+
+  // ContentMainDelegate implementation.
+  bool BasicStartupComplete(int* exit_code) override;
+  void PreSandboxStartup() override;
+  int RunProcess(
+      const std::string& process_type,
+      const content::MainFunctionParams& main_function_params) override;
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(WebRunnerMainDelegate);
+};
+
+}  // namespace webrunner
+
+#endif  // WEBRUNNER_APP_WEBRUNNER_MAIN_DELEGATE_H_
diff --git a/webrunner/browser/DEPS b/webrunner/browser/DEPS
new file mode 100644
index 0000000..e6a7598
--- /dev/null
+++ b/webrunner/browser/DEPS
@@ -0,0 +1,3 @@
+include_rules = [
+  "+content/public/browser",
+]
\ No newline at end of file
diff --git a/webrunner/browser/webrunner_browser_main.cc b/webrunner/browser/webrunner_browser_main.cc
new file mode 100644
index 0000000..fe0ec37a
--- /dev/null
+++ b/webrunner/browser/webrunner_browser_main.cc
@@ -0,0 +1,30 @@
+// 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_main.h"
+
+#include <memory>
+
+#include "base/logging.h"
+#include "base/message_loop/message_loop.h"
+#include "build/build_config.h"
+#include "content/public/browser/browser_main_runner.h"
+
+namespace webrunner {
+
+int WebRunnerBrowserMain(const content::MainFunctionParams& parameters) {
+  std::unique_ptr<content::BrowserMainRunner> main_runner(
+      content::BrowserMainRunner::Create());
+  int exit_code = main_runner->Initialize(parameters);
+  if (exit_code >= 0)
+    return exit_code;
+
+  exit_code = main_runner->Run();
+
+  main_runner->Shutdown();
+
+  return exit_code;
+}
+
+}  // namespace webrunner
\ No newline at end of file
diff --git a/webrunner/browser/webrunner_browser_main.h b/webrunner/browser/webrunner_browser_main.h
new file mode 100644
index 0000000..37428a1
--- /dev/null
+++ b/webrunner/browser/webrunner_browser_main.h
@@ -0,0 +1,18 @@
+// 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_MAIN_H_
+#define WEBRUNNER_BROWSER_WEBRUNNER_BROWSER_MAIN_H_
+
+#include <memory>
+
+namespace content {
+struct MainFunctionParams;
+}  // namespace content
+
+namespace webrunner {
+int WebRunnerBrowserMain(const content::MainFunctionParams& parameters);
+}  // namespace webrunner
+
+#endif  // WEBRUNNER_BROWSER_WEBRUNNER_BROWSER_MAIN_H_