File: tab_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 (94 lines) | stat: -rw-r--r-- 3,608 bytes parent folder | download | duplicates (9)
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
// Copyright 2016 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_TAB_DESKTOP_MEDIA_LIST_H_
#define CHROME_BROWSER_MEDIA_WEBRTC_TAB_DESKTOP_MEDIA_LIST_H_

#include <map>

#include "base/functional/callback_helpers.h"
#include "base/task/sequenced_task_runner.h"
#include "chrome/browser/media/webrtc/desktop_media_list_base.h"

// Implementation of DesktopMediaList that shows tab/WebContents.
class TabDesktopMediaList : public DesktopMediaListBase {
 public:
  TabDesktopMediaList(
      content::WebContents* web_contents,
      DesktopMediaList::WebContentsFilter includable_web_contents_filter,
      bool include_chrome_app_windows);

  TabDesktopMediaList(const TabDesktopMediaList&) = delete;
  TabDesktopMediaList& operator=(const TabDesktopMediaList&) = delete;

  ~TabDesktopMediaList() override;

  void SetPreviewedSource(
      const std::optional<content::DesktopMediaID>& id) override;

 private:
  class RefreshCompleter {
   public:
    explicit RefreshCompleter(const base::WeakPtr<TabDesktopMediaList> list);
    ~RefreshCompleter();

   private:
    base::WeakPtr<TabDesktopMediaList> list_;
  };

  typedef std::map<content::DesktopMediaID, uint32_t> ImageHashesMap;

  void Refresh(bool update_thumnails) override;

  // TODO(crbug.com/40187992): Combine the below logic for screenshotting with
  // the very similar behaviour in current_tab_desktop_media_list.h

  // Called on the UI thread after the captured image is handled. If the
  // image was new, it's rescaled to the desired size and sent back in |image|.
  // Otherwise, an empty Optional is sent back. In either case, |new_hash| is
  // the hash value of the frame that was handled.
  void OnPreviewCaptureHandled(
      const content::DesktopMediaID& media_id,
      std::unique_ptr<TabDesktopMediaList::RefreshCompleter> refresh_completer,
      uint32_t new_hash,
      const gfx::ImageSkia& image);

  void StartPreviewUpdate();
  void TriggerScreenshot(
      int remaining_retries,
      std::unique_ptr<TabDesktopMediaList::RefreshCompleter> refresh_completer);
  void ScreenshotReceived(
      int remaining_retries,
      const content::DesktopMediaID& id,
      std::unique_ptr<TabDesktopMediaList::RefreshCompleter> refresh_completer,
      const SkBitmap& bitmap);
  void CompleteRefreshAfterThumbnailProcessing();

  // The WebContents from which the media-picker was invoked, if such
  // a WebContents was ever set.
  const std::optional<base::WeakPtr<content::WebContents>> web_contents_;

  // The hash of the last captured preview frame. Used to detect identical
  // frames and prevent needless rescaling.
  std::optional<uint32_t> last_hash_;

  ImageHashesMap favicon_hashes_;
  const DesktopMediaList::WebContentsFilter includable_web_contents_filter_;
  const bool include_chrome_app_windows_;

  // Task runner used for resizing thumbnail and preview images.
  scoped_refptr<base::SequencedTaskRunner> image_resize_task_runner_;

  std::optional<content::DesktopMediaID> previewed_source_;

  // Handle returned when incrementing the visible capturer count on the
  // WebContents instance being previewed, if there is one. Allowing this to go
  // out of scope, either when switching previewed sources or on destruction,
  // allows the source to stop painting when not visible etc.
  base::ScopedClosureRunner previewed_source_visible_keepalive_;

  base::WeakPtrFactory<TabDesktopMediaList> weak_factory_{this};
};

#endif  // CHROME_BROWSER_MEDIA_WEBRTC_TAB_DESKTOP_MEDIA_LIST_H_