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