diff options
7 files changed, 198 insertions, 525 deletions
diff --git a/chrome/browser/extensions/api/input_ime/input_ime_api.cc b/chrome/browser/extensions/api/input_ime/input_ime_api.cc index fc73e16..e14c620 100644 --- a/chrome/browser/extensions/api/input_ime/input_ime_api.cc +++ b/chrome/browser/extensions/api/input_ime/input_ime_api.cc @@ -4,132 +4,66 @@ #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" -#include "base/json/json_writer.h" -#include "base/lazy_instance.h" -#include "base/stl_util.h" #include "base/strings/string_number_conversions.h" #include "base/values.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chromeos/input_method/input_method_engine.h" #include "chrome/browser/extensions/event_router.h" #include "chrome/browser/extensions/extension_function_registry.h" -#include "chrome/browser/extensions/extension_input_module_constants.h" #include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/common/extensions/api/input_ime.h" #include "chrome/common/extensions/api/input_ime/input_components_handler.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_source.h" -namespace keys = extension_input_module_constants; +namespace input_ime = extensions::api::input_ime; +namespace KeyEventHandled = extensions::api::input_ime::KeyEventHandled; +namespace DeleteSurroundingText = + extensions::api::input_ime::DeleteSurroundingText; +namespace UpdateMenuItems = extensions::api::input_ime::UpdateMenuItems; +namespace SetMenuItems = extensions::api::input_ime::SetMenuItems; +namespace SetCursorPosition = extensions::api::input_ime::SetCursorPosition; +namespace SetCandidates = extensions::api::input_ime::SetCandidates; +namespace SetCandidateWindowProperties = + extensions::api::input_ime::SetCandidateWindowProperties; +namespace CommitText = extensions::api::input_ime::CommitText; +namespace ClearComposition = extensions::api::input_ime::ClearComposition; +namespace SetComposition = extensions::api::input_ime::SetComposition; namespace { -const char kStyleNone[] = "none"; -const char kStyleCheck[] = "check"; -const char kStyleRadio[] = "radio"; -const char kStyleSeparator[] = "separator"; -const char kWindowPositionComposition[] = "composition"; - const char kErrorEngineNotAvailable[] = "Engine is not available"; const char kErrorBadCandidateList[] = "Invalid candidate list provided"; const char kErrorSetMenuItemsFail[] = "Could not create menu Items"; const char kErrorUpdateMenuItemsFail[] = "Could not update menu Items"; -bool ReadMenuItems( - base::ListValue* menu_items, - std::vector<chromeos::InputMethodEngine::MenuItem>* output) { - for (size_t i = 0; i < menu_items->GetSize(); ++i) { - base::DictionaryValue* item_dict; - if (!menu_items->GetDictionary(i, &item_dict)) { - return false; - } - - std::string id; - std::string label; - chromeos::InputMethodEngine::MenuItemStyle style = - chromeos::InputMethodEngine::MENU_ITEM_STYLE_NONE; - bool visible = true; - bool enabled = true; - bool checked = false; - std::string icon; - chromeos::InputMethodEngine::KeyboardEvent shortcut_key; - - unsigned int modified = 0; - - if (!item_dict->GetString(keys::kIdKey, &id)) { - return false; - } - - if (item_dict->HasKey(keys::kLabelKey)) { - if (!item_dict->GetString(keys::kLabelKey, &label)) { - return false; - } - modified |= chromeos::InputMethodEngine::MENU_ITEM_MODIFIED_LABEL; - } - if (item_dict->HasKey(keys::kStyleKey)) { - std::string style_string; - if (!item_dict->GetString(keys::kStyleKey, &style_string)) { - return false; - } - - if (style_string == kStyleNone) { - style = chromeos::InputMethodEngine::MENU_ITEM_STYLE_NONE; - } else if (style_string == kStyleCheck) { - style = chromeos::InputMethodEngine::MENU_ITEM_STYLE_CHECK; - } else if (style_string == kStyleRadio) { - style = chromeos::InputMethodEngine::MENU_ITEM_STYLE_RADIO; - } else if (style_string == kStyleSeparator) { - style = chromeos::InputMethodEngine::MENU_ITEM_STYLE_SEPARATOR; - } else { - return false; - } - modified |= chromeos::InputMethodEngine::MENU_ITEM_MODIFIED_STYLE; - } - - if (item_dict->HasKey(keys::kVisibleKey)) { - if (!item_dict->GetBoolean(keys::kVisibleKey, &visible)) { - return false; - } - modified |= chromeos::InputMethodEngine::MENU_ITEM_MODIFIED_VISIBLE; - } - - if (item_dict->HasKey(keys::kCheckedKey)) { - if (!item_dict->GetBoolean(keys::kCheckedKey, &checked)) { - return false; - } - modified |= chromeos::InputMethodEngine::MENU_ITEM_MODIFIED_CHECKED; - } - - if (item_dict->HasKey(keys::kEnabledKey)) { - if (!item_dict->GetBoolean(keys::kEnabledKey, &enabled)) { - return false; - } - modified |= chromeos::InputMethodEngine::MENU_ITEM_MODIFIED_ENABLED; - } +void SetMenuItemToMenu(const input_ime::MenuItem& input, + chromeos::InputMethodEngine::MenuItem* out) { + out->modified = 0; + out->id = input.id; + if (input.label) { + out->modified |= chromeos::InputMethodEngine::MENU_ITEM_MODIFIED_LABEL; + out->label = *input.label; + } - output->push_back(chromeos::InputMethodEngine::MenuItem()); - output->back().id = id; - output->back().label = label; - output->back().style = style; - output->back().visible = visible; - output->back().enabled = enabled; - output->back().checked = checked; + if (input.style != input_ime::MenuItem::STYLE_NONE) { + out->modified |= chromeos::InputMethodEngine::MENU_ITEM_MODIFIED_STYLE; + out->style = static_cast<chromeos::InputMethodEngine::MenuItemStyle>( + input.style); + } - output->back().modified = modified; + if (input.visible) + out->modified |= chromeos::InputMethodEngine::MENU_ITEM_MODIFIED_VISIBLE; + out->visible = input.visible ? *input.visible : true; - if (item_dict->HasKey(keys::kItemsKey)) { - base::ListValue* sub_list; - if (!item_dict->GetList(keys::kItemsKey, &sub_list)) { - return false; - } + if (input.checked) + out->modified |= chromeos::InputMethodEngine::MENU_ITEM_MODIFIED_CHECKED; + out->checked = input.checked ? *input.checked : false; - if (!ReadMenuItems(sub_list, &(output->back().children))) { - return false; - } - } - } - - return true; + if (input.enabled) + out->modified |= chromeos::InputMethodEngine::MENU_ITEM_MODIFIED_ENABLED; + out->enabled = input.enabled ? *input.enabled : true; } static void DispatchEventToExtension(Profile* profile, @@ -367,9 +301,8 @@ bool InputImeEventRouter::RegisterIme( std::map<std::string, chromeos::InputMethodEngine*>::iterator engine_ix = engine_map.find(component.id); - if (engine_ix != engine_map.end()) { + if (engine_ix != engine_map.end()) return false; - } std::string error; chromeos::ImeObserver* observer = new chromeos::ImeObserver(profile, @@ -435,9 +368,8 @@ chromeos::InputMethodEngine* InputImeEventRouter::GetEngine( if (engine_list != engines_.end()) { std::map<std::string, chromeos::InputMethodEngine*>::const_iterator engine_ix = engine_list->second.find(engine_id); - if (engine_ix != engine_list->second.end()) { + if (engine_ix != engine_list->second.end()) return engine_ix->second; - } } return NULL; } @@ -453,9 +385,8 @@ chromeos::InputMethodEngine* InputImeEventRouter::GetActiveEngine( for (engine_ix = engine_list->second.begin(); engine_ix != engine_list->second.end(); ++engine_ix) { - if (engine_ix->second->IsActive()) { + if (engine_ix->second->IsActive()) return engine_ix->second; - } } } return NULL; @@ -509,70 +440,41 @@ bool InputImeSetCompositionFunction::RunImpl() { return true; } - base::DictionaryValue* args; - EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); - int context_id; - std::string text; - int selection_start; - int selection_end; - int cursor; + scoped_ptr<SetComposition::Params> parent_params( + SetComposition::Params::Create(*args_)); + const SetComposition::Params::Parameters& params = parent_params->parameters; std::vector<chromeos::InputMethodEngine::SegmentInfo> segments; - - EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, - &context_id)); - EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kTextKey, &text)); - EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kCursorKey, &cursor)); - if (args->HasKey(keys::kSelectionStartKey)) { - EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kSelectionStartKey, - &selection_start)); - } else { - selection_start = cursor; - } - if (args->HasKey(keys::kSelectionEndKey)) { - EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kSelectionEndKey, - &selection_end)); - } else { - selection_end = cursor; - } - - if (args->HasKey(keys::kSegmentsKey)) { - base::ListValue* segment_list = NULL; - EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kSegmentsKey, - &segment_list)); - - for (size_t i = 0; i < segment_list->GetSize(); ++i) { - base::DictionaryValue* segment = NULL; - if (!segment_list->GetDictionary(i, &segment)) - continue; - - int start; - int end; - std::string style; - - EXTENSION_FUNCTION_VALIDATE(segment->GetInteger(keys::kStartKey, - &start)); - EXTENSION_FUNCTION_VALIDATE(segment->GetInteger(keys::kEndKey, &end)); - EXTENSION_FUNCTION_VALIDATE(segment->GetString(keys::kStyleKey, &style)); - + if (params.segments) { + const std::vector<linked_ptr< + SetComposition::Params::Parameters::SegmentsType> >& + segments_args = *params.segments; + for (size_t i = 0; i < segments_args.size(); ++i) { + EXTENSION_FUNCTION_VALIDATE( + segments_args[i]->style != + SetComposition::Params::Parameters::SegmentsType::STYLE_NONE); segments.push_back(chromeos::InputMethodEngine::SegmentInfo()); - segments.back().start = start; - segments.back().end = end; - if (style == keys::kStyleUnderline) { + segments.back().start = segments_args[i]->start; + segments.back().end = segments_args[i]->end; + if (segments_args[i]->style == + SetComposition::Params::Parameters::SegmentsType::STYLE_UNDERLINE) { segments.back().style = chromeos::InputMethodEngine::SEGMENT_STYLE_UNDERLINE; - } else if (style == keys::kStyleDoubleUnderline) { + } else { segments.back().style = chromeos::InputMethodEngine::SEGMENT_STYLE_DOUBLE_UNDERLINE; } } } - if (engine->SetComposition(context_id, text.c_str(), selection_start, - selection_end, cursor, segments, &error_)) { - SetResult(Value::CreateBooleanValue(true)); - } else { - SetResult(Value::CreateBooleanValue(false)); - } + int selection_start = + params.selection_start ? *params.selection_start : params.cursor; + int selection_end = + params.selection_end ? *params.selection_end : params.cursor; + + SetResult(Value::CreateBooleanValue( + engine->SetComposition(params.context_id, params.text.c_str(), + selection_start, selection_end, params.cursor, + segments, &error_))); return true; } @@ -584,18 +486,13 @@ bool InputImeClearCompositionFunction::RunImpl() { return true; } - base::DictionaryValue* args; - EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); - int context_id; + scoped_ptr<ClearComposition::Params> parent_params( + ClearComposition::Params::Create(*args_)); + const ClearComposition::Params::Parameters& params = + parent_params->parameters; - EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, - &context_id)); - - if (engine->ClearComposition(context_id, &error_)) { - SetResult(Value::CreateBooleanValue(true)); - } else { - SetResult(Value::CreateBooleanValue(false)); - } + SetResult(Value::CreateBooleanValue( + engine->ClearComposition(params.context_id, &error_))); return true; } @@ -608,99 +505,67 @@ bool InputImeCommitTextFunction::RunImpl() { return true; } - base::DictionaryValue* args; - EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); - int context_id; - std::string text; + scoped_ptr<CommitText::Params> parent_params( + CommitText::Params::Create(*args_)); + const CommitText::Params::Parameters& params = + parent_params->parameters; - EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, - &context_id)); - EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kTextKey, &text)); - - if (engine->CommitText(context_id, text.c_str(), &error_)) { - SetResult(Value::CreateBooleanValue(true)); - } else { - SetResult(Value::CreateBooleanValue(false)); - } + SetResult(Value::CreateBooleanValue( + engine->CommitText(params.context_id, params.text.c_str(), &error_))); return true; } bool InputImeSetCandidateWindowPropertiesFunction::RunImpl() { - base::DictionaryValue* args; - EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); - - std::string engine_id; - EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); + scoped_ptr<SetCandidateWindowProperties::Params> parent_params( + SetCandidateWindowProperties::Params::Create(*args_)); + const SetCandidateWindowProperties::Params::Parameters& + params = parent_params->parameters; chromeos::InputMethodEngine* engine = - InputImeEventRouter::GetInstance()->GetEngine(extension_id(), engine_id); + InputImeEventRouter::GetInstance()->GetEngine(extension_id(), + params.engine_id); + if (!engine) { SetResult(Value::CreateBooleanValue(false)); return true; } - base::DictionaryValue* properties; - EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(keys::kPropertiesKey, - &properties)); + const SetCandidateWindowProperties::Params::Parameters::Properties& + properties = params.properties; - if (properties->HasKey(keys::kVisibleKey)) { - bool visible; - EXTENSION_FUNCTION_VALIDATE(properties->GetBoolean(keys::kVisibleKey, - &visible)); - if (!engine->SetCandidateWindowVisible(visible, &error_)) { - SetResult(Value::CreateBooleanValue(false)); - return true; - } + if (properties.visible && + !engine->SetCandidateWindowVisible(*properties.visible, &error_)) { + SetResult(Value::CreateBooleanValue(false)); + return true; } - if (properties->HasKey(keys::kCursorVisibleKey)) { - bool visible; - EXTENSION_FUNCTION_VALIDATE(properties->GetBoolean(keys::kCursorVisibleKey, - &visible)); - engine->SetCandidateWindowCursorVisible(visible); - } + if (properties.cursor_visible) + engine->SetCandidateWindowCursorVisible(*properties.cursor_visible); - if (properties->HasKey(keys::kVerticalKey)) { - bool vertical; - EXTENSION_FUNCTION_VALIDATE(properties->GetBoolean(keys::kVerticalKey, - &vertical)); - engine->SetCandidateWindowVertical(vertical); - } + if (properties.vertical) + engine->SetCandidateWindowVertical(*properties.vertical); - if (properties->HasKey(keys::kPageSizeKey)) { - int page_size; - EXTENSION_FUNCTION_VALIDATE(properties->GetInteger(keys::kPageSizeKey, - &page_size)); - engine->SetCandidateWindowPageSize(page_size); - } + if (properties.page_size) + engine->SetCandidateWindowPageSize(*properties.page_size); - if (properties->HasKey(keys::kAuxiliaryTextKey)) { - std::string aux_text; - EXTENSION_FUNCTION_VALIDATE(properties->GetString(keys::kAuxiliaryTextKey, - &aux_text)); - engine->SetCandidateWindowAuxText(aux_text.c_str()); - } + if (properties.auxiliary_text) + engine->SetCandidateWindowAuxText(properties.auxiliary_text->c_str()); - if (properties->HasKey(keys::kAuxiliaryTextVisibleKey)) { - bool visible; - EXTENSION_FUNCTION_VALIDATE(properties->GetBoolean( - keys::kAuxiliaryTextVisibleKey, - &visible)); - engine->SetCandidateWindowAuxTextVisible(visible); + if (properties.auxiliary_text_visible) { + engine->SetCandidateWindowAuxTextVisible( + *properties.auxiliary_text_visible); } - if (properties->HasKey(keys::kWindowPositionKey)) { - // TODO(nona): Switch to scheme compiler. (crbug.com/235552) - chromeos::InputMethodEngine::CandidateWindowPosition window_position = - chromeos::InputMethodEngine::WINDOW_POS_CURSOR; - std::string position_in_str; - EXTENSION_FUNCTION_VALIDATE(properties->GetString( - keys::kWindowPositionKey, - &position_in_str)); - window_position = (position_in_str == kWindowPositionComposition) ? - chromeos::InputMethodEngine::WINDOW_POS_COMPOSITTION : - chromeos::InputMethodEngine::WINDOW_POS_CURSOR; - engine->SetCandidateWindowPosition(window_position); + if (properties.window_position == + SetCandidateWindowProperties::Params::Parameters::Properties:: + WINDOW_POSITION_COMPOSITION) { + engine->SetCandidateWindowPosition( + chromeos::InputMethodEngine::WINDOW_POS_COMPOSITTION); + } else if (properties.window_position == + SetCandidateWindowProperties::Params::Parameters::Properties:: + WINDOW_POSITION_CURSOR) { + engine->SetCandidateWindowPosition( + chromeos::InputMethodEngine::WINDOW_POS_CURSOR); } SetResult(Value::CreateBooleanValue(true)); @@ -709,64 +574,6 @@ bool InputImeSetCandidateWindowPropertiesFunction::RunImpl() { } #if defined(OS_CHROMEOS) -bool InputImeSetCandidatesFunction::ReadCandidates( - base::ListValue* candidates, - std::vector<chromeos::InputMethodEngine::Candidate>* output) { - for (size_t i = 0; i < candidates->GetSize(); ++i) { - base::DictionaryValue* candidate_dict; - EXTENSION_FUNCTION_VALIDATE(candidates->GetDictionary(i, &candidate_dict)); - - std::string candidate; - int id; - std::string label; - std::string annotation; - chromeos::InputMethodEngine::UsageEntry usage_entry; - - EXTENSION_FUNCTION_VALIDATE(candidate_dict->GetString(keys::kCandidateKey, - &candidate)); - EXTENSION_FUNCTION_VALIDATE(candidate_dict->GetInteger(keys::kIdKey, &id)); - - if (candidate_dict->HasKey(keys::kLabelKey)) { - EXTENSION_FUNCTION_VALIDATE(candidate_dict->GetString(keys::kLabelKey, - &label)); - } - if (candidate_dict->HasKey(keys::kAnnotationKey)) { - EXTENSION_FUNCTION_VALIDATE(candidate_dict->GetString( - keys::kAnnotationKey, - &annotation)); - } - - if (candidate_dict->HasKey(keys::kUsageKey)) { - base::DictionaryValue* usage_dict; - EXTENSION_FUNCTION_VALIDATE(candidate_dict->GetDictionary(keys::kUsageKey, - &usage_dict)); - EXTENSION_FUNCTION_VALIDATE(usage_dict->GetString(keys::kUsageTitleKey, - &usage_entry.title)); - EXTENSION_FUNCTION_VALIDATE(usage_dict->GetString(keys::kUsageBodyKey, - &usage_entry.body)); - } - - output->push_back(chromeos::InputMethodEngine::Candidate()); - output->back().value = candidate; - output->back().id = id; - output->back().label = label; - output->back().annotation = annotation; - output->back().usage = usage_entry; - - if (candidate_dict->HasKey(keys::kCandidatesKey)) { - base::ListValue* sub_list; - EXTENSION_FUNCTION_VALIDATE(candidate_dict->GetList(keys::kCandidatesKey, - &sub_list)); - if (!ReadCandidates(sub_list, &(output->back().candidates))) { - error_ = kErrorBadCandidateList; - return false; - } - } - } - - return true; -} - bool InputImeSetCandidatesFunction::RunImpl() { chromeos::InputMethodEngine* engine = InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); @@ -775,29 +582,31 @@ bool InputImeSetCandidatesFunction::RunImpl() { return true; } - base::DictionaryValue* args; - EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); - - int context_id; - std::vector<chromeos::InputMethodEngine::Candidate> candidates; - - EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, - &context_id)); - - base::ListValue* candidate_list; - EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kCandidatesKey, - &candidate_list)); - if (!ReadCandidates(candidate_list, &candidates)) { - error_ = kErrorBadCandidateList; - return false; + scoped_ptr<SetCandidates::Params> parent_params( + SetCandidates::Params::Create(*args_)); + const SetCandidates::Params::Parameters& params = + parent_params->parameters; + + std::vector<chromeos::InputMethodEngine::Candidate> candidates_out; + const std::vector<linked_ptr< + SetCandidates::Params::Parameters::CandidatesType> >& candidates_in = + params.candidates; + for (size_t i = 0; i < candidates_in.size(); ++i) { + candidates_out.push_back(chromeos::InputMethodEngine::Candidate()); + candidates_out.back().value = candidates_in[i]->candidate; + candidates_out.back().id = candidates_in[i]->id; + if (candidates_in[i]->label) + candidates_out.back().label = *candidates_in[i]->label; + if (candidates_in[i]->annotation) + candidates_out.back().annotation = *candidates_in[i]->annotation; + if (candidates_in[i]->usage) { + candidates_out.back().usage.title = candidates_in[i]->usage->title; + candidates_out.back().usage.body = candidates_in[i]->usage->body; + } } - std::string error; - if (engine->SetCandidates(context_id, candidates, &error_)) { - SetResult(Value::CreateBooleanValue(true)); - } else { - SetResult(Value::CreateBooleanValue(false)); - } + SetResult(Value::CreateBooleanValue( + engine->SetCandidates(params.context_id, candidates_out, &error_))); return true; } @@ -809,112 +618,95 @@ bool InputImeSetCursorPositionFunction::RunImpl() { return true; } - base::DictionaryValue* args; - EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); - int context_id; - int candidate_id; - - EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, - &context_id)); - EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kCandidateIdKey, - &candidate_id)); + scoped_ptr<SetCursorPosition::Params> parent_params( + SetCursorPosition::Params::Create(*args_)); + const SetCursorPosition::Params::Parameters& params = + parent_params->parameters; - if (engine->SetCursorPosition(context_id, candidate_id, &error_)) { - SetResult(Value::CreateBooleanValue(true)); - } else { - SetResult(Value::CreateBooleanValue(false)); - } + SetResult(Value::CreateBooleanValue( + engine->SetCursorPosition(params.context_id, params.candidate_id, + &error_))); return true; } bool InputImeSetMenuItemsFunction::RunImpl() { - base::DictionaryValue* args; - EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); - - std::string engine_id; - EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); + scoped_ptr<SetMenuItems::Params> parent_params( + SetMenuItems::Params::Create(*args_)); + const SetMenuItems::Params::Parameters& params = + parent_params->parameters; chromeos::InputMethodEngine* engine = - InputImeEventRouter::GetInstance()->GetEngine(extension_id(), engine_id); + InputImeEventRouter::GetInstance()->GetEngine(extension_id(), + params.engine_id); if (!engine) { error_ = kErrorEngineNotAvailable; return false; } - base::ListValue* items; - EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kItemsKey, &items)); + const std::vector<linked_ptr<input_ime::MenuItem> >& items = params.items; + std::vector<chromeos::InputMethodEngine::MenuItem> items_out; - std::vector<chromeos::InputMethodEngine::MenuItem> menu_items; - EXTENSION_FUNCTION_VALIDATE(ReadMenuItems(items, &menu_items)); + for (size_t i = 0; i < items.size(); ++i) { + items_out.push_back(chromeos::InputMethodEngine::MenuItem()); + SetMenuItemToMenu(*items[i], &items_out.back()); + } - if (!engine->SetMenuItems(menu_items)) { + if (!engine->SetMenuItems(items_out)) error_ = kErrorSetMenuItemsFail; - } return true; } bool InputImeUpdateMenuItemsFunction::RunImpl() { - base::DictionaryValue* args; - EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); - - std::string engine_id; - EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); + scoped_ptr<UpdateMenuItems::Params> parent_params( + UpdateMenuItems::Params::Create(*args_)); + const UpdateMenuItems::Params::Parameters& params = + parent_params->parameters; chromeos::InputMethodEngine* engine = - InputImeEventRouter::GetInstance()->GetEngine(extension_id(), engine_id); + InputImeEventRouter::GetInstance()->GetEngine(extension_id(), + params.engine_id); if (!engine) { error_ = kErrorEngineNotAvailable; return false; } - base::ListValue* items; - EXTENSION_FUNCTION_VALIDATE(args->GetList(keys::kItemsKey, &items)); + const std::vector<linked_ptr<input_ime::MenuItem> >& items = params.items; + std::vector<chromeos::InputMethodEngine::MenuItem> items_out; - std::vector<chromeos::InputMethodEngine::MenuItem> menu_items; - EXTENSION_FUNCTION_VALIDATE(ReadMenuItems(items, &menu_items)); + for (size_t i = 0; i < items.size(); ++i) { + items_out.push_back(chromeos::InputMethodEngine::MenuItem()); + SetMenuItemToMenu(*items[i], &items_out.back()); + } - if (!engine->UpdateMenuItems(menu_items)) { + if (!engine->UpdateMenuItems(items_out)) error_ = kErrorUpdateMenuItemsFail; - } return true; } bool InputImeDeleteSurroundingTextFunction::RunImpl() { - base::DictionaryValue* args; - EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args)); - - std::string engine_id; - EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id)); + scoped_ptr<DeleteSurroundingText::Params> parent_params( + DeleteSurroundingText::Params::Create(*args_)); + const DeleteSurroundingText::Params::Parameters& params = + parent_params->parameters; chromeos::InputMethodEngine* engine = - InputImeEventRouter::GetInstance()->GetEngine(extension_id(), engine_id); + InputImeEventRouter::GetInstance()->GetEngine(extension_id(), + params.engine_id); if (!engine) { error_ = kErrorEngineNotAvailable; return false; } - int context_id = 0; - int offset = 0; - int length = 0; - EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kContextIdKey, - &context_id)); - EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kOffsetKey, &offset)); - EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kLengthKey, &length)); - - engine->DeleteSurroundingText(context_id, offset, length, &error_); + engine->DeleteSurroundingText(params.context_id, params.offset, params.length, + &error_); return true; } bool InputImeKeyEventHandledFunction::RunImpl() { - std::string request_id_str; - EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &request_id_str)); - - bool handled = false; - EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &handled)); - + scoped_ptr<KeyEventHandled::Params> params( + KeyEventHandled::Params::Create(*args_)); InputImeEventRouter::GetInstance()->OnKeyEventHandled( - extension_id(), request_id_str, handled); - + extension_id(), params->request_id, params->response); return true; } #endif @@ -963,9 +755,8 @@ void InputImeAPI::Observe(int type, extensions::InputComponents::GetInputComponents(extension); if (!input_components) return; - if (input_components->size() > 0) { + if (input_components->size() > 0) input_ime_event_router()->UnregisterAllImes(profile_, extension->id()); - } } } diff --git a/chrome/browser/extensions/api/input_ime/input_ime_api.h b/chrome/browser/extensions/api/input_ime/input_ime_api.h index 1e103cc..1eef451 100644 --- a/chrome/browser/extensions/api/input_ime/input_ime_api.h +++ b/chrome/browser/extensions/api/input_ime/input_ime_api.h @@ -126,11 +126,6 @@ class InputImeSetCandidatesFunction : public SyncExtensionFunction { // ExtensionFunction: virtual bool RunImpl() OVERRIDE; - - private: - bool ReadCandidates( - base::ListValue* candidates, - std::vector<chromeos::InputMethodEngine::Candidate>* output); }; class InputImeSetCursorPositionFunction : public SyncExtensionFunction { diff --git a/chrome/browser/extensions/api/streams_private/streams_private_api.cc b/chrome/browser/extensions/api/streams_private/streams_private_api.cc index 1d540a1..61fceb2 100644 --- a/chrome/browser/extensions/api/streams_private/streams_private_api.cc +++ b/chrome/browser/extensions/api/streams_private/streams_private_api.cc @@ -12,7 +12,6 @@ #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/extensions/event_router.h" #include "chrome/browser/extensions/extension_function_registry.h" -#include "chrome/browser/extensions/extension_input_module_constants.h" #include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/extensions/extension_tab_util.h" #include "chrome/browser/profiles/profile.h" @@ -20,8 +19,6 @@ #include "content/public/browser/notification_source.h" #include "content/public/browser/stream_handle.h" -namespace keys = extension_input_module_constants; - namespace events { const char kOnExecuteMimeTypeHandler[] = diff --git a/chrome/browser/extensions/extension_input_module_constants.cc b/chrome/browser/extensions/extension_input_module_constants.cc deleted file mode 100644 index 67fd3a71..0000000 --- a/chrome/browser/extensions/extension_input_module_constants.cc +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/extensions/extension_input_module_constants.h" - -namespace extension_input_module_constants { - -const char kAnnotationKey[] = "annotation"; -const char kAuxiliaryTextKey[] = "auxiliaryText"; -const char kAuxiliaryTextVisibleKey[] = "auxiliaryTextVisible"; -const char kCandidateIdKey[] = "candidateID"; -const char kCandidateKey[] = "candidate"; -const char kCandidatesKey[] = "candidates"; -const char kCheckedKey[] = "checked"; -const char kContextIdKey[] = "contextID"; -const char kCursorKey[] = "cursor"; -const char kCursorVisibleKey[] = "cursorVisible"; -const char kEnabledKey[] = "enabled"; -const char kEndKey[] = "end"; -const char kEngineIdKey[] = "engineID"; -const char kIdKey[] = "id"; -const char kItemsKey[] = "items"; -const char kKeyKey[] = "key"; -const char kLabelKey[] = "label"; -const char kLengthKey[] = "length"; -const char kOffsetKey[] = "offset"; -const char kPageSizeKey[] = "pageSize"; -const char kParentIdKey[] = "parentId"; -const char kPropertiesKey[] = "properties"; -const char kSegmentsKey[] = "segments"; -const char kSelectionEndKey[] = "selectionEnd"; -const char kSelectionStartKey[] = "selectionStart"; -const char kStartKey[] = "start"; -const char kStyleDoubleUnderline[] = "doubleUnderline"; -const char kStyleKey[] = "style"; -const char kStyleUnderline[] = "underline"; -const char kTextKey[] = "text"; -const char kUsageBodyKey[] = "body"; -const char kUsageKey[] = "usage"; -const char kUsageTitleKey[] = "title"; -const char kVerticalKey[] = "vertical"; -const char kVisibleKey[] = "visible"; -const char kWindowPositionKey[] = "windowPosition"; - -} // namespace extension_input_module_constants diff --git a/chrome/browser/extensions/extension_input_module_constants.h b/chrome/browser/extensions/extension_input_module_constants.h deleted file mode 100644 index fb93922..0000000 --- a/chrome/browser/extensions/extension_input_module_constants.h +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Constants used for the input API and the Windows API. - -#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_INPUT_MODULE_CONSTANTS_H_ -#define CHROME_BROWSER_EXTENSIONS_EXTENSION_INPUT_MODULE_CONSTANTS_H_ - -namespace extension_input_module_constants { - -// Keys used in serializing input data & events. -extern const char kAnnotationKey[]; -extern const char kAuxiliaryTextKey[]; -extern const char kAuxiliaryTextVisibleKey[]; -extern const char kCandidateIdKey[]; -extern const char kCandidateKey[]; -extern const char kCandidatesKey[]; -extern const char kCheckedKey[]; -extern const char kContextIdKey[]; -extern const char kCursorKey[]; -extern const char kCursorVisibleKey[]; -extern const char kEnabledKey[]; -extern const char kEndKey[]; -extern const char kEngineIdKey[]; -extern const char kIdKey[]; -extern const char kItemsKey[]; -extern const char kKeyKey[]; -extern const char kLabelKey[]; -extern const char kLengthKey[]; -extern const char kOffsetKey[]; -extern const char kPageSizeKey[]; -extern const char kParentIdKey[]; -extern const char kPropertiesKey[]; -extern const char kSegmentsKey[]; -extern const char kSelectionEndKey[]; -extern const char kSelectionStartKey[]; -extern const char kStartKey[]; -extern const char kStyleDoubleUnderline[]; -extern const char kStyleKey[]; -extern const char kStyleUnderline[]; -extern const char kTextKey[]; -extern const char kUsageBodyKey[]; -extern const char kUsageKey[]; -extern const char kUsageTitleKey[]; -extern const char kVerticalKey[]; -extern const char kVisibleKey[]; -extern const char kWindowPositionKey[]; - -}; // namespace extension_input_module_constants - -#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INPUT_MODULE_CONSTANTS_H_ diff --git a/chrome/chrome_browser_extensions.gypi b/chrome/chrome_browser_extensions.gypi index 36fc4aa..d113225 100644 --- a/chrome/chrome_browser_extensions.gypi +++ b/chrome/chrome_browser_extensions.gypi @@ -597,8 +597,6 @@ 'browser/extensions/extension_info_map.h', 'browser/extensions/extension_infobar_delegate.cc', 'browser/extensions/extension_infobar_delegate.h', - 'browser/extensions/extension_input_module_constants.cc', - 'browser/extensions/extension_input_module_constants.h', 'browser/extensions/extension_install_prompt.cc', 'browser/extensions/extension_install_prompt.h', 'browser/extensions/extension_install_ui.cc', diff --git a/chrome/common/extensions/api/input_ime.json b/chrome/common/extensions/api/input_ime.json index c16f4de..e334946 100644 --- a/chrome/common/extensions/api/input_ime.json +++ b/chrome/common/extensions/api/input_ime.json @@ -31,6 +31,24 @@ "contextID": {"type": "integer", "description": "This is used to specify targets of text field operations. This ID becomes invalid as soon as onBlur is called."}, "type": {"type": "string", "description": "Type of value this text field edits, (Text, Number, Password, etc)", "enum": ["text", "number", "password"]} } + }, + { + "id": "MenuItem", + "type": "object", + "description": "A menu item used by an input method to interact with the user from the language menu.", + "properties": { + "id": {"type": "string", "description": "String that will be passed to callbacks referencing this MenuItem."}, + "label": {"type": "string", "optional": true, "description": "Text displayed in the menu for this item."}, + "style": { + "type": "string", + "optional": true, + "description": "Enum representing if this item is: check, radio, or a separator. Radio buttons between separators are considered grouped.", + "enum": ["check", "radio", "separator"] + }, + "visible": {"type": "boolean", "optional": true, "description": "Indicates this item is visible."}, + "checked": {"type": "boolean", "optional": true, "description": "Indicates this item should be drawn with a check."}, + "enabled": {"type": "boolean", "optional": true, "description": "Indicates this item is enabled."} + } } ], "functions": [ @@ -338,21 +356,7 @@ "description": "MenuItems to add. They will be added in the order they exist in the array.", "type": "array", "items": { - "type": "object", - "description": "A menu item used by an input method to interact with the user from the language menu.", - "properties": { - "id": {"type": "string", "description": "String that will be passed to callbacks referencing this MenuItem."}, - "label": {"type": "string", "optional": true, "description": "Text displayed in the menu for this item."}, - "style": { - "type": "string", - "optional": true, - "description": "Enum representing if this item is: none, check, radio, or a separator. Radio buttons between separators are considered grouped.", - "enum": ["check", "radio", "separator"] - }, - "visible": {"type": "boolean", "optional": true, "description": "Indicates this item is visible."}, - "checked": {"type": "boolean", "optional": true, "description": "Indicates this item should be drawn with a check."}, - "enabled": {"type": "boolean", "optional": true, "description": "Indicates this item is enabled."} - } + "$ref": "MenuItem" } } } @@ -383,21 +387,7 @@ "description": "Array of MenuItems to update", "type": "array", "items": { - "type": "object", - "description": "A menu item used by an input method to interact with the user from the language menu.", - "properties": { - "id": {"type": "string", "description": "String that will be passed to callbacks referencing this MenuItem."}, - "label": {"type": "string", "optional": true, "description": "Text displayed in the menu for this item."}, - "style": { - "type": "string", - "optional": true, - "description": "Enum representing if this item is: none, check, radio, or a separator. Radio buttons between separators are considered grouped.", - "enum": ["check", "radio", "separator"] - }, - "visible": {"type": "boolean", "optional": true, "description": "Indicates this item is visible."}, - "checked": {"type": "boolean", "optional": true, "description": "Indicates this item should be drawn with a check."}, - "enabled": {"type": "boolean", "optional": true, "description": "Indicates this item is enabled."} - } + "$ref": "MenuItem" } } } |