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

Remove AnswerCardContentsRegistry and WebContentsManager.

Previously AnswerCardContentsRegistry was used by AppList and Assistant
to embed WebContents in Ash, although this would not work in Mash.
Assistant used AnswerCardContentsRegistry in conjunction with
WebContentsManager to embed Assistant cards.

Now, we have migrated to Content Service which renders these classes
no longer needed.

AppList was transitioned in:
https://chromium-review.googlesource.com/c/chromium/src/+/1269622

Assistant was transitioned in:
https://chromium-review.googlesource.com/c/chromium/src/+/1313745
https://chromium-review.googlesource.com/c/chromium/src/+/1321861

Bug: b:78078693
Change-Id: I5b855b6ff24722524b600eb1032960210c0233f7
Reviewed-on: https://chromium-review.googlesource.com/c/1325430
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607089}
parent 93772f30
......@@ -17,7 +17,6 @@
#include "ash/app_list/views/search_box_view.h"
#include "ash/assistant/assistant_controller.h"
#include "ash/assistant/assistant_ui_controller.h"
#include "ash/public/cpp/app_list/answer_card_contents_registry.h"
#include "ash/public/cpp/app_list/app_list_features.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/session/session_controller.h"
......@@ -45,17 +44,6 @@ AppListControllerImpl::AppListControllerImpl()
is_home_launcher_enabled_(app_list_features::IsHomeLauncherEnabled()) {
model_.AddObserver(this);
// Create only for non-mash. Mash uses window tree embed API to get a
// token to map answer card contents.
//
// TODO(https://crbug.com/894987): This is now only used (as a singleton) by
// assistant UI code to display its answer card contents. It can be removed
// once that code is ported to use Content Service.
if (!::features::IsUsingWindowService()) {
answer_card_contents_registry_ =
std::make_unique<app_list::AnswerCardContentsRegistry>();
}
SessionController* session_controller = Shell::Get()->session_controller();
session_controller->AddObserver(this);
......
......@@ -30,10 +30,6 @@
#include "mojo/public/cpp/bindings/interface_ptr_set.h"
#include "ui/keyboard/keyboard_controller_observer.h"
namespace app_list {
class AnswerCardContentsRegistry;
} // namespace app_list
namespace ui {
class MouseWheelEvent;
} // namespace ui
......@@ -267,12 +263,6 @@ class ASH_EXPORT AppListControllerImpl
// Bindings for the AppListController interface.
mojo::BindingSet<mojom::AppListController> bindings_;
// TODO(https://crbug.com/894987): Remove this once assistant UI is converted
// to use Content Service, as there will then be no more consumers of
// AnswerCardContentsRegistry.
std::unique_ptr<app_list::AnswerCardContentsRegistry>
answer_card_contents_registry_;
// Owned pointer to the object which handles gestures related to the home
// launcher.
std::unique_ptr<HomeLauncherGestureHandler> home_launcher_gesture_handler_;
......
......@@ -23,7 +23,6 @@
#include "ash/voice_interaction/voice_interaction_controller.h"
#include "base/bind.h"
#include "base/memory/scoped_refptr.h"
#include "base/unguessable_token.h"
#include "services/content/public/mojom/constants.mojom.h"
#include "services/service_manager/public/cpp/connector.h"
......@@ -108,11 +107,6 @@ void AssistantController::SetAssistantSetup(
assistant_setup_controller_->SetAssistantSetup(assistant_setup_.get());
}
void AssistantController::SetWebContentsManager(
mojom::WebContentsManagerPtr web_contents_manager) {
web_contents_manager_ = std::move(web_contents_manager);
}
// TODO(dmblack): Expose AssistantScreenContextController over mojo rather
// than implementing RequestScreenshot here in AssistantController.
void AssistantController::RequestScreenshot(
......@@ -127,50 +121,6 @@ void AssistantController::OpenAssistantSettings() {
OpenUrl(assistant::util::CreateAssistantSettingsDeepLink());
}
void AssistantController::ManageWebContents(
const base::UnguessableToken& id_token,
mojom::ManagedWebContentsParamsPtr params,
mojom::WebContentsManager::ManageWebContentsCallback callback) {
DCHECK(web_contents_manager_);
const mojom::UserSession* user_session =
Shell::Get()->session_controller()->GetUserSession(0);
if (!user_session) {
LOG(WARNING) << "Unable to retrieve active user session.";
std::move(callback).Run(base::nullopt);
return;
}
// Supply account ID.
params->account_id = user_session->user_info->account_id;
// Specify that we will handle top level browser requests.
ash::mojom::ManagedWebContentsOpenUrlDelegatePtr ptr;
web_contents_open_url_delegate_bindings_.AddBinding(this,
mojo::MakeRequest(&ptr));
params->open_url_delegate_ptr_info = ptr.PassInterface();
web_contents_manager_->ManageWebContents(id_token, std::move(params),
std::move(callback));
}
void AssistantController::ReleaseWebContents(
const base::UnguessableToken& id_token) {
web_contents_manager_->ReleaseWebContents(id_token);
}
void AssistantController::ReleaseWebContents(
const std::vector<base::UnguessableToken>& id_tokens) {
web_contents_manager_->ReleaseAllWebContents(id_tokens);
}
void AssistantController::NavigateWebContentsBack(
const base::UnguessableToken& id_token,
mojom::WebContentsManager::NavigateWebContentsBackCallback callback) {
web_contents_manager_->NavigateWebContentsBack(id_token, std::move(callback));
}
void AssistantController::DownloadImage(
const GURL& url,
mojom::AssistantImageDownloader::DownloadCallback callback) {
......@@ -229,34 +179,6 @@ void AssistantController::OnDeepLinkReceived(
}
}
void AssistantController::ShouldOpenUrlFromTab(
const GURL& url,
WindowOpenDisposition disposition,
ash::mojom::ManagedWebContentsOpenUrlDelegate::ShouldOpenUrlFromTabCallback
callback) {
// We always handle deep links ourselves.
if (assistant::util::IsDeepLinkUrl(url)) {
std::move(callback).Run(/*should_open=*/false);
NotifyDeepLinkReceived(url);
return;
}
AssistantUiMode ui_mode = assistant_ui_controller_->model()->ui_mode();
// When in main UI mode, WebContents should not navigate as they are hosting
// Assistant cards. Instead, we route navigation attempts to the browser. We
// also respect open |disposition| to launch in the browser if appropriate.
if (ui_mode == AssistantUiMode::kMainUi ||
disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB) {
std::move(callback).Run(/*should_open=*/false);
OpenUrl(url);
return;
}
// In all other cases WebContents should be able to navigate freely.
std::move(callback).Run(/*should_open=*/true);
}
void AssistantController::SetVolume(int volume, bool user_initiated) {
volume = std::min(100, volume);
volume = std::max(volume, 0);
......
......@@ -19,7 +19,6 @@
#include "ash/public/interfaces/assistant_setup.mojom.h"
#include "ash/public/interfaces/assistant_volume_control.mojom.h"
#include "ash/public/interfaces/voice_interaction_controller.mojom.h"
#include "ash/public/interfaces/web_contents_manager.mojom.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
......@@ -30,10 +29,6 @@
#include "services/content/public/mojom/navigable_contents_factory.mojom.h"
#include "ui/gfx/geometry/rect.h"
namespace base {
class UnguessableToken;
} // namespace base
namespace ash {
class AssistantCacheController;
......@@ -46,7 +41,6 @@ class AssistantUiController;
class ASH_EXPORT AssistantController
: public mojom::AssistantController,
public AssistantControllerObserver,
public mojom::ManagedWebContentsOpenUrlDelegate,
public DefaultVoiceInteractionObserver,
public mojom::AssistantVolumeControl,
public chromeos::CrasAudioHandler::AudioObserver,
......@@ -62,30 +56,6 @@ class ASH_EXPORT AssistantController
void AddObserver(AssistantControllerObserver* observer);
void RemoveObserver(AssistantControllerObserver* observer);
// Requests that WebContents, uniquely identified by |id_token|, be created
// and managed according to the specified |params|. When the WebContents is
// ready for embedding, the supplied |callback| is run with an embed token. In
// the event that an error occurs, the supplied callback will still be run but
// no embed token will be provided.
void ManageWebContents(
const base::UnguessableToken& id_token,
mojom::ManagedWebContentsParamsPtr params,
mojom::WebContentsManager::ManageWebContentsCallback callback);
// Releases resources for the WebContents uniquely identified by |id_token|.
void ReleaseWebContents(const base::UnguessableToken& id_token);
// Releases resources for any WebContents uniquely identified in
// |id_token_list|.
void ReleaseWebContents(const std::vector<base::UnguessableToken>& id_tokens);
// Navigates the WebContents uniquely identified by |id_token| back relative
// to the current history entry. The supplied |callback| will run specifying
// true if navigation occurred, false otherwise.
void NavigateWebContentsBack(
const base::UnguessableToken& id_token,
mojom::WebContentsManager::NavigateWebContentsBackCallback callback);
// Downloads the image found at the specified |url|. On completion, the
// supplied |callback| will be run with the downloaded image. If the download
// attempt is unsuccessful, a NULL image is returned.
......@@ -102,8 +72,6 @@ class ASH_EXPORT AssistantController
void SetAssistantImageDownloader(
mojom::AssistantImageDownloaderPtr assistant_image_downloader) override;
void SetAssistantSetup(mojom::AssistantSetupPtr assistant_setup) override;
void SetWebContentsManager(
mojom::WebContentsManagerPtr web_contents_manager) override;
void RequestScreenshot(const gfx::Rect& rect,
RequestScreenshotCallback callback) override;
void OpenAssistantSettings() override;
......@@ -113,13 +81,6 @@ class ASH_EXPORT AssistantController
assistant::util::DeepLinkType type,
const std::map<std::string, std::string>& params) override;
// mojom::ManagedWebContentsOpenUrlDelegate:
void ShouldOpenUrlFromTab(
const GURL& url,
WindowOpenDisposition disposition,
mojom::ManagedWebContentsOpenUrlDelegate::ShouldOpenUrlFromTabCallback
callback) override;
// mojom::VolumeControl:
void SetVolume(int volume, bool user_initiated) override;
void SetMuted(bool muted) override;
......@@ -189,9 +150,6 @@ class ASH_EXPORT AssistantController
mojo::BindingSet<mojom::AssistantController> assistant_controller_bindings_;
mojo::BindingSet<mojom::ManagedWebContentsOpenUrlDelegate>
web_contents_open_url_delegate_bindings_;
mojo::Binding<mojom::AssistantVolumeControl>
assistant_volume_control_binding_;
mojo::InterfacePtrSet<mojom::VolumeObserver> volume_observer_;
......@@ -202,8 +160,6 @@ class ASH_EXPORT AssistantController
mojom::AssistantSetupPtr assistant_setup_;
mojom::WebContentsManagerPtr web_contents_manager_;
std::unique_ptr<AssistantCacheController> assistant_cache_controller_;
std::unique_ptr<AssistantInteractionController>
......
......@@ -212,20 +212,17 @@ void AssistantWebView::DidSuppressNavigation(const GURL& url,
if (!from_user_gesture)
return;
// We defer to |assistant_controller_| to tell us if we should allow
// navigation to continue or not as we, in some cases, intercept navigation
// to perform special handling for deep links, etc.
assistant_controller_->ShouldOpenUrlFromTab(
url, disposition,
base::BindOnce(
[](const base::WeakPtr<AssistantWebView>& assistant_web_view,
const GURL& url, bool should_navigate) {
// If the navigation attempt hasn't been specially handled we can
// allow the web contents to continue navigating.
if (should_navigate && assistant_web_view)
assistant_web_view->contents_->Navigate(url);
},
weak_factory_.GetWeakPtr(), url));
// Deep links are always handled by AssistantController. If the |disposition|
// indicates a desire to open a new foreground tab, we also defer to the
// AssistantController so that it can open the |url| in the browser.
if (assistant::util::IsDeepLinkUrl(url) ||
disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB) {
assistant_controller_->OpenUrl(url);
return;
}
// Otherwise we'll allow our web contents to navigate freely.
contents_->Navigate(url);
}
void AssistantWebView::RemoveContents() {
......
......@@ -9,8 +9,6 @@ component("cpp") {
sources = [
"accelerators.cc",
"accelerators.h",
"app_list/answer_card_contents_registry.cc",
"app_list/answer_card_contents_registry.h",
"app_list/app_list_config.cc",
"app_list/app_list_config.h",
"app_list/app_list_constants.cc",
......
// 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.
#include "ash/public/cpp/app_list/answer_card_contents_registry.h"
#include "base/logging.h"
namespace app_list {
namespace {
AnswerCardContentsRegistry* instance = nullptr;
} // namespace
AnswerCardContentsRegistry::AnswerCardContentsRegistry() {
DCHECK(!instance);
instance = this;
}
AnswerCardContentsRegistry::~AnswerCardContentsRegistry() {
DCHECK_EQ(this, instance);
instance = nullptr;
}
// static
AnswerCardContentsRegistry* AnswerCardContentsRegistry::Get() {
return instance;
}
base::UnguessableToken AnswerCardContentsRegistry::Register(
views::View* contents_view,
gfx::NativeView contents_native_view) {
const base::UnguessableToken token = base::UnguessableToken::Create();
contents_map_[token] = {contents_view, contents_native_view};
return token;
}
void AnswerCardContentsRegistry::Unregister(
const base::UnguessableToken& token) {
auto it = contents_map_.find(token);
if (it == contents_map_.end())
return;
contents_map_.erase(it);
}
views::View* AnswerCardContentsRegistry::GetView(
const base::UnguessableToken& token) {
auto it = contents_map_.find(token);
if (it == contents_map_.end())
return nullptr;
return it->second.view;
}
gfx::NativeView AnswerCardContentsRegistry::GetNativeView(
const base::UnguessableToken& token) {
auto it = contents_map_.find(token);
if (it == contents_map_.end())
return nullptr;
return it->second.native_view;
}
} // namespace app_list
// 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.
#ifndef ASH_PUBLIC_CPP_APP_LIST_ANSWER_CARD_CONTENTS_REGISTRY_H_
#define ASH_PUBLIC_CPP_APP_LIST_ANSWER_CARD_CONTENTS_REGISTRY_H_
#include <map>
#include "ash/public/cpp/ash_public_export.h"
#include "base/macros.h"
#include "base/unguessable_token.h"
#include "ui/gfx/native_widget_types.h"
namespace views {
class View;
}
namespace app_list {
// Helper class to provide a token to answer card view map when app list UI code
// runs in the same process of answer card provider (classic ash, or mash before
// UI code is migrated to ash). In such environment, chrome creates and owns an
// instance of this class. AnswerCardContents registers answer card contents
// with it and get a token back. App list UI code gets the token and use it to
// look up the view to show. On mash after the UI code migration, this class
// will NOT be used at all. App list UI code would use the token to embed the
// answer card content directly.
class ASH_PUBLIC_EXPORT AnswerCardContentsRegistry {
public:
AnswerCardContentsRegistry();
~AnswerCardContentsRegistry();
static AnswerCardContentsRegistry* Get();
// Register content with a View and its relevant NativeView.
base::UnguessableToken Register(views::View* contents_view,
gfx::NativeView contents_native_view);
// Unregister and release the associated resources.
void Unregister(const base::UnguessableToken& token);
// Get the view for the given token. Return nullptr for unknown token.
views::View* GetView(const base::UnguessableToken& token);
gfx::NativeView GetNativeView(const base::UnguessableToken& token);
private:
struct Entry {
views::View* view;
gfx::NativeView native_view;
};
std::map<base::UnguessableToken, Entry> contents_map_;
DISALLOW_COPY_AND_ASSIGN(AnswerCardContentsRegistry);
};
} // namespace app_list
#endif // ASH_PUBLIC_CPP_APP_LIST_ANSWER_CARD_CONTENTS_REGISTRY_H_
......@@ -60,7 +60,6 @@ mojom("interfaces_internal") {
"volume.mojom",
"vpn_list.mojom",
"wallpaper.mojom",
"web_contents_manager.mojom",
"window_pin_type.mojom",
"window_properties.mojom",
"window_state_type.mojom",
......
......@@ -5,7 +5,6 @@
module ash.mojom;
import "ash/public/interfaces/assistant_image_downloader.mojom";
import "ash/public/interfaces/web_contents_manager.mojom";
import "ash/public/interfaces/assistant_setup.mojom";
import "chromeos/services/assistant/public/mojom/assistant.mojom";
import "ui/gfx/geometry/mojo/geometry.mojom";
......@@ -23,10 +22,6 @@ interface AssistantController {
SetAssistantImageDownloader(
AssistantImageDownloader assistant_image_downloader);
// Provides an interface to the |web_contents_manager| owned by
// AssistantClient.
SetWebContentsManager(WebContentsManager web_contents_manager);
// Provides an interface to the |assistant_setup| owned by AssistantClient.
SetAssistantSetup(AssistantSetup assistant_setup);
......
// 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/unguessable_token.mojom";
import "ui/base/mojo/window_open_disposition.mojom";
import "ui/gfx/geometry/mojo/geometry.mojom";
import "url/mojom/url.mojom";
// Interface for a class which is responsible for managing a WebContents in
// chrome/browser and owning associated resources until they are explicity
// released using the provided APIs.
interface WebContentsManager {
// Creates and manages WebContents as defined by the specified |params|. Any
// call to ManageWebContents should be paired with a corresponding call to
// ReleaseWebContents when the resources are no longer needed. To this end,
// the caller must supply an identifier by which to uniquely identify
// WebContents resources. When the rendered content is ready for embedding,
// the supplied callback will be run providing an unguessable |embed_token|.
// In the event of failure, the callback will still be run but no
// |embed_token| will be provided.
ManageWebContents(mojo_base.mojom.UnguessableToken id_token,
ManagedWebContentsParams params)
=> (mojo_base.mojom.UnguessableToken? embed_token);
// Releases any resources associated with the WebContents uniquely identified
// by |id_token|.
ReleaseWebContents(mojo_base.mojom.UnguessableToken id_token);
// Releases any resources associated with any WebContents uniquely identified
// by one of the specified |id_tokens|.
ReleaseAllWebContents(array<mojo_base.mojom.UnguessableToken> id_tokens);
// Navigates the WebContents uniquely identified by |id_token| back relative
// to the current history entry. The callback returns true if the WebContents
// were navigated, false otherwise.
NavigateWebContentsBack(mojo_base.mojom.UnguessableToken id_token)
=> (bool navigated);
};
// Defines parameters for a managed WebContents.
struct ManagedWebContentsParams {
// The account identifier for the profile.
signin.mojom.AccountId account_id;
// The initial URL.
url.mojom.Url url;
// The minimum desired size. Omitting defaults to (1, 1).
gfx.mojom.Size? min_size_dip;
// The maximum desired size. Omitting defaults to (INT_MAX, INT_MAX).
gfx.mojom.Size? max_size_dip;
// An optional delegate to handle top level browser requests. If omitted, top
// level browser requests will be handled according to default behavior.
ManagedWebContentsOpenUrlDelegate? open_url_delegate_ptr_info;
};
// Interface for a delegate to handle top level browser requests for a
// managed WebContents.
interface ManagedWebContentsOpenUrlDelegate {
// Invoked on a top level browser request to navigate to |url| with the
// specified window open |disposition|. Return false to consume the
// navigation attempt or true to allow it to continue.
ShouldOpenUrlFromTab(url.mojom.Url url,
ui.mojom.WindowOpenDisposition disposition) => (bool should_open);
};
......@@ -3278,8 +3278,6 @@ jumbo_split_static_library("ui") {
"ash/assistant/assistant_setup.h",
"ash/assistant/device_actions.cc",
"ash/assistant/device_actions.h",
"ash/assistant/web_contents_manager.cc",
"ash/assistant/web_contents_manager.h",
]
}
......
......@@ -13,7 +13,6 @@
#include "chrome/browser/ui/ash/assistant/assistant_context_util.h"
#include "chrome/browser/ui/ash/assistant/assistant_image_downloader.h"
#include "chrome/browser/ui/ash/assistant/assistant_setup.h"
#include "chrome/browser/ui/ash/assistant/web_contents_manager.h"
#include "chromeos/services/assistant/public/mojom/constants.mojom.h"
#include "services/service_manager/public/cpp/connector.h"
......@@ -64,7 +63,6 @@ void AssistantClient::MaybeInit(service_manager::Connector* connector) {
assistant_image_downloader_ =
std::make_unique<AssistantImageDownloader>(connector);
web_contents_manager_ = std::make_unique<WebContentsManager>(connector);
assistant_setup_ = std::make_unique<AssistantSetup>(connector);
}
......
......@@ -17,7 +17,6 @@ class Connector;
} // namespace service_manager
class AssistantImageDownloader;
class WebContentsManager;
class AssistantSetup;
// Class to handle all assistant in-browser-process functionalities.
......@@ -46,8 +45,6 @@ class AssistantClient : chromeos::assistant::mojom::Client {
std::unique_ptr<AssistantImageDownloader> assistant_image_downloader_;
std::unique_ptr<AssistantSetup> assistant_setup_;
std::unique_ptr<WebContentsManager> web_contents_manager_;
bool initialized_ = false;
DISALLOW_COPY_AND_ASSIGN(AssistantClient);
......
// 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.
#ifndef CHROME_BROWSER_UI_ASH_ASSISTANT_WEB_CONTENTS_MANAGER_H_
#define CHROME_BROWSER_UI_ASH_ASSISTANT_WEB_CONTENTS_MANAGER_H_
#include <map>
#include <vector>
#include "ash/public/interfaces/web_contents_manager.mojom.h"
#include "base/macros.h"
#include "mojo/public/cpp/bindings/binding.h"
class ManagedWebContents;
namespace service_manager {
class Connector;
} // namespace service_manager
// WebContentsManager is responsible for rendering WebContents and owning their
// associated resources in chrome/browser for others to embed. In order to
// ensure resources live only as long as is necessary, any call to
// ManageWebContents should be paired with a corresponding call to
// ReleaseWebContents when the resources are no longer needed. As such, the
// caller of ManageWebContents must provide a unique identifier by which to
// identify managed resources.
class WebContentsManager : public ash::mojom::WebContentsManager {
public:
explicit WebContentsManager(service_manager::Connector* connector);
~WebContentsManager() override;
// ash::mojom::WebContentsManager:
void ManageWebContents(
const base::UnguessableToken& id_token,
ash::mojom::ManagedWebContentsParamsPtr params,
ash::mojom::WebContentsManager::ManageWebContentsCallback callback)
override;
void ReleaseWebContents(const base::UnguessableToken& id_token) override;
void ReleaseAllWebContents(
const std::vector<base::UnguessableToken>& id_tokens) override;
void NavigateWebContentsBack(
const base::UnguessableToken& id_token,
ash::mojom::WebContentsManager::NavigateWebContentsBackCallback callback)
override;
private:
mojo::Binding<ash::mojom::WebContentsManager> binding_;
std::map<base::UnguessableToken, std::unique_ptr<ManagedWebContents>>
managed_web_contents_map_;
DISALLOW_COPY_AND_ASSIGN(WebContentsManager);
};
#endif // CHROME_BROWSER_UI_ASH_ASSISTANT_WEB_CONTENTS_MANAGER_H_
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