| 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/extension_input_ime_api.h" | 5 #include "chrome/browser/extensions/extension_input_ime_api.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 117 |
| 118 if (!ReadMenuItems(sub_list, &(output->back().children))) { | 118 if (!ReadMenuItems(sub_list, &(output->back().children))) { |
| 119 return false; | 119 return false; |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 | 123 |
| 124 return true; | 124 return true; |
| 125 } | 125 } |
| 126 | 126 |
| 127 } | 127 } // namespace |
| 128 | 128 |
| 129 namespace events { | 129 namespace events { |
| 130 | 130 |
| 131 const char kOnActivate[] = "input.ime.onActivate"; | 131 const char kOnActivate[] = "input.ime.onActivate"; |
| 132 const char kOnDeactivated[] = "input.ime.onDeactivated"; | 132 const char kOnDeactivated[] = "input.ime.onDeactivated"; |
| 133 const char kOnFocus[] = "input.ime.onFocus"; | 133 const char kOnFocus[] = "input.ime.onFocus"; |
| 134 const char kOnBlur[] = "input.ime.onBlur"; | 134 const char kOnBlur[] = "input.ime.onBlur"; |
| 135 const char kOnInputContextUpdate[] = "input.ime.onInputContextUpdate"; | 135 const char kOnInputContextUpdate[] = "input.ime.onInputContextUpdate"; |
| 136 const char kOnKeyEvent[] = "input.ime.onKeyEvent"; | 136 const char kOnKeyEvent[] = "input.ime.onKeyEvent"; |
| 137 const char kOnCandidateClicked[] = "input.ime.onCandidateClicked"; | 137 const char kOnCandidateClicked[] = "input.ime.onCandidateClicked"; |
| 138 const char kOnMenuItemActivated[] = "input.ime.onMenuItemActivated"; | 138 const char kOnMenuItemActivated[] = "input.ime.onMenuItemActivated"; |
| 139 | 139 |
| 140 } // namespace events | 140 } // namespace events |
| 141 | 141 |
| 142 namespace chromeos { | 142 namespace chromeos { |
| 143 class ImeObserver : public chromeos::InputMethodEngine::Observer { | 143 class ImeObserver : public chromeos::InputMethodEngine::Observer { |
| 144 public: | 144 public: |
| 145 ImeObserver(Profile* profile, const std::string& extension_id, | 145 ImeObserver(Profile* profile, const std::string& extension_id, |
| 146 const std::string& engine_id) : | 146 const std::string& engine_id) : |
| 147 profile_(profile), | 147 profile_(profile), |
| 148 extension_id_(extension_id), | 148 extension_id_(extension_id), |
| 149 engine_id_(engine_id) { | 149 engine_id_(engine_id) { |
| 150 } | 150 } |
| 151 | 151 |
| 152 virtual ~ImeObserver() { | 152 virtual ~ImeObserver() {} |
| 153 } | |
| 154 | 153 |
| 155 virtual void OnActivate(const std::string& engine_id) { | 154 virtual void OnActivate(const std::string& engine_id) { |
| 156 if (profile_ == NULL || extension_id_.empty()) | 155 if (profile_ == NULL || extension_id_.empty()) |
| 157 return; | 156 return; |
| 158 | 157 |
| 159 ListValue args; | 158 ListValue args; |
| 160 args.Append(Value::CreateStringValue(engine_id)); | 159 args.Append(Value::CreateStringValue(engine_id)); |
| 161 | 160 |
| 162 std::string json_args; | 161 std::string json_args; |
| 163 base::JSONWriter::Write(&args, &json_args); | 162 base::JSONWriter::Write(&args, &json_args); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 GURL()); | 303 GURL()); |
| 305 } | 304 } |
| 306 | 305 |
| 307 private: | 306 private: |
| 308 Profile* profile_; | 307 Profile* profile_; |
| 309 std::string extension_id_; | 308 std::string extension_id_; |
| 310 std::string engine_id_; | 309 std::string engine_id_; |
| 311 | 310 |
| 312 DISALLOW_COPY_AND_ASSIGN(ImeObserver); | 311 DISALLOW_COPY_AND_ASSIGN(ImeObserver); |
| 313 }; | 312 }; |
| 313 |
| 314 } // namespace chromeos | 314 } // namespace chromeos |
| 315 | 315 |
| 316 | |
| 317 ExtensionInputImeEventRouter* | 316 ExtensionInputImeEventRouter* |
| 318 ExtensionInputImeEventRouter::GetInstance() { | 317 ExtensionInputImeEventRouter::GetInstance() { |
| 319 return Singleton<ExtensionInputImeEventRouter>::get(); | 318 return Singleton<ExtensionInputImeEventRouter>::get(); |
| 320 } | 319 } |
| 321 | 320 |
| 322 ExtensionInputImeEventRouter::ExtensionInputImeEventRouter() | 321 void ExtensionInputImeEventRouter::Init() {} |
| 323 : next_request_id_(1) { | |
| 324 } | |
| 325 | |
| 326 ExtensionInputImeEventRouter::~ExtensionInputImeEventRouter() { | |
| 327 } | |
| 328 | |
| 329 void ExtensionInputImeEventRouter::Init() { | |
| 330 } | |
| 331 | 322 |
| 332 #if defined(OS_CHROMEOS) | 323 #if defined(OS_CHROMEOS) |
| 333 bool ExtensionInputImeEventRouter::RegisterIme( | 324 bool ExtensionInputImeEventRouter::RegisterIme( |
| 334 Profile* profile, | 325 Profile* profile, |
| 335 const std::string& extension_id, | 326 const std::string& extension_id, |
| 336 const Extension::InputComponentInfo& component) { | 327 const Extension::InputComponentInfo& component) { |
| 337 VLOG(1) << "RegisterIme: " << extension_id << " id: " << component.id; | 328 VLOG(1) << "RegisterIme: " << extension_id << " id: " << component.id; |
| 338 | 329 |
| 339 std::map<std::string, chromeos::InputMethodEngine*>& engine_map = | 330 std::map<std::string, chromeos::InputMethodEngine*>& engine_map = |
| 340 engines_[extension_id]; | 331 engines_[extension_id]; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 const std::string& engine_id, | 449 const std::string& engine_id, |
| 459 chromeos::input_method::KeyEventHandle* key_data) { | 450 chromeos::input_method::KeyEventHandle* key_data) { |
| 460 std::string request_id = base::IntToString(next_request_id_); | 451 std::string request_id = base::IntToString(next_request_id_); |
| 461 ++next_request_id_; | 452 ++next_request_id_; |
| 462 | 453 |
| 463 request_map_[request_id] = std::make_pair(engine_id, key_data); | 454 request_map_[request_id] = std::make_pair(engine_id, key_data); |
| 464 | 455 |
| 465 return request_id; | 456 return request_id; |
| 466 } | 457 } |
| 467 | 458 |
| 459 ExtensionInputImeEventRouter::ExtensionInputImeEventRouter() |
| 460 : next_request_id_(1) { |
| 461 } |
| 462 |
| 463 ExtensionInputImeEventRouter::~ExtensionInputImeEventRouter() {} |
| 464 |
| 468 bool SetCompositionFunction::RunImpl() { | 465 bool SetCompositionFunction::RunImpl() { |
| 469 chromeos::InputMethodEngine* engine = | 466 chromeos::InputMethodEngine* engine = |
| 470 ExtensionInputImeEventRouter::GetInstance()-> | 467 ExtensionInputImeEventRouter::GetInstance()-> |
| 471 GetActiveEngine(extension_id()); | 468 GetActiveEngine(extension_id()); |
| 472 if (!engine) { | 469 if (!engine) { |
| 473 result_.reset(Value::CreateBooleanValue(false)); | 470 result_.reset(Value::CreateBooleanValue(false)); |
| 474 return true; | 471 return true; |
| 475 } | 472 } |
| 476 | 473 |
| 477 DictionaryValue* args; | 474 DictionaryValue* args; |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 | 821 |
| 825 bool handled = false; | 822 bool handled = false; |
| 826 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &handled)); | 823 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &handled)); |
| 827 | 824 |
| 828 ExtensionInputImeEventRouter::GetInstance()->OnEventHandled( | 825 ExtensionInputImeEventRouter::GetInstance()->OnEventHandled( |
| 829 extension_id(), request_id_str, handled); | 826 extension_id(), request_id_str, handled); |
| 830 | 827 |
| 831 return true; | 828 return true; |
| 832 } | 829 } |
| 833 #endif | 830 #endif |
| OLD | NEW |