Commit 9b03340a authored by Collin Baker's avatar Collin Baker Committed by Commit Bot

Fix crash when tab with media dragged to new window

Creating a new window for a tab playing media shows the medial toolbar
button immediately. With a recent change, it would then attempt to get
the window's BrowserView. But BrowserView::GetBrowserViewForBrowser()
returns nullptr when called during BrowserView construction resulting
in a crash.

This CL changes MediaToolbarButtonView to take the BrowserView on
construction instead.

Fixed: 1130921, 1130897
Change-Id: Ica879fe9825c4ef1af2789169bffb49da28370b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2423551Reviewed-by: default avatarAbigail Klein <abigailbklein@google.com>
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809365}
parent 206e4c01
......@@ -30,11 +30,12 @@
#include "ui/views/animation/ink_drop.h"
#include "ui/views/controls/button/button_controller.h"
MediaToolbarButtonView::MediaToolbarButtonView(const Browser* browser)
MediaToolbarButtonView::MediaToolbarButtonView(BrowserView* browser_view)
: ToolbarButton(this),
service_(
MediaNotificationServiceFactory::GetForProfile(browser->profile())),
browser_(browser) {
browser_(browser_view->browser()),
service_(MediaNotificationServiceFactory::GetForProfile(
browser_view->browser()->profile())),
feature_promo_controller_(browser_view->feature_promo_controller()) {
GlobalMediaControlsInProductHelp* global_media_controls_in_product_help =
GlobalMediaControlsInProductHelpFactory::GetForProfile(
browser_->profile());
......@@ -162,14 +163,10 @@ void MediaToolbarButtonView::OnPromoEnded() {
}
void MediaToolbarButtonView::EnsurePromoController() {
if (!promo_controller_) {
promo_controller_ = std::make_unique<GlobalMediaControlsPromoController>(
this, browser_->profile());
AddObserver(promo_controller_.get());
}
if (promo_controller_)
return;
if (!feature_promo_controller_) {
feature_promo_controller_ = BrowserView::GetBrowserViewForBrowser(browser_)
->feature_promo_controller();
}
promo_controller_ = std::make_unique<GlobalMediaControlsPromoController>(
this, browser_->profile());
AddObserver(promo_controller_.get());
}
......@@ -10,6 +10,7 @@
#include "chrome/browser/ui/views/toolbar/toolbar_button.h"
class Browser;
class BrowserView;
class FeaturePromoControllerViews;
class GlobalMediaControlsPromoController;
class MediaNotificationService;
......@@ -23,7 +24,7 @@ class MediaToolbarButtonView : public ToolbarButton,
public MediaToolbarButtonControllerDelegate,
public views::ButtonListener {
public:
explicit MediaToolbarButtonView(const Browser* browser);
explicit MediaToolbarButtonView(BrowserView* browser_view);
~MediaToolbarButtonView() override;
void AddObserver(MediaToolbarButtonObserver* observer);
......@@ -65,18 +66,20 @@ class MediaToolbarButtonView : public ToolbarButton,
void InformIPHOfButtonEnabled();
void InformIPHOfButtonDisabledorHidden();
// Shows the in-product help bubble.
std::unique_ptr<GlobalMediaControlsPromoController> promo_controller_;
const Browser* const browser_;
MediaNotificationService* const service_;
// The window's IPH promo controller.
FeaturePromoControllerViews* feature_promo_controller_ = nullptr;
FeaturePromoControllerViews* const feature_promo_controller_;
// Shows the in-product help bubble.
std::unique_ptr<GlobalMediaControlsPromoController> promo_controller_;
// True if the in-product help bubble is currently showing.
bool is_promo_showing_ = false;
MediaNotificationService* const service_;
std::unique_ptr<MediaToolbarButtonController> controller_;
const Browser* const browser_;
base::ObserverList<MediaToolbarButtonObserver> observers_;
......
......@@ -228,7 +228,7 @@ void ToolbarView::Init() {
std::unique_ptr<MediaToolbarButtonView> media_button;
if (base::FeatureList::IsEnabled(media::kGlobalMediaControls)) {
media_button = std::make_unique<MediaToolbarButtonView>(browser_);
media_button = std::make_unique<MediaToolbarButtonView>(browser_view_);
}
std::unique_ptr<ToolbarAccountIconContainerView>
......
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