mirror of
https://github.com/electron/electron.git
synced 2026-05-02 03:00:22 -04:00
refactor: do not pass a DesktopMediaList* to DesktopCapturer::OnListReady() The list pointer was being used as a proxy for its type, so just pass the type instead. This solves a lifecycle issue occurring in CI where the callack can outlive the DesktopMediaList. Sample error log: [48471:0428/193441.269750:FATAL:base/allocator/partition_alloc_support.cc:798] Detected dangling raw_ptr in unretained with id=0x0000013c02e14378: Task trace: 0 Electron Framework 0x000000012283a0ba electron::api::DesktopCapturer::ListObserver::MaybeNotifyReady() + 170 1 Electron Framework 0x0000000133246dc5 NativeDesktopMediaList::Worker::OnRecurrentCaptureResult(webrtc::DesktopCapturer::Result, std::__Cr::unique_ptr<webrtc::DesktopFrame, std::__Cr::default_delete<webrtc::DesktopFrame>>, long) + 357 2 Electron Framework 0x000000013328dbcf (anonymous namespace)::ScreenshotManagerCapturer::OnRecurrentCaptureTimer() + 1343 Stack trace: 0 Electron Framework 0x000000012ade42f2 base::debug::CollectStackTrace(base::span<void const*, 18446744073709551615ul, void const**>) + 18 1 Electron Framework 0x000000012add00e1 base::debug::StackTrace::StackTrace(unsigned long) + 225 2 Electron Framework 0x000000012ade978a base::allocator::UnretainedDanglingRawPtrDetectedCrash(unsigned long) + 90 3 Electron Framework 0x000000012ae437f7 base::internal::RawPtrBackupRefImpl<true>::ReportIfDanglingInternal(unsigned long) + 391
91 lines
2.7 KiB
C++
91 lines
2.7 KiB
C++
// Copyright (c) 2015 GitHub, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_DESKTOP_CAPTURER_H_
|
|
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_DESKTOP_CAPTURER_H_
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "base/memory/weak_ptr.h"
|
|
#include "base/timer/timer.h"
|
|
#include "chrome/browser/media/webrtc/desktop_media_list.h"
|
|
#include "shell/common/gin_helper/pinnable.h"
|
|
#include "shell/common/gin_helper/wrappable.h"
|
|
|
|
namespace gin_helper {
|
|
template <typename T>
|
|
class Handle;
|
|
} // namespace gin_helper
|
|
|
|
namespace electron::api {
|
|
|
|
class DesktopCapturer final
|
|
: public gin_helper::DeprecatedWrappable<DesktopCapturer>,
|
|
public gin_helper::Pinnable<DesktopCapturer> {
|
|
public:
|
|
struct Source {
|
|
DesktopMediaList::Source media_list_source;
|
|
// Will be an empty string if not available.
|
|
std::string display_id;
|
|
|
|
// Whether or not this source should provide an icon.
|
|
bool fetch_icon = false;
|
|
};
|
|
|
|
static gin_helper::Handle<DesktopCapturer> Create(v8::Isolate* isolate);
|
|
|
|
static bool IsDisplayMediaSystemPickerAvailable();
|
|
|
|
void StartHandling(bool capture_window,
|
|
bool capture_screen,
|
|
const gfx::Size& thumbnail_size,
|
|
bool fetch_window_icons);
|
|
|
|
// gin_helper::Wrappable
|
|
static gin::DeprecatedWrapperInfo kWrapperInfo;
|
|
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
|
v8::Isolate* isolate) override;
|
|
const char* GetTypeName() override;
|
|
|
|
// disable copy
|
|
DesktopCapturer(const DesktopCapturer&) = delete;
|
|
DesktopCapturer& operator=(const DesktopCapturer&) = delete;
|
|
|
|
protected:
|
|
DesktopCapturer();
|
|
~DesktopCapturer() override;
|
|
|
|
private:
|
|
class ListObserver;
|
|
|
|
void FinalizeList(std::unique_ptr<ListObserver>& observer,
|
|
std::unique_ptr<DesktopMediaList>& list);
|
|
void OnListReady(DesktopMediaList::Type type);
|
|
void OnReadyTimeout();
|
|
void CollectSourcesFrom(DesktopMediaList* list);
|
|
void HandleFailure();
|
|
void HandleSuccess();
|
|
|
|
std::unique_ptr<ListObserver> window_observer_;
|
|
std::unique_ptr<ListObserver> screen_observer_;
|
|
std::unique_ptr<DesktopMediaList> window_capturer_;
|
|
std::unique_ptr<DesktopMediaList> screen_capturer_;
|
|
std::vector<DesktopCapturer::Source> captured_sources_;
|
|
int pending_lists_ = 0;
|
|
bool finished_ = false;
|
|
bool fetch_window_icons_ = false;
|
|
base::OneShotTimer deadline_;
|
|
#if BUILDFLAG(IS_WIN)
|
|
bool using_directx_capturer_ = false;
|
|
#endif // BUILDFLAG(IS_WIN)
|
|
|
|
base::WeakPtrFactory<DesktopCapturer> weak_ptr_factory_{this};
|
|
};
|
|
|
|
} // namespace electron::api
|
|
|
|
#endif // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_DESKTOP_CAPTURER_H_
|