Commit b8c45b5c authored by Siye Liu's avatar Siye Liu Committed by Commit Bot

For TSF1 on Windows 10, we need to set input scope to IS_PRIVATE if we

are in "Incognito" or "guest" mode.

Bug: 958054
Change-Id: I35e4adec0fd1800cff1ec2fcfe7983e2a65540e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1591886
Commit-Queue: Siye Liu <siliu@microsoft.com>
Reviewed-by: default avatarYohei Yukawa <yukawa@chromium.org>
Cr-Commit-Position: refs/heads/master@{#657438}
parent 18adb490
...@@ -188,8 +188,18 @@ std::vector<InputScope> GetInputScopes(TextInputType text_input_type, ...@@ -188,8 +188,18 @@ std::vector<InputScope> GetInputScopes(TextInputType text_input_type,
} }
ITfInputScope* CreateInputScope(TextInputType text_input_type, ITfInputScope* CreateInputScope(TextInputType text_input_type,
TextInputMode text_input_mode) { TextInputMode text_input_mode,
return new TSFInputScope(GetInputScopes(text_input_type, text_input_mode)); bool should_do_learning) {
std::vector<InputScope> input_scopes;
// Should set input scope to IS_PRIVATE if we are in "incognito" or "guest"
// mode. Note that the IS_PRIVATE input scope is only support from WIN10.
if (!should_do_learning &&
(base::win::GetVersion() >= base::win::Version::WIN10)) {
input_scopes.push_back(IS_PRIVATE);
} else {
input_scopes = GetInputScopes(text_input_type, text_input_mode);
}
return new TSFInputScope(input_scopes);
} }
void SetInputScopeForTsfUnawareWindow(HWND window_handle, void SetInputScopeForTsfUnawareWindow(HWND window_handle,
......
...@@ -35,7 +35,8 @@ std::vector<InputScope> GetInputScopes(TextInputType text_input_type, ...@@ -35,7 +35,8 @@ std::vector<InputScope> GetInputScopes(TextInputType text_input_type,
// reference count. // reference count.
COMPONENT_EXPORT(UI_BASE_IME_WIN) COMPONENT_EXPORT(UI_BASE_IME_WIN)
ITfInputScope* CreateInputScope(TextInputType text_input_type, ITfInputScope* CreateInputScope(TextInputType text_input_type,
TextInputMode text_input_mode); TextInputMode text_input_mode,
bool should_do_learning);
// A wrapper of the SetInputScopes API exported by msctf.dll. // A wrapper of the SetInputScopes API exported by msctf.dll.
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms629026.aspx // http://msdn.microsoft.com/en-us/library/windows/desktop/ms629026.aspx
......
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
#include <InputScope.h> #include <InputScope.h>
#include <stddef.h> #include <stddef.h>
#include <wrl/client.h>
#include "base/win/windows_version.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace ui { namespace ui {
...@@ -103,5 +105,54 @@ INSTANTIATE_TEST_SUITE_P(, ...@@ -103,5 +105,54 @@ INSTANTIATE_TEST_SUITE_P(,
TSFInputScopeTest, TSFInputScopeTest,
::testing::ValuesIn(kGetInputScopesTestCases)); ::testing::ValuesIn(kGetInputScopesTestCases));
struct CreateInputScopesTestCase {
TextInputType input_type;
TextInputMode input_mode;
bool should_do_learning;
UINT expected_size;
InputScope expected_input_scopes[2];
};
class TSFCreateInputScopeTest
: public testing::TestWithParam<CreateInputScopesTestCase> {};
const CreateInputScopesTestCase kCreateInputScopesTestCases[] = {
// Test cases of TextInputType.
{TEXT_INPUT_TYPE_NONE, TEXT_INPUT_MODE_DEFAULT, true, 1, {IS_DEFAULT}},
{TEXT_INPUT_TYPE_TEXT, TEXT_INPUT_MODE_DEFAULT, false, 1, {IS_PRIVATE}},
{TEXT_INPUT_TYPE_PASSWORD, TEXT_INPUT_MODE_DEFAULT, true, 1, {IS_PASSWORD}},
{TEXT_INPUT_TYPE_PASSWORD, TEXT_INPUT_MODE_DEFAULT, false, 1, {IS_PRIVATE}},
// Test cases of TextInputMode.
{TEXT_INPUT_TYPE_NONE, TEXT_INPUT_MODE_DEFAULT, true, 1, {IS_DEFAULT}},
{TEXT_INPUT_TYPE_NONE, TEXT_INPUT_MODE_URL, false, 1, {IS_PRIVATE}},
{TEXT_INPUT_TYPE_NONE, TEXT_INPUT_MODE_SEARCH, true, 1, {IS_SEARCH}},
{TEXT_INPUT_TYPE_NONE, TEXT_INPUT_MODE_SEARCH, false, 1, {IS_PRIVATE}},
// Mixed test cases.
{TEXT_INPUT_TYPE_NUMBER,
TEXT_INPUT_MODE_NUMERIC,
true,
2,
{IS_NUMBER, IS_DIGITS}},
{TEXT_INPUT_TYPE_NUMBER, TEXT_INPUT_MODE_NUMERIC, false, 1, {IS_PRIVATE}},
};
TEST_P(TSFCreateInputScopeTest, CreateInputScopes) {
if (base::win::GetVersion() < base::win::Version::WIN10)
return;
const CreateInputScopesTestCase& test_case = GetParam();
Microsoft::WRL::ComPtr<ITfInputScope> input_scope =
tsf_inputscope::CreateInputScope(test_case.input_type,
test_case.input_mode,
test_case.should_do_learning);
UINT c_input_scopes = 0;
InputScope* input_scopes = nullptr;
HRESULT result = input_scope->GetInputScopes(&input_scopes, &c_input_scopes);
EXPECT_EQ(S_OK, result);
EXPECT_EQ(test_case.expected_size, c_input_scopes);
for (size_t i = 0; i < test_case.expected_size; ++i)
EXPECT_EQ(test_case.expected_input_scopes[i], input_scopes[i]);
CoTaskMemFree(input_scopes);
}
INSTANTIATE_TEST_SUITE_P(,
TSFCreateInputScopeTest,
::testing::ValuesIn(kCreateInputScopesTestCases));
} // namespace } // namespace
} // namespace ui } // namespace ui
...@@ -672,7 +672,8 @@ STDMETHODIMP TSFTextStore::RetrieveRequestedAttrs( ...@@ -672,7 +672,8 @@ STDMETHODIMP TSFTextStore::RetrieveRequestedAttrs(
attribute_buffer[0].varValue.vt = VT_UNKNOWN; attribute_buffer[0].varValue.vt = VT_UNKNOWN;
attribute_buffer[0].varValue.punkVal = attribute_buffer[0].varValue.punkVal =
tsf_inputscope::CreateInputScope(text_input_client_->GetTextInputType(), tsf_inputscope::CreateInputScope(text_input_client_->GetTextInputType(),
text_input_client_->GetTextInputMode()); text_input_client_->GetTextInputMode(),
text_input_client_->ShouldDoLearning());
attribute_buffer[0].varValue.punkVal->AddRef(); attribute_buffer[0].varValue.punkVal->AddRef();
*attribute_buffer_copied = 1; *attribute_buffer_copied = 1;
return S_OK; return S_OK;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment