Bug 1369696 - part 1: TSFTextStore::sKeystrokeMgr should be QIed from TSFTextStore::sThreadMgr at first use r?m_kato
sKeystrokeMgr is required only when WM_KEYDOWN or WM_KEYUP message are received. So, we can put off to initialize sKeystrokeMgr until then.
MozReview-Commit-ID: JsLeM0SYXG6
--- a/widget/windows/TSFTextStore.cpp
+++ b/widget/windows/TSFTextStore.cpp
@@ -6157,26 +6157,16 @@ TSFTextStore::Initialize()
getter_AddRefs(messagePump));
if (FAILED(hr) || !messagePump) {
MOZ_LOG(sTextStoreLog, LogLevel::Error,
(" TSFTextStore::Initialize() FAILED to "
"QI message pump from the thread manager, hr=0x%08X", hr));
return;
}
- RefPtr<ITfKeystrokeMgr> keystrokeMgr;
- hr = threadMgr->QueryInterface(IID_ITfKeystrokeMgr,
- getter_AddRefs(keystrokeMgr));
- if (FAILED(hr) || !keystrokeMgr) {
- MOZ_LOG(sTextStoreLog, LogLevel::Error,
- (" TSFTextStore::Initialize() FAILED to "
- "QI keystroke manager from the thread manager, hr=0x%08X", hr));
- return;
- }
-
hr = threadMgr->Activate(&sClientId);
if (FAILED(hr)) {
MOZ_LOG(sTextStoreLog, LogLevel::Error,
(" TSFTextStore::Initialize() FAILED to activate, hr=0x%08X", hr));
return;
}
RefPtr<ITfDocumentMgr> disabledDocumentMgr;
@@ -6200,17 +6190,16 @@ TSFTextStore::Initialize()
return;
}
MarkContextAsKeyboardDisabled(disabledContext);
MarkContextAsEmpty(disabledContext);
sThreadMgr = threadMgr;
sMessagePump = messagePump;
- sKeystrokeMgr = keystrokeMgr;
sDisabledDocumentMgr = disabledDocumentMgr;
sDisabledContext = disabledContext;
MOZ_LOG(sTextStoreLog, LogLevel::Info,
(" TSFTextStore::Initialize(), sThreadMgr=0x%p, "
"sClientId=0x%08X, sDisabledDocumentMgr=0x%p, sDisabledContext=%p",
sThreadMgr.get(), sClientId,
sDisabledDocumentMgr.get(), sDisabledContext.get()));
@@ -6321,18 +6310,38 @@ TSFTextStore::Terminate()
sKeystrokeMgr = nullptr;
}
}
// static
bool
TSFTextStore::ProcessRawKeyMessage(const MSG& aMsg)
{
+ if (!sThreadMgr) {
+ return false; // not in TSF mode
+ }
+ static bool sInitialized = false;
if (!sKeystrokeMgr) {
- return false; // not in TSF mode
+ // If it tried to retrieve ITfKeystrokeMgr from sThreadMgr but it failed,
+ // we shouldn't retry it at every keydown nor keyup due to performance
+ // reason. Although this shouldn't occur actually.
+ if (sInitialized) {
+ return false;
+ }
+ sInitialized = true;
+ RefPtr<ITfKeystrokeMgr> keystrokeMgr;
+ HRESULT hr = sThreadMgr->QueryInterface(IID_ITfKeystrokeMgr,
+ getter_AddRefs(keystrokeMgr));
+ if (NS_WARN_IF(FAILED(hr)) || NS_WARN_IF(!keystrokeMgr)) {
+ MOZ_LOG(sTextStoreLog, LogLevel::Error,
+ ("TSFTextStore::ProcessRawKeyMessage() FAILED to "
+ "QI keystroke manager from the thread manager, hr=0x%08X", hr));
+ return false;
+ }
+ sKeystrokeMgr = keystrokeMgr.forget();
}
if (aMsg.message == WM_KEYDOWN) {
BOOL eaten;
RefPtr<ITfKeystrokeMgr> keystrokeMgr = sKeystrokeMgr;
HRESULT hr = keystrokeMgr->TestKeyDown(aMsg.wParam, aMsg.lParam, &eaten);
if (FAILED(hr) || !sKeystrokeMgr || !eaten) {
return false;