Commit 5d650580 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

cbui: remove ChooserBubbleUi

This change removes the last BubbleDelegate subclass in //chrome.
Specifically:
1) ChooserBubbleUiViewDelegate is now a subclass of
   LocationBarBubbleDelegateView, so that it will close on cross-origin
   navigations and fullscreen transitions; this behavior was previously
   provided by ChromeBubbleManager
2) ChooserBubbleUi is now removed, along with all references to it

The next steps in this refactor are:
1) Removing the now-dead ChromeBubbleManager and all references to it
2) Removing BubbleUi itself, since ChromeBubbleManager is the last
   reference to it

Bug: 496955
Change-Id: I558cecf89dee6c1dce987a678e2f25805f6f1f82
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2109972
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751996}
parent 83baeabc
...@@ -3258,8 +3258,6 @@ jumbo_static_library("ui") { ...@@ -3258,8 +3258,6 @@ jumbo_static_library("ui") {
"views/payments/view_stack.cc", "views/payments/view_stack.cc",
"views/payments/view_stack.h", "views/payments/view_stack.h",
"views/permission_bubble/chooser_bubble_ui.cc", "views/permission_bubble/chooser_bubble_ui.cc",
"views/permission_bubble/chooser_bubble_ui.h",
"views/permission_bubble/chooser_bubble_ui_views.cc",
"views/permission_bubble/permission_prompt_bubble_view.cc", "views/permission_bubble/permission_prompt_bubble_view.cc",
"views/permission_bubble/permission_prompt_bubble_view.h", "views/permission_bubble/permission_prompt_bubble_view.h",
"views/permission_bubble/permission_prompt_impl.cc", "views/permission_bubble/permission_prompt_impl.cc",
......
...@@ -10,19 +10,19 @@ ...@@ -10,19 +10,19 @@
#include "chrome/browser/chooser_controller/fake_bluetooth_chooser_controller.h" #include "chrome/browser/chooser_controller/fake_bluetooth_chooser_controller.h"
#include "chrome/browser/chooser_controller/fake_usb_chooser_controller.h" #include "chrome/browser/chooser_controller/fake_usb_chooser_controller.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/test/test_browser_dialog.h" #include "chrome/browser/ui/test/test_browser_dialog.h"
#include "chrome/browser/ui/views/extensions/chooser_dialog_view.h" #include "chrome/browser/ui/views/extensions/chooser_dialog_view.h"
#include "chrome/browser/ui/views/permission_bubble/chooser_bubble_ui.h"
#include "components/constrained_window/constrained_window_views.h" #include "components/constrained_window/constrained_window_views.h"
namespace { namespace {
void ShowChooserBubble(Browser* browser, void ShowChooserBubble(Browser* browser,
std::unique_ptr<ChooserController> controller) { std::unique_ptr<ChooserController> controller) {
auto bubble = auto* contents = browser->tab_strip_model()->GetActiveWebContents();
std::make_unique<ChooserBubbleUi>(browser, std::move(controller)); chrome::ShowDeviceChooserDialog(contents->GetMainFrame(),
bubble->Show(nullptr); std::move(controller));
} }
void ShowChooserModal(Browser* browser, void ShowChooserModal(Browser* browser,
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/ui/views/permission_bubble/chooser_bubble_ui.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "chrome/browser/chooser_controller/chooser_controller.h" #include "chrome/browser/chooser_controller/chooser_controller.h"
...@@ -13,6 +11,7 @@ ...@@ -13,6 +11,7 @@
#include "chrome/browser/ui/permission_bubble/chooser_bubble_delegate.h" #include "chrome/browser/ui/permission_bubble/chooser_bubble_delegate.h"
#include "chrome/browser/ui/views/bubble_anchor_util_views.h" #include "chrome/browser/ui/views/bubble_anchor_util_views.h"
#include "chrome/browser/ui/views/device_chooser_content_view.h" #include "chrome/browser/ui/views/device_chooser_content_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_bubble_delegate_view.h"
#include "chrome/browser/ui/views/title_origin_label.h" #include "chrome/browser/ui/views/title_origin_label.h"
#include "components/bubble/bubble_controller.h" #include "components/bubble/bubble_controller.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h" #include "ui/views/bubble/bubble_dialog_delegate_view.h"
...@@ -38,11 +37,12 @@ gfx::Rect GetChooserAnchorRect(Browser* browser) { ...@@ -38,11 +37,12 @@ gfx::Rect GetChooserAnchorRect(Browser* browser) {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// View implementation for the chooser bubble. // View implementation for the chooser bubble.
class ChooserBubbleUiViewDelegate : public views::BubbleDialogDelegateView, class ChooserBubbleUiViewDelegate : public LocationBarBubbleDelegateView,
public views::TableViewObserver { public views::TableViewObserver {
public: public:
ChooserBubbleUiViewDelegate( ChooserBubbleUiViewDelegate(
Browser* browser, Browser* browser,
content::WebContents* web_contents,
std::unique_ptr<ChooserController> chooser_controller); std::unique_ptr<ChooserController> chooser_controller);
~ChooserBubbleUiViewDelegate() override; ~ChooserBubbleUiViewDelegate() override;
...@@ -71,7 +71,6 @@ class ChooserBubbleUiViewDelegate : public views::BubbleDialogDelegateView, ...@@ -71,7 +71,6 @@ class ChooserBubbleUiViewDelegate : public views::BubbleDialogDelegateView,
private: private:
DeviceChooserContentView* device_chooser_content_view_ = nullptr; DeviceChooserContentView* device_chooser_content_view_ = nullptr;
BubbleReference bubble_reference_;
base::WeakPtrFactory<ChooserBubbleUiViewDelegate> weak_ptr_factory_{this}; base::WeakPtrFactory<ChooserBubbleUiViewDelegate> weak_ptr_factory_{this};
...@@ -80,7 +79,11 @@ class ChooserBubbleUiViewDelegate : public views::BubbleDialogDelegateView, ...@@ -80,7 +79,11 @@ class ChooserBubbleUiViewDelegate : public views::BubbleDialogDelegateView,
ChooserBubbleUiViewDelegate::ChooserBubbleUiViewDelegate( ChooserBubbleUiViewDelegate::ChooserBubbleUiViewDelegate(
Browser* browser, Browser* browser,
std::unique_ptr<ChooserController> chooser_controller) { content::WebContents* contents,
std::unique_ptr<ChooserController> chooser_controller)
: LocationBarBubbleDelegateView(
GetChooserAnchorConfiguration(browser).anchor_view,
contents) {
// ------------------------------------ // ------------------------------------
// | Chooser bubble title | // | Chooser bubble title |
// | -------------------------------- | // | -------------------------------- |
...@@ -108,27 +111,16 @@ ChooserBubbleUiViewDelegate::ChooserBubbleUiViewDelegate( ...@@ -108,27 +111,16 @@ ChooserBubbleUiViewDelegate::ChooserBubbleUiViewDelegate(
DialogDelegate::SetExtraView(device_chooser_content_view_->CreateExtraView()); DialogDelegate::SetExtraView(device_chooser_content_view_->CreateExtraView());
using ContentViewFn = void (DeviceChooserContentView::*)(); DialogDelegate::SetAcceptCallback(
auto closure_callback = [](ChooserBubbleUiViewDelegate* dialog, base::BindOnce(&DeviceChooserContentView::Accept,
ContentViewFn func, base::Unretained(device_chooser_content_view_)));
base::Optional<BubbleCloseReason> reason) { DialogDelegate::SetCancelCallback(
(dialog->device_chooser_content_view_->*func)(); base::BindOnce(&DeviceChooserContentView::Cancel,
if (reason.has_value() && dialog->bubble_reference_) base::Unretained(device_chooser_content_view_)));
dialog->bubble_reference_->CloseBubble(reason.value());
};
DialogDelegate::SetAcceptCallback(base::BindOnce(
closure_callback, base::Unretained(this),
&DeviceChooserContentView::Accept,
base::make_optional<BubbleCloseReason>(BUBBLE_CLOSE_ACCEPTED)));
DialogDelegate::SetCancelCallback(base::BindOnce(
closure_callback, base::Unretained(this),
&DeviceChooserContentView::Cancel,
base::make_optional<BubbleCloseReason>(BUBBLE_CLOSE_CANCELED)));
DialogDelegate::SetCloseCallback( DialogDelegate::SetCloseCallback(
base::BindOnce(closure_callback, base::Unretained(this), base::BindOnce(&DeviceChooserContentView::Close,
&DeviceChooserContentView::Close, base::nullopt)); base::Unretained(device_chooser_content_view_)));
UpdateAnchor(browser);
chrome::RecordDialogCreation(chrome::DialogIdentifier::CHOOSER_UI); chrome::RecordDialogCreation(chrome::DialogIdentifier::CHOOSER_UI);
} }
...@@ -164,11 +156,6 @@ void ChooserBubbleUiViewDelegate::UpdateAnchor(Browser* browser) { ...@@ -164,11 +156,6 @@ void ChooserBubbleUiViewDelegate::UpdateAnchor(Browser* browser) {
SetArrow(configuration.bubble_arrow); SetArrow(configuration.bubble_arrow);
} }
void ChooserBubbleUiViewDelegate::set_bubble_reference(
BubbleReference bubble_reference) {
bubble_reference_ = bubble_reference;
}
void ChooserBubbleUiViewDelegate::UpdateTableView() const { void ChooserBubbleUiViewDelegate::UpdateTableView() const {
device_chooser_content_view_->UpdateTableView(); device_chooser_content_view_->UpdateTableView();
} }
...@@ -183,62 +170,18 @@ void ChooserBubbleUiViewDelegate::Close() { ...@@ -183,62 +170,18 @@ void ChooserBubbleUiViewDelegate::Close() {
GetWidget()->CloseWithReason(views::Widget::ClosedReason::kUnspecified); GetWidget()->CloseWithReason(views::Widget::ClosedReason::kUnspecified);
} }
//////////////////////////////////////////////////////////////////////////////
// ChooserBubbleUi
ChooserBubbleUi::ChooserBubbleUi(
Browser* browser,
std::unique_ptr<ChooserController> chooser_controller)
: browser_(browser), chooser_bubble_ui_view_delegate_(nullptr) {
DCHECK(browser_);
DCHECK(chooser_controller);
chooser_bubble_ui_view_delegate_ =
new ChooserBubbleUiViewDelegate(browser, std::move(chooser_controller));
}
ChooserBubbleUi::~ChooserBubbleUi() {
if (chooser_bubble_ui_view_delegate_ &&
chooser_bubble_ui_view_delegate_->GetWidget()) {
chooser_bubble_ui_view_delegate_->GetWidget()->RemoveObserver(this);
}
}
void ChooserBubbleUi::Show(BubbleReference bubble_reference) {
chooser_bubble_ui_view_delegate_->set_bubble_reference(bubble_reference);
chooser_bubble_ui_view_delegate_->UpdateAnchor(browser_);
CreateAndShow(chooser_bubble_ui_view_delegate_);
chooser_bubble_ui_view_delegate_->GetWidget()->AddObserver(this);
chooser_bubble_ui_view_delegate_->UpdateTableView();
}
void ChooserBubbleUi::Close() {
if (chooser_bubble_ui_view_delegate_ &&
!chooser_bubble_ui_view_delegate_->GetWidget()->IsClosed()) {
chooser_bubble_ui_view_delegate_->GetWidget()->Close();
}
}
void ChooserBubbleUi::UpdateAnchorPosition() {
if (chooser_bubble_ui_view_delegate_)
chooser_bubble_ui_view_delegate_->UpdateAnchor(browser_);
}
void ChooserBubbleUi::OnWidgetClosing(views::Widget* widget) {
widget->RemoveObserver(this);
chooser_bubble_ui_view_delegate_ = nullptr;
}
namespace chrome { namespace chrome {
base::OnceClosure ShowDeviceChooserDialog( base::OnceClosure ShowDeviceChooserDialog(
content::RenderFrameHost* owner, content::RenderFrameHost* owner,
std::unique_ptr<ChooserController> controller) { std::unique_ptr<ChooserController> controller) {
Browser* browser = chrome::FindBrowserWithWebContents( auto* contents = content::WebContents::FromRenderFrameHost(owner);
content::WebContents::FromRenderFrameHost(owner)); auto* browser = chrome::FindBrowserWithWebContents(contents);
if (!browser) if (!browser)
return base::DoNothing(); return base::DoNothing();
auto bubble = std::make_unique<ChooserBubbleUiViewDelegate>( auto bubble = std::make_unique<ChooserBubbleUiViewDelegate>(
browser, std::move(controller)); browser, contents, std::move(controller));
// Set |parent_window_| because some valid anchors can become hidden. // Set |parent_window_| because some valid anchors can become hidden.
views::Widget* parent_widget = views::Widget::GetWidgetForNativeWindow( views::Widget* parent_widget = views::Widget::GetWidgetForNativeWindow(
......
// Copyright 2015 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_VIEWS_PERMISSION_BUBBLE_CHOOSER_BUBBLE_UI_H_
#define CHROME_BROWSER_UI_VIEWS_PERMISSION_BUBBLE_CHOOSER_BUBBLE_UI_H_
#include <memory>
#include "base/macros.h"
#include "components/bubble/bubble_ui.h"
#include "ui/views/widget/widget_observer.h"
namespace views {
class BubbleDialogDelegateView;
}
class Browser;
class ChooserController;
class ChooserBubbleUiViewDelegate;
// ChooserBubbleUi implements a chooser-based permission model,
// it uses table view to show a list of items (such as usb devices, etc.)
// for user to grant permission. It can be used by the WebUSB or WebBluetooth
// APIs. It is owned by the BubbleController, which is owned by the
// BubbleManager.
class ChooserBubbleUi : public BubbleUi, public views::WidgetObserver {
public:
ChooserBubbleUi(Browser* browser,
std::unique_ptr<ChooserController> chooser_controller);
~ChooserBubbleUi() override;
// BubbleUi
void Show(BubbleReference bubble_reference) override;
void Close() override;
void UpdateAnchorPosition() override;
// views::WidgetObserver
void OnWidgetClosing(views::Widget* widget) override;
private:
void CreateAndShow(views::BubbleDialogDelegateView* delegate);
Browser* const browser_; // Weak.
// Weak. Owned by its parent view.
ChooserBubbleUiViewDelegate* chooser_bubble_ui_view_delegate_;
DISALLOW_COPY_AND_ASSIGN(ChooserBubbleUi);
};
#endif // CHROME_BROWSER_UI_VIEWS_PERMISSION_BUBBLE_CHOOSER_BUBBLE_UI_H_
// Copyright 2017 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/views/permission_bubble/chooser_bubble_ui.h"
#include <memory>
#include "build/build_config.h"
#include "build/buildflag.h"
#include "chrome/browser/chooser_controller/chooser_controller.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/permission_bubble/chooser_bubble_delegate.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/widget/widget.h"
// The Views browser implementation of ChooserBubbleUi's anchor methods.
// Views browsers have a native View to anchor the bubble to, which these
// functions provide.
std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() {
return std::make_unique<ChooserBubbleUi>(browser_,
std::move(chooser_controller_));
}
void ChooserBubbleUi::CreateAndShow(views::BubbleDialogDelegateView* delegate) {
// Set |parent_window_| because some valid anchors can become hidden.
views::Widget* widget = views::Widget::GetWidgetForNativeWindow(
browser_->window()->GetNativeWindow());
gfx::NativeView parent = widget->GetNativeView();
DCHECK(parent);
delegate->set_parent_window(parent);
if (browser_->window()->IsActive())
views::BubbleDialogDelegateView::CreateBubble(delegate)->Show();
else
views::BubbleDialogDelegateView::CreateBubble(delegate)->ShowInactive();
}
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