1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
// Copyright 2018 The Chromium Authors
// 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_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_VIEWS_H_
#define CHROME_BROWSER_UI_VIEWS_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_VIEWS_H_
#include <memory>
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_multi_source_observation.h"
#include "chrome/browser/ui/media_router/media_router_ui_service.h"
#include "chrome/browser/ui/views/media_router/cast_dialog_coordinator.h"
#include "components/media_router/browser/media_router_dialog_controller.h"
#include "content/public/browser/web_contents_user_data.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_observer.h"
class MediaToolbarButtonView;
namespace media_router {
class MediaRouterUI;
class StartPresentationContext;
// A Views implementation of MediaRouterDialogController.
class MediaRouterDialogControllerViews
: public content::WebContentsUserData<MediaRouterDialogControllerViews>,
public MediaRouterDialogController,
public views::WidgetObserver,
public MediaRouterUIService::Observer {
public:
MediaRouterDialogControllerViews(const MediaRouterDialogControllerViews&) =
delete;
MediaRouterDialogControllerViews& operator=(
const MediaRouterDialogControllerViews&) = delete;
~MediaRouterDialogControllerViews() override;
// MediaRouterDialogController:
bool ShowMediaRouterDialogForPresentation(
std::unique_ptr<StartPresentationContext> context) override;
void CreateMediaRouterDialog(
MediaRouterDialogActivationLocation activation_location) override;
void CloseMediaRouterDialog() override;
bool IsShowingMediaRouterDialog() const override;
void Reset() override;
// views::WidgetObserver:
void OnWidgetDestroying(views::Widget* widget) override;
// Sets a callback to be called whenever a dialog is created.
void SetDialogCreationCallbackForTesting(base::RepeatingClosure callback);
void SetHideMediaButtonForTesting(bool hide);
CastDialogCoordinator& GetCastDialogCoordinatorForTesting() {
return cast_dialog_coordinator_;
}
private:
friend class content::WebContentsUserData<MediaRouterDialogControllerViews>;
friend class MediaRouterCastUiForTest;
// Use MediaRouterDialogController::GetOrCreateForWebContents() to create
// an instance.
explicit MediaRouterDialogControllerViews(content::WebContents* web_contents);
// MediaRouterUIService::Observer:
void OnServiceDisabled() override;
// Initializes and destroys |ui_| respectively.
void InitializeMediaRouterUI();
void DestroyMediaRouterUI();
#if BUILDFLAG(IS_CHROMEOS)
// Show the GMC dialog in the Ash UI.
void ShowGlobalMediaControlsDialog(
std::unique_ptr<StartPresentationContext> context);
#else
// If there exists a media button, show the GMC dialog anchored to the media
// button. Otherwise, show the dialog anchored to the top center of the web
// contents.
void ShowGlobalMediaControlsDialogAsync(
std::unique_ptr<StartPresentationContext> context);
void ShowGlobalMediaControlsDialog();
#endif // BUILDFLAG(IS_CHROMEOS)
// Returns the media button from the browser that initiates the request to
// open the dialog. Returns nullptr if:
// (1) the browser does not have a media button (i.e. the browser is
// running a PWA.) or (2) |hide_media_button_for_testing_| is true.
MediaToolbarButtonView* GetMediaButton();
// CastToolbarButtonController is responsible for showing and hiding the
// toolbar action. It's owned by MediaRouterUIService and it may be nullptr.
CastToolbarButtonController* GetActionController();
MediaRouterUI* ui() { return ui_.get(); }
// Responsible for notifying the dialog view of dialog model updates and
// sending route requests to MediaRouter. Set to nullptr when the dialog is
// closed. Not used for presentation requests.
std::unique_ptr<MediaRouterUI> ui_;
CastDialogCoordinator cast_dialog_coordinator_;
base::RepeatingClosure dialog_creation_callback_;
base::ScopedMultiSourceObservation<views::Widget, views::WidgetObserver>
scoped_widget_observations_{this};
// Service that provides CastToolbarButtonController. It outlives |this|.
const raw_ptr<MediaRouterUIService> media_router_ui_service_;
bool hide_media_button_for_testing_ = false;
base::WeakPtrFactory<MediaRouterDialogControllerViews> weak_ptr_factory_{
this};
WEB_CONTENTS_USER_DATA_KEY_DECL();
};
} // namespace media_router
#endif // CHROME_BROWSER_UI_VIEWS_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_VIEWS_H_
|