File: desktop_media_pane_view.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; 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,806; 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 (117 lines) | stat: -rw-r--r-- 3,460 bytes parent folder | download | duplicates (6)
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
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/views/desktop_capture/desktop_media_pane_view.h"

#include <string_view>

#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/compositor/layer.h"
#include "ui/views/background.h"
#include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/separator.h"

#if BUILDFLAG(IS_MAC)
#include "chrome/browser/ui/views/desktop_capture/desktop_media_permission_pane_view_mac.h"
#endif

DesktopMediaPaneView::DesktopMediaPaneView(
    DesktopMediaList::Type type,
    std::unique_ptr<views::View> content_view,
    std::unique_ptr<ShareAudioView> share_audio_view)
#if BUILDFLAG(IS_MAC)
    : type_(type)
#endif
{
  layout_ = SetLayoutManager(std::make_unique<views::BoxLayout>(
      views::BoxLayout::Orientation::kVertical, gfx::Insets(0)));

  // TODO(crbug.com/339311813): Hide content_pane_view_ from the start if
  // lacking permission.
  content_pane_view_ =
      AddChildView(std::make_unique<DesktopMediaContentPaneView>(
          std::move(content_view), std::move(share_audio_view)));
  layout_->SetFlexForView(content_pane_view_, 1);
}

DesktopMediaPaneView::~DesktopMediaPaneView() = default;

bool DesktopMediaPaneView::AudioOffered() const {
  return content_pane_view_->AudioOffered();
}

bool DesktopMediaPaneView::IsAudioSharingApprovedByUser() const {
  return content_pane_view_->IsAudioSharingApprovedByUser();
}

void DesktopMediaPaneView::SetAudioSharingApprovedByUser(bool is_on) {
  content_pane_view_->SetAudioSharingApprovedByUser(is_on);
}

std::u16string_view DesktopMediaPaneView::GetAudioLabelText() const {
  return content_pane_view_->GetAudioLabelText();
}

bool DesktopMediaPaneView::IsPermissionPaneVisible() const {
#if BUILDFLAG(IS_MAC)
  return permission_pane_view_ && permission_pane_view_->GetVisible();
#else
  CHECK(!permission_pane_view_);
  return false;
#endif
}

bool DesktopMediaPaneView::IsContentPaneVisible() const {
  return content_pane_view_->GetVisible();
}

#if BUILDFLAG(IS_MAC)
void DesktopMediaPaneView::OnScreenCapturePermissionUpdate(
    bool has_permission) {
  if (!PermissionRequired()) {
    return;
  }

  if (!has_permission && !permission_pane_view_) {
    MakePermissionPaneView();
  }

  // permission_pane_view_ is only constructed when needed and otherwise the
  // visibilities do not need to be changed.
  if (permission_pane_view_) {
    content_pane_view_->SetVisible(has_permission);
    permission_pane_view_->SetVisible(!has_permission);
  }
}

bool DesktopMediaPaneView::WasPermissionButtonClicked() const {
  return permission_pane_view_ &&
         permission_pane_view_->WasPermissionButtonClicked();
}

bool DesktopMediaPaneView::PermissionRequired() const {
  switch (type_) {
    case DesktopMediaList::Type::kScreen:
    case DesktopMediaList::Type::kWindow:
      return true;

    case DesktopMediaList::Type::kNone:
    case DesktopMediaList::Type::kWebContents:
    case DesktopMediaList::Type::kCurrentTab:
      return false;
  }
  NOTREACHED();
}

void DesktopMediaPaneView::MakePermissionPaneView() {
  CHECK(!permission_pane_view_);

  permission_pane_view_ =
      AddChildView(std::make_unique<DesktopMediaPermissionPaneViewMac>(type_));
  layout_->SetFlexForView(permission_pane_view_, 1);
}
#endif  // BUILDFLAG(IS_MAC)

BEGIN_METADATA(DesktopMediaPaneView)
END_METADATA