Commit b80de0f5 authored by John Williams's avatar John Williams Committed by Commit Bot

[Media Router] Show global media controls from Presentation API.

The Presentation API is invoked when the user clicks the Cast button
in a web page.

This change only takes effect when the
GlobalMediaControlsOverlayControls and
GlobalMediaControlsCastStartStop features are both enabled.

Bug: 1107160, b/161612085
Change-Id: I086d8e4928a80e0a2b0f247d9a62a573e024f254
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2317087
Commit-Queue: John Williams <jrw@chromium.org>
Reviewed-by: default avatarmark a. foltz <mfoltz@chromium.org>
Reviewed-by: default avatarTakumi Fujimoto <takumif@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801117}
parent dc90f233
# Note: don't add "+chrome/browser/ui" here, because it will
# cause a circular dependency. See crbug.com/1030821.
include_rules = [
"+components/openscreen_platform",
"+services/network",
......
......@@ -47,7 +47,7 @@ class MediaRouterDialogController {
// Returns true if the dialog is created as a result of this call.
// If the dialog already exists, or dialog cannot be created, then false is
// returned, and |error_cb| will be invoked.
bool ShowMediaRouterDialogForPresentation(
virtual bool ShowMediaRouterDialogForPresentation(
std::unique_ptr<StartPresentationContext> context);
// Shows the media router dialog modal to |initiator_|.
......
......@@ -131,9 +131,10 @@ bool CastMediaRouteProviderEnabled() {
}
bool GlobalMediaControlsCastStartStopEnabled() {
return base::FeatureList::IsEnabled(
media::kGlobalMediaControlsOverlayControls) &&
base::FeatureList::IsEnabled(kGlobalMediaControlsCastStartStop);
return base::FeatureList::IsEnabled(kGlobalMediaControlsCastStartStop) &&
base::FeatureList::IsEnabled(media::kGlobalMediaControlsForCast) &&
base::FeatureList::IsEnabled(
media::kGlobalMediaControlsOverlayControls);
}
#endif // !defined(OS_ANDROID)
......
......@@ -27,8 +27,8 @@ MediaDialogView* MediaDialogView::instance_ = nullptr;
bool MediaDialogView::has_been_opened_ = false;
// static
void MediaDialogView::ShowDialog(views::View* anchor_view,
MediaNotificationService* service) {
views::Widget* MediaDialogView::ShowDialog(views::View* anchor_view,
MediaNotificationService* service) {
DCHECK(!instance_);
DCHECK(service);
instance_ = new MediaDialogView(anchor_view, service);
......@@ -40,6 +40,8 @@ void MediaDialogView::ShowDialog(views::View* anchor_view,
base::UmaHistogramBoolean("Media.GlobalMediaControls.RepeatUsage",
has_been_opened_);
has_been_opened_ = true;
return widget;
}
// static
......
......@@ -21,8 +21,8 @@ class MediaDialogView : public views::BubbleDialogDelegateView,
public MediaDialogDelegate,
public MediaNotificationContainerObserver {
public:
static void ShowDialog(views::View* anchor_view,
MediaNotificationService* service);
static views::Widget* ShowDialog(views::View* anchor_view,
MediaNotificationService* service);
static void HideDialog();
static bool IsShowing();
......
......@@ -9,8 +9,12 @@
#include "build/build_config.h"
#include "chrome/browser/media/router/media_router_feature.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/global_media_controls/media_notification_service.h"
#include "chrome/browser/ui/global_media_controls/media_notification_service_factory.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/top_container_view.h"
#include "chrome/browser/ui/views/global_media_controls/media_dialog_view.h"
#include "chrome/browser/ui/views/global_media_controls/media_toolbar_button_view.h"
#include "chrome/browser/ui/views/media_router/cast_dialog_view.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "content/public/browser/web_contents.h"
......@@ -44,6 +48,38 @@ MediaRouterDialogControllerViews::~MediaRouterDialogControllerViews() {
media_router_ui_service_->RemoveObserver(this);
}
bool MediaRouterDialogControllerViews::ShowMediaRouterDialogForPresentation(
std::unique_ptr<StartPresentationContext> context) {
if (GlobalMediaControlsCastStartStopEnabled()) {
// Show global media controls instead of the Cast dialog.
Profile* const profile =
Profile::FromBrowserContext(initiator()->GetBrowserContext());
MediaNotificationService* const service =
MediaNotificationServiceFactory::GetForProfile(profile);
Browser* const browser = chrome::FindBrowserWithWebContents(initiator());
BrowserView* const browser_view =
browser ? BrowserView::GetBrowserViewForBrowser(browser) : nullptr;
ToolbarView* const toolbar_view =
browser_view ? browser_view->toolbar() : nullptr;
MediaToolbarButtonView* const media_button =
toolbar_view ? toolbar_view->media_button() : nullptr;
// TODO(crbug/1111120): When |media_button| is null, we want to show the
// global media controls anchored to the top of the web contents. As it is
// now, it shows the dialog in the wrong place with a big blue border around
// it. Fixing the position probably involves doing something similar to the
// computation of |anchor_bounds| in CreateMediaRouterDialog() below, but
// just doing the same thing here doesn't work. I suspect that approach
// will work, though, once the issue causing the blue border is fixed.
scoped_widget_observer_.Add(
MediaDialogView::ShowDialog(media_button, service));
return true;
} else {
// Delegate to the base class, which will show the Cast dialog.
return MediaRouterDialogController::ShowMediaRouterDialogForPresentation(
std::move(context));
}
}
void MediaRouterDialogControllerViews::CreateMediaRouterDialog(
MediaRouterDialogOpenOrigin activation_location) {
base::Time dialog_creation_time = base::Time::Now();
......@@ -52,10 +88,11 @@ void MediaRouterDialogControllerViews::CreateMediaRouterDialog(
Profile* profile =
Profile::FromBrowserContext(initiator()->GetBrowserContext());
InitializeMediaRouterUI();
InitializeMediaRouterUI();
Browser* browser = chrome::FindBrowserWithWebContents(initiator());
if (browser) {
// Show the Cast dialog anchored to the Cast toolbar button.
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
if (browser_view->toolbar()->cast_button()) {
CastDialogView::ShowDialogWithToolbarAction(
......@@ -65,6 +102,7 @@ void MediaRouterDialogControllerViews::CreateMediaRouterDialog(
ui_.get(), browser, dialog_creation_time, activation_location);
}
} else {
// Show the Cast dialog anchored to the top of the web contents.
gfx::Rect anchor_bounds = initiator()->GetContainerBounds();
// Set the height to 0 so that the dialog gets anchored to the top of the
// window.
......@@ -74,6 +112,7 @@ void MediaRouterDialogControllerViews::CreateMediaRouterDialog(
activation_location);
}
scoped_widget_observer_.Add(CastDialogView::GetCurrentDialogWidget());
if (dialog_creation_callback_)
dialog_creation_callback_.Run();
}
......
......@@ -28,6 +28,8 @@ class MediaRouterDialogControllerViews
~MediaRouterDialogControllerViews() override;
// MediaRouterDialogController:
bool ShowMediaRouterDialogForPresentation(
std::unique_ptr<StartPresentationContext> context) override;
void CreateMediaRouterDialog(
MediaRouterDialogOpenOrigin activation_location) override;
void CloseMediaRouterDialog() override;
......@@ -62,7 +64,8 @@ class MediaRouterDialogControllerViews
// Responsible for notifying the dialog view of dialog model updates and
// sending route requests to MediaRouter. Set to nullptr when the dialog is
// closed.
// closed. Not used for presentation requests when
// GlobalMediaControlsCastStartStopEnabled() returns true.
std::unique_ptr<MediaRouterViewsUI> ui_;
base::RepeatingClosure dialog_creation_callback_;
......
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