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

Side by Side Diff: chrome/browser/extensions/api/input_ime/input_ime_api_chromeos.cc

Issue 1554983002: Build chrome.input.ime.* API in GN mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/extensions/api/input_ime/input_ime_api.h" 5 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 return "normal"; 279 return "normal";
280 } 280 }
281 281
282 DISALLOW_COPY_AND_ASSIGN(ImeObserverChromeOS); 282 DISALLOW_COPY_AND_ASSIGN(ImeObserverChromeOS);
283 }; 283 };
284 284
285 } // namespace 285 } // namespace
286 286
287 namespace extensions { 287 namespace extensions {
288 288
289 InputImeEventRouter::InputImeEventRouter(Profile* profile)
290 : InputImeEventRouterBase(profile) {}
291
292 InputImeEventRouter::~InputImeEventRouter() {}
293
289 bool InputImeEventRouter::RegisterImeExtension( 294 bool InputImeEventRouter::RegisterImeExtension(
290 const std::string& extension_id, 295 const std::string& extension_id,
291 const std::vector<extensions::InputComponentInfo>& input_components) { 296 const std::vector<extensions::InputComponentInfo>& input_components) {
292 VLOG(1) << "RegisterImeExtension: " << extension_id; 297 VLOG(1) << "RegisterImeExtension: " << extension_id;
293 298
294 if (engine_map_[extension_id]) 299 if (engine_map_[extension_id])
295 return false; 300 return false;
296 301
297 chromeos::input_method::InputMethodManager* manager = 302 chromeos::input_method::InputMethodManager* manager =
298 chromeos::input_method::InputMethodManager::Get(); 303 chromeos::input_method::InputMethodManager::Get();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 engine_map_.find(extension_id); 352 engine_map_.find(extension_id);
348 if (it != engine_map_.end()) { 353 if (it != engine_map_.end()) {
349 chromeos::input_method::InputMethodManager::Get() 354 chromeos::input_method::InputMethodManager::Get()
350 ->GetActiveIMEState() 355 ->GetActiveIMEState()
351 ->RemoveInputMethodExtension(extension_id); 356 ->RemoveInputMethodExtension(extension_id);
352 delete it->second; 357 delete it->second;
353 engine_map_.erase(it); 358 engine_map_.erase(it);
354 } 359 }
355 } 360 }
356 361
362 IMEEngineHandlerInterface* InputImeEventRouter::GetEngine(
363 const std::string& extension_id,
364 const std::string& component_id) {
365 std::map<std::string, IMEEngineHandlerInterface*>::iterator it =
366 engine_map_.find(extension_id);
367 if (it != engine_map_.end())
368 return it->second;
369 return NULL;
370 }
371
372 IMEEngineHandlerInterface* InputImeEventRouter::GetActiveEngine(
373 const std::string& extension_id) {
374 std::map<std::string, IMEEngineHandlerInterface*>::iterator it =
375 engine_map_.find(extension_id);
376 if (it != engine_map_.end() && it->second->IsActive())
377 return it->second;
378 return NULL;
379 }
380
357 bool InputImeSetCompositionFunction::RunSync() { 381 bool InputImeSetCompositionFunction::RunSync() {
358 IMEEngineHandlerInterface* engine = 382 IMEEngineHandlerInterface* engine =
359 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) 383 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context()))
360 ->GetActiveEngine(extension_id()); 384 ->GetActiveEngine(extension_id());
361 if (!engine) { 385 if (!engine) {
362 SetResult(new base::FundamentalValue(false)); 386 SetResult(new base::FundamentalValue(false));
363 return true; 387 return true;
364 } 388 }
365 389
366 scoped_ptr<SetComposition::Params> parent_params( 390 scoped_ptr<SetComposition::Params> parent_params(
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 if (!engine) { 709 if (!engine) {
686 error_ = kErrorEngineNotAvailable; 710 error_ = kErrorEngineNotAvailable;
687 return false; 711 return false;
688 } 712 }
689 713
690 engine->DeleteSurroundingText(params.context_id, params.offset, params.length, 714 engine->DeleteSurroundingText(params.context_id, params.offset, params.length,
691 &error_); 715 &error_);
692 return true; 716 return true;
693 } 717 }
694 718
719 void InputImeAPI::OnExtensionLoaded(content::BrowserContext* browser_context,
720 const Extension* extension) {
721 const std::vector<InputComponentInfo>* input_components =
722 extensions::InputComponents::GetInputComponents(extension);
723 if (input_components)
724 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context))
725 ->RegisterImeExtension(extension->id(), *input_components);
726 }
727
728 void InputImeAPI::OnExtensionUnloaded(content::BrowserContext* browser_context,
729 const Extension* extension,
730 UnloadedExtensionInfo::Reason reason) {
731 const std::vector<InputComponentInfo>* input_components =
732 extensions::InputComponents::GetInputComponents(extension);
733 if (!input_components)
734 return;
735 if (input_components->size() > 0) {
736 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context))
737 ->UnregisterAllImes(extension->id());
738 }
739 }
740
741 void InputImeAPI::OnListenerAdded(const EventListenerInfo& details) {
742 if (!details.browser_context)
743 return;
744 IMEEngineHandlerInterface* engine =
745 GetInputImeEventRouter(
746 Profile::FromBrowserContext(details.browser_context))
747 ->GetActiveEngine(details.extension_id);
748 // Notifies the IME extension for IME ready with onActivate/onFocus events.
749 if (engine)
750 engine->Enable(engine->GetActiveComponentId());
751 }
752
695 } // namespace extensions 753 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698