OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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/window_capturer.h" | 11 #include "webrtc/modules/desktop_capture/window_capturer.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 | 14 |
15 #include "webrtc/base/scoped_ptr.h" | 15 #include "webrtc/base/scoped_ptr.h" |
| 16 #include "webrtc/base/checks.h" |
16 #include "webrtc/base/win32.h" | 17 #include "webrtc/base/win32.h" |
17 #include "webrtc/modules/desktop_capture/desktop_frame_win.h" | 18 #include "webrtc/modules/desktop_capture/desktop_frame_win.h" |
18 #include "webrtc/modules/desktop_capture/win/window_capture_utils.h" | 19 #include "webrtc/modules/desktop_capture/win/window_capture_utils.h" |
19 #include "webrtc/system_wrappers/interface/logging.h" | 20 #include "webrtc/system_wrappers/interface/logging.h" |
20 | 21 |
21 namespace webrtc { | 22 namespace webrtc { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) { | 26 BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) { |
26 WindowCapturer::WindowList* list = | 27 WindowCapturer::WindowList* list = |
27 reinterpret_cast<WindowCapturer::WindowList*>(param); | 28 reinterpret_cast<WindowCapturer::WindowList*>(param); |
28 | 29 |
29 // Skip windows that are invisible, minimized, have no title, or are owned, | 30 // Skip windows that are invisible, minimized, have no title, or are owned, |
30 // unless they have the app window style set. | 31 // unless they have the app window style set. |
31 int len = GetWindowTextLength(hwnd); | 32 int len = GetWindowTextLength(hwnd); |
32 HWND owner = GetWindow(hwnd, GW_OWNER); | 33 HWND owner = GetWindow(hwnd, GW_OWNER); |
33 LONG exstyle = GetWindowLong(hwnd, GWL_EXSTYLE); | 34 LONG exstyle = GetWindowLong(hwnd, GWL_EXSTYLE); |
34 if (len == 0 || IsIconic(hwnd) || !IsWindowVisible(hwnd) || | 35 if (len == 0 || IsIconic(hwnd) || !IsWindowVisible(hwnd) || |
35 (owner && !(exstyle & WS_EX_APPWINDOW))) { | 36 (owner && !(exstyle & WS_EX_APPWINDOW))) { |
36 return TRUE; | 37 return TRUE; |
37 } | 38 } |
38 | 39 |
39 // Skip the Program Manager window and the Start button. | 40 // Skip the Program Manager window and the Start button. |
40 const size_t kClassLength = 256; | 41 const size_t kClassLength = 256; |
41 WCHAR class_name[kClassLength]; | 42 WCHAR class_name[kClassLength]; |
42 GetClassName(hwnd, class_name, kClassLength); | 43 const int class_name_length = GetClassName(hwnd, class_name, kClassLength); |
| 44 RTC_DCHECK(class_name_length) |
| 45 << "Error retrieving the application's class name"; |
| 46 |
43 // Skip Program Manager window and the Start button. This is the same logic | 47 // Skip Program Manager window and the Start button. This is the same logic |
44 // that's used in Win32WindowPicker in libjingle. Consider filtering other | 48 // that's used in Win32WindowPicker in libjingle. Consider filtering other |
45 // windows as well (e.g. toolbars). | 49 // windows as well (e.g. toolbars). |
46 if (wcscmp(class_name, L"Progman") == 0 || wcscmp(class_name, L"Button") == 0) | 50 if (wcscmp(class_name, L"Progman") == 0 || wcscmp(class_name, L"Button") == 0) |
47 return TRUE; | 51 return TRUE; |
48 | 52 |
| 53 // Windows 8 introduced a "Modern App" identified by their class name being |
| 54 // either ApplicationFrameWindow or windows.UI.Core.coreWindow. The |
| 55 // associated windows cannot be captured, so we skip them. |
| 56 // http://crbug.com/526883. |
| 57 if (rtc::IsWindows8OrLater() && |
| 58 (wcscmp(class_name, L"ApplicationFrameWindow") == 0 || |
| 59 wcscmp(class_name, L"Windows.UI.Core.CoreWindow") == 0)) { |
| 60 return TRUE; |
| 61 } |
| 62 |
49 WindowCapturer::Window window; | 63 WindowCapturer::Window window; |
50 window.id = reinterpret_cast<WindowCapturer::WindowId>(hwnd); | 64 window.id = reinterpret_cast<WindowCapturer::WindowId>(hwnd); |
51 | 65 |
52 const size_t kTitleLength = 500; | 66 const size_t kTitleLength = 500; |
53 WCHAR window_title[kTitleLength]; | 67 WCHAR window_title[kTitleLength]; |
54 // Truncate the title if it's longer than kTitleLength. | 68 // Truncate the title if it's longer than kTitleLength. |
55 GetWindowText(hwnd, window_title, kTitleLength); | 69 GetWindowText(hwnd, window_title, kTitleLength); |
56 window.title = rtc::ToUtf8(window_title); | 70 window.title = rtc::ToUtf8(window_title); |
57 | 71 |
58 // Skip windows when we failed to convert the title or it is empty. | 72 // Skip windows when we failed to convert the title or it is empty. |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 } | 248 } |
235 | 249 |
236 } // namespace | 250 } // namespace |
237 | 251 |
238 // static | 252 // static |
239 WindowCapturer* WindowCapturer::Create(const DesktopCaptureOptions& options) { | 253 WindowCapturer* WindowCapturer::Create(const DesktopCaptureOptions& options) { |
240 return new WindowCapturerWin(); | 254 return new WindowCapturerWin(); |
241 } | 255 } |
242 | 256 |
243 } // namespace webrtc | 257 } // namespace webrtc |
OLD | NEW |