summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/extensions/api/input_ime/input_ime_api.cc27
-rw-r--r--chrome/browser/extensions/api/input_ime/input_ime_api.h11
-rw-r--r--chrome/browser/extensions/extension_function_histogram_value.h1
-rw-r--r--chrome/browser/extensions/extension_input_module_constants.cc2
-rw-r--r--chrome/browser/extensions/extension_input_module_constants.h2
-rw-r--r--chrome/common/extensions/api/input_ime.json37
-rw-r--r--chrome/test/data/extensions/api_test/input_ime/background.js12
7 files changed, 91 insertions, 1 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 248442a..048ed35 100644
--- a/chrome/browser/extensions/api/input_ime/input_ime_api.cc
+++ b/chrome/browser/extensions/api/input_ime/input_ime_api.cc
@@ -844,6 +844,32 @@ bool UpdateMenuItemsFunction::RunImpl() {
return true;
}
+bool DeleteSurroundingTextFunction::RunImpl() {
+ DictionaryValue* args;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &args));
+
+ std::string engine_id;
+ EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kEngineIdKey, &engine_id));
+
+ chromeos::InputMethodEngine* engine =
+ InputImeEventRouter::GetInstance()->GetEngine(extension_id(), 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_);
+ return true;
+}
+
bool KeyEventHandled::RunImpl() {
std::string request_id_str;
EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &request_id_str));
@@ -877,6 +903,7 @@ InputImeAPI::InputImeAPI(Profile* profile)
registry->RegisterFunction<SetCursorPositionFunction>();
registry->RegisterFunction<SetMenuItemsFunction>();
registry->RegisterFunction<UpdateMenuItemsFunction>();
+ registry->RegisterFunction<DeleteSurroundingTextFunction>();
registry->RegisterFunction<KeyEventHandled>();
}
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 8a358e7..7542fa9 100644
--- a/chrome/browser/extensions/api/input_ime/input_ime_api.h
+++ b/chrome/browser/extensions/api/input_ime/input_ime_api.h
@@ -167,6 +167,17 @@ class UpdateMenuItemsFunction : public SyncExtensionFunction {
virtual bool RunImpl() OVERRIDE;
};
+class DeleteSurroundingTextFunction : public SyncExtensionFunction {
+ public:
+ DECLARE_EXTENSION_FUNCTION("input.ime.deleteSurroundingText",
+ INPUT_IME_DELETESURROUNDINGTEXT)
+ protected:
+ virtual ~DeleteSurroundingTextFunction() {}
+
+ // ExtensionFunction:
+ virtual bool RunImpl() OVERRIDE;
+};
+
class KeyEventHandled : public AsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("input.ime.keyEventHandled",
diff --git a/chrome/browser/extensions/extension_function_histogram_value.h b/chrome/browser/extensions/extension_function_histogram_value.h
index 927ae00..4aeb435 100644
--- a/chrome/browser/extensions/extension_function_histogram_value.h
+++ b/chrome/browser/extensions/extension_function_histogram_value.h
@@ -484,6 +484,7 @@ enum HistogramValue {
NETWORKINGPRIVATE_VERIFYANDSIGNDATA,
DEVELOPERPRIVATE_RESTART,
DEVELOPERPRIVATE_ALLOWINCOGNITO,
+ INPUT_IME_DELETESURROUNDINGTEXT,
ENUM_BOUNDARY // Last entry: Add new entries above.
};
diff --git a/chrome/browser/extensions/extension_input_module_constants.cc b/chrome/browser/extensions/extension_input_module_constants.cc
index 7860a8e..a0da10f 100644
--- a/chrome/browser/extensions/extension_input_module_constants.cc
+++ b/chrome/browser/extensions/extension_input_module_constants.cc
@@ -23,6 +23,8 @@ 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";
diff --git a/chrome/browser/extensions/extension_input_module_constants.h b/chrome/browser/extensions/extension_input_module_constants.h
index 78593ed..2a47adc 100644
--- a/chrome/browser/extensions/extension_input_module_constants.h
+++ b/chrome/browser/extensions/extension_input_module_constants.h
@@ -27,6 +27,8 @@ 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[];
diff --git a/chrome/common/extensions/api/input_ime.json b/chrome/common/extensions/api/input_ime.json
index b958852..4c68ccc 100644
--- a/chrome/common/extensions/api/input_ime.json
+++ b/chrome/common/extensions/api/input_ime.json
@@ -404,6 +404,43 @@
]
},
{
+ "name": "deleteSurroundingText",
+ "type": "function",
+ "description": "Deletes the text around the caret.",
+ "parameters": [
+ {
+ "name": "parameters",
+ "type": "object",
+ "properties": {
+ "engineID": {
+ "type": "string",
+ "description": "ID of the engine receiving the event."
+ },
+ "contextID": {
+ "type": "integer",
+ "description": "ID of the context where the surrounding text will be deleted."
+ },
+ "offset": {
+ "type": "integer",
+ "description": "The offset from the caret position where deletion will start. This value can be negative."
+ },
+ "length": {
+ "type": "integer",
+ "description": "The number of characters to be deleted",
+ "minimum": 0
+ }
+ }
+ },
+ {
+ "type": "function",
+ "name": "callback",
+ "optional": true,
+ "description": "Called when the operation completes.",
+ "parameters": []
+ }
+ ]
+ },
+ {
"name": "keyEventHandled",
"type": "function",
"description": "Indicates that the key event received by onKeyEvent is handled. This should only be called if the onKeyEvent listener is asynchronous.",
diff --git a/chrome/test/data/extensions/api_test/input_ime/background.js b/chrome/test/data/extensions/api_test/input_ime/background.js
index 826d290..973c4532 100644
--- a/chrome/test/data/extensions/api_test/input_ime/background.js
+++ b/chrome/test/data/extensions/api_test/input_ime/background.js
@@ -112,7 +112,17 @@ function updateMenuItemsTest() {
}, chrome.test.callbackPass());
}
+function deleteSurroundingText() {
+ chrome.input.ime.deleteSurroundingText({
+ "engineID": "test",
+ "contextID": 1,
+ "offset": -1,
+ "length": 1
+ }, chrome.test.callbackPass());
+}
+
chrome.test.runTests([setCompositionTest, clearCompositionTest,
commitTextTest, setCandidateWindowPropertiesTest,
setCandidatesTest, setCursorPositionTest,
- setMenuItemsTest, updateMenuItemsTest]);
+ setMenuItemsTest, updateMenuItemsTest,
+ deleteSurroundingText]);