Commit 683075cc authored by Alexei Filippov's avatar Alexei Filippov Committed by Commit Bot

Revert "Mash cleanup: remove kiosk related mojos, replace with interface"

This reverts commit 4bace02d.

Reason for revert:
Broke compile step
https://ci.chromium.org/p/chrome/builders/ci/linux-chromeos-google-rel/2457

Original change's description:
> Mash cleanup: remove kiosk related mojos, replace with interface
> 
> This splits out the kiosk related mojos from the login controller
> interface, and removes kiosk_app_info.mojom. It also removes a couple
> methods from mojom::LoginScreenClient, replacing them with a single
> callback passed to the KioskAppMenu.
> 
> TBR=tsepez@chromium.org
> 
> Bug: 958206, 958204
> Change-Id: I59d38c83fc91397d1d0890c87f5b18fe23fac7d8
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1604333
> Reviewed-by: Evan Stade <estade@chromium.org>
> Reviewed-by: Tom Sepez <tsepez@chromium.org>
> Reviewed-by: James Cook <jamescook@chromium.org>
> Commit-Queue: Evan Stade <estade@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#659100}

TBR=jamescook@chromium.org,estade@chromium.org,tsepez@chromium.org

Change-Id: Ib88e0d99d4fea0f264affc56e146c3e292d7177b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 958206, 958204
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1610475Reviewed-by: default avatarAlexei Filippov <alph@chromium.org>
Commit-Queue: Alexei Filippov <alph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659170}
parent eb4075dd
......@@ -485,6 +485,16 @@ void LoginScreenController::SetPublicSessionShowFullManagementDisclosure(
}
}
void LoginScreenController::SetKioskApps(
std::vector<mojom::KioskAppInfoPtr> kiosk_apps,
SetKioskAppsCallback callback) {
Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
->shelf_widget()
->login_shelf_view()
->SetKioskApps(std::move(kiosk_apps));
std::move(callback).Run(true);
}
void LoginScreenController::ShowKioskAppError(const std::string& message) {
ToastData toast_data(
"KioskAppError", base::UTF8ToUTF16(message), -1 /*duration_ms*/,
......@@ -542,15 +552,6 @@ void LoginScreenController::FocusLoginShelf(bool reverse) {
}
}
void LoginScreenController::SetKioskApps(
const std::vector<KioskAppMenuEntry>& kiosk_apps,
const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app) {
Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
->shelf_widget()
->login_shelf_view()
->SetKioskApps(kiosk_apps, launch_app);
}
void LoginScreenController::SetAddUserButtonEnabled(bool enable) {
Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
->shelf_widget()
......@@ -565,6 +566,14 @@ void LoginScreenController::SetShutdownButtonEnabled(bool enable) {
->SetShutdownButtonEnabled(enable);
}
void LoginScreenController::LaunchKioskApp(const std::string& app_id) {
login_screen_client_->LaunchKioskApp(app_id);
}
void LoginScreenController::LaunchArcKioskApp(const AccountId& account_id) {
login_screen_client_->LaunchArcKioskApp(account_id);
}
void LoginScreenController::ShowResetScreen() {
login_screen_client_->ShowResetScreen();
}
......
......@@ -9,8 +9,8 @@
#include "ash/ash_export.h"
#include "ash/login/login_screen_controller_observer.h"
#include "ash/public/cpp/kiosk_app_menu.h"
#include "ash/public/cpp/system_tray_focus_observer.h"
#include "ash/public/interfaces/kiosk_app_info.mojom.h"
#include "ash/public/interfaces/login_screen.mojom.h"
#include "base/macros.h"
#include "base/observer_list.h"
......@@ -30,7 +30,6 @@ class SystemTrayNotifier;
// This could send requests to LoginScreenClient and also handle requests from
// LoginScreenClient through mojo.
class ASH_EXPORT LoginScreenController : public mojom::LoginScreen,
public KioskAppMenu,
public SystemTrayFocusObserver {
public:
// The current authentication stage. Used to get more verbose logging.
......@@ -96,6 +95,8 @@ class ASH_EXPORT LoginScreenController : public mojom::LoginScreen,
void RequestPublicSessionKeyboardLayouts(const AccountId& account_id,
const std::string& locale);
void ShowFeedback();
void LaunchKioskApp(const std::string& app_id);
void LaunchArcKioskApp(const AccountId& account_id);
void ShowResetScreen();
void ShowAccountAccessHelpApp();
void FocusOobeDialog();
......@@ -159,6 +160,8 @@ class ASH_EXPORT LoginScreenController : public mojom::LoginScreen,
std::vector<mojom::InputMethodItemPtr> keyboard_layouts) override;
void SetPublicSessionShowFullManagementDisclosure(
bool is_full_management_disclosure_needed) override;
void SetKioskApps(std::vector<mojom::KioskAppInfoPtr> kiosk_apps,
SetKioskAppsCallback callback) override;
void ShowKioskAppError(const std::string& message) override;
void NotifyOobeDialogState(mojom::OobeDialogState state) override;
void SetAddUserButtonEnabled(bool enable) override;
......@@ -169,12 +172,6 @@ class ASH_EXPORT LoginScreenController : public mojom::LoginScreen,
void SetShowParentAccessDialog(bool show) override;
void FocusLoginShelf(bool reverse) override;
// KioskAppMenu:
void SetKioskApps(
const std::vector<KioskAppMenuEntry>& kiosk_apps,
const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app)
override;
// Flushes the mojo pipes - to be used in tests.
void FlushForTesting();
......
......@@ -5,6 +5,7 @@
#ifndef ASH_LOGIN_MOCK_LOGIN_SCREEN_CLIENT_H_
#define ASH_LOGIN_MOCK_LOGIN_SCREEN_CLIENT_H_
#include "ash/public/interfaces/kiosk_app_info.mojom.h"
#include "ash/public/interfaces/login_screen.mojom.h"
#include "components/password_manager/core/browser/hash_password_manager.h"
#include "mojo/public/cpp/bindings/binding_set.h"
......@@ -101,6 +102,8 @@ class MockLoginScreenClient : public mojom::LoginScreenClient {
MOCK_METHOD2(RequestPublicSessionKeyboardLayouts,
void(const AccountId& account_id, const std::string& locale));
MOCK_METHOD0(ShowFeedback, void());
MOCK_METHOD1(LaunchKioskApp, void(const std::string& app_id));
MOCK_METHOD1(LaunchArcKioskApp, void(const AccountId& account_id));
MOCK_METHOD0(ShowResetScreen, void());
MOCK_METHOD0(ShowAccountAccessHelpApp, void());
MOCK_METHOD0(FocusOobeDialog, void());
......
......@@ -18,7 +18,7 @@
#include "ash/login/ui/login_detachable_base_model.h"
#include "ash/login/ui/non_accessible_view.h"
#include "ash/login/ui/views_utils.h"
#include "ash/public/cpp/kiosk_app_menu.h"
#include "ash/public/interfaces/kiosk_app_info.mojom.h"
#include "ash/shelf/login_shelf_view.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_widget.h"
......@@ -414,18 +414,19 @@ class LockDebugView::DebugDataDispatcherTransformer
}
void AddKioskApp(ShelfWidget* shelf_widget) {
KioskAppMenuEntry menu_item;
menu_item.app_id = kDebugKioskAppId;
menu_item.name = base::UTF8ToUTF16(kDebugKioskAppName);
kiosk_apps_.push_back(std::move(menu_item));
shelf_widget->login_shelf_view()->SetKioskApps(kiosk_apps_, {});
mojom::KioskAppInfoPtr app_info = mojom::KioskAppInfo::New();
app_info->identifier = mojom::KioskAppIdentifier::New();
app_info->identifier->set_app_id(kDebugKioskAppId);
app_info->name = base::UTF8ToUTF16(kDebugKioskAppName);
kiosk_apps_.push_back(std::move(app_info));
shelf_widget->login_shelf_view()->SetKioskApps(mojo::Clone(kiosk_apps_));
}
void RemoveKioskApp(ShelfWidget* shelf_widget) {
if (kiosk_apps_.empty())
return;
kiosk_apps_.pop_back();
shelf_widget->login_shelf_view()->SetKioskApps(kiosk_apps_, {});
shelf_widget->login_shelf_view()->SetKioskApps(mojo::Clone(kiosk_apps_));
}
void AddSystemInfo(const std::string& os_version,
......@@ -521,7 +522,7 @@ class LockDebugView::DebugDataDispatcherTransformer
mojom::TrayActionState lock_screen_note_state_;
// List of kiosk apps loaded.
std::vector<KioskAppMenuEntry> kiosk_apps_;
std::vector<mojom::KioskAppInfoPtr> kiosk_apps_;
// Called when a new user list has been received.
base::RepeatingClosure on_users_received_;
......
......@@ -79,8 +79,6 @@ component("cpp") {
"immersive/immersive_revealed_lock.cc",
"immersive/immersive_revealed_lock.h",
"keyboard_shortcut_viewer.h",
"kiosk_app_menu.cc",
"kiosk_app_menu.h",
"lock_screen_widget_factory.cc",
"lock_screen_widget_factory.h",
"login_constants.h",
......
// Copyright 2019 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 "ash/public/cpp/kiosk_app_menu.h"
namespace ash {
namespace {
KioskAppMenu* g_instance = nullptr;
}
KioskAppMenuEntry::KioskAppMenuEntry() = default;
KioskAppMenuEntry::KioskAppMenuEntry(const KioskAppMenuEntry& other) = default;
KioskAppMenuEntry::KioskAppMenuEntry(KioskAppMenuEntry&& other) = default;
KioskAppMenuEntry::~KioskAppMenuEntry() = default;
KioskAppMenuEntry& KioskAppMenuEntry::operator=(KioskAppMenuEntry&& other) =
default;
KioskAppMenuEntry& KioskAppMenuEntry::operator=(
const KioskAppMenuEntry& other) = default;
// static
KioskAppMenu* KioskAppMenu::Get() {
return g_instance;
}
KioskAppMenu::KioskAppMenu() {
DCHECK_EQ(nullptr, g_instance);
g_instance = this;
}
KioskAppMenu::~KioskAppMenu() {
DCHECK_EQ(this, g_instance);
g_instance = nullptr;
}
} // namespace ash
// Copyright 2019 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 ASH_PUBLIC_CPP_KIOSK_APP_MENU_H_
#define ASH_PUBLIC_CPP_KIOSK_APP_MENU_H_
#include <string>
#include <vector>
#include "ash/public/cpp/ash_public_export.h"
#include "base/callback_forward.h"
#include "base/strings/string16.h"
#include "components/account_id/account_id.h"
#include "ui/gfx/image/image_skia.h"
namespace ash {
// Metadata about a kiosk app. Used for display in the kiosk app menu in the
// login screen shelf.
struct ASH_PUBLIC_EXPORT KioskAppMenuEntry {
KioskAppMenuEntry();
KioskAppMenuEntry(const KioskAppMenuEntry& other);
KioskAppMenuEntry(KioskAppMenuEntry&& other);
~KioskAppMenuEntry();
KioskAppMenuEntry& operator=(KioskAppMenuEntry&& other);
KioskAppMenuEntry& operator=(const KioskAppMenuEntry& other);
// For Chrome kiosk apps only, the extension app id.
std::string app_id;
// For ARC kiosk apps only, the account id for the app.
AccountId account_id;
base::string16 name;
gfx::ImageSkia icon;
};
// An interface implemented by Ash to allow Chrome to control the kiosk app
// menu, which appears in the login shelf.
class ASH_PUBLIC_EXPORT KioskAppMenu {
public:
// Returns the singleton instance.
static KioskAppMenu* Get();
// Update the kiosk app data. |launch_app| will be called if the user selects
// an item (app) from the menu.
virtual void SetKioskApps(
const std::vector<KioskAppMenuEntry>& kiosk_apps,
const base::RepeatingCallback<void(const KioskAppMenuEntry&)>&
launch_app) = 0;
protected:
KioskAppMenu();
virtual ~KioskAppMenu();
};
} // namespace ash
#endif // ASH_PUBLIC_CPP_KIOSK_APP_MENU_H_
......@@ -38,6 +38,7 @@ mojom("interfaces_internal") {
"ime_controller.mojom",
"ime_info.mojom",
"keyboard_controller.mojom",
"kiosk_app_info.mojom",
"kiosk_next_shell.mojom",
"locale.mojom",
"login_screen.mojom",
......
// 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.
module ash.mojom;
import "components/account_id/interfaces/account_id.mojom";
import "mojo/public/mojom/base/string16.mojom";
import "ui/gfx/image/mojo/image.mojom";
union KioskAppIdentifier {
// For chrome kiosk apps only, the extension app id.
string app_id;
// For ARC kiosk apps only, the account id for the app.
signin.mojom.AccountId account_id;
};
// Metadata about a kiosk app. Used for display in the kiosk app menu in the
// login screen shelf.
struct KioskAppInfo {
KioskAppIdentifier identifier;
mojo_base.mojom.String16 name;
gfx.mojom.ImageSkia icon;
};
\ No newline at end of file
......@@ -6,6 +6,7 @@ module ash.mojom;
import "ash/public/interfaces/user_info.mojom";
import "ash/public/interfaces/login_user_info.mojom";
import "ash/public/interfaces/kiosk_app_info.mojom";
import "chromeos/components/proximity_auth/public/interfaces/auth_type.mojom";
import "components/account_id/interfaces/account_id.mojom";
import "mojo/public/mojom/base/string16.mojom";
......@@ -217,6 +218,10 @@ interface LoginScreen {
SetPublicSessionShowFullManagementDisclosure(
bool show_full_management_disclosure);
// Update the kiosk app data for the login screen.
// Returns true on success.
SetKioskApps(array<KioskAppInfo> kiosk_apps) => (bool success);
// Display a toast describing the latest kiosk app launch error.
ShowKioskAppError(string message);
......@@ -360,6 +365,12 @@ interface LoginScreenClient {
// Request to show a feedback report dialog in chrome.
ShowFeedback();
// Launch the specific kiosk app.
LaunchKioskApp(string app_id);
// Launch the specific ARC++ kiosk app.
LaunchArcKioskApp(signin.mojom.AccountId account_id);
// Show the powerwash (device reset) dialog.
ShowResetScreen();
......
......@@ -265,27 +265,25 @@ class KioskAppsButton : public views::MenuButton,
bool LaunchAppForTesting(const std::string& app_id) {
for (size_t i = 0; i < kiosk_apps_.size(); ++i) {
if (kiosk_apps_[i].app_id == app_id) {
ExecuteCommand(i, 0);
return true;
}
if (kiosk_apps_[i]->identifier->get_app_id() != app_id)
continue;
ExecuteCommand(i, 0);
return true;
}
return false;
}
// Replace the existing items list with a new list of kiosk app menu items.
void SetApps(const std::vector<KioskAppMenuEntry>& kiosk_apps,
const base::RepeatingCallback<void(const KioskAppMenuEntry&)>&
launch_app) {
launch_app_callback_ = launch_app;
kiosk_apps_ = kiosk_apps;
void SetApps(std::vector<mojom::KioskAppInfoPtr> kiosk_apps) {
kiosk_apps_ = std::move(kiosk_apps);
Clear();
const gfx::Size kAppIconSize(16, 16);
for (size_t i = 0; i < kiosk_apps_.size(); ++i) {
gfx::ImageSkia icon = gfx::ImageSkiaOperations::CreateResizedImage(
kiosk_apps_[i].icon, skia::ImageOperations::RESIZE_GOOD,
kiosk_apps_[i]->icon, skia::ImageOperations::RESIZE_GOOD,
kAppIconSize);
AddItemWithIcon(i, kiosk_apps_[i].name, icon);
AddItemWithIcon(i, kiosk_apps_[i]->name, icon);
}
}
......@@ -361,7 +359,20 @@ class KioskAppsButton : public views::MenuButton,
// the state is reset (when login screen reappears).
is_launch_enabled_ = false;
launch_app_callback_.Run(kiosk_apps_[command_id]);
const mojom::KioskAppInfoPtr& kiosk_app = kiosk_apps_[command_id];
switch (kiosk_app->identifier->which()) {
case mojom::KioskAppIdentifier::Tag::ACCOUNT_ID:
Shell::Get()->login_screen_controller()->LaunchArcKioskApp(
kiosk_app->identifier->get_account_id());
return;
case mojom::KioskAppIdentifier::Tag::APP_ID:
Shell::Get()->login_screen_controller()->LaunchKioskApp(
kiosk_app->identifier->get_app_id());
return;
default:
NOTREACHED();
}
}
bool IsCommandIdChecked(int command_id) const override { return false; }
......@@ -369,9 +380,8 @@ class KioskAppsButton : public views::MenuButton,
bool IsCommandIdEnabled(int command_id) const override { return true; }
private:
base::RepeatingCallback<void(const KioskAppMenuEntry&)> launch_app_callback_;
std::unique_ptr<views::MenuRunner> menu_runner_;
std::vector<KioskAppMenuEntry> kiosk_apps_;
std::vector<mojom::KioskAppInfoPtr> kiosk_apps_;
bool is_launch_enabled_ = true;
DISALLOW_COPY_AND_ASSIGN(KioskAppsButton);
......@@ -538,9 +548,8 @@ void LoginShelfView::InstallTestUiUpdateDelegate(
}
void LoginShelfView::SetKioskApps(
const std::vector<KioskAppMenuEntry>& kiosk_apps,
const base::RepeatingCallback<void(const KioskAppMenuEntry&)>& launch_app) {
kiosk_apps_button_->SetApps(kiosk_apps, launch_app);
std::vector<mojom::KioskAppInfoPtr> kiosk_apps) {
kiosk_apps_button_->SetApps(std::move(kiosk_apps));
UpdateUi();
}
......
......@@ -13,7 +13,7 @@
#include "ash/lock_screen_action/lock_screen_action_background_observer.h"
#include "ash/login/login_screen_controller_observer.h"
#include "ash/login/ui/login_data_dispatcher.h"
#include "ash/public/cpp/kiosk_app_menu.h"
#include "ash/public/interfaces/kiosk_app_info.mojom.h"
#include "ash/public/interfaces/login_screen.mojom.h"
#include "ash/shutdown_controller.h"
#include "ash/system/locale/locale_update_controller.h"
......@@ -80,12 +80,8 @@ class ASH_EXPORT LoginShelfView : public views::View,
// then notifies LoginShelfView to update its own UI.
void UpdateAfterSessionChange();
// Sets the contents of the kiosk app menu, as well as the callback used when
// a menu item is selected.
void SetKioskApps(
const std::vector<KioskAppMenuEntry>& kiosk_apps,
const base::RepeatingCallback<void(const KioskAppMenuEntry&)>&
launch_app);
// Sets the list of kiosk apps that can be launched from the login shelf.
void SetKioskApps(std::vector<mojom::KioskAppInfoPtr> kiosk_apps);
// Sets the state of the login dialog.
void SetLoginDialogState(mojom::OobeDialogState state);
......@@ -192,9 +188,7 @@ class ASH_EXPORT LoginShelfView : public views::View,
ScopedObserver<LocaleUpdateController, LocaleChangeObserver>
locale_change_observer_{this};
// The kiosk app button will only be created for the primary display's login
// shelf.
KioskAppsButton* kiosk_apps_button_ = nullptr;
KioskAppsButton* kiosk_apps_button_ = nullptr; // Owned by view hierarchy
// This is used in tests to wait until UI is updated.
std::unique_ptr<TestUiUpdateDelegate> test_ui_update_delegate_;
......
......@@ -14,7 +14,7 @@
#include "ash/login/mock_login_screen_client.h"
#include "ash/login/ui/login_test_base.h"
#include "ash/login/ui/views_utils.h"
#include "ash/public/cpp/kiosk_app_menu.h"
#include "ash/public/interfaces/kiosk_app_info.mojom.h"
#include "ash/root_window_controller.h"
#include "ash/session/session_controller_impl.h"
#include "ash/session/test_session_controller_client.h"
......@@ -264,13 +264,15 @@ TEST_F(LoginShelfViewTest, ShouldUpdateUiAfterKioskAppsLoaded) {
LoginShelfView::kBrowseAsGuest,
LoginShelfView::kAddUser}));
std::vector<KioskAppMenuEntry> kiosk_apps(2);
login_shelf_view_->SetKioskApps(kiosk_apps, {});
std::vector<mojom::KioskAppInfoPtr> kiosk_apps;
kiosk_apps.push_back(mojom::KioskAppInfo::New());
kiosk_apps.push_back(mojom::KioskAppInfo::New());
login_shelf_view_->SetKioskApps(std::move(kiosk_apps));
EXPECT_TRUE(ShowsShelfButtons(
{LoginShelfView::kShutdown, LoginShelfView::kBrowseAsGuest,
LoginShelfView::kAddUser, LoginShelfView::kApps}));
login_shelf_view_->SetKioskApps({}, {});
login_shelf_view_->SetKioskApps(std::vector<mojom::KioskAppInfoPtr>());
EXPECT_TRUE(ShowsShelfButtons({LoginShelfView::kShutdown,
LoginShelfView::kBrowseAsGuest,
LoginShelfView::kAddUser}));
......@@ -347,8 +349,9 @@ TEST_F(LoginShelfViewTest, ShouldUpdateUiAfterDialogStateChange) {
// Kiosk app button is visible when dialog state == OobeDialogState::HIDDEN
// or GAIA_SIGNIN.
login_shelf_view_->SetLoginDialogState(mojom::OobeDialogState::GAIA_SIGNIN);
std::vector<KioskAppMenuEntry> kiosk_apps(1);
login_shelf_view_->SetKioskApps(kiosk_apps, {});
std::vector<mojom::KioskAppInfoPtr> kiosk_apps;
kiosk_apps.push_back(mojom::KioskAppInfo::New());
login_shelf_view_->SetKioskApps(std::move(kiosk_apps));
EXPECT_TRUE(
ShowsShelfButtons({LoginShelfView::kShutdown, LoginShelfView::kApps}));
......@@ -362,7 +365,7 @@ TEST_F(LoginShelfViewTest, ShouldUpdateUiAfterDialogStateChange) {
LoginShelfView::kApps}));
// Kiosk app button is hidden when no app exists.
login_shelf_view_->SetKioskApps({}, {});
login_shelf_view_->SetKioskApps(std::vector<mojom::KioskAppInfoPtr>());
EXPECT_TRUE(
ShowsShelfButtons({LoginShelfView::kShutdown, LoginShelfView::kAddUser}));
}
......
......@@ -1373,8 +1373,8 @@ source_set("chromeos") {
"login/ui/captive_portal_window_proxy.h",
"login/ui/input_events_blocker.cc",
"login/ui/input_events_blocker.h",
"login/ui/kiosk_app_menu_controller.cc",
"login/ui/kiosk_app_menu_controller.h",
"login/ui/kiosk_app_menu_updater.cc",
"login/ui/kiosk_app_menu_updater.h",
"login/ui/login_display.cc",
"login/ui/login_display.h",
"login/ui/login_display_host.cc",
......
......@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/login/ui/kiosk_app_menu_controller.h"
#include "chrome/browser/chromeos/login/ui/kiosk_app_menu_updater.h"
#include <utility>
#include "ash/public/cpp/kiosk_app_menu.h"
#include "ash/public/interfaces/kiosk_app_info.mojom.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/app_mode/arc/arc_kiosk_app_data.h"
......@@ -14,7 +14,6 @@
#include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h"
#include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
#include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h"
#include "chrome/browser/chromeos/login/ui/login_display_host.h"
#include "chrome/browser/ui/ash/login_screen_client.h"
#include "content/public/browser/notification_service.h"
#include "extensions/grit/extensions_browser_resources.h"
......@@ -23,74 +22,82 @@
namespace chromeos {
KioskAppMenuController::KioskAppMenuController() {
KioskAppMenuUpdater::KioskAppMenuUpdater()
: kiosk_observer_(this), arc_kiosk_observer_(this) {
kiosk_observer_.Add(KioskAppManager::Get());
arc_kiosk_observer_.Add(ArcKioskAppManager::Get());
}
KioskAppMenuController::~KioskAppMenuController() = default;
KioskAppMenuUpdater::~KioskAppMenuUpdater() = default;
void KioskAppMenuController::OnKioskAppDataChanged(const std::string& app_id) {
void KioskAppMenuUpdater::OnKioskAppDataChanged(const std::string& app_id) {
SendKioskApps();
}
void KioskAppMenuController::OnKioskAppDataLoadFailure(
const std::string& app_id) {
void KioskAppMenuUpdater::OnKioskAppDataLoadFailure(const std::string& app_id) {
SendKioskApps();
}
void KioskAppMenuController::OnKioskAppsSettingsChanged() {
void KioskAppMenuUpdater::OnKioskAppsSettingsChanged() {
SendKioskApps();
}
void KioskAppMenuController::OnArcKioskAppsChanged() {
void KioskAppMenuUpdater::OnArcKioskAppsChanged() {
SendKioskApps();
}
void KioskAppMenuController::SendKioskApps() {
void KioskAppMenuUpdater::OnKioskAppsSet(bool success) {
if (!success)
return;
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_KIOSK_APPS_LOADED,
content::NotificationService::AllSources(),
content::NotificationService::NoDetails());
}
void KioskAppMenuUpdater::SendKioskApps() {
if (!LoginScreenClient::HasInstance())
return;
std::vector<ash::KioskAppMenuEntry> output;
std::vector<ash::mojom::KioskAppInfoPtr> output;
std::vector<KioskAppManager::App> apps;
KioskAppManager::Get()->GetApps(&apps);
for (const auto& app : apps) {
ash::KioskAppMenuEntry menu_entry;
menu_entry.app_id = app.app_id;
menu_entry.name = base::UTF8ToUTF16(app.name);
auto mojo_app = ash::mojom::KioskAppInfo::New();
mojo_app->identifier = ash::mojom::KioskAppIdentifier::New();
mojo_app->identifier->set_app_id(app.app_id);
mojo_app->name = base::UTF8ToUTF16(app.name);
if (app.icon.isNull()) {
menu_entry.icon = *ui::ResourceBundle::GetSharedInstance()
.GetImageNamed(IDR_APP_DEFAULT_ICON)
.ToImageSkia();
mojo_app->icon = *ui::ResourceBundle::GetSharedInstance()
.GetImageNamed(IDR_APP_DEFAULT_ICON)
.ToImageSkia();
} else {
menu_entry.icon = app.icon;
mojo_app->icon = gfx::ImageSkia(app.icon);
}
output.push_back(std::move(menu_entry));
output.push_back(std::move(mojo_app));
}
std::vector<ArcKioskAppData*> arc_apps;
ArcKioskAppManager::Get()->GetAllApps(&arc_apps);
for (ArcKioskAppData* app : arc_apps) {
ash::KioskAppMenuEntry menu_entry;
menu_entry.account_id = app->account_id();
menu_entry.name = base::UTF8ToUTF16(app->name());
auto mojo_app = ash::mojom::KioskAppInfo::New();
mojo_app->identifier = ash::mojom::KioskAppIdentifier::New();
mojo_app->identifier->set_account_id(app->account_id());
mojo_app->name = base::UTF8ToUTF16(app->name());
if (app->icon().isNull()) {
menu_entry.icon = *ui::ResourceBundle::GetSharedInstance()
.GetImageNamed(IDR_APP_DEFAULT_ICON)
.ToImageSkia();
mojo_app->icon = *ui::ResourceBundle::GetSharedInstance()
.GetImageNamed(IDR_APP_DEFAULT_ICON)
.ToImageSkia();
} else {
menu_entry.icon = app->icon();
mojo_app->icon = gfx::ImageSkia(app->icon());
}
output.push_back(std::move(menu_entry));
output.push_back(std::move(mojo_app));
}
ash::KioskAppMenu::Get()->SetKioskApps(
output, base::BindRepeating(&KioskAppMenuController::LaunchApp,
weak_factory_.GetWeakPtr()));
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_KIOSK_APPS_LOADED,
content::NotificationService::AllSources(),
content::NotificationService::NoDetails());
LoginScreenClient::Get()->login_screen()->SetKioskApps(
std::move(output), base::BindOnce(&KioskAppMenuUpdater::OnKioskAppsSet,
weak_factory_.GetWeakPtr()));
KioskAppLaunchError::Error error = KioskAppLaunchError::Get();
if (error == KioskAppLaunchError::NONE)
......@@ -103,14 +110,4 @@ void KioskAppMenuController::SendKioskApps() {
KioskAppLaunchError::GetErrorMessage(error));
}
void KioskAppMenuController::LaunchApp(const ash::KioskAppMenuEntry& app) {
auto* host = chromeos::LoginDisplayHost::default_host();
if (!app.app_id.empty())
host->StartAppLaunch(app.app_id, false, false);
else if (app.account_id.is_valid())
host->StartArcKiosk(app.account_id);
else
NOTREACHED();
}
} // namespace chromeos
......@@ -2,10 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_UI_KIOSK_APP_MENU_CONTROLLER_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_UI_KIOSK_APP_MENU_CONTROLLER_H_
#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_UI_KIOSK_APP_MENU_UPDATER_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_UI_KIOSK_APP_MENU_UPDATER_H_
#include "ash/public/cpp/kiosk_app_menu.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
......@@ -16,12 +15,12 @@
namespace chromeos {
// Observer class to update the Kiosk app menu when Kiosk app data is changed.
class KioskAppMenuController
class KioskAppMenuUpdater
: public KioskAppManagerObserver,
public ArcKioskAppManager::ArcKioskAppManagerObserver {
public:
KioskAppMenuController();
~KioskAppMenuController() override;
KioskAppMenuUpdater();
~KioskAppMenuUpdater() override;
// Manually dispatch kiosk app data to Ash.
void SendKioskApps();
......@@ -35,17 +34,17 @@ class KioskAppMenuController
void OnArcKioskAppsChanged() override;
private:
void LaunchApp(const ash::KioskAppMenuEntry& app);
// Mojo SendKioskApps() callback.
void OnKioskAppsSet(bool success);
ScopedObserver<KioskAppManager, KioskAppMenuController> kiosk_observer_{this};
ScopedObserver<ArcKioskAppManager, KioskAppMenuController>
arc_kiosk_observer_{this};
ScopedObserver<KioskAppManager, KioskAppMenuUpdater> kiosk_observer_;
ScopedObserver<ArcKioskAppManager, KioskAppMenuUpdater> arc_kiosk_observer_;
base::WeakPtrFactory<KioskAppMenuController> weak_factory_{this};
base::WeakPtrFactory<KioskAppMenuUpdater> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(KioskAppMenuController);
DISALLOW_COPY_AND_ASSIGN(KioskAppMenuUpdater);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_UI_KIOSK_APP_MENU_CONTROLLER_H_
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_UI_KIOSK_APP_MENU_UPDATER_H_
......@@ -269,7 +269,7 @@ void LoginDisplayHostCommon::ShutdownDisplayHost() {
}
void LoginDisplayHostCommon::OnStartSignInScreenCommon() {
kiosk_app_menu_controller_.SendKioskApps();
kiosk_updater_.SendKioskApps();
}
void LoginDisplayHostCommon::ShowGaiaDialogCommon(
......
......@@ -9,7 +9,7 @@
#include <string>
#include <vector>
#include "chrome/browser/chromeos/login/ui/kiosk_app_menu_controller.h"
#include "chrome/browser/chromeos/login/ui/kiosk_app_menu_updater.h"
#include "chrome/browser/chromeos/login/ui/login_display_host.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
......@@ -113,7 +113,7 @@ class LoginDisplayHostCommon : public LoginDisplayHost,
// Called after host deletion.
std::vector<base::OnceClosure> completion_callbacks_;
KioskAppMenuController kiosk_app_menu_controller_;
KioskAppMenuUpdater kiosk_updater_;
base::WeakPtrFactory<LoginDisplayHostCommon> weak_factory_;
......
......@@ -28,6 +28,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
#include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
#include "chrome/browser/chromeos/base/locale_util.h"
#include "chrome/browser/chromeos/boot_times_recorder.h"
#include "chrome/browser/chromeos/first_run/drive_first_run_controller.h"
......
......@@ -17,6 +17,7 @@
#include "chrome/browser/chromeos/login/existing_user_controller.h"
#include "chrome/browser/chromeos/login/oobe_configuration.h"
#include "chrome/browser/chromeos/login/signin_screen_controller.h"
#include "chrome/browser/chromeos/login/ui/kiosk_app_menu_updater.h"
#include "chrome/browser/chromeos/login/ui/login_display.h"
#include "chrome/browser/chromeos/login/ui/login_display_host_common.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
......@@ -272,6 +273,9 @@ class LoginDisplayHostWebUI : public LoginDisplayHostCommon,
// True if we need to play startup sound when audio device becomes available.
bool need_to_play_startup_sound_ = false;
// Updates shelf kiosk app list.
KioskAppMenuUpdater kiosk_updater_;
base::WeakPtrFactory<LoginDisplayHostWebUI> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(LoginDisplayHostWebUI);
......
......@@ -218,6 +218,15 @@ void LoginScreenClient::ShowFeedback() {
chromeos::LoginDisplayHost::default_host()->ShowFeedback();
}
void LoginScreenClient::LaunchKioskApp(const std::string& app_id) {
chromeos::LoginDisplayHost::default_host()->StartAppLaunch(app_id, false,
false);
}
void LoginScreenClient::LaunchArcKioskApp(const AccountId& account_id) {
chromeos::LoginDisplayHost::default_host()->StartArcKiosk(account_id);
}
void LoginScreenClient::ShowResetScreen() {
chromeos::LoginDisplayHost::default_host()->ShowResetScreen();
}
......
......@@ -125,6 +125,8 @@ class LoginScreenClient : public ash::mojom::LoginScreenClient {
void RequestPublicSessionKeyboardLayouts(const AccountId& account_id,
const std::string& locale) override;
void ShowFeedback() override;
void LaunchKioskApp(const std::string& app_id) override;
void LaunchArcKioskApp(const AccountId& account_id) override;
void ShowResetScreen() override;
void ShowAccountAccessHelpApp() override;
void OnFocusLeavingSystemTray(bool reverse) override;
......
......@@ -113,6 +113,10 @@ void TestLoginScreen::SetPublicSessionKeyboardLayouts(
void TestLoginScreen::SetPublicSessionShowFullManagementDisclosure(
bool show_full_management_disclosure) {}
void TestLoginScreen::SetKioskApps(
std::vector<::ash::mojom::KioskAppInfoPtr> kiosk_apps,
SetKioskAppsCallback callback) {}
void TestLoginScreen::ShowKioskAppError(const std::string& message) {}
void TestLoginScreen::NotifyOobeDialogState(ash::mojom::OobeDialogState state) {
......
......@@ -74,6 +74,8 @@ class TestLoginScreen : public ash::mojom::LoginScreen {
std::vector<::ash::mojom::InputMethodItemPtr> keyboard_layouts) override;
void SetPublicSessionShowFullManagementDisclosure(
bool show_full_management_disclosure) override;
void SetKioskApps(std::vector<::ash::mojom::KioskAppInfoPtr> kiosk_apps,
SetKioskAppsCallback callback) override;
void ShowKioskAppError(const std::string& message) override;
void NotifyOobeDialogState(ash::mojom::OobeDialogState state) override;
void SetAddUserButtonEnabled(bool enable) override;
......
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