Commit 4e78f6da authored by David Vallet's avatar David Vallet Committed by Commit Bot

COIL: Change to use allowlist in component_extension_ime_manager.

Bug: 1124062
Change-Id: I549503bf2ae09c30260133c48af304923bba0996
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2409884
Commit-Queue: David Vallet <dvallet@chromium.org>
Reviewed-by: default avatarDavid Vallet <dvallet@chromium.org>
Reviewed-by: default avatarKeith Lee <keithlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807260}
parent dfb9023b
......@@ -1145,7 +1145,7 @@ void InputMethodManagerImpl::LoadNecessaryComponentExtensions(
unfiltered_input_method_id)) {
// Legacy IMEs or xkb layouts are alwayes active.
state->active_input_method_ids.push_back(unfiltered_input_method_id);
} else if (component_extension_ime_manager_->IsWhitelisted(
} else if (component_extension_ime_manager_->IsAllowlisted(
unfiltered_input_method_id)) {
if (enable_extension_loading_) {
component_extension_ime_manager_->LoadComponentExtensionIME(
......
......@@ -557,7 +557,7 @@ bool InputImeEventRouter::RegisterImeExtension(
chromeos::input_method::InputMethodDescriptors descriptors;
// Only creates descriptors for 3rd party IME extension, because the
// descriptors for component IME extensions are managed by InputMethodUtil.
if (!comp_ext_ime_manager->IsWhitelistedExtension(extension_id)) {
if (!comp_ext_ime_manager->IsAllowlistedExtension(extension_id)) {
for (const auto& component : input_components) {
DCHECK(component.type == INPUT_COMPONENT_TYPE_IME);
......@@ -1056,7 +1056,7 @@ void InputImeAPI::OnExtensionUnloaded(content::BrowserContext* browser_context,
chromeos::ComponentExtensionIMEManager* comp_ext_ime_manager =
manager->GetComponentExtensionIMEManager();
if (comp_ext_ime_manager->IsWhitelistedExtension(extension->id())) {
if (comp_ext_ime_manager->IsAllowlistedExtension(extension->id())) {
// Since the first party ime is not allow to uninstall, and when it's
// unloaded unexpectedly, OS will recover the extension at once.
// So should not unregister the IMEs. Otherwise the IME icons on the
......
......@@ -75,13 +75,13 @@ void ComponentExtensionIMEManager::Initialize(
delegate_ = std::move(delegate);
std::vector<ComponentExtensionIME> ext_list = delegate_->ListIME();
for (const auto& ext : ext_list) {
bool extension_exists = IsWhitelistedExtension(ext.id);
bool extension_exists = IsAllowlistedExtension(ext.id);
if (!extension_exists)
component_extension_imes_[ext.id] = ext;
for (const auto& ime : ext.engines) {
const std::string input_method_id =
extension_ime_util::GetComponentInputMethodID(ext.id, ime.engine_id);
if (extension_exists && !IsWhitelisted(input_method_id))
if (extension_exists && !IsAllowlisted(input_method_id))
component_extension_imes_[ext.id].engines.push_back(ime);
input_method_id_set_.insert(input_method_id);
}
......@@ -109,13 +109,13 @@ bool ComponentExtensionIMEManager::UnloadComponentExtensionIME(
return true;
}
bool ComponentExtensionIMEManager::IsWhitelisted(
bool ComponentExtensionIMEManager::IsAllowlisted(
const std::string& input_method_id) {
return input_method_id_set_.find(input_method_id) !=
input_method_id_set_.end();
}
bool ComponentExtensionIMEManager::IsWhitelistedExtension(
bool ComponentExtensionIMEManager::IsAllowlistedExtension(
const std::string& extension_id) {
return component_extension_imes_.find(extension_id) !=
component_extension_imes_.end();
......@@ -134,18 +134,13 @@ input_method::InputMethodDescriptors
extension_ime_util::GetComponentInputMethodID(
ext.id, ime.engine_id);
const std::vector<std::string>& layouts = ime.layouts;
result.push_back(
input_method::InputMethodDescriptor(
input_method_id,
ime.display_name,
ime.indicator,
layouts,
result.push_back(input_method::InputMethodDescriptor(
input_method_id, ime.display_name, ime.indicator, layouts,
ime.language_codes,
// Enables extension based xkb keyboards on login screen.
extension_ime_util::IsKeyboardLayoutExtension(
input_method_id) && IsInLoginLayoutWhitelist(layouts),
ime.options_page_url,
ime.input_view_url));
extension_ime_util::IsKeyboardLayoutExtension(input_method_id) &&
IsInLoginLayoutAllowlist(layouts),
ime.options_page_url, ime.input_view_url));
}
}
std::stable_sort(result.begin(), result.end(), InputMethodCompare);
......@@ -167,7 +162,7 @@ ComponentExtensionIMEManager::GetXkbIMEAsInputMethodDescriptor() {
bool ComponentExtensionIMEManager::FindEngineEntry(
const std::string& input_method_id,
ComponentExtensionIME* out_extension) {
if (!IsWhitelisted(input_method_id))
if (!IsAllowlisted(input_method_id))
return false;
std::string extension_id =
......@@ -181,7 +176,7 @@ bool ComponentExtensionIMEManager::FindEngineEntry(
return true;
}
bool ComponentExtensionIMEManager::IsInLoginLayoutWhitelist(
bool ComponentExtensionIMEManager::IsInLoginLayoutAllowlist(
const std::vector<std::string>& layouts) {
for (const auto& layout : layouts) {
if (login_layout_set_.find(layout) != login_layout_set_.end())
......
......@@ -94,12 +94,12 @@ class COMPONENT_EXPORT(UI_BASE_IME_CHROMEOS) ComponentExtensionIMEManager {
bool UnloadComponentExtensionIME(Profile* profile,
const std::string& input_method_id);
// Returns true if |input_method_id| is whitelisted component extension input
// Returns true if |input_method_id| is allowlisted component extension input
// method.
bool IsWhitelisted(const std::string& input_method_id);
bool IsAllowlisted(const std::string& input_method_id);
// Returns true if |extension_id| is whitelisted component extension.
bool IsWhitelistedExtension(const std::string& extension_id);
// Returns true if |extension_id| is allowlisted component extension.
bool IsAllowlistedExtension(const std::string& extension_id);
// Returns all IME as InputMethodDescriptors.
input_method::InputMethodDescriptors GetAllIMEAsInputMethodDescriptor();
......@@ -115,7 +115,7 @@ class COMPONENT_EXPORT(UI_BASE_IME_CHROMEOS) ComponentExtensionIMEManager {
bool FindEngineEntry(const std::string& input_method_id,
ComponentExtensionIME* out_extension);
bool IsInLoginLayoutWhitelist(const std::vector<std::string>& layouts);
bool IsInLoginLayoutAllowlist(const std::vector<std::string>& layouts);
std::unique_ptr<ComponentExtensionIMEManagerDelegate> delegate_;
......
......@@ -161,28 +161,25 @@ TEST_F(ComponentExtensionIMEManagerTest, UnloadComponentExtensionIMETest) {
EXPECT_EQ(9, mock_delegate_->unload_call_count());
}
TEST_F(ComponentExtensionIMEManagerTest, IsWhitelistedTest) {
EXPECT_TRUE(component_ext_mgr_->IsWhitelisted(
TEST_F(ComponentExtensionIMEManagerTest, IsAllowlistedTest) {
EXPECT_TRUE(component_ext_mgr_->IsAllowlisted(
extension_ime_util::GetComponentInputMethodID(
ime_list_[0].id,
ime_list_[0].engines[0].engine_id)));
EXPECT_FALSE(component_ext_mgr_->IsWhitelisted(
extension_ime_util::GetInputMethodID(
ime_list_[0].id,
ime_list_[0].engines[0].engine_id)));
EXPECT_FALSE(component_ext_mgr_->IsWhitelisted("mozc"));
EXPECT_FALSE(component_ext_mgr_->IsWhitelisted(
ime_list_[0].id, ime_list_[0].engines[0].engine_id)));
EXPECT_FALSE(
component_ext_mgr_->IsAllowlisted(extension_ime_util::GetInputMethodID(
ime_list_[0].id, ime_list_[0].engines[0].engine_id)));
EXPECT_FALSE(component_ext_mgr_->IsAllowlisted("mozc"));
EXPECT_FALSE(component_ext_mgr_->IsAllowlisted(
extension_ime_util::GetInputMethodID("AAAA", "012345")));
EXPECT_FALSE(component_ext_mgr_->IsWhitelisted(
extension_ime_util::GetComponentInputMethodID(
"AAAA", "012345")));
EXPECT_FALSE(component_ext_mgr_->IsAllowlisted(
extension_ime_util::GetComponentInputMethodID("AAAA", "012345")));
}
TEST_F(ComponentExtensionIMEManagerTest, IsWhitelistedExtensionTest) {
EXPECT_TRUE(component_ext_mgr_->IsWhitelistedExtension(ime_list_[0].id));
EXPECT_TRUE(component_ext_mgr_->IsWhitelistedExtension(ime_list_[1].id));
EXPECT_FALSE(component_ext_mgr_->IsWhitelistedExtension("dummy"));
EXPECT_FALSE(component_ext_mgr_->IsWhitelistedExtension(""));
TEST_F(ComponentExtensionIMEManagerTest, IsAllowlistedExtensionTest) {
EXPECT_TRUE(component_ext_mgr_->IsAllowlistedExtension(ime_list_[0].id));
EXPECT_TRUE(component_ext_mgr_->IsAllowlistedExtension(ime_list_[1].id));
EXPECT_FALSE(component_ext_mgr_->IsAllowlistedExtension("dummy"));
EXPECT_FALSE(component_ext_mgr_->IsAllowlistedExtension(""));
}
TEST_F(ComponentExtensionIMEManagerTest, GetAllIMEAsInputMethodDescriptor) {
......
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