Assistant Cleanup: Refactor AssistantWebView

The AssistantWebView is used by Ash to work around dependency
restrictions.
This change rename the class to AshWebView, detach with the Assistant
to expose the class to other ash features.

Bug: b/198811694
Test: Run existing tests
Change-Id: I7dba283247f3d62ca979b49a38922ba94ffd78d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3247881
Reviewed-by: Meilin Wang <[email protected]>
Reviewed-by: Xiyuan Xia <[email protected]>
Commit-Queue: Yue Li <[email protected]>
Cr-Commit-Position: refs/heads/main@{#936098}
diff --git a/ash/assistant/model/DEPS b/ash/assistant/model/DEPS
index a8f9d90..545bcaa 100644
--- a/ash/assistant/model/DEPS
+++ b/ash/assistant/model/DEPS
@@ -2,6 +2,7 @@
   "-ash",
   "+ash/assistant/ui/assistant_ui_constants.h",
   "+ash/assistant/model",
+  "+ash/public/cpp",
   "+ash/public/cpp/app_list",
   "+ash/public/cpp/assistant",
   "+ash/public/mojom",
diff --git a/ash/assistant/model/ui/assistant_card_element.cc b/ash/assistant/model/ui/assistant_card_element.cc
index 6c46d4d..6a67d03 100644
--- a/ash/assistant/model/ui/assistant_card_element.cc
+++ b/ash/assistant/model/ui/assistant_card_element.cc
@@ -7,14 +7,14 @@
 #include <utility>
 
 #include "ash/assistant/ui/assistant_ui_constants.h"
-#include "ash/public/cpp/assistant/assistant_web_view_factory.h"
+#include "ash/public/cpp/ash_web_view_factory.h"
 #include "base/base64.h"
 
 namespace ash {
 
 // AssistantCardElement::Processor ---------------------------------------------
 
-class AssistantCardElement::Processor : public AssistantWebView::Observer {
+class AssistantCardElement::Processor : public AshWebView::Observer {
  public:
   Processor(AssistantCardElement* card_element, ProcessingCallback callback)
       : card_element_(card_element), callback_(std::move(callback)) {}
@@ -35,7 +35,7 @@
     const int width_dip = kPreferredWidthDip - 2 * kHorizontalMarginDip;
 
     // Configure parameters for the card.
-    AssistantWebView::InitParams contents_params;
+    AshWebView::InitParams contents_params;
     contents_params.enable_auto_resize = true;
     contents_params.min_size = gfx::Size(width_dip, 1);
     contents_params.max_size = gfx::Size(width_dip, INT_MAX);
@@ -43,7 +43,7 @@
 
     // Create |contents_view_| and retain ownership until it is added to the
     // view hierarchy. If that never happens, it will be still be cleaned up.
-    contents_view_ = AssistantWebViewFactory::Get()->Create(contents_params);
+    contents_view_ = AshWebViewFactory::Get()->Create(contents_params);
 
     // Observe |contents_view_| so that we are notified when loading is
     // complete.
@@ -59,7 +59,7 @@
   }
 
  private:
-  // AssistantWebView::Observer:
+  // AshWebView::Observer:
   void DidStopLoading() override {
     contents_view_->RemoveObserver(this);
 
@@ -73,7 +73,7 @@
   AssistantCardElement* const card_element_;
   ProcessingCallback callback_;
 
-  std::unique_ptr<AssistantWebView> contents_view_;
+  std::unique_ptr<AshWebView> contents_view_;
 };
 
 // AssistantCardElement --------------------------------------------------------
diff --git a/ash/assistant/model/ui/assistant_card_element.h b/ash/assistant/model/ui/assistant_card_element.h
index 503676f..f9b0b80d 100644
--- a/ash/assistant/model/ui/assistant_card_element.h
+++ b/ash/assistant/model/ui/assistant_card_element.h
@@ -10,7 +10,7 @@
 #include <utility>
 
 #include "ash/assistant/model/ui/assistant_ui_element.h"
-#include "ash/public/cpp/assistant/assistant_web_view.h"
+#include "ash/public/cpp/ash_web_view.h"
 #include "base/component_export.h"
 #include "base/macros.h"
 
@@ -33,11 +33,11 @@
 
   const std::string& html() const { return html_; }
   const std::string& fallback() const { return fallback_; }
-  std::unique_ptr<AssistantWebView> MoveContentsView() {
+  std::unique_ptr<AshWebView> MoveContentsView() {
     return std::move(contents_view_);
   }
 
-  void set_contents_view(std::unique_ptr<AssistantWebView> contents_view) {
+  void set_contents_view(std::unique_ptr<AshWebView> contents_view) {
     contents_view_ = std::move(contents_view);
   }
 
@@ -46,7 +46,7 @@
 
   const std::string html_;
   const std::string fallback_;
-  std::unique_ptr<AssistantWebView> contents_view_;
+  std::unique_ptr<AshWebView> contents_view_;
 
   std::unique_ptr<Processor> processor_;
 
diff --git a/ash/assistant/test/assistant_ash_test_base.cc b/ash/assistant/test/assistant_ash_test_base.cc
index 74fd1e75..b217bbeb 100644
--- a/ash/assistant/test/assistant_ash_test_base.cc
+++ b/ash/assistant/test/assistant_ash_test_base.cc
@@ -10,7 +10,6 @@
 #include "ash/app_list/app_list_controller_impl.h"
 #include "ash/app_list/views/app_list_view.h"
 #include "ash/assistant/test/test_assistant_setup.h"
-#include "ash/assistant/test/test_assistant_web_view_factory.h"
 #include "ash/assistant/ui/main_stage/assistant_onboarding_suggestion_view.h"
 #include "ash/assistant/ui/main_stage/suggestion_chip_view.h"
 #include "ash/keyboard/ui/keyboard_ui_controller.h"
@@ -21,6 +20,7 @@
 #include "ash/session/session_controller_impl.h"
 #include "ash/shell.h"
 #include "ash/test/ash_test_helper.h"
+#include "ash/test/test_ash_web_view_factory.h"
 #include "ash/test/view_drawn_waiter.h"
 #include "base/run_loop.h"
 #include "base/test/task_environment.h"
@@ -105,7 +105,7 @@
     : AshTestBase(time),
       test_api_(AssistantTestApi::Create()),
       test_setup_(std::make_unique<TestAssistantSetup>()),
-      test_web_view_factory_(std::make_unique<TestAssistantWebViewFactory>()),
+      test_web_view_factory_(std::make_unique<TestAshWebViewFactory>()),
       delegate_(std::make_unique<
                 chromeos::assistant::ScopedAssistantBrowserDelegate>()) {}
 
diff --git a/ash/assistant/test/assistant_ash_test_base.h b/ash/assistant/test/assistant_ash_test_base.h
index 2f2b1ef4..4b736e5 100644
--- a/ash/assistant/test/assistant_ash_test_base.h
+++ b/ash/assistant/test/assistant_ash_test_base.h
@@ -39,7 +39,7 @@
 class SuggestionChipView;
 class TestAssistantService;
 class TestAssistantSetup;
-class TestAssistantWebViewFactory;
+class TestAshWebViewFactory;
 
 // Helper class to make testing the Assistant Ash UI easier.
 class AssistantAshTestBase : public AshTestBase {
@@ -219,7 +219,7 @@
 
   std::unique_ptr<AssistantTestApi> test_api_;
   std::unique_ptr<TestAssistantSetup> test_setup_;
-  std::unique_ptr<TestAssistantWebViewFactory> test_web_view_factory_;
+  std::unique_ptr<TestAshWebViewFactory> test_web_view_factory_;
 
   std::vector<std::unique_ptr<aura::Window>> windows_;
   std::vector<std::unique_ptr<views::Widget>> widgets_;
diff --git a/ash/assistant/test/test_assistant_web_view.cc b/ash/assistant/test/test_assistant_web_view.cc
deleted file mode 100644
index 8c71328..0000000
--- a/ash/assistant/test/test_assistant_web_view.cc
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2020 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/test/test_assistant_web_view.h"
-
-#include "base/bind.h"
-#include "base/threading/sequenced_task_runner_handle.h"
-
-namespace ash {
-
-TestAssistantWebView::TestAssistantWebView() = default;
-
-TestAssistantWebView::~TestAssistantWebView() = default;
-
-void TestAssistantWebView::AddObserver(Observer* observer) {
-  observers_.AddObserver(observer);
-}
-
-void TestAssistantWebView::RemoveObserver(Observer* observer) {
-  observers_.RemoveObserver(observer);
-}
-
-gfx::NativeView TestAssistantWebView::GetNativeView() {
-  // Not yet implemented for unittests.
-  return nullptr;
-}
-
-bool TestAssistantWebView::GoBack() {
-  // Not yet implemented for unittests.
-  return false;
-}
-
-void TestAssistantWebView::Navigate(const GURL& url) {
-  // Simulate navigation by notifying |observers_| of the expected event that
-  // would normally signal navigation completion. We do this asynchronously to
-  // more accurately simulate real-world conditions.
-  base::SequencedTaskRunnerHandle::Get()->PostTask(
-      FROM_HERE, base::BindOnce(
-                     [](const base::WeakPtr<TestAssistantWebView>& self) {
-                       if (self) {
-                         for (auto& observer : self->observers_)
-                           observer.DidStopLoading();
-                       }
-                     },
-                     weak_factory_.GetWeakPtr()));
-}
-
-}  // namespace ash
diff --git a/ash/assistant/test/test_assistant_web_view.h b/ash/assistant/test/test_assistant_web_view.h
deleted file mode 100644
index d9a4e50a..0000000
--- a/ash/assistant/test/test_assistant_web_view.h
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2020 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_TEST_TEST_ASSISTANT_WEB_VIEW_H_
-#define ASH_ASSISTANT_TEST_TEST_ASSISTANT_WEB_VIEW_H_
-
-#include "ash/public/cpp/assistant/assistant_web_view.h"
-#include "base/observer_list.h"
-
-namespace ash {
-
-// An implementation of AssistantWebView for use in unittests.
-class TestAssistantWebView : public AssistantWebView {
- public:
-  TestAssistantWebView();
-  ~TestAssistantWebView() override;
-
-  TestAssistantWebView(const TestAssistantWebView&) = delete;
-  TestAssistantWebView& operator=(const TestAssistantWebView&) = delete;
-
-  // AssistantWebView:
-  void AddObserver(Observer* observer) override;
-  void RemoveObserver(Observer* observer) override;
-  gfx::NativeView GetNativeView() override;
-  bool GoBack() override;
-  void Navigate(const GURL& url) override;
-
- private:
-  base::ObserverList<Observer> observers_;
-
-  base::WeakPtrFactory<TestAssistantWebView> weak_factory_{this};
-};
-
-}  // namespace ash
-
-#endif  // ASH_ASSISTANT_TEST_TEST_ASSISTANT_WEB_VIEW_H_
diff --git a/ash/assistant/test/test_assistant_web_view_factory.cc b/ash/assistant/test/test_assistant_web_view_factory.cc
deleted file mode 100644
index e603a0d..0000000
--- a/ash/assistant/test/test_assistant_web_view_factory.cc
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2020 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/test/test_assistant_web_view_factory.h"
-
-#include "ash/assistant/test/test_assistant_web_view.h"
-
-namespace ash {
-
-TestAssistantWebViewFactory::TestAssistantWebViewFactory() = default;
-
-TestAssistantWebViewFactory::~TestAssistantWebViewFactory() = default;
-
-std::unique_ptr<AssistantWebView> TestAssistantWebViewFactory::Create(
-    const AssistantWebView::InitParams& params) {
-  return std::make_unique<TestAssistantWebView>();
-}
-
-}  // namespace ash
\ No newline at end of file
diff --git a/ash/assistant/test/test_assistant_web_view_factory.h b/ash/assistant/test/test_assistant_web_view_factory.h
deleted file mode 100644
index ca32ab7f..0000000
--- a/ash/assistant/test/test_assistant_web_view_factory.h
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright 2020 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_TEST_TEST_ASSISTANT_WEB_VIEW_FACTORY_H_
-#define ASH_ASSISTANT_TEST_TEST_ASSISTANT_WEB_VIEW_FACTORY_H_
-
-#include <memory>
-
-#include "ash/public/cpp/assistant/assistant_web_view_factory.h"
-
-namespace ash {
-
-// An implementation of AssistantWebViewFactory for use in unittests.
-class TestAssistantWebViewFactory : public AssistantWebViewFactory {
- public:
-  TestAssistantWebViewFactory();
-  TestAssistantWebViewFactory(const AssistantWebViewFactory& copy) = delete;
-  TestAssistantWebViewFactory& operator=(
-      const AssistantWebViewFactory& assign) = delete;
-  ~TestAssistantWebViewFactory() override;
-
-  // AssistantWebViewFactory:
-  std::unique_ptr<AssistantWebView> Create(
-      const AssistantWebView::InitParams& params) override;
-};
-
-}  // namespace ash
-
-#endif  // ASH_ASSISTANT_TEST_TEST_ASSISTANT_WEB_VIEW_FACTORY_H_
diff --git a/ash/assistant/ui/assistant_web_container_view.cc b/ash/assistant/ui/assistant_web_container_view.cc
index d8041d7b..40f472b 100644
--- a/ash/assistant/ui/assistant_web_container_view.cc
+++ b/ash/assistant/ui/assistant_web_container_view.cc
@@ -12,7 +12,7 @@
 #include "ash/assistant/ui/assistant_ui_constants.h"
 #include "ash/assistant/ui/assistant_web_view_delegate.h"
 #include "ash/assistant/util/deep_link_util.h"
-#include "ash/public/cpp/assistant/assistant_web_view_factory.h"
+#include "ash/public/cpp/ash_web_view_factory.h"
 #include "ash/public/cpp/assistant/controller/assistant_controller.h"
 #include "ui/base/metadata/metadata_impl_macros.h"
 #include "ui/base/window_open_disposition.h"
@@ -127,11 +127,11 @@
 void AssistantWebContainerView::OpenUrl(const GURL& url) {
   RemoveContents();
 
-  AssistantWebView::InitParams contents_params;
+  AshWebView::InitParams contents_params;
   contents_params.suppress_navigation = true;
   contents_params.minimize_on_back_key = true;
 
-  contents_view_ = AssistantWebViewFactory::Get()->Create(contents_params);
+  contents_view_ = AshWebViewFactory::Get()->Create(contents_params);
 
   // We observe |contents_view_| so that we can handle events from the
   // underlying WebContents.
@@ -145,7 +145,7 @@
   DidChangeCanGoBack(can_go_back);
 }
 
-AssistantWebView* AssistantWebContainerView::ContentsView() {
+AshWebView* AssistantWebContainerView::ContentsView() {
   return contents_view_ptr_ ? contents_view_ptr_ : contents_view_.get();
 }
 
diff --git a/ash/assistant/ui/assistant_web_container_view.h b/ash/assistant/ui/assistant_web_container_view.h
index bdb76bf..c6af3a7 100644
--- a/ash/assistant/ui/assistant_web_container_view.h
+++ b/ash/assistant/ui/assistant_web_container_view.h
@@ -5,7 +5,7 @@
 #ifndef ASH_ASSISTANT_UI_ASSISTANT_WEB_CONTAINER_VIEW_H_
 #define ASH_ASSISTANT_UI_ASSISTANT_WEB_CONTAINER_VIEW_H_
 
-#include "ash/public/cpp/assistant/assistant_web_view.h"
+#include "ash/public/cpp/ash_web_view.h"
 #include "base/component_export.h"
 #include "base/macros.h"
 #include "ui/base/metadata/metadata_header_macros.h"
@@ -18,7 +18,7 @@
 // The container for hosting standalone WebContents in Assistant.
 class COMPONENT_EXPORT(ASSISTANT_UI) AssistantWebContainerView
     : public views::WidgetDelegateView,
-      public AssistantWebView::Observer {
+      public AshWebView::Observer {
  public:
   METADATA_HEADER(AssistantWebContainerView);
 
@@ -53,14 +53,14 @@
   void SetCanGoBackForTesting(bool can_go_back);
 
  private:
-  AssistantWebView* ContentsView();
+  AshWebView* ContentsView();
   void InitLayout();
   void RemoveContents();
 
   AssistantWebViewDelegate* const web_container_view_delegate_;
 
-  std::unique_ptr<AssistantWebView> contents_view_;
-  AssistantWebView* contents_view_ptr_ = nullptr;
+  std::unique_ptr<AshWebView> contents_view_;
+  AshWebView* contents_view_ptr_ = nullptr;
 };
 
 }  // namespace ash
diff --git a/ash/assistant/ui/main_stage/assistant_card_element_view.h b/ash/assistant/ui/main_stage/assistant_card_element_view.h
index 90e6b9b..6de6d50 100644
--- a/ash/assistant/ui/main_stage/assistant_card_element_view.h
+++ b/ash/assistant/ui/main_stage/assistant_card_element_view.h
@@ -8,7 +8,7 @@
 #include <string>
 
 #include "ash/assistant/ui/main_stage/assistant_ui_element_view.h"
-#include "ash/public/cpp/assistant/assistant_web_view.h"
+#include "ash/public/cpp/ash_web_view.h"
 #include "base/component_export.h"
 #include "base/macros.h"
 
@@ -21,7 +21,7 @@
 // AssistantCardElement. It is a child view of UiElementContainerView.
 class COMPONENT_EXPORT(ASSISTANT_UI) AssistantCardElementView
     : public AssistantUiElementView,
-      public AssistantWebView::Observer {
+      public AshWebView::Observer {
  public:
   AssistantCardElementView(AssistantViewDelegate* delegate,
                            const AssistantCardElement* card_element);
@@ -41,7 +41,7 @@
   void ScrollRectToVisible(const gfx::Rect& rect) override;
   std::unique_ptr<ElementAnimator> CreateAnimator() override;
 
-  // AssistantWebView::Observer:
+  // AshWebView::Observer:
   void DidSuppressNavigation(const GURL& url,
                              WindowOpenDisposition disposition,
                              bool from_user_gesture) override;
@@ -56,7 +56,7 @@
  private:
   void InitLayout();
 
-  AssistantWebView* contents_view_ = nullptr;
+  AshWebView* contents_view_ = nullptr;
 
   AssistantViewDelegate* const delegate_;
   const AssistantCardElement* const card_element_;