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

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

Issue 1556783002: Convert Pass()→std::move() for CrOS extension code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <stddef.h> 7 #include <stddef.h>
8 #include <utility>
8 9
9 #include "base/macros.h" 10 #include "base/macros.h"
10 #include "chrome/browser/chromeos/input_method/input_method_engine.h" 11 #include "chrome/browser/chromeos/input_method/input_method_engine.h"
11 #include "chrome/browser/chromeos/login/lock/screen_locker.h" 12 #include "chrome/browser/chromeos/login/lock/screen_locker.h"
12 #include "chrome/browser/chromeos/login/session/user_session_manager.h" 13 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
13 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" 14 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
14 #include "chrome/browser/chromeos/profiles/profile_helper.h" 15 #include "chrome/browser/chromeos/profiles/profile_helper.h"
15 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/profiles/profile_manager.h" 17 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/common/extensions/api/input_ime.h" 18 #include "chrome/common/extensions/api/input_ime.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 void OnActivate(const std::string& component_id) override { 86 void OnActivate(const std::string& component_id) override {
86 if (extension_id_.empty() || 87 if (extension_id_.empty() ||
87 !HasListener(input_ime::OnActivate::kEventName)) 88 !HasListener(input_ime::OnActivate::kEventName))
88 return; 89 return;
89 90
90 scoped_ptr<base::ListValue> args(input_ime::OnActivate::Create( 91 scoped_ptr<base::ListValue> args(input_ime::OnActivate::Create(
91 component_id, 92 component_id,
92 input_ime::ParseScreenType(GetCurrentScreenType()))); 93 input_ime::ParseScreenType(GetCurrentScreenType())));
93 94
94 DispatchEventToExtension(extensions::events::INPUT_IME_ON_ACTIVATE, 95 DispatchEventToExtension(extensions::events::INPUT_IME_ON_ACTIVATE,
95 input_ime::OnActivate::kEventName, args.Pass()); 96 input_ime::OnActivate::kEventName,
97 std::move(args));
96 } 98 }
97 99
98 void OnInputContextUpdate( 100 void OnInputContextUpdate(
99 const IMEEngineHandlerInterface::InputContext& context) override { 101 const IMEEngineHandlerInterface::InputContext& context) override {
100 if (extension_id_.empty() || 102 if (extension_id_.empty() ||
101 !HasListener(input_ime::OnInputContextUpdate::kEventName)) 103 !HasListener(input_ime::OnInputContextUpdate::kEventName))
102 return; 104 return;
103 105
104 input_ime::InputContext context_value; 106 input_ime::InputContext context_value;
105 context_value.context_id = context.id; 107 context_value.context_id = context.id;
106 context_value.type = 108 context_value.type =
107 input_ime::ParseInputContextType(ConvertInputContextType(context)); 109 input_ime::ParseInputContextType(ConvertInputContextType(context));
108 110
109 scoped_ptr<base::ListValue> args( 111 scoped_ptr<base::ListValue> args(
110 input_ime::OnInputContextUpdate::Create(context_value)); 112 input_ime::OnInputContextUpdate::Create(context_value));
111 113
112 DispatchEventToExtension( 114 DispatchEventToExtension(
113 extensions::events::INPUT_IME_ON_INPUT_CONTEXT_UPDATE, 115 extensions::events::INPUT_IME_ON_INPUT_CONTEXT_UPDATE,
114 input_ime::OnInputContextUpdate::kEventName, args.Pass()); 116 input_ime::OnInputContextUpdate::kEventName, std::move(args));
115 } 117 }
116 118
117 bool IsInterestedInKeyEvent() const override { 119 bool IsInterestedInKeyEvent() const override {
118 return ShouldForwardKeyEvent(); 120 return ShouldForwardKeyEvent();
119 } 121 }
120 122
121 void OnCandidateClicked( 123 void OnCandidateClicked(
122 const std::string& component_id, 124 const std::string& component_id,
123 int candidate_id, 125 int candidate_id,
124 ui::IMEEngineObserver::MouseButtonEvent button) override { 126 ui::IMEEngineObserver::MouseButtonEvent button) override {
(...skipping 16 matching lines...) Expand all
141 default: 143 default:
142 button_enum = input_ime::MOUSE_BUTTON_LEFT; 144 button_enum = input_ime::MOUSE_BUTTON_LEFT;
143 break; 145 break;
144 } 146 }
145 147
146 scoped_ptr<base::ListValue> args(input_ime::OnCandidateClicked::Create( 148 scoped_ptr<base::ListValue> args(input_ime::OnCandidateClicked::Create(
147 component_id, candidate_id, button_enum)); 149 component_id, candidate_id, button_enum));
148 150
149 DispatchEventToExtension(extensions::events::INPUT_IME_ON_CANDIDATE_CLICKED, 151 DispatchEventToExtension(extensions::events::INPUT_IME_ON_CANDIDATE_CLICKED,
150 input_ime::OnCandidateClicked::kEventName, 152 input_ime::OnCandidateClicked::kEventName,
151 args.Pass()); 153 std::move(args));
152 } 154 }
153 155
154 void OnMenuItemActivated(const std::string& component_id, 156 void OnMenuItemActivated(const std::string& component_id,
155 const std::string& menu_id) override { 157 const std::string& menu_id) override {
156 if (extension_id_.empty() || 158 if (extension_id_.empty() ||
157 !HasListener(input_ime::OnMenuItemActivated::kEventName)) 159 !HasListener(input_ime::OnMenuItemActivated::kEventName))
158 return; 160 return;
159 161
160 scoped_ptr<base::ListValue> args( 162 scoped_ptr<base::ListValue> args(
161 input_ime::OnMenuItemActivated::Create(component_id, menu_id)); 163 input_ime::OnMenuItemActivated::Create(component_id, menu_id));
162 164
163 DispatchEventToExtension( 165 DispatchEventToExtension(
164 extensions::events::INPUT_IME_ON_MENU_ITEM_ACTIVATED, 166 extensions::events::INPUT_IME_ON_MENU_ITEM_ACTIVATED,
165 input_ime::OnMenuItemActivated::kEventName, args.Pass()); 167 input_ime::OnMenuItemActivated::kEventName, std::move(args));
166 } 168 }
167 169
168 void OnSurroundingTextChanged(const std::string& component_id, 170 void OnSurroundingTextChanged(const std::string& component_id,
169 const std::string& text, 171 const std::string& text,
170 int cursor_pos, 172 int cursor_pos,
171 int anchor_pos, 173 int anchor_pos,
172 int offset_pos) override { 174 int offset_pos) override {
173 if (extension_id_.empty() || 175 if (extension_id_.empty() ||
174 !HasListener(input_ime::OnSurroundingTextChanged::kEventName)) 176 !HasListener(input_ime::OnSurroundingTextChanged::kEventName))
175 return; 177 return;
176 178
177 input_ime::OnSurroundingTextChanged::SurroundingInfo info; 179 input_ime::OnSurroundingTextChanged::SurroundingInfo info;
178 info.text = text; 180 info.text = text;
179 info.focus = cursor_pos; 181 info.focus = cursor_pos;
180 info.anchor = anchor_pos; 182 info.anchor = anchor_pos;
181 info.offset = offset_pos; 183 info.offset = offset_pos;
182 scoped_ptr<base::ListValue> args( 184 scoped_ptr<base::ListValue> args(
183 input_ime::OnSurroundingTextChanged::Create(component_id, info)); 185 input_ime::OnSurroundingTextChanged::Create(component_id, info));
184 186
185 DispatchEventToExtension( 187 DispatchEventToExtension(
186 extensions::events::INPUT_IME_ON_SURROUNDING_TEXT_CHANGED, 188 extensions::events::INPUT_IME_ON_SURROUNDING_TEXT_CHANGED,
187 input_ime::OnSurroundingTextChanged::kEventName, args.Pass()); 189 input_ime::OnSurroundingTextChanged::kEventName, std::move(args));
188 } 190 }
189 191
190 void OnCompositionBoundsChanged( 192 void OnCompositionBoundsChanged(
191 const std::vector<gfx::Rect>& bounds) override { 193 const std::vector<gfx::Rect>& bounds) override {
192 if (extension_id_.empty() || 194 if (extension_id_.empty() ||
193 !HasListener(kOnCompositionBoundsChangedEventName)) 195 !HasListener(kOnCompositionBoundsChangedEventName))
194 return; 196 return;
195 197
196 // Note: this is a private API event. 198 // Note: this is a private API event.
197 base::ListValue* bounds_list = new base::ListValue(); 199 base::ListValue* bounds_list = new base::ListValue();
(...skipping 12 matching lines...) Expand all
210 212
211 // The old extension code uses the first parameter to get the bounds of the 213 // The old extension code uses the first parameter to get the bounds of the
212 // first composition character, so for backward compatibility, add it here. 214 // first composition character, so for backward compatibility, add it here.
213 base::Value* first_value = NULL; 215 base::Value* first_value = NULL;
214 if (bounds_list->Get(0, &first_value)) 216 if (bounds_list->Get(0, &first_value))
215 args->Append(first_value->DeepCopy()); 217 args->Append(first_value->DeepCopy());
216 args->Append(bounds_list); 218 args->Append(bounds_list);
217 219
218 DispatchEventToExtension( 220 DispatchEventToExtension(
219 extensions::events::INPUT_METHOD_PRIVATE_ON_COMPOSITION_BOUNDS_CHANGED, 221 extensions::events::INPUT_METHOD_PRIVATE_ON_COMPOSITION_BOUNDS_CHANGED,
220 kOnCompositionBoundsChangedEventName, args.Pass()); 222 kOnCompositionBoundsChangedEventName, std::move(args));
221 } 223 }
222 224
223 private: 225 private:
224 // ui::ImeObserver overrides. 226 // ui::ImeObserver overrides.
225 void DispatchEventToExtension( 227 void DispatchEventToExtension(
226 extensions::events::HistogramValue histogram_value, 228 extensions::events::HistogramValue histogram_value,
227 const std::string& event_name, 229 const std::string& event_name,
228 scoped_ptr<base::ListValue> args) override { 230 scoped_ptr<base::ListValue> args) override {
229 if (event_name != input_ime::OnActivate::kEventName) { 231 if (event_name != input_ime::OnActivate::kEventName) {
230 // For suspended IME extension (e.g. XKB extension), don't awake it by IME 232 // For suspended IME extension (e.g. XKB extension), don't awake it by IME
(...skipping 12 matching lines...) Expand all
243 extensions::ProcessManager* process_manager = 245 extensions::ProcessManager* process_manager =
244 extensions::ProcessManager::Get(profile_); 246 extensions::ProcessManager::Get(profile_);
245 if (extensions::BackgroundInfo::HasBackgroundPage(extension) && 247 if (extensions::BackgroundInfo::HasBackgroundPage(extension) &&
246 !process_manager->GetBackgroundHostForExtension(extension_id_)) { 248 !process_manager->GetBackgroundHostForExtension(extension_id_)) {
247 return; 249 return;
248 } 250 }
249 } 251 }
250 } 252 }
251 253
252 scoped_ptr<extensions::Event> event( 254 scoped_ptr<extensions::Event> event(
253 new extensions::Event(histogram_value, event_name, args.Pass())); 255 new extensions::Event(histogram_value, event_name, std::move(args)));
254 event->restrict_to_browser_context = profile_; 256 event->restrict_to_browser_context = profile_;
255 extensions::EventRouter::Get(profile_) 257 extensions::EventRouter::Get(profile_)
256 ->DispatchEventToExtension(extension_id_, event.Pass()); 258 ->DispatchEventToExtension(extension_id_, std::move(event));
257 } 259 }
258 260
259 // The component IME extensions need to know the current screen type (e.g. 261 // The component IME extensions need to know the current screen type (e.g.
260 // lock screen, login screen, etc.) so that its on-screen keyboard page 262 // lock screen, login screen, etc.) so that its on-screen keyboard page
261 // won't open new windows/pages. See crbug.com/395621. 263 // won't open new windows/pages. See crbug.com/395621.
262 std::string GetCurrentScreenType() { 264 std::string GetCurrentScreenType() {
263 switch (chromeos::input_method::InputMethodManager::Get() 265 switch (chromeos::input_method::InputMethodManager::Get()
264 ->GetUISessionState()) { 266 ->GetUISessionState()) {
265 case chromeos::input_method::InputMethodManager::STATE_LOGIN_SCREEN: 267 case chromeos::input_method::InputMethodManager::STATE_LOGIN_SCREEN:
266 return "login"; 268 return "login";
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 languages, 326 languages,
325 false, // 3rd party IMEs are always not for login. 327 false, // 3rd party IMEs are always not for login.
326 component.options_page_url, 328 component.options_page_url,
327 component.input_view_url)); 329 component.input_view_url));
328 } 330 }
329 } 331 }
330 332
331 scoped_ptr<ui::IMEEngineObserver> observer( 333 scoped_ptr<ui::IMEEngineObserver> observer(
332 new ImeObserverChromeOS(extension_id, profile_)); 334 new ImeObserverChromeOS(extension_id, profile_));
333 chromeos::InputMethodEngine* engine = new chromeos::InputMethodEngine(); 335 chromeos::InputMethodEngine* engine = new chromeos::InputMethodEngine();
334 engine->Initialize(observer.Pass(), extension_id.c_str(), profile_); 336 engine->Initialize(std::move(observer), extension_id.c_str(), profile_);
335 engine_map_[extension_id] = engine; 337 engine_map_[extension_id] = engine;
336 chromeos::UserSessionManager::GetInstance() 338 chromeos::UserSessionManager::GetInstance()
337 ->GetDefaultIMEState(profile_) 339 ->GetDefaultIMEState(profile_)
338 ->AddInputMethodExtension(extension_id, descriptors, engine); 340 ->AddInputMethodExtension(extension_id, descriptors, engine);
339 341
340 return true; 342 return true;
341 } 343 }
342 344
343 void InputImeEventRouter::UnregisterAllImes(const std::string& extension_id) { 345 void InputImeEventRouter::UnregisterAllImes(const std::string& extension_id) {
344 std::map<std::string, IMEEngineHandlerInterface*>::iterator it = 346 std::map<std::string, IMEEngineHandlerInterface*>::iterator it =
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 error_ = kErrorEngineNotAvailable; 686 error_ = kErrorEngineNotAvailable;
685 return false; 687 return false;
686 } 688 }
687 689
688 engine->DeleteSurroundingText(params.context_id, params.offset, params.length, 690 engine->DeleteSurroundingText(params.context_id, params.offset, params.length,
689 &error_); 691 &error_);
690 return true; 692 return true;
691 } 693 }
692 694
693 } // namespace extensions 695 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698