tor-browser

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

selected_window_context.cc (2234B)


      1 /*
      2 *  Copyright (c) 2019 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 #include "modules/desktop_capture/win/selected_window_context.h"
     12 
     13 #include "modules/desktop_capture/desktop_geometry.h"
     14 #include "modules/desktop_capture/win/window_capture_utils.h"
     15 
     16 namespace webrtc {
     17 
     18 SelectedWindowContext::SelectedWindowContext(
     19    HWND selected_window,
     20    DesktopRect selected_window_rect,
     21    WindowCaptureHelperWin* window_capture_helper)
     22    : selected_window_(selected_window),
     23      selected_window_rect_(selected_window_rect),
     24      window_capture_helper_(window_capture_helper) {
     25  selected_window_thread_id_ =
     26      GetWindowThreadProcessId(selected_window, &selected_window_process_id_);
     27 }
     28 
     29 bool SelectedWindowContext::IsSelectedWindowValid() const {
     30  return selected_window_thread_id_ != 0;
     31 }
     32 
     33 bool SelectedWindowContext::IsWindowOwnedBySelectedWindow(HWND hwnd) const {
     34  // This check works for drop-down menus & dialog pop-up windows.
     35  if (GetAncestor(hwnd, GA_ROOTOWNER) == selected_window_) {
     36    return true;
     37  }
     38 
     39  // Assume that all other windows are unrelated to the selected window.
     40  // This will cause some windows that are actually related to be missed,
     41  // e.g. context menus and tool-tips, but avoids the risk of capturing
     42  // unrelated windows. Using heuristics such as matching the thread and
     43  // process Ids suffers from false-positives, e.g. in multi-document
     44  // applications.
     45 
     46  return false;
     47 }
     48 
     49 bool SelectedWindowContext::IsWindowOverlappingSelectedWindow(HWND hwnd) const {
     50  return window_capture_helper_->AreWindowsOverlapping(hwnd, selected_window_,
     51                                                       selected_window_rect_);
     52 }
     53 
     54 HWND SelectedWindowContext::selected_window() const {
     55  return selected_window_;
     56 }
     57 
     58 WindowCaptureHelperWin* SelectedWindowContext::window_capture_helper() const {
     59  return window_capture_helper_;
     60 }
     61 
     62 }  // namespace webrtc