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 <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 int selection_start = | 333 int selection_start = |
334 params.selection_start ? *params.selection_start : params.cursor; | 334 params.selection_start ? *params.selection_start : params.cursor; |
335 int selection_end = | 335 int selection_end = |
336 params.selection_end ? *params.selection_end : params.cursor; | 336 params.selection_end ? *params.selection_end : params.cursor; |
337 std::string error; | 337 std::string error; |
338 if (!engine->SetComposition(params.context_id, params.text.c_str(), | 338 if (!engine->SetComposition(params.context_id, params.text.c_str(), |
339 selection_start, selection_end, params.cursor, | 339 selection_start, selection_end, params.cursor, |
340 segments, &error)) { | 340 segments, &error)) { |
341 std::unique_ptr<base::ListValue> results = | 341 std::unique_ptr<base::ListValue> results = |
342 base::MakeUnique<base::ListValue>(); | 342 base::MakeUnique<base::ListValue>(); |
343 results->Append(base::MakeUnique<base::FundamentalValue>(false)); | 343 results->Append(base::MakeUnique<base::Value>(false)); |
344 return RespondNow(ErrorWithArguments(std::move(results), error)); | 344 return RespondNow(ErrorWithArguments(std::move(results), error)); |
345 } | 345 } |
346 } | 346 } |
347 return RespondNow( | 347 return RespondNow(OneArgument(base::MakeUnique<base::Value>(true))); |
348 OneArgument(base::MakeUnique<base::FundamentalValue>(true))); | |
349 } | 348 } |
350 | 349 |
351 ExtensionFunction::ResponseAction InputImeCommitTextFunction::Run() { | 350 ExtensionFunction::ResponseAction InputImeCommitTextFunction::Run() { |
352 InputImeEventRouter* event_router = | 351 InputImeEventRouter* event_router = |
353 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())); | 352 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())); |
354 InputMethodEngineBase* engine = | 353 InputMethodEngineBase* engine = |
355 event_router ? event_router->GetActiveEngine(extension_id()) : nullptr; | 354 event_router ? event_router->GetActiveEngine(extension_id()) : nullptr; |
356 if (engine) { | 355 if (engine) { |
357 std::unique_ptr<CommitText::Params> parent_params( | 356 std::unique_ptr<CommitText::Params> parent_params( |
358 CommitText::Params::Create(*args_)); | 357 CommitText::Params::Create(*args_)); |
359 const CommitText::Params::Parameters& params = parent_params->parameters; | 358 const CommitText::Params::Parameters& params = parent_params->parameters; |
360 std::string error; | 359 std::string error; |
361 if (!engine->CommitText(params.context_id, params.text.c_str(), &error)) { | 360 if (!engine->CommitText(params.context_id, params.text.c_str(), &error)) { |
362 std::unique_ptr<base::ListValue> results = | 361 std::unique_ptr<base::ListValue> results = |
363 base::MakeUnique<base::ListValue>(); | 362 base::MakeUnique<base::ListValue>(); |
364 results->Append(base::MakeUnique<base::FundamentalValue>(false)); | 363 results->Append(base::MakeUnique<base::Value>(false)); |
365 return RespondNow(ErrorWithArguments(std::move(results), error)); | 364 return RespondNow(ErrorWithArguments(std::move(results), error)); |
366 } | 365 } |
367 } | 366 } |
368 return RespondNow( | 367 return RespondNow(OneArgument(base::MakeUnique<base::Value>(true))); |
369 OneArgument(base::MakeUnique<base::FundamentalValue>(true))); | |
370 } | 368 } |
371 | 369 |
372 ExtensionFunction::ResponseAction InputImeSendKeyEventsFunction::Run() { | 370 ExtensionFunction::ResponseAction InputImeSendKeyEventsFunction::Run() { |
373 InputImeEventRouter* event_router = | 371 InputImeEventRouter* event_router = |
374 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())); | 372 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())); |
375 InputMethodEngineBase* engine = | 373 InputMethodEngineBase* engine = |
376 event_router ? event_router->GetActiveEngine(extension_id()) : nullptr; | 374 event_router ? event_router->GetActiveEngine(extension_id()) : nullptr; |
377 if (!engine) | 375 if (!engine) |
378 return RespondNow(Error(kErrorEngineNotAvailable)); | 376 return RespondNow(Error(kErrorEngineNotAvailable)); |
379 | 377 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 InputImeEventRouter* GetInputImeEventRouter(Profile* profile) { | 432 InputImeEventRouter* GetInputImeEventRouter(Profile* profile) { |
435 if (!profile) | 433 if (!profile) |
436 return nullptr; | 434 return nullptr; |
437 if (profile->HasOffTheRecordProfile()) | 435 if (profile->HasOffTheRecordProfile()) |
438 profile = profile->GetOffTheRecordProfile(); | 436 profile = profile->GetOffTheRecordProfile(); |
439 return extensions::InputImeEventRouterFactory::GetInstance()->GetRouter( | 437 return extensions::InputImeEventRouterFactory::GetInstance()->GetRouter( |
440 profile); | 438 profile); |
441 } | 439 } |
442 | 440 |
443 } // namespace extensions | 441 } // namespace extensions |
OLD | NEW |