Commit 0ebf3c59 authored by Richard Knoll's avatar Richard Knoll Committed by Commit Bot

Fix more WidgetObserver usages

These instances were found by adding a CHECK to the WidgetObserver DTOR
to ensure the observer is removed before destruction and then running
all tests.

Bug: 1055483
Change-Id: I83353f33962b00f0f922a21ebb0afb2131295482
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2165105
Commit-Queue: Richard Knoll <knollr@chromium.org>
Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#763422}
parent 9cdc65f2
...@@ -136,8 +136,8 @@ void FirstAppRunToastManager::CreateAndShowToastDialog() { ...@@ -136,8 +136,8 @@ void FirstAppRunToastManager::CreateAndShowToastDialog() {
base::UTF8ToUTF16(app_window_->GetExtension()->short_name()), base::UTF8ToUTF16(app_window_->GetExtension()->short_name()),
base::BindOnce(&FirstAppRunToastManager::ToastDialogDismissed, base::BindOnce(&FirstAppRunToastManager::ToastDialogDismissed,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
toast_dialog->Show(); toast_widget_ = views::BubbleDialogDelegateView::CreateBubble(toast_dialog);
toast_widget_ = toast_dialog->GetWidget(); toast_widget_->Show();
AdjustToastWidgetBounds(); AdjustToastWidgetBounds();
toast_widget_observer_.Add(toast_widget_); toast_widget_observer_.Add(toast_widget_);
} }
......
...@@ -75,19 +75,6 @@ ToastDialogView::ToastDialogView(const base::string16& app_name, ...@@ -75,19 +75,6 @@ ToastDialogView::ToastDialogView(const base::string16& app_name,
ToastDialogView::~ToastDialogView() = default; ToastDialogView::~ToastDialogView() = default;
void ToastDialogView::Show() {
views::Widget::InitParams params =
GetDialogWidgetInitParams(this, nullptr, nullptr, gfx::Rect());
ash_util::SetupWidgetInitParamsForContainer(
&params, ash::kShellWindowId_SettingBubbleContainer);
views::Widget* widget = new views::Widget; // owned by native widget
widget->Init(std::move(params));
widget->AddObserver(this);
widget->Show();
}
ui::ModalType ToastDialogView::GetModalType() const { ui::ModalType ToastDialogView::GetModalType() const {
return ui::MODAL_TYPE_NONE; return ui::MODAL_TYPE_NONE;
} }
...@@ -109,4 +96,11 @@ bool ToastDialogView::ShouldShowCloseButton() const { ...@@ -109,4 +96,11 @@ bool ToastDialogView::ShouldShowCloseButton() const {
return true; return true;
} }
void ToastDialogView::OnBeforeBubbleWidgetInit(
views::Widget::InitParams* params,
views::Widget* widget) const {
ash_util::SetupWidgetInitParamsForContainer(
params, ash::kShellWindowId_SettingBubbleContainer);
}
} // namespace lock_screen_apps } // namespace lock_screen_apps
...@@ -14,23 +14,20 @@ namespace lock_screen_apps { ...@@ -14,23 +14,20 @@ namespace lock_screen_apps {
// The system modal bubble dialog shown to the user when a lock screen app is // The system modal bubble dialog shown to the user when a lock screen app is
// first launched from the lock screen. The dialog will block the app UI until // first launched from the lock screen. The dialog will block the app UI until
// the uesr closes it. // the user closes it.
class ToastDialogView : public views::BubbleDialogDelegateView { class ToastDialogView : public views::BubbleDialogDelegateView {
public: public:
ToastDialogView(const base::string16& app_name, ToastDialogView(const base::string16& app_name,
base::OnceClosure dismissed_callback); base::OnceClosure dismissed_callback);
~ToastDialogView() override; ~ToastDialogView() override;
// Shows the toast dialog. // views::BubbleDialogDelegateView:
void Show();
// views::WidgetDelegate:
ui::ModalType GetModalType() const override; ui::ModalType GetModalType() const override;
base::string16 GetWindowTitle() const override; base::string16 GetWindowTitle() const override;
// views::BubbleDialogDelegate:
void AddedToWidget() override; void AddedToWidget() override;
bool ShouldShowCloseButton() const override; bool ShouldShowCloseButton() const override;
void OnBeforeBubbleWidgetInit(views::Widget::InitParams* params,
views::Widget* widget) const override;
private: private:
// The name of the app for which the dialog is shown. // The name of the app for which the dialog is shown.
......
...@@ -2393,6 +2393,7 @@ views::View* BrowserView::CreateOverlayView() { ...@@ -2393,6 +2393,7 @@ views::View* BrowserView::CreateOverlayView() {
} }
void BrowserView::OnWidgetDestroying(views::Widget* widget) { void BrowserView::OnWidgetDestroying(views::Widget* widget) {
widget_observer_.Remove(widget);
// Destroy any remaining WebContents early on. Doing so may result in // Destroy any remaining WebContents early on. Doing so may result in
// calling back to one of the Views/LayoutManagers or supporting classes of // calling back to one of the Views/LayoutManagers or supporting classes of
// BrowserView. By destroying here we ensure all said classes are valid. // BrowserView. By destroying here we ensure all said classes are valid.
...@@ -2640,7 +2641,7 @@ void BrowserView::ViewHierarchyChanged( ...@@ -2640,7 +2641,7 @@ void BrowserView::ViewHierarchyChanged(
void BrowserView::AddedToWidget() { void BrowserView::AddedToWidget() {
views::ClientView::AddedToWidget(); views::ClientView::AddedToWidget();
GetWidget()->AddObserver(this); widget_observer_.Add(GetWidget());
// Stow a pointer to this object onto the window handle so that we can get at // Stow a pointer to this object onto the window handle so that we can get at
// it later when all we have is a native view. // it later when all we have is a native view.
......
...@@ -870,6 +870,8 @@ class BrowserView : public BrowserWindow, ...@@ -870,6 +870,8 @@ class BrowserView : public BrowserWindow,
ScopedObserver<banners::AppBannerManager, banners::AppBannerManager::Observer> ScopedObserver<banners::AppBannerManager, banners::AppBannerManager::Observer>
app_banner_manager_observer_{this}; app_banner_manager_observer_{this};
ScopedObserver<views::Widget, views::WidgetObserver> widget_observer_{this};
bool interactive_resize_in_progress_ = false; bool interactive_resize_in_progress_ = false;
mutable base::WeakPtrFactory<BrowserView> activate_modal_dialog_factory_{ mutable base::WeakPtrFactory<BrowserView> activate_modal_dialog_factory_{
......
...@@ -179,7 +179,7 @@ Widget* BubbleDialogDelegateView::CreateBubble( ...@@ -179,7 +179,7 @@ Widget* BubbleDialogDelegateView::CreateBubble(
#endif #endif
bubble_delegate->SizeToContents(); bubble_delegate->SizeToContents();
bubble_widget->AddObserver(bubble_delegate); bubble_delegate->widget_observer_.Add(bubble_widget);
return bubble_widget; return bubble_widget;
} }
...@@ -203,8 +203,6 @@ BubbleDialogDelegateView::BubbleDialogDelegateView(View* anchor_view, ...@@ -203,8 +203,6 @@ BubbleDialogDelegateView::BubbleDialogDelegateView(View* anchor_view,
} }
BubbleDialogDelegateView::~BubbleDialogDelegateView() { BubbleDialogDelegateView::~BubbleDialogDelegateView() {
if (GetWidget())
GetWidget()->RemoveObserver(this);
SetLayoutManager(nullptr); SetLayoutManager(nullptr);
SetAnchorView(nullptr); SetAnchorView(nullptr);
} }
...@@ -263,6 +261,9 @@ void BubbleDialogDelegateView::OnWidgetClosing(Widget* widget) { ...@@ -263,6 +261,9 @@ void BubbleDialogDelegateView::OnWidgetClosing(Widget* widget) {
void BubbleDialogDelegateView::OnWidgetDestroying(Widget* widget) { void BubbleDialogDelegateView::OnWidgetDestroying(Widget* widget) {
if (anchor_widget() == widget) if (anchor_widget() == widget)
SetAnchorView(nullptr); SetAnchorView(nullptr);
if (widget_observer_.IsObserving(widget))
widget_observer_.Remove(widget);
} }
void BubbleDialogDelegateView::OnWidgetVisibilityChanging(Widget* widget, void BubbleDialogDelegateView::OnWidgetVisibilityChanging(Widget* widget,
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/scoped_observer.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "ui/accessibility/ax_enums.mojom-forward.h" #include "ui/accessibility/ax_enums.mojom-forward.h"
#include "ui/base/accelerators/accelerator.h" #include "ui/base/accelerators/accelerator.h"
...@@ -160,7 +161,6 @@ class VIEWS_EXPORT BubbleDialogDelegateView : public DialogDelegateView, ...@@ -160,7 +161,6 @@ class VIEWS_EXPORT BubbleDialogDelegateView : public DialogDelegateView,
void OnAnchorBoundsChanged(); void OnAnchorBoundsChanged();
protected: protected:
// Returns the desired arrow post-RTL mirroring if needed. // Returns the desired arrow post-RTL mirroring if needed.
BubbleBorder::Arrow arrow() const { return arrow_; } BubbleBorder::Arrow arrow() const { return arrow_; }
...@@ -284,6 +284,8 @@ class VIEWS_EXPORT BubbleDialogDelegateView : public DialogDelegateView, ...@@ -284,6 +284,8 @@ class VIEWS_EXPORT BubbleDialogDelegateView : public DialogDelegateView,
std::unique_ptr<ui::BubbleCloser> mac_bubble_closer_; std::unique_ptr<ui::BubbleCloser> mac_bubble_closer_;
#endif #endif
ScopedObserver<views::Widget, views::WidgetObserver> widget_observer_{this};
DISALLOW_COPY_AND_ASSIGN(BubbleDialogDelegateView); DISALLOW_COPY_AND_ASSIGN(BubbleDialogDelegateView);
}; };
......
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