Chromium Code Reviews| 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 CheckFilePath(const base::FilePath* file_path, bool* result) { | |
| 245 *result = base::PathExists(*file_path); | |
| 246 } | |
| 247 | |
| 248 void OnFilePathChecked(Profile* profile, | |
| 249 const std::string* manifest, | |
| 250 const base::FilePath* file_path, | |
| 251 bool* result) { | |
| 252 if (*result) | |
| 253 GetComponentLoader(profile)->Add(*manifest, *file_path); | |
| 254 else | |
| 255 LOG(ERROR) << "IME extension file path not exists: " << file_path->value(); | |
| 256 } | |
| 257 | |
| 241 } // namespace | 258 } // namespace |
| 242 | 259 |
| 243 ComponentExtensionIMEManagerImpl::ComponentExtensionIMEManagerImpl() | 260 ComponentExtensionIMEManagerImpl::ComponentExtensionIMEManagerImpl() { |
| 244 : weak_ptr_factory_(this) { | |
| 245 ReadComponentExtensionsInfo(&component_extension_list_); | 261 ReadComponentExtensionsInfo(&component_extension_list_); |
| 246 } | 262 } |
| 247 | 263 |
| 248 ComponentExtensionIMEManagerImpl::~ComponentExtensionIMEManagerImpl() { | 264 ComponentExtensionIMEManagerImpl::~ComponentExtensionIMEManagerImpl() { |
| 249 } | 265 } |
| 250 | 266 |
| 251 std::vector<ComponentExtensionIME> ComponentExtensionIMEManagerImpl::ListIME() { | 267 std::vector<ComponentExtensionIME> ComponentExtensionIMEManagerImpl::ListIME() { |
| 252 return component_extension_list_; | 268 return component_extension_list_; |
| 253 } | 269 } |
| 254 | 270 |
| 255 bool ComponentExtensionIMEManagerImpl::Load(Profile* profile, | 271 bool ComponentExtensionIMEManagerImpl::Load(Profile* profile, |
| 256 const std::string& extension_id, | 272 const std::string& extension_id, |
| 257 const std::string& manifest, | 273 const std::string& manifest, |
| 258 const base::FilePath& file_path) { | 274 const base::FilePath& file_path) { |
| 259 extensions::ExtensionSystem* extension_system = | 275 extensions::ExtensionSystem* extension_system = |
| 260 extensions::ExtensionSystem::Get(profile); | 276 extensions::ExtensionSystem::Get(profile); |
| 261 ExtensionService* extension_service = extension_system->extension_service(); | 277 ExtensionService* extension_service = extension_system->extension_service(); |
| 262 if (extension_service->GetExtensionById(extension_id, false)) | 278 if (extension_service->GetExtensionById(extension_id, false)) |
| 263 return false; | 279 return false; |
| 280 | |
| 281 // If current environment is linux_chromeos, check the existence of file path | |
| 282 // to avoid unnecessary extension loading and InputMethodEngine creation, so | |
| 283 // that the virtual keyboard web content url won't be override by IME | |
| 284 // component extensions. | |
| 285 if (!base::SysInfo::IsRunningOnChromeOS()) { | |
| 286 bool* exists = new bool; | |
| 287 *exists = false; | |
| 288 base::FilePath* copied_file_path = new base::FilePath(file_path); | |
| 289 | |
| 290 content::BrowserThread::PostTaskAndReply( | |
|
Seigo Nonaka
2014/08/25 02:01:08
Probably, you may want to use PostTaskAndReplyWIth
Shu Chen
2014/08/25 02:31:08
Done.
| |
| 291 content::BrowserThread::FILE, | |
| 292 FROM_HERE, | |
| 293 base::Bind(&CheckFilePath, | |
| 294 base::Unretained(copied_file_path), | |
| 295 base::Unretained(exists)), | |
| 296 base::Bind(&OnFilePathChecked, | |
| 297 base::Unretained(profile), | |
| 298 base::Owned(new std::string(manifest)), | |
| 299 base::Owned(copied_file_path), | |
| 300 base::Owned(exists))); | |
| 301 return false; | |
|
Seigo Nonaka
2014/08/25 02:01:08
is it okay to return false here? Probably at least
Shu Chen
2014/08/25 02:31:08
Done. I've made the return type as void.
| |
| 302 } | |
| 264 const std::string loaded_extension_id = | 303 const std::string loaded_extension_id = |
| 265 GetComponentLoader(profile)->Add(manifest, file_path); | 304 GetComponentLoader(profile)->Add(manifest, file_path); |
| 266 DCHECK_EQ(loaded_extension_id, extension_id); | 305 DCHECK_EQ(loaded_extension_id, extension_id); |
| 267 return true; | 306 return true; |
| 268 } | 307 } |
| 269 | 308 |
| 270 void ComponentExtensionIMEManagerImpl::Unload(Profile* profile, | 309 void ComponentExtensionIMEManagerImpl::Unload(Profile* profile, |
| 271 const std::string& extension_id, | 310 const std::string& extension_id, |
| 272 const base::FilePath& file_path) { | 311 const base::FilePath& file_path) { |
| 273 // Remove(extension_id) does nothing when the extension has already been | 312 // Remove(extension_id) does nothing when the extension has already been |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 | 483 |
| 445 ComponentExtensionEngine engine; | 484 ComponentExtensionEngine engine; |
| 446 ReadEngineComponent(component_ime, *dictionary, &engine); | 485 ReadEngineComponent(component_ime, *dictionary, &engine); |
| 447 component_ime.engines.push_back(engine); | 486 component_ime.engines.push_back(engine); |
| 448 } | 487 } |
| 449 out_imes->push_back(component_ime); | 488 out_imes->push_back(component_ime); |
| 450 } | 489 } |
| 451 } | 490 } |
| 452 | 491 |
| 453 } // namespace chromeos | 492 } // namespace chromeos |
| OLD | NEW |