Skip to content

Commit

Permalink
[OOBE] - Add screen code generator
Browse files Browse the repository at this point in the history
This CL introduces MVP implementation of the OOBE Code Generator. This
tool in a form of the Python script can create all needed boilerplate
code with a given screen name and add new files to correct BUILD.gn
files.

After tool's work is done user will need only to integrate new screen
into the wizard controller flow and add their business logic.

Bug: b:266668077
Change-Id: I4e366ef5b1e842f5f719e485848c1991370c17b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4400951
Reviewed-by: Danila Kuzmin <dkuzmin@google.com>
Commit-Queue: Bohdan Tyshchenko <bohdanty@google.com>
Reviewed-by: Dirk Pranke <dpranke@google.com>
Reviewed-by: Osama Fathy <osamafathy@google.com>
Cr-Commit-Position: refs/heads/main@{#1152078}
  • Loading branch information
bohdanty authored and Chromium LUCI CQ committed Jun 1, 2023
1 parent 4f77ef4 commit 82cca37
Show file tree
Hide file tree
Showing 13 changed files with 741 additions and 0 deletions.
4 changes: 4 additions & 0 deletions chrome/browser/ash/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1824,6 +1824,10 @@ source_set("ash") {
"login/screens/parental_handoff_screen.h",
"login/screens/pin_setup_screen.cc",
"login/screens/pin_setup_screen.h",

# Template used by the `tools/oobe/generate_screen_template.py` script.
"login/screens/placeholder_screen.cc",
"login/screens/placeholder_screen.h",
"login/screens/quick_start_screen.cc",
"login/screens/quick_start_screen.h",
"login/screens/recommend_apps/fake_recommend_apps_fetcher.cc",
Expand Down
67 changes: 67 additions & 0 deletions chrome/browser/ash/login/screens/placeholder_screen.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ash/login/screens/placeholder_screen.h"

#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "chrome/browser/ash/login/oobe_screen.h"
#include "chrome/browser/ash/login/screens/base_screen.h"
#include "chrome/browser/ash/login/wizard_context.h"
#include "chrome/browser/ui/webui/ash/login/placeholder_screen_handler.h"

namespace ash {
namespace {

constexpr char kUserActionBackButtonClicked[] = "back";
constexpr char kUserActionNextButtonClicked[] = "next";

} // namespace

// static
std::string PlaceholderScreen::GetResultString(Result result) {
switch (result) {
case Result::kNext:
return "Next";
case Result::kBack:
return "Back";
case Result::kNotApplicable:
return BaseScreen::kNotApplicable;
}
}

PlaceholderScreen::PlaceholderScreen(base::WeakPtr<PlaceholderScreenView> view,
const ScreenExitCallback& exit_callback)
: BaseScreen(PlaceholderScreenView::kScreenId, OobeScreenPriority::DEFAULT),
view_(std::move(view)),
exit_callback_(exit_callback) {}

PlaceholderScreen::~PlaceholderScreen() = default;

bool PlaceholderScreen::MaybeSkip(WizardContext& context) {
return false;
}

void PlaceholderScreen::ShowImpl() {
if (!view_) {
return;
}

view_->Show();
}

void PlaceholderScreen::HideImpl() {}

void PlaceholderScreen::OnUserAction(const base::Value::List& args) {
const std::string& action_id = args[0].GetString();
if (action_id == kUserActionNextButtonClicked) {
exit_callback_.Run(Result::kNext);
} else if (action_id == kUserActionBackButtonClicked) {
exit_callback_.Run(Result::kBack);
} else {
BaseScreen::OnUserAction(args);
}
}

} // namespace ash
52 changes: 52 additions & 0 deletions chrome/browser/ash/login/screens/placeholder_screen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ASH_LOGIN_SCREENS_PLACEHOLDER_SCREEN_H_
#define CHROME_BROWSER_ASH_LOGIN_SCREENS_PLACEHOLDER_SCREEN_H_

#include <memory>
#include <string>

#include "base/functional/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "chrome/browser/ash/login/screens/base_screen.h"
#include "chrome/browser/ash/login/wizard_context.h"

namespace ash {

class PlaceholderScreenView;

class PlaceholderScreen : public BaseScreen {
public:
using TView = PlaceholderScreenView;

enum class Result { kNext = 0, kBack, kNotApplicable };

using ScreenExitCallback = base::RepeatingCallback<void(Result result)>;

PlaceholderScreen(base::WeakPtr<PlaceholderScreenView> view,
const ScreenExitCallback& exit_callback);

PlaceholderScreen(const PlaceholderScreen&) = delete;
PlaceholderScreen& operator=(const PlaceholderScreen&) = delete;

~PlaceholderScreen() override;

static std::string GetResultString(Result result);

private:
// BaseScreen:
bool MaybeSkip(WizardContext& context) override;
void ShowImpl() override;
void HideImpl() override;
void OnUserAction(const base::Value::List& args) override;

base::WeakPtr<PlaceholderScreenView> view_;
ScreenExitCallback exit_callback_;
};

} // namespace ash

#endif // CHROME_BROWSER_ASH_LOGIN_SCREENS_PLACEHOLDER_SCREEN_H_
3 changes: 3 additions & 0 deletions chrome/browser/resources/chromeos/login/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ preprocess_if_expr("preprocess_unconditional_autogenerated") {
"screens/common/os_trial.js",
"screens/common/parental_handoff.js",
"screens/common/pin_setup.js",

# Template used by the `tools/oobe/generate_screen_template.py` script.
"screens/common/placeholder.js",
"screens/common/recommend_apps.js",
"screens/common/saml_confirm_password.js",
"screens/common/signin_fatal_error.js",
Expand Down
14 changes: 14 additions & 0 deletions chrome/browser/resources/chromeos/login/screens/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ js_type_check("closure_compile_local") {
":os_trial",
":parental_handoff",
":pin_setup",
":placeholder",
":recommend_apps",
":saml_confirm_password",
":signin_fatal_error",
Expand Down Expand Up @@ -545,6 +546,18 @@ js_library("gaia_info") {
extra_deps = [ ":web_components" ]
}

# Template used by the `tools/oobe/generate_screen_template.py` script.
js_library("placeholder") {
sources = [ "$root_gen_dir/chrome/browser/resources/chromeos/login/screens/common/placeholder.js" ]
deps = [
"../../components/behaviors:login_screen_behavior",
"../../components/behaviors:oobe_dialog_host_behavior",
"../../components/behaviors:oobe_i18n_behavior",
"../../components/dialogs:oobe_adaptive_dialog",
]
extra_deps = [ ":web_components" ]
}

js_library("recommend_apps") {
sources = [ "$root_gen_dir/chrome/browser/resources/chromeos/login/screens/common/recommend_apps.js" ]
deps = [
Expand Down Expand Up @@ -738,6 +751,7 @@ html_to_js("web_components") {
"os_trial.js",
"parental_handoff.js",
"pin_setup.js",
"placeholder.js",
"recommend_apps.js",
"saml_confirm_password.js",
"signin_fatal_error.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!--
Copyright 2023 The Chromium Authors
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<style include="oobe-dialog-host-styles">

/* Add styles here */

</style>
<oobe-adaptive-dialog role="dialog">
<!-- Add HTML content here -->
<h1 slot="title">
Your title
</h1>
<div slot="subtitle">
Your subtitle
</div>
<div slot="content" class="layout vertical">
Your content
</div>
<div slot="back-navigation">
<oobe-back-button id="backButton"
on-click="onBackClicked_"></oobe-back-button>
</div>
<div slot="bottom-buttons">
<oobe-next-button id="nextButton"
on-click="onNextClicked_"></oobe-next-button>
</div>
</oobe-adaptive-dialog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import '../../components/buttons/oobe_back_button.js';
import '../../components/buttons/oobe_next_button.js';
import '../../components/common_styles/oobe_common_styles.css.js';
import '../../components/common_styles/oobe_dialog_host_styles.css.js';
import '../../components/dialogs/oobe_adaptive_dialog.js';

import {html, mixinBehaviors, PolymerElement} from '//resources/polymer/v3_0/polymer/polymer_bundled.min.js';

import {LoginScreenBehavior, LoginScreenBehaviorInterface} from '../../components/behaviors/login_screen_behavior.js';
import {OobeDialogHostBehavior} from '../../components/behaviors/oobe_dialog_host_behavior.js';
import {OobeI18nBehavior, OobeI18nBehaviorInterface} from '../../components/behaviors/oobe_i18n_behavior.js';

/**
* @constructor
* @extends {PolymerElement}
* @implements {LoginScreenBehaviorInterface}
* @implements {OobeI18nBehaviorInterface}
*/
const PlaceholderScreenElementBase = mixinBehaviors(
[OobeI18nBehavior, OobeDialogHostBehavior, LoginScreenBehavior],
PolymerElement);

/**
* @polymer
*/
class PlaceholderScreen extends PlaceholderScreenElementBase {
static get is() {
return 'placeholder-element';
}

static get template() {
return html`{__html_template__}`;
}

static get properties() {
return {};
}

/** @override */
ready() {
super.ready();
this.initializeLoginScreen('PlaceholderScreen');
}

/**
* Next button click handler.
* @private
*/
onNextClicked_() {
this.userActed('next');
}

/**
* Back button click handler.
* @private
*/
onBackClicked_() {
this.userActed('back');
}
}

customElements.define(PlaceholderScreen.is, PlaceholderScreen);
4 changes: 4 additions & 0 deletions chrome/browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3034,6 +3034,10 @@ static_library("ui") {
"webui/ash/login/parental_handoff_screen_handler.h",
"webui/ash/login/pin_setup_screen_handler.cc",
"webui/ash/login/pin_setup_screen_handler.h",

# Template used by the `tools/oobe/generate_screen_template.py` script.
"webui/ash/login/placeholder_screen_handler.cc",
"webui/ash/login/placeholder_screen_handler.h",
"webui/ash/login/quick_start_screen_handler.cc",
"webui/ash/login/quick_start_screen_handler.h",
"webui/ash/login/recommend_apps_screen_handler.cc",
Expand Down
25 changes: 25 additions & 0 deletions chrome/browser/ui/webui/ash/login/placeholder_screen_handler.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/webui/ash/login/placeholder_screen_handler.h"

#include "chrome/browser/ui/webui/ash/login/base_screen_handler.h"
#include "components/login/localized_values_builder.h"

namespace ash {

PlaceholderScreenHandler::PlaceholderScreenHandler()
: BaseScreenHandler(kScreenId) {}

PlaceholderScreenHandler::~PlaceholderScreenHandler() = default;

// Add localized values that you want to propagate to the JS side here.
void PlaceholderScreenHandler::DeclareLocalizedValues(
::login::LocalizedValuesBuilder* builder) {}

void PlaceholderScreenHandler::Show() {
ShowInWebUI();
}

} // namespace ash
53 changes: 53 additions & 0 deletions chrome/browser/ui/webui/ash/login/placeholder_screen_handler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_WEBUI_ASH_LOGIN_PLACEHOLDER_SCREEN_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_ASH_LOGIN_PLACEHOLDER_SCREEN_HANDLER_H_

#include "base/memory/weak_ptr.h"
#include "chrome/browser/ash/login/oobe_screen.h"
#include "chrome/browser/ui/webui/ash/login/base_screen_handler.h"
#include "components/login/localized_values_builder.h"

namespace ash {

class PlaceholderScreen;

// Interface for dependency injection between PlaceholderScreen and its
// WebUI representation.
class PlaceholderScreenView
: public base::SupportsWeakPtr<PlaceholderScreenView> {
public:
inline constexpr static StaticOobeScreenId kScreenId{"placeholder",
"PlaceholderScreen"};

virtual ~PlaceholderScreenView() = default;

// Shows the contents of the screen.
virtual void Show() = 0;
};

class PlaceholderScreenHandler : public BaseScreenHandler,
public PlaceholderScreenView {
public:
using TView = PlaceholderScreenView;

PlaceholderScreenHandler();

PlaceholderScreenHandler(const PlaceholderScreenHandler&) = delete;
PlaceholderScreenHandler& operator=(const PlaceholderScreenHandler&) = delete;

~PlaceholderScreenHandler() override;

// BaseScreenHandler:
void DeclareLocalizedValues(
::login::LocalizedValuesBuilder* builder) override;

// PlaceholderScreenView:
void Show() override;
};

} // namespace ash

#endif // CHROME_BROWSER_UI_WEBUI_ASH_LOGIN_PLACEHOLDER_SCREEN_HANDLER_H_
20 changes: 20 additions & 0 deletions tools/oobe/DIR_METADATA
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Metadata information for this directory.
#
# For more information on DIR_METADATA files, see:
# https://source.chromium.org/chromium/infra/infra/+/HEAD:go/src/infra/tools/dirmd/README.md
#
# For the schema of this file, see Metadata message:
# https://source.chromium.org/chromium/infra/infra/+/HEAD:go/src/infra/tools/dirmd/proto/dir_metadata.proto

# ChromeOS > Software > OOBE
buganizer {
component_id: 1263090
}

# ChromeOS Pubblic Tracker > UI > OOBE
buganizer_public {
component_id: 1263509
}

team_email: "cros-oobe@google.com"
os: CHROME_OS
2 changes: 2 additions & 0 deletions tools/oobe/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bohdanty@google.com
dkuzmin@google.com

0 comments on commit 82cca37

Please sign in to comment.