| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/desktop_capture/mac/full_screen_chrome_window_detector.
h" | 11 #include "webrtc/modules/desktop_capture/mac/full_screen_chrome_window_detector.
h" |
| 12 | 12 |
| 13 #include <assert.h> | 13 #include <assert.h> |
| 14 #include <libproc.h> | 14 #include <libproc.h> |
| 15 #include <string> | 15 #include <string> |
| 16 | 16 |
| 17 #include "webrtc/base/macutils.h" | 17 #include "webrtc/base/macutils.h" |
| 18 #include "webrtc/base/timeutils.h" |
| 18 #include "webrtc/modules/desktop_capture/mac/window_list_utils.h" | 19 #include "webrtc/modules/desktop_capture/mac/window_list_utils.h" |
| 19 #include "webrtc/system_wrappers/include/logging.h" | 20 #include "webrtc/system_wrappers/include/logging.h" |
| 20 | 21 |
| 21 | 22 |
| 22 namespace webrtc { | 23 namespace webrtc { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 const int64_t kUpdateIntervalMs = 500; | 27 const int64_t kUpdateIntervalMs = 500; |
| 27 | 28 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 return false; | 135 return false; |
| 135 | 136 |
| 136 const char* last_slash = strrchr(buffer, '/'); | 137 const char* last_slash = strrchr(buffer, '/'); |
| 137 std::string name(last_slash ? last_slash + 1 : buffer); | 138 std::string name(last_slash ? last_slash + 1 : buffer); |
| 138 return name.find("Google Chrome") == 0 || name == "Chromium"; | 139 return name.find("Google Chrome") == 0 || name == "Chromium"; |
| 139 } | 140 } |
| 140 | 141 |
| 141 } // namespace | 142 } // namespace |
| 142 | 143 |
| 143 FullScreenChromeWindowDetector::FullScreenChromeWindowDetector() | 144 FullScreenChromeWindowDetector::FullScreenChromeWindowDetector() |
| 144 : ref_count_(0) {} | 145 : ref_count_(0), last_update_time_ns_(0) {} |
| 145 | 146 |
| 146 FullScreenChromeWindowDetector::~FullScreenChromeWindowDetector() {} | 147 FullScreenChromeWindowDetector::~FullScreenChromeWindowDetector() {} |
| 147 | 148 |
| 148 CGWindowID FullScreenChromeWindowDetector::FindFullScreenWindow( | 149 CGWindowID FullScreenChromeWindowDetector::FindFullScreenWindow( |
| 149 CGWindowID original_window) { | 150 CGWindowID original_window) { |
| 150 if (!IsChromeWindow(original_window) || !IsWindowMinimized(original_window)) | 151 if (!IsChromeWindow(original_window) || !IsWindowMinimized(original_window)) |
| 151 return kCGNullWindowID; | 152 return kCGNullWindowID; |
| 152 | 153 |
| 153 CGWindowID full_screen_window_id = | 154 CGWindowID full_screen_window_id = |
| 154 FindFullScreenWindowWithSamePidAndTitle(original_window); | 155 FindFullScreenWindowWithSamePidAndTitle(original_window); |
| 155 | 156 |
| 156 if (full_screen_window_id == kCGNullWindowID) | 157 if (full_screen_window_id == kCGNullWindowID) |
| 157 return kCGNullWindowID; | 158 return kCGNullWindowID; |
| 158 | 159 |
| 159 for (WindowCapturer::WindowList::iterator it = previous_window_list_.begin(); | 160 for (WindowCapturer::WindowList::iterator it = previous_window_list_.begin(); |
| 160 it != previous_window_list_.end(); ++it) { | 161 it != previous_window_list_.end(); ++it) { |
| 161 if (static_cast<CGWindowID>(it->id) != full_screen_window_id) | 162 if (static_cast<CGWindowID>(it->id) != full_screen_window_id) |
| 162 continue; | 163 continue; |
| 163 | 164 |
| 164 int64_t time_interval = | 165 LOG(LS_WARNING) << "The full-screen window exists in the list."; |
| 165 (TickTime::Now() - last_udpate_time_).Milliseconds(); | |
| 166 LOG(LS_WARNING) << "The full-screen window exists in the list, " | |
| 167 << "which was updated " << time_interval << "ms ago."; | |
| 168 return kCGNullWindowID; | 166 return kCGNullWindowID; |
| 169 } | 167 } |
| 170 | 168 |
| 171 return full_screen_window_id; | 169 return full_screen_window_id; |
| 172 } | 170 } |
| 173 | 171 |
| 174 void FullScreenChromeWindowDetector::UpdateWindowListIfNeeded( | 172 void FullScreenChromeWindowDetector::UpdateWindowListIfNeeded( |
| 175 CGWindowID original_window) { | 173 CGWindowID original_window) { |
| 176 if (IsChromeWindow(original_window) && | 174 if (IsChromeWindow(original_window) && |
| 177 (TickTime::Now() - last_udpate_time_).Milliseconds() | 175 (rtc::TimeNanos() - last_update_time_ns_) / rtc::kNumNanosecsPerMillisec |
| 178 > kUpdateIntervalMs) { | 176 > kUpdateIntervalMs) { |
| 179 previous_window_list_.clear(); | 177 previous_window_list_.clear(); |
| 180 previous_window_list_.swap(current_window_list_); | 178 previous_window_list_.swap(current_window_list_); |
| 181 | 179 |
| 182 // No need to update the window list when the window is minimized. | 180 // No need to update the window list when the window is minimized. |
| 183 if (IsWindowMinimized(original_window)) { | 181 if (IsWindowMinimized(original_window)) { |
| 184 previous_window_list_.clear(); | 182 previous_window_list_.clear(); |
| 185 return; | 183 return; |
| 186 } | 184 } |
| 187 | 185 |
| 188 GetWindowList(¤t_window_list_); | 186 GetWindowList(¤t_window_list_); |
| 189 last_udpate_time_ = TickTime::Now(); | 187 last_update_time_ns_ = rtc::TimeNanos(); |
| 190 } | 188 } |
| 191 } | 189 } |
| 192 | 190 |
| 193 } // namespace webrtc | 191 } // namespace webrtc |
| OLD | NEW |