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

Side by Side Diff: chrome/browser/chromeos/extensions/input_method_api.cc

Issue 2038613003: Revert of ExtensionFunction: don't pass ownership of base::Value by raw pointer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 (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/chromeos/extensions/input_method_api.h" 5 #include "chrome/browser/chromeos/extensions/input_method_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
15 #include "base/memory/ptr_util.h"
16 #include "base/values.h" 15 #include "base/values.h"
17 #include "build/build_config.h" 16 #include "build/build_config.h"
18 #include "chrome/browser/chromeos/extensions/dictionary_event_router.h" 17 #include "chrome/browser/chromeos/extensions/dictionary_event_router.h"
19 #include "chrome/browser/chromeos/extensions/ime_menu_event_router.h" 18 #include "chrome/browser/chromeos/extensions/ime_menu_event_router.h"
20 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" 19 #include "chrome/browser/chromeos/extensions/input_method_event_router.h"
21 #include "chrome/browser/chromeos/input_method/input_method_util.h" 20 #include "chrome/browser/chromeos/input_method/input_method_util.h"
22 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" 21 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h"
23 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/spellchecker/spellcheck_factory.h" 23 #include "chrome/browser/spellchecker/spellcheck_factory.h"
25 #include "chrome/browser/spellchecker/spellcheck_service.h" 24 #include "chrome/browser/spellchecker/spellcheck_service.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 68
70 } // namespace 69 } // namespace
71 70
72 namespace extensions { 71 namespace extensions {
73 72
74 ExtensionFunction::ResponseAction 73 ExtensionFunction::ResponseAction
75 InputMethodPrivateGetInputMethodConfigFunction::Run() { 74 InputMethodPrivateGetInputMethodConfigFunction::Run() {
76 #if !defined(OS_CHROMEOS) 75 #if !defined(OS_CHROMEOS)
77 EXTENSION_FUNCTION_VALIDATE(false); 76 EXTENSION_FUNCTION_VALIDATE(false);
78 #else 77 #else
79 std::unique_ptr<base::DictionaryValue> output(new base::DictionaryValue()); 78 base::DictionaryValue* output = new base::DictionaryValue();
80 output->SetBoolean( 79 output->SetBoolean(
81 "isPhysicalKeyboardAutocorrectEnabled", 80 "isPhysicalKeyboardAutocorrectEnabled",
82 !base::CommandLine::ForCurrentProcess()->HasSwitch( 81 !base::CommandLine::ForCurrentProcess()->HasSwitch(
83 chromeos::switches::kDisablePhysicalKeyboardAutocorrect)); 82 chromeos::switches::kDisablePhysicalKeyboardAutocorrect));
84 output->SetBoolean("isImeMenuActivated", 83 output->SetBoolean("isImeMenuActivated",
85 base::FeatureList::IsEnabled(features::kOptInImeMenu) && 84 base::FeatureList::IsEnabled(features::kOptInImeMenu) &&
86 Profile::FromBrowserContext(browser_context()) 85 Profile::FromBrowserContext(browser_context())
87 ->GetPrefs() 86 ->GetPrefs()
88 ->GetBoolean(prefs::kLanguageImeMenuActivated)); 87 ->GetBoolean(prefs::kLanguageImeMenuActivated));
89 return RespondNow(OneArgument(std::move(output))); 88 return RespondNow(OneArgument(output));
90 #endif 89 #endif
91 } 90 }
92 91
93 ExtensionFunction::ResponseAction 92 ExtensionFunction::ResponseAction
94 InputMethodPrivateGetCurrentInputMethodFunction::Run() { 93 InputMethodPrivateGetCurrentInputMethodFunction::Run() {
95 #if !defined(OS_CHROMEOS) 94 #if !defined(OS_CHROMEOS)
96 EXTENSION_FUNCTION_VALIDATE(false); 95 EXTENSION_FUNCTION_VALIDATE(false);
97 #else 96 #else
98 chromeos::input_method::InputMethodManager* manager = 97 chromeos::input_method::InputMethodManager* manager =
99 chromeos::input_method::InputMethodManager::Get(); 98 chromeos::input_method::InputMethodManager::Get();
100 return RespondNow(OneArgument(base::MakeUnique<base::StringValue>( 99 return RespondNow(OneArgument(new base::StringValue(
101 manager->GetActiveIMEState()->GetCurrentInputMethod().id()))); 100 manager->GetActiveIMEState()->GetCurrentInputMethod().id())));
102 #endif 101 #endif
103 } 102 }
104 103
105 ExtensionFunction::ResponseAction 104 ExtensionFunction::ResponseAction
106 InputMethodPrivateSetCurrentInputMethodFunction::Run() { 105 InputMethodPrivateSetCurrentInputMethodFunction::Run() {
107 #if !defined(OS_CHROMEOS) 106 #if !defined(OS_CHROMEOS)
108 EXTENSION_FUNCTION_VALIDATE(false); 107 EXTENSION_FUNCTION_VALIDATE(false);
109 #else 108 #else
110 std::unique_ptr<SetCurrentInputMethod::Params> params( 109 std::unique_ptr<SetCurrentInputMethod::Params> params(
(...skipping 13 matching lines...) Expand all
124 } 123 }
125 return RespondNow(Error("Invalid input method id.")); 124 return RespondNow(Error("Invalid input method id."));
126 #endif 125 #endif
127 } 126 }
128 127
129 ExtensionFunction::ResponseAction 128 ExtensionFunction::ResponseAction
130 InputMethodPrivateGetInputMethodsFunction::Run() { 129 InputMethodPrivateGetInputMethodsFunction::Run() {
131 #if !defined(OS_CHROMEOS) 130 #if !defined(OS_CHROMEOS)
132 EXTENSION_FUNCTION_VALIDATE(false); 131 EXTENSION_FUNCTION_VALIDATE(false);
133 #else 132 #else
134 std::unique_ptr<base::ListValue> output(new base::ListValue()); 133 base::ListValue* output = new base::ListValue();
135 chromeos::input_method::InputMethodManager* manager = 134 chromeos::input_method::InputMethodManager* manager =
136 chromeos::input_method::InputMethodManager::Get(); 135 chromeos::input_method::InputMethodManager::Get();
137 chromeos::input_method::InputMethodUtil* util = manager->GetInputMethodUtil(); 136 chromeos::input_method::InputMethodUtil* util = manager->GetInputMethodUtil();
138 scoped_refptr<chromeos::input_method::InputMethodManager::State> ime_state = 137 scoped_refptr<chromeos::input_method::InputMethodManager::State> ime_state =
139 manager->GetActiveIMEState(); 138 manager->GetActiveIMEState();
140 std::unique_ptr<chromeos::input_method::InputMethodDescriptors> 139 std::unique_ptr<chromeos::input_method::InputMethodDescriptors>
141 input_methods = ime_state->GetActiveInputMethods(); 140 input_methods = ime_state->GetActiveInputMethods();
142 for (size_t i = 0; i < input_methods->size(); ++i) { 141 for (size_t i = 0; i < input_methods->size(); ++i) {
143 const chromeos::input_method::InputMethodDescriptor& input_method = 142 const chromeos::input_method::InputMethodDescriptor& input_method =
144 (*input_methods)[i]; 143 (*input_methods)[i];
145 base::DictionaryValue* val = new base::DictionaryValue(); 144 base::DictionaryValue* val = new base::DictionaryValue();
146 val->SetString("id", input_method.id()); 145 val->SetString("id", input_method.id());
147 val->SetString("name", util->GetInputMethodLongName(input_method)); 146 val->SetString("name", util->GetInputMethodLongName(input_method));
148 val->SetString("indicator", util->GetInputMethodShortName(input_method)); 147 val->SetString("indicator", util->GetInputMethodShortName(input_method));
149 output->Append(val); 148 output->Append(val);
150 } 149 }
151 return RespondNow(OneArgument(std::move(output))); 150 return RespondNow(OneArgument(output));
152 #endif 151 #endif
153 } 152 }
154 153
155 ExtensionFunction::ResponseAction 154 ExtensionFunction::ResponseAction
156 InputMethodPrivateFetchAllDictionaryWordsFunction::Run() { 155 InputMethodPrivateFetchAllDictionaryWordsFunction::Run() {
157 #if !defined(OS_CHROMEOS) 156 #if !defined(OS_CHROMEOS)
158 EXTENSION_FUNCTION_VALIDATE(false); 157 EXTENSION_FUNCTION_VALIDATE(false);
159 #else 158 #else
160 SpellcheckService* spellcheck = SpellcheckServiceFactory::GetForContext( 159 SpellcheckService* spellcheck = SpellcheckServiceFactory::GetForContext(
161 context_); 160 context_);
162 if (!spellcheck) { 161 if (!spellcheck) {
163 return RespondNow(Error("Spellcheck service not available.")); 162 return RespondNow(Error("Spellcheck service not available."));
164 } 163 }
165 SpellcheckCustomDictionary* dictionary = spellcheck->GetCustomDictionary(); 164 SpellcheckCustomDictionary* dictionary = spellcheck->GetCustomDictionary();
166 if (!dictionary->IsLoaded()) { 165 if (!dictionary->IsLoaded()) {
167 return RespondNow(Error("Custom dictionary not loaded yet.")); 166 return RespondNow(Error("Custom dictionary not loaded yet."));
168 } 167 }
169 168
170 const std::set<std::string>& words = dictionary->GetWords(); 169 const std::set<std::string>& words = dictionary->GetWords();
171 std::unique_ptr<base::ListValue> output(new base::ListValue()); 170 base::ListValue* output = new base::ListValue();
172 for (auto it = words.begin(); it != words.end(); ++it) { 171 for (auto it = words.begin(); it != words.end(); ++it) {
173 output->AppendString(*it); 172 output->AppendString(*it);
174 } 173 }
175 return RespondNow(OneArgument(std::move(output))); 174 return RespondNow(OneArgument(output));
176 #endif 175 #endif
177 } 176 }
178 177
179 ExtensionFunction::ResponseAction 178 ExtensionFunction::ResponseAction
180 InputMethodPrivateAddWordToDictionaryFunction::Run() { 179 InputMethodPrivateAddWordToDictionaryFunction::Run() {
181 #if !defined(OS_CHROMEOS) 180 #if !defined(OS_CHROMEOS)
182 EXTENSION_FUNCTION_VALIDATE(false); 181 EXTENSION_FUNCTION_VALIDATE(false);
183 #else 182 #else
184 std::unique_ptr<AddWordToDictionary::Params> params( 183 std::unique_ptr<AddWordToDictionary::Params> params(
185 AddWordToDictionary::Params::Create(*args_)); 184 AddWordToDictionary::Params::Create(*args_));
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> > 368 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> >
370 g_factory = LAZY_INSTANCE_INITIALIZER; 369 g_factory = LAZY_INSTANCE_INITIALIZER;
371 370
372 // static 371 // static
373 BrowserContextKeyedAPIFactory<InputMethodAPI>* 372 BrowserContextKeyedAPIFactory<InputMethodAPI>*
374 InputMethodAPI::GetFactoryInstance() { 373 InputMethodAPI::GetFactoryInstance() {
375 return g_factory.Pointer(); 374 return g_factory.Pointer();
376 } 375 }
377 376
378 } // namespace extensions 377 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698