summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/rtc_base/win
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--third_party/libwebrtc/rtc_base/win/BUILD.gn68
-rw-r--r--third_party/libwebrtc/rtc_base/win/create_direct3d_device.cc57
-rw-r--r--third_party/libwebrtc/rtc_base/win/create_direct3d_device.h34
-rw-r--r--third_party/libwebrtc/rtc_base/win/create_direct3d_device_gn/moz.build84
-rw-r--r--third_party/libwebrtc/rtc_base/win/get_activation_factory.cc49
-rw-r--r--third_party/libwebrtc/rtc_base/win/get_activation_factory.h53
-rw-r--r--third_party/libwebrtc/rtc_base/win/get_activation_factory_gn/moz.build84
-rw-r--r--third_party/libwebrtc/rtc_base/win/hstring.cc62
-rw-r--r--third_party/libwebrtc/rtc_base/win/hstring.h30
-rw-r--r--third_party/libwebrtc/rtc_base/win/hstring_gn/moz.build84
-rw-r--r--third_party/libwebrtc/rtc_base/win/scoped_com_initializer.cc57
-rw-r--r--third_party/libwebrtc/rtc_base/win/scoped_com_initializer.h56
-rw-r--r--third_party/libwebrtc/rtc_base/win/windows_version.cc445
-rw-r--r--third_party/libwebrtc/rtc_base/win/windows_version.h156
-rw-r--r--third_party/libwebrtc/rtc_base/win/windows_version_gn/moz.build84
-rw-r--r--third_party/libwebrtc/rtc_base/win/windows_version_unittest.cc47
-rw-r--r--third_party/libwebrtc/rtc_base/win32.cc314
-rw-r--r--third_party/libwebrtc/rtc_base/win32.h48
-rw-r--r--third_party/libwebrtc/rtc_base/win32_gn/moz.build93
-rw-r--r--third_party/libwebrtc/rtc_base/win32_socket_init.h41
-rw-r--r--third_party/libwebrtc/rtc_base/win32_unittest.cc89
-rw-r--r--third_party/libwebrtc/rtc_base/win32_window.cc136
-rw-r--r--third_party/libwebrtc/rtc_base/win32_window.h70
-rw-r--r--third_party/libwebrtc/rtc_base/win32_window_unittest.cc66
24 files changed, 2307 insertions, 0 deletions
diff --git a/third_party/libwebrtc/rtc_base/win/BUILD.gn b/third_party/libwebrtc/rtc_base/win/BUILD.gn
new file mode 100644
index 0000000000..cf8bc21950
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win/BUILD.gn
@@ -0,0 +1,68 @@
+# Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
+#
+# Use of this source code is governed by a BSD-style license
+# that can be found in the LICENSE file in the root of the source
+# tree. An additional intellectual property rights grant can be found
+# in the file PATENTS. All contributing project authors may
+# be found in the AUTHORS file in the root of the source tree.
+
+import("../../webrtc.gni")
+
+rtc_library("create_direct3d_device") {
+ sources = [
+ "create_direct3d_device.cc",
+ "create_direct3d_device.h",
+ ]
+ data_deps = [ "//build/win:runtime_libs" ]
+}
+
+rtc_library("get_activation_factory") {
+ sources = [
+ "get_activation_factory.cc",
+ "get_activation_factory.h",
+ ]
+ data_deps = [ "//build/win:runtime_libs" ]
+ deps = [ ":hstring" ]
+}
+
+rtc_library("hstring") {
+ sources = [
+ "hstring.cc",
+ "hstring.h",
+ ]
+ data_deps = [ "//build/win:runtime_libs" ]
+}
+
+rtc_library("scoped_com_initializer") {
+ sources = [
+ "scoped_com_initializer.cc",
+ "scoped_com_initializer.h",
+ ]
+ data_deps = [ "//build/win:runtime_libs" ]
+ deps = [
+ "..:checks",
+ "..:logging",
+ ]
+}
+
+rtc_library("windows_version") {
+ sources = [
+ "windows_version.cc",
+ "windows_version.h",
+ ]
+ data_deps = [ "//build/win:runtime_libs" ]
+ deps = [
+ "..:checks",
+ "..:stringutils",
+ ]
+}
+
+rtc_library("windows_version_unittest") {
+ testonly = true
+ sources = [ "windows_version_unittest.cc" ]
+ deps = [
+ ":windows_version",
+ "..:gunit_helpers",
+ "..:logging",
+ ]
+}
diff --git a/third_party/libwebrtc/rtc_base/win/create_direct3d_device.cc b/third_party/libwebrtc/rtc_base/win/create_direct3d_device.cc
new file mode 100644
index 0000000000..02fe340d56
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win/create_direct3d_device.cc
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "rtc_base/win/create_direct3d_device.h"
+
+#include <libloaderapi.h>
+#include <utility>
+
+namespace {
+
+FARPROC LoadD3D11Function(const char* function_name) {
+ static HMODULE const handle =
+ ::LoadLibraryExW(L"d3d11.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
+ return handle ? ::GetProcAddress(handle, function_name) : nullptr;
+}
+
+decltype(&::CreateDirect3D11DeviceFromDXGIDevice)
+GetCreateDirect3D11DeviceFromDXGIDevice() {
+ static decltype(&::CreateDirect3D11DeviceFromDXGIDevice) const function =
+ reinterpret_cast<decltype(&::CreateDirect3D11DeviceFromDXGIDevice)>(
+ LoadD3D11Function("CreateDirect3D11DeviceFromDXGIDevice"));
+ return function;
+}
+
+} // namespace
+
+namespace webrtc {
+
+bool ResolveCoreWinRTDirect3DDelayload() {
+ return GetCreateDirect3D11DeviceFromDXGIDevice();
+}
+
+HRESULT CreateDirect3DDeviceFromDXGIDevice(
+ IDXGIDevice* dxgi_device,
+ ABI::Windows::Graphics::DirectX::Direct3D11::IDirect3DDevice**
+ out_d3d11_device) {
+ decltype(&::CreateDirect3D11DeviceFromDXGIDevice) create_d3d11_device_func =
+ GetCreateDirect3D11DeviceFromDXGIDevice();
+ if (!create_d3d11_device_func)
+ return E_FAIL;
+
+ Microsoft::WRL::ComPtr<IInspectable> inspectableSurface;
+ HRESULT hr = create_d3d11_device_func(dxgi_device, &inspectableSurface);
+ if (FAILED(hr))
+ return hr;
+
+ return inspectableSurface->QueryInterface(IID_PPV_ARGS(out_d3d11_device));
+}
+
+} // namespace webrtc
diff --git a/third_party/libwebrtc/rtc_base/win/create_direct3d_device.h b/third_party/libwebrtc/rtc_base/win/create_direct3d_device.h
new file mode 100644
index 0000000000..7c21f8720a
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win/create_direct3d_device.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef RTC_BASE_WIN_CREATE_DIRECT3D_DEVICE_H_
+#define RTC_BASE_WIN_CREATE_DIRECT3D_DEVICE_H_
+
+#include <windows.graphics.directX.direct3d11.h>
+#include <windows.graphics.directX.direct3d11.interop.h>
+#include <winerror.h>
+#include <wrl/client.h>
+
+namespace webrtc {
+
+// Callers must check the return value of ResolveCoreWinRTDirect3DDelayload()
+// before using CreateDirect3DDeviceFromDXGIDevice().
+bool ResolveCoreWinRTDirect3DDelayload();
+
+// Allows for the creating of Direct3D Devices from a DXGI device on versions
+// of Windows greater than Win7.
+HRESULT CreateDirect3DDeviceFromDXGIDevice(
+ IDXGIDevice* dxgi_device,
+ ABI::Windows::Graphics::DirectX::Direct3D11::IDirect3DDevice**
+ out_d3d11_device);
+
+} // namespace webrtc
+
+#endif // RTC_BASE_WIN_CREATE_DIRECT3D_DEVICE_H_
diff --git a/third_party/libwebrtc/rtc_base/win/create_direct3d_device_gn/moz.build b/third_party/libwebrtc/rtc_base/win/create_direct3d_device_gn/moz.build
new file mode 100644
index 0000000000..d5882af2bb
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win/create_direct3d_device_gn/moz.build
@@ -0,0 +1,84 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+ ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ###
+ ### DO NOT edit it by hand. ###
+
+COMPILE_FLAGS["OS_INCLUDES"] = []
+AllowCompilerWarnings()
+
+DEFINES["ABSL_ALLOCATOR_NOTHROW"] = "1"
+DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True
+DEFINES["NOMINMAX"] = True
+DEFINES["NTDDI_VERSION"] = "0x0A000000"
+DEFINES["PSAPI_VERSION"] = "2"
+DEFINES["RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY"] = True
+DEFINES["RTC_ENABLE_VP9"] = True
+DEFINES["UNICODE"] = True
+DEFINES["USE_AURA"] = "1"
+DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0"
+DEFINES["WEBRTC_LIBRARY_IMPL"] = True
+DEFINES["WEBRTC_MOZILLA_BUILD"] = True
+DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0"
+DEFINES["WEBRTC_STRICT_FIELD_TRIALS"] = "0"
+DEFINES["WEBRTC_WIN"] = True
+DEFINES["WIN32"] = True
+DEFINES["WIN32_LEAN_AND_MEAN"] = True
+DEFINES["WINAPI_FAMILY"] = "WINAPI_FAMILY_DESKTOP_APP"
+DEFINES["WINVER"] = "0x0A00"
+DEFINES["_ATL_NO_OPENGL"] = True
+DEFINES["_CRT_RAND_S"] = True
+DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True
+DEFINES["_ENABLE_EXTENDED_ALIGNED_STORAGE"] = True
+DEFINES["_HAS_EXCEPTIONS"] = "0"
+DEFINES["_HAS_NODISCARD"] = True
+DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True
+DEFINES["_SECURE_ATL"] = True
+DEFINES["_UNICODE"] = True
+DEFINES["_WIN32_WINNT"] = "0x0A00"
+DEFINES["_WINDOWS"] = True
+DEFINES["__STD_C"] = True
+
+FINAL_LIBRARY = "webrtc"
+
+
+LOCAL_INCLUDES += [
+ "!/ipc/ipdl/_ipdlheaders",
+ "!/third_party/libwebrtc/gen",
+ "/ipc/chromium/src",
+ "/third_party/libwebrtc/",
+ "/third_party/libwebrtc/third_party/abseil-cpp/",
+ "/tools/profiler/public"
+]
+
+UNIFIED_SOURCES += [
+ "/third_party/libwebrtc/rtc_base/win/create_direct3d_device.cc"
+]
+
+if not CONFIG["MOZ_DEBUG"]:
+
+ DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0"
+ DEFINES["NDEBUG"] = True
+ DEFINES["NVALGRIND"] = True
+
+if CONFIG["MOZ_DEBUG"] == "1":
+
+ DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1"
+ DEFINES["_HAS_ITERATOR_DEBUGGING"] = "0"
+
+if CONFIG["CPU_ARCH"] == "aarch64":
+
+ DEFINES["WEBRTC_ARCH_ARM64"] = True
+ DEFINES["WEBRTC_HAS_NEON"] = True
+
+if CONFIG["CPU_ARCH"] == "x86":
+
+ DEFINES["WEBRTC_ENABLE_AVX2"] = True
+
+if CONFIG["CPU_ARCH"] == "x86_64":
+
+ DEFINES["WEBRTC_ENABLE_AVX2"] = True
+
+Library("create_direct3d_device_gn")
diff --git a/third_party/libwebrtc/rtc_base/win/get_activation_factory.cc b/third_party/libwebrtc/rtc_base/win/get_activation_factory.cc
new file mode 100644
index 0000000000..b3be9abfa7
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win/get_activation_factory.cc
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "rtc_base/win/get_activation_factory.h"
+
+#include <libloaderapi.h>
+#include <roapi.h>
+
+namespace {
+
+FARPROC LoadComBaseFunction(const char* function_name) {
+ static HMODULE const handle =
+ ::LoadLibraryExW(L"combase.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
+ return handle ? ::GetProcAddress(handle, function_name) : nullptr;
+}
+
+decltype(&::RoGetActivationFactory) GetRoGetActivationFactoryFunction() {
+ static decltype(&::RoGetActivationFactory) const function =
+ reinterpret_cast<decltype(&::RoGetActivationFactory)>(
+ LoadComBaseFunction("RoGetActivationFactory"));
+ return function;
+}
+
+} // namespace
+
+namespace webrtc {
+
+bool ResolveCoreWinRTDelayload() {
+ return GetRoGetActivationFactoryFunction() &&
+ ResolveCoreWinRTStringDelayload();
+}
+
+HRESULT RoGetActivationFactoryProxy(HSTRING class_id,
+ const IID& iid,
+ void** out_factory) {
+ auto get_factory_func = GetRoGetActivationFactoryFunction();
+ if (!get_factory_func)
+ return E_FAIL;
+ return get_factory_func(class_id, iid, out_factory);
+}
+
+} // namespace webrtc
diff --git a/third_party/libwebrtc/rtc_base/win/get_activation_factory.h b/third_party/libwebrtc/rtc_base/win/get_activation_factory.h
new file mode 100644
index 0000000000..08f602f0c4
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win/get_activation_factory.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef RTC_BASE_WIN_GET_ACTIVATION_FACTORY_H_
+#define RTC_BASE_WIN_GET_ACTIVATION_FACTORY_H_
+
+#include <winerror.h>
+
+#include "rtc_base/win/hstring.h"
+
+namespace webrtc {
+
+// Provides access to Core WinRT functions which may not be available on
+// Windows 7. Loads functions dynamically at runtime to prevent library
+// dependencies.
+
+// Callers must check the return value of ResolveCoreWinRTDelayLoad() before
+// using these functions.
+
+bool ResolveCoreWinRTDelayload();
+
+HRESULT RoGetActivationFactoryProxy(HSTRING class_id,
+ const IID& iid,
+ void** out_factory);
+
+// Retrieves an activation factory for the type specified.
+template <typename InterfaceType, wchar_t const* runtime_class_id>
+HRESULT GetActivationFactory(InterfaceType** factory) {
+ HSTRING class_id_hstring;
+ HRESULT hr = CreateHstring(runtime_class_id, wcslen(runtime_class_id),
+ &class_id_hstring);
+ if (FAILED(hr))
+ return hr;
+
+ hr = RoGetActivationFactoryProxy(class_id_hstring, IID_PPV_ARGS(factory));
+ if (FAILED(hr)) {
+ DeleteHstring(class_id_hstring);
+ return hr;
+ }
+
+ return DeleteHstring(class_id_hstring);
+}
+
+} // namespace webrtc
+
+#endif // RTC_BASE_WIN_GET_ACTIVATION_FACTORY_H_
diff --git a/third_party/libwebrtc/rtc_base/win/get_activation_factory_gn/moz.build b/third_party/libwebrtc/rtc_base/win/get_activation_factory_gn/moz.build
new file mode 100644
index 0000000000..d2449d9860
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win/get_activation_factory_gn/moz.build
@@ -0,0 +1,84 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+ ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ###
+ ### DO NOT edit it by hand. ###
+
+COMPILE_FLAGS["OS_INCLUDES"] = []
+AllowCompilerWarnings()
+
+DEFINES["ABSL_ALLOCATOR_NOTHROW"] = "1"
+DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True
+DEFINES["NOMINMAX"] = True
+DEFINES["NTDDI_VERSION"] = "0x0A000000"
+DEFINES["PSAPI_VERSION"] = "2"
+DEFINES["RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY"] = True
+DEFINES["RTC_ENABLE_VP9"] = True
+DEFINES["UNICODE"] = True
+DEFINES["USE_AURA"] = "1"
+DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0"
+DEFINES["WEBRTC_LIBRARY_IMPL"] = True
+DEFINES["WEBRTC_MOZILLA_BUILD"] = True
+DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0"
+DEFINES["WEBRTC_STRICT_FIELD_TRIALS"] = "0"
+DEFINES["WEBRTC_WIN"] = True
+DEFINES["WIN32"] = True
+DEFINES["WIN32_LEAN_AND_MEAN"] = True
+DEFINES["WINAPI_FAMILY"] = "WINAPI_FAMILY_DESKTOP_APP"
+DEFINES["WINVER"] = "0x0A00"
+DEFINES["_ATL_NO_OPENGL"] = True
+DEFINES["_CRT_RAND_S"] = True
+DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True
+DEFINES["_ENABLE_EXTENDED_ALIGNED_STORAGE"] = True
+DEFINES["_HAS_EXCEPTIONS"] = "0"
+DEFINES["_HAS_NODISCARD"] = True
+DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True
+DEFINES["_SECURE_ATL"] = True
+DEFINES["_UNICODE"] = True
+DEFINES["_WIN32_WINNT"] = "0x0A00"
+DEFINES["_WINDOWS"] = True
+DEFINES["__STD_C"] = True
+
+FINAL_LIBRARY = "webrtc"
+
+
+LOCAL_INCLUDES += [
+ "!/ipc/ipdl/_ipdlheaders",
+ "!/third_party/libwebrtc/gen",
+ "/ipc/chromium/src",
+ "/third_party/libwebrtc/",
+ "/third_party/libwebrtc/third_party/abseil-cpp/",
+ "/tools/profiler/public"
+]
+
+UNIFIED_SOURCES += [
+ "/third_party/libwebrtc/rtc_base/win/get_activation_factory.cc"
+]
+
+if not CONFIG["MOZ_DEBUG"]:
+
+ DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0"
+ DEFINES["NDEBUG"] = True
+ DEFINES["NVALGRIND"] = True
+
+if CONFIG["MOZ_DEBUG"] == "1":
+
+ DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1"
+ DEFINES["_HAS_ITERATOR_DEBUGGING"] = "0"
+
+if CONFIG["CPU_ARCH"] == "aarch64":
+
+ DEFINES["WEBRTC_ARCH_ARM64"] = True
+ DEFINES["WEBRTC_HAS_NEON"] = True
+
+if CONFIG["CPU_ARCH"] == "x86":
+
+ DEFINES["WEBRTC_ENABLE_AVX2"] = True
+
+if CONFIG["CPU_ARCH"] == "x86_64":
+
+ DEFINES["WEBRTC_ENABLE_AVX2"] = True
+
+Library("get_activation_factory_gn")
diff --git a/third_party/libwebrtc/rtc_base/win/hstring.cc b/third_party/libwebrtc/rtc_base/win/hstring.cc
new file mode 100644
index 0000000000..5a362a97c9
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win/hstring.cc
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "rtc_base/win/hstring.h"
+
+#include <libloaderapi.h>
+#include <winstring.h>
+
+namespace {
+
+FARPROC LoadComBaseFunction(const char* function_name) {
+ static HMODULE const handle =
+ ::LoadLibraryExW(L"combase.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
+ return handle ? ::GetProcAddress(handle, function_name) : nullptr;
+}
+
+decltype(&::WindowsCreateString) GetWindowsCreateString() {
+ static decltype(&::WindowsCreateString) const function =
+ reinterpret_cast<decltype(&::WindowsCreateString)>(
+ LoadComBaseFunction("WindowsCreateString"));
+ return function;
+}
+
+decltype(&::WindowsDeleteString) GetWindowsDeleteString() {
+ static decltype(&::WindowsDeleteString) const function =
+ reinterpret_cast<decltype(&::WindowsDeleteString)>(
+ LoadComBaseFunction("WindowsDeleteString"));
+ return function;
+}
+
+} // namespace
+
+namespace webrtc {
+
+bool ResolveCoreWinRTStringDelayload() {
+ return GetWindowsDeleteString() && GetWindowsCreateString();
+}
+
+HRESULT CreateHstring(const wchar_t* src, uint32_t len, HSTRING* out_hstr) {
+ decltype(&::WindowsCreateString) create_string_func =
+ GetWindowsCreateString();
+ if (!create_string_func)
+ return E_FAIL;
+ return create_string_func(src, len, out_hstr);
+}
+
+HRESULT DeleteHstring(HSTRING hstr) {
+ decltype(&::WindowsDeleteString) delete_string_func =
+ GetWindowsDeleteString();
+ if (!delete_string_func)
+ return E_FAIL;
+ return delete_string_func(hstr);
+}
+
+} // namespace webrtc
diff --git a/third_party/libwebrtc/rtc_base/win/hstring.h b/third_party/libwebrtc/rtc_base/win/hstring.h
new file mode 100644
index 0000000000..8fb119a9e6
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win/hstring.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef RTC_BASE_WIN_HSTRING_H_
+#define RTC_BASE_WIN_HSTRING_H_
+
+#include <hstring.h>
+#include <stdint.h>
+#include <winerror.h>
+
+namespace webrtc {
+
+// Callers must check the return value of ResolveCoreWinRTStringDelayLoad()
+// before using these functions.
+bool ResolveCoreWinRTStringDelayload();
+
+HRESULT CreateHstring(const wchar_t* src, uint32_t len, HSTRING* out_hstr);
+
+HRESULT DeleteHstring(HSTRING hstr);
+
+} // namespace webrtc
+
+#endif // RTC_BASE_WIN_HSTRING_H_
diff --git a/third_party/libwebrtc/rtc_base/win/hstring_gn/moz.build b/third_party/libwebrtc/rtc_base/win/hstring_gn/moz.build
new file mode 100644
index 0000000000..3a495f5b6c
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win/hstring_gn/moz.build
@@ -0,0 +1,84 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+ ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ###
+ ### DO NOT edit it by hand. ###
+
+COMPILE_FLAGS["OS_INCLUDES"] = []
+AllowCompilerWarnings()
+
+DEFINES["ABSL_ALLOCATOR_NOTHROW"] = "1"
+DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True
+DEFINES["NOMINMAX"] = True
+DEFINES["NTDDI_VERSION"] = "0x0A000000"
+DEFINES["PSAPI_VERSION"] = "2"
+DEFINES["RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY"] = True
+DEFINES["RTC_ENABLE_VP9"] = True
+DEFINES["UNICODE"] = True
+DEFINES["USE_AURA"] = "1"
+DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0"
+DEFINES["WEBRTC_LIBRARY_IMPL"] = True
+DEFINES["WEBRTC_MOZILLA_BUILD"] = True
+DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0"
+DEFINES["WEBRTC_STRICT_FIELD_TRIALS"] = "0"
+DEFINES["WEBRTC_WIN"] = True
+DEFINES["WIN32"] = True
+DEFINES["WIN32_LEAN_AND_MEAN"] = True
+DEFINES["WINAPI_FAMILY"] = "WINAPI_FAMILY_DESKTOP_APP"
+DEFINES["WINVER"] = "0x0A00"
+DEFINES["_ATL_NO_OPENGL"] = True
+DEFINES["_CRT_RAND_S"] = True
+DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True
+DEFINES["_ENABLE_EXTENDED_ALIGNED_STORAGE"] = True
+DEFINES["_HAS_EXCEPTIONS"] = "0"
+DEFINES["_HAS_NODISCARD"] = True
+DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True
+DEFINES["_SECURE_ATL"] = True
+DEFINES["_UNICODE"] = True
+DEFINES["_WIN32_WINNT"] = "0x0A00"
+DEFINES["_WINDOWS"] = True
+DEFINES["__STD_C"] = True
+
+FINAL_LIBRARY = "webrtc"
+
+
+LOCAL_INCLUDES += [
+ "!/ipc/ipdl/_ipdlheaders",
+ "!/third_party/libwebrtc/gen",
+ "/ipc/chromium/src",
+ "/third_party/libwebrtc/",
+ "/third_party/libwebrtc/third_party/abseil-cpp/",
+ "/tools/profiler/public"
+]
+
+SOURCES += [
+ "/third_party/libwebrtc/rtc_base/win/hstring.cc"
+]
+
+if not CONFIG["MOZ_DEBUG"]:
+
+ DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0"
+ DEFINES["NDEBUG"] = True
+ DEFINES["NVALGRIND"] = True
+
+if CONFIG["MOZ_DEBUG"] == "1":
+
+ DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1"
+ DEFINES["_HAS_ITERATOR_DEBUGGING"] = "0"
+
+if CONFIG["CPU_ARCH"] == "aarch64":
+
+ DEFINES["WEBRTC_ARCH_ARM64"] = True
+ DEFINES["WEBRTC_HAS_NEON"] = True
+
+if CONFIG["CPU_ARCH"] == "x86":
+
+ DEFINES["WEBRTC_ENABLE_AVX2"] = True
+
+if CONFIG["CPU_ARCH"] == "x86_64":
+
+ DEFINES["WEBRTC_ENABLE_AVX2"] = True
+
+Library("hstring_gn")
diff --git a/third_party/libwebrtc/rtc_base/win/scoped_com_initializer.cc b/third_party/libwebrtc/rtc_base/win/scoped_com_initializer.cc
new file mode 100644
index 0000000000..4b56772ebf
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win/scoped_com_initializer.cc
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "rtc_base/win/scoped_com_initializer.h"
+
+#include "rtc_base/checks.h"
+#include "rtc_base/logging.h"
+
+namespace webrtc {
+
+ScopedCOMInitializer::ScopedCOMInitializer() {
+ RTC_DLOG(LS_INFO) << "Single-Threaded Apartment (STA) COM thread";
+ Initialize(COINIT_APARTMENTTHREADED);
+}
+
+// Constructor for MTA initialization.
+ScopedCOMInitializer::ScopedCOMInitializer(SelectMTA mta) {
+ RTC_DLOG(LS_INFO) << "Multi-Threaded Apartment (MTA) COM thread";
+ Initialize(COINIT_MULTITHREADED);
+}
+
+ScopedCOMInitializer::~ScopedCOMInitializer() {
+ if (Succeeded()) {
+ CoUninitialize();
+ }
+}
+
+void ScopedCOMInitializer::Initialize(COINIT init) {
+ // Initializes the COM library for use by the calling thread, sets the
+ // thread's concurrency model, and creates a new apartment for the thread
+ // if one is required. CoInitializeEx must be called at least once, and is
+ // usually called only once, for each thread that uses the COM library.
+ hr_ = CoInitializeEx(NULL, init);
+ RTC_CHECK_NE(RPC_E_CHANGED_MODE, hr_)
+ << "Invalid COM thread model change (MTA->STA)";
+ // Multiple calls to CoInitializeEx by the same thread are allowed as long
+ // as they pass the same concurrency flag, but subsequent valid calls
+ // return S_FALSE. To close the COM library gracefully on a thread, each
+ // successful call to CoInitializeEx, including any call that returns
+ // S_FALSE, must be balanced by a corresponding call to CoUninitialize.
+ if (hr_ == S_OK) {
+ RTC_DLOG(LS_INFO)
+ << "The COM library was initialized successfully on this thread";
+ } else if (hr_ == S_FALSE) {
+ RTC_DLOG(LS_WARNING)
+ << "The COM library is already initialized on this thread";
+ }
+}
+
+} // namespace webrtc
diff --git a/third_party/libwebrtc/rtc_base/win/scoped_com_initializer.h b/third_party/libwebrtc/rtc_base/win/scoped_com_initializer.h
new file mode 100644
index 0000000000..2427097b5b
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win/scoped_com_initializer.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef RTC_BASE_WIN_SCOPED_COM_INITIALIZER_H_
+#define RTC_BASE_WIN_SCOPED_COM_INITIALIZER_H_
+
+#include <comdef.h>
+
+namespace webrtc {
+
+// Initializes COM in the constructor (STA or MTA), and uninitializes COM in the
+// destructor. Taken from base::win::ScopedCOMInitializer.
+//
+// WARNING: This should only be used once per thread, ideally scoped to a
+// similar lifetime as the thread itself. You should not be using this in
+// random utility functions that make COM calls; instead ensure that these
+// functions are running on a COM-supporting thread!
+// See https://msdn.microsoft.com/en-us/library/ms809971.aspx for details.
+class ScopedCOMInitializer {
+ public:
+ // Enum value provided to initialize the thread as an MTA instead of STA.
+ // There are two types of apartments, Single Threaded Apartments (STAs)
+ // and Multi Threaded Apartments (MTAs). Within a given process there can
+ // be multiple STA’s but there is only one MTA. STA is typically used by
+ // "GUI applications" and MTA by "worker threads" with no UI message loop.
+ enum SelectMTA { kMTA };
+
+ // Constructor for STA initialization.
+ ScopedCOMInitializer();
+
+ // Constructor for MTA initialization.
+ explicit ScopedCOMInitializer(SelectMTA mta);
+
+ ~ScopedCOMInitializer();
+
+ ScopedCOMInitializer(const ScopedCOMInitializer&) = delete;
+ ScopedCOMInitializer& operator=(const ScopedCOMInitializer&) = delete;
+
+ bool Succeeded() { return SUCCEEDED(hr_); }
+
+ private:
+ void Initialize(COINIT init);
+
+ HRESULT hr_;
+};
+
+} // namespace webrtc
+
+#endif // RTC_BASE_WIN_SCOPED_COM_INITIALIZER_H_
diff --git a/third_party/libwebrtc/rtc_base/win/windows_version.cc b/third_party/libwebrtc/rtc_base/win/windows_version.cc
new file mode 100644
index 0000000000..93af1377be
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win/windows_version.cc
@@ -0,0 +1,445 @@
+/*
+ * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "rtc_base/win/windows_version.h"
+
+#include <windows.h>
+
+#include <memory>
+
+#include "rtc_base/checks.h"
+#include "rtc_base/string_utils.h"
+
+#if !defined(__clang__) && _MSC_FULL_VER < 191125507
+#error VS 2017 Update 3.2 or higher is required
+#endif
+
+#if !defined(WINUWP)
+
+namespace {
+
+typedef BOOL(WINAPI* GetProductInfoPtr)(DWORD, DWORD, DWORD, DWORD, PDWORD);
+
+// Mask to pull WOW64 access flags out of REGSAM access.
+const REGSAM kWow64AccessMask = KEY_WOW64_32KEY | KEY_WOW64_64KEY;
+
+// Utility class to read, write and manipulate the Windows Registry.
+// Registry vocabulary primer: a "key" is like a folder, in which there
+// are "values", which are <name, data> pairs, with an associated data type.
+// Based on base::win::RegKey but only implements a small fraction of it.
+class RegKey {
+ public:
+ RegKey() : key_(nullptr), wow64access_(0) {}
+
+ RegKey(HKEY rootkey, const wchar_t* subkey, REGSAM access)
+ : key_(nullptr), wow64access_(0) {
+ if (rootkey) {
+ if (access & (KEY_SET_VALUE | KEY_CREATE_SUB_KEY | KEY_CREATE_LINK))
+ Create(rootkey, subkey, access);
+ else
+ Open(rootkey, subkey, access);
+ } else {
+ RTC_DCHECK(!subkey);
+ wow64access_ = access & kWow64AccessMask;
+ }
+ }
+
+ ~RegKey() { Close(); }
+
+ LONG Create(HKEY rootkey, const wchar_t* subkey, REGSAM access) {
+ DWORD disposition_value;
+ return CreateWithDisposition(rootkey, subkey, &disposition_value, access);
+ }
+
+ LONG CreateWithDisposition(HKEY rootkey,
+ const wchar_t* subkey,
+ DWORD* disposition,
+ REGSAM access) {
+ RTC_DCHECK(rootkey && subkey && access && disposition);
+ HKEY subhkey = NULL;
+ LONG result =
+ ::RegCreateKeyExW(rootkey, subkey, 0, NULL, REG_OPTION_NON_VOLATILE,
+ access, NULL, &subhkey, disposition);
+ if (result == ERROR_SUCCESS) {
+ Close();
+ key_ = subhkey;
+ wow64access_ = access & kWow64AccessMask;
+ }
+
+ return result;
+ }
+
+ // Opens an existing reg key.
+ LONG Open(HKEY rootkey, const wchar_t* subkey, REGSAM access) {
+ RTC_DCHECK(rootkey && subkey && access);
+ HKEY subhkey = NULL;
+
+ LONG result = ::RegOpenKeyExW(rootkey, subkey, 0, access, &subhkey);
+ if (result == ERROR_SUCCESS) {
+ Close();
+ key_ = subhkey;
+ wow64access_ = access & kWow64AccessMask;
+ }
+
+ return result;
+ }
+
+ // Closes this reg key.
+ void Close() {
+ if (key_) {
+ ::RegCloseKey(key_);
+ key_ = nullptr;
+ }
+ }
+
+ // Reads a REG_DWORD (uint32_t) into `out_value`. If `name` is null or empty,
+ // reads the key's default value, if any.
+ LONG ReadValueDW(const wchar_t* name, DWORD* out_value) const {
+ RTC_DCHECK(out_value);
+ DWORD type = REG_DWORD;
+ DWORD size = sizeof(DWORD);
+ DWORD local_value = 0;
+ LONG result = ReadValue(name, &local_value, &size, &type);
+ if (result == ERROR_SUCCESS) {
+ if ((type == REG_DWORD || type == REG_BINARY) && size == sizeof(DWORD))
+ *out_value = local_value;
+ else
+ result = ERROR_CANTREAD;
+ }
+
+ return result;
+ }
+
+ // Reads a string into `out_value`. If `name` is null or empty, reads
+ // the key's default value, if any.
+ LONG ReadValue(const wchar_t* name, std::wstring* out_value) const {
+ RTC_DCHECK(out_value);
+ const size_t kMaxStringLength = 1024; // This is after expansion.
+ // Use the one of the other forms of ReadValue if 1024 is too small for you.
+ wchar_t raw_value[kMaxStringLength];
+ DWORD type = REG_SZ, size = sizeof(raw_value);
+ LONG result = ReadValue(name, raw_value, &size, &type);
+ if (result == ERROR_SUCCESS) {
+ if (type == REG_SZ) {
+ *out_value = raw_value;
+ } else if (type == REG_EXPAND_SZ) {
+ wchar_t expanded[kMaxStringLength];
+ size =
+ ::ExpandEnvironmentStringsW(raw_value, expanded, kMaxStringLength);
+ // Success: returns the number of wchar_t's copied
+ // Fail: buffer too small, returns the size required
+ // Fail: other, returns 0
+ if (size == 0 || size > kMaxStringLength) {
+ result = ERROR_MORE_DATA;
+ } else {
+ *out_value = expanded;
+ }
+ } else {
+ // Not a string. Oops.
+ result = ERROR_CANTREAD;
+ }
+ }
+
+ return result;
+ }
+
+ LONG ReadValue(const wchar_t* name,
+ void* data,
+ DWORD* dsize,
+ DWORD* dtype) const {
+ LONG result = RegQueryValueExW(key_, name, 0, dtype,
+ reinterpret_cast<LPBYTE>(data), dsize);
+ return result;
+ }
+
+ private:
+ HKEY key_;
+ REGSAM wow64access_;
+};
+
+} // namespace
+
+#endif // !defined(WINUWP)
+
+namespace rtc {
+namespace rtc_win {
+namespace {
+
+// Helper to map a major.minor.x.build version (e.g. 6.1) to a Windows release.
+Version MajorMinorBuildToVersion(int major, int minor, int build) {
+ if ((major == 5) && (minor > 0)) {
+ // Treat XP Pro x64, Home Server, and Server 2003 R2 as Server 2003.
+ return (minor == 1) ? VERSION_XP : VERSION_SERVER_2003;
+ } else if (major == 6) {
+ switch (minor) {
+ case 0:
+ // Treat Windows Server 2008 the same as Windows Vista.
+ return VERSION_VISTA;
+ case 1:
+ // Treat Windows Server 2008 R2 the same as Windows 7.
+ return VERSION_WIN7;
+ case 2:
+ // Treat Windows Server 2012 the same as Windows 8.
+ return VERSION_WIN8;
+ default:
+ RTC_DCHECK_EQ(minor, 3);
+ return VERSION_WIN8_1;
+ }
+ } else if (major == 10) {
+ if (build < 10586) {
+ return VERSION_WIN10;
+ } else if (build < 14393) {
+ return VERSION_WIN10_TH2;
+ } else if (build < 15063) {
+ return VERSION_WIN10_RS1;
+ } else if (build < 16299) {
+ return VERSION_WIN10_RS2;
+ } else if (build < 17134) {
+ return VERSION_WIN10_RS3;
+ } else if (build < 17763) {
+ return VERSION_WIN10_RS4;
+ } else if (build < 18362) {
+ return VERSION_WIN10_RS5;
+ } else if (build < 18363) {
+ return VERSION_WIN10_19H1;
+ } else if (build < 19041) {
+ return VERSION_WIN10_19H2;
+ } else if (build < 19042) {
+ return VERSION_WIN10_20H1;
+ } else if (build < 19043) {
+ return VERSION_WIN10_20H2;
+ } else if (build < 19044) {
+ return VERSION_WIN10_21H1;
+ } else if (build < 20348) {
+ return VERSION_WIN10_21H2;
+ } else if (build < 22000) {
+ return VERSION_SERVER_2022;
+ } else {
+ return VERSION_WIN11;
+ }
+ } else if (major == 11) {
+ return VERSION_WIN11;
+ } else if (major > 6) {
+ RTC_DCHECK_NOTREACHED();
+ return VERSION_WIN_LAST;
+ }
+
+ return VERSION_PRE_XP;
+}
+
+// Returns the the "UBR" value from the registry. Introduced in Windows 10,
+// this undocumented value appears to be similar to a patch number.
+// Returns 0 if the value does not exist or it could not be read.
+int GetUBR() {
+#if defined(WINUWP)
+ // The registry is not accessible for WinUWP sandboxed store applications.
+ return 0;
+#else
+ // The values under the CurrentVersion registry hive are mirrored under
+ // the corresponding Wow6432 hive.
+ static constexpr wchar_t kRegKeyWindowsNTCurrentVersion[] =
+ L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
+
+ RegKey key;
+ if (key.Open(HKEY_LOCAL_MACHINE, kRegKeyWindowsNTCurrentVersion,
+ KEY_QUERY_VALUE) != ERROR_SUCCESS) {
+ return 0;
+ }
+
+ DWORD ubr = 0;
+ key.ReadValueDW(L"UBR", &ubr);
+
+ return static_cast<int>(ubr);
+#endif // defined(WINUWP)
+}
+
+} // namespace
+
+// static
+OSInfo* OSInfo::GetInstance() {
+ // Note: we don't use the Singleton class because it depends on AtExitManager,
+ // and it's convenient for other modules to use this class without it. This
+ // pattern is copied from gurl.cc.
+ static OSInfo* info;
+ if (!info) {
+ OSInfo* new_info = new OSInfo();
+ if (InterlockedCompareExchangePointer(reinterpret_cast<PVOID*>(&info),
+ new_info, NULL)) {
+ delete new_info;
+ }
+ }
+ return info;
+}
+
+OSInfo::OSInfo()
+ : version_(VERSION_PRE_XP),
+ architecture_(OTHER_ARCHITECTURE),
+ wow64_status_(GetWOW64StatusForProcess(GetCurrentProcess())) {
+ OSVERSIONINFOEXW version_info = {sizeof version_info};
+ // Applications not manifested for Windows 8.1 or Windows 10 will return the
+ // Windows 8 OS version value (6.2). Once an application is manifested for a
+ // given operating system version, GetVersionEx() will always return the
+ // version that the application is manifested for in future releases.
+ // https://docs.microsoft.com/en-us/windows/desktop/SysInfo/targeting-your-application-at-windows-8-1
+ // https://www.codeproject.com/Articles/678606/Part-Overcoming-Windows-s-deprecation-of-GetVe
+#pragma warning(push)
+#pragma warning(disable : 4996)
+ ::GetVersionExW(reinterpret_cast<OSVERSIONINFOW*>(&version_info));
+#pragma warning(pop)
+ version_number_.major = version_info.dwMajorVersion;
+ version_number_.minor = version_info.dwMinorVersion;
+ version_number_.build = version_info.dwBuildNumber;
+ version_number_.patch = GetUBR();
+ version_ = MajorMinorBuildToVersion(
+ version_number_.major, version_number_.minor, version_number_.build);
+ service_pack_.major = version_info.wServicePackMajor;
+ service_pack_.minor = version_info.wServicePackMinor;
+ service_pack_str_ = rtc::ToUtf8(version_info.szCSDVersion);
+
+ SYSTEM_INFO system_info = {};
+ ::GetNativeSystemInfo(&system_info);
+ switch (system_info.wProcessorArchitecture) {
+ case PROCESSOR_ARCHITECTURE_INTEL:
+ architecture_ = X86_ARCHITECTURE;
+ break;
+ case PROCESSOR_ARCHITECTURE_AMD64:
+ architecture_ = X64_ARCHITECTURE;
+ break;
+ case PROCESSOR_ARCHITECTURE_IA64:
+ architecture_ = IA64_ARCHITECTURE;
+ break;
+ }
+ processors_ = system_info.dwNumberOfProcessors;
+ allocation_granularity_ = system_info.dwAllocationGranularity;
+
+#if !defined(WINUWP)
+ GetProductInfoPtr get_product_info;
+ DWORD os_type;
+
+ if (version_info.dwMajorVersion == 6 || version_info.dwMajorVersion == 10) {
+ // Only present on Vista+.
+ get_product_info = reinterpret_cast<GetProductInfoPtr>(::GetProcAddress(
+ ::GetModuleHandleW(L"kernel32.dll"), "GetProductInfo"));
+
+ get_product_info(version_info.dwMajorVersion, version_info.dwMinorVersion,
+ 0, 0, &os_type);
+ switch (os_type) {
+ case PRODUCT_CLUSTER_SERVER:
+ case PRODUCT_DATACENTER_SERVER:
+ case PRODUCT_DATACENTER_SERVER_CORE:
+ case PRODUCT_ENTERPRISE_SERVER:
+ case PRODUCT_ENTERPRISE_SERVER_CORE:
+ case PRODUCT_ENTERPRISE_SERVER_IA64:
+ case PRODUCT_SMALLBUSINESS_SERVER:
+ case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
+ case PRODUCT_STANDARD_SERVER:
+ case PRODUCT_STANDARD_SERVER_CORE:
+ case PRODUCT_WEB_SERVER:
+ version_type_ = SUITE_SERVER;
+ break;
+ case PRODUCT_PROFESSIONAL:
+ case PRODUCT_ULTIMATE:
+ version_type_ = SUITE_PROFESSIONAL;
+ break;
+ case PRODUCT_ENTERPRISE:
+ case PRODUCT_ENTERPRISE_E:
+ case PRODUCT_ENTERPRISE_EVALUATION:
+ case PRODUCT_ENTERPRISE_N:
+ case PRODUCT_ENTERPRISE_N_EVALUATION:
+ case PRODUCT_ENTERPRISE_S:
+ case PRODUCT_ENTERPRISE_S_EVALUATION:
+ case PRODUCT_ENTERPRISE_S_N:
+ case PRODUCT_ENTERPRISE_S_N_EVALUATION:
+ case PRODUCT_BUSINESS:
+ case PRODUCT_BUSINESS_N:
+ version_type_ = SUITE_ENTERPRISE;
+ break;
+ case PRODUCT_EDUCATION:
+ case PRODUCT_EDUCATION_N:
+ version_type_ = SUITE_EDUCATION;
+ break;
+ case PRODUCT_HOME_BASIC:
+ case PRODUCT_HOME_PREMIUM:
+ case PRODUCT_STARTER:
+ default:
+ version_type_ = SUITE_HOME;
+ break;
+ }
+ } else if (version_info.dwMajorVersion == 5 &&
+ version_info.dwMinorVersion == 2) {
+ if (version_info.wProductType == VER_NT_WORKSTATION &&
+ system_info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) {
+ version_type_ = SUITE_PROFESSIONAL;
+ } else if (version_info.wSuiteMask & VER_SUITE_WH_SERVER) {
+ version_type_ = SUITE_HOME;
+ } else {
+ version_type_ = SUITE_SERVER;
+ }
+ } else if (version_info.dwMajorVersion == 5 &&
+ version_info.dwMinorVersion == 1) {
+ if (version_info.wSuiteMask & VER_SUITE_PERSONAL)
+ version_type_ = SUITE_HOME;
+ else
+ version_type_ = SUITE_PROFESSIONAL;
+ } else {
+ // Windows is pre XP so we don't care but pick a safe default.
+ version_type_ = SUITE_HOME;
+ }
+#else
+ // WinUWP sandboxed store apps do not have a mechanism to determine
+ // product suite thus the most restricted suite is chosen.
+ version_type_ = SUITE_HOME;
+#endif // !defined(WINUWP)
+}
+
+OSInfo::~OSInfo() {}
+
+std::string OSInfo::processor_model_name() {
+#if defined(WINUWP)
+ // WinUWP sandboxed store apps do not have the ability to
+ // probe the name of the current processor.
+ return "Unknown Processor (UWP)";
+#else
+ if (processor_model_name_.empty()) {
+ const wchar_t kProcessorNameString[] =
+ L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0";
+ RegKey key(HKEY_LOCAL_MACHINE, kProcessorNameString, KEY_READ);
+ std::wstring value;
+ key.ReadValue(L"ProcessorNameString", &value);
+ processor_model_name_ = rtc::ToUtf8(value);
+ }
+ return processor_model_name_;
+#endif // defined(WINUWP)
+}
+
+// static
+OSInfo::WOW64Status OSInfo::GetWOW64StatusForProcess(HANDLE process_handle) {
+ BOOL is_wow64;
+#if defined(WINUWP)
+ if (!IsWow64Process(process_handle, &is_wow64))
+ return WOW64_UNKNOWN;
+#else
+ typedef BOOL(WINAPI * IsWow64ProcessFunc)(HANDLE, PBOOL);
+ IsWow64ProcessFunc is_wow64_process = reinterpret_cast<IsWow64ProcessFunc>(
+ GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "IsWow64Process"));
+ if (!is_wow64_process)
+ return WOW64_DISABLED;
+ if (!(*is_wow64_process)(process_handle, &is_wow64))
+ return WOW64_UNKNOWN;
+#endif // defined(WINUWP)
+ return is_wow64 ? WOW64_ENABLED : WOW64_DISABLED;
+}
+
+Version GetVersion() {
+ return OSInfo::GetInstance()->version();
+}
+
+} // namespace rtc_win
+} // namespace rtc
diff --git a/third_party/libwebrtc/rtc_base/win/windows_version.h b/third_party/libwebrtc/rtc_base/win/windows_version.h
new file mode 100644
index 0000000000..8542626afb
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win/windows_version.h
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef RTC_BASE_WIN_WINDOWS_VERSION_H_
+#define RTC_BASE_WIN_WINDOWS_VERSION_H_
+
+#include <stddef.h>
+
+#include <string>
+
+typedef void* HANDLE;
+
+namespace rtc {
+namespace rtc_win {
+
+// The running version of Windows. This is declared outside OSInfo for
+// syntactic sugar reasons; see the declaration of GetVersion() below.
+// NOTE: Keep these in order so callers can do things like
+// "if (rtc_win::GetVersion() >= rtc_win::VERSION_VISTA) ...".
+//
+// This enum is used in metrics histograms, so they shouldn't be reordered or
+// removed. New values can be added before VERSION_WIN_LAST.
+enum Version {
+ VERSION_PRE_XP = 0, // Not supported.
+ VERSION_XP = 1,
+ VERSION_SERVER_2003 = 2, // Also includes XP Pro x64 and Server 2003 R2.
+ VERSION_VISTA = 3, // Also includes Windows Server 2008.
+ VERSION_WIN7 = 4, // Also includes Windows Server 2008 R2.
+ VERSION_WIN8 = 5, // Also includes Windows Server 2012.
+ VERSION_WIN8_1 = 6, // Also includes Windows Server 2012 R2.
+ VERSION_WIN10 = 7, // Threshold 1: Version 1507, Build 10240.
+ VERSION_WIN10_TH2 = 8, // Threshold 2: Version 1511, Build 10586.
+ VERSION_WIN10_RS1 = 9, // Redstone 1: Version 1607, Build 14393.
+ VERSION_WIN10_RS2 = 10, // Redstone 2: Version 1703, Build 15063.
+ VERSION_WIN10_RS3 = 11, // Redstone 3: Version 1709, Build 16299.
+ VERSION_WIN10_RS4 = 12, // Redstone 4: Version 1803, Build 17134.
+ VERSION_WIN10_RS5 = 13, // Redstone 5: Version 1809, Build 17763.
+ VERSION_WIN10_19H1 = 14, // 19H1: Version 1903, Build 18362.
+ VERSION_WIN10_19H2 = 15, // 19H2: Version 1909, Build 18363.
+ VERSION_WIN10_20H1 = 16, // 20H1: Version 2004, Build 19041.
+ VERSION_WIN10_20H2 = 17, // 20H2: Build 19042.
+ VERSION_WIN10_21H1 = 18, // 21H1: Build 19043.
+ VERSION_WIN10_21H2 = 19, // 21H2: Build 19044.
+ VERSION_SERVER_2022 = 20, // Server 2022: Build 20348.
+ VERSION_WIN11 = 21, // Windows 11: Build 22000.
+ VERSION_WIN_LAST, // Indicates error condition.
+};
+
+// A rough bucketing of the available types of versions of Windows. This is used
+// to distinguish enterprise enabled versions from home versions and potentially
+// server versions. Keep these values in the same order, since they are used as
+// is for metrics histogram ids.
+enum VersionType {
+ SUITE_HOME = 0,
+ SUITE_PROFESSIONAL,
+ SUITE_SERVER,
+ SUITE_ENTERPRISE,
+ SUITE_EDUCATION,
+ SUITE_LAST,
+};
+
+// A singleton that can be used to query various pieces of information about the
+// OS and process state. Note that this doesn't use the base Singleton class, so
+// it can be used without an AtExitManager.
+class OSInfo {
+ public:
+ struct VersionNumber {
+ int major;
+ int minor;
+ int build;
+ int patch;
+ };
+
+ struct ServicePack {
+ int major;
+ int minor;
+ };
+
+ // The processor architecture this copy of Windows natively uses. For
+ // example, given an x64-capable processor, we have three possibilities:
+ // 32-bit Chrome running on 32-bit Windows: X86_ARCHITECTURE
+ // 32-bit Chrome running on 64-bit Windows via WOW64: X64_ARCHITECTURE
+ // 64-bit Chrome running on 64-bit Windows: X64_ARCHITECTURE
+ enum WindowsArchitecture {
+ X86_ARCHITECTURE,
+ X64_ARCHITECTURE,
+ IA64_ARCHITECTURE,
+ OTHER_ARCHITECTURE,
+ };
+
+ // Whether a process is running under WOW64 (the wrapper that allows 32-bit
+ // processes to run on 64-bit versions of Windows). This will return
+ // WOW64_DISABLED for both "32-bit Chrome on 32-bit Windows" and "64-bit
+ // Chrome on 64-bit Windows". WOW64_UNKNOWN means "an error occurred", e.g.
+ // the process does not have sufficient access rights to determine this.
+ enum WOW64Status {
+ WOW64_DISABLED,
+ WOW64_ENABLED,
+ WOW64_UNKNOWN,
+ };
+
+ OSInfo(const OSInfo&) = delete;
+ OSInfo& operator=(const OSInfo&) = delete;
+
+ static OSInfo* GetInstance();
+
+ Version version() const { return version_; }
+ VersionNumber version_number() const { return version_number_; }
+ VersionType version_type() const { return version_type_; }
+ ServicePack service_pack() const { return service_pack_; }
+ std::string service_pack_str() const { return service_pack_str_; }
+ WindowsArchitecture architecture() const { return architecture_; }
+ int processors() const { return processors_; }
+ size_t allocation_granularity() const { return allocation_granularity_; }
+ WOW64Status wow64_status() const { return wow64_status_; }
+ std::string processor_model_name();
+
+ // Like wow64_status(), but for the supplied handle instead of the current
+ // process. This doesn't touch member state, so you can bypass the singleton.
+ static WOW64Status GetWOW64StatusForProcess(HANDLE process_handle);
+
+ private:
+ OSInfo();
+ ~OSInfo();
+
+ Version version_;
+ VersionNumber version_number_;
+ VersionType version_type_;
+ ServicePack service_pack_;
+
+ // A string, such as "Service Pack 3", that indicates the latest Service Pack
+ // installed on the system. If no Service Pack has been installed, the string
+ // is empty.
+ std::string service_pack_str_;
+ WindowsArchitecture architecture_;
+ int processors_;
+ size_t allocation_granularity_;
+ WOW64Status wow64_status_;
+ std::string processor_model_name_;
+};
+
+// Because this is by far the most commonly-requested value from the above
+// singleton, we add a global-scope accessor here as syntactic sugar.
+Version GetVersion();
+
+} // namespace rtc_win
+} // namespace rtc
+
+#endif // RTC_BASE_WIN_WINDOWS_VERSION_H_
diff --git a/third_party/libwebrtc/rtc_base/win/windows_version_gn/moz.build b/third_party/libwebrtc/rtc_base/win/windows_version_gn/moz.build
new file mode 100644
index 0000000000..88dc67ea48
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win/windows_version_gn/moz.build
@@ -0,0 +1,84 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+ ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ###
+ ### DO NOT edit it by hand. ###
+
+COMPILE_FLAGS["OS_INCLUDES"] = []
+AllowCompilerWarnings()
+
+DEFINES["ABSL_ALLOCATOR_NOTHROW"] = "1"
+DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True
+DEFINES["NOMINMAX"] = True
+DEFINES["NTDDI_VERSION"] = "0x0A000000"
+DEFINES["PSAPI_VERSION"] = "2"
+DEFINES["RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY"] = True
+DEFINES["RTC_ENABLE_VP9"] = True
+DEFINES["UNICODE"] = True
+DEFINES["USE_AURA"] = "1"
+DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0"
+DEFINES["WEBRTC_LIBRARY_IMPL"] = True
+DEFINES["WEBRTC_MOZILLA_BUILD"] = True
+DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0"
+DEFINES["WEBRTC_STRICT_FIELD_TRIALS"] = "0"
+DEFINES["WEBRTC_WIN"] = True
+DEFINES["WIN32"] = True
+DEFINES["WIN32_LEAN_AND_MEAN"] = True
+DEFINES["WINAPI_FAMILY"] = "WINAPI_FAMILY_DESKTOP_APP"
+DEFINES["WINVER"] = "0x0A00"
+DEFINES["_ATL_NO_OPENGL"] = True
+DEFINES["_CRT_RAND_S"] = True
+DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True
+DEFINES["_ENABLE_EXTENDED_ALIGNED_STORAGE"] = True
+DEFINES["_HAS_EXCEPTIONS"] = "0"
+DEFINES["_HAS_NODISCARD"] = True
+DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True
+DEFINES["_SECURE_ATL"] = True
+DEFINES["_UNICODE"] = True
+DEFINES["_WIN32_WINNT"] = "0x0A00"
+DEFINES["_WINDOWS"] = True
+DEFINES["__STD_C"] = True
+
+FINAL_LIBRARY = "webrtc"
+
+
+LOCAL_INCLUDES += [
+ "!/ipc/ipdl/_ipdlheaders",
+ "!/third_party/libwebrtc/gen",
+ "/ipc/chromium/src",
+ "/third_party/libwebrtc/",
+ "/third_party/libwebrtc/third_party/abseil-cpp/",
+ "/tools/profiler/public"
+]
+
+UNIFIED_SOURCES += [
+ "/third_party/libwebrtc/rtc_base/win/windows_version.cc"
+]
+
+if not CONFIG["MOZ_DEBUG"]:
+
+ DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0"
+ DEFINES["NDEBUG"] = True
+ DEFINES["NVALGRIND"] = True
+
+if CONFIG["MOZ_DEBUG"] == "1":
+
+ DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1"
+ DEFINES["_HAS_ITERATOR_DEBUGGING"] = "0"
+
+if CONFIG["CPU_ARCH"] == "aarch64":
+
+ DEFINES["WEBRTC_ARCH_ARM64"] = True
+ DEFINES["WEBRTC_HAS_NEON"] = True
+
+if CONFIG["CPU_ARCH"] == "x86":
+
+ DEFINES["WEBRTC_ENABLE_AVX2"] = True
+
+if CONFIG["CPU_ARCH"] == "x86_64":
+
+ DEFINES["WEBRTC_ENABLE_AVX2"] = True
+
+Library("windows_version_gn")
diff --git a/third_party/libwebrtc/rtc_base/win/windows_version_unittest.cc b/third_party/libwebrtc/rtc_base/win/windows_version_unittest.cc
new file mode 100644
index 0000000000..e1cd920157
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win/windows_version_unittest.cc
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "rtc_base/win/windows_version.h"
+
+#include "rtc_base/gunit.h"
+#include "rtc_base/logging.h"
+
+namespace rtc {
+namespace rtc_win {
+namespace {
+
+void MethodSupportedOnWin10AndLater() {
+ RTC_DLOG(LS_INFO) << "MethodSupportedOnWin10AndLater";
+}
+
+void MethodNotSupportedOnWin10AndLater() {
+ RTC_DLOG(LS_INFO) << "MethodNotSupportedOnWin10AndLater";
+}
+
+// Use global GetVersion() and use it in a way a user would typically use it
+// when checking for support of a certain API:
+// "if (rtc_win::GetVersion() < VERSION_WIN10) ...".
+TEST(WindowsVersion, GetVersionGlobalScopeAccessor) {
+ if (GetVersion() < VERSION_WIN10) {
+ MethodNotSupportedOnWin10AndLater();
+ } else {
+ MethodSupportedOnWin10AndLater();
+ }
+}
+
+TEST(WindowsVersion, ProcessorModelName) {
+ std::string name = OSInfo::GetInstance()->processor_model_name();
+ EXPECT_FALSE(name.empty());
+ RTC_DLOG(LS_INFO) << "processor_model_name: " << name;
+}
+
+} // namespace
+} // namespace rtc_win
+} // namespace rtc
diff --git a/third_party/libwebrtc/rtc_base/win32.cc b/third_party/libwebrtc/rtc_base/win32.cc
new file mode 100644
index 0000000000..b44e513026
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win32.cc
@@ -0,0 +1,314 @@
+/*
+ * Copyright 2004 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "rtc_base/win32.h"
+
+#include <winsock2.h>
+#include <ws2tcpip.h>
+
+#include <algorithm>
+
+#include "rtc_base/arraysize.h"
+#include "rtc_base/byte_order.h"
+#include "rtc_base/checks.h"
+#include "rtc_base/logging.h"
+#include "rtc_base/string_utils.h"
+
+namespace rtc {
+
+// Helper function declarations for inet_ntop/inet_pton.
+static const char* inet_ntop_v4(const void* src, char* dst, socklen_t size);
+static const char* inet_ntop_v6(const void* src, char* dst, socklen_t size);
+static int inet_pton_v4(const char* src, void* dst);
+static int inet_pton_v6(const char* src, void* dst);
+
+// Implementation of inet_ntop (create a printable representation of an
+// ip address). XP doesn't have its own inet_ntop, and
+// WSAAddressToString requires both IPv6 to be installed and for Winsock
+// to be initialized.
+const char* win32_inet_ntop(int af,
+ const void* src,
+ char* dst,
+ socklen_t size) {
+ if (!src || !dst) {
+ return nullptr;
+ }
+ switch (af) {
+ case AF_INET: {
+ return inet_ntop_v4(src, dst, size);
+ }
+ case AF_INET6: {
+ return inet_ntop_v6(src, dst, size);
+ }
+ }
+ return nullptr;
+}
+
+// As above, but for inet_pton. Implements inet_pton for v4 and v6.
+// Note that our inet_ntop will output normal 'dotted' v4 addresses only.
+int win32_inet_pton(int af, const char* src, void* dst) {
+ if (!src || !dst) {
+ return 0;
+ }
+ if (af == AF_INET) {
+ return inet_pton_v4(src, dst);
+ } else if (af == AF_INET6) {
+ return inet_pton_v6(src, dst);
+ }
+ return -1;
+}
+
+// Helper function for inet_ntop for IPv4 addresses.
+// Outputs "dotted-quad" decimal notation.
+const char* inet_ntop_v4(const void* src, char* dst, socklen_t size) {
+ if (size < INET_ADDRSTRLEN) {
+ return nullptr;
+ }
+ const struct in_addr* as_in_addr =
+ reinterpret_cast<const struct in_addr*>(src);
+ snprintf(dst, size, "%d.%d.%d.%d", as_in_addr->S_un.S_un_b.s_b1,
+ as_in_addr->S_un.S_un_b.s_b2, as_in_addr->S_un.S_un_b.s_b3,
+ as_in_addr->S_un.S_un_b.s_b4);
+ return dst;
+}
+
+// Helper function for inet_ntop for IPv6 addresses.
+const char* inet_ntop_v6(const void* src, char* dst, socklen_t size) {
+ if (size < INET6_ADDRSTRLEN) {
+ return nullptr;
+ }
+ const uint16_t* as_shorts = reinterpret_cast<const uint16_t*>(src);
+ int runpos[8];
+ int current = 1;
+ int max = 0;
+ int maxpos = -1;
+ int run_array_size = arraysize(runpos);
+ // Run over the address marking runs of 0s.
+ for (int i = 0; i < run_array_size; ++i) {
+ if (as_shorts[i] == 0) {
+ runpos[i] = current;
+ if (current > max) {
+ maxpos = i;
+ max = current;
+ }
+ ++current;
+ } else {
+ runpos[i] = -1;
+ current = 1;
+ }
+ }
+
+ if (max > 0) {
+ int tmpmax = maxpos;
+ // Run back through, setting -1 for all but the longest run.
+ for (int i = run_array_size - 1; i >= 0; i--) {
+ if (i > tmpmax) {
+ runpos[i] = -1;
+ } else if (runpos[i] == -1) {
+ // We're less than maxpos, we hit a -1, so the 'good' run is done.
+ // Setting tmpmax -1 means all remaining positions get set to -1.
+ tmpmax = -1;
+ }
+ }
+ }
+
+ char* cursor = dst;
+ // Print IPv4 compatible and IPv4 mapped addresses using the IPv4 helper.
+ // These addresses have an initial run of either eight zero-bytes followed
+ // by 0xFFFF, or an initial run of ten zero-bytes.
+ if (runpos[0] == 1 &&
+ (maxpos == 5 || (maxpos == 4 && as_shorts[5] == 0xFFFF))) {
+ *cursor++ = ':';
+ *cursor++ = ':';
+ if (maxpos == 4) {
+ cursor += snprintf(cursor, INET6_ADDRSTRLEN - 2, "ffff:");
+ }
+ const struct in_addr* as_v4 =
+ reinterpret_cast<const struct in_addr*>(&(as_shorts[6]));
+ inet_ntop_v4(as_v4, cursor,
+ static_cast<socklen_t>(INET6_ADDRSTRLEN - (cursor - dst)));
+ } else {
+ for (int i = 0; i < run_array_size; ++i) {
+ if (runpos[i] == -1) {
+ cursor += snprintf(cursor, INET6_ADDRSTRLEN - (cursor - dst), "%x",
+ NetworkToHost16(as_shorts[i]));
+ if (i != 7 && runpos[i + 1] != 1) {
+ *cursor++ = ':';
+ }
+ } else if (runpos[i] == 1) {
+ // Entered the run; print the colons and skip the run.
+ *cursor++ = ':';
+ *cursor++ = ':';
+ i += (max - 1);
+ }
+ }
+ }
+ return dst;
+}
+
+// Helper function for inet_pton for IPv4 addresses.
+// `src` points to a character string containing an IPv4 network address in
+// dotted-decimal format, "ddd.ddd.ddd.ddd", where ddd is a decimal number
+// of up to three digits in the range 0 to 255.
+// The address is converted and copied to dst,
+// which must be sizeof(struct in_addr) (4) bytes (32 bits) long.
+int inet_pton_v4(const char* src, void* dst) {
+ const int kIpv4AddressSize = 4;
+ int found = 0;
+ const char* src_pos = src;
+ unsigned char result[kIpv4AddressSize] = {0};
+
+ while (*src_pos != '\0') {
+ // strtol won't treat whitespace characters in the begining as an error,
+ // so check to ensure this is started with digit before passing to strtol.
+ if (!isdigit(*src_pos)) {
+ return 0;
+ }
+ char* end_pos;
+ long value = strtol(src_pos, &end_pos, 10);
+ if (value < 0 || value > 255 || src_pos == end_pos) {
+ return 0;
+ }
+ ++found;
+ if (found > kIpv4AddressSize) {
+ return 0;
+ }
+ result[found - 1] = static_cast<unsigned char>(value);
+ src_pos = end_pos;
+ if (*src_pos == '.') {
+ // There's more.
+ ++src_pos;
+ } else if (*src_pos != '\0') {
+ // If it's neither '.' nor '\0' then return fail.
+ return 0;
+ }
+ }
+ if (found != kIpv4AddressSize) {
+ return 0;
+ }
+ memcpy(dst, result, sizeof(result));
+ return 1;
+}
+
+// Helper function for inet_pton for IPv6 addresses.
+int inet_pton_v6(const char* src, void* dst) {
+ // sscanf will pick any other invalid chars up, but it parses 0xnnnn as hex.
+ // Check for literal x in the input string.
+ const char* readcursor = src;
+ char c = *readcursor++;
+ while (c) {
+ if (c == 'x') {
+ return 0;
+ }
+ c = *readcursor++;
+ }
+ readcursor = src;
+
+ struct in6_addr an_addr;
+ memset(&an_addr, 0, sizeof(an_addr));
+
+ uint16_t* addr_cursor = reinterpret_cast<uint16_t*>(&an_addr.s6_addr[0]);
+ uint16_t* addr_end = reinterpret_cast<uint16_t*>(&an_addr.s6_addr[16]);
+ bool seencompressed = false;
+
+ // Addresses that start with "::" (i.e., a run of initial zeros) or
+ // "::ffff:" can potentially be IPv4 mapped or compatibility addresses.
+ // These have dotted-style IPv4 addresses on the end (e.g. "::192.168.7.1").
+ if (*readcursor == ':' && *(readcursor + 1) == ':' &&
+ *(readcursor + 2) != 0) {
+ // Check for periods, which we'll take as a sign of v4 addresses.
+ const char* addrstart = readcursor + 2;
+ if (strchr(addrstart, '.')) {
+ const char* colon = strchr(addrstart, ':');
+ if (colon) {
+ uint16_t a_short;
+ int bytesread = 0;
+ if (sscanf(addrstart, "%hx%n", &a_short, &bytesread) != 1 ||
+ a_short != 0xFFFF || bytesread != 4) {
+ // Colons + periods means has to be ::ffff:a.b.c.d. But it wasn't.
+ return 0;
+ } else {
+ an_addr.s6_addr[10] = 0xFF;
+ an_addr.s6_addr[11] = 0xFF;
+ addrstart = colon + 1;
+ }
+ }
+ struct in_addr v4;
+ if (inet_pton_v4(addrstart, &v4.s_addr)) {
+ memcpy(&an_addr.s6_addr[12], &v4, sizeof(v4));
+ memcpy(dst, &an_addr, sizeof(an_addr));
+ return 1;
+ } else {
+ // Invalid v4 address.
+ return 0;
+ }
+ }
+ }
+
+ // For addresses without a trailing IPv4 component ('normal' IPv6 addresses).
+ while (*readcursor != 0 && addr_cursor < addr_end) {
+ if (*readcursor == ':') {
+ if (*(readcursor + 1) == ':') {
+ if (seencompressed) {
+ // Can only have one compressed run of zeroes ("::") per address.
+ return 0;
+ }
+ // Hit a compressed run. Count colons to figure out how much of the
+ // address is skipped.
+ readcursor += 2;
+ const char* coloncounter = readcursor;
+ int coloncount = 0;
+ if (*coloncounter == 0) {
+ // Special case - trailing ::.
+ addr_cursor = addr_end;
+ } else {
+ while (*coloncounter) {
+ if (*coloncounter == ':') {
+ ++coloncount;
+ }
+ ++coloncounter;
+ }
+ // (coloncount + 1) is the number of shorts left in the address.
+ // If this number is greater than the number of available shorts, the
+ // address is malformed.
+ if (coloncount + 1 > addr_end - addr_cursor) {
+ return 0;
+ }
+ addr_cursor = addr_end - (coloncount + 1);
+ seencompressed = true;
+ }
+ } else {
+ ++readcursor;
+ }
+ } else {
+ uint16_t word;
+ int bytesread = 0;
+ if (sscanf(readcursor, "%4hx%n", &word, &bytesread) != 1) {
+ return 0;
+ } else {
+ *addr_cursor = HostToNetwork16(word);
+ ++addr_cursor;
+ readcursor += bytesread;
+ if (*readcursor != ':' && *readcursor != '\0') {
+ return 0;
+ }
+ }
+ }
+ }
+
+ if (*readcursor != '\0' || addr_cursor < addr_end) {
+ // Catches addresses too short or too long.
+ return 0;
+ }
+ memcpy(dst, &an_addr, sizeof(an_addr));
+ return 1;
+}
+
+} // namespace rtc
diff --git a/third_party/libwebrtc/rtc_base/win32.h b/third_party/libwebrtc/rtc_base/win32.h
new file mode 100644
index 0000000000..6e8d2873aa
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win32.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2004 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef RTC_BASE_WIN32_H_
+#define RTC_BASE_WIN32_H_
+
+#ifndef WEBRTC_WIN
+#error "Only #include this header in Windows builds"
+#endif
+
+// Make sure we don't get min/max macros
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
+
+#include <winsock2.h>
+
+// Must be after winsock2.h.
+#include <windows.h>
+
+typedef int socklen_t;
+
+#ifndef SECURITY_MANDATORY_LABEL_AUTHORITY
+// Add defines that we use if we are compiling against older sdks
+#define SECURITY_MANDATORY_MEDIUM_RID (0x00002000L)
+#define TokenIntegrityLevel static_cast<TOKEN_INFORMATION_CLASS>(0x19)
+typedef struct _TOKEN_MANDATORY_LABEL {
+ SID_AND_ATTRIBUTES Label;
+} TOKEN_MANDATORY_LABEL, *PTOKEN_MANDATORY_LABEL;
+#endif // SECURITY_MANDATORY_LABEL_AUTHORITY
+
+#undef SetPort
+
+namespace rtc {
+
+const char* win32_inet_ntop(int af, const void* src, char* dst, socklen_t size);
+int win32_inet_pton(int af, const char* src, void* dst);
+
+} // namespace rtc
+
+#endif // RTC_BASE_WIN32_H_
diff --git a/third_party/libwebrtc/rtc_base/win32_gn/moz.build b/third_party/libwebrtc/rtc_base/win32_gn/moz.build
new file mode 100644
index 0000000000..656bd4014b
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win32_gn/moz.build
@@ -0,0 +1,93 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+ ### This moz.build was AUTOMATICALLY GENERATED from a GN config, ###
+ ### DO NOT edit it by hand. ###
+
+COMPILE_FLAGS["OS_INCLUDES"] = []
+AllowCompilerWarnings()
+
+DEFINES["ABSL_ALLOCATOR_NOTHROW"] = "1"
+DEFINES["CERT_CHAIN_PARA_HAS_EXTRA_FIELDS"] = True
+DEFINES["NOMINMAX"] = True
+DEFINES["NTDDI_VERSION"] = "0x0A000000"
+DEFINES["PSAPI_VERSION"] = "2"
+DEFINES["RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY"] = True
+DEFINES["RTC_ENABLE_VP9"] = True
+DEFINES["UNICODE"] = True
+DEFINES["USE_AURA"] = "1"
+DEFINES["WEBRTC_ENABLE_PROTOBUF"] = "0"
+DEFINES["WEBRTC_LIBRARY_IMPL"] = True
+DEFINES["WEBRTC_MOZILLA_BUILD"] = True
+DEFINES["WEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS"] = "0"
+DEFINES["WEBRTC_STRICT_FIELD_TRIALS"] = "0"
+DEFINES["WEBRTC_WIN"] = True
+DEFINES["WIN32"] = True
+DEFINES["WIN32_LEAN_AND_MEAN"] = True
+DEFINES["WINAPI_FAMILY"] = "WINAPI_FAMILY_DESKTOP_APP"
+DEFINES["WINVER"] = "0x0A00"
+DEFINES["_ATL_NO_OPENGL"] = True
+DEFINES["_CRT_NONSTDC_NO_DEPRECATE"] = True
+DEFINES["_CRT_RAND_S"] = True
+DEFINES["_CRT_SECURE_NO_DEPRECATE"] = True
+DEFINES["_ENABLE_EXTENDED_ALIGNED_STORAGE"] = True
+DEFINES["_HAS_EXCEPTIONS"] = "0"
+DEFINES["_HAS_NODISCARD"] = True
+DEFINES["_SCL_SECURE_NO_DEPRECATE"] = True
+DEFINES["_SECURE_ATL"] = True
+DEFINES["_UNICODE"] = True
+DEFINES["_WIN32_WINNT"] = "0x0A00"
+DEFINES["_WINDOWS"] = True
+DEFINES["__STD_C"] = True
+
+FINAL_LIBRARY = "webrtc"
+
+
+LOCAL_INCLUDES += [
+ "!/ipc/ipdl/_ipdlheaders",
+ "!/third_party/libwebrtc/gen",
+ "/ipc/chromium/src",
+ "/third_party/libwebrtc/",
+ "/third_party/libwebrtc/third_party/abseil-cpp/",
+ "/tools/profiler/public"
+]
+
+OS_LIBS += [
+ "crypt32",
+ "iphlpapi",
+ "secur32",
+ "winmm"
+]
+
+UNIFIED_SOURCES += [
+ "/third_party/libwebrtc/rtc_base/win32.cc",
+ "/third_party/libwebrtc/rtc_base/win32_window.cc"
+]
+
+if not CONFIG["MOZ_DEBUG"]:
+
+ DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "0"
+ DEFINES["NDEBUG"] = True
+ DEFINES["NVALGRIND"] = True
+
+if CONFIG["MOZ_DEBUG"] == "1":
+
+ DEFINES["DYNAMIC_ANNOTATIONS_ENABLED"] = "1"
+ DEFINES["_HAS_ITERATOR_DEBUGGING"] = "0"
+
+if CONFIG["CPU_ARCH"] == "aarch64":
+
+ DEFINES["WEBRTC_ARCH_ARM64"] = True
+ DEFINES["WEBRTC_HAS_NEON"] = True
+
+if CONFIG["CPU_ARCH"] == "x86":
+
+ DEFINES["WEBRTC_ENABLE_AVX2"] = True
+
+if CONFIG["CPU_ARCH"] == "x86_64":
+
+ DEFINES["WEBRTC_ENABLE_AVX2"] = True
+
+Library("win32_gn")
diff --git a/third_party/libwebrtc/rtc_base/win32_socket_init.h b/third_party/libwebrtc/rtc_base/win32_socket_init.h
new file mode 100644
index 0000000000..4a90e142b6
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win32_socket_init.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2009 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef RTC_BASE_WIN32_SOCKET_INIT_H_
+#define RTC_BASE_WIN32_SOCKET_INIT_H_
+
+#ifndef WEBRTC_WIN
+#error "Only #include this header in Windows builds"
+#endif
+
+#include "rtc_base/win32.h"
+
+namespace rtc {
+
+class WinsockInitializer {
+ public:
+ WinsockInitializer() {
+ WSADATA wsaData;
+ WORD wVersionRequested = MAKEWORD(1, 0);
+ err_ = WSAStartup(wVersionRequested, &wsaData);
+ }
+ ~WinsockInitializer() {
+ if (!err_)
+ WSACleanup();
+ }
+ int error() { return err_; }
+
+ private:
+ int err_;
+};
+
+} // namespace rtc
+
+#endif // RTC_BASE_WIN32_SOCKET_INIT_H_
diff --git a/third_party/libwebrtc/rtc_base/win32_unittest.cc b/third_party/libwebrtc/rtc_base/win32_unittest.cc
new file mode 100644
index 0000000000..b2955e500a
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win32_unittest.cc
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2010 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "rtc_base/win32.h"
+
+#include <string>
+
+#include "rtc_base/gunit.h"
+#include "rtc_base/net_helpers.h"
+
+#if !defined(WEBRTC_WIN)
+#error Only for Windows
+#endif
+
+namespace rtc {
+
+class Win32Test : public ::testing::Test {
+ public:
+ Win32Test() {}
+};
+
+TEST_F(Win32Test, IPv6AddressCompression) {
+ IPAddress ipv6;
+
+ // Zero compression should be done on the leftmost 0s when there are
+ // multiple longest series.
+ ASSERT_TRUE(IPFromString("2a00:8a00:a000:1190:0000:0001:000:252", &ipv6));
+ EXPECT_EQ("2a00:8a00:a000:1190::1:0:252", ipv6.ToString());
+
+ // Ensure the zero compression could handle multiple octects.
+ ASSERT_TRUE(IPFromString("0:0:0:0:0:0:0:1", &ipv6));
+ EXPECT_EQ("::1", ipv6.ToString());
+
+ // Make sure multiple 0 octects compressed.
+ ASSERT_TRUE(IPFromString("fe80:0:0:0:2aa:ff:fe9a:4ca2", &ipv6));
+ EXPECT_EQ("fe80::2aa:ff:fe9a:4ca2", ipv6.ToString());
+
+ // Test zero compression at the end of string.
+ ASSERT_TRUE(IPFromString("2a00:8a00:a000:1190:0000:0001:000:00", &ipv6));
+ EXPECT_EQ("2a00:8a00:a000:1190:0:1::", ipv6.ToString());
+
+ // Test zero compression at the beginning of string.
+ ASSERT_TRUE(IPFromString("0:0:000:1190:0000:0001:000:00", &ipv6));
+ EXPECT_EQ("::1190:0:1:0:0", ipv6.ToString());
+
+ // Test zero compression only done once.
+ ASSERT_TRUE(IPFromString("0:1:000:1190:0000:0001:000:01", &ipv6));
+ EXPECT_EQ("::1:0:1190:0:1:0:1", ipv6.ToString());
+
+ // Make sure noncompressable IPv6 is the same.
+ ASSERT_TRUE(IPFromString("1234:5678:abcd:1234:5678:abcd:1234:5678", &ipv6));
+ EXPECT_EQ("1234:5678:abcd:1234:5678:abcd:1234:5678", ipv6.ToString());
+}
+
+// Test that invalid IPv6 addresses are recognized and false is returned.
+TEST_F(Win32Test, InvalidIPv6AddressParsing) {
+ IPAddress ipv6;
+
+ // More than 1 run of "::"s.
+ EXPECT_FALSE(IPFromString("1::2::3", &ipv6));
+
+ // More than 1 run of "::"s in a longer address.
+ // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=7592
+ EXPECT_FALSE(IPFromString("1::2::3::4::5::6::7::8", &ipv6));
+
+ // Three ':'s in a row.
+ EXPECT_FALSE(IPFromString("1:::2", &ipv6));
+
+ // Non-hex character.
+ EXPECT_FALSE(IPFromString("test::1", &ipv6));
+
+ // More than 4 hex digits per group.
+ EXPECT_FALSE(IPFromString("abcde::1", &ipv6));
+
+ // More than 8 groups.
+ EXPECT_FALSE(IPFromString("1:2:3:4:5:6:7:8:9", &ipv6));
+
+ // Less than 8 groups.
+ EXPECT_FALSE(IPFromString("1:2:3:4:5:6:7", &ipv6));
+}
+
+} // namespace rtc
diff --git a/third_party/libwebrtc/rtc_base/win32_window.cc b/third_party/libwebrtc/rtc_base/win32_window.cc
new file mode 100644
index 0000000000..775535a759
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win32_window.cc
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2004 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "rtc_base/win32_window.h"
+
+#include "rtc_base/checks.h"
+#include "rtc_base/logging.h"
+
+namespace rtc {
+
+///////////////////////////////////////////////////////////////////////////////
+// Win32Window
+///////////////////////////////////////////////////////////////////////////////
+
+static const wchar_t kWindowBaseClassName[] = L"RtcWindowBaseClass";
+HINSTANCE Win32Window::instance_ = nullptr;
+ATOM Win32Window::window_class_ = 0;
+
+Win32Window::Win32Window() : wnd_(nullptr) {}
+
+Win32Window::~Win32Window() { RTC_DCHECK(nullptr == wnd_); }
+
+bool Win32Window::Create(HWND parent, const wchar_t* title, DWORD style,
+ DWORD exstyle, int x, int y, int cx, int cy) {
+ if (wnd_) {
+ // Window already exists.
+ return false;
+ }
+
+ if (!window_class_) {
+ if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
+ GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+ reinterpret_cast<LPCWSTR>(&Win32Window::WndProc),
+ &instance_)) {
+ RTC_LOG_GLE(LS_ERROR) << "GetModuleHandleEx failed";
+ return false;
+ }
+
+ // Register or reregister the class as necessary. window_class_ == nullptr
+ // is not an infallible indicator that the class is unregistered.
+ WNDCLASSEXW wcex;
+ memset(&wcex, 0, sizeof(wcex));
+ wcex.cbSize = sizeof(wcex);
+ if (::GetClassInfoExW(instance_, kWindowBaseClassName, &wcex) &&
+ !::UnregisterClassW(kWindowBaseClassName, instance_)) {
+ RTC_LOG_GLE(LS_ERROR) << "UnregisterClass failed.";
+ }
+
+ memset(&wcex, 0, sizeof(wcex));
+ wcex.cbSize = sizeof(wcex);
+ wcex.hInstance = instance_;
+ wcex.lpfnWndProc = &Win32Window::WndProc;
+ wcex.lpszClassName = kWindowBaseClassName;
+ window_class_ = ::RegisterClassExW(&wcex);
+ if (!window_class_) {
+ RTC_LOG_GLE(LS_ERROR) << "RegisterClassEx failed";
+ return false;
+ }
+ }
+ wnd_ = ::CreateWindowExW(exstyle, kWindowBaseClassName, title, style, x, y,
+ cx, cy, parent, nullptr, instance_, this);
+ return (nullptr != wnd_);
+}
+
+void Win32Window::Destroy() {
+ const bool success = ::DestroyWindow(wnd_);
+ RTC_DCHECK(success);
+}
+
+void Win32Window::Shutdown() {
+ if (window_class_) {
+ if (!::UnregisterClass(MAKEINTATOM(window_class_), instance_)) {
+ RTC_LOG_GLE(LS_ERROR) << "UnregisterClass failed.";
+ }
+ window_class_ = 0;
+ }
+}
+
+bool Win32Window::OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam,
+ LRESULT& result) {
+ switch (uMsg) {
+ case WM_CLOSE:
+ if (!OnClose()) {
+ result = 0;
+ return true;
+ }
+ break;
+ }
+ return false;
+}
+
+bool Win32Window::OnClose() { return true; }
+
+void Win32Window::OnNcDestroy() {
+ // Do nothing. }
+}
+
+LRESULT Win32Window::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
+ LPARAM lParam) {
+ Win32Window* that =
+ reinterpret_cast<Win32Window*>(::GetWindowLongPtr(hwnd, GWLP_USERDATA));
+ if (!that && (WM_CREATE == uMsg)) {
+ CREATESTRUCT* cs = reinterpret_cast<CREATESTRUCT*>(lParam);
+ that = static_cast<Win32Window*>(cs->lpCreateParams);
+ that->wnd_ = hwnd;
+ ::SetWindowLongPtr(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(that));
+ }
+ if (that) {
+ LRESULT result;
+ bool handled = that->OnMessage(uMsg, wParam, lParam, result);
+ if (WM_DESTROY == uMsg) {
+ for (HWND child = ::GetWindow(hwnd, GW_CHILD); child;
+ child = ::GetWindow(child, GW_HWNDNEXT)) {
+ RTC_LOG(LS_INFO) << "Child window: " << static_cast<void*>(child);
+ }
+ }
+ if (WM_NCDESTROY == uMsg) {
+ ::SetWindowLongPtr(hwnd, GWLP_USERDATA, NULL);
+ that->wnd_ = nullptr;
+ that->OnNcDestroy();
+ }
+ if (handled) {
+ return result;
+ }
+ }
+ return ::DefWindowProc(hwnd, uMsg, wParam, lParam);
+}
+
+} // namespace rtc
diff --git a/third_party/libwebrtc/rtc_base/win32_window.h b/third_party/libwebrtc/rtc_base/win32_window.h
new file mode 100644
index 0000000000..5256a85d09
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win32_window.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2004 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef RTC_BASE_WIN32_WINDOW_H_
+#define RTC_BASE_WIN32_WINDOW_H_
+
+#if defined(WEBRTC_WIN)
+
+#include "rtc_base/win32.h"
+
+namespace rtc {
+
+///////////////////////////////////////////////////////////////////////////////
+// Win32Window
+///////////////////////////////////////////////////////////////////////////////
+
+class Win32Window {
+ public:
+ Win32Window();
+ virtual ~Win32Window();
+
+ HWND handle() const { return wnd_; }
+
+ bool Create(HWND parent,
+ const wchar_t* title,
+ DWORD style,
+ DWORD exstyle,
+ int x,
+ int y,
+ int cx,
+ int cy);
+ void Destroy();
+
+ // Call this when your DLL unloads.
+ static void Shutdown();
+
+ protected:
+ virtual bool OnMessage(UINT uMsg,
+ WPARAM wParam,
+ LPARAM lParam,
+ LRESULT& result);
+
+ virtual bool OnClose();
+ virtual void OnNcDestroy();
+
+ private:
+ static LRESULT CALLBACK WndProc(HWND hwnd,
+ UINT uMsg,
+ WPARAM wParam,
+ LPARAM lParam);
+
+ HWND wnd_;
+ static HINSTANCE instance_;
+ static ATOM window_class_;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+} // namespace rtc
+
+#endif // WEBRTC_WIN
+
+#endif // RTC_BASE_WIN32_WINDOW_H_
diff --git a/third_party/libwebrtc/rtc_base/win32_window_unittest.cc b/third_party/libwebrtc/rtc_base/win32_window_unittest.cc
new file mode 100644
index 0000000000..665b5c6b9a
--- /dev/null
+++ b/third_party/libwebrtc/rtc_base/win32_window_unittest.cc
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2009 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "rtc_base/win32_window.h"
+
+#include "rtc_base/gunit.h"
+#include "rtc_base/logging.h"
+
+static LRESULT kDummyResult = 0x1234ABCD;
+
+class TestWindow : public rtc::Win32Window {
+ public:
+ TestWindow() : destroyed_(false) { memset(&msg_, 0, sizeof(msg_)); }
+ const MSG& msg() const { return msg_; }
+ bool destroyed() const { return destroyed_; }
+
+ bool OnMessage(UINT uMsg,
+ WPARAM wParam,
+ LPARAM lParam,
+ LRESULT& result) override {
+ msg_.message = uMsg;
+ msg_.wParam = wParam;
+ msg_.lParam = lParam;
+ result = kDummyResult;
+ return true;
+ }
+ void OnNcDestroy() override { destroyed_ = true; }
+
+ private:
+ MSG msg_;
+ bool destroyed_;
+};
+
+TEST(Win32WindowTest, Basics) {
+ TestWindow wnd;
+ EXPECT_TRUE(wnd.handle() == nullptr);
+ EXPECT_FALSE(wnd.destroyed());
+ EXPECT_TRUE(wnd.Create(0, L"Test", 0, 0, 0, 0, 100, 100));
+ EXPECT_TRUE(wnd.handle() != nullptr);
+ EXPECT_EQ(kDummyResult, ::SendMessage(wnd.handle(), WM_USER, 1, 2));
+ EXPECT_EQ(static_cast<UINT>(WM_USER), wnd.msg().message);
+ EXPECT_EQ(1u, wnd.msg().wParam);
+ EXPECT_EQ(2l, wnd.msg().lParam);
+ wnd.Destroy();
+ EXPECT_TRUE(wnd.handle() == nullptr);
+ EXPECT_TRUE(wnd.destroyed());
+}
+
+TEST(Win32WindowTest, MultipleWindows) {
+ TestWindow wnd1, wnd2;
+ EXPECT_TRUE(wnd1.Create(0, L"Test", 0, 0, 0, 0, 100, 100));
+ EXPECT_TRUE(wnd2.Create(0, L"Test", 0, 0, 0, 0, 100, 100));
+ EXPECT_TRUE(wnd1.handle() != nullptr);
+ EXPECT_TRUE(wnd2.handle() != nullptr);
+ wnd1.Destroy();
+ wnd2.Destroy();
+ EXPECT_TRUE(wnd2.handle() == nullptr);
+ EXPECT_TRUE(wnd1.handle() == nullptr);
+}