Commit e36480b8 authored by shuchen's avatar shuchen Committed by Commit bot

Check the IME component extension's availability on linux_chromeos, so that...

Check the IME component extension's availability on linux_chromeos, so that system fallback VK can be showed.

BUG=405042
TEST=Verified on linux_chromeos.

Review URL: https://codereview.chromium.org/495593004

Cr-Commit-Position: refs/heads/master@{#291642}
parent cec05883
...@@ -22,9 +22,11 @@ ...@@ -22,9 +22,11 @@
#include "chrome/grit/browser_resources.h" #include "chrome/grit/browser_resources.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chromeos/ime/extension_ime_util.h" #include "chromeos/ime/extension_ime_util.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/browser/extension_system.h" #include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "extensions/common/extension_l10n_util.h" #include "extensions/common/extension_l10n_util.h"
#include "extensions/common/file_util.h"
#include "extensions/common/manifest_constants.h" #include "extensions/common/manifest_constants.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
...@@ -238,10 +240,39 @@ extensions::ComponentLoader* GetComponentLoader(Profile* profile) { ...@@ -238,10 +240,39 @@ extensions::ComponentLoader* GetComponentLoader(Profile* profile) {
ExtensionService* extension_service = extension_system->extension_service(); ExtensionService* extension_service = extension_system->extension_service();
return extension_service->component_loader(); return extension_service->component_loader();
} }
void DoLoadExtension(Profile* profile,
const std::string& extension_id,
const std::string& manifest,
const base::FilePath& file_path) {
extensions::ExtensionSystem* extension_system =
extensions::ExtensionSystem::Get(profile);
ExtensionService* extension_service = extension_system->extension_service();
if (extension_service->GetExtensionById(extension_id, false))
return;
const std::string loaded_extension_id =
GetComponentLoader(profile)->Add(manifest, file_path);
DCHECK_EQ(loaded_extension_id, extension_id);
}
bool CheckFilePath(const base::FilePath* file_path) {
return base::PathExists(*file_path);
}
void OnFilePathChecked(Profile* profile,
const std::string* extension_id,
const std::string* manifest,
const base::FilePath* file_path,
bool result) {
if (result)
DoLoadExtension(profile, *extension_id, *manifest, *file_path);
else
LOG(ERROR) << "IME extension file path not exists: " << file_path->value();
}
} // namespace } // namespace
ComponentExtensionIMEManagerImpl::ComponentExtensionIMEManagerImpl() ComponentExtensionIMEManagerImpl::ComponentExtensionIMEManagerImpl() {
: weak_ptr_factory_(this) {
ReadComponentExtensionsInfo(&component_extension_list_); ReadComponentExtensionsInfo(&component_extension_list_);
} }
...@@ -252,19 +283,31 @@ std::vector<ComponentExtensionIME> ComponentExtensionIMEManagerImpl::ListIME() { ...@@ -252,19 +283,31 @@ std::vector<ComponentExtensionIME> ComponentExtensionIMEManagerImpl::ListIME() {
return component_extension_list_; return component_extension_list_;
} }
bool ComponentExtensionIMEManagerImpl::Load(Profile* profile, void ComponentExtensionIMEManagerImpl::Load(Profile* profile,
const std::string& extension_id, const std::string& extension_id,
const std::string& manifest, const std::string& manifest,
const base::FilePath& file_path) { const base::FilePath& file_path) {
extensions::ExtensionSystem* extension_system = if (base::SysInfo::IsRunningOnChromeOS()) {
extensions::ExtensionSystem::Get(profile); // In the case of real Chrome OS device, the no need to check the file path
ExtensionService* extension_service = extension_system->extension_service(); // for preinstalled files existence.
if (extension_service->GetExtensionById(extension_id, false)) DoLoadExtension(profile, extension_id, manifest, file_path);
return false; return;
const std::string loaded_extension_id = }
GetComponentLoader(profile)->Add(manifest, file_path); // If current environment is linux_chromeos, check the existence of file path
DCHECK_EQ(loaded_extension_id, extension_id); // to avoid unnecessary extension loading and InputMethodEngine creation, so
return true; // that the virtual keyboard web content url won't be override by IME
// component extensions.
base::FilePath* copied_file_path = new base::FilePath(file_path);
content::BrowserThread::PostTaskAndReplyWithResult(
content::BrowserThread::FILE,
FROM_HERE,
base::Bind(&CheckFilePath,
base::Unretained(copied_file_path)),
base::Bind(&OnFilePathChecked,
base::Unretained(profile),
base::Owned(new std::string(extension_id)),
base::Owned(new std::string(manifest)),
base::Owned(copied_file_path)));
} }
void ComponentExtensionIMEManagerImpl::Unload(Profile* profile, void ComponentExtensionIMEManagerImpl::Unload(Profile* profile,
......
...@@ -28,7 +28,7 @@ class ComponentExtensionIMEManagerImpl ...@@ -28,7 +28,7 @@ class ComponentExtensionIMEManagerImpl
// ComponentExtensionIMEManagerDelegate overrides: // ComponentExtensionIMEManagerDelegate overrides:
virtual std::vector<ComponentExtensionIME> ListIME() OVERRIDE; virtual std::vector<ComponentExtensionIME> ListIME() OVERRIDE;
virtual bool Load(Profile* profile, virtual void Load(Profile* profile,
const std::string& extension_id, const std::string& extension_id,
const std::string& manifest, const std::string& manifest,
const base::FilePath& file_path) OVERRIDE; const base::FilePath& file_path) OVERRIDE;
...@@ -63,10 +63,6 @@ class ComponentExtensionIMEManagerImpl ...@@ -63,10 +63,6 @@ class ComponentExtensionIMEManagerImpl
// The list of component extension IME. // The list of component extension IME.
std::vector<ComponentExtensionIME> component_extension_list_; std::vector<ComponentExtensionIME> component_extension_list_;
// For checking the function should be called on UI thread.
base::ThreadChecker thread_checker_;
base::WeakPtrFactory<ComponentExtensionIMEManagerImpl> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ComponentExtensionIMEManagerImpl); DISALLOW_COPY_AND_ASSIGN(ComponentExtensionIMEManagerImpl);
}; };
......
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
#include "third_party/icu/source/common/unicode/uloc.h" #include "third_party/icu/source/common/unicode/uloc.h"
#include "ui/base/accelerators/accelerator.h" #include "ui/base/accelerators/accelerator.h"
#include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/keyboard_util.h"
namespace chromeos { namespace chromeos {
namespace input_method { namespace input_method {
...@@ -920,8 +922,17 @@ void InputMethodManagerImpl::ChangeInputMethodInternal( ...@@ -920,8 +922,17 @@ void InputMethodManagerImpl::ChangeInputMethodInternal(
IMEBridge::Get()->SetCurrentEngineHandler(engine); IMEBridge::Get()->SetCurrentEngineHandler(engine);
if (engine) if (engine) {
engine->Enable(component_id); engine->Enable(component_id);
} else {
// If no engine to enable, cancel the virtual keyboard url override so that
// it can use the fallback system virtual keyboard UI.
keyboard::SetOverrideContentUrl(GURL());
keyboard::KeyboardController* keyboard_controller =
keyboard::KeyboardController::GetInstance();
if (keyboard_controller)
keyboard_controller->Reload();
}
// Change the keyboard layout to a preferred layout for the input method. // Change the keyboard layout to a preferred layout for the input method.
if (!keyboard_->SetCurrentKeyboardLayoutByName( if (!keyboard_->SetCurrentKeyboardLayoutByName(
......
...@@ -108,10 +108,11 @@ bool ComponentExtensionIMEManager::LoadComponentExtensionIME( ...@@ -108,10 +108,11 @@ bool ComponentExtensionIMEManager::LoadComponentExtensionIME(
Profile* profile, Profile* profile,
const std::string& input_method_id) { const std::string& input_method_id) {
ComponentExtensionIME ime; ComponentExtensionIME ime;
if (FindEngineEntry(input_method_id, &ime)) if (FindEngineEntry(input_method_id, &ime)) {
return delegate_->Load(profile, ime.id, ime.manifest, ime.path); delegate_->Load(profile, ime.id, ime.manifest, ime.path);
else return true;
return false; }
return false;
} }
bool ComponentExtensionIMEManager::UnloadComponentExtensionIME( bool ComponentExtensionIMEManager::UnloadComponentExtensionIME(
......
...@@ -54,7 +54,7 @@ class CHROMEOS_EXPORT ComponentExtensionIMEManagerDelegate { ...@@ -54,7 +54,7 @@ class CHROMEOS_EXPORT ComponentExtensionIMEManagerDelegate {
// Loads component extension IME associated with |extension_id|. // Loads component extension IME associated with |extension_id|.
// Returns false if it fails, otherwise returns true. // Returns false if it fails, otherwise returns true.
virtual bool Load(Profile* profile, virtual void Load(Profile* profile,
const std::string& extension_id, const std::string& extension_id,
const std::string& manifest, const std::string& manifest,
const base::FilePath& path) = 0; const base::FilePath& path) = 0;
......
...@@ -23,13 +23,12 @@ std::vector<ComponentExtensionIME> ...@@ -23,13 +23,12 @@ std::vector<ComponentExtensionIME>
return ime_list_; return ime_list_;
} }
bool MockComponentExtIMEManagerDelegate::Load(Profile* profile, void MockComponentExtIMEManagerDelegate::Load(Profile* profile,
const std::string& extension_id, const std::string& extension_id,
const std::string& manifest, const std::string& manifest,
const base::FilePath& path) { const base::FilePath& path) {
last_loaded_extension_id_ = extension_id; last_loaded_extension_id_ = extension_id;
load_call_count_++; load_call_count_++;
return true;
} }
void MockComponentExtIMEManagerDelegate::Unload(Profile* profile, void MockComponentExtIMEManagerDelegate::Unload(Profile* profile,
......
...@@ -18,7 +18,7 @@ class CHROMEOS_EXPORT MockComponentExtIMEManagerDelegate ...@@ -18,7 +18,7 @@ class CHROMEOS_EXPORT MockComponentExtIMEManagerDelegate
virtual ~MockComponentExtIMEManagerDelegate(); virtual ~MockComponentExtIMEManagerDelegate();
virtual std::vector<ComponentExtensionIME> ListIME() OVERRIDE; virtual std::vector<ComponentExtensionIME> ListIME() OVERRIDE;
virtual bool Load(Profile*, virtual void Load(Profile*,
const std::string& extension_id, const std::string& extension_id,
const std::string& manifest, const std::string& manifest,
const base::FilePath& path) OVERRIDE; const base::FilePath& path) OVERRIDE;
......
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