tor-browser

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

full_screen_window_detector.h (4515B)


      1 /*
      2 *  Copyright (c) 2014 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_FULL_SCREEN_WINDOW_DETECTOR_H_
     12 #define MODULES_DESKTOP_CAPTURE_FULL_SCREEN_WINDOW_DETECTOR_H_
     13 
     14 #include <cstdint>
     15 #include <functional>
     16 #include <memory>
     17 
     18 #include "api/function_view.h"
     19 #include "api/ref_counted_base.h"
     20 #include "api/scoped_refptr.h"
     21 #include "modules/desktop_capture/desktop_capturer.h"
     22 #include "modules/desktop_capture/full_screen_application_handler.h"
     23 
     24 namespace webrtc {
     25 
     26 // This is a way to handle switch to full-screen mode for application in some
     27 // specific cases:
     28 // - Chrome on MacOS creates a new window in full-screen mode to
     29 //   show a tab full-screen and minimizes the old window.
     30 // - PowerPoint creates new windows in full-screen mode when user goes to
     31 //   presentation mode (Slide Show Window, Presentation Window).
     32 //
     33 // To continue capturing in these cases, we try to find the new full-screen
     34 // window using criteria provided by application specific
     35 // FullScreenApplicationHandler.
     36 
     37 class FullScreenWindowDetector
     38    : public RefCountedNonVirtual<FullScreenWindowDetector> {
     39 public:
     40  using ApplicationHandlerFactory =
     41      std::function<std::unique_ptr<FullScreenApplicationHandler>(
     42          DesktopCapturer::SourceId sourceId)>;
     43 
     44  FullScreenWindowDetector(
     45      ApplicationHandlerFactory application_handler_factory);
     46 
     47  FullScreenWindowDetector(const FullScreenWindowDetector&) = delete;
     48  FullScreenWindowDetector& operator=(const FullScreenWindowDetector&) = delete;
     49 
     50  // Returns the full-screen window in place of the original window if all the
     51  // criteria provided by FullScreenApplicationHandler are met, or 0 if no such
     52  // window found.
     53  DesktopCapturer::SourceId FindFullScreenWindow(
     54      DesktopCapturer::SourceId original_source_id);
     55 
     56  // The caller should call this function periodically, implementation will
     57  // update internal state no often than twice per second
     58  void UpdateWindowListIfNeeded(
     59      DesktopCapturer::SourceId original_source_id,
     60      FunctionView<bool(DesktopCapturer::SourceList*)> get_sources);
     61 
     62  static scoped_refptr<FullScreenWindowDetector>
     63  CreateFullScreenWindowDetector();
     64  void SetUseHeuristicFullscreenPowerPointWindows(
     65      bool use_heuristic_fullscreen_powerpoint_windows,
     66      bool use_heuristic_for_wgc = false) {
     67    use_heuristic_fullscreen_powerpoint_windows_ =
     68        use_heuristic_fullscreen_powerpoint_windows;
     69    use_heuristic_for_wgc_ = use_heuristic_for_wgc;
     70    if (app_handler_) {
     71      app_handler_->SetUseHeuristicFullscreenPowerPointWindows(
     72          use_heuristic_fullscreen_powerpoint_windows);
     73    }
     74  }
     75  bool UseHeuristicForWGC() { return use_heuristic_for_wgc_; }
     76 
     77  // Used for tests.
     78  void CreateFullScreenApplicationHandlerForTest(
     79      DesktopCapturer::SourceId source_id,
     80      bool fullscreen_slide_show_started_after_capture_start);
     81 
     82 protected:
     83  std::unique_ptr<FullScreenApplicationHandler> app_handler_;
     84 
     85 private:
     86  void CreateApplicationHandlerIfNeeded(DesktopCapturer::SourceId source_id);
     87 
     88  ApplicationHandlerFactory application_handler_factory_;
     89  // `use_heuristic_fullscreen_powerpoint_windows_` controls if we create the
     90  // FullScreenPowerPointHandler class or not.
     91  // TODO(crbug.com/409473386): Remove
     92  // `use_heuristic_fullscreen_powerpoint_windows_` once the feature is
     93  // available in stable for some milestones.
     94  bool use_heuristic_fullscreen_powerpoint_windows_ = true;
     95 
     96  // `use_heuristic_for_wgc_` implements the finch experiment for
     97  // the usage of FullScreenPowerPointHandler class for WGC API.
     98  // TODO(crbug.com/409473386): Remove `use_heuristic_for_wgc_` once
     99  // the feature has been rolled out to Stable for some milestones.
    100  bool use_heuristic_for_wgc_ = false;
    101 
    102  int64_t last_update_time_ms_;
    103  DesktopCapturer::SourceId previous_source_id_;
    104 
    105  // Save the source id when we fail to create an instance of
    106  // CreateApplicationHandlerIfNeeded to avoid redundant attempt to do it again.
    107  DesktopCapturer::SourceId no_handler_source_id_;
    108 
    109  DesktopCapturer::SourceList window_list_;
    110 };
    111 
    112 }  // namespace webrtc
    113 
    114 #endif  // MODULES_DESKTOP_CAPTURE_FULL_SCREEN_WINDOW_DETECTOR_H_