Implement and use new DesktopCapturer APIs in WebRTC

This change replaces all GetWindowList / GetScreenList with GetScreenList,
SelectWindow / SelectScreen with SelectSource, and BringSelectedWindowToFront
with FocusOnSelectedSource in WebRTC.

BUG=webrtc:6513

Review-Url: https://codereview.webrtc.org/2479553006
Cr-Commit-Position: refs/heads/master@{#14960}
diff --git a/webrtc/modules/desktop_capture/cropping_window_capturer.cc b/webrtc/modules/desktop_capture/cropping_window_capturer.cc
index 71c5bea..2968978 100644
--- a/webrtc/modules/desktop_capture/cropping_window_capturer.cc
+++ b/webrtc/modules/desktop_capture/cropping_window_capturer.cc
@@ -58,20 +58,20 @@
   }
 }
 
-bool CroppingWindowCapturer::GetWindowList(WindowList* windows) {
-  return window_capturer_->GetWindowList(windows);
+bool CroppingWindowCapturer::GetSourceList(SourceList* sources) {
+  return window_capturer_->GetSourceList(sources);
 }
 
-bool CroppingWindowCapturer::SelectWindow(WindowId id) {
-  if (window_capturer_->SelectWindow(id)) {
+bool CroppingWindowCapturer::SelectSource(SourceId id) {
+  if (window_capturer_->SelectSource(id)) {
     selected_window_ = id;
     return true;
   }
   return false;
 }
 
-bool CroppingWindowCapturer::BringSelectedWindowToFront() {
-  return window_capturer_->BringSelectedWindowToFront();
+bool CroppingWindowCapturer::FocusOnSelectedSource() {
+  return window_capturer_->FocusOnSelectedSource();
 }
 
 void CroppingWindowCapturer::OnCaptureResult(
diff --git a/webrtc/modules/desktop_capture/cropping_window_capturer.h b/webrtc/modules/desktop_capture/cropping_window_capturer.h
index 768e1ee..a2c6c2f 100644
--- a/webrtc/modules/desktop_capture/cropping_window_capturer.h
+++ b/webrtc/modules/desktop_capture/cropping_window_capturer.h
@@ -34,11 +34,9 @@
       std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override;
   void CaptureFrame() override;
   void SetExcludedWindow(WindowId window) override;
-
-  // WindowCapturer implementation.
-  bool GetWindowList(WindowList* windows) override;
-  bool SelectWindow(WindowId id) override;
-  bool BringSelectedWindowToFront() override;
+  bool GetSourceList(SourceList* sources) override;
+  bool SelectSource(SourceId id) override;
+  bool FocusOnSelectedSource() override;
 
   // DesktopCapturer::Callback implementation, passed to |screen_capturer_| to
   // intercept the capture result.
@@ -67,7 +65,7 @@
   DesktopCapturer::Callback* callback_;
   std::unique_ptr<WindowCapturer> window_capturer_;
   std::unique_ptr<ScreenCapturer> screen_capturer_;
-  WindowId selected_window_;
+  SourceId selected_window_;
   WindowId excluded_window_;
 };
 
diff --git a/webrtc/modules/desktop_capture/desktop_capturer.h b/webrtc/modules/desktop_capture/desktop_capturer.h
index ecae4cb..71834a9 100644
--- a/webrtc/modules/desktop_capture/desktop_capturer.h
+++ b/webrtc/modules/desktop_capture/desktop_capturer.h
@@ -16,6 +16,7 @@
 
 #include <memory>
 #include <string>
+#include <type_traits>
 #include <vector>
 
 #include "webrtc/modules/desktop_capture/desktop_frame.h"
@@ -59,6 +60,9 @@
 
   typedef intptr_t SourceId;
 
+  static_assert(std::is_same<SourceId, ScreenId>::value,
+                "SourceId should be a same type as ScreenId.");
+
   struct Source {
     // The unique id to represent a Source of current DesktopCapturer.
     SourceId id;
diff --git a/webrtc/modules/desktop_capture/mac/full_screen_chrome_window_detector.cc b/webrtc/modules/desktop_capture/mac/full_screen_chrome_window_detector.cc
index 451acb3..4035cbf 100644
--- a/webrtc/modules/desktop_capture/mac/full_screen_chrome_window_detector.cc
+++ b/webrtc/modules/desktop_capture/mac/full_screen_chrome_window_detector.cc
@@ -157,9 +157,8 @@
   if (full_screen_window_id == kCGNullWindowID)
     return kCGNullWindowID;
 
-  for (WindowCapturer::WindowList::iterator it = previous_window_list_.begin();
-       it != previous_window_list_.end(); ++it) {
-    if (static_cast<CGWindowID>(it->id) != full_screen_window_id)
+  for (const auto& window : previous_window_list_) {
+    if (static_cast<CGWindowID>(window.id) != full_screen_window_id)
       continue;
 
     LOG(LS_WARNING) << "The full-screen window exists in the list.";
@@ -183,7 +182,7 @@
       return;
     }
 
-    GetWindowList(&current_window_list_);
+    GetWindowList(&current_window_list_, false);
     last_update_time_ns_ = rtc::TimeNanos();
   }
 }
diff --git a/webrtc/modules/desktop_capture/mac/full_screen_chrome_window_detector.h b/webrtc/modules/desktop_capture/mac/full_screen_chrome_window_detector.h
index 838966d..7a10b42 100644
--- a/webrtc/modules/desktop_capture/mac/full_screen_chrome_window_detector.h
+++ b/webrtc/modules/desktop_capture/mac/full_screen_chrome_window_detector.h
@@ -14,7 +14,7 @@
 #include <ApplicationServices/ApplicationServices.h>
 
 #include "webrtc/base/constructormagic.h"
-#include "webrtc/modules/desktop_capture/window_capturer.h"
+#include "webrtc/modules/desktop_capture/desktop_capturer.h"
 #include "webrtc/system_wrappers/include/atomic32.h"
 
 namespace webrtc {
@@ -57,8 +57,8 @@
   // |previous_window_list_| is taken at least 500ms before the next Capture()
   // call. If we only save the last result, we may get false positive (i.e.
   // full-screen window exists in the list) if Capture() is called too soon.
-  WindowCapturer::WindowList current_window_list_;
-  WindowCapturer::WindowList previous_window_list_;
+  DesktopCapturer::SourceList current_window_list_;
+  DesktopCapturer::SourceList previous_window_list_;
   int64_t last_update_time_ns_;
 
   RTC_DISALLOW_COPY_AND_ASSIGN(FullScreenChromeWindowDetector);
diff --git a/webrtc/modules/desktop_capture/mac/window_list_utils.cc b/webrtc/modules/desktop_capture/mac/window_list_utils.cc
index 0261c45..bcb8798 100644
--- a/webrtc/modules/desktop_capture/mac/window_list_utils.cc
+++ b/webrtc/modules/desktop_capture/mac/window_list_utils.cc
@@ -16,7 +16,8 @@
 
 namespace webrtc {
 
-bool GetWindowList(WindowCapturer::WindowList* windows) {
+bool GetWindowList(DesktopCapturer::SourceList* windows,
+                   bool ignore_minimized) {
   // Only get on screen, non-desktop windows.
   CFArrayRef window_array = CGWindowListCopyWindowInfo(
       kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements,
@@ -24,6 +25,12 @@
   if (!window_array)
     return false;
 
+  MacDesktopConfiguration desktop_config;
+  if (ignore_minimized) {
+    desktop_config = MacDesktopConfiguration::GetCurrent(
+        MacDesktopConfiguration::TopLeftOrigin);
+  }
+
   // Check windows to make sure they have an id, title, and use window layer
   // other than 0.
   CFIndex count = CFArrayGetCount(window_array);
@@ -45,7 +52,14 @@
 
       int id;
       CFNumberGetValue(window_id, kCFNumberIntType, &id);
-      WindowCapturer::Window window;
+
+      // Skip windows that are minimized and not full screen.
+      if (ignore_minimized && IsWindowMinimized(id) &&
+          !IsWindowFullScreen(desktop_config, window)) {
+        continue;
+      }
+
+      DesktopCapturer::Source window;
       window.id = id;
       if (!rtc::ToUtf8(window_title, &(window.title)) ||
           window.title.empty()) {
diff --git a/webrtc/modules/desktop_capture/mac/window_list_utils.h b/webrtc/modules/desktop_capture/mac/window_list_utils.h
index d56166f..7cc4571 100644
--- a/webrtc/modules/desktop_capture/mac/window_list_utils.h
+++ b/webrtc/modules/desktop_capture/mac/window_list_utils.h
@@ -13,17 +13,17 @@
 
 #include <ApplicationServices/ApplicationServices.h>
 
+#include "webrtc/modules/desktop_capture/desktop_capturer.h"
 #include "webrtc/modules/desktop_capture/mac/desktop_configuration.h"
-#include "webrtc/modules/desktop_capture/window_capturer.h"
 
 namespace webrtc {
 
-// A helper function to get the on-screen windows.
-bool GetWindowList(WindowCapturer::WindowList* windows);
+// Another helper function to get the on-screen windows.
+bool GetWindowList(DesktopCapturer::SourceList* windows, bool ignore_minimized);
 
 // Returns true if the window is occupying a full screen.
 bool IsWindowFullScreen(const MacDesktopConfiguration& desktop_config,
-                                 CFDictionaryRef window);
+                        CFDictionaryRef window);
 
 // Returns true if the window is minimized.
 bool IsWindowMinimized(CGWindowID id);
diff --git a/webrtc/modules/desktop_capture/mouse_cursor_monitor_unittest.cc b/webrtc/modules/desktop_capture/mouse_cursor_monitor_unittest.cc
index 663e970..59ad8e0 100644
--- a/webrtc/modules/desktop_capture/mouse_cursor_monitor_unittest.cc
+++ b/webrtc/modules/desktop_capture/mouse_cursor_monitor_unittest.cc
@@ -94,17 +94,17 @@
   if (!window_capturer.get())
     return;
 
-  WindowCapturer::WindowList windows;
-  EXPECT_TRUE(window_capturer->GetWindowList(&windows));
+  DesktopCapturer::SourceList sources;
+  EXPECT_TRUE(window_capturer->GetSourceList(&sources));
 
   // Iterate over all windows and try capturing mouse cursor for each of them.
-  for (size_t i = 0; i < windows.size(); ++i) {
+  for (size_t i = 0; i < sources.size(); ++i) {
     cursor_image_.reset();
     position_received_ = false;
 
     std::unique_ptr<MouseCursorMonitor> capturer(
         MouseCursorMonitor::CreateForWindow(
-            DesktopCaptureOptions::CreateDefault(), windows[i].id));
+            DesktopCaptureOptions::CreateDefault(), sources[i].id));
     assert(capturer.get());
 
     capturer->Init(this, MouseCursorMonitor::SHAPE_AND_POSITION);
diff --git a/webrtc/modules/desktop_capture/screen_capturer_x11.cc b/webrtc/modules/desktop_capture/screen_capturer_x11.cc
index fb8446e..1bd2d41 100644
--- a/webrtc/modules/desktop_capture/screen_capturer_x11.cc
+++ b/webrtc/modules/desktop_capture/screen_capturer_x11.cc
@@ -55,10 +55,8 @@
   // DesktopCapturer interface.
   void Start(Callback* delegate) override;
   void CaptureFrame() override;
-
-  // ScreenCapturer interface.
-  bool GetScreenList(ScreenList* screens) override;
-  bool SelectScreen(ScreenId id) override;
+  bool GetSourceList(SourceList* sources) override;
+  bool SelectSource(SourceId id) override;
 
  private:
   Display* display() { return options_.x_display()->display(); }
@@ -267,16 +265,14 @@
   callback_->OnCaptureResult(Result::SUCCESS, std::move(result));
 }
 
-bool ScreenCapturerLinux::GetScreenList(ScreenList* screens) {
-  RTC_DCHECK(screens->size() == 0);
+bool ScreenCapturerLinux::GetSourceList(SourceList* sources) {
+  RTC_DCHECK(sources->size() == 0);
   // TODO(jiayl): implement screen enumeration.
-  Screen default_screen;
-  default_screen.id = 0;
-  screens->push_back(default_screen);
+  sources->push_back({0});
   return true;
 }
 
-bool ScreenCapturerLinux::SelectScreen(ScreenId id) {
+bool ScreenCapturerLinux::SelectSource(SourceId id) {
   // TODO(jiayl): implement screen selection.
   return true;
 }
diff --git a/webrtc/modules/desktop_capture/win/screen_capture_utils.cc b/webrtc/modules/desktop_capture/win/screen_capture_utils.cc
index 1b33545..7d9203f 100644
--- a/webrtc/modules/desktop_capture/win/screen_capture_utils.cc
+++ b/webrtc/modules/desktop_capture/win/screen_capture_utils.cc
@@ -10,13 +10,14 @@
 
 #include "webrtc/modules/desktop_capture/win/screen_capture_utils.h"
 
-#include <assert.h>
 #include <windows.h>
 
+#include "webrtc/base/checks.h"
+
 namespace webrtc {
 
-bool GetScreenList(ScreenCapturer::ScreenList* screens) {
-  assert(screens->size() == 0);
+bool GetScreenList(DesktopCapturer::SourceList* screens) {
+  RTC_DCHECK(screens->size() == 0);
 
   BOOL enum_result = TRUE;
   for (int device_index = 0;; ++device_index) {
@@ -32,14 +33,12 @@
     if (!(device.StateFlags & DISPLAY_DEVICE_ACTIVE))
       continue;
 
-    ScreenCapturer::Screen screen;
-    screen.id = device_index;
-    screens->push_back(screen);
+    screens->push_back({device_index, std::string()});
   }
   return true;
 }
 
-bool IsScreenValid(ScreenId screen, std::wstring* device_key) {
+bool IsScreenValid(DesktopCapturer::SourceId screen, std::wstring* device_key) {
   if (screen == kFullDesktopScreenId) {
     *device_key = L"";
     return true;
@@ -54,7 +53,8 @@
   return !!enum_result;
 }
 
-DesktopRect GetScreenRect(ScreenId screen, const std::wstring& device_key) {
+DesktopRect GetScreenRect(DesktopCapturer::SourceId screen,
+                          const std::wstring& device_key) {
   if (screen == kFullDesktopScreenId) {
     return DesktopRect::MakeXYWH(GetSystemMetrics(SM_XVIRTUALSCREEN),
                                  GetSystemMetrics(SM_YVIRTUALSCREEN),
diff --git a/webrtc/modules/desktop_capture/win/screen_capture_utils.h b/webrtc/modules/desktop_capture/win/screen_capture_utils.h
index 42473e0..751588b 100644
--- a/webrtc/modules/desktop_capture/win/screen_capture_utils.h
+++ b/webrtc/modules/desktop_capture/win/screen_capture_utils.h
@@ -11,24 +11,25 @@
 #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_SCREEN_CAPTURE_UTILS_H_
 #define WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_SCREEN_CAPTURE_UTILS_H_
 
-#include "webrtc/modules/desktop_capture/screen_capturer.h"
+#include "webrtc/modules/desktop_capture/desktop_capturer.h"
 
 namespace webrtc {
 
 // Output the list of active screens into |screens|. Returns true if succeeded,
 // or false if it fails to enumerate the display devices.
-bool GetScreenList(ScreenCapturer::ScreenList* screens);
+bool GetScreenList(DesktopCapturer::SourceList* screens);
 
 // Returns true if |screen| is a valid screen. The screen device key is
 // returned through |device_key| if the screen is valid. The device key can be
 // used in GetScreenRect to verify the screen matches the previously obtained
 // id.
-bool IsScreenValid(ScreenId screen, std::wstring* device_key);
+bool IsScreenValid(DesktopCapturer::SourceId screen, std::wstring* device_key);
 
 // Get the rect of the screen identified by |screen|, relative to the primary
 // display's top-left. If the screen device key does not match |device_key|, or
 // the screen does not exist, or any error happens, an empty rect is returned.
-DesktopRect GetScreenRect(ScreenId screen, const std::wstring& device_key);
+DesktopRect GetScreenRect(DesktopCapturer::SourceId screen,
+                          const std::wstring& device_key);
 
 }  // namespace webrtc
 
diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.cc b/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.cc
index 770cfa2..bbd5c69 100644
--- a/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.cc
+++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.cc
@@ -109,15 +109,15 @@
   callback_->OnCaptureResult(Result::SUCCESS, std::move(result));
 }
 
-bool ScreenCapturerWinDirectx::GetScreenList(ScreenList* screens) {
+bool ScreenCapturerWinDirectx::GetSourceList(SourceList* sources) {
   int screen_count = DxgiDuplicatorController::Instance()->ScreenCount();
   for (int i = 0; i < screen_count; i++) {
-    screens->push_back(Screen{i});
+    sources->push_back({i});
   }
   return true;
 }
 
-bool ScreenCapturerWinDirectx::SelectScreen(ScreenId id) {
+bool ScreenCapturerWinDirectx::SelectSource(SourceId id) {
   if (id == current_screen_id_) {
     return true;
   }
diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h b/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h
index c84aac0..078bf17 100644
--- a/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h
+++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h
@@ -39,8 +39,8 @@
   void SetSharedMemoryFactory(
       std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override;
   void CaptureFrame() override;
-  bool GetScreenList(ScreenList* screens) override;
-  bool SelectScreen(ScreenId id) override;
+  bool GetSourceList(SourceList* sources) override;
+  bool SelectSource(SourceId id) override;
 
  private:
   // Returns desktop size of selected screen.
@@ -52,7 +52,7 @@
 
   DxgiDuplicatorController::Context context_;
 
-  ScreenId current_screen_id_ = kFullDesktopScreenId;
+  SourceId current_screen_id_ = kFullDesktopScreenId;
 
   RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCapturerWinDirectx);
 };
diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.cc b/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.cc
index 4bf8b14..b22f038 100644
--- a/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.cc
+++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.cc
@@ -98,11 +98,11 @@
   callback_->OnCaptureResult(Result::SUCCESS, std::move(frame));
 }
 
-bool ScreenCapturerWinGdi::GetScreenList(ScreenList* screens) {
-  return webrtc::GetScreenList(screens);
+bool ScreenCapturerWinGdi::GetSourceList(SourceList* sources) {
+  return webrtc::GetScreenList(sources);
 }
 
-bool ScreenCapturerWinGdi::SelectScreen(ScreenId id) {
+bool ScreenCapturerWinGdi::SelectSource(SourceId id) {
   bool valid = IsScreenValid(id, &current_device_key_);
   if (valid)
     current_screen_id_ = id;
diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.h b/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.h
index 1d08c1c..fc99bf1 100644
--- a/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.h
+++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.h
@@ -40,8 +40,8 @@
   void SetSharedMemoryFactory(
       std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override;
   void CaptureFrame() override;
-  bool GetScreenList(ScreenList* screens) override;
-  bool SelectScreen(ScreenId id) override;
+  bool GetSourceList(SourceList* sources) override;
+  bool SelectSource(SourceId id) override;
 
  private:
   typedef HRESULT (WINAPI * DwmEnableCompositionFunc)(UINT);
@@ -58,7 +58,7 @@
 
   Callback* callback_ = nullptr;
   std::unique_ptr<SharedMemoryFactory> shared_memory_factory_;
-  ScreenId current_screen_id_ = kFullDesktopScreenId;
+  SourceId current_screen_id_ = kFullDesktopScreenId;
   std::wstring current_device_key_;
 
   ScopedThreadDesktop desktop_;
diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc b/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc
index b425681..96348ca 100644
--- a/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc
+++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc
@@ -126,11 +126,11 @@
   callback_->OnCaptureResult(Result::SUCCESS, std::move(frame));
 }
 
-bool ScreenCapturerWinMagnifier::GetScreenList(ScreenList* screens) {
-  return webrtc::GetScreenList(screens);
+bool ScreenCapturerWinMagnifier::GetSourceList(SourceList* sources) {
+  return webrtc::GetScreenList(sources);
 }
 
-bool ScreenCapturerWinMagnifier::SelectScreen(ScreenId id) {
+bool ScreenCapturerWinMagnifier::SelectSource(SourceId id) {
   bool valid = IsScreenValid(id, &current_device_key_);
 
   // Set current_screen_id_ even if the fallback capturer is being used, so we
diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.h b/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.h
index 06b4ec6..0978d88 100644
--- a/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.h
+++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.h
@@ -52,8 +52,8 @@
   void SetSharedMemoryFactory(
       std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override;
   void CaptureFrame() override;
-  bool GetScreenList(ScreenList* screens) override;
-  bool SelectScreen(ScreenId id) override;
+  bool GetSourceList(SourceList* screens) override;
+  bool SelectSource(SourceId id) override;
   void SetExcludedWindow(WindowId window) override;
 
  private:
diff --git a/webrtc/modules/desktop_capture/window_capturer_mac.mm b/webrtc/modules/desktop_capture/window_capturer_mac.mm
index 72b20f3..7484f9f 100644
--- a/webrtc/modules/desktop_capture/window_capturer_mac.mm
+++ b/webrtc/modules/desktop_capture/window_capturer_mac.mm
@@ -48,14 +48,12 @@
                                  full_screen_chrome_window_detector);
   ~WindowCapturerMac() override;
 
-  // WindowCapturer interface.
-  bool GetWindowList(WindowList* windows) override;
-  bool SelectWindow(WindowId id) override;
-  bool BringSelectedWindowToFront() override;
-
   // DesktopCapturer interface.
   void Start(Callback* callback) override;
   void CaptureFrame() override;
+  bool GetSourceList(SourceList* sources) override;
+  bool SelectSource(SourceId id) override;
+  bool FocusOnSelectedSource() override;
 
  private:
   Callback* callback_ = nullptr;
@@ -76,63 +74,18 @@
 
 WindowCapturerMac::~WindowCapturerMac() {}
 
-bool WindowCapturerMac::GetWindowList(WindowList* windows) {
-  // Only get on screen, non-desktop windows.
-  CFArrayRef window_array = CGWindowListCopyWindowInfo(
-      kCGWindowListExcludeDesktopElements,
-      kCGNullWindowID);
-  if (!window_array)
-    return false;
-  MacDesktopConfiguration desktop_config = MacDesktopConfiguration::GetCurrent(
-      MacDesktopConfiguration::TopLeftOrigin);
-  // Check windows to make sure they have an id, title, and use window layer
-  // other than 0.
-  CFIndex count = CFArrayGetCount(window_array);
-  for (CFIndex i = 0; i < count; ++i) {
-    CFDictionaryRef window = reinterpret_cast<CFDictionaryRef>(
-        CFArrayGetValueAtIndex(window_array, i));
-    CFStringRef window_title = reinterpret_cast<CFStringRef>(
-        CFDictionaryGetValue(window, kCGWindowName));
-    CFNumberRef window_id = reinterpret_cast<CFNumberRef>(
-        CFDictionaryGetValue(window, kCGWindowNumber));
-    CFNumberRef window_layer = reinterpret_cast<CFNumberRef>(
-        CFDictionaryGetValue(window, kCGWindowLayer));
-    if (window_title && window_id && window_layer) {
-      // Skip windows with layer=0 (menu, dock).
-      int layer;
-      CFNumberGetValue(window_layer, kCFNumberIntType, &layer);
-      if (layer != 0)
-        continue;
-
-      int id;
-      CFNumberGetValue(window_id, kCFNumberIntType, &id);
-
-      // Skip windows that are minimized and not full screen.
-      if (IsWindowMinimized(id) &&
-          !IsWindowFullScreen(desktop_config, window)) { continue;}
-
-      WindowCapturer::Window window;
-      window.id = id;
-      if (!rtc::ToUtf8(window_title, &(window.title)) ||
-          window.title.empty()) {
-        continue;
-      }
-      windows->push_back(window);
-    }
-  }
-
-  CFRelease(window_array);
-  return true;
+bool WindowCapturerMac::GetSourceList(SourceList* sources) {
+  return webrtc::GetWindowList(sources, true);
 }
 
-bool WindowCapturerMac::SelectWindow(WindowId id) {
+bool WindowCapturerMac::SelectSource(SourceId id) {
   if (!IsWindowValid(id))
     return false;
   window_id_ = id;
   return true;
 }
 
-bool WindowCapturerMac::BringSelectedWindowToFront() {
+bool WindowCapturerMac::FocusOnSelectedSource() {
   if (!window_id_)
     return false;
 
diff --git a/webrtc/modules/desktop_capture/window_capturer_null.cc b/webrtc/modules/desktop_capture/window_capturer_null.cc
index 3afe533..7816513 100755
--- a/webrtc/modules/desktop_capture/window_capturer_null.cc
+++ b/webrtc/modules/desktop_capture/window_capturer_null.cc
@@ -24,14 +24,11 @@
   WindowCapturerNull();
   ~WindowCapturerNull() override;
 
-  // WindowCapturer interface.
-  bool GetWindowList(WindowList* windows) override;
-  bool SelectWindow(WindowId id) override;
-  bool BringSelectedWindowToFront() override;
-
   // DesktopCapturer interface.
   void Start(Callback* callback) override;
   void CaptureFrame() override;
+  bool GetSourceList(SourceList* sources) override;
+  bool SelectSource(SourceId id) override;
 
  private:
   Callback* callback_ = nullptr;
@@ -42,17 +39,12 @@
 WindowCapturerNull::WindowCapturerNull() {}
 WindowCapturerNull::~WindowCapturerNull() {}
 
-bool WindowCapturerNull::GetWindowList(WindowList* windows) {
+bool WindowCapturerNull::GetSourceList(SourceList* sources) {
   // Not implemented yet.
   return false;
 }
 
-bool WindowCapturerNull::SelectWindow(WindowId id) {
-  // Not implemented yet.
-  return false;
-}
-
-bool WindowCapturerNull::BringSelectedWindowToFront() {
+bool WindowCapturerNull::SelectSource(SourceId id) {
   // Not implemented yet.
   return false;
 }
diff --git a/webrtc/modules/desktop_capture/window_capturer_unittest.cc b/webrtc/modules/desktop_capture/window_capturer_unittest.cc
index a30d23e..e56a1de 100644
--- a/webrtc/modules/desktop_capture/window_capturer_unittest.cc
+++ b/webrtc/modules/desktop_capture/window_capturer_unittest.cc
@@ -43,12 +43,11 @@
 
 // Verify that we can enumerate windows.
 TEST_F(WindowCapturerTest, Enumerate) {
-  WindowCapturer::WindowList windows;
-  EXPECT_TRUE(capturer_->GetWindowList(&windows));
+  DesktopCapturer::SourceList sources;
+  EXPECT_TRUE(capturer_->GetSourceList(&sources));
 
   // Verify that window titles are set.
-  for (WindowCapturer::WindowList::iterator it = windows.begin();
-       it != windows.end(); ++it) {
+  for (auto it = sources.begin(); it != sources.end(); ++it) {
     EXPECT_FALSE(it->title.empty());
   }
 }
@@ -61,24 +60,23 @@
 // have a python script showing Tk dialog, but launching code will differ
 // between platforms).
 TEST_F(WindowCapturerTest, Capture) {
-  WindowCapturer::WindowList windows;
+  DesktopCapturer::SourceList sources;
   capturer_->Start(this);
-  EXPECT_TRUE(capturer_->GetWindowList(&windows));
+  EXPECT_TRUE(capturer_->GetSourceList(&sources));
 
   // Verify that we can select and capture each window.
-  for (WindowCapturer::WindowList::iterator it = windows.begin();
-       it != windows.end(); ++it) {
+  for (auto it = sources.begin(); it != sources.end(); ++it) {
     frame_.reset();
-    if (capturer_->SelectWindow(it->id)) {
+    if (capturer_->SelectSource(it->id)) {
       capturer_->CaptureFrame();
     }
 
     // If we failed to capture a window make sure it no longer exists.
     if (!frame_.get()) {
-      WindowCapturer::WindowList new_list;
-      EXPECT_TRUE(capturer_->GetWindowList(&new_list));
-      for (WindowCapturer::WindowList::iterator new_list_it = new_list.begin();
-           new_list_it != new_list.end(); ++new_list_it) {
+      DesktopCapturer::SourceList new_list;
+      EXPECT_TRUE(capturer_->GetSourceList(&new_list));
+      for (auto new_list_it = new_list.begin(); new_list_it != new_list.end();
+           ++new_list_it) {
         EXPECT_FALSE(it->id == new_list_it->id);
       }
       continue;
diff --git a/webrtc/modules/desktop_capture/window_capturer_win.cc b/webrtc/modules/desktop_capture/window_capturer_win.cc
index 101b17a..feb25c7 100644
--- a/webrtc/modules/desktop_capture/window_capturer_win.cc
+++ b/webrtc/modules/desktop_capture/window_capturer_win.cc
@@ -26,8 +26,8 @@
 namespace {
 
 BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) {
-  WindowCapturer::WindowList* list =
-      reinterpret_cast<WindowCapturer::WindowList*>(param);
+  DesktopCapturer::SourceList* list =
+      reinterpret_cast<DesktopCapturer::SourceList*>(param);
 
   // Skip windows that are invisible, minimized, have no title, or are owned,
   // unless they have the app window style set.
@@ -62,7 +62,7 @@
     return TRUE;
   }
 
-  WindowCapturer::Window window;
+  DesktopCapturer::Source window;
   window.id = reinterpret_cast<WindowId>(hwnd);
 
   const size_t kTitleLength = 500;
@@ -85,14 +85,12 @@
   WindowCapturerWin();
   ~WindowCapturerWin() override;
 
-  // WindowCapturer interface.
-  bool GetWindowList(WindowList* windows) override;
-  bool SelectWindow(WindowId id) override;
-  bool BringSelectedWindowToFront() override;
-
   // DesktopCapturer interface.
   void Start(Callback* callback) override;
   void CaptureFrame() override;
+  bool GetSourceList(SourceList* sources) override;
+  bool SelectSource(SourceId id) override;
+  bool FocusOnSelectedSource() override;
 
  private:
   Callback* callback_ = nullptr;
@@ -115,15 +113,15 @@
 WindowCapturerWin::WindowCapturerWin() {}
 WindowCapturerWin::~WindowCapturerWin() {}
 
-bool WindowCapturerWin::GetWindowList(WindowList* windows) {
-  WindowList result;
+bool WindowCapturerWin::GetSourceList(SourceList* sources) {
+  SourceList result;
   LPARAM param = reinterpret_cast<LPARAM>(&result);
   if (!EnumWindows(&WindowsEnumerationHandler, param))
     return false;
-  windows->swap(result);
+  sources->swap(result);
 
   std::map<HWND, DesktopSize> new_map;
-  for (const auto& item : *windows) {
+  for (const auto& item : *sources) {
     HWND hwnd = reinterpret_cast<HWND>(item.id);
     new_map[hwnd] = window_size_map_[hwnd];
   }
@@ -132,7 +130,7 @@
   return true;
 }
 
-bool WindowCapturerWin::SelectWindow(WindowId id) {
+bool WindowCapturerWin::SelectSource(SourceId id) {
   HWND window = reinterpret_cast<HWND>(id);
   if (!IsWindow(window) || !IsWindowVisible(window) || IsIconic(window))
     return false;
@@ -143,7 +141,7 @@
   return true;
 }
 
-bool WindowCapturerWin::BringSelectedWindowToFront() {
+bool WindowCapturerWin::FocusOnSelectedSource() {
   if (!window_)
     return false;
 
diff --git a/webrtc/modules/desktop_capture/window_capturer_x11.cc b/webrtc/modules/desktop_capture/window_capturer_x11.cc
index 11a27d5..eefd0f7 100644
--- a/webrtc/modules/desktop_capture/window_capturer_x11.cc
+++ b/webrtc/modules/desktop_capture/window_capturer_x11.cc
@@ -88,14 +88,12 @@
   WindowCapturerLinux(const DesktopCaptureOptions& options);
   ~WindowCapturerLinux() override;
 
-  // WindowCapturer interface.
-  bool GetWindowList(WindowList* windows) override;
-  bool SelectWindow(WindowId id) override;
-  bool BringSelectedWindowToFront() override;
-
   // DesktopCapturer interface.
   void Start(Callback* callback) override;
   void CaptureFrame() override;
+  bool GetSourceList(SourceList* sources) override;
+  bool SelectSource(SourceId id) override;
+  bool FocusOnSelectedSource() override;
 
   // SharedXDisplay::XEventHandler interface.
   bool HandleXEvent(const XEvent& event) override;
@@ -154,8 +152,8 @@
   x_display_->RemoveEventHandler(ConfigureNotify, this);
 }
 
-bool WindowCapturerLinux::GetWindowList(WindowList* windows) {
-  WindowList result;
+bool WindowCapturerLinux::GetSourceList(SourceList* sources) {
+  SourceList result;
 
   XErrorTrap error_trap(display());
 
@@ -178,7 +176,7 @@
       ::Window app_window =
           GetApplicationWindow(children[num_children - 1 - i]);
       if (app_window && !IsDesktopElement(app_window)) {
-        Window w;
+        Source w;
         w.id = app_window;
         if (GetWindowTitle(app_window, &w.title))
           result.push_back(w);
@@ -189,12 +187,12 @@
       XFree(children);
   }
 
-  windows->swap(result);
+  sources->swap(result);
 
   return true;
 }
 
-bool WindowCapturerLinux::SelectWindow(WindowId id) {
+bool WindowCapturerLinux::SelectSource(SourceId id) {
   if (!x_server_pixel_buffer_.Init(display(), id))
     return false;
 
@@ -215,7 +213,7 @@
   return true;
 }
 
-bool WindowCapturerLinux::BringSelectedWindowToFront() {
+bool WindowCapturerLinux::FocusOnSelectedSource() {
   if (!selected_window_)
     return false;