Bug 1589497 - Make PendingAction of TSFStore copy of key message r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 26 Mar 2020 07:33:37 +0000
changeset 520478 46bf06a42ba623133cfdaceac9d3f9f778975b79
parent 520477 1fe283e3bb59d87eb597ee4a0287fbafe264bc34
child 520479 fff410e32a31f0849fc3d65048ed07d32fa12a08
push id37252
push usermalexandru@mozilla.com
push dateThu, 26 Mar 2020 15:34:27 +0000
treeherdermozilla-central@31360ced8ff8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1589497
milestone76.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1589497 - Make PendingAction of TSFStore copy of key message r=m_kato `TSFTextStore::sHandlingKeyMsg` refers pointer of struct, but referred via `TSFTextStore::PendingAction` so that we should make it has a copy of `sHandlingKeyMsg` because of for async handling. Differential Revision: https://phabricator.services.mozilla.com/D68049
widget/windows/KeyboardLayout.cpp
widget/windows/TSFTextStore.cpp
widget/windows/TSFTextStore.h
--- a/widget/windows/KeyboardLayout.cpp
+++ b/widget/windows/KeyboardLayout.cpp
@@ -1555,18 +1555,20 @@ void NativeKey::InitWithKeyOrChar() {
       // NOTE: If other applications like a11y tools sends WM_*CHAR without
       //       scancode, we cannot compute virtual keycode.  I.e., with such
       //       applications, we cannot generate proper KeyboardEvent.code value.
 
       mVirtualKeyCode = mOriginalVirtualKeyCode =
           ComputeVirtualKeyCodeFromScanCodeEx();
       NS_ASSERTION(mVirtualKeyCode, "Failed to compute virtual keycode");
       break;
-    default:
-      MOZ_CRASH("Unsupported message");
+    default: {
+      MOZ_CRASH_UNSAFE_PRINTF("Unsupported message: 0x%04X", mMsg.message);
+      break;
+    }
   }
 
   if (!mVirtualKeyCode) {
     mVirtualKeyCode = mOriginalVirtualKeyCode;
   }
 
   KeyboardLayout* keyboardLayout = KeyboardLayout::GetInstance();
   mDOMKeyCode =
--- a/widget/windows/TSFTextStore.cpp
+++ b/widget/windows/TSFTextStore.cpp
@@ -2336,25 +2336,25 @@ void TSFTextStore::FlushPendingActions()
              this));
     return;
   }
   for (uint32_t i = 0; i < mPendingActions.Length(); i++) {
     PendingAction& action = mPendingActions[i];
     switch (action.mType) {
       case PendingAction::Type::eKeyboardEvent:
         if (mDestroyed) {
-          MOZ_LOG(
-              sTextStoreLog, LogLevel::Warning,
-              ("0x%p   TSFTextStore::FlushPendingActions() "
-               "IGNORED pending KeyboardEvent(%s) due to already destroyed",
-               action.mKeyMsg->message == WM_KEYDOWN ? "eKeyDown" : "eKeyUp",
-               this));
+          MOZ_LOG(sTextStoreLog, LogLevel::Warning,
+                  ("0x%p   TSFTextStore::FlushPendingActions() "
+                   "IGNORED pending KeyboardEvent(%s) due to already destroyed",
+                   action.mKeyMsg.message == WM_KEYDOWN ? "eKeyDown" : "eKeyUp",
+                   this));
         }
-        MOZ_DIAGNOSTIC_ASSERT(action.mKeyMsg);
-        DispatchKeyboardEventAsProcessedByIME(*action.mKeyMsg);
+        MOZ_DIAGNOSTIC_ASSERT(action.mKeyMsg.message == WM_KEYDOWN ||
+                              action.mKeyMsg.message == WM_KEYUP);
+        DispatchKeyboardEventAsProcessedByIME(action.mKeyMsg);
         if (!widget || widget->Destroyed()) {
           break;
         }
         break;
       case PendingAction::Type::eCompositionStart: {
         MOZ_LOG(sTextStoreLog, LogLevel::Debug,
                 ("0x%p   TSFTextStore::FlushPendingActions() "
                  "flushing Type::eCompositionStart={ mSelectionStart=%d, "
@@ -2660,17 +2660,17 @@ void TSFTextStore::MaybeDispatchKeyboard
   if (IsReadLocked()) {
     MOZ_LOG(
         sTextStoreLog, LogLevel::Debug,
         ("0x%p   TSFTextStore::MaybeDispatchKeyboardEventAsProcessedByIME(), "
          "adding to dispatch a keyboard event into the queue...",
          this));
     PendingAction* action = mPendingActions.AppendElement();
     action->mType = PendingAction::Type::eKeyboardEvent;
-    action->mKeyMsg = sHandlingKeyMsg;
+    memcpy(&action->mKeyMsg, sHandlingKeyMsg, sizeof(MSG));
     return;
   }
 
   // Otherwise, dispatch a keyboard event.
   MOZ_LOG(sTextStoreLog, LogLevel::Debug,
           ("0x%p   TSFTextStore::MaybeDispatchKeyboardEventAsProcessedByIME(), "
            "trying to dispatch a keyboard event...",
            this));
--- a/widget/windows/TSFTextStore.h
+++ b/widget/windows/TSFTextStore.h
@@ -674,17 +674,17 @@ class TSFTextStore final : public ITextS
     LONG mSelectionStart;
     // For eCompositionStart and eSetSelection
     LONG mSelectionLength;
     // For eCompositionStart, eCompositionUpdate and eCompositionEnd
     nsString mData;
     // For eCompositionUpdate
     RefPtr<TextRangeArray> mRanges;
     // For eKeyboardEvent
-    const MSG* mKeyMsg;
+    MSG mKeyMsg;
     // For eSetSelection
     bool mSelectionReversed;
     // For eCompositionUpdate
     bool mIncomplete;
     // For eCompositionStart
     bool mAdjustSelection;
   };
   // Items of mPendingActions are appended when TSF tells us to need to dispatch