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

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

Issue 2386823002: [Extensions] Remove ExtensionFunction::SetError() (Closed)
Patch Set: lazyboy's Created 4 years, 2 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 (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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 InputMethodEngineBase* engine = 276 InputMethodEngineBase* engine =
277 event_router ? event_router->GetActiveEngine(extension_id()) : nullptr; 277 event_router ? event_router->GetActiveEngine(extension_id()) : nullptr;
278 if (engine) { 278 if (engine) {
279 engine->KeyEventHandled(extension_id(), params->request_id, 279 engine->KeyEventHandled(extension_id(), params->request_id,
280 params->response); 280 params->response);
281 } 281 }
282 return RespondNow(NoArguments()); 282 return RespondNow(NoArguments());
283 } 283 }
284 284
285 ExtensionFunction::ResponseAction InputImeSetCompositionFunction::Run() { 285 ExtensionFunction::ResponseAction InputImeSetCompositionFunction::Run() {
286 bool success = false;
287 InputImeEventRouter* event_router = 286 InputImeEventRouter* event_router =
288 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())); 287 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context()));
289 InputMethodEngineBase* engine = 288 InputMethodEngineBase* engine =
290 event_router ? event_router->GetActiveEngine(extension_id()) : nullptr; 289 event_router ? event_router->GetActiveEngine(extension_id()) : nullptr;
291 if (engine) { 290 if (engine) {
292 std::unique_ptr<SetComposition::Params> parent_params( 291 std::unique_ptr<SetComposition::Params> parent_params(
293 SetComposition::Params::Create(*args_)); 292 SetComposition::Params::Create(*args_));
294 const SetComposition::Params::Parameters& params = 293 const SetComposition::Params::Parameters& params =
295 parent_params->parameters; 294 parent_params->parameters;
296 std::vector<InputMethodEngineBase::SegmentInfo> segments; 295 std::vector<InputMethodEngineBase::SegmentInfo> segments;
(...skipping 15 matching lines...) Expand all
312 InputMethodEngineBase::SEGMENT_STYLE_NO_UNDERLINE; 311 InputMethodEngineBase::SEGMENT_STYLE_NO_UNDERLINE;
313 } 312 }
314 segments.push_back(segment_info); 313 segments.push_back(segment_info);
315 } 314 }
316 } 315 }
317 int selection_start = 316 int selection_start =
318 params.selection_start ? *params.selection_start : params.cursor; 317 params.selection_start ? *params.selection_start : params.cursor;
319 int selection_end = 318 int selection_end =
320 params.selection_end ? *params.selection_end : params.cursor; 319 params.selection_end ? *params.selection_end : params.cursor;
321 std::string error; 320 std::string error;
322 success = engine->SetComposition(params.context_id, params.text.c_str(), 321 if (!engine->SetComposition(params.context_id, params.text.c_str(),
323 selection_start, selection_end, 322 selection_start, selection_end, params.cursor,
324 params.cursor, segments, &error); 323 segments, &error)) {
325 SetError(error); 324 std::unique_ptr<base::ListValue> results =
325 base::MakeUnique<base::ListValue>();
326 results->Append(base::MakeUnique<base::FundamentalValue>(false));
327 return RespondNow(ErrorWithArguments(std::move(results), error));
328 }
326 } 329 }
327 std::unique_ptr<base::ListValue> output = 330 return RespondNow(
328 SetComposition::Results::Create(success); 331 OneArgument(base::MakeUnique<base::FundamentalValue>(true)));
329 return RespondNow(ArgumentList(std::move(output)));
330 } 332 }
331 333
332 ExtensionFunction::ResponseAction InputImeCommitTextFunction::Run() { 334 ExtensionFunction::ResponseAction InputImeCommitTextFunction::Run() {
333 bool success = false;
334 InputImeEventRouter* event_router = 335 InputImeEventRouter* event_router =
335 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())); 336 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context()));
336 InputMethodEngineBase* engine = 337 InputMethodEngineBase* engine =
337 event_router ? event_router->GetActiveEngine(extension_id()) : nullptr; 338 event_router ? event_router->GetActiveEngine(extension_id()) : nullptr;
338 if (engine) { 339 if (engine) {
339 std::unique_ptr<CommitText::Params> parent_params( 340 std::unique_ptr<CommitText::Params> parent_params(
340 CommitText::Params::Create(*args_)); 341 CommitText::Params::Create(*args_));
341 const CommitText::Params::Parameters& params = parent_params->parameters; 342 const CommitText::Params::Parameters& params = parent_params->parameters;
342 std::string error; 343 std::string error;
343 success = 344 if (!engine->CommitText(params.context_id, params.text.c_str(), &error)) {
344 engine->CommitText(params.context_id, params.text.c_str(), &error); 345 std::unique_ptr<base::ListValue> results =
345 SetError(error); 346 base::MakeUnique<base::ListValue>();
347 results->Append(base::MakeUnique<base::FundamentalValue>(false));
348 return RespondNow(ErrorWithArguments(std::move(results), error));
349 }
346 } 350 }
347 std::unique_ptr<base::ListValue> output = 351 return RespondNow(
348 CommitText::Results::Create(success); 352 OneArgument(base::MakeUnique<base::FundamentalValue>(true)));
349 return RespondNow(ArgumentList(std::move(output)));
350 } 353 }
351 354
352 ExtensionFunction::ResponseAction InputImeSendKeyEventsFunction::Run() { 355 ExtensionFunction::ResponseAction InputImeSendKeyEventsFunction::Run() {
353 InputImeEventRouter* event_router = 356 InputImeEventRouter* event_router =
354 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())); 357 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context()));
355 InputMethodEngineBase* engine = 358 InputMethodEngineBase* engine =
356 event_router ? event_router->GetActiveEngine(extension_id()) : nullptr; 359 event_router ? event_router->GetActiveEngine(extension_id()) : nullptr;
357 if (!engine) 360 if (!engine)
358 return RespondNow(Error(kErrorEngineNotAvailable)); 361 return RespondNow(Error(kErrorEngineNotAvailable));
359 362
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 InputImeEventRouter* GetInputImeEventRouter(Profile* profile) { 417 InputImeEventRouter* GetInputImeEventRouter(Profile* profile) {
415 if (!profile) 418 if (!profile)
416 return nullptr; 419 return nullptr;
417 if (profile->HasOffTheRecordProfile()) 420 if (profile->HasOffTheRecordProfile())
418 profile = profile->GetOffTheRecordProfile(); 421 profile = profile->GetOffTheRecordProfile();
419 return extensions::InputImeEventRouterFactory::GetInstance()->GetRouter( 422 return extensions::InputImeEventRouterFactory::GetInstance()->GetRouter(
420 profile); 423 profile);
421 } 424 }
422 425
423 } // namespace extensions 426 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698