Commit 599c0ac8 authored by Tommy Li's avatar Tommy Li Committed by Commit Bot

[omnibox] WebUIOmniboxPopup: Add Views => WebUI message handler plumbing

This CL adds the plumbing between Views and the WebUI message handler.

It introduces a new OmniboxPopupHandler class meant to keep the popup
related method calls separate from the chrome://omnibox calls.

Eventually, the WebUI popup will be entirely divorced from the
OmniboxPageHandler.

Bug: 1046561
Change-Id: I9636f602a1df9761cb3570bb71bc805b08edf138
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2072338Reviewed-by: default avatarmanuk hovanesian <manukh@chromium.org>
Commit-Queue: Tommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744398}
parent 967372fc
...@@ -1320,6 +1320,8 @@ jumbo_static_library("ui") { ...@@ -1320,6 +1320,8 @@ jumbo_static_library("ui") {
"webui/ntp/ntp_resource_cache.h", "webui/ntp/ntp_resource_cache.h",
"webui/ntp/ntp_resource_cache_factory.cc", "webui/ntp/ntp_resource_cache_factory.cc",
"webui/ntp/ntp_resource_cache_factory.h", "webui/ntp/ntp_resource_cache_factory.h",
"webui/omnibox/omnibox_popup_handler.cc",
"webui/omnibox/omnibox_popup_handler.h",
"webui/page_not_available_for_guest/page_not_available_for_guest_ui.cc", "webui/page_not_available_for_guest/page_not_available_for_guest_ui.cc",
"webui/page_not_available_for_guest/page_not_available_for_guest_ui.h", "webui/page_not_available_for_guest/page_not_available_for_guest_ui.h",
"webui/plural_string_handler.cc", "webui/plural_string_handler.cc",
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "chrome/browser/ui/views/omnibox/rounded_omnibox_results_frame.h" #include "chrome/browser/ui/views/omnibox/rounded_omnibox_results_frame.h"
#include "chrome/browser/ui/views/omnibox/webui_omnibox_popup_view.h" #include "chrome/browser/ui/views/omnibox/webui_omnibox_popup_view.h"
#include "chrome/browser/ui/views/theme_copying_widget.h" #include "chrome/browser/ui/views/theme_copying_widget.h"
#include "chrome/browser/ui/webui/omnibox/omnibox_popup_handler.h"
#include "components/omnibox/common/omnibox_features.h" #include "components/omnibox/common/omnibox_features.h"
#include "ui/accessibility/ax_node_data.h" #include "ui/accessibility/ax_node_data.h"
#include "ui/compositor/closure_animation_observer.h" #include "ui/compositor/closure_animation_observer.h"
...@@ -210,8 +211,10 @@ bool OmniboxPopupContentsView::IsOpen() const { ...@@ -210,8 +211,10 @@ bool OmniboxPopupContentsView::IsOpen() const {
} }
void OmniboxPopupContentsView::InvalidateLine(size_t line) { void OmniboxPopupContentsView::InvalidateLine(size_t line) {
if (base::FeatureList::IsEnabled(omnibox::kWebUIOmniboxPopup)) if (base::FeatureList::IsEnabled(omnibox::kWebUIOmniboxPopup)) {
return; // TODO(tommycli): Not implemented yet for WebUI. webui_view_->GetWebUIHandler()->InvalidateLine(line);
return;
}
OmniboxResultView* result = result_view_at(line); OmniboxResultView* result = result_view_at(line);
result->Invalidate(); result->Invalidate();
...@@ -224,8 +227,10 @@ void OmniboxPopupContentsView::InvalidateLine(size_t line) { ...@@ -224,8 +227,10 @@ void OmniboxPopupContentsView::InvalidateLine(size_t line) {
} }
void OmniboxPopupContentsView::OnSelectionStateChanged(size_t line) { void OmniboxPopupContentsView::OnSelectionStateChanged(size_t line) {
if (base::FeatureList::IsEnabled(omnibox::kWebUIOmniboxPopup)) if (base::FeatureList::IsEnabled(omnibox::kWebUIOmniboxPopup)) {
return; // TODO(tommycli): Not implemented yet for WebUI. webui_view_->GetWebUIHandler()->OnSelectionStateChanged(line);
return;
}
result_view_at(line)->OnSelectionStateChanged(); result_view_at(line)->OnSelectionStateChanged();
InvalidateLine(line); InvalidateLine(line);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/ui/views/omnibox/webui_omnibox_popup_view.h" #include "chrome/browser/ui/views/omnibox/webui_omnibox_popup_view.h"
#include "chrome/browser/ui/webui/omnibox/omnibox_ui.h"
#include "chrome/common/webui_url_constants.h" #include "chrome/common/webui_url_constants.h"
WebUIOmniboxPopupView::WebUIOmniboxPopupView( WebUIOmniboxPopupView::WebUIOmniboxPopupView(
...@@ -17,3 +18,12 @@ WebUIOmniboxPopupView::WebUIOmniboxPopupView( ...@@ -17,3 +18,12 @@ WebUIOmniboxPopupView::WebUIOmniboxPopupView(
constexpr char kOmniboxPopupUrl[] = "chrome://omnibox/omnibox_popup.html"; constexpr char kOmniboxPopupUrl[] = "chrome://omnibox/omnibox_popup.html";
LoadInitialURL(GURL(kOmniboxPopupUrl)); LoadInitialURL(GURL(kOmniboxPopupUrl));
} }
OmniboxPopupHandler* WebUIOmniboxPopupView::GetWebUIHandler() {
OmniboxUI* const omnibox_ui =
static_cast<OmniboxUI*>(GetWebContents()->GetWebUI()->GetController());
OmniboxPopupHandler* handler = omnibox_ui->popup_handler();
DCHECK(handler);
return handler;
}
...@@ -8,12 +8,16 @@ ...@@ -8,12 +8,16 @@
#include "base/macros.h" #include "base/macros.h"
#include "ui/views/controls/webview/webview.h" #include "ui/views/controls/webview/webview.h"
class OmniboxPopupHandler;
// A WebView to display suggestions in the Views autocomplete popup. // A WebView to display suggestions in the Views autocomplete popup.
class WebUIOmniboxPopupView : public views::WebView { class WebUIOmniboxPopupView : public views::WebView {
public: public:
explicit WebUIOmniboxPopupView(content::BrowserContext* browser_context); explicit WebUIOmniboxPopupView(content::BrowserContext* browser_context);
~WebUIOmniboxPopupView() override = default; ~WebUIOmniboxPopupView() override = default;
OmniboxPopupHandler* GetWebUIHandler();
DISALLOW_COPY_AND_ASSIGN(WebUIOmniboxPopupView); DISALLOW_COPY_AND_ASSIGN(WebUIOmniboxPopupView);
}; };
......
// 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 "chrome/browser/ui/webui/omnibox/omnibox_popup_handler.h"
OmniboxPopupHandler::OmniboxPopupHandler() = default;
// 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 CHROME_BROWSER_UI_WEBUI_OMNIBOX_OMNIBOX_POPUP_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_OMNIBOX_OMNIBOX_POPUP_HANDLER_H_
#include "base/macros.h"
#include "components/omnibox/browser/omnibox_popup_model.h"
// The WebUI handler for the experimental WebUI omnibox popup.
class OmniboxPopupHandler {
public:
OmniboxPopupHandler();
// These are roughly speaking analogues of the OmniboxPopupView API.
// TODO(tommycli): Update the OmniboxPopupView API to better suit WebUI.
void InvalidateLine(size_t line) {}
void OnSelectionStateChanged(size_t line) {}
DISALLOW_COPY_AND_ASSIGN(OmniboxPopupHandler);
};
#endif // CHROME_BROWSER_UI_WEBUI_OMNIBOX_OMNIBOX_POPUP_HANDLER_H_
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
#include "content/public/browser/web_ui_controller.h" #include "content/public/browser/web_ui_controller.h"
#include "content/public/browser/web_ui_data_source.h" #include "content/public/browser/web_ui_data_source.h"
#if !defined(OS_ANDROID)
#include "chrome/browser/ui/webui/omnibox/omnibox_popup_handler.h"
#endif
OmniboxUI::OmniboxUI(content::WebUI* web_ui) OmniboxUI::OmniboxUI(content::WebUI* web_ui)
: ui::MojoWebUIController(web_ui, /*enable_chrome_send=*/true) { : ui::MojoWebUIController(web_ui, /*enable_chrome_send=*/true) {
// Set up the chrome://omnibox/ source. // Set up the chrome://omnibox/ source.
...@@ -44,10 +48,14 @@ OmniboxUI::OmniboxUI(content::WebUI* web_ui) ...@@ -44,10 +48,14 @@ OmniboxUI::OmniboxUI(content::WebUI* web_ui)
IDR_OMNIBOX_MOJO_JS); IDR_OMNIBOX_MOJO_JS);
source->SetDefaultResource(IDR_OMNIBOX_HTML); source->SetDefaultResource(IDR_OMNIBOX_HTML);
#if !defined(OS_ANDROID)
if (base::FeatureList::IsEnabled(omnibox::kWebUIOmniboxPopup)) { if (base::FeatureList::IsEnabled(omnibox::kWebUIOmniboxPopup)) {
source->AddResourcePath("omnibox_popup.js", IDR_OMNIBOX_POPUP_JS); source->AddResourcePath("omnibox_popup.js", IDR_OMNIBOX_POPUP_JS);
source->AddResourcePath("omnibox_popup.html", IDR_OMNIBOX_POPUP_HTML); source->AddResourcePath("omnibox_popup.html", IDR_OMNIBOX_POPUP_HTML);
popup_handler_ = std::make_unique<OmniboxPopupHandler>();
} }
#endif
content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source); content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source);
web_ui->AddMessageHandler(std::make_unique<VersionHandler>()); web_ui->AddMessageHandler(std::make_unique<VersionHandler>());
......
...@@ -6,12 +6,17 @@ ...@@ -6,12 +6,17 @@
#define CHROME_BROWSER_UI_WEBUI_OMNIBOX_OMNIBOX_UI_H_ #define CHROME_BROWSER_UI_WEBUI_OMNIBOX_OMNIBOX_UI_H_
#include "base/macros.h" #include "base/macros.h"
#include "build/build_config.h"
#include "chrome/browser/ui/webui/omnibox/omnibox.mojom.h" #include "chrome/browser/ui/webui/omnibox/omnibox.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "ui/webui/mojo_web_ui_controller.h" #include "ui/webui/mojo_web_ui_controller.h"
class OmniboxPageHandler; class OmniboxPageHandler;
#if !defined(OS_ANDROID)
class OmniboxPopupHandler;
#endif
// The UI for chrome://omnibox/ // The UI for chrome://omnibox/
class OmniboxUI : public ui::MojoWebUIController { class OmniboxUI : public ui::MojoWebUIController {
public: public:
...@@ -22,9 +27,18 @@ class OmniboxUI : public ui::MojoWebUIController { ...@@ -22,9 +27,18 @@ class OmniboxUI : public ui::MojoWebUIController {
// interface passing the pending receiver that will be internally bound. // interface passing the pending receiver that will be internally bound.
void BindInterface(mojo::PendingReceiver<mojom::OmniboxPageHandler> receiver); void BindInterface(mojo::PendingReceiver<mojom::OmniboxPageHandler> receiver);
#if !defined(OS_ANDROID)
// This is needed for the Views native UI to call into the WebUI code.
OmniboxPopupHandler* popup_handler() { return popup_handler_.get(); }
#endif
private: private:
std::unique_ptr<OmniboxPageHandler> omnibox_handler_; std::unique_ptr<OmniboxPageHandler> omnibox_handler_;
#if !defined(OS_ANDROID)
std::unique_ptr<OmniboxPopupHandler> popup_handler_;
#endif
WEB_UI_CONTROLLER_TYPE_DECL(); WEB_UI_CONTROLLER_TYPE_DECL();
DISALLOW_COPY_AND_ASSIGN(OmniboxUI); DISALLOW_COPY_AND_ASSIGN(OmniboxUI);
......
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