File: media_router_dialog_controller_views.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (127 lines) | stat: -rw-r--r-- 4,704 bytes parent folder | download | duplicates (5)
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_