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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
|
// Copyright 2014 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_DESKTOP_CAPTURE_DESKTOP_MEDIA_PICKER_VIEWS_H_
#define CHROME_BROWSER_UI_VIEWS_DESKTOP_CAPTURE_DESKTOP_MEDIA_PICKER_VIEWS_H_
#include <string>
#include "base/memory/raw_ptr.h"
#include "base/types/expected.h"
#include "build/build_config.h"
#include "chrome/browser/media/webrtc/desktop_media_picker.h"
#include "chrome/browser/ui/views/desktop_capture/desktop_media_list_controller.h"
#include "chrome/browser/ui/views/desktop_capture/desktop_media_pane_view.h"
#include "chrome/browser/ui/views/desktop_capture/screen_capture_permission_checker.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/mojom/dialog_button.mojom.h"
#include "ui/views/controls/button/toggle_button.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/tabbed_pane/tabbed_pane_listener.h"
#include "ui/views/window/dialog_delegate.h"
namespace views {
class TabbedPane;
class MdTextButton;
} // namespace views
class DesktopMediaPickerImpl;
const DesktopMediaSourceViewStyle& GetGenericScreenStyle();
const DesktopMediaSourceViewStyle& GetSingleScreenStyle();
// Dialog view used for DesktopMediaPickerImpl.
//
// TODO(crbug.com/40637301): Consider renaming this class.
class DesktopMediaPickerDialogView : public views::DialogDelegateView,
public views::TabbedPaneListener {
METADATA_HEADER(DesktopMediaPickerDialogView, views::DialogDelegateView)
public:
DesktopMediaPickerDialogView(
const DesktopMediaPicker::Params& params,
DesktopMediaPickerImpl* parent,
std::vector<std::unique_ptr<DesktopMediaList>> source_lists);
DesktopMediaPickerDialogView(const DesktopMediaPickerDialogView&) = delete;
DesktopMediaPickerDialogView& operator=(const DesktopMediaPickerDialogView&) =
delete;
~DesktopMediaPickerDialogView() override;
void RecordUmaDismissal() const;
// Called by parent (DesktopMediaPickerImpl) when it's destroyed.
void DetachParent();
// Called by DesktopMediaListController.
void OnSelectionChanged();
void AcceptSource();
void AcceptSpecificSource(const content::DesktopMediaID& source);
void Reject();
void OnSourceListLayoutChanged();
void OnDelegatedSourceListDismissed();
void OnCanReselectChanged(const DesktopMediaListController* controller);
// views::TabbedPaneListener:
void TabSelectedAt(int index) override;
// views::DialogDelegateView:
gfx::Size CalculatePreferredSize(
const views::SizeBounds& /*available_size*/) const override;
std::u16string GetWindowTitle() const override;
bool IsDialogButtonEnabled(ui::mojom::DialogButton button) const override;
views::View* GetInitiallyFocusedView() override;
bool Accept() override;
bool Cancel() override;
bool ShouldShowCloseButton() const override;
void OnWidgetInitialized() override;
private:
friend class DesktopMediaPickerViewsTestApi;
struct DisplaySurfaceCategory {
DisplaySurfaceCategory(
DesktopMediaList::Type type,
std::unique_ptr<DesktopMediaListController> controller,
bool audio_offered,
bool audio_checked,
bool supports_reselect_button);
DisplaySurfaceCategory(DisplaySurfaceCategory&& other);
~DisplaySurfaceCategory();
DesktopMediaList::Type type;
std::unique_ptr<DesktopMediaListController> controller;
// TODO(crbug.com/397167331): Fix `audio_offered`, which is misleading.
bool audio_offered; // Whether the audio-checkbox should be visible.
bool audio_checked; // Whether the audio-checkbox is checked.
// Whether to show a button to allow re-selecting a choice within this
// category. Primarily used if there is a separate selection surface that we
// may need to re-open.
bool supports_reselect_button;
raw_ptr<DesktopMediaPaneView> pane = nullptr;
};
// Whether audio-capture is supported for display surfaces of type `type`.
bool AudioSupported(DesktopMediaList::Type type) const;
// Whether audio-capture is requested for display surfaces of type `type`.
//
// While getDisplayMedia({audio: true}) would normally ask for audio for
// all display surfaces of types where audio-capture is supported,
// there are options that Web apps can use in order to specify that the
// user should only be prompted for audio if a specific type is used.
// (For example, excluding system-audio or window-audio.)
bool AudioRequestedForType(DesktopMediaList::Type type) const;
void ConfigureUIForNewPane(int index);
void StoreAudioCheckboxState();
void RemoveCurrentPaneUI();
void MaybeCreateReselectButtonForPane(const DisplaySurfaceCategory& category);
std::u16string GetLabelForAudioToggle(
const DisplaySurfaceCategory& category) const;
// Sets up the view for the pane based on the passed-in content_view and the
// corresponding category object.
std::unique_ptr<views::View> SetupPane(
DesktopMediaList::Type type,
std::unique_ptr<DesktopMediaListController> controller,
bool audio_offered,
bool audio_checked,
bool supports_reselect_button,
std::unique_ptr<views::View> content_view);
void OnSourceTypeSwitched(int index);
int GetSelectedTabIndex() const;
const DesktopMediaListController* GetSelectedController() const;
DesktopMediaListController* GetSelectedController();
DesktopMediaList::Type GetSelectedSourceListType() const;
bool IsAudioSharingApprovedByUser() const;
// Records the number of tabs, windows and screens that were available
// for the user to choose from when they eventually made their selection
// of which tab/window/screen to capture.
//
// Note: The number of sources available can flactuate over time while
// the media-picker is open. We only record the number at the end,
// when the user either chooses what to capture, or chooses
// not to capture anything.
void RecordSourceCountsUma();
// Records the state of the audio toggle at the time when the user approved
// the capture. If the audio toggle is not present, the histogram
// distinguishes the reason for its absence.
void RecordAudioToggleUma(const content::DesktopMediaID& source);
// Helper for UMA-tracking of how often a user shares a discarded tab.
void RecordTabDiscardedStatusUma(const content::DesktopMediaID& source);
// Counts the number of sources of a given type.
// * Returns nullopt if such sources are not offered to the user due to
// a configuration of the picker.
// * Returns 0 if such sources were supposed to be offered to the user,
// but no such sources were available.
std::optional<int> CountSourcesOfType(DesktopMediaList::Type type);
#if BUILDFLAG(IS_MAC)
void OnPermissionUpdate(bool has_permission);
void RecordPermissionInteractionUma() const;
#endif
const raw_ptr<content::WebContents, AcrossTasksDanglingUntriaged>
web_contents_;
const DesktopMediaPicker::Params::RequestSource request_source_;
const std::u16string app_name_;
const bool audio_requested_;
const bool exclude_system_audio_requested_; // JS-exposed as systemAudio.
const bool is_system_audio_offered_;
const bool suppress_local_audio_playback_; // Effective only if audio shared.
const bool restrict_own_audio_; // Effective only if audio shared.
const content::GlobalRenderFrameHostId capturer_global_id_;
raw_ptr<DesktopMediaPickerImpl> parent_;
raw_ptr<views::Label> description_label_ = nullptr;
raw_ptr<views::MdTextButton> reselect_button_ = nullptr;
raw_ptr<views::TabbedPane> tabbed_pane_ = nullptr;
std::vector<DisplaySurfaceCategory> categories_;
int previously_selected_category_ = 0;
std::optional<content::DesktopMediaID> accepted_source_;
#if BUILDFLAG(IS_MAC)
std::unique_ptr<ScreenCapturePermissionChecker>
screen_capture_permission_checker_;
std::optional<bool> initial_permission_state_;
bool permission_pane_was_shown_ = false;
#endif
// For recording dialog-duration UMA histograms.
const base::TimeTicks dialog_open_time_;
base::WeakPtrFactory<DesktopMediaPickerDialogView> weak_factory_{this};
};
// Implementation of DesktopMediaPicker for Views.
//
// TODO(crbug.com/40637301): Consider merging with DesktopMediaPickerController
// and naming the merged class just DesktopMediaPicker.
class DesktopMediaPickerImpl : public DesktopMediaPicker {
public:
DesktopMediaPickerImpl();
DesktopMediaPickerImpl(const DesktopMediaPickerImpl&) = delete;
DesktopMediaPickerImpl& operator=(const DesktopMediaPickerImpl&) = delete;
~DesktopMediaPickerImpl() override;
void NotifyDialogResult(
base::expected<content::DesktopMediaID,
blink::mojom::MediaStreamRequestResult> result);
// DesktopMediaPicker:
void Show(const DesktopMediaPicker::Params& params,
std::vector<std::unique_ptr<DesktopMediaList>> source_lists,
DoneCallback done_callback) override;
DesktopMediaPickerDialogView* GetDialogViewForTesting() const {
return dialog_;
}
private:
friend class DesktopMediaPickerViewsTestApi;
DoneCallback callback_;
Params::RequestSource request_source_;
// The |dialog_| is owned by the corresponding views::Widget instance.
// When DesktopMediaPickerImpl is destroyed the |dialog_| is destroyed
// asynchronously by closing the widget.
raw_ptr<DesktopMediaPickerDialogView> dialog_;
};
#endif // CHROME_BROWSER_UI_VIEWS_DESKTOP_CAPTURE_DESKTOP_MEDIA_PICKER_VIEWS_H_
|