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

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

Issue 2392693002: Rewrite simple uses of base::ListValue::Append(base::Value*) on CrOS. (Closed)
Patch Set: MakeUnique Created 4 years, 2 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
9 #include <memory>
8 #include <utility> 10 #include <utility>
9 11
10 #include "base/macros.h" 12 #include "base/macros.h"
11 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
12 #include "chrome/browser/chromeos/input_method/input_method_engine.h" 14 #include "chrome/browser/chromeos/input_method/input_method_engine.h"
13 #include "chrome/browser/chromeos/login/lock/screen_locker.h" 15 #include "chrome/browser/chromeos/login/lock/screen_locker.h"
14 #include "chrome/browser/chromeos/login/session/user_session_manager.h" 16 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
15 #include "chrome/browser/chromeos/profiles/profile_helper.h" 17 #include "chrome/browser/chromeos/profiles/profile_helper.h"
16 #include "chrome/browser/extensions/extension_service.h" 18 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/profiles/profile_manager.h" 19 #include "chrome/browser/profiles/profile_manager.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 input_ime::OnMenuItemActivated::kEventName, std::move(args)); 155 input_ime::OnMenuItemActivated::kEventName, std::move(args));
154 } 156 }
155 157
156 void OnCompositionBoundsChanged( 158 void OnCompositionBoundsChanged(
157 const std::vector<gfx::Rect>& bounds) override { 159 const std::vector<gfx::Rect>& bounds) override {
158 if (extension_id_.empty() || 160 if (extension_id_.empty() ||
159 !HasListener(OnCompositionBoundsChanged::kEventName)) 161 !HasListener(OnCompositionBoundsChanged::kEventName))
160 return; 162 return;
161 163
162 // Note: this is a private API event. 164 // Note: this is a private API event.
163 base::ListValue* bounds_list = new base::ListValue(); 165 auto bounds_list = base::MakeUnique<base::ListValue>();
164 for (size_t i = 0; i < bounds.size(); ++i) { 166 for (size_t i = 0; i < bounds.size(); ++i) {
165 base::DictionaryValue* bounds_value = new base::DictionaryValue(); 167 auto bounds_value = base::MakeUnique<base::DictionaryValue>();
166 bounds_value->SetInteger("x", bounds[i].x()); 168 bounds_value->SetInteger("x", bounds[i].x());
167 bounds_value->SetInteger("y", bounds[i].y()); 169 bounds_value->SetInteger("y", bounds[i].y());
168 bounds_value->SetInteger("w", bounds[i].width()); 170 bounds_value->SetInteger("w", bounds[i].width());
169 bounds_value->SetInteger("h", bounds[i].height()); 171 bounds_value->SetInteger("h", bounds[i].height());
170 bounds_list->Append(bounds_value); 172 bounds_list->Append(std::move(bounds_value));
171 } 173 }
172 174
173 if (bounds_list->GetSize() <= 0) 175 if (bounds_list->GetSize() <= 0)
174 return; 176 return;
175 std::unique_ptr<base::ListValue> args(new base::ListValue()); 177 std::unique_ptr<base::ListValue> args(new base::ListValue());
176 178
177 // The old extension code uses the first parameter to get the bounds of the 179 // The old extension code uses the first parameter to get the bounds of the
178 // first composition character, so for backward compatibility, add it here. 180 // first composition character, so for backward compatibility, add it here.
179 base::Value* first_value = NULL; 181 base::Value* first_value = NULL;
180 if (bounds_list->Get(0, &first_value)) 182 if (bounds_list->Get(0, &first_value))
181 args->Append(first_value->DeepCopy()); 183 args->Append(first_value->DeepCopy());
182 args->Append(bounds_list); 184 args->Append(std::move(bounds_list));
183 185
184 DispatchEventToExtension( 186 DispatchEventToExtension(
185 extensions::events::INPUT_METHOD_PRIVATE_ON_COMPOSITION_BOUNDS_CHANGED, 187 extensions::events::INPUT_METHOD_PRIVATE_ON_COMPOSITION_BOUNDS_CHANGED,
186 OnCompositionBoundsChanged::kEventName, std::move(args)); 188 OnCompositionBoundsChanged::kEventName, std::move(args));
187 } 189 }
188 190
189 private: 191 private:
190 // ui::ImeObserver overrides. 192 // ui::ImeObserver overrides.
191 void DispatchEventToExtension( 193 void DispatchEventToExtension(
192 extensions::events::HistogramValue histogram_value, 194 extensions::events::HistogramValue histogram_value,
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 return; 646 return;
645 InputMethodEngine* engine = 647 InputMethodEngine* engine =
646 GetActiveEngine(Profile::FromBrowserContext(details.browser_context), 648 GetActiveEngine(Profile::FromBrowserContext(details.browser_context),
647 details.extension_id); 649 details.extension_id);
648 // Notifies the IME extension for IME ready with onActivate/onFocus events. 650 // Notifies the IME extension for IME ready with onActivate/onFocus events.
649 if (engine) 651 if (engine)
650 engine->Enable(engine->GetActiveComponentId()); 652 engine->Enable(engine->GetActiveComponentId());
651 } 653 }
652 654
653 } // namespace extensions 655 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698