Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(356)

Side by Side Diff: chrome/browser/chromeos/input_method/component_extension_ime_manager_impl.cc

Issue 495593004: Check the IME component extension's availability on linux_chromeos, so that system fallback VK can … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revised per comments. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 current environment is linux_chromeos, check the existence of file path
260 extensions::ExtensionSystem::Get(profile); 291 // to avoid unnecessary extension loading and InputMethodEngine creation, so
261 ExtensionService* extension_service = extension_system->extension_service(); 292 // that the virtual keyboard web content url won't be override by IME
262 if (extension_service->GetExtensionById(extension_id, false)) 293 // component extensions.
263 return false; 294 if (!base::SysInfo::IsRunningOnChromeOS()) {
Seigo Nonaka 2014/08/25 04:43:27 nit: I perfer if (condition) { // doing A } else
Shu Chen 2014/08/25 04:58:06 Done.
264 const std::string loaded_extension_id = 295 base::FilePath* copied_file_path = new base::FilePath(file_path);
265 GetComponentLoader(profile)->Add(manifest, file_path); 296
266 DCHECK_EQ(loaded_extension_id, extension_id); 297 content::BrowserThread::PostTaskAndReplyWithResult(
267 return true; 298 content::BrowserThread::FILE,
299 FROM_HERE,
300 base::Bind(&CheckFilePath,
301 base::Unretained(copied_file_path)),
302 base::Bind(&OnFilePathChecked,
303 base::Unretained(profile),
304 base::Owned(new std::string(extension_id)),
305 base::Owned(new std::string(manifest)),
306 base::Owned(copied_file_path)));
307 } else {
308 DoLoadExtension(profile, extension_id, manifest, file_path);
309 }
268 } 310 }
269 311
270 void ComponentExtensionIMEManagerImpl::Unload(Profile* profile, 312 void ComponentExtensionIMEManagerImpl::Unload(Profile* profile,
271 const std::string& extension_id, 313 const std::string& extension_id,
272 const base::FilePath& file_path) { 314 const base::FilePath& file_path) {
273 // Remove(extension_id) does nothing when the extension has already been 315 // Remove(extension_id) does nothing when the extension has already been
274 // removed or not been registered. 316 // removed or not been registered.
275 GetComponentLoader(profile)->Remove(extension_id); 317 GetComponentLoader(profile)->Remove(extension_id);
276 } 318 }
277 319
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 486
445 ComponentExtensionEngine engine; 487 ComponentExtensionEngine engine;
446 ReadEngineComponent(component_ime, *dictionary, &engine); 488 ReadEngineComponent(component_ime, *dictionary, &engine);
447 component_ime.engines.push_back(engine); 489 component_ime.engines.push_back(engine);
448 } 490 }
449 out_imes->push_back(component_ime); 491 out_imes->push_back(component_ime);
450 } 492 }
451 } 493 }
452 494
453 } // namespace chromeos 495 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698