| 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" |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 {"__MSG_TRANSLITERATION_SA__", IDS_IME_NAME_TRANSLITERATION_SA}, | 225 {"__MSG_TRANSLITERATION_SA__", IDS_IME_NAME_TRANSLITERATION_SA}, |
| 226 {"__MSG_TRANSLITERATION_SR__", IDS_IME_NAME_TRANSLITERATION_SR}, | 226 {"__MSG_TRANSLITERATION_SR__", IDS_IME_NAME_TRANSLITERATION_SR}, |
| 227 {"__MSG_TRANSLITERATION_TA__", IDS_IME_NAME_TRANSLITERATION_TA}, | 227 {"__MSG_TRANSLITERATION_TA__", IDS_IME_NAME_TRANSLITERATION_TA}, |
| 228 {"__MSG_TRANSLITERATION_TE__", IDS_IME_NAME_TRANSLITERATION_TE}, | 228 {"__MSG_TRANSLITERATION_TE__", IDS_IME_NAME_TRANSLITERATION_TE}, |
| 229 {"__MSG_TRANSLITERATION_TI__", IDS_IME_NAME_TRANSLITERATION_TI}, | 229 {"__MSG_TRANSLITERATION_TI__", IDS_IME_NAME_TRANSLITERATION_TI}, |
| 230 {"__MSG_TRANSLITERATION_UR__", IDS_IME_NAME_TRANSLITERATION_UR}, | 230 {"__MSG_TRANSLITERATION_UR__", IDS_IME_NAME_TRANSLITERATION_UR}, |
| 231 }; | 231 }; |
| 232 | 232 |
| 233 const char kImePathKeyName[] = "ime_path"; | 233 const char kImePathKeyName[] = "ime_path"; |
| 234 | 234 |
| 235 extensions::ComponentLoader* GetComponentLoader() { | 235 extensions::ComponentLoader* GetComponentLoader(Profile* profile) { |
| 236 // TODO(skuhne, nkostylev): At this time the only thing which makes sense here | |
| 237 // is to use the active profile. Nkostylev is working on getting IME settings | |
| 238 // to work for multi user by collecting all settings from all users. Once that | |
| 239 // is done we might have to re-visit this decision. | |
| 240 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
| 241 extensions::ExtensionSystem* extension_system = | 236 extensions::ExtensionSystem* extension_system = |
| 242 extensions::ExtensionSystem::Get(profile); | 237 extensions::ExtensionSystem::Get(profile); |
| 243 ExtensionService* extension_service = extension_system->extension_service(); | 238 ExtensionService* extension_service = extension_system->extension_service(); |
| 244 return extension_service->component_loader(); | 239 return extension_service->component_loader(); |
| 245 } | 240 } |
| 246 } // namespace | 241 } // namespace |
| 247 | 242 |
| 248 ComponentExtensionIMEManagerImpl::ComponentExtensionIMEManagerImpl() | 243 ComponentExtensionIMEManagerImpl::ComponentExtensionIMEManagerImpl() |
| 249 : weak_ptr_factory_(this) { | 244 : weak_ptr_factory_(this) { |
| 250 ReadComponentExtensionsInfo(&component_extension_list_); | 245 ReadComponentExtensionsInfo(&component_extension_list_); |
| 251 } | 246 } |
| 252 | 247 |
| 253 ComponentExtensionIMEManagerImpl::~ComponentExtensionIMEManagerImpl() { | 248 ComponentExtensionIMEManagerImpl::~ComponentExtensionIMEManagerImpl() { |
| 254 } | 249 } |
| 255 | 250 |
| 256 std::vector<ComponentExtensionIME> ComponentExtensionIMEManagerImpl::ListIME() { | 251 std::vector<ComponentExtensionIME> ComponentExtensionIMEManagerImpl::ListIME() { |
| 257 return component_extension_list_; | 252 return component_extension_list_; |
| 258 } | 253 } |
| 259 | 254 |
| 260 bool ComponentExtensionIMEManagerImpl::Load(const std::string& extension_id, | 255 bool ComponentExtensionIMEManagerImpl::Load(Profile* profile, |
| 256 const std::string& extension_id, |
| 261 const std::string& manifest, | 257 const std::string& manifest, |
| 262 const base::FilePath& file_path) { | 258 const base::FilePath& file_path) { |
| 263 // If current environment is linux_chromeos, there should be no file path for | 259 // If current environment is linux_chromeos, there should be no file path for |
| 264 // the component extensions, so avoid loading them. | 260 // the component extensions, so avoid loading them. |
| 265 // The tests are also running on linux_chromeos environment. No test should | 261 // The tests are also running on linux_chromeos environment. No test should |
| 266 // run with the real component extensions because the component extension | 262 // run with the real component extensions because the component extension |
| 267 // contents are not in chromium code base. They're installed through ebuild | 263 // contents are not in chromium code base. They're installed through ebuild |
| 268 // scripts from chromeos. | 264 // scripts from chromeos. |
| 269 if (!base::SysInfo::IsRunningOnChromeOS()) | 265 if (!base::SysInfo::IsRunningOnChromeOS()) |
| 270 return false; | 266 return false; |
| 271 | 267 |
| 272 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
| 273 extensions::ExtensionSystem* extension_system = | 268 extensions::ExtensionSystem* extension_system = |
| 274 extensions::ExtensionSystem::Get(profile); | 269 extensions::ExtensionSystem::Get(profile); |
| 275 ExtensionService* extension_service = extension_system->extension_service(); | 270 ExtensionService* extension_service = extension_system->extension_service(); |
| 276 if (extension_service->GetExtensionById(extension_id, false)) | 271 if (extension_service->GetExtensionById(extension_id, false)) |
| 277 return false; | 272 return false; |
| 278 const std::string loaded_extension_id = | 273 const std::string loaded_extension_id = |
| 279 GetComponentLoader()->Add(manifest, file_path); | 274 GetComponentLoader(profile)->Add(manifest, file_path); |
| 280 DCHECK_EQ(loaded_extension_id, extension_id); | 275 DCHECK_EQ(loaded_extension_id, extension_id); |
| 281 return true; | 276 return true; |
| 282 } | 277 } |
| 283 | 278 |
| 284 void ComponentExtensionIMEManagerImpl::Unload(const std::string& extension_id, | 279 void ComponentExtensionIMEManagerImpl::Unload(Profile* profile, |
| 280 const std::string& extension_id, |
| 285 const base::FilePath& file_path) { | 281 const base::FilePath& file_path) { |
| 286 // Remove(extension_id) does nothing when the extension has already been | 282 // Remove(extension_id) does nothing when the extension has already been |
| 287 // removed or not been registered. | 283 // removed or not been registered. |
| 288 GetComponentLoader()->Remove(extension_id); | 284 GetComponentLoader(profile)->Remove(extension_id); |
| 289 } | 285 } |
| 290 | 286 |
| 291 scoped_ptr<base::DictionaryValue> ComponentExtensionIMEManagerImpl::GetManifest( | 287 scoped_ptr<base::DictionaryValue> ComponentExtensionIMEManagerImpl::GetManifest( |
| 292 const std::string& manifest_string) { | 288 const std::string& manifest_string) { |
| 293 std::string error; | 289 std::string error; |
| 294 JSONStringValueSerializer serializer(manifest_string); | 290 JSONStringValueSerializer serializer(manifest_string); |
| 295 scoped_ptr<base::Value> manifest(serializer.Deserialize(NULL, &error)); | 291 scoped_ptr<base::Value> manifest(serializer.Deserialize(NULL, &error)); |
| 296 if (!manifest.get()) | 292 if (!manifest.get()) |
| 297 LOG(ERROR) << "Failed at getting manifest"; | 293 LOG(ERROR) << "Failed at getting manifest"; |
| 298 | 294 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 | 453 |
| 458 ComponentExtensionEngine engine; | 454 ComponentExtensionEngine engine; |
| 459 ReadEngineComponent(component_ime, *dictionary, &engine); | 455 ReadEngineComponent(component_ime, *dictionary, &engine); |
| 460 component_ime.engines.push_back(engine); | 456 component_ime.engines.push_back(engine); |
| 461 } | 457 } |
| 462 out_imes->push_back(component_ime); | 458 out_imes->push_back(component_ime); |
| 463 } | 459 } |
| 464 } | 460 } |
| 465 | 461 |
| 466 } // namespace chromeos | 462 } // namespace chromeos |
| OLD | NEW |