| OLD | NEW |
| 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/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/common/extensions/api/input_ime.h" | 9 #include "chrome/common/extensions/api/input_ime.h" |
| 10 #include "content/public/browser/notification_registrar.h" | 10 #include "content/public/browser/notification_registrar.h" |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 int selection_start = | 316 int selection_start = |
| 317 params.selection_start ? *params.selection_start : params.cursor; | 317 params.selection_start ? *params.selection_start : params.cursor; |
| 318 int selection_end = | 318 int selection_end = |
| 319 params.selection_end ? *params.selection_end : params.cursor; | 319 params.selection_end ? *params.selection_end : params.cursor; |
| 320 std::string error; | 320 std::string error; |
| 321 if (!engine->SetComposition(params.context_id, params.text.c_str(), | 321 if (!engine->SetComposition(params.context_id, params.text.c_str(), |
| 322 selection_start, selection_end, params.cursor, | 322 selection_start, selection_end, params.cursor, |
| 323 segments, &error)) { | 323 segments, &error)) { |
| 324 std::unique_ptr<base::ListValue> results = | 324 std::unique_ptr<base::ListValue> results = |
| 325 base::MakeUnique<base::ListValue>(); | 325 base::MakeUnique<base::ListValue>(); |
| 326 results->Append(base::MakeUnique<base::FundamentalValue>(false)); | 326 results->Append(base::MakeUnique<base::Value>(false)); |
| 327 return RespondNow(ErrorWithArguments(std::move(results), error)); | 327 return RespondNow(ErrorWithArguments(std::move(results), error)); |
| 328 } | 328 } |
| 329 } | 329 } |
| 330 return RespondNow( | 330 return RespondNow( |
| 331 OneArgument(base::MakeUnique<base::FundamentalValue>(true))); | 331 OneArgument(base::MakeUnique<base::Value>(true))); |
| 332 } | 332 } |
| 333 | 333 |
| 334 ExtensionFunction::ResponseAction InputImeCommitTextFunction::Run() { | 334 ExtensionFunction::ResponseAction InputImeCommitTextFunction::Run() { |
| 335 InputImeEventRouter* event_router = | 335 InputImeEventRouter* event_router = |
| 336 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())); | 336 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())); |
| 337 InputMethodEngineBase* engine = | 337 InputMethodEngineBase* engine = |
| 338 event_router ? event_router->GetActiveEngine(extension_id()) : nullptr; | 338 event_router ? event_router->GetActiveEngine(extension_id()) : nullptr; |
| 339 if (engine) { | 339 if (engine) { |
| 340 std::unique_ptr<CommitText::Params> parent_params( | 340 std::unique_ptr<CommitText::Params> parent_params( |
| 341 CommitText::Params::Create(*args_)); | 341 CommitText::Params::Create(*args_)); |
| 342 const CommitText::Params::Parameters& params = parent_params->parameters; | 342 const CommitText::Params::Parameters& params = parent_params->parameters; |
| 343 std::string error; | 343 std::string error; |
| 344 if (!engine->CommitText(params.context_id, params.text.c_str(), &error)) { | 344 if (!engine->CommitText(params.context_id, params.text.c_str(), &error)) { |
| 345 std::unique_ptr<base::ListValue> results = | 345 std::unique_ptr<base::ListValue> results = |
| 346 base::MakeUnique<base::ListValue>(); | 346 base::MakeUnique<base::ListValue>(); |
| 347 results->Append(base::MakeUnique<base::FundamentalValue>(false)); | 347 results->Append(base::MakeUnique<base::Value>(false)); |
| 348 return RespondNow(ErrorWithArguments(std::move(results), error)); | 348 return RespondNow(ErrorWithArguments(std::move(results), error)); |
| 349 } | 349 } |
| 350 } | 350 } |
| 351 return RespondNow( | 351 return RespondNow( |
| 352 OneArgument(base::MakeUnique<base::FundamentalValue>(true))); | 352 OneArgument(base::MakeUnique<base::Value>(true))); |
| 353 } | 353 } |
| 354 | 354 |
| 355 ExtensionFunction::ResponseAction InputImeSendKeyEventsFunction::Run() { | 355 ExtensionFunction::ResponseAction InputImeSendKeyEventsFunction::Run() { |
| 356 InputImeEventRouter* event_router = | 356 InputImeEventRouter* event_router = |
| 357 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())); | 357 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())); |
| 358 InputMethodEngineBase* engine = | 358 InputMethodEngineBase* engine = |
| 359 event_router ? event_router->GetActiveEngine(extension_id()) : nullptr; | 359 event_router ? event_router->GetActiveEngine(extension_id()) : nullptr; |
| 360 if (!engine) | 360 if (!engine) |
| 361 return RespondNow(Error(kErrorEngineNotAvailable)); | 361 return RespondNow(Error(kErrorEngineNotAvailable)); |
| 362 | 362 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 InputImeEventRouter* GetInputImeEventRouter(Profile* profile) { | 417 InputImeEventRouter* GetInputImeEventRouter(Profile* profile) { |
| 418 if (!profile) | 418 if (!profile) |
| 419 return nullptr; | 419 return nullptr; |
| 420 if (profile->HasOffTheRecordProfile()) | 420 if (profile->HasOffTheRecordProfile()) |
| 421 profile = profile->GetOffTheRecordProfile(); | 421 profile = profile->GetOffTheRecordProfile(); |
| 422 return extensions::InputImeEventRouterFactory::GetInstance()->GetRouter( | 422 return extensions::InputImeEventRouterFactory::GetInstance()->GetRouter( |
| 423 profile); | 423 profile); |
| 424 } | 424 } |
| 425 | 425 |
| 426 } // namespace extensions | 426 } // namespace extensions |
| OLD | NEW |