Commit 2d8fd1e8 authored by wutao's avatar wutao Committed by Commit Bot

assistant: Add web view container

In embedded Assistant UI experiment, we will move the web view to its
own container.

This cl is the first part to add the container. A follow up cl will
handle the back arrow.

Bug: b/141268413
Test: new unittest
Change-Id: I9d3b9663b7a60f02e9f50e0076d9c342c299d8f9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1837294
Commit-Queue: Tao Wu <wutao@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707946}
parent 74ce1079
...@@ -209,6 +209,8 @@ component("ash") { ...@@ -209,6 +209,8 @@ component("ash") {
"assistant/assistant_ui_controller.h", "assistant/assistant_ui_controller.h",
"assistant/assistant_view_delegate_impl.cc", "assistant/assistant_view_delegate_impl.cc",
"assistant/assistant_view_delegate_impl.h", "assistant/assistant_view_delegate_impl.h",
"assistant/assistant_web_ui_controller.cc",
"assistant/assistant_web_ui_controller.h",
"autoclick/autoclick_controller.cc", "autoclick/autoclick_controller.cc",
"autoclick/autoclick_controller.h", "autoclick/autoclick_controller.h",
"autoclick/autoclick_drag_event_rewriter.cc", "autoclick/autoclick_drag_event_rewriter.cc",
...@@ -1672,6 +1674,7 @@ test("ash_unittests") { ...@@ -1672,6 +1674,7 @@ test("ash_unittests") {
"assistant/assistant_state_controller_unittest.cc", "assistant/assistant_state_controller_unittest.cc",
"assistant/model/assistant_query_history_unittest.cc", "assistant/model/assistant_query_history_unittest.cc",
"assistant/ui/assistant_container_view_unittest.cc", "assistant/ui/assistant_container_view_unittest.cc",
"assistant/ui/assistant_web_container_view_unittest.cc",
"assistant/util/deep_link_util_unittest.cc", "assistant/util/deep_link_util_unittest.cc",
"autoclick/autoclick_drag_event_rewriter_unittest.cc", "autoclick/autoclick_drag_event_rewriter_unittest.cc",
"autoclick/autoclick_unittest.cc", "autoclick/autoclick_unittest.cc",
...@@ -2017,6 +2020,7 @@ test("ash_unittests") { ...@@ -2017,6 +2020,7 @@ test("ash_unittests") {
# TODO(https://crbug.com/644355): Remove Shill dependencies. # TODO(https://crbug.com/644355): Remove Shill dependencies.
"//chromeos/network:test_support", "//chromeos/network:test_support",
"//chromeos/services/assistant:test_support", "//chromeos/services/assistant:test_support",
"//chromeos/services/assistant/public:feature_flags",
"//chromeos/services/assistant/public/cpp:prefs", "//chromeos/services/assistant/public/cpp:prefs",
"//chromeos/services/assistant/public/mojom", "//chromeos/services/assistant/public/mojom",
"//chromeos/services/multidevice_setup/public/cpp:test_support", "//chromeos/services/multidevice_setup/public/cpp:test_support",
......
...@@ -118,6 +118,7 @@ component("app_list") { ...@@ -118,6 +118,7 @@ component("app_list") {
"//base/third_party/dynamic_annotations", "//base/third_party/dynamic_annotations",
"//cc/paint", "//cc/paint",
"//chromeos:chromeos", "//chromeos:chromeos",
"//chromeos/services/assistant/public:feature_flags",
"//components/keyed_service/core", "//components/keyed_service/core",
"//components/sync", "//components/sync",
"//mojo/public/cpp/bindings", "//mojo/public/cpp/bindings",
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "ash/public/cpp/view_shadow.h" #include "ash/public/cpp/view_shadow.h"
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chromeos/services/assistant/public/features.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/chromeos/search_box/search_box_constants.h" #include "ui/chromeos/search_box/search_box_constants.h"
#include "ui/views/background.h" #include "ui/views/background.h"
...@@ -78,12 +79,14 @@ void AssistantPageView::InitLayout() { ...@@ -78,12 +79,14 @@ void AssistantPageView::InitLayout() {
SetLayoutManager(std::make_unique<views::FillLayout>()); SetLayoutManager(std::make_unique<views::FillLayout>());
if (assistant_view_delegate_) { if (assistant_view_delegate_) {
assistant_main_view_ = new AssistantMainView(assistant_view_delegate_); assistant_main_view_ = AddChildView(
AddChildView(assistant_main_view_); std::make_unique<AssistantMainView>(assistant_view_delegate_));
// Web view. // Do not add web view when Assistant web container is enabled.
assistant_web_view_ = new AssistantWebView(assistant_view_delegate_); if (!chromeos::assistant::features::IsAssistantWebContainerEnabled()) {
AddChildView(assistant_web_view_); assistant_web_view_ = AddChildView(
std::make_unique<AssistantWebView>(assistant_view_delegate_));
}
// Update the view state based on the current UI mode. // Update the view state based on the current UI mode.
OnUiModeChanged(assistant_view_delegate_->GetUiModel()->ui_mode(), OnUiModeChanged(assistant_view_delegate_->GetUiModel()->ui_mode(),
...@@ -129,8 +132,12 @@ void AssistantPageView::RequestFocus() { ...@@ -129,8 +132,12 @@ void AssistantPageView::RequestFocus() {
assistant_main_view_->RequestFocus(); assistant_main_view_->RequestFocus();
break; break;
case AssistantUiMode::kWebUi: case AssistantUiMode::kWebUi:
if (assistant_web_view_) if (!chromeos::assistant::features::IsAssistantWebContainerEnabled()) {
assistant_web_view_->RequestFocus(); if (assistant_web_view_)
assistant_web_view_->RequestFocus();
break;
}
NOTREACHED();
break; break;
case AssistantUiMode::kMainUi: case AssistantUiMode::kMainUi:
case AssistantUiMode::kMiniUi: case AssistantUiMode::kMiniUi:
...@@ -249,8 +256,12 @@ void AssistantPageView::OnUiModeChanged(AssistantUiMode ui_mode, ...@@ -249,8 +256,12 @@ void AssistantPageView::OnUiModeChanged(AssistantUiMode ui_mode,
assistant_main_view_->SetVisible(true); assistant_main_view_->SetVisible(true);
break; break;
case AssistantUiMode::kWebUi: case AssistantUiMode::kWebUi:
if (assistant_web_view_) if (!chromeos::assistant::features::IsAssistantWebContainerEnabled()) {
assistant_web_view_->SetVisible(true); if (assistant_web_view_)
assistant_web_view_->SetVisible(true);
break;
}
NOTREACHED();
break; break;
case AssistantUiMode::kMainUi: case AssistantUiMode::kMainUi:
case AssistantUiMode::kMiniUi: case AssistantUiMode::kMiniUi:
...@@ -296,8 +307,12 @@ int AssistantPageView::GetChildViewHeightForWidth(int width) const { ...@@ -296,8 +307,12 @@ int AssistantPageView::GetChildViewHeightForWidth(int width) const {
height = assistant_main_view_->GetHeightForWidth(width); height = assistant_main_view_->GetHeightForWidth(width);
break; break;
case AssistantUiMode::kWebUi: case AssistantUiMode::kWebUi:
if (assistant_web_view_) if (!chromeos::assistant::features::IsAssistantWebContainerEnabled()) {
height = assistant_web_view_->GetHeightForWidth(width); if (assistant_web_view_)
height = assistant_web_view_->GetHeightForWidth(width);
break;
}
NOTREACHED();
break; break;
case AssistantUiMode::kMainUi: case AssistantUiMode::kMainUi:
case AssistantUiMode::kMiniUi: case AssistantUiMode::kMiniUi:
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <utility> #include <utility>
#include "ash/accessibility/accessibility_controller_impl.h" #include "ash/accessibility/accessibility_controller_impl.h"
#include "ash/assistant/assistant_web_ui_controller.h"
#include "ash/assistant/util/deep_link_util.h" #include "ash/assistant/util/deep_link_util.h"
#include "ash/public/cpp/android_intent_helper.h" #include "ash/public/cpp/android_intent_helper.h"
#include "ash/public/cpp/ash_pref_names.h" #include "ash/public/cpp/ash_pref_names.h"
...@@ -20,6 +21,7 @@ ...@@ -20,6 +21,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "chromeos/services/assistant/public/cpp/assistant_prefs.h" #include "chromeos/services/assistant/public/cpp/assistant_prefs.h"
#include "chromeos/services/assistant/public/features.h"
#include "chromeos/services/assistant/public/mojom/assistant.mojom.h" #include "chromeos/services/assistant/public/mojom/assistant.mojom.h"
#include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_registry_simple.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
...@@ -33,6 +35,11 @@ ...@@ -33,6 +35,11 @@
namespace ash { namespace ash {
AssistantController::AssistantController() { AssistantController::AssistantController() {
if (chromeos::assistant::features::IsAssistantWebContainerEnabled()) {
assistant_web_ui_controller_ =
std::make_unique<AssistantWebUiController>(this);
}
assistant_state_controller_.AddObserver(this); assistant_state_controller_.AddObserver(this);
chromeos::CrasAudioHandler::Get()->AddAudioObserver(this); chromeos::CrasAudioHandler::Get()->AddAudioObserver(this);
AddObserver(this); AddObserver(this);
......
...@@ -51,6 +51,7 @@ class AssistantSetupController; ...@@ -51,6 +51,7 @@ class AssistantSetupController;
class AssistantStateController; class AssistantStateController;
class AssistantSuggestionsController; class AssistantSuggestionsController;
class AssistantUiController; class AssistantUiController;
class AssistantWebUiController;
class ASH_EXPORT AssistantController class ASH_EXPORT AssistantController
: public chromeos::assistant::mojom::AssistantController, : public chromeos::assistant::mojom::AssistantController,
...@@ -145,6 +146,10 @@ class ASH_EXPORT AssistantController ...@@ -145,6 +146,10 @@ class ASH_EXPORT AssistantController
AssistantUiController* ui_controller() { return &assistant_ui_controller_; } AssistantUiController* ui_controller() { return &assistant_ui_controller_; }
AssistantWebUiController* web_ui_controller() {
return assistant_web_ui_controller_.get();
}
AssistantViewDelegate* view_delegate() { return &view_delegate_; } AssistantViewDelegate* view_delegate() { return &view_delegate_; }
bool IsAssistantReady() const; bool IsAssistantReady() const;
...@@ -202,6 +207,7 @@ class ASH_EXPORT AssistantController ...@@ -202,6 +207,7 @@ class ASH_EXPORT AssistantController
AssistantSetupController assistant_setup_controller_{this}; AssistantSetupController assistant_setup_controller_{this};
AssistantSuggestionsController assistant_suggestions_controller_{this}; AssistantSuggestionsController assistant_suggestions_controller_{this};
AssistantUiController assistant_ui_controller_{this}; AssistantUiController assistant_ui_controller_{this};
std::unique_ptr<AssistantWebUiController> assistant_web_ui_controller_;
AssistantViewDelegateImpl view_delegate_{this}; AssistantViewDelegateImpl view_delegate_{this};
......
...@@ -396,6 +396,11 @@ void AssistantUiController::OnAssistantControllerDestroying() { ...@@ -396,6 +396,11 @@ void AssistantUiController::OnAssistantControllerDestroying() {
void AssistantUiController::OnDeepLinkReceived( void AssistantUiController::OnDeepLinkReceived(
assistant::util::DeepLinkType type, assistant::util::DeepLinkType type,
const std::map<std::string, std::string>& params) { const std::map<std::string, std::string>& params) {
// This method only handles web deep links, which will be handled separately
// in |AssistantWebUiController| when Assistant web container is enabled.
if (chromeos::assistant::features::IsAssistantWebContainerEnabled())
return;
if (!assistant::util::IsWebDeepLinkType(type, params)) if (!assistant::util::IsWebDeepLinkType(type, params))
return; return;
......
// 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/assistant/assistant_web_ui_controller.h"
#include "ash/assistant/assistant_controller.h"
#include "ash/assistant/ui/assistant_web_container_view.h"
#include "ash/assistant/util/deep_link_util.h"
#include "ash/multi_user/multi_user_window_manager_impl.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "chromeos/services/assistant/public/features.h"
#include "ui/aura/client/aura_constants.h"
namespace ash {
AssistantWebUiController::AssistantWebUiController(
AssistantController* assistant_controller)
: assistant_controller_(assistant_controller) {
DCHECK(chromeos::assistant::features::IsAssistantWebContainerEnabled());
assistant_controller_->AddObserver(this);
}
AssistantWebUiController::~AssistantWebUiController() {
assistant_controller_->RemoveObserver(this);
}
void AssistantWebUiController::OnWidgetDestroying(views::Widget* widget) {
ResetWebContainerView();
}
void AssistantWebUiController::OnAssistantControllerDestroying() {
if (!web_container_view_)
return;
// The view should not outlive the controller.
web_container_view_->GetWidget()->CloseNow();
DCHECK_EQ(nullptr, web_container_view_);
}
void AssistantWebUiController::OnDeepLinkReceived(
assistant::util::DeepLinkType type,
const std::map<std::string, std::string>& params) {
if (!assistant::util::IsWebDeepLinkType(type, params))
return;
ShowUi();
}
void AssistantWebUiController::ShowUi() {
if (!web_container_view_)
CreateWebContainerView();
web_container_view_->GetWidget()->Show();
}
AssistantWebContainerView* AssistantWebUiController::GetViewForTest() {
return web_container_view_;
}
void AssistantWebUiController::CreateWebContainerView() {
DCHECK(!web_container_view_);
web_container_view_ =
new AssistantWebContainerView(assistant_controller_->view_delegate());
web_container_view_->GetWidget()->AddObserver(this);
// Associate the window for Assistant Web UI with the active user in order to
// not leak across user sessions.
auto* window_manager = MultiUserWindowManagerImpl::Get();
if (!window_manager)
return;
const UserSession* active_user_session =
Shell::Get()->session_controller()->GetUserSession(0);
if (!active_user_session)
return;
web_container_view_->GetWidget()->GetNativeWindow()->SetProperty(
aura::client::kCreatedByUserGesture, true);
window_manager->SetWindowOwner(
web_container_view_->GetWidget()->GetNativeWindow(),
active_user_session->user_info.account_id);
}
void AssistantWebUiController::ResetWebContainerView() {
DCHECK(web_container_view_);
web_container_view_->GetWidget()->RemoveObserver(this);
web_container_view_ = 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_ASSISTANT_ASSISTANT_WEB_UI_CONTROLLER_H_
#define ASH_ASSISTANT_ASSISTANT_WEB_UI_CONTROLLER_H_
#include "ash/ash_export.h"
#include "ash/assistant/assistant_controller_observer.h"
#include "base/macros.h"
#include "ui/views/widget/widget_observer.h"
namespace ash {
class AssistantController;
class AssistantWebContainerView;
// The class to manage Assistant web container view.
class ASH_EXPORT AssistantWebUiController : public views::WidgetObserver,
public AssistantControllerObserver {
public:
explicit AssistantWebUiController(AssistantController* assistant_controller);
~AssistantWebUiController() override;
// views::WidgetObserver:
void OnWidgetDestroying(views::Widget* widget) override;
// AssistantControllerObserver:
void OnAssistantControllerDestroying() override;
void OnDeepLinkReceived(
assistant::util::DeepLinkType type,
const std::map<std::string, std::string>& params) override;
AssistantWebContainerView* GetViewForTest();
private:
void ShowUi();
// Constructs/resets |web_container_view_|.
void CreateWebContainerView();
void ResetWebContainerView();
AssistantController* const assistant_controller_; // Owned by Shell.
// Owned by view hierarchy.
AssistantWebContainerView* web_container_view_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(AssistantWebUiController);
};
} // namespace ash
#endif // ASH_ASSISTANT_ASSISTANT_WEB_UI_CONTROLLER_H_
...@@ -45,6 +45,7 @@ void AssistantAshTestBase::SetUp() { ...@@ -45,6 +45,7 @@ void AssistantAshTestBase::SetUp() {
void AssistantAshTestBase::TearDown() { void AssistantAshTestBase::TearDown() {
AshTestBase::TearDown(); AshTestBase::TearDown();
scoped_feature_list_.Reset();
ReenableAnimations(); ReenableAnimations();
} }
......
...@@ -50,6 +50,8 @@ component("ui") { ...@@ -50,6 +50,8 @@ component("ui") {
"assistant_notification_view.h", "assistant_notification_view.h",
"assistant_overlay.h", "assistant_overlay.h",
"assistant_view_delegate.h", "assistant_view_delegate.h",
"assistant_web_container_view.cc",
"assistant_web_container_view.h",
"assistant_web_view.cc", "assistant_web_view.cc",
"assistant_web_view.h", "assistant_web_view.h",
"base/assistant_button.cc", "base/assistant_button.cc",
......
...@@ -23,6 +23,8 @@ specific_include_rules = { ...@@ -23,6 +23,8 @@ specific_include_rules = {
".*_unittest\.cc": [ ".*_unittest\.cc": [
"+ash/assistant/assistant_controller.h", "+ash/assistant/assistant_controller.h",
"+ash/assistant/assistant_ui_controller.h", "+ash/assistant/assistant_ui_controller.h",
"+ash/assistant/assistant_web_ui_controller.h",
"+ash/assistant/test/assistant_ash_test_base.h",
"+ash/shell.h", "+ash/shell.h",
"+ash/session/session_controller_impl.h", "+ash/session/session_controller_impl.h",
"+ash/test/ash_test_base.h", "+ash/test/ash_test_base.h",
......
...@@ -71,10 +71,7 @@ TEST_F(AssistantContainerViewTest, InitialAnchoring) { ...@@ -71,10 +71,7 @@ TEST_F(AssistantContainerViewTest, InitialAnchoring) {
// We expect the view to appear in the work area where new windows will open. // We expect the view to appear in the work area where new windows will open.
gfx::Rect expected_work_area = gfx::Rect expected_work_area =
display::Screen::GetScreen() display::Screen::GetScreen()->GetPrimaryDisplay().work_area();
->GetDisplayMatching(
Shell::Get()->GetRootWindowForNewWindows()->GetBoundsInScreen())
.work_area();
// We expect the view to be horizontally centered and bottom aligned. // We expect the view to be horizontally centered and bottom aligned.
gfx::Rect expected_bounds = gfx::Rect(expected_work_area); gfx::Rect expected_bounds = gfx::Rect(expected_work_area);
......
// 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/assistant/ui/assistant_web_container_view.h"
#include <algorithm>
#include <memory>
#include "ash/assistant/ui/assistant_ui_constants.h"
#include "ash/assistant/ui/assistant_view_delegate.h"
#include "ash/assistant/ui/assistant_web_view.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/views/background.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/window/caption_button_layout_constants.h"
namespace ash {
namespace {
constexpr int kPreferredWindowWidthDip = 768;
// This height includes the window's |non_client_frame_view|'s height.
constexpr int kPreferredWindowHeightDip = 768;
// The minimum padding of the window to the edges of the screen.
constexpr int kPreferredPaddingMinDip = 48;
} // namespace
AssistantWebContainerView::AssistantWebContainerView(
AssistantViewDelegate* delegate)
: delegate_(delegate) {
InitLayout();
}
AssistantWebContainerView::~AssistantWebContainerView() = default;
const char* AssistantWebContainerView::GetClassName() const {
return "AssistantWebContainerView";
}
gfx::Size AssistantWebContainerView::CalculatePreferredSize() const {
// TODO(b/142565300): Handle virtual keyboard resize.
const gfx::Rect work_area =
display::Screen::GetScreen()
->GetDisplayNearestWindow(GetWidget()->GetNativeWindow())
.work_area();
const int width = std::min(work_area.width() - 2 * kPreferredPaddingMinDip,
kPreferredWindowWidthDip);
const int height = std::min(work_area.height() - 2 * kPreferredPaddingMinDip,
kPreferredWindowHeightDip);
const int non_client_frame_view_height =
views::GetCaptionButtonLayoutSize(
views::CaptionButtonLayoutSize::kNonBrowserCaption)
.height();
return gfx::Size(width, height - non_client_frame_view_height);
}
void AssistantWebContainerView::InitLayout() {
views::Widget::InitParams params;
params.type = views::Widget::InitParams::TYPE_WINDOW;
params.delegate = this;
params.name = GetClassName();
views::Widget* widget = new views::Widget;
widget->Init(std::move(params));
SetLayoutManager(std::make_unique<views::FillLayout>());
SetBackground(views::CreateSolidBackground(SK_ColorWHITE));
// Web view.
AddChildView(std::make_unique<AssistantWebView>(delegate_));
}
} // 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_ASSISTANT_UI_ASSISTANT_WEB_CONTAINER_VIEW_H_
#define ASH_ASSISTANT_UI_ASSISTANT_WEB_CONTAINER_VIEW_H_
#include "base/component_export.h"
#include "base/macros.h"
#include "ui/views/widget/widget_delegate.h"
namespace ash {
class AssistantViewDelegate;
// The container of assistant_web_view when Assistant web container is enabled.
class COMPONENT_EXPORT(ASSISTANT_UI) AssistantWebContainerView
: public views::WidgetDelegateView {
public:
explicit AssistantWebContainerView(AssistantViewDelegate* delegate);
~AssistantWebContainerView() override;
// views::WidgetDelegateView:
const char* GetClassName() const override;
gfx::Size CalculatePreferredSize() const override;
private:
void InitLayout();
AssistantViewDelegate* const delegate_;
DISALLOW_COPY_AND_ASSIGN(AssistantWebContainerView);
};
} // namespace ash
#endif // ASH_ASSISTANT_UI_ASSISTANT_WEB_CONTAINER_VIEW_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/assistant/ui/assistant_web_container_view.h"
#include "ash/assistant/assistant_controller.h"
#include "ash/assistant/assistant_ui_controller.h"
#include "ash/assistant/assistant_web_ui_controller.h"
#include "ash/assistant/test/assistant_ash_test_base.h"
#include "ash/public/cpp/assistant/assistant_settings.h"
#include "ash/shell.h"
#include "base/macros.h"
#include "base/test/scoped_feature_list.h"
#include "chromeos/services/assistant/public/features.h"
namespace ash {
namespace {
class AssistantWebContainerViewTest : public AssistantAshTestBase {
public:
AssistantWebContainerViewTest() = default;
~AssistantWebContainerViewTest() override = default;
void SetUp() override {
scoped_feature_list_.InitAndEnableFeature(
chromeos::assistant::features::kEnableAssistantWebContainer);
AssistantAshTestBase::SetUp();
}
void TearDown() override {
AssistantAshTestBase::TearDown();
scoped_feature_list_.Reset();
}
protected:
AssistantWebContainerView* view() {
return Shell::Get()
->assistant_controller()
->web_ui_controller()
->GetViewForTest();
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(AssistantWebContainerViewTest);
};
} // namespace
TEST_F(AssistantWebContainerViewTest, ShowAndCloseWindow) {
// Show Assistant Settings UI.
OpenAssistantSettings();
AssistantWebContainerView* container_view = view();
ASSERT_TRUE(container_view);
// Close Assistant Settings UI.
container_view->GetWidget()->CloseNow();
container_view = view();
ASSERT_FALSE(container_view);
}
TEST_F(AssistantWebContainerViewTest, CenterWindow) {
// Test large and small screens.
std::vector<std::string> resolutions{"1200x1000", "800x600"};
for (const auto& resolution : resolutions) {
UpdateDisplay(resolution);
// Show Assistant Settings UI and grab a reference to our view under test.
OpenAssistantSettings();
AssistantWebContainerView* container_view = view();
// We expect the view to appear in the work area where new windows will
// open.
gfx::Rect expected_work_area =
display::Screen::GetScreen()->GetPrimaryDisplay().work_area();
// We expect the view to be centered in screen.
gfx::Rect expected_bounds = gfx::Rect(expected_work_area);
expected_bounds.ClampToCenteredSize(
container_view->GetWidget()->GetNativeWindow()->bounds().size());
ASSERT_EQ(expected_bounds,
container_view->GetWidget()->GetWindowBoundsInScreen());
container_view->GetWidget()->CloseNow();
}
}
} // namespace ash
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "ash/public/cpp/app_list/app_list_features.h" #include "ash/public/cpp/app_list/app_list_features.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "chromeos/services/assistant/public/features.h"
#include "services/content/public/cpp/navigable_contents_view.h" #include "services/content/public/cpp/navigable_contents_view.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
...@@ -32,11 +33,17 @@ AssistantWebView::AssistantWebView(AssistantViewDelegate* delegate) ...@@ -32,11 +33,17 @@ AssistantWebView::AssistantWebView(AssistantViewDelegate* delegate)
InitLayout(); InitLayout();
delegate_->AddObserver(this); delegate_->AddObserver(this);
delegate_->AddUiModelObserver(this);
// |AssistantWebView| has its own separate container when Assistant web
// container is enabled. The container will handle its own lifecycle.
if (!chromeos::assistant::features::IsAssistantWebContainerEnabled())
delegate_->AddUiModelObserver(this);
} }
AssistantWebView::~AssistantWebView() { AssistantWebView::~AssistantWebView() {
delegate_->RemoveUiModelObserver(this); if (!chromeos::assistant::features::IsAssistantWebContainerEnabled())
delegate_->RemoveUiModelObserver(this);
delegate_->RemoveObserver(this); delegate_->RemoveObserver(this);
} }
...@@ -49,6 +56,10 @@ gfx::Size AssistantWebView::CalculatePreferredSize() const { ...@@ -49,6 +56,10 @@ gfx::Size AssistantWebView::CalculatePreferredSize() const {
} }
int AssistantWebView::GetHeightForWidth(int width) const { int AssistantWebView::GetHeightForWidth(int width) const {
// The Assistant web container has fixed height.
if (chromeos::assistant::features::IsAssistantWebContainerEnabled())
return INT_MAX;
if (app_list_features::IsEmbeddedAssistantUIEnabled()) if (app_list_features::IsEmbeddedAssistantUIEnabled())
return kMaxHeightEmbeddedDip; return kMaxHeightEmbeddedDip;
...@@ -184,6 +195,10 @@ void AssistantWebView::OnUiVisibilityChanged( ...@@ -184,6 +195,10 @@ void AssistantWebView::OnUiVisibilityChanged(
AssistantVisibility old_visibility, AssistantVisibility old_visibility,
base::Optional<AssistantEntryPoint> entry_point, base::Optional<AssistantEntryPoint> entry_point,
base::Optional<AssistantExitPoint> exit_point) { base::Optional<AssistantExitPoint> exit_point) {
// When Assistant web container is enabled, |assistant_web_view| has its own
// container and this method should not be called on it.
DCHECK(!chromeos::assistant::features::IsAssistantWebContainerEnabled());
// When the Assistant UI is closed we need to clear the |contents_| in order // When the Assistant UI is closed we need to clear the |contents_| in order
// to free the memory. // to free the memory.
if (new_visibility == AssistantVisibility::kClosed) if (new_visibility == AssistantVisibility::kClosed)
...@@ -192,6 +207,8 @@ void AssistantWebView::OnUiVisibilityChanged( ...@@ -192,6 +207,8 @@ void AssistantWebView::OnUiVisibilityChanged(
void AssistantWebView::OnUsableWorkAreaChanged( void AssistantWebView::OnUsableWorkAreaChanged(
const gfx::Rect& usable_work_area) { const gfx::Rect& usable_work_area) {
DCHECK(!chromeos::assistant::features::IsAssistantWebContainerEnabled());
UpdateContentSize(); UpdateContentSize();
} }
......
...@@ -13,6 +13,7 @@ component("feature_flags") { ...@@ -13,6 +13,7 @@ component("feature_flags") {
] ]
deps = [ deps = [
"//ash/public/cpp",
"//base", "//base",
] ]
} }
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chromeos/services/assistant/public/features.h" #include "chromeos/services/assistant/public/features.h"
#include "ash/public/cpp/app_list/app_list_features.h"
#include "base/feature_list.h" #include "base/feature_list.h"
namespace chromeos { namespace chromeos {
...@@ -76,6 +77,9 @@ const base::Feature kEnableMediaSessionIntegration{ ...@@ -76,6 +77,9 @@ const base::Feature kEnableMediaSessionIntegration{
const base::Feature kDisableVoiceMatch{"DisableVoiceMatch", const base::Feature kDisableVoiceMatch{"DisableVoiceMatch",
base::FEATURE_DISABLED_BY_DEFAULT}; base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kEnableAssistantWebContainer{
"EnableAssistantWebContainer", base::FEATURE_DISABLED_BY_DEFAULT};
int GetProactiveSuggestionsMaxWidth() { int GetProactiveSuggestionsMaxWidth() {
return kAssistantProactiveSuggestionsMaxWidth.Get(); return kAssistantProactiveSuggestionsMaxWidth.Get();
} }
...@@ -152,6 +156,11 @@ bool IsVoiceMatchDisabled() { ...@@ -152,6 +156,11 @@ bool IsVoiceMatchDisabled() {
return base::FeatureList::IsEnabled(kDisableVoiceMatch); return base::FeatureList::IsEnabled(kDisableVoiceMatch);
} }
bool IsAssistantWebContainerEnabled() {
return app_list_features::IsEmbeddedAssistantUIEnabled() &&
base::FeatureList::IsEnabled(kEnableAssistantWebContainer);
}
} // namespace features } // namespace features
} // namespace assistant } // namespace assistant
} // namespace chromeos } // namespace chromeos
...@@ -85,6 +85,10 @@ extern const base::Feature kEnablePowerManager; ...@@ -85,6 +85,10 @@ extern const base::Feature kEnablePowerManager;
COMPONENT_EXPORT(ASSISTANT_SERVICE_PUBLIC) COMPONENT_EXPORT(ASSISTANT_SERVICE_PUBLIC)
extern const base::Feature kEnableTextQueriesWithClientDiscourseContext; extern const base::Feature kEnableTextQueriesWithClientDiscourseContext;
// Enables the Assistant web container (e.g. Assistant Settings).
COMPONENT_EXPORT(ASSISTANT_SERVICE_PUBLIC)
extern const base::Feature kEnableAssistantWebContainer;
COMPONENT_EXPORT(ASSISTANT_SERVICE_PUBLIC) COMPONENT_EXPORT(ASSISTANT_SERVICE_PUBLIC)
int GetProactiveSuggestionsMaxWidth(); int GetProactiveSuggestionsMaxWidth();
...@@ -127,8 +131,10 @@ COMPONENT_EXPORT(ASSISTANT_SERVICE_PUBLIC) bool IsStereoAudioInputEnabled(); ...@@ -127,8 +131,10 @@ COMPONENT_EXPORT(ASSISTANT_SERVICE_PUBLIC) bool IsStereoAudioInputEnabled();
COMPONENT_EXPORT(ASSISTANT_SERVICE_PUBLIC) bool IsWarmerWelcomeEnabled(); COMPONENT_EXPORT(ASSISTANT_SERVICE_PUBLIC) bool IsWarmerWelcomeEnabled();
COMPONENT_EXPORT(ASSISTANT_SERVICE_PUBLIC) bool IsVoiceMatchDisabled();
COMPONENT_EXPORT(ASSISTANT_SERVICE_PUBLIC) COMPONENT_EXPORT(ASSISTANT_SERVICE_PUBLIC)
bool IsVoiceMatchDisabled(); bool IsAssistantWebContainerEnabled();
} // namespace features } // namespace features
} // namespace assistant } // namespace assistant
......
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