File: access_code_cast_dialog.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 (121 lines) | stat: -rw-r--r-- 4,634 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
// Copyright 2022 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_WEBUI_ACCESS_CODE_CAST_ACCESS_CODE_CAST_DIALOG_H_
#define CHROME_BROWSER_UI_WEBUI_ACCESS_CODE_CAST_ACCESS_CODE_CAST_DIALOG_H_

#include "base/check_is_test.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/media_router/media_cast_mode.h"
#include "chrome/browser/ui/media_router/media_route_starter.h"
#include "components/access_code_cast/common/access_code_cast_metrics.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_observer.h"
#include "ui/web_dialogs/web_dialog_delegate.h"

namespace content {
class WebContents;
}  // namespace content

namespace media_router {

enum class AccessCodeCastDialogMode {
  // Dialog opened from the browser. This will match the styling of other
  // browser dialogs (i.e. Cast dialog), and will be positioned in the center of
  // the window and overlapping top-chrome.
  kBrowserStandard = 0,
  // Dialog is shown system modal, and matches the style for ChromeOS system
  // dialogs.
  kSystem = 1,
};

class AccessCodeCastDialog : public ui::WebDialogDelegate,
                             public views::WidgetObserver {
 public:
  AccessCodeCastDialog(
      const media_router::CastModeSet& cast_mode_set,
      std::unique_ptr<media_router::MediaRouteStarter> media_route_starter);
  ~AccessCodeCastDialog() override;
  AccessCodeCastDialog(const AccessCodeCastDialog&) = delete;
  AccessCodeCastDialog& operator=(const AccessCodeCastDialog&) = delete;

  static void Show(
      const media_router::CastModeSet& cast_mode_set,
      std::unique_ptr<media_router::MediaRouteStarter> media_route_starter,
      AccessCodeCastDialogOpenLocation open_location,
      AccessCodeCastDialogMode dialog_mode =
          AccessCodeCastDialogMode::kBrowserStandard);

  // Show the access code dialog box for desktop mirroring.
  static void ShowForDesktopMirroring(
      AccessCodeCastDialogOpenLocation open_location);

  void CloseDialogWidget();

  // views::WidgetObserver:
  void OnWidgetActivationChanged(views::Widget* widget, bool active) override;

  // Blocks the widget automatically closing
  // when focus changes. This is to counter flaky tests.
  static void ShouldBlockWidgetActivationChangedForTest(bool should_block) {
    CHECK_IS_TEST();
    block_widget_activation_changed_for_test_ = should_block;
  }

  base::WeakPtr<AccessCodeCastDialog> GetWeakPtr();

 protected:
  // Creates default params for showing AccessCodeCastDialog
  virtual views::Widget::InitParams CreateParams(
      AccessCodeCastDialogMode dialog_mode);

 private:
  void OnDialogShown(content::WebUI* webui) override;
  void OnCloseContents(content::WebContents* source,
                       bool* out_close_dialog) override;
  void RequestMediaAccessPermission(
      content::WebContents* web_contents,
      const content::MediaStreamRequest& request,
      content::MediaResponseCallback callback) override;
  bool CheckMediaAccessPermission(content::RenderFrameHost* render_frame_host,
                                  const url::Origin& security_origin,
                                  blink::mojom::MediaStreamType type) override;

  // Displays the dialog
  void ShowWebDialog(AccessCodeCastDialogMode dialog_mode);

  gfx::NativeView GetParentView();

  raw_ptr<views::Widget> dialog_widget_ = nullptr;
  raw_ptr<content::WebUI> webui_ = nullptr;
  // Cast modes that should be attempted.
  const media_router::CastModeSet cast_mode_set_;

  // Important to note that this is a temporary placeholder - as soon as the
  // dialog is shown the pointer held by media_route_starter_ will be
  // moved to |AccessCodeCastUI|, so no |AccessCodeCastDialog| code should make
  // use of the media_route_starter_ pointer after c'tor.
  std::unique_ptr<media_router::MediaRouteStarter> media_route_starter_;

  const raw_ptr<content::WebContents, AcrossTasksDanglingUntriaged>
      web_contents_;
  const raw_ptr<Profile> context_;
  base::Time dialog_creation_timestamp_;
  bool closing_dialog_ = false;

  base::ScopedObservation<views::Widget, views::WidgetObserver>
      widget_observation_{this};

  static bool block_widget_activation_changed_for_test_;

  base::WeakPtrFactory<AccessCodeCastDialog> weak_ptr_factory_{this};
};

}  // namespace media_router

#endif  // CHROME_BROWSER_UI_WEBUI_ACCESS_CODE_CAST_ACCESS_CODE_CAST_DIALOG_H_