tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

tab_capturer.h (3063B)


      1 /*
      2 *  Copyright 2018 The WebRTC project authors. All Rights Reserved.
      3 *
      4 *  Use of this source code is governed by a BSD-style license
      5 *  that can be found in the LICENSE file in the root of the source
      6 *  tree. An additional intellectual property rights grant can be found
      7 *  in the file PATENTS.  All contributing project authors may
      8 *  be found in the AUTHORS file in the root of the source tree.
      9 */
     10 
     11 #ifndef MODULES_DESKTOP_CAPTURE_TAB_CAPTURER_H_
     12 #define MODULES_DESKTOP_CAPTURE_TAB_CAPTURER_H_
     13 
     14 #include "api/sequence_checker.h"
     15 #include "modules/desktop_capture/desktop_capturer.h"
     16 #include "mozilla/MozPromise.h"
     17 #include "nsDeque.h"
     18 #include "nsThreadUtils.h"
     19 
     20 namespace mozilla {
     21 namespace dom {
     22 struct ImageBitmapCloneData;
     23 }  // namespace dom
     24 
     25 class CaptureFrameRequest;
     26 class TabCapturedHandler;
     27 class TaskQueue;
     28 
     29 class TabCapturerWebrtc : public webrtc::DesktopCapturer {
     30 protected:
     31  TabCapturerWebrtc(SourceId aSourceId,
     32                    nsCOMPtr<nsISerialEventTarget> aCaptureThread);
     33  ~TabCapturerWebrtc();
     34 
     35 public:
     36  friend class CaptureFrameRequest;
     37  friend class TabCapturedHandler;
     38 
     39  static std::unique_ptr<webrtc::DesktopCapturer> Create(
     40      SourceId aSourceId, nsCOMPtr<nsISerialEventTarget> aCaptureThread);
     41 
     42  TabCapturerWebrtc(const TabCapturerWebrtc&) = delete;
     43  TabCapturerWebrtc& operator=(const TabCapturerWebrtc&) = delete;
     44 
     45  // DesktopCapturer interface.
     46  void Start(Callback* aCallback) override;
     47  void CaptureFrame() override;
     48  bool GetSourceList(SourceList* aSources) override;
     49  bool SelectSource(SourceId) override;
     50  bool FocusOnSelectedSource() override;
     51  bool IsOccluded(const webrtc::DesktopVector& aPos) override;
     52 
     53 private:
     54  // Capture code
     55  using CapturePromise =
     56      MozPromise<UniquePtr<dom::ImageBitmapCloneData>, nsresult, true>;
     57  RefPtr<CapturePromise> CaptureFrameNow();
     58 
     59  // Helper that checks for overrun requests. Returns true if aRequest had not
     60  // been dropped due to disconnection or overrun.
     61  // Note that if this returns true, the caller takes the responsibility to call
     62  // mCallback with a capture result for aRequest.
     63  bool CompleteRequest(CaptureFrameRequest* aRequest);
     64 
     65  // Helper that disconnects the request, and notifies mCallback of a temporary
     66  // failure.
     67  void DisconnectRequest(CaptureFrameRequest* aRequest);
     68 
     69  // Handle the result from the async callback from CaptureFrameNow.
     70  void OnCaptureFrameSuccess(UniquePtr<dom::ImageBitmapCloneData> aData);
     71  void OnCaptureFrameFailure();
     72 
     73  const uint64_t mBrowserId;
     74  const RefPtr<TaskQueue> mMainThreadWorker;
     75  const RefPtr<TaskQueue> mCallbackWorker;
     76  webrtc::SequenceChecker mControlChecker;
     77  webrtc::SequenceChecker mCallbackChecker;
     78  // Set in Start() and guaranteed by the owner of this class to outlive us.
     79  webrtc::DesktopCapturer::Callback* mCallback
     80      RTC_GUARDED_BY(mCallbackChecker) = nullptr;
     81 
     82  // mCallbackWorker only
     83  nsRefPtrDeque<CaptureFrameRequest> mRequests RTC_GUARDED_BY(mCallbackChecker);
     84 };
     85 
     86 }  // namespace mozilla
     87 
     88 #endif  // MODULES_DESKTOP_CAPTURE_TAB_CAPTURER_H_