Commit b7276d1a authored by David Black's avatar David Black Committed by Commit Bot

Migrate proactive suggestions off Content Service.

As this is the last usage of Content Service by Assistant, the Content
Service-related APIs on AssistantController/AssistantViewDelegate are
also cleaned up in this CL.

Bug: b:146351046
Change-Id: I852a17630e3d9e3b17b8dfac025648d693004dc4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2006228Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: David Black <dmblack@google.com>
Cr-Commit-Position: refs/heads/master@{#732936}
parent 51ce9c3f
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "ash/public/mojom/assistant_volume_control.mojom.h" #include "ash/public/mojom/assistant_volume_control.mojom.h"
#include "ash/session/session_controller_impl.h" #include "ash/session/session_controller_impl.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "ash/utility/screenshot_controller.h" #include "ash/utility/screenshot_controller.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
...@@ -24,7 +23,6 @@ ...@@ -24,7 +23,6 @@
#include "chromeos/services/assistant/public/features.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 "services/content/public/mojom/navigable_contents_factory.mojom.h"
namespace ash { namespace ash {
...@@ -263,12 +261,6 @@ void AssistantController::OpenUrl(const GURL& url, ...@@ -263,12 +261,6 @@ void AssistantController::OpenUrl(const GURL& url,
NotifyUrlOpened(url, from_server); NotifyUrlOpened(url, from_server);
} }
void AssistantController::GetNavigableContentsFactory(
mojo::PendingReceiver<content::mojom::NavigableContentsFactory> receiver) {
Shell::Get()->shell_delegate()->BindNavigableContentsFactory(
std::move(receiver));
}
bool AssistantController::IsAssistantReady() const { bool AssistantController::IsAssistantReady() const {
return !!assistant_; return !!assistant_;
} }
......
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
#include "mojo/public/cpp/bindings/receiver_set.h" #include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/remote_set.h" #include "mojo/public/cpp/bindings/remote_set.h"
#include "services/content/public/mojom/navigable_contents_factory.mojom-forward.h"
class PrefRegistrySimple; class PrefRegistrySimple;
...@@ -121,11 +120,6 @@ class ASH_EXPORT AssistantController ...@@ -121,11 +120,6 @@ class ASH_EXPORT AssistantController
bool in_background = false, bool in_background = false,
bool from_server = false); bool from_server = false);
// Acquires a NavigableContentsFactory from the Content Service to allow
// Assistant to display embedded web contents.
void GetNavigableContentsFactory(
mojo::PendingReceiver<content::mojom::NavigableContentsFactory> receiver);
AssistantAlarmTimerController* alarm_timer_controller() { AssistantAlarmTimerController* alarm_timer_controller() {
return &assistant_alarm_timer_controller_; return &assistant_alarm_timer_controller_;
} }
......
...@@ -107,11 +107,6 @@ void AssistantViewDelegateImpl::DownloadImage( ...@@ -107,11 +107,6 @@ void AssistantViewDelegateImpl::DownloadImage(
return Shell::Get()->cursor_manager(); return Shell::Get()->cursor_manager();
} }
void AssistantViewDelegateImpl::GetNavigableContentsFactoryForView(
mojo::PendingReceiver<content::mojom::NavigableContentsFactory> receiver) {
assistant_controller_->GetNavigableContentsFactory(std::move(receiver));
}
aura::Window* AssistantViewDelegateImpl::GetRootWindowForDisplayId( aura::Window* AssistantViewDelegateImpl::GetRootWindowForDisplayId(
int64_t display_id) { int64_t display_id) {
return Shell::Get()->GetRootWindowForDisplayId(display_id); return Shell::Get()->GetRootWindowForDisplayId(display_id);
......
...@@ -45,9 +45,6 @@ class AssistantViewDelegateImpl : public AssistantViewDelegate { ...@@ -45,9 +45,6 @@ class AssistantViewDelegateImpl : public AssistantViewDelegate {
const GURL& url, const GURL& url,
AssistantImageDownloader::DownloadCallback callback) override; AssistantImageDownloader::DownloadCallback callback) override;
::wm::CursorManager* GetCursorManager() override; ::wm::CursorManager* GetCursorManager() override;
void GetNavigableContentsFactoryForView(
mojo::PendingReceiver<content::mojom::NavigableContentsFactory> receiver)
override;
aura::Window* GetRootWindowForDisplayId(int64_t display_id) override; aura::Window* GetRootWindowForDisplayId(int64_t display_id) override;
aura::Window* GetRootWindowForNewWindows() override; aura::Window* GetRootWindowForNewWindows() override;
bool IsTabletMode() const override; bool IsTabletMode() const override;
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "base/observer_list_types.h" #include "base/observer_list_types.h"
#include "chromeos/services/assistant/public/mojom/assistant.mojom.h" #include "chromeos/services/assistant/public/mojom/assistant.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "services/content/public/mojom/navigable_contents_factory.mojom.h"
#include "ui/wm/core/cursor_manager.h" #include "ui/wm/core/cursor_manager.h"
namespace ash { namespace ash {
...@@ -130,12 +129,6 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantViewDelegate { ...@@ -130,12 +129,6 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantViewDelegate {
// Returns the cursor_manager. // Returns the cursor_manager.
virtual ::wm::CursorManager* GetCursorManager() = 0; virtual ::wm::CursorManager* GetCursorManager() = 0;
// Acquires a NavigableContentsFactory from the Content Service to allow
// Assistant to display embedded web contents.
virtual void GetNavigableContentsFactoryForView(
mojo::PendingReceiver<content::mojom::NavigableContentsFactory>
receiver) = 0;
// Returns the root window for the specified |display_id|. // Returns the root window for the specified |display_id|.
virtual aura::Window* GetRootWindowForDisplayId(int64_t display_id) = 0; virtual aura::Window* GetRootWindowForDisplayId(int64_t display_id) = 0;
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "chromeos/services/assistant/public/features.h" #include "chromeos/services/assistant/public/features.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/base/window_open_disposition.h"
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
......
...@@ -5,11 +5,13 @@ ...@@ -5,11 +5,13 @@
#include "ash/assistant/ui/proactive_suggestions_rich_view.h" #include "ash/assistant/ui/proactive_suggestions_rich_view.h"
#include "ash/assistant/ui/assistant_view_delegate.h" #include "ash/assistant/ui/assistant_view_delegate.h"
#include "ash/public/cpp/assistant/assistant_web_view_factory.h"
#include "ash/public/cpp/assistant/proactive_suggestions.h" #include "ash/public/cpp/assistant/proactive_suggestions.h"
#include "ash/public/cpp/view_shadow.h" #include "ash/public/cpp/view_shadow.h"
#include "base/base64.h" #include "base/base64.h"
#include "chromeos/services/assistant/public/features.h" #include "chromeos/services/assistant/public/features.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/views/background.h"
#include "ui/views/event_monitor.h" #include "ui/views/event_monitor.h"
#include "ui/views/layout/fill_layout.h" #include "ui/views/layout/fill_layout.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
...@@ -22,8 +24,8 @@ ProactiveSuggestionsRichView::ProactiveSuggestionsRichView( ...@@ -22,8 +24,8 @@ ProactiveSuggestionsRichView::ProactiveSuggestionsRichView(
: ProactiveSuggestionsView(delegate) {} : ProactiveSuggestionsView(delegate) {}
ProactiveSuggestionsRichView::~ProactiveSuggestionsRichView() { ProactiveSuggestionsRichView::~ProactiveSuggestionsRichView() {
if (contents_) if (contents_view_)
contents_->RemoveObserver(this); contents_view_->RemoveObserver(this);
} }
const char* ProactiveSuggestionsRichView::GetClassName() const { const char* ProactiveSuggestionsRichView::GetClassName() const {
...@@ -40,21 +42,19 @@ void ProactiveSuggestionsRichView::InitLayout() { ...@@ -40,21 +42,19 @@ void ProactiveSuggestionsRichView::InitLayout() {
chromeos::assistant::features:: chromeos::assistant::features::
GetProactiveSuggestionsRichEntryPointCornerRadius()); GetProactiveSuggestionsRichEntryPointCornerRadius());
// Initialize NavigableContentsFactory. // Initialize |contents_view_| params.
delegate()->GetNavigableContentsFactoryForView( AssistantWebView2::InitParams params;
contents_factory_.BindNewPipeAndPassReceiver()); params.enable_auto_resize = true;
params.min_size = gfx::Size(1, 1);
params.max_size = gfx::Size(INT_MAX, INT_MAX);
params.suppress_navigation = true;
// Initialize NavigableContentsParams. // Initialize |contents_view_|.
auto params = content::mojom::NavigableContentsParams::New(); // Note that we retain ownership of the underlying pointer so that it is
params->enable_view_auto_resize = true; // cleaned up in the event that the view is never added to the view hierarchy.
params->auto_resize_min_size = gfx::Size(1, 1); contents_view_ = AssistantWebViewFactory::Get()->Create(params);
params->auto_resize_max_size = gfx::Size(INT_MAX, INT_MAX); contents_view_->set_owned_by_client();
params->suppress_navigations = true; contents_view_->AddObserver(this);
// Initialize NavigableContents.
contents_ = std::make_unique<content::NavigableContents>(
contents_factory_.get(), std::move(params));
contents_->AddObserver(this);
// Encode the html for the entry point to be URL safe. // Encode the html for the entry point to be URL safe.
std::string encoded_html; std::string encoded_html;
...@@ -63,7 +63,7 @@ void ProactiveSuggestionsRichView::InitLayout() { ...@@ -63,7 +63,7 @@ void ProactiveSuggestionsRichView::InitLayout() {
// Navigate to the data URL representing our encoded HTML. // Navigate to the data URL representing our encoded HTML.
constexpr char kDataUriPrefix[] = "data:text/html;base64,"; constexpr char kDataUriPrefix[] = "data:text/html;base64,";
contents_->Navigate(GURL(kDataUriPrefix + encoded_html)); contents_view_->Navigate(GURL(kDataUriPrefix + encoded_html));
} }
void ProactiveSuggestionsRichView::AddedToWidget() { void ProactiveSuggestionsRichView::AddedToWidget() {
...@@ -75,6 +75,11 @@ void ProactiveSuggestionsRichView::AddedToWidget() { ...@@ -75,6 +75,11 @@ void ProactiveSuggestionsRichView::AddedToWidget() {
ui::ET_MOUSE_ENTERED, ui::ET_MOUSE_EXITED}); ui::ET_MOUSE_ENTERED, ui::ET_MOUSE_EXITED});
} }
void ProactiveSuggestionsRichView::ChildPreferredSizeChanged(
views::View* child) {
PreferredSizeChanged();
}
void ProactiveSuggestionsRichView::OnMouseEntered(const ui::MouseEvent& event) { void ProactiveSuggestionsRichView::OnMouseEntered(const ui::MouseEvent& event) {
// Our embedded web contents is expected to consume events that would // Our embedded web contents is expected to consume events that would
// otherwise reach our view. We instead handle these events in OnEvent(). // otherwise reach our view. We instead handle these events in OnEvent().
...@@ -133,19 +138,13 @@ void ProactiveSuggestionsRichView::Close() { ...@@ -133,19 +138,13 @@ void ProactiveSuggestionsRichView::Close() {
ProactiveSuggestionsView::Close(); ProactiveSuggestionsView::Close();
} }
void ProactiveSuggestionsRichView::DidAutoResizeView(
const gfx::Size& new_size) {
contents_->GetView()->view()->SetPreferredSize(new_size);
PreferredSizeChanged();
}
void ProactiveSuggestionsRichView::DidStopLoading() { void ProactiveSuggestionsRichView::DidStopLoading() {
AddChildView(contents_->GetView()->view()); AddChildView(contents_view_.get());
PreferredSizeChanged(); PreferredSizeChanged();
// Once the view for the embedded web contents has been fully initialized, // Once the view for the embedded web contents has been fully initialized,
// it's safe to set our desired corner radius. // it's safe to set our desired corner radius.
contents_->GetView()->native_view()->layer()->SetRoundedCornerRadius( contents_view_->GetNativeView()->layer()->SetRoundedCornerRadius(
gfx::RoundedCornersF( gfx::RoundedCornersF(
chromeos::assistant::features:: chromeos::assistant::features::
GetProactiveSuggestionsRichEntryPointCornerRadius())); GetProactiveSuggestionsRichEntryPointCornerRadius()));
......
...@@ -8,9 +8,8 @@ ...@@ -8,9 +8,8 @@
#include <memory> #include <memory>
#include "ash/assistant/ui/proactive_suggestions_view.h" #include "ash/assistant/ui/proactive_suggestions_view.h"
#include "ash/public/cpp/assistant/assistant_web_view_2.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
#include "services/content/public/cpp/navigable_contents.h"
#include "services/content/public/cpp/navigable_contents_view.h"
#include "ui/events/event_observer.h" #include "ui/events/event_observer.h"
namespace views { namespace views {
...@@ -26,7 +25,7 @@ class ViewShadow; ...@@ -26,7 +25,7 @@ class ViewShadow;
class COMPONENT_EXPORT(ASSISTANT_UI) ProactiveSuggestionsRichView class COMPONENT_EXPORT(ASSISTANT_UI) ProactiveSuggestionsRichView
: public ProactiveSuggestionsView, : public ProactiveSuggestionsView,
public ui::EventObserver, public ui::EventObserver,
public content::NavigableContentsObserver { public AssistantWebView2::Observer {
public: public:
explicit ProactiveSuggestionsRichView(AssistantViewDelegate* delegate); explicit ProactiveSuggestionsRichView(AssistantViewDelegate* delegate);
explicit ProactiveSuggestionsRichView(ProactiveSuggestionsRichView&) = delete; explicit ProactiveSuggestionsRichView(ProactiveSuggestionsRichView&) = delete;
...@@ -38,6 +37,7 @@ class COMPONENT_EXPORT(ASSISTANT_UI) ProactiveSuggestionsRichView ...@@ -38,6 +37,7 @@ class COMPONENT_EXPORT(ASSISTANT_UI) ProactiveSuggestionsRichView
const char* GetClassName() const override; const char* GetClassName() const override;
void InitLayout() override; void InitLayout() override;
void AddedToWidget() override; void AddedToWidget() override;
void ChildPreferredSizeChanged(views::View* child) override;
void ShowWhenReady() override; void ShowWhenReady() override;
void Hide() override; void Hide() override;
void Close() override; void Close() override;
...@@ -49,16 +49,14 @@ class COMPONENT_EXPORT(ASSISTANT_UI) ProactiveSuggestionsRichView ...@@ -49,16 +49,14 @@ class COMPONENT_EXPORT(ASSISTANT_UI) ProactiveSuggestionsRichView
using views::View::OnEvent; // Suppress clang warning. using views::View::OnEvent; // Suppress clang warning.
void OnEvent(const ui::Event& event) override; void OnEvent(const ui::Event& event) override;
// content::NavigableContentsObserver: // AssistantWebView2::Observer:
void DidAutoResizeView(const gfx::Size& new_size) override;
void DidStopLoading() override; void DidStopLoading() override;
void DidSuppressNavigation(const GURL& url, void DidSuppressNavigation(const GURL& url,
WindowOpenDisposition disposition, WindowOpenDisposition disposition,
bool from_user_gesture) override; bool from_user_gesture) override;
private: private:
mojo::Remote<content::mojom::NavigableContentsFactory> contents_factory_; std::unique_ptr<AssistantWebView2> contents_view_;
std::unique_ptr<content::NavigableContents> contents_;
std::unique_ptr<views::EventMonitor> event_monitor_; std::unique_ptr<views::EventMonitor> event_monitor_;
std::unique_ptr<ViewShadow> view_shadow_; std::unique_ptr<ViewShadow> view_shadow_;
......
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