diff options
author | altimofeev@chromium.org <altimofeev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-14 07:21:01 +0000 |
---|---|---|
committer | altimofeev@chromium.org <altimofeev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-14 07:21:01 +0000 |
commit | be5bd57480e654424c3f3fbd3e3ef0a66ff899f6 (patch) | |
tree | 52d0c6db05eacd20119fc53073eca14ed7db4fee | |
parent | e7ca1878add521afcea1cad630e986432771322d (diff) | |
download | chromium_src-be5bd57480e654424c3f3fbd3e3ef0a66ff899f6.zip chromium_src-be5bd57480e654424c3f3fbd3e3ef0a66ff899f6.tar.gz chromium_src-be5bd57480e654424c3f3fbd3e3ef0a66ff899f6.tar.bz2 |
Adds extension API for getting/observing input method.
API includes async input method getter and onChange event.
BUG=chromium-os:16735
TEST=InputMethodApiBasic browser_test
Review URL: http://codereview.chromium.org/7311005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92493 0039d316-1c4b-4281-b951-d872f2087c98
20 files changed, 447 insertions, 5 deletions
diff --git a/chrome/browser/chromeos/extensions/input_method_event_router.cc b/chrome/browser/chromeos/extensions/input_method_event_router.cc new file mode 100644 index 0000000..d316857 --- /dev/null +++ b/chrome/browser/chromeos/extensions/input_method_event_router.cc @@ -0,0 +1,129 @@ +// Copyright (c) 2011 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 "input_method_event_router.h" + +#include <algorithm> + +#include "base/json/json_writer.h" +#include "base/lazy_instance.h" +#include "base/values.h" +#include "chrome/browser/chromeos/web_socket_proxy_controller.h" +#include "chrome/browser/extensions/extension_event_names.h" +#include "chrome/browser/extensions/extension_event_router.h" +#include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/profiles/profile.h" + +namespace { + +// Prefix, which is used by XKB. +const char kXkbPrefix[] = "xkb:"; + +// Extension ID which is used in browser_tests. +const char kInputMethodTestExtensionID[] = "ilanclmaeigfpnmdlgelmhkpkegdioip"; + +class InputMethodPrivateExtensionsWhitelist { + public: + InputMethodPrivateExtensionsWhitelist() { + chromeos::FillWithExtensionsIdsWithPrivateAccess(&ids_); + ids_.push_back(kInputMethodTestExtensionID); + std::sort(ids_.begin(), ids_.end()); + } + + bool HasId(const std::string& id) { + return std::binary_search(ids_.begin(), ids_.end(), id); + } + + const std::vector<std::string>& ids() { return ids_; } + + private: + std::vector<std::string> ids_; +}; + +base::LazyInstance<InputMethodPrivateExtensionsWhitelist> + g_input_method_private_extensions_whitelist(base::LINKER_INITIALIZED); + +} // namespace + +namespace chromeos { + +// static +ExtensionInputMethodEventRouter* + ExtensionInputMethodEventRouter::GetInstance() { + return Singleton<ExtensionInputMethodEventRouter>::get(); +} + +ExtensionInputMethodEventRouter::ExtensionInputMethodEventRouter() { + input_method::InputMethodManager::GetInstance()->AddObserver(this); +} + +ExtensionInputMethodEventRouter::~ExtensionInputMethodEventRouter() { + input_method::InputMethodManager::GetInstance()->RemoveObserver(this); +} + +void ExtensionInputMethodEventRouter::InputMethodChanged( + input_method::InputMethodManager *manager, + const input_method::InputMethodDescriptor ¤t_input_method, + size_t num_active_input_methods) { + Profile *profile = ProfileManager::GetDefaultProfile(); + ExtensionEventRouter *router = profile->GetExtensionEventRouter(); + + if (!router->HasEventListener(extension_event_names::kOnInputMethodChanged)) + return; + + ListValue args; + StringValue *input_method_name = + new StringValue(GetInputMethodForXkb(current_input_method.id())); + args.Append(input_method_name); + std::string args_json; + base::JSONWriter::Write(&args, false, &args_json); + + const std::vector<std::string>& ids = + g_input_method_private_extensions_whitelist.Get().ids(); + + for (size_t i = 0; i < ids.size(); ++i) { + // ExtensionEventRoutner will check that the extension is listening for the + // event. + router->DispatchEventToExtension( + ids[i], extension_event_names::kOnInputMethodChanged, + args_json, profile, GURL()); + } +} + +void ExtensionInputMethodEventRouter::ActiveInputMethodsChanged( + input_method::InputMethodManager *manager, + const input_method::InputMethodDescriptor & current_input_method, + size_t num_active_input_methods) { +} + +void ExtensionInputMethodEventRouter::PreferenceUpdateNeeded( + input_method::InputMethodManager *manager, + const input_method::InputMethodDescriptor & previous_input_method, + const input_method::InputMethodDescriptor & current_input_method) { +} + +void ExtensionInputMethodEventRouter::PropertyListChanged( + input_method::InputMethodManager *manager, + const input_method::ImePropertyList & current_ime_properties) { +} + +void ExtensionInputMethodEventRouter::FirstObserverIsAdded( + input_method::InputMethodManager *obj) { +} + +// static +std::string ExtensionInputMethodEventRouter::GetInputMethodForXkb( + const std::string& xkb_id) { + size_t prefix_length = std::string(kXkbPrefix).length(); + DCHECK(xkb_id.substr(0, prefix_length) == kXkbPrefix); + return xkb_id.substr(prefix_length); +} + +// static +bool ExtensionInputMethodEventRouter::IsExtensionWhitelisted( + const std::string& extension_id) { + return g_input_method_private_extensions_whitelist.Get().HasId(extension_id); +} + +} // namespace chromeos diff --git a/chrome/browser/chromeos/extensions/input_method_event_router.h b/chrome/browser/chromeos/extensions/input_method_event_router.h new file mode 100644 index 0000000..4a7a9e6 --- /dev/null +++ b/chrome/browser/chromeos/extensions/input_method_event_router.h @@ -0,0 +1,57 @@ +// Copyright (c) 2011 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. + +#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_INPUT_METHOD_EVENT_ROUTER_H_ +#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_INPUT_METHOD_EVENT_ROUTER_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "base/memory/singleton.h" +#include "chrome/browser/chromeos/input_method/input_method_manager.h" + +namespace chromeos { + +// Event router class for the input method events. +class ExtensionInputMethodEventRouter + : public input_method::InputMethodManager::Observer { + public: + static ExtensionInputMethodEventRouter* GetInstance(); + + // Implements input_method::InputMethodManager::Observer: + virtual void InputMethodChanged( + input_method::InputMethodManager* manager, + const input_method::InputMethodDescriptor& current_input_method, + size_t num_active_input_methods) OVERRIDE; + virtual void ActiveInputMethodsChanged( + input_method::InputMethodManager* manager, + const input_method::InputMethodDescriptor& current_input_method, + size_t num_active_input_methods) OVERRIDE; + virtual void PreferenceUpdateNeeded( + input_method::InputMethodManager* manager, + const input_method::InputMethodDescriptor& previous_input_method, + const input_method::InputMethodDescriptor& current_input_method) OVERRIDE; + virtual void PropertyListChanged( + input_method::InputMethodManager* manager, + const input_method::ImePropertyList& current_ime_properties) OVERRIDE ; + virtual void FirstObserverIsAdded( + input_method::InputMethodManager* obj) OVERRIDE; + + // Returns input method name for the given XKB (X keyboard extensions in X + // Window System) id. + static std::string GetInputMethodForXkb(const std::string& xkb_id); + + // Returns whether the extension is allowed to use input method API. + static bool IsExtensionWhitelisted(const std::string& extension_id); + + private: + friend struct DefaultSingletonTraits<ExtensionInputMethodEventRouter>; + + ExtensionInputMethodEventRouter(); + virtual ~ExtensionInputMethodEventRouter(); + + DISALLOW_COPY_AND_ASSIGN(ExtensionInputMethodEventRouter); +}; + +} // namespace chromeos +#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_INPUT_METHOD_EVENT_ROUTER_H_ diff --git a/chrome/browser/chromeos/web_socket_proxy_controller.cc b/chrome/browser/chromeos/web_socket_proxy_controller.cc index 3e16d80..8feff45 100644 --- a/chrome/browser/chromeos/web_socket_proxy_controller.cc +++ b/chrome/browser/chromeos/web_socket_proxy_controller.cc @@ -33,8 +33,8 @@ const char* kAllowedIds[] = { class OriginValidator { public: - OriginValidator() - : allowed_ids_(kAllowedIds, kAllowedIds + arraysize(kAllowedIds)) { + OriginValidator() { + chromeos::FillWithExtensionsIdsWithPrivateAccess(&allowed_ids_); CommandLine* command_line = CommandLine::ForCurrentProcess(); DCHECK(command_line); std::string allowed_list = @@ -156,6 +156,12 @@ void ProxyTask::Run() { namespace chromeos { +void FillWithExtensionsIdsWithPrivateAccess(std::vector<std::string>* ids) { + ids->clear(); + for (size_t i = 0; i < arraysize(kAllowedIds); ++i) + ids->push_back(kAllowedIds[i]); +} + // static void WebSocketProxyController::Initiate() { LOG(INFO) << "WebSocketProxyController initiation"; diff --git a/chrome/browser/chromeos/web_socket_proxy_controller.h b/chrome/browser/chromeos/web_socket_proxy_controller.h index f96fedc..bcee38e 100644 --- a/chrome/browser/chromeos/web_socket_proxy_controller.h +++ b/chrome/browser/chromeos/web_socket_proxy_controller.h @@ -7,9 +7,14 @@ #pragma once #include <string> +#include <vector> namespace chromeos { +// Fills vector with extensions IDs which are allowed to use private +// extension API (WebSocketProxyPrivate, InputMethodPrivate, etc.) +void FillWithExtensionsIdsWithPrivateAccess(std::vector<std::string>* ids); + // Controls webproxy to TCP service. class WebSocketProxyController { public: diff --git a/chrome/browser/extensions/extension_event_names.cc b/chrome/browser/extensions/extension_event_names.cc index 4718f52..76c0d8f 100644 --- a/chrome/browser/extensions/extension_event_names.cc +++ b/chrome/browser/extensions/extension_event_names.cc @@ -25,4 +25,6 @@ const char kOnExtensionDisabled[] = "management.onDisabled"; const char kOnFileBrowserDiskChanged[] = "fileBrowserPrivate.onDiskChanged"; const char kOnFileChanged[] = "fileBrowserPrivate.onFileChanged"; + +const char kOnInputMethodChanged[] = "inputMethodPrivate.onChanged"; } // namespace extension_event_names diff --git a/chrome/browser/extensions/extension_event_names.h b/chrome/browser/extensions/extension_event_names.h index 177c70b..b6958e2 100644 --- a/chrome/browser/extensions/extension_event_names.h +++ b/chrome/browser/extensions/extension_event_names.h @@ -34,6 +34,9 @@ extern const char kOnExtensionDisabled[]; extern const char kOnFileBrowserDiskChanged[]; extern const char kOnFileChanged[]; +// InputMethod. +extern const char kOnInputMethodChanged[]; + }; // namespace extension_event_names #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_NAMES_H_ diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc index 4f41eed..e3ce123 100644 --- a/chrome/browser/extensions/extension_function_dispatcher.cc +++ b/chrome/browser/extensions/extension_function_dispatcher.cc @@ -72,6 +72,7 @@ #if defined(OS_CHROMEOS) #include "chrome/browser/extensions/extension_file_browser_private_api.h" #include "chrome/browser/extensions/extension_info_private_api_chromeos.h" +#include "chrome/browser/extensions/extension_input_method_api.h" #include "chrome/browser/extensions/extension_mediaplayer_private_api.h" #endif @@ -355,6 +356,10 @@ void FactoryRegistry::ResetFunctions() { RegisterFunction<GetPlaylistMediaplayerFunction>(); RegisterFunction<TogglePlaylistPanelMediaplayerFunction>(); RegisterFunction<ToggleFullscreenMediaplayerFunction>(); + + // InputMethod + RegisterFunction<GetInputMethodFunction>(); + #if defined(TOUCH_UI) // Input RegisterFunction<SendHandwritingStrokeFunction>(); diff --git a/chrome/browser/extensions/extension_input_method_api.cc b/chrome/browser/extensions/extension_input_method_api.cc new file mode 100644 index 0000000..60cec6e --- /dev/null +++ b/chrome/browser/extensions/extension_input_method_api.cc @@ -0,0 +1,36 @@ +// Copyright (c) 2011 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_method_api.h" + +#include "base/values.h" +#include "chrome/browser/chromeos/input_method/input_method_manager.h" +#include "chrome/browser/chromeos/extensions/input_method_event_router.h" + +namespace { + +const char kErrorInputMethodPrivateApi[] = "Input method API is private"; + +} // namespace + +GetInputMethodFunction::GetInputMethodFunction() { +} + +GetInputMethodFunction::~GetInputMethodFunction() { +} + +bool GetInputMethodFunction::RunImpl() { + if (!chromeos::ExtensionInputMethodEventRouter:: + IsExtensionWhitelisted(extension_id())) { + error_ = kErrorInputMethodPrivateApi; + return false; + } + chromeos::input_method::InputMethodManager* manager = + chromeos::input_method::InputMethodManager::GetInstance(); + std::string input_method = + chromeos::ExtensionInputMethodEventRouter::GetInputMethodForXkb( + manager->current_input_method().id()); + result_.reset(Value::CreateStringValue(input_method)); + return true; +} diff --git a/chrome/browser/extensions/extension_input_method_api.h b/chrome/browser/extensions/extension_input_method_api.h new file mode 100644 index 0000000..c30510c --- /dev/null +++ b/chrome/browser/extensions/extension_input_method_api.h @@ -0,0 +1,25 @@ +// Copyright (c) 2011 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. + +#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_INPUT_METHOD_API_H_ +#define CHROME_BROWSER_EXTENSIONS_EXTENSION_INPUT_METHOD_API_H_ + +#include "base/compiler_specific.h" +#include "chrome/browser/extensions/extension_function.h" + +// Implements the experimental.inputMethod.get method. +class GetInputMethodFunction : public SyncExtensionFunction { + public: + GetInputMethodFunction(); + + protected: + virtual ~GetInputMethodFunction(); + + virtual bool RunImpl() OVERRIDE; + + private: + DECLARE_EXTENSION_FUNCTION_NAME("inputMethodPrivate.get"); +}; + +#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INPUT_METHOD_API_H_ diff --git a/chrome/browser/extensions/extension_input_method_apitest.cc b/chrome/browser/extensions/extension_input_method_apitest.cc new file mode 100644 index 0000000..bce261c --- /dev/null +++ b/chrome/browser/extensions/extension_input_method_apitest.cc @@ -0,0 +1,69 @@ +// Copyright (c) 2011 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_apitest.h" + +#include "base/stringprintf.h" +#include "chrome/browser/chromeos/extensions/input_method_event_router.h" +#include "chrome/browser/chromeos/input_method/input_method_manager.h" +#include "chrome/browser/extensions/extension_test_api.h" +#include "chrome/common/chrome_notification_types.h" +#include "content/common/notification_observer.h" +#include "content/common/notification_registrar.h" +#include "content/common/notification_service.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +const char kNewInputMethod[] = "ru::rus"; +const char kSetInputMethodMessage[] = "setInputMethod"; +const char kSetInputMethodDone[] = "done"; + +// Class that listens for the JS message then changes input method and replies +// back. +class SetInputMethodListener : public NotificationObserver { + public: + // Creates listener, which should reply exactly |count_| times. + explicit SetInputMethodListener(int count) : count_(count) { + registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_TEST_MESSAGE, + NotificationService::AllSources()); + } + + virtual ~SetInputMethodListener() { + EXPECT_EQ(0, count_); + } + + // Implements the NotificationObserver interface. + virtual void Observe(int type, + const NotificationSource& source, + const NotificationDetails& details) { + const std::string& content = *Details<std::string>(details).ptr(); + const std::string expected_message = StringPrintf("%s:%s", + kSetInputMethodMessage, + kNewInputMethod); + if (content == expected_message) { + chromeos::input_method::InputMethodManager::GetInstance()-> + ChangeInputMethod(StringPrintf("xkb:%s", kNewInputMethod)); + + ExtensionTestSendMessageFunction* function = + Source<ExtensionTestSendMessageFunction>(source).ptr(); + EXPECT_GT(count_--, 0); + function->Reply(kSetInputMethodDone); + } + } + + private: + NotificationRegistrar registrar_; + + int count_; +}; + +} // namespace + +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, InputMethodApiBasic) { + // Two test, two calls. See JS code for more info. + SetInputMethodListener listener(2); + + ASSERT_TRUE(RunExtensionTest("input_method")) << message_; +} diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc index 09711b5..c0ce5ec 100644 --- a/chrome/browser/extensions/extension_service.cc +++ b/chrome/browser/extensions/extension_service.cc @@ -87,6 +87,7 @@ #if defined(OS_CHROMEOS) #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" +#include "chrome/browser/chromeos/extensions/input_method_event_router.h" #include "chrome/browser/chromeos/extensions/media_player_event_router.h" #include "webkit/fileapi/file_system_context.h" #include "webkit/fileapi/file_system_mount_point_provider.h" @@ -680,6 +681,9 @@ void ExtensionService::InitEventRouters() { #if defined(OS_CHROMEOS) ExtensionFileBrowserEventRouter::GetInstance()->ObserveFileSystemEvents( profile_); + // Lazy initialization. + chromeos::ExtensionInputMethodEventRouter::GetInstance(); + ExtensionMediaPlayerEventRouter::GetInstance()->Init(profile_); #endif diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index c991939..5fb28ab6 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -397,6 +397,8 @@ 'browser/chromeos/enterprise_extension_observer.h', 'browser/chromeos/extensions/file_browser_event_router.cc', 'browser/chromeos/extensions/file_browser_event_router.h', + 'browser/chromeos/extensions/input_method_event_router.cc', + 'browser/chromeos/extensions/input_method_event_router.h', 'browser/chromeos/extensions/media_player_event_router.cc', 'browser/chromeos/extensions/media_player_event_router.h', 'browser/chromeos/external_metrics.cc', @@ -966,6 +968,8 @@ 'browser/extensions/extension_infobar_module_constants.h', 'browser/extensions/extension_input_api.cc', 'browser/extensions/extension_input_api.h', + 'browser/extensions/extension_input_method_api.cc', + 'browser/extensions/extension_input_method_api.h', 'browser/extensions/extension_input_ui_api.cc', 'browser/extensions/extension_input_ui_api.h', 'browser/extensions/extension_install_dialog.h', @@ -3713,6 +3717,8 @@ ['exclude', '^browser/ui/webui/options/chromeos'], ['exclude', 'browser/extensions/extension_file_browser_private_api.cc'], ['exclude', 'browser/extensions/extension_file_browser_private_api.h'], + ['exclude', 'browser/extensions/extension_input_method_api.cc'], + ['exclude', 'browser/extensions/extension_input_method_api.h'], ['exclude', 'browser/extensions/extension_mediaplayer_private_api.cc'], ['exclude', 'browser/extensions/extension_mediaplayer_private_api.h'], ['exclude', 'browser/extensions/extension_tts_api_chromeos.cc'], diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 9275d8e..fe54971 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1908,8 +1908,8 @@ 'common/extensions/extension_unittest.cc', 'common/extensions/extension_unpacker_unittest.cc', 'common/extensions/update_manifest_unittest.cc', - 'common/extensions/url_pattern_unittest.cc', 'common/extensions/url_pattern_set_unittest.cc', + 'common/extensions/url_pattern_unittest.cc', 'common/extensions/user_script_unittest.cc', 'common/guid_unittest.cc', 'common/important_file_writer_unittest.cc', @@ -2457,6 +2457,7 @@ 'browser/extensions/extension_info_private_apitest_chromeos.cc', 'browser/extensions/extension_infobar_apitest.cc', 'browser/extensions/extension_input_apitest.cc', + 'browser/extensions/extension_input_method_apitest.cc', 'browser/extensions/extension_input_ui_apitest.cc', 'browser/extensions/extension_install_ui_browsertest.cc', 'browser/extensions/extension_javascript_url_apitest.cc', @@ -2599,6 +2600,7 @@ 'sources!': [ 'browser/chromeos/media/media_player_browsertest.cc', 'browser/extensions/extension_file_browser_private_apitest.cc', + 'browser/extensions/extension_input_method_apitest.cc', ], }, { #else: OS == "chromeos" 'sources!': [ diff --git a/chrome/common/extensions/api/extension_api.json b/chrome/common/extensions/api/extension_api.json index a50c14a..bb3b5c5 100644 --- a/chrome/common/extensions/api/extension_api.json +++ b/chrome/common/extensions/api/extension_api.json @@ -2627,7 +2627,7 @@ { "name": "strokeCount", "optional": true, - "description": "The number of strokes to be removed. Pass 0 to remove all strokes. If omitted, removes all.", + "description": "The number of strokes to be removed. Pass 0 to remove all strokes. If omitted, removes all.", "type": "integer", "minimum": 0 } @@ -2637,6 +2637,48 @@ "events": [] }, { + "namespace": "inputMethodPrivate", + "nodoc": true, + "platforms": ["chromeos"], + "types": [], + "functions": [ + { + "name": "get", + "type": "function", + "description": "Gets the current input method.", + "parameters": [ + { + "name": "callback", + "type": "function", + "optional": false, + "description": "Callback which is called with the current input method.", + "parameters": [ + { + "name": "inputMethodId", + "type": "string", + "description": "Current input method." + } + ] + } + ] + } + ], + "events": [ + { + "name": "onChanged", + "type": "function", + "description": "Fired when the input method is changed.", + "parameters": [ + { + "name": "newInputMethodId", + "type": "string", + "description": "New input method which is being used." + } + ] + } + ] + }, + { "namespace": "experimental.inputUI", "nodoc": true, "platforms": ["chromeos touch"], diff --git a/chrome/common/extensions/extension_permission_set.cc b/chrome/common/extensions/extension_permission_set.cc index 91c2238..8d27abd 100644 --- a/chrome/common/extensions/extension_permission_set.cc +++ b/chrome/common/extensions/extension_permission_set.cc @@ -287,6 +287,10 @@ ExtensionPermissionsInfo::ExtensionPermissionsInfo() ExtensionAPIPermission::kIdle, "idle", 0, ExtensionPermissionMessage::kNone); RegisterExtensionPermission( + ExtensionAPIPermission::kInputMethodPrivate, + "inputMethodPrivate", 0, + ExtensionPermissionMessage::kNone); + RegisterExtensionPermission( ExtensionAPIPermission::kManagement, "management", IDS_EXTENSION_PROMPT_WARNING_MANAGEMENT, ExtensionPermissionMessage::kManagement); diff --git a/chrome/common/extensions/extension_permission_set.h b/chrome/common/extensions/extension_permission_set.h index 7aa39e7..d3884e4 100644 --- a/chrome/common/extensions/extension_permission_set.h +++ b/chrome/common/extensions/extension_permission_set.h @@ -86,7 +86,7 @@ class ExtensionAPIPermission { kInvalid = -2, kUnknown = -1, - // Default permission that every extension has implicity. + // Default permission that every extension has implicitly. kDefault, // Real permissions. @@ -107,6 +107,7 @@ class ExtensionAPIPermission { kGeolocation, kHistory, kIdle, + kInputMethodPrivate, kManagement, kMediaPlayerPrivate, kNotification, diff --git a/chrome/common/extensions/extension_permission_set_unittest.cc b/chrome/common/extensions/extension_permission_set_unittest.cc index 8110487..ebfb419 100644 --- a/chrome/common/extensions/extension_permission_set_unittest.cc +++ b/chrome/common/extensions/extension_permission_set_unittest.cc @@ -486,6 +486,7 @@ TEST(ExtensionPermissionSetTest, PermissionMessages) { skip.insert(ExtensionAPIPermission::kChromePrivate); skip.insert(ExtensionAPIPermission::kChromeosInfoPrivate); skip.insert(ExtensionAPIPermission::kWebSocketProxyPrivate); + skip.insert(ExtensionAPIPermission::kInputMethodPrivate); // Warned as part of host permissions. skip.insert(ExtensionAPIPermission::kDevtools); diff --git a/chrome/renderer/resources/renderer_extension_bindings.js b/chrome/renderer/resources/renderer_extension_bindings.js index 1508d8a..8f78ff5 100644 --- a/chrome/renderer/resources/renderer_extension_bindings.js +++ b/chrome/renderer/resources/renderer_extension_bindings.js @@ -323,6 +323,7 @@ var chrome = chrome || {}; "fileSystem", "history", "idle", + "inputMethodPrivate", "management", "mediaPlayerPrivate", "omnibox", diff --git a/chrome/test/data/extensions/api_test/input_method/background.html b/chrome/test/data/extensions/api_test/input_method/background.html new file mode 100644 index 0000000..a09673d --- /dev/null +++ b/chrome/test/data/extensions/api_test/input_method/background.html @@ -0,0 +1,35 @@ +<script> + var kNewInputMethod = "ru::rus"; + + function setAndGetTest() { + console.log('Changing input method to: ' + kNewInputMethod); + chrome.test.sendMessage('setInputMethod:' + kNewInputMethod, + function (response) { + chrome.test.assertEq('done', response); + console.log('Getting current input method.'); + chrome.inputMethodPrivate.get(function (inputMethod) { + chrome.test.assertEq(inputMethod, kNewInputMethod); + chrome.test.succeed(); + } + ); + }); + } + + function setAndObserveTest() { + console.log('Adding input method event listener.'); + chrome.inputMethodPrivate.onChanged.addListener( + function(newInputMethod) { + chrome.test.assertEq(kNewInputMethod, newInputMethod); + chrome.test.succeed(); + } + ); + console.log('Changing input method to: ' + kNewInputMethod); + chrome.test.sendMessage('setInputMethod:' + kNewInputMethod, + function (response) { + chrome.test.assertEq('done', response); + } + ); + } + + chrome.test.runTests([setAndGetTest, setAndObserveTest]); +</script> diff --git a/chrome/test/data/extensions/api_test/input_method/manifest.json b/chrome/test/data/extensions/api_test/input_method/manifest.json new file mode 100644 index 0000000..6721b7c --- /dev/null +++ b/chrome/test/data/extensions/api_test/input_method/manifest.json @@ -0,0 +1,9 @@ +{ + "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9fDu8apG3Dz72XTT3Ym1SfGt06tdowTlYQ+3lGlCbVpfnMOmewgRgYxzUtUPso9aQERZcmI2+7UtbWjtk6/usl9Hr7a1JBQwfaUoUygEe56ajUeZhe/ErkH5CXT84U0pokfPr5vMvc7RVPduU+UBiF0DnGb/hSpzz/1UhJ5H9AwIDAQAB", + "name": "experimental.inputMethod test", + "version": "0.1", + "description": "Input method events tests.", + "background_page": "background.html", + "permissions": [ "inputMethodPrivate" ] +} + |