Skip to content

Commit

Permalink
Backed out changeset 60b8f96f35ec (bug 1645571) for causing bug 1907766.
Browse files Browse the repository at this point in the history
  • Loading branch information
rvandermeulen committed Jul 25, 2024
1 parent 8a8eebc commit 34877aa
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 136 deletions.
51 changes: 0 additions & 51 deletions widget/tests/gtest/TestWinInputPane.cpp

This file was deleted.

1 change: 0 additions & 1 deletion widget/tests/gtest/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ if CONFIG["OS_ARCH"] == "WINNT":
UNIFIED_SOURCES += [
"MockWinWidget.cpp",
"TestWinHeaderOnlyUtils.cpp",
"TestWinInputPane.cpp",
"TestWinMessageLoggingUtils.cpp",
"TestWinWindowOcclusionTracker.cpp",
"TestWinWindowOcclusionTrackerInteractive.cpp",
Expand Down
81 changes: 1 addition & 80 deletions widget/windows/OSKInputPaneManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@
#define NTDDI_VERSION NTDDI_WIN10_RS1

#include "OSKInputPaneManager.h"
#include "mozilla/Maybe.h"
#include "nscore.h"
#include "nsDebug.h"
#include "nsWindowsHelpers.h"

#ifndef __MINGW32__
# include <inputpaneinterop.h>
# include <windows.ui.viewmanagement.h>
# include <wrl.h>

using ABI::Windows::Foundation::ITypedEventHandler;
using namespace ABI::Windows::UI::ViewManagement;
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
Expand All @@ -27,7 +23,7 @@ namespace mozilla {
namespace widget {

#ifndef __MINGW32__
static ComPtr<IInputPane> GetInputPaneInternal(HWND aHwnd) {
static ComPtr<IInputPane2> GetInputPane(HWND aHwnd) {
ComPtr<IInputPaneInterop> inputPaneInterop;
HRESULT hr = RoGetActivationFactory(
HStringReference(RuntimeClass_Windows_UI_ViewManagement_InputPane).Get(),
Expand All @@ -42,44 +38,6 @@ static ComPtr<IInputPane> GetInputPaneInternal(HWND aHwnd) {
return nullptr;
}

return inputPane;
}

static ComPtr<IInputPane2> GetInputPane(HWND aHwnd) {
ComPtr<IInputPane> inputPane = GetInputPaneInternal(aHwnd);
if (!inputPane) {
return nullptr;
}

// Bug 1645571: We need to ensure that we have a SID_InputPaneEventHandler
// window service registered on aHwnd, or explorer.exe will mess with our
// window through twinui!CKeyboardOcclusionMitigation::_MitigateWindow.

Maybe<bool> hasEventHandler =
OSKInputPaneManager::HasInputPaneEventHandlerService(aHwnd);
if (hasEventHandler.isSome() && !hasEventHandler.value()) {
// Run IInputPane::add_Hiding once to register the window service.
EventRegistrationToken token{};
HRESULT registered = inputPane->add_Hiding(
Callback<ITypedEventHandler<InputPane*, InputPaneVisibilityEventArgs*>>(
[](IInputPane* aInputPane, IInputPaneVisibilityEventArgs* aArgs) {
return S_OK;
})
.Get(),
&token);

// Validate our assumption that we now have the window service registered.
hasEventHandler =
OSKInputPaneManager::HasInputPaneEventHandlerService(aHwnd);
if (SUCCEEDED(registered) &&
!(hasEventHandler.isSome() && hasEventHandler.value())) {
// If our assumption is wrong, we undo the operation. This prevents a
// memory leak where we would be adding a new callback every time the
// on-screen keyboard is shown.
inputPane->remove_Hiding(token);
}
}

ComPtr<IInputPane2> inputPane2;
inputPane.As(&inputPane2);
return inputPane2;
Expand Down Expand Up @@ -139,42 +97,5 @@ void OSKInputPaneManager::DismissOnScreenKeyboard(HWND aWnd) {
#endif
}

// static
Maybe<bool> OSKInputPaneManager::HasInputPaneEventHandlerService(HWND aHwnd) {
using CoreIsWindowServiceSupportedFn =
HRESULT(WINAPI*)(HWND aHwnd, LPCGUID aServiceSid);

static auto sCoreIsWindowServiceSupported =
[]() -> CoreIsWindowServiceSupportedFn {
HMODULE twinApiAppCore = LoadLibrarySystem32(L"twinapi.appcore.dll");
if (!twinApiAppCore) {
return nullptr;
}
return reinterpret_cast<CoreIsWindowServiceSupportedFn>(
::GetProcAddress(twinApiAppCore, reinterpret_cast<LPCSTR>(8)));
}();

if (!sCoreIsWindowServiceSupported) {
return Nothing();
}

// {958e2b85-b035-4590-9bc5-ef01779b45dc}
static const GUID sSID_InputPaneEventHandler{
0x958e2b85,
0xb035,
0x4590,
{0x9b, 0xc5, 0xef, 0x1, 0x77, 0x9b, 0x45, 0xdc}};

// Since we are calling a Windows internal function here, the function
// signature is subject to arbitrary changes from Microsoft. This could
// result in wrong results or even crashing. Ensure that if things are so bad
// that we are about to crash, we just return Nothing instead.
MOZ_SEH_TRY {
return Some(SUCCEEDED(
sCoreIsWindowServiceSupported(aHwnd, &sSID_InputPaneEventHandler)));
}
MOZ_SEH_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { return Nothing(); }
}

} // namespace widget
} // namespace mozilla
3 changes: 0 additions & 3 deletions widget/windows/OSKInputPaneManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#ifndef mozilla_widget_OSKInputPaneManager_h
#define mozilla_widget_OSKInputPaneManager_h

#include "mozilla/Maybe.h"

#include <windows.h>

namespace mozilla {
Expand All @@ -18,7 +16,6 @@ class OSKInputPaneManager final {
public:
static void ShowOnScreenKeyboard(HWND aHwnd);
static void DismissOnScreenKeyboard(HWND aHwnd);
static Maybe<bool> HasInputPaneEventHandlerService(HWND aHwnd);
};

} // namespace widget
Expand Down
1 change: 0 additions & 1 deletion widget/windows/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ EXPORTS.mozilla.widget += [
"InProcessWinCompositorWidget.h",
"JumpListBuilder.h",
"nsWindowLoggedMessages.h",
"OSKInputPaneManager.h",
"WinCompositorWidget.h",
"WinCompositorWindowThread.h",
"WindowsEMF.h",
Expand Down

0 comments on commit 34877aa

Please sign in to comment.