File: desktop_media_list.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (152 lines) | stat: -rw-r--r-- 6,349 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
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
// Copyright 2013 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_MEDIA_WEBRTC_DESKTOP_MEDIA_LIST_H_
#define CHROME_BROWSER_MEDIA_WEBRTC_DESKTOP_MEDIA_LIST_H_

#include <optional>
#include <string>
#include <vector>

#include "base/functional/callback_forward.h"
#include "base/time/time.h"
#include "content/public/browser/desktop_media_id.h"
#include "ui/gfx/image/image_skia.h"

class DesktopMediaListObserver;

namespace content {
class WebContents;
}

// DesktopMediaList provides the list of desktop media source (screens, windows,
// tabs), and their thumbnails, to the desktop media picker dialog. It
// transparently updates the list in the background, and notifies the desktop
// media picker when something changes.
//
// TODO(crbug.com/40637301): Consider renaming this class.
class DesktopMediaList {
 public:
  // Reflects content::DesktopMediaID::Type, but can decorate it with additional
  // information. For example, we can specify *current* screen/window/type while
  // keeping all other code that uses content::DesktopMediaID::Type unchanged.
  enum class Type {
    kNone,         // TYPE_NONE
    kScreen,       // TYPE_SCREEN
    kWindow,       // TYPE_WINDOW
    kWebContents,  // TYPE_WEB_CONTENTS
    kCurrentTab,   // TYPE_WEB_CONTENTS of the current tab.
  };

  // A WebContents filter can be applied to DesktopMediaList::Type::kWebContents
  // MediaList object in order to provide a way to filter out any WebContents
  // that shouldn't be included.
  using WebContentsFilter =
      base::RepeatingCallback<bool(content::WebContents*)>;

  // Wraps a given filter to produce a new filter that excludes a given
  // WebContents, but is otherwise identical to the original filter.
  //
  // Note: |excluded_web_contents| will internally be converted to a WeakPtr
  // in order to make posting the filter safe. If that weak pointer expires,
  // the exclusion also expires. This is safe even when the capturer/capturee
  // are the same, because capturing itself will be rejected in that case.
  static WebContentsFilter ExcludeWebContents(
      WebContentsFilter filter,
      content::WebContents* excluded_web_contents);

  // Struct used to represent each entry in the list.
  struct Source {
    Source();
    Source(const Source& other_source);
    ~Source();

    // Id of the source.
    content::DesktopMediaID id;

    // Name of the source that should be shown to the user.
    std::u16string name;

    // The thumbnail for the source.
    gfx::ImageSkia thumbnail;

    // A preview for this source, used when both a thumbnail and preview are
    // used. Currently only the case in the tab_desktop_media_list.
    gfx::ImageSkia preview;
  };

  using UpdateCallback = base::OnceClosure;

  virtual ~DesktopMediaList() = default;

  // Sets time interval between updates. By default list of sources and their
  // thumbnail are updated once per second. If called after StartUpdating() then
  // it will take effect only after the next update.
  virtual void SetUpdatePeriod(base::TimeDelta period) = 0;

  // Sets size to which the thumbnails should be scaled. If called after
  // StartUpdating() then some thumbnails may be still scaled to the old size
  // until they are updated.
  virtual void SetThumbnailSize(const gfx::Size& thumbnail_size) = 0;

  // Sets ID of the hosting desktop picker dialog. The window with this ID will
  // be filtered out from the list of sources.
  virtual void SetViewDialogWindowId(content::DesktopMediaID dialog_id) = 0;

  // Starts updating the model. The model is initially empty, so OnSourceAdded()
  // notifications will be generated for each existing source as it is
  // enumerated. After the initial enumeration the model will be refreshed based
  // on the update period, and notifications generated only for changes in the
  // model.
  virtual void StartUpdating(DesktopMediaListObserver* observer) = 0;

  // Updates the model and calls |callback| when all currently existing sources
  // have been found, passing |this| as the argument.  In most respects, this is
  // a simplified version of StartUpdating().  This method should only be called
  // once per DesktopMediaList instance.  It should not be called after
  // StartUpdating(), and StartUpdating() should not be called until |callback|
  // has been called.
  virtual void Update(UpdateCallback callback) = 0;

  virtual int GetSourceCount() const = 0;
  virtual const Source& GetSource(int index) const = 0;

  virtual Type GetMediaListType() const = 0;

  // Set or clear the id of a single source which needs a preview image
  // generating in addition to its thumbnail.
  virtual void SetPreviewedSource(
      const std::optional<content::DesktopMediaID>& id) = 0;

  // Returns true if this DesktopMediaList wraps some other object (usually a
  // DesktopCapturer), that takes responsibility for showing its own source
  // list where the user will likely make their selection. When true, there will
  // only be one source listed which will represent the selection made in the
  // delegated source list.
  // Returns false if this DesktopMediaList needs UI created for it to show its
  // source list.
  virtual bool IsSourceListDelegated() const = 0;

  // May only be called if |IsSourceListDelegated| returns true. When called,
  // clears any selection from the delegated source list and will cause the
  // delegated source list to reappear if it is focused.
  virtual void ClearDelegatedSourceListSelection() = 0;

  // Notifies the list that it is now focused. This is especially important
  // when IsSourceDelegated() returns true, as it helps to notify the delegated
  // source list when it should be visible.
  virtual void FocusList() = 0;

  // Notifies the list that it is no longer focused. This is especially
  // important when IsSourceDelegated() returns true, as it helps to notify the
  // delegated source list when it should be hidden.
  virtual void HideList() = 0;

  // Show the delegated source list. This is intended to be used for delegated
  // source lists that need to be displayed independently from when the
  // DesktopMediaList gains focus.
  virtual void ShowDelegatedList() = 0;
};

#endif  // CHROME_BROWSER_MEDIA_WEBRTC_DESKTOP_MEDIA_LIST_H_