| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/input_method/component_extension_ime_manager_i
mpl.h" | 5 #include "chrome/browser/chromeos/input_method/component_extension_ime_manager_i
mpl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/sys_info.h" | 14 #include "base/sys_info.h" |
| 15 #include "chrome/browser/extensions/component_loader.h" | 15 #include "chrome/browser/extensions/component_loader.h" |
| 16 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
| 19 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
| 20 #include "chrome/common/extensions/extension_constants.h" | 20 #include "chrome/common/extensions/extension_constants.h" |
| 21 #include "chrome/common/extensions/extension_file_util.h" | 21 #include "chrome/common/extensions/extension_file_util.h" |
| 22 #include "chrome/grit/browser_resources.h" | 22 #include "chrome/grit/browser_resources.h" |
| 23 #include "chrome/grit/generated_resources.h" | 23 #include "chrome/grit/generated_resources.h" |
| 24 #include "chromeos/ime/extension_ime_util.h" | 24 #include "chromeos/ime/extension_ime_util.h" |
| 25 #include "content/public/browser/browser_thread.h" |
| 25 #include "extensions/browser/extension_system.h" | 26 #include "extensions/browser/extension_system.h" |
| 26 #include "extensions/common/extension.h" | 27 #include "extensions/common/extension.h" |
| 27 #include "extensions/common/extension_l10n_util.h" | 28 #include "extensions/common/extension_l10n_util.h" |
| 29 #include "extensions/common/file_util.h" |
| 28 #include "extensions/common/manifest_constants.h" | 30 #include "extensions/common/manifest_constants.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
| 31 | 33 |
| 32 namespace chromeos { | 34 namespace chromeos { |
| 33 | 35 |
| 34 namespace { | 36 namespace { |
| 35 | 37 |
| 36 struct WhitelistedComponentExtensionIME { | 38 struct WhitelistedComponentExtensionIME { |
| 37 const char* id; | 39 const char* id; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 }; | 233 }; |
| 232 | 234 |
| 233 const char kImePathKeyName[] = "ime_path"; | 235 const char kImePathKeyName[] = "ime_path"; |
| 234 | 236 |
| 235 extensions::ComponentLoader* GetComponentLoader(Profile* profile) { | 237 extensions::ComponentLoader* GetComponentLoader(Profile* profile) { |
| 236 extensions::ExtensionSystem* extension_system = | 238 extensions::ExtensionSystem* extension_system = |
| 237 extensions::ExtensionSystem::Get(profile); | 239 extensions::ExtensionSystem::Get(profile); |
| 238 ExtensionService* extension_service = extension_system->extension_service(); | 240 ExtensionService* extension_service = extension_system->extension_service(); |
| 239 return extension_service->component_loader(); | 241 return extension_service->component_loader(); |
| 240 } | 242 } |
| 243 |
| 244 void DoLoadExtension(Profile* profile, |
| 245 const std::string& extension_id, |
| 246 const std::string& manifest, |
| 247 const base::FilePath& file_path) { |
| 248 extensions::ExtensionSystem* extension_system = |
| 249 extensions::ExtensionSystem::Get(profile); |
| 250 ExtensionService* extension_service = extension_system->extension_service(); |
| 251 if (extension_service->GetExtensionById(extension_id, false)) |
| 252 return; |
| 253 const std::string loaded_extension_id = |
| 254 GetComponentLoader(profile)->Add(manifest, file_path); |
| 255 DCHECK_EQ(loaded_extension_id, extension_id); |
| 256 } |
| 257 |
| 258 bool CheckFilePath(const base::FilePath* file_path) { |
| 259 return base::PathExists(*file_path); |
| 260 } |
| 261 |
| 262 void OnFilePathChecked(Profile* profile, |
| 263 const std::string* extension_id, |
| 264 const std::string* manifest, |
| 265 const base::FilePath* file_path, |
| 266 bool result) { |
| 267 if (result) |
| 268 DoLoadExtension(profile, *extension_id, *manifest, *file_path); |
| 269 else |
| 270 LOG(ERROR) << "IME extension file path not exists: " << file_path->value(); |
| 271 } |
| 272 |
| 241 } // namespace | 273 } // namespace |
| 242 | 274 |
| 243 ComponentExtensionIMEManagerImpl::ComponentExtensionIMEManagerImpl() | 275 ComponentExtensionIMEManagerImpl::ComponentExtensionIMEManagerImpl() { |
| 244 : weak_ptr_factory_(this) { | |
| 245 ReadComponentExtensionsInfo(&component_extension_list_); | 276 ReadComponentExtensionsInfo(&component_extension_list_); |
| 246 } | 277 } |
| 247 | 278 |
| 248 ComponentExtensionIMEManagerImpl::~ComponentExtensionIMEManagerImpl() { | 279 ComponentExtensionIMEManagerImpl::~ComponentExtensionIMEManagerImpl() { |
| 249 } | 280 } |
| 250 | 281 |
| 251 std::vector<ComponentExtensionIME> ComponentExtensionIMEManagerImpl::ListIME() { | 282 std::vector<ComponentExtensionIME> ComponentExtensionIMEManagerImpl::ListIME() { |
| 252 return component_extension_list_; | 283 return component_extension_list_; |
| 253 } | 284 } |
| 254 | 285 |
| 255 bool ComponentExtensionIMEManagerImpl::Load(Profile* profile, | 286 void ComponentExtensionIMEManagerImpl::Load(Profile* profile, |
| 256 const std::string& extension_id, | 287 const std::string& extension_id, |
| 257 const std::string& manifest, | 288 const std::string& manifest, |
| 258 const base::FilePath& file_path) { | 289 const base::FilePath& file_path) { |
| 259 extensions::ExtensionSystem* extension_system = | 290 if (base::SysInfo::IsRunningOnChromeOS()) { |
| 260 extensions::ExtensionSystem::Get(profile); | 291 // In the case of real Chrome OS device, the no need to check the file path |
| 261 ExtensionService* extension_service = extension_system->extension_service(); | 292 // for preinstalled files existence. |
| 262 if (extension_service->GetExtensionById(extension_id, false)) | 293 DoLoadExtension(profile, extension_id, manifest, file_path); |
| 263 return false; | 294 return; |
| 264 const std::string loaded_extension_id = | 295 } |
| 265 GetComponentLoader(profile)->Add(manifest, file_path); | 296 // If current environment is linux_chromeos, check the existence of file path |
| 266 DCHECK_EQ(loaded_extension_id, extension_id); | 297 // to avoid unnecessary extension loading and InputMethodEngine creation, so |
| 267 return true; | 298 // that the virtual keyboard web content url won't be override by IME |
| 299 // component extensions. |
| 300 base::FilePath* copied_file_path = new base::FilePath(file_path); |
| 301 content::BrowserThread::PostTaskAndReplyWithResult( |
| 302 content::BrowserThread::FILE, |
| 303 FROM_HERE, |
| 304 base::Bind(&CheckFilePath, |
| 305 base::Unretained(copied_file_path)), |
| 306 base::Bind(&OnFilePathChecked, |
| 307 base::Unretained(profile), |
| 308 base::Owned(new std::string(extension_id)), |
| 309 base::Owned(new std::string(manifest)), |
| 310 base::Owned(copied_file_path))); |
| 268 } | 311 } |
| 269 | 312 |
| 270 void ComponentExtensionIMEManagerImpl::Unload(Profile* profile, | 313 void ComponentExtensionIMEManagerImpl::Unload(Profile* profile, |
| 271 const std::string& extension_id, | 314 const std::string& extension_id, |
| 272 const base::FilePath& file_path) { | 315 const base::FilePath& file_path) { |
| 273 // Remove(extension_id) does nothing when the extension has already been | 316 // Remove(extension_id) does nothing when the extension has already been |
| 274 // removed or not been registered. | 317 // removed or not been registered. |
| 275 GetComponentLoader(profile)->Remove(extension_id); | 318 GetComponentLoader(profile)->Remove(extension_id); |
| 276 } | 319 } |
| 277 | 320 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 | 487 |
| 445 ComponentExtensionEngine engine; | 488 ComponentExtensionEngine engine; |
| 446 ReadEngineComponent(component_ime, *dictionary, &engine); | 489 ReadEngineComponent(component_ime, *dictionary, &engine); |
| 447 component_ime.engines.push_back(engine); | 490 component_ime.engines.push_back(engine); |
| 448 } | 491 } |
| 449 out_imes->push_back(component_ime); | 492 out_imes->push_back(component_ime); |
| 450 } | 493 } |
| 451 } | 494 } |
| 452 | 495 |
| 453 } // namespace chromeos | 496 } // namespace chromeos |
| OLD | NEW |