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

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

Issue 232233003: ozone: Protect X11-specific code in IME support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/chrome_browser_chromeos.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/chromeos/input_method/input_method_engine.h"
11 #include "chrome/browser/chromeos/profiles/profile_helper.h" 10 #include "chrome/browser/chromeos/profiles/profile_helper.h"
12 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/profiles/profile_manager.h" 12 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/common/extensions/api/input_ime.h" 13 #include "chrome/common/extensions/api/input_ime.h"
15 #include "chrome/common/extensions/api/input_ime/input_components_handler.h" 14 #include "chrome/common/extensions/api/input_ime/input_components_handler.h"
16 #include "content/public/browser/notification_details.h" 15 #include "content/public/browser/notification_details.h"
17 #include "content/public/browser/notification_source.h" 16 #include "content/public/browser/notification_source.h"
18 #include "extensions/browser/event_router.h" 17 #include "extensions/browser/event_router.h"
19 #include "extensions/browser/extension_function_registry.h" 18 #include "extensions/browser/extension_function_registry.h"
20 #include "extensions/browser/extension_system.h" 19 #include "extensions/browser/extension_system.h"
21 20
21 #if defined(USE_X11)
22 #include "chrome/browser/chromeos/input_method/input_method_engine.h"
23 #endif
24
22 namespace input_ime = extensions::api::input_ime; 25 namespace input_ime = extensions::api::input_ime;
23 namespace KeyEventHandled = extensions::api::input_ime::KeyEventHandled; 26 namespace KeyEventHandled = extensions::api::input_ime::KeyEventHandled;
24 namespace DeleteSurroundingText = 27 namespace DeleteSurroundingText =
25 extensions::api::input_ime::DeleteSurroundingText; 28 extensions::api::input_ime::DeleteSurroundingText;
26 namespace UpdateMenuItems = extensions::api::input_ime::UpdateMenuItems; 29 namespace UpdateMenuItems = extensions::api::input_ime::UpdateMenuItems;
27 namespace SendKeyEvents = extensions::api::input_ime::SendKeyEvents; 30 namespace SendKeyEvents = extensions::api::input_ime::SendKeyEvents;
28 namespace HideInputView = extensions::api::input_ime::HideInputView; 31 namespace HideInputView = extensions::api::input_ime::HideInputView;
29 namespace SetMenuItems = extensions::api::input_ime::SetMenuItems; 32 namespace SetMenuItems = extensions::api::input_ime::SetMenuItems;
30 namespace SetCursorPosition = extensions::api::input_ime::SetCursorPosition; 33 namespace SetCursorPosition = extensions::api::input_ime::SetCursorPosition;
31 namespace SetCandidates = extensions::api::input_ime::SetCandidates; 34 namespace SetCandidates = extensions::api::input_ime::SetCandidates;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 304
302 } // namespace chromeos 305 } // namespace chromeos
303 306
304 namespace extensions { 307 namespace extensions {
305 308
306 InputImeEventRouter* 309 InputImeEventRouter*
307 InputImeEventRouter::GetInstance() { 310 InputImeEventRouter::GetInstance() {
308 return Singleton<InputImeEventRouter>::get(); 311 return Singleton<InputImeEventRouter>::get();
309 } 312 }
310 313
311 #if defined(OS_CHROMEOS)
312 bool InputImeEventRouter::RegisterIme( 314 bool InputImeEventRouter::RegisterIme(
313 Profile* profile, 315 Profile* profile,
314 const std::string& extension_id, 316 const std::string& extension_id,
315 const extensions::InputComponentInfo& component) { 317 const extensions::InputComponentInfo& component) {
318 #if defined(USE_X11)
316 VLOG(1) << "RegisterIme: " << extension_id << " id: " << component.id; 319 VLOG(1) << "RegisterIme: " << extension_id << " id: " << component.id;
317 320
318 // If the engine exists already, it may be registered with an old profile. 321 // If the engine exists already, it may be registered with an old profile.
319 // So overwrite it with the new engine instance. 322 // So overwrite it with the new engine instance.
320 EngineMap& engine_map = engines_[extension_id]; 323 EngineMap& engine_map = engines_[extension_id];
321 EngineMap::iterator engine_ix = engine_map.find(component.id); 324 EngineMap::iterator engine_ix = engine_map.find(component.id);
322 if (engine_ix != engine_map.end()) { 325 if (engine_ix != engine_map.end()) {
323 delete engine_ix->second; 326 delete engine_ix->second;
324 engine_map.erase(engine_ix); 327 engine_map.erase(engine_ix);
325 } 328 }
(...skipping 16 matching lines...) Expand all
342 component.name.c_str(), 345 component.name.c_str(),
343 extension_id.c_str(), 346 extension_id.c_str(),
344 component.id.c_str(), 347 component.id.c_str(),
345 languages, 348 languages,
346 layouts, 349 layouts,
347 component.options_page_url, 350 component.options_page_url,
348 component.input_view_url); 351 component.input_view_url);
349 engine_map[component.id] = engine; 352 engine_map[component.id] = engine;
350 353
351 return true; 354 return true;
355 #else
356 // TODO(spang): IME support under ozone.
357 NOTIMPLEMENTED();
358 return false;
359 #endif
352 } 360 }
353 361
354 void InputImeEventRouter::UnregisterAllImes( 362 void InputImeEventRouter::UnregisterAllImes(
355 Profile* profile, const std::string& extension_id) { 363 Profile* profile, const std::string& extension_id) {
356 std::map<std::string, EngineMap>::iterator engine_map = 364 std::map<std::string, EngineMap>::iterator engine_map =
357 engines_.find(extension_id); 365 engines_.find(extension_id);
358 if (engine_map != engines_.end()) { 366 if (engine_map != engines_.end()) {
359 STLDeleteContainerPairSecondPointers(engine_map->second.begin(), 367 STLDeleteContainerPairSecondPointers(engine_map->second.begin(),
360 engine_map->second.end()); 368 engine_map->second.end());
361 engines_.erase(engine_map); 369 engines_.erase(engine_map);
362 } 370 }
363 } 371 }
364 #endif
365 372
366 InputMethodEngineInterface* InputImeEventRouter::GetEngine( 373 InputMethodEngineInterface* InputImeEventRouter::GetEngine(
367 const std::string& extension_id, const std::string& engine_id) { 374 const std::string& extension_id, const std::string& engine_id) {
368 std::map<std::string, 375 std::map<std::string,
369 std::map<std::string, InputMethodEngineInterface*> >::const_iterator 376 std::map<std::string, InputMethodEngineInterface*> >::const_iterator
370 engine_list = engines_.find(extension_id); 377 engine_list = engines_.find(extension_id);
371 if (engine_list != engines_.end()) { 378 if (engine_list != engines_.end()) {
372 std::map<std::string, InputMethodEngineInterface*>::const_iterator 379 std::map<std::string, InputMethodEngineInterface*>::const_iterator
373 engine_ix = engine_list->second.find(engine_id); 380 engine_ix = engine_list->second.find(engine_id);
374 if (engine_ix != engine_list->second.end()) 381 if (engine_ix != engine_list->second.end())
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 parent_params->parameters; 542 parent_params->parameters;
536 chromeos::InputMethodEngineInterface* engine = 543 chromeos::InputMethodEngineInterface* engine =
537 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); 544 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id());
538 if (!engine) { 545 if (!engine) {
539 error_ = kErrorEngineNotAvailable; 546 error_ = kErrorEngineNotAvailable;
540 return false; 547 return false;
541 } 548 }
542 549
543 const std::vector<linked_ptr<input_ime::KeyboardEvent> >& key_data = 550 const std::vector<linked_ptr<input_ime::KeyboardEvent> >& key_data =
544 params.key_data; 551 params.key_data;
545 std::vector<chromeos::InputMethodEngine::KeyboardEvent> key_data_out; 552 std::vector<chromeos::InputMethodEngineInterface::KeyboardEvent> key_data_out;
546 553
547 for (size_t i = 0; i < key_data.size(); ++i) { 554 for (size_t i = 0; i < key_data.size(); ++i) {
548 chromeos::InputMethodEngine::KeyboardEvent event; 555 chromeos::InputMethodEngineInterface::KeyboardEvent event;
549 event.type = input_ime::KeyboardEvent::ToString(key_data[i]->type); 556 event.type = input_ime::KeyboardEvent::ToString(key_data[i]->type);
550 event.key = key_data[i]->key; 557 event.key = key_data[i]->key;
551 event.code = key_data[i]->code; 558 event.code = key_data[i]->code;
552 if (key_data[i]->alt_key) 559 if (key_data[i]->alt_key)
553 event.alt_key = *(key_data[i]->alt_key); 560 event.alt_key = *(key_data[i]->alt_key);
554 if (key_data[i]->ctrl_key) 561 if (key_data[i]->ctrl_key)
555 event.ctrl_key = *(key_data[i]->ctrl_key); 562 event.ctrl_key = *(key_data[i]->ctrl_key);
556 if (key_data[i]->shift_key) 563 if (key_data[i]->shift_key)
557 event.shift_key = *(key_data[i]->shift_key); 564 event.shift_key = *(key_data[i]->shift_key);
558 if (key_data[i]->caps_lock) 565 if (key_data[i]->caps_lock)
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 639
633 if (modified) { 640 if (modified) {
634 engine->SetCandidateWindowProperty(properties_out); 641 engine->SetCandidateWindowProperty(properties_out);
635 } 642 }
636 643
637 SetResult(new base::FundamentalValue(true)); 644 SetResult(new base::FundamentalValue(true));
638 645
639 return true; 646 return true;
640 } 647 }
641 648
642 #if defined(OS_CHROMEOS)
643 bool InputImeSetCandidatesFunction::RunImpl() { 649 bool InputImeSetCandidatesFunction::RunImpl() {
644 InputMethodEngineInterface* engine = 650 InputMethodEngineInterface* engine =
645 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); 651 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id());
646 if (!engine) { 652 if (!engine) {
647 SetResult(new base::FundamentalValue(false)); 653 SetResult(new base::FundamentalValue(false));
648 return true; 654 return true;
649 } 655 }
650 656
651 scoped_ptr<SetCandidates::Params> parent_params( 657 scoped_ptr<SetCandidates::Params> parent_params(
652 SetCandidates::Params::Create(*args_)); 658 SetCandidates::Params::Create(*args_));
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 return true; 774 return true;
769 } 775 }
770 776
771 bool InputImeKeyEventHandledFunction::RunImpl() { 777 bool InputImeKeyEventHandledFunction::RunImpl() {
772 scoped_ptr<KeyEventHandled::Params> params( 778 scoped_ptr<KeyEventHandled::Params> params(
773 KeyEventHandled::Params::Create(*args_)); 779 KeyEventHandled::Params::Create(*args_));
774 InputImeEventRouter::GetInstance()->OnKeyEventHandled( 780 InputImeEventRouter::GetInstance()->OnKeyEventHandled(
775 extension_id(), params->request_id, params->response); 781 extension_id(), params->request_id, params->response);
776 return true; 782 return true;
777 } 783 }
778 #endif
779 784
780 InputImeAPI::InputImeAPI(content::BrowserContext* context) 785 InputImeAPI::InputImeAPI(content::BrowserContext* context)
781 : profile_(Profile::FromBrowserContext(context)) { 786 : profile_(Profile::FromBrowserContext(context)) {
782 registrar_.Add(this, 787 registrar_.Add(this,
783 chrome::NOTIFICATION_EXTENSION_LOADED, 788 chrome::NOTIFICATION_EXTENSION_LOADED,
784 content::Source<Profile>(profile_)); 789 content::Source<Profile>(profile_));
785 registrar_.Add(this, 790 registrar_.Add(this,
786 chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, 791 chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
787 content::Source<Profile>(profile_)); 792 content::Source<Profile>(profile_));
788 793
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 input_ime_event_router()->GetActiveEngine(details.extension_id); 843 input_ime_event_router()->GetActiveEngine(details.extension_id);
839 if (engine) 844 if (engine)
840 engine->NotifyImeReady(); 845 engine->NotifyImeReady();
841 } 846 }
842 847
843 InputImeEventRouter* InputImeAPI::input_ime_event_router() { 848 InputImeEventRouter* InputImeAPI::input_ime_event_router() {
844 return InputImeEventRouter::GetInstance(); 849 return InputImeEventRouter::GetInstance();
845 } 850 }
846 851
847 } // namespace extensions 852 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_browser_chromeos.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698