| 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 "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "chrome/browser/extensions/component_loader.h" | 9 #include "chrome/browser/extensions/component_loader.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 bool ComponentExtensionIMEManagerImpl::Unload(const std::string& extension_id, | 128 bool ComponentExtensionIMEManagerImpl::Unload(const std::string& extension_id, |
| 129 const base::FilePath& file_path) { | 129 const base::FilePath& file_path) { |
| 130 DCHECK(thread_checker_.CalledOnValidThread()); | 130 DCHECK(thread_checker_.CalledOnValidThread()); |
| 131 if (loaded_extension_id_.find(extension_id) == loaded_extension_id_.end()) | 131 if (loaded_extension_id_.find(extension_id) == loaded_extension_id_.end()) |
| 132 return false; | 132 return false; |
| 133 GetComponentLoader()->Remove(extension_id); | 133 GetComponentLoader()->Remove(extension_id); |
| 134 loaded_extension_id_.erase(extension_id); | 134 loaded_extension_id_.erase(extension_id); |
| 135 return true; | 135 return true; |
| 136 } | 136 } |
| 137 | 137 |
| 138 scoped_ptr<DictionaryValue> ComponentExtensionIMEManagerImpl::GetManifest( | 138 scoped_ptr<base::DictionaryValue> ComponentExtensionIMEManagerImpl::GetManifest( |
| 139 const base::FilePath& file_path) { | 139 const base::FilePath& file_path) { |
| 140 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 140 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
| 141 std::string error; | 141 std::string error; |
| 142 scoped_ptr<DictionaryValue> manifest( | 142 scoped_ptr<base::DictionaryValue> manifest( |
| 143 extension_file_util::LoadManifest(file_path, &error)); | 143 extension_file_util::LoadManifest(file_path, &error)); |
| 144 if (!manifest.get()) | 144 if (!manifest.get()) |
| 145 LOG(ERROR) << "Failed at getting manifest"; | 145 LOG(ERROR) << "Failed at getting manifest"; |
| 146 if (!extension_l10n_util::LocalizeExtension(file_path, | 146 if (!extension_l10n_util::LocalizeExtension(file_path, |
| 147 manifest.get(), | 147 manifest.get(), |
| 148 &error)) | 148 &error)) |
| 149 LOG(ERROR) << "Localization failed"; | 149 LOG(ERROR) << "Localization failed"; |
| 150 | 150 |
| 151 return manifest.Pass(); | 151 return manifest.Pass(); |
| 152 } | 152 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 169 base::Owned(component_extension_ime_list), | 169 base::Owned(component_extension_ime_list), |
| 170 callback)); | 170 callback)); |
| 171 } | 171 } |
| 172 | 172 |
| 173 bool ComponentExtensionIMEManagerImpl::IsInitialized() { | 173 bool ComponentExtensionIMEManagerImpl::IsInitialized() { |
| 174 return is_initialized_; | 174 return is_initialized_; |
| 175 } | 175 } |
| 176 | 176 |
| 177 // static | 177 // static |
| 178 bool ComponentExtensionIMEManagerImpl::ReadEngineComponent( | 178 bool ComponentExtensionIMEManagerImpl::ReadEngineComponent( |
| 179 const DictionaryValue& dict, | 179 const base::DictionaryValue& dict, |
| 180 ComponentExtensionEngine* out) { | 180 ComponentExtensionEngine* out) { |
| 181 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 181 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
| 182 DCHECK(out); | 182 DCHECK(out); |
| 183 std::string type; | 183 std::string type; |
| 184 if (!dict.GetString(extensions::manifest_keys::kType, &type)) | 184 if (!dict.GetString(extensions::manifest_keys::kType, &type)) |
| 185 return false; | 185 return false; |
| 186 if (type != "ime") | 186 if (type != "ime") |
| 187 return false; | 187 return false; |
| 188 if (!dict.GetString(extensions::manifest_keys::kId, &out->engine_id)) | 188 if (!dict.GetString(extensions::manifest_keys::kId, &out->engine_id)) |
| 189 return false; | 189 return false; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 203 for (size_t j = 0; j < language_list->GetSize(); ++j) { | 203 for (size_t j = 0; j < language_list->GetSize(); ++j) { |
| 204 std::string language_str; | 204 std::string language_str; |
| 205 if (language_list->GetString(j, &language_str)) | 205 if (language_list->GetString(j, &language_str)) |
| 206 languages.insert(language_str); | 206 languages.insert(language_str); |
| 207 } | 207 } |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 DCHECK(!languages.empty()); | 210 DCHECK(!languages.empty()); |
| 211 out->language_codes.assign(languages.begin(), languages.end()); | 211 out->language_codes.assign(languages.begin(), languages.end()); |
| 212 | 212 |
| 213 const ListValue* layouts = NULL; | 213 const base::ListValue* layouts = NULL; |
| 214 if (!dict.GetList(extensions::manifest_keys::kLayouts, &layouts)) | 214 if (!dict.GetList(extensions::manifest_keys::kLayouts, &layouts)) |
| 215 return false; | 215 return false; |
| 216 | 216 |
| 217 for (size_t i = 0; i < layouts->GetSize(); ++i) { | 217 for (size_t i = 0; i < layouts->GetSize(); ++i) { |
| 218 std::string buffer; | 218 std::string buffer; |
| 219 if (layouts->GetString(i, &buffer)) | 219 if (layouts->GetString(i, &buffer)) |
| 220 out->layouts.push_back(buffer); | 220 out->layouts.push_back(buffer); |
| 221 } | 221 } |
| 222 return true; | 222 return true; |
| 223 } | 223 } |
| 224 | 224 |
| 225 // static | 225 // static |
| 226 bool ComponentExtensionIMEManagerImpl::ReadExtensionInfo( | 226 bool ComponentExtensionIMEManagerImpl::ReadExtensionInfo( |
| 227 const DictionaryValue& manifest, | 227 const base::DictionaryValue& manifest, |
| 228 const std::string& extension_id, | 228 const std::string& extension_id, |
| 229 ComponentExtensionIME* out) { | 229 ComponentExtensionIME* out) { |
| 230 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 230 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
| 231 if (!manifest.GetString(extensions::manifest_keys::kDescription, | 231 if (!manifest.GetString(extensions::manifest_keys::kDescription, |
| 232 &out->description)) | 232 &out->description)) |
| 233 return false; | 233 return false; |
| 234 std::string url_string; | 234 std::string url_string; |
| 235 if (manifest.GetString(extensions::manifest_keys::kOptionsPage, | 235 if (manifest.GetString(extensions::manifest_keys::kOptionsPage, |
| 236 &url_string)) { | 236 &url_string)) { |
| 237 GURL url = extensions::Extension::GetResourceURL( | 237 GURL url = extensions::Extension::GetResourceURL( |
| (...skipping 29 matching lines...) Expand all Loading... |
| 267 const base::FilePath manifest_path = | 267 const base::FilePath manifest_path = |
| 268 component_ime.path.Append("manifest.json"); | 268 component_ime.path.Append("manifest.json"); |
| 269 | 269 |
| 270 if (!base::PathExists(component_ime.path) || | 270 if (!base::PathExists(component_ime.path) || |
| 271 !base::PathExists(manifest_path)) | 271 !base::PathExists(manifest_path)) |
| 272 continue; | 272 continue; |
| 273 | 273 |
| 274 if (!base::ReadFileToString(manifest_path, &component_ime.manifest)) | 274 if (!base::ReadFileToString(manifest_path, &component_ime.manifest)) |
| 275 continue; | 275 continue; |
| 276 | 276 |
| 277 scoped_ptr<DictionaryValue> manifest = GetManifest(component_ime.path); | 277 scoped_ptr<base::DictionaryValue> manifest = |
| 278 GetManifest(component_ime.path); |
| 278 if (!manifest.get()) | 279 if (!manifest.get()) |
| 279 continue; | 280 continue; |
| 280 | 281 |
| 281 if (!ReadExtensionInfo(*manifest.get(), | 282 if (!ReadExtensionInfo(*manifest.get(), |
| 282 whitelisted_component_extension[i].id, | 283 whitelisted_component_extension[i].id, |
| 283 &component_ime)) | 284 &component_ime)) |
| 284 continue; | 285 continue; |
| 285 component_ime.id = whitelisted_component_extension[i].id; | 286 component_ime.id = whitelisted_component_extension[i].id; |
| 286 | 287 |
| 287 const ListValue* component_list; | 288 const base::ListValue* component_list; |
| 288 if (!manifest->GetList(extensions::manifest_keys::kInputComponents, | 289 if (!manifest->GetList(extensions::manifest_keys::kInputComponents, |
| 289 &component_list)) | 290 &component_list)) |
| 290 continue; | 291 continue; |
| 291 | 292 |
| 292 for (size_t i = 0; i < component_list->GetSize(); ++i) { | 293 for (size_t i = 0; i < component_list->GetSize(); ++i) { |
| 293 const DictionaryValue* dictionary; | 294 const base::DictionaryValue* dictionary; |
| 294 if (!component_list->GetDictionary(i, &dictionary)) | 295 if (!component_list->GetDictionary(i, &dictionary)) |
| 295 continue; | 296 continue; |
| 296 | 297 |
| 297 ComponentExtensionEngine engine; | 298 ComponentExtensionEngine engine; |
| 298 ReadEngineComponent(*dictionary, &engine); | 299 ReadEngineComponent(*dictionary, &engine); |
| 299 component_ime.engines.push_back(engine); | 300 component_ime.engines.push_back(engine); |
| 300 } | 301 } |
| 301 out_imes->push_back(component_ime); | 302 out_imes->push_back(component_ime); |
| 302 } | 303 } |
| 303 } | 304 } |
| 304 | 305 |
| 305 void ComponentExtensionIMEManagerImpl::OnReadComponentExtensionsInfo( | 306 void ComponentExtensionIMEManagerImpl::OnReadComponentExtensionsInfo( |
| 306 std::vector<ComponentExtensionIME>* result, | 307 std::vector<ComponentExtensionIME>* result, |
| 307 const base::Closure& callback) { | 308 const base::Closure& callback) { |
| 308 DCHECK(thread_checker_.CalledOnValidThread()); | 309 DCHECK(thread_checker_.CalledOnValidThread()); |
| 309 DCHECK(result); | 310 DCHECK(result); |
| 310 component_extension_list_ = *result; | 311 component_extension_list_ = *result; |
| 311 is_initialized_ = true; | 312 is_initialized_ = true; |
| 312 callback.Run(); | 313 callback.Run(); |
| 313 } | 314 } |
| 314 | 315 |
| 315 } // namespace chromeos | 316 } // namespace chromeos |
| OLD | NEW |