| OLD | NEW |
| 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 20 matching lines...) Expand all Loading... |
| 31 namespace HideInputView = extensions::api::input_ime::HideInputView; | 31 namespace HideInputView = extensions::api::input_ime::HideInputView; |
| 32 namespace SetMenuItems = extensions::api::input_ime::SetMenuItems; | 32 namespace SetMenuItems = extensions::api::input_ime::SetMenuItems; |
| 33 namespace SetCursorPosition = extensions::api::input_ime::SetCursorPosition; | 33 namespace SetCursorPosition = extensions::api::input_ime::SetCursorPosition; |
| 34 namespace SetCandidates = extensions::api::input_ime::SetCandidates; | 34 namespace SetCandidates = extensions::api::input_ime::SetCandidates; |
| 35 namespace SetCandidateWindowProperties = | 35 namespace SetCandidateWindowProperties = |
| 36 extensions::api::input_ime::SetCandidateWindowProperties; | 36 extensions::api::input_ime::SetCandidateWindowProperties; |
| 37 namespace CommitText = extensions::api::input_ime::CommitText; | 37 namespace CommitText = extensions::api::input_ime::CommitText; |
| 38 namespace ClearComposition = extensions::api::input_ime::ClearComposition; | 38 namespace ClearComposition = extensions::api::input_ime::ClearComposition; |
| 39 namespace SetComposition = extensions::api::input_ime::SetComposition; | 39 namespace SetComposition = extensions::api::input_ime::SetComposition; |
| 40 using ui::IMEEngineHandlerInterface; | 40 using ui::IMEEngineHandlerInterface; |
| 41 using input_method::InputMethodEngineBase; |
| 42 using chromeos::InputMethodEngine; |
| 41 | 43 |
| 42 namespace { | 44 namespace { |
| 43 const char kErrorEngineNotAvailable[] = "Engine is not available"; | 45 const char kErrorEngineNotAvailable[] = "Engine is not available"; |
| 44 const char kErrorSetMenuItemsFail[] = "Could not create menu Items"; | 46 const char kErrorSetMenuItemsFail[] = "Could not create menu Items"; |
| 45 const char kErrorUpdateMenuItemsFail[] = "Could not update menu Items"; | 47 const char kErrorUpdateMenuItemsFail[] = "Could not update menu Items"; |
| 46 const char kOnCompositionBoundsChangedEventName[] = | 48 const char kOnCompositionBoundsChangedEventName[] = |
| 47 "inputMethodPrivate.onCompositionBoundsChanged"; | 49 "inputMethodPrivate.onCompositionBoundsChanged"; |
| 48 | 50 |
| 49 void SetMenuItemToMenu(const input_ime::MenuItem& input, | 51 void SetMenuItemToMenu(const input_ime::MenuItem& input, |
| 50 IMEEngineHandlerInterface::MenuItem* out) { | 52 InputMethodEngine::MenuItem* out) { |
| 51 out->modified = 0; | 53 out->modified = 0; |
| 52 out->id = input.id; | 54 out->id = input.id; |
| 53 if (input.label) { | 55 if (input.label) { |
| 54 out->modified |= IMEEngineHandlerInterface::MENU_ITEM_MODIFIED_LABEL; | 56 out->modified |= InputMethodEngine::MENU_ITEM_MODIFIED_LABEL; |
| 55 out->label = *input.label; | 57 out->label = *input.label; |
| 56 } | 58 } |
| 57 | 59 |
| 58 if (input.style != input_ime::MENU_ITEM_STYLE_NONE) { | 60 if (input.style != input_ime::MENU_ITEM_STYLE_NONE) { |
| 59 out->modified |= IMEEngineHandlerInterface::MENU_ITEM_MODIFIED_STYLE; | 61 out->modified |= InputMethodEngine::MENU_ITEM_MODIFIED_STYLE; |
| 60 out->style = | 62 out->style = static_cast<InputMethodEngine::MenuItemStyle>(input.style); |
| 61 static_cast<IMEEngineHandlerInterface::MenuItemStyle>(input.style); | |
| 62 } | 63 } |
| 63 | 64 |
| 64 if (input.visible) | 65 if (input.visible) |
| 65 out->modified |= IMEEngineHandlerInterface::MENU_ITEM_MODIFIED_VISIBLE; | 66 out->modified |= InputMethodEngine::MENU_ITEM_MODIFIED_VISIBLE; |
| 66 out->visible = input.visible ? *input.visible : true; | 67 out->visible = input.visible ? *input.visible : true; |
| 67 | 68 |
| 68 if (input.checked) | 69 if (input.checked) |
| 69 out->modified |= IMEEngineHandlerInterface::MENU_ITEM_MODIFIED_CHECKED; | 70 out->modified |= InputMethodEngine::MENU_ITEM_MODIFIED_CHECKED; |
| 70 out->checked = input.checked ? *input.checked : false; | 71 out->checked = input.checked ? *input.checked : false; |
| 71 | 72 |
| 72 if (input.enabled) | 73 if (input.enabled) |
| 73 out->modified |= IMEEngineHandlerInterface::MENU_ITEM_MODIFIED_ENABLED; | 74 out->modified |= InputMethodEngine::MENU_ITEM_MODIFIED_ENABLED; |
| 74 out->enabled = input.enabled ? *input.enabled : true; | 75 out->enabled = input.enabled ? *input.enabled : true; |
| 75 } | 76 } |
| 76 | 77 |
| 77 class ImeObserverChromeOS : public ui::ImeObserver { | 78 class ImeObserverChromeOS : public ui::ImeObserver { |
| 78 public: | 79 public: |
| 79 ImeObserverChromeOS(const std::string& extension_id, Profile* profile) | 80 ImeObserverChromeOS(const std::string& extension_id, Profile* profile) |
| 80 : ImeObserver(extension_id, profile) {} | 81 : ImeObserver(extension_id, profile) {} |
| 81 | 82 |
| 82 ~ImeObserverChromeOS() override {} | 83 ~ImeObserverChromeOS() override {} |
| 83 | 84 |
| 84 // ui::IMEEngineObserver overrides | 85 // input_method::InputMethodEngineBase::Observer overrides. |
| 85 void OnInputContextUpdate( | 86 void OnInputContextUpdate( |
| 86 const IMEEngineHandlerInterface::InputContext& context) override { | 87 const IMEEngineHandlerInterface::InputContext& context) override { |
| 87 if (extension_id_.empty() || | 88 if (extension_id_.empty() || |
| 88 !HasListener(input_ime::OnInputContextUpdate::kEventName)) | 89 !HasListener(input_ime::OnInputContextUpdate::kEventName)) |
| 89 return; | 90 return; |
| 90 | 91 |
| 91 input_ime::InputContext context_value; | 92 input_ime::InputContext context_value; |
| 92 context_value.context_id = context.id; | 93 context_value.context_id = context.id; |
| 93 context_value.type = | 94 context_value.type = |
| 94 input_ime::ParseInputContextType(ConvertInputContextType(context)); | 95 input_ime::ParseInputContextType(ConvertInputContextType(context)); |
| 95 | 96 |
| 96 scoped_ptr<base::ListValue> args( | 97 scoped_ptr<base::ListValue> args( |
| 97 input_ime::OnInputContextUpdate::Create(context_value)); | 98 input_ime::OnInputContextUpdate::Create(context_value)); |
| 98 | 99 |
| 99 DispatchEventToExtension( | 100 DispatchEventToExtension( |
| 100 extensions::events::INPUT_IME_ON_INPUT_CONTEXT_UPDATE, | 101 extensions::events::INPUT_IME_ON_INPUT_CONTEXT_UPDATE, |
| 101 input_ime::OnInputContextUpdate::kEventName, std::move(args)); | 102 input_ime::OnInputContextUpdate::kEventName, std::move(args)); |
| 102 } | 103 } |
| 103 | 104 |
| 104 void OnCandidateClicked( | 105 void OnCandidateClicked( |
| 105 const std::string& component_id, | 106 const std::string& component_id, |
| 106 int candidate_id, | 107 int candidate_id, |
| 107 ui::IMEEngineObserver::MouseButtonEvent button) override { | 108 InputMethodEngineBase::MouseButtonEvent button) override { |
| 108 if (extension_id_.empty() || | 109 if (extension_id_.empty() || |
| 109 !HasListener(input_ime::OnCandidateClicked::kEventName)) | 110 !HasListener(input_ime::OnCandidateClicked::kEventName)) |
| 110 return; | 111 return; |
| 111 | 112 |
| 112 input_ime::MouseButton button_enum = input_ime::MOUSE_BUTTON_NONE; | 113 input_ime::MouseButton button_enum = input_ime::MOUSE_BUTTON_NONE; |
| 113 switch (button) { | 114 switch (button) { |
| 114 case ui::IMEEngineObserver::MOUSE_BUTTON_MIDDLE: | 115 case InputMethodEngineBase::MOUSE_BUTTON_MIDDLE: |
| 115 button_enum = input_ime::MOUSE_BUTTON_MIDDLE; | 116 button_enum = input_ime::MOUSE_BUTTON_MIDDLE; |
| 116 break; | 117 break; |
| 117 | 118 |
| 118 case ui::IMEEngineObserver::MOUSE_BUTTON_RIGHT: | 119 case InputMethodEngineBase::MOUSE_BUTTON_RIGHT: |
| 119 button_enum = input_ime::MOUSE_BUTTON_RIGHT; | 120 button_enum = input_ime::MOUSE_BUTTON_RIGHT; |
| 120 break; | 121 break; |
| 121 | 122 |
| 122 case ui::IMEEngineObserver::MOUSE_BUTTON_LEFT: | 123 case InputMethodEngineBase::MOUSE_BUTTON_LEFT: |
| 123 // Default to left. | 124 // Default to left. |
| 124 default: | 125 default: |
| 125 button_enum = input_ime::MOUSE_BUTTON_LEFT; | 126 button_enum = input_ime::MOUSE_BUTTON_LEFT; |
| 126 break; | 127 break; |
| 127 } | 128 } |
| 128 | 129 |
| 129 scoped_ptr<base::ListValue> args(input_ime::OnCandidateClicked::Create( | 130 scoped_ptr<base::ListValue> args(input_ime::OnCandidateClicked::Create( |
| 130 component_id, candidate_id, button_enum)); | 131 component_id, candidate_id, button_enum)); |
| 131 | 132 |
| 132 DispatchEventToExtension(extensions::events::INPUT_IME_ON_CANDIDATE_CLICKED, | 133 DispatchEventToExtension(extensions::events::INPUT_IME_ON_CANDIDATE_CLICKED, |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 component.name, | 288 component.name, |
| 288 std::string(), // TODO(uekawa): Set short name. | 289 std::string(), // TODO(uekawa): Set short name. |
| 289 layouts, | 290 layouts, |
| 290 languages, | 291 languages, |
| 291 false, // 3rd party IMEs are always not for login. | 292 false, // 3rd party IMEs are always not for login. |
| 292 component.options_page_url, | 293 component.options_page_url, |
| 293 component.input_view_url)); | 294 component.input_view_url)); |
| 294 } | 295 } |
| 295 } | 296 } |
| 296 | 297 |
| 297 scoped_ptr<ui::IMEEngineObserver> observer( | 298 scoped_ptr<InputMethodEngineBase::Observer> observer( |
| 298 new ImeObserverChromeOS(extension_id, profile())); | 299 new ImeObserverChromeOS(extension_id, profile())); |
| 299 chromeos::InputMethodEngine* engine = new chromeos::InputMethodEngine(); | 300 chromeos::InputMethodEngine* engine = new chromeos::InputMethodEngine(); |
| 300 engine->Initialize(std::move(observer), extension_id.c_str(), profile()); | 301 engine->Initialize(std::move(observer), extension_id.c_str(), profile()); |
| 301 engine_map_[extension_id] = engine; | 302 engine_map_[extension_id] = engine; |
| 302 chromeos::UserSessionManager::GetInstance() | 303 chromeos::UserSessionManager::GetInstance() |
| 303 ->GetDefaultIMEState(profile()) | 304 ->GetDefaultIMEState(profile()) |
| 304 ->AddInputMethodExtension(extension_id, descriptors, engine); | 305 ->AddInputMethodExtension(extension_id, descriptors, engine); |
| 305 | 306 |
| 306 return true; | 307 return true; |
| 307 } | 308 } |
| 308 | 309 |
| 309 void InputImeEventRouter::UnregisterAllImes(const std::string& extension_id) { | 310 void InputImeEventRouter::UnregisterAllImes(const std::string& extension_id) { |
| 310 std::map<std::string, IMEEngineHandlerInterface*>::iterator it = | 311 std::map<std::string, InputMethodEngine*>::iterator it = |
| 311 engine_map_.find(extension_id); | 312 engine_map_.find(extension_id); |
| 312 if (it != engine_map_.end()) { | 313 if (it != engine_map_.end()) { |
| 313 chromeos::input_method::InputMethodManager::Get() | 314 chromeos::input_method::InputMethodManager::Get() |
| 314 ->GetActiveIMEState() | 315 ->GetActiveIMEState() |
| 315 ->RemoveInputMethodExtension(extension_id); | 316 ->RemoveInputMethodExtension(extension_id); |
| 316 delete it->second; | 317 delete it->second; |
| 317 engine_map_.erase(it); | 318 engine_map_.erase(it); |
| 318 } | 319 } |
| 319 } | 320 } |
| 320 | 321 |
| 321 IMEEngineHandlerInterface* InputImeEventRouter::GetEngine( | 322 InputMethodEngine* InputImeEventRouter::GetEngine( |
| 322 const std::string& extension_id, | 323 const std::string& extension_id, |
| 323 const std::string& component_id) { | 324 const std::string& component_id) { |
| 324 std::map<std::string, IMEEngineHandlerInterface*>::iterator it = | 325 std::map<std::string, InputMethodEngine*>::iterator it = |
| 325 engine_map_.find(extension_id); | 326 engine_map_.find(extension_id); |
| 326 return (it != engine_map_.end()) ? it->second : nullptr; | 327 return (it != engine_map_.end()) ? it->second : nullptr; |
| 327 } | 328 } |
| 328 | 329 |
| 329 IMEEngineHandlerInterface* InputImeEventRouter::GetActiveEngine( | 330 InputMethodEngine* InputImeEventRouter::GetActiveEngine( |
| 330 const std::string& extension_id) { | 331 const std::string& extension_id) { |
| 331 std::map<std::string, IMEEngineHandlerInterface*>::iterator it = | 332 std::map<std::string, InputMethodEngine*>::iterator it = |
| 332 engine_map_.find(extension_id); | 333 engine_map_.find(extension_id); |
| 333 return (it != engine_map_.end() && it->second->IsActive()) ? it->second | 334 return (it != engine_map_.end() && it->second->IsActive()) ? it->second |
| 334 : nullptr; | 335 : nullptr; |
| 335 } | 336 } |
| 336 | 337 |
| 337 bool InputImeSetCompositionFunction::RunSync() { | 338 bool InputImeSetCompositionFunction::RunSync() { |
| 338 IMEEngineHandlerInterface* engine = | 339 InputMethodEngine* engine = |
| 339 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) | 340 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
| 340 ->GetActiveEngine(extension_id()); | 341 ->GetActiveEngine(extension_id()); |
| 341 if (!engine) { | 342 if (!engine) { |
| 342 SetResult(new base::FundamentalValue(false)); | 343 SetResult(new base::FundamentalValue(false)); |
| 343 return true; | 344 return true; |
| 344 } | 345 } |
| 345 | 346 |
| 346 scoped_ptr<SetComposition::Params> parent_params( | 347 scoped_ptr<SetComposition::Params> parent_params( |
| 347 SetComposition::Params::Create(*args_)); | 348 SetComposition::Params::Create(*args_)); |
| 348 const SetComposition::Params::Parameters& params = parent_params->parameters; | 349 const SetComposition::Params::Parameters& params = parent_params->parameters; |
| 349 std::vector<IMEEngineHandlerInterface::SegmentInfo> segments; | 350 std::vector<InputMethodEngineBase::SegmentInfo> segments; |
| 350 if (params.segments) { | 351 if (params.segments) { |
| 351 const std::vector<linked_ptr< | 352 const std::vector<linked_ptr< |
| 352 SetComposition::Params::Parameters::SegmentsType> >& | 353 SetComposition::Params::Parameters::SegmentsType> >& |
| 353 segments_args = *params.segments; | 354 segments_args = *params.segments; |
| 354 for (size_t i = 0; i < segments_args.size(); ++i) { | 355 for (size_t i = 0; i < segments_args.size(); ++i) { |
| 355 EXTENSION_FUNCTION_VALIDATE( | 356 EXTENSION_FUNCTION_VALIDATE( |
| 356 segments_args[i]->style != | 357 segments_args[i]->style != |
| 357 input_ime::UNDERLINE_STYLE_NONE); | 358 input_ime::UNDERLINE_STYLE_NONE); |
| 358 segments.push_back(IMEEngineHandlerInterface::SegmentInfo()); | 359 segments.push_back(InputMethodEngineBase::SegmentInfo()); |
| 359 segments.back().start = segments_args[i]->start; | 360 segments.back().start = segments_args[i]->start; |
| 360 segments.back().end = segments_args[i]->end; | 361 segments.back().end = segments_args[i]->end; |
| 361 if (segments_args[i]->style == | 362 if (segments_args[i]->style == |
| 362 input_ime::UNDERLINE_STYLE_UNDERLINE) { | 363 input_ime::UNDERLINE_STYLE_UNDERLINE) { |
| 363 segments.back().style = | 364 segments.back().style = InputMethodEngineBase::SEGMENT_STYLE_UNDERLINE; |
| 364 IMEEngineHandlerInterface::SEGMENT_STYLE_UNDERLINE; | |
| 365 } else if (segments_args[i]->style == | 365 } else if (segments_args[i]->style == |
| 366 input_ime::UNDERLINE_STYLE_DOUBLEUNDERLINE) { | 366 input_ime::UNDERLINE_STYLE_DOUBLEUNDERLINE) { |
| 367 segments.back().style = | 367 segments.back().style = |
| 368 IMEEngineHandlerInterface::SEGMENT_STYLE_DOUBLE_UNDERLINE; | 368 InputMethodEngineBase::SEGMENT_STYLE_DOUBLE_UNDERLINE; |
| 369 } else { | 369 } else { |
| 370 segments.back().style = | 370 segments.back().style = |
| 371 IMEEngineHandlerInterface::SEGMENT_STYLE_NO_UNDERLINE; | 371 InputMethodEngineBase::SEGMENT_STYLE_NO_UNDERLINE; |
| 372 } | 372 } |
| 373 } | 373 } |
| 374 } | 374 } |
| 375 | 375 |
| 376 int selection_start = | 376 int selection_start = |
| 377 params.selection_start ? *params.selection_start : params.cursor; | 377 params.selection_start ? *params.selection_start : params.cursor; |
| 378 int selection_end = | 378 int selection_end = |
| 379 params.selection_end ? *params.selection_end : params.cursor; | 379 params.selection_end ? *params.selection_end : params.cursor; |
| 380 | 380 |
| 381 SetResult(new base::FundamentalValue( | 381 SetResult(new base::FundamentalValue( |
| 382 engine->SetComposition(params.context_id, params.text.c_str(), | 382 engine->SetComposition(params.context_id, params.text.c_str(), |
| 383 selection_start, selection_end, params.cursor, | 383 selection_start, selection_end, params.cursor, |
| 384 segments, &error_))); | 384 segments, &error_))); |
| 385 return true; | 385 return true; |
| 386 } | 386 } |
| 387 | 387 |
| 388 bool InputImeClearCompositionFunction::RunSync() { | 388 bool InputImeClearCompositionFunction::RunSync() { |
| 389 IMEEngineHandlerInterface* engine = | 389 InputMethodEngine* engine = |
| 390 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) | 390 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
| 391 ->GetActiveEngine(extension_id()); | 391 ->GetActiveEngine(extension_id()); |
| 392 if (!engine) { | 392 if (!engine) { |
| 393 SetResult(new base::FundamentalValue(false)); | 393 SetResult(new base::FundamentalValue(false)); |
| 394 return true; | 394 return true; |
| 395 } | 395 } |
| 396 | 396 |
| 397 scoped_ptr<ClearComposition::Params> parent_params( | 397 scoped_ptr<ClearComposition::Params> parent_params( |
| 398 ClearComposition::Params::Create(*args_)); | 398 ClearComposition::Params::Create(*args_)); |
| 399 const ClearComposition::Params::Parameters& params = | 399 const ClearComposition::Params::Parameters& params = |
| 400 parent_params->parameters; | 400 parent_params->parameters; |
| 401 | 401 |
| 402 SetResult(new base::FundamentalValue( | 402 SetResult(new base::FundamentalValue( |
| 403 engine->ClearComposition(params.context_id, &error_))); | 403 engine->ClearComposition(params.context_id, &error_))); |
| 404 return true; | 404 return true; |
| 405 } | 405 } |
| 406 | 406 |
| 407 bool InputImeCommitTextFunction::RunSync() { | 407 bool InputImeCommitTextFunction::RunSync() { |
| 408 IMEEngineHandlerInterface* engine = | 408 InputMethodEngine* engine = |
| 409 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) | 409 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
| 410 ->GetActiveEngine(extension_id()); | 410 ->GetActiveEngine(extension_id()); |
| 411 if (!engine) { | 411 if (!engine) { |
| 412 SetResult(new base::FundamentalValue(false)); | 412 SetResult(new base::FundamentalValue(false)); |
| 413 return true; | 413 return true; |
| 414 } | 414 } |
| 415 | 415 |
| 416 scoped_ptr<CommitText::Params> parent_params( | 416 scoped_ptr<CommitText::Params> parent_params( |
| 417 CommitText::Params::Create(*args_)); | 417 CommitText::Params::Create(*args_)); |
| 418 const CommitText::Params::Parameters& params = | 418 const CommitText::Params::Parameters& params = |
| 419 parent_params->parameters; | 419 parent_params->parameters; |
| 420 | 420 |
| 421 SetResult(new base::FundamentalValue( | 421 SetResult(new base::FundamentalValue( |
| 422 engine->CommitText(params.context_id, params.text.c_str(), &error_))); | 422 engine->CommitText(params.context_id, params.text.c_str(), &error_))); |
| 423 return true; | 423 return true; |
| 424 } | 424 } |
| 425 | 425 |
| 426 bool InputImeHideInputViewFunction::RunAsync() { | 426 bool InputImeHideInputViewFunction::RunAsync() { |
| 427 IMEEngineHandlerInterface* engine = | 427 InputMethodEngine* engine = |
| 428 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) | 428 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
| 429 ->GetActiveEngine(extension_id()); | 429 ->GetActiveEngine(extension_id()); |
| 430 if (!engine) { | 430 if (!engine) { |
| 431 return true; | 431 return true; |
| 432 } | 432 } |
| 433 engine->HideInputView(); | 433 engine->HideInputView(); |
| 434 return true; | 434 return true; |
| 435 } | 435 } |
| 436 | 436 |
| 437 bool InputImeSendKeyEventsFunction::RunAsync() { | 437 bool InputImeSendKeyEventsFunction::RunAsync() { |
| 438 scoped_ptr<SendKeyEvents::Params> parent_params( | 438 scoped_ptr<SendKeyEvents::Params> parent_params( |
| 439 SendKeyEvents::Params::Create(*args_)); | 439 SendKeyEvents::Params::Create(*args_)); |
| 440 const SendKeyEvents::Params::Parameters& params = | 440 const SendKeyEvents::Params::Parameters& params = |
| 441 parent_params->parameters; | 441 parent_params->parameters; |
| 442 IMEEngineHandlerInterface* engine = | 442 InputMethodEngine* engine = |
| 443 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) | 443 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
| 444 ->GetActiveEngine(extension_id()); | 444 ->GetActiveEngine(extension_id()); |
| 445 if (!engine) { | 445 if (!engine) { |
| 446 error_ = kErrorEngineNotAvailable; | 446 error_ = kErrorEngineNotAvailable; |
| 447 return false; | 447 return false; |
| 448 } | 448 } |
| 449 | 449 |
| 450 const std::vector<linked_ptr<input_ime::KeyboardEvent> >& key_data = | 450 const std::vector<linked_ptr<input_ime::KeyboardEvent> >& key_data = |
| 451 params.key_data; | 451 params.key_data; |
| 452 std::vector<IMEEngineHandlerInterface::KeyboardEvent> key_data_out; | 452 std::vector<InputMethodEngineBase::KeyboardEvent> key_data_out; |
| 453 | 453 |
| 454 for (size_t i = 0; i < key_data.size(); ++i) { | 454 for (size_t i = 0; i < key_data.size(); ++i) { |
| 455 IMEEngineHandlerInterface::KeyboardEvent event; | 455 InputMethodEngineBase::KeyboardEvent event; |
| 456 event.type = input_ime::ToString(key_data[i]->type); | 456 event.type = input_ime::ToString(key_data[i]->type); |
| 457 event.key = key_data[i]->key; | 457 event.key = key_data[i]->key; |
| 458 event.code = key_data[i]->code; | 458 event.code = key_data[i]->code; |
| 459 event.key_code = key_data[i]->key_code.get() ? *(key_data[i]->key_code) : 0; | 459 event.key_code = key_data[i]->key_code.get() ? *(key_data[i]->key_code) : 0; |
| 460 if (key_data[i]->alt_key) | 460 if (key_data[i]->alt_key) |
| 461 event.alt_key = *(key_data[i]->alt_key); | 461 event.alt_key = *(key_data[i]->alt_key); |
| 462 if (key_data[i]->ctrl_key) | 462 if (key_data[i]->ctrl_key) |
| 463 event.ctrl_key = *(key_data[i]->ctrl_key); | 463 event.ctrl_key = *(key_data[i]->ctrl_key); |
| 464 if (key_data[i]->shift_key) | 464 if (key_data[i]->shift_key) |
| 465 event.shift_key = *(key_data[i]->shift_key); | 465 event.shift_key = *(key_data[i]->shift_key); |
| 466 if (key_data[i]->caps_lock) | 466 if (key_data[i]->caps_lock) |
| 467 event.caps_lock = *(key_data[i]->caps_lock); | 467 event.caps_lock = *(key_data[i]->caps_lock); |
| 468 key_data_out.push_back(event); | 468 key_data_out.push_back(event); |
| 469 } | 469 } |
| 470 | 470 |
| 471 engine->SendKeyEvents(params.context_id, key_data_out); | 471 engine->SendKeyEvents(params.context_id, key_data_out); |
| 472 return true; | 472 return true; |
| 473 } | 473 } |
| 474 | 474 |
| 475 bool InputImeSetCandidateWindowPropertiesFunction::RunSync() { | 475 bool InputImeSetCandidateWindowPropertiesFunction::RunSync() { |
| 476 scoped_ptr<SetCandidateWindowProperties::Params> parent_params( | 476 scoped_ptr<SetCandidateWindowProperties::Params> parent_params( |
| 477 SetCandidateWindowProperties::Params::Create(*args_)); | 477 SetCandidateWindowProperties::Params::Create(*args_)); |
| 478 const SetCandidateWindowProperties::Params::Parameters& | 478 const SetCandidateWindowProperties::Params::Parameters& |
| 479 params = parent_params->parameters; | 479 params = parent_params->parameters; |
| 480 | 480 |
| 481 IMEEngineHandlerInterface* engine = | 481 InputMethodEngine* engine = |
| 482 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) | 482 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
| 483 ->GetEngine(extension_id(), params.engine_id); | 483 ->GetEngine(extension_id(), params.engine_id); |
| 484 if (!engine) { | 484 if (!engine) { |
| 485 SetResult(new base::FundamentalValue(false)); | 485 SetResult(new base::FundamentalValue(false)); |
| 486 return true; | 486 return true; |
| 487 } | 487 } |
| 488 | 488 |
| 489 const SetCandidateWindowProperties::Params::Parameters::Properties& | 489 const SetCandidateWindowProperties::Params::Parameters::Properties& |
| 490 properties = params.properties; | 490 properties = params.properties; |
| 491 | 491 |
| 492 if (properties.visible && | 492 if (properties.visible && |
| 493 !engine->SetCandidateWindowVisible(*properties.visible, &error_)) { | 493 !engine->SetCandidateWindowVisible(*properties.visible, &error_)) { |
| 494 SetResult(new base::FundamentalValue(false)); | 494 SetResult(new base::FundamentalValue(false)); |
| 495 return true; | 495 return true; |
| 496 } | 496 } |
| 497 | 497 |
| 498 IMEEngineHandlerInterface::CandidateWindowProperty properties_out = | 498 InputMethodEngine::CandidateWindowProperty properties_out = |
| 499 engine->GetCandidateWindowProperty(); | 499 engine->GetCandidateWindowProperty(); |
| 500 bool modified = false; | 500 bool modified = false; |
| 501 | 501 |
| 502 if (properties.cursor_visible) { | 502 if (properties.cursor_visible) { |
| 503 properties_out.is_cursor_visible = *properties.cursor_visible; | 503 properties_out.is_cursor_visible = *properties.cursor_visible; |
| 504 modified = true; | 504 modified = true; |
| 505 } | 505 } |
| 506 | 506 |
| 507 if (properties.vertical) { | 507 if (properties.vertical) { |
| 508 properties_out.is_vertical = *properties.vertical; | 508 properties_out.is_vertical = *properties.vertical; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 536 if (modified) { | 536 if (modified) { |
| 537 engine->SetCandidateWindowProperty(properties_out); | 537 engine->SetCandidateWindowProperty(properties_out); |
| 538 } | 538 } |
| 539 | 539 |
| 540 SetResult(new base::FundamentalValue(true)); | 540 SetResult(new base::FundamentalValue(true)); |
| 541 | 541 |
| 542 return true; | 542 return true; |
| 543 } | 543 } |
| 544 | 544 |
| 545 bool InputImeSetCandidatesFunction::RunSync() { | 545 bool InputImeSetCandidatesFunction::RunSync() { |
| 546 IMEEngineHandlerInterface* engine = | 546 InputMethodEngine* engine = |
| 547 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) | 547 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
| 548 ->GetActiveEngine(extension_id()); | 548 ->GetActiveEngine(extension_id()); |
| 549 if (!engine) { | 549 if (!engine) { |
| 550 SetResult(new base::FundamentalValue(false)); | 550 SetResult(new base::FundamentalValue(false)); |
| 551 return true; | 551 return true; |
| 552 } | 552 } |
| 553 | 553 |
| 554 scoped_ptr<SetCandidates::Params> parent_params( | 554 scoped_ptr<SetCandidates::Params> parent_params( |
| 555 SetCandidates::Params::Create(*args_)); | 555 SetCandidates::Params::Create(*args_)); |
| 556 const SetCandidates::Params::Parameters& params = | 556 const SetCandidates::Params::Parameters& params = |
| 557 parent_params->parameters; | 557 parent_params->parameters; |
| 558 | 558 |
| 559 std::vector<IMEEngineHandlerInterface::Candidate> candidates_out; | 559 std::vector<InputMethodEngine::Candidate> candidates_out; |
| 560 const std::vector<linked_ptr< | 560 const std::vector<linked_ptr< |
| 561 SetCandidates::Params::Parameters::CandidatesType> >& candidates_in = | 561 SetCandidates::Params::Parameters::CandidatesType> >& candidates_in = |
| 562 params.candidates; | 562 params.candidates; |
| 563 for (size_t i = 0; i < candidates_in.size(); ++i) { | 563 for (size_t i = 0; i < candidates_in.size(); ++i) { |
| 564 candidates_out.push_back(IMEEngineHandlerInterface::Candidate()); | 564 candidates_out.push_back(InputMethodEngine::Candidate()); |
| 565 candidates_out.back().value = candidates_in[i]->candidate; | 565 candidates_out.back().value = candidates_in[i]->candidate; |
| 566 candidates_out.back().id = candidates_in[i]->id; | 566 candidates_out.back().id = candidates_in[i]->id; |
| 567 if (candidates_in[i]->label) | 567 if (candidates_in[i]->label) |
| 568 candidates_out.back().label = *candidates_in[i]->label; | 568 candidates_out.back().label = *candidates_in[i]->label; |
| 569 if (candidates_in[i]->annotation) | 569 if (candidates_in[i]->annotation) |
| 570 candidates_out.back().annotation = *candidates_in[i]->annotation; | 570 candidates_out.back().annotation = *candidates_in[i]->annotation; |
| 571 if (candidates_in[i]->usage) { | 571 if (candidates_in[i]->usage) { |
| 572 candidates_out.back().usage.title = candidates_in[i]->usage->title; | 572 candidates_out.back().usage.title = candidates_in[i]->usage->title; |
| 573 candidates_out.back().usage.body = candidates_in[i]->usage->body; | 573 candidates_out.back().usage.body = candidates_in[i]->usage->body; |
| 574 } | 574 } |
| 575 } | 575 } |
| 576 | 576 |
| 577 SetResult(new base::FundamentalValue( | 577 SetResult(new base::FundamentalValue( |
| 578 engine->SetCandidates(params.context_id, candidates_out, &error_))); | 578 engine->SetCandidates(params.context_id, candidates_out, &error_))); |
| 579 return true; | 579 return true; |
| 580 } | 580 } |
| 581 | 581 |
| 582 bool InputImeSetCursorPositionFunction::RunSync() { | 582 bool InputImeSetCursorPositionFunction::RunSync() { |
| 583 IMEEngineHandlerInterface* engine = | 583 InputMethodEngine* engine = |
| 584 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) | 584 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
| 585 ->GetActiveEngine(extension_id()); | 585 ->GetActiveEngine(extension_id()); |
| 586 if (!engine) { | 586 if (!engine) { |
| 587 SetResult(new base::FundamentalValue(false)); | 587 SetResult(new base::FundamentalValue(false)); |
| 588 return true; | 588 return true; |
| 589 } | 589 } |
| 590 | 590 |
| 591 scoped_ptr<SetCursorPosition::Params> parent_params( | 591 scoped_ptr<SetCursorPosition::Params> parent_params( |
| 592 SetCursorPosition::Params::Create(*args_)); | 592 SetCursorPosition::Params::Create(*args_)); |
| 593 const SetCursorPosition::Params::Parameters& params = | 593 const SetCursorPosition::Params::Parameters& params = |
| 594 parent_params->parameters; | 594 parent_params->parameters; |
| 595 | 595 |
| 596 SetResult(new base::FundamentalValue( | 596 SetResult(new base::FundamentalValue( |
| 597 engine->SetCursorPosition(params.context_id, params.candidate_id, | 597 engine->SetCursorPosition(params.context_id, params.candidate_id, |
| 598 &error_))); | 598 &error_))); |
| 599 return true; | 599 return true; |
| 600 } | 600 } |
| 601 | 601 |
| 602 bool InputImeSetMenuItemsFunction::RunSync() { | 602 bool InputImeSetMenuItemsFunction::RunSync() { |
| 603 scoped_ptr<SetMenuItems::Params> parent_params( | 603 scoped_ptr<SetMenuItems::Params> parent_params( |
| 604 SetMenuItems::Params::Create(*args_)); | 604 SetMenuItems::Params::Create(*args_)); |
| 605 const SetMenuItems::Params::Parameters& params = | 605 const SetMenuItems::Params::Parameters& params = |
| 606 parent_params->parameters; | 606 parent_params->parameters; |
| 607 | 607 |
| 608 IMEEngineHandlerInterface* engine = | 608 InputMethodEngine* engine = |
| 609 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) | 609 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
| 610 ->GetEngine(extension_id(), params.engine_id); | 610 ->GetEngine(extension_id(), params.engine_id); |
| 611 if (!engine) { | 611 if (!engine) { |
| 612 error_ = kErrorEngineNotAvailable; | 612 error_ = kErrorEngineNotAvailable; |
| 613 return false; | 613 return false; |
| 614 } | 614 } |
| 615 | 615 |
| 616 const std::vector<linked_ptr<input_ime::MenuItem> >& items = params.items; | 616 const std::vector<linked_ptr<input_ime::MenuItem> >& items = params.items; |
| 617 std::vector<IMEEngineHandlerInterface::MenuItem> items_out; | 617 std::vector<InputMethodEngine::MenuItem> items_out; |
| 618 | 618 |
| 619 for (size_t i = 0; i < items.size(); ++i) { | 619 for (size_t i = 0; i < items.size(); ++i) { |
| 620 items_out.push_back(IMEEngineHandlerInterface::MenuItem()); | 620 items_out.push_back(InputMethodEngine::MenuItem()); |
| 621 SetMenuItemToMenu(*items[i], &items_out.back()); | 621 SetMenuItemToMenu(*items[i], &items_out.back()); |
| 622 } | 622 } |
| 623 | 623 |
| 624 if (!engine->SetMenuItems(items_out)) | 624 if (!engine->SetMenuItems(items_out)) |
| 625 error_ = kErrorSetMenuItemsFail; | 625 error_ = kErrorSetMenuItemsFail; |
| 626 return true; | 626 return true; |
| 627 } | 627 } |
| 628 | 628 |
| 629 bool InputImeUpdateMenuItemsFunction::RunSync() { | 629 bool InputImeUpdateMenuItemsFunction::RunSync() { |
| 630 scoped_ptr<UpdateMenuItems::Params> parent_params( | 630 scoped_ptr<UpdateMenuItems::Params> parent_params( |
| 631 UpdateMenuItems::Params::Create(*args_)); | 631 UpdateMenuItems::Params::Create(*args_)); |
| 632 const UpdateMenuItems::Params::Parameters& params = | 632 const UpdateMenuItems::Params::Parameters& params = |
| 633 parent_params->parameters; | 633 parent_params->parameters; |
| 634 | 634 |
| 635 IMEEngineHandlerInterface* engine = | 635 InputMethodEngine* engine = |
| 636 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) | 636 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
| 637 ->GetEngine(extension_id(), params.engine_id); | 637 ->GetEngine(extension_id(), params.engine_id); |
| 638 if (!engine) { | 638 if (!engine) { |
| 639 error_ = kErrorEngineNotAvailable; | 639 error_ = kErrorEngineNotAvailable; |
| 640 return false; | 640 return false; |
| 641 } | 641 } |
| 642 | 642 |
| 643 const std::vector<linked_ptr<input_ime::MenuItem> >& items = params.items; | 643 const std::vector<linked_ptr<input_ime::MenuItem> >& items = params.items; |
| 644 std::vector<IMEEngineHandlerInterface::MenuItem> items_out; | 644 std::vector<InputMethodEngine::MenuItem> items_out; |
| 645 | 645 |
| 646 for (size_t i = 0; i < items.size(); ++i) { | 646 for (size_t i = 0; i < items.size(); ++i) { |
| 647 items_out.push_back(IMEEngineHandlerInterface::MenuItem()); | 647 items_out.push_back(InputMethodEngine::MenuItem()); |
| 648 SetMenuItemToMenu(*items[i], &items_out.back()); | 648 SetMenuItemToMenu(*items[i], &items_out.back()); |
| 649 } | 649 } |
| 650 | 650 |
| 651 if (!engine->UpdateMenuItems(items_out)) | 651 if (!engine->UpdateMenuItems(items_out)) |
| 652 error_ = kErrorUpdateMenuItemsFail; | 652 error_ = kErrorUpdateMenuItemsFail; |
| 653 return true; | 653 return true; |
| 654 } | 654 } |
| 655 | 655 |
| 656 bool InputImeDeleteSurroundingTextFunction::RunSync() { | 656 bool InputImeDeleteSurroundingTextFunction::RunSync() { |
| 657 scoped_ptr<DeleteSurroundingText::Params> parent_params( | 657 scoped_ptr<DeleteSurroundingText::Params> parent_params( |
| 658 DeleteSurroundingText::Params::Create(*args_)); | 658 DeleteSurroundingText::Params::Create(*args_)); |
| 659 const DeleteSurroundingText::Params::Parameters& params = | 659 const DeleteSurroundingText::Params::Parameters& params = |
| 660 parent_params->parameters; | 660 parent_params->parameters; |
| 661 | 661 |
| 662 IMEEngineHandlerInterface* engine = | 662 InputMethodEngine* engine = |
| 663 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) | 663 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
| 664 ->GetEngine(extension_id(), params.engine_id); | 664 ->GetEngine(extension_id(), params.engine_id); |
| 665 if (!engine) { | 665 if (!engine) { |
| 666 error_ = kErrorEngineNotAvailable; | 666 error_ = kErrorEngineNotAvailable; |
| 667 return false; | 667 return false; |
| 668 } | 668 } |
| 669 | 669 |
| 670 engine->DeleteSurroundingText(params.context_id, params.offset, params.length, | 670 engine->DeleteSurroundingText(params.context_id, params.offset, params.length, |
| 671 &error_); | 671 &error_); |
| 672 return true; | 672 return true; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 688 InputComponents::GetInputComponents(extension); | 688 InputComponents::GetInputComponents(extension); |
| 689 if (input_components && !input_components->empty()) { | 689 if (input_components && !input_components->empty()) { |
| 690 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context)) | 690 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context)) |
| 691 ->UnregisterAllImes(extension->id()); | 691 ->UnregisterAllImes(extension->id()); |
| 692 } | 692 } |
| 693 } | 693 } |
| 694 | 694 |
| 695 void InputImeAPI::OnListenerAdded(const EventListenerInfo& details) { | 695 void InputImeAPI::OnListenerAdded(const EventListenerInfo& details) { |
| 696 if (!details.browser_context) | 696 if (!details.browser_context) |
| 697 return; | 697 return; |
| 698 IMEEngineHandlerInterface* engine = | 698 InputMethodEngine* engine = |
| 699 GetInputImeEventRouter( | 699 GetInputImeEventRouter( |
| 700 Profile::FromBrowserContext(details.browser_context)) | 700 Profile::FromBrowserContext(details.browser_context)) |
| 701 ->GetActiveEngine(details.extension_id); | 701 ->GetActiveEngine(details.extension_id); |
| 702 // Notifies the IME extension for IME ready with onActivate/onFocus events. | 702 // Notifies the IME extension for IME ready with onActivate/onFocus events. |
| 703 if (engine) | 703 if (engine) |
| 704 engine->Enable(engine->GetActiveComponentId()); | 704 engine->Enable(engine->GetActiveComponentId()); |
| 705 } | 705 } |
| 706 | 706 |
| 707 } // namespace extensions | 707 } // namespace extensions |
| OLD | NEW |