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

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

Issue 2476493003: Remove FundamentalValue
Patch Set: Fix Created 4 years, 1 month 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 // This file is for non-chromeos (win & linux) functions, such as 5 // This file is for non-chromeos (win & linux) functions, such as
6 // chrome.input.ime.activate, chrome.input.ime.createWindow and 6 // chrome.input.ime.activate, chrome.input.ime.createWindow and
7 // chrome.input.ime.onSelectionChanged. 7 // chrome.input.ime.onSelectionChanged.
8 // TODO(azurewei): May refactor the code structure by using delegate or 8 // TODO(azurewei): May refactor the code structure by using delegate or
9 // redesign the API to remove this platform-specific file in the future. 9 // redesign the API to remove this platform-specific file in the future.
10 10
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 void InputImeAPI::OnExtensionLoaded(content::BrowserContext* browser_context, 131 void InputImeAPI::OnExtensionLoaded(content::BrowserContext* browser_context,
132 const Extension* extension) { 132 const Extension* extension) {
133 // No-op if called multiple times. 133 // No-op if called multiple times.
134 ui::IMEBridge::Initialize(); 134 ui::IMEBridge::Initialize();
135 135
136 // Set the preference kPrefNeverActivatedSinceLoaded true to indicate 136 // Set the preference kPrefNeverActivatedSinceLoaded true to indicate
137 // input.ime.activate API has been never called since loaded. 137 // input.ime.activate API has been never called since loaded.
138 Profile* profile = Profile::FromBrowserContext(browser_context); 138 Profile* profile = Profile::FromBrowserContext(browser_context);
139 ExtensionPrefs::Get(profile)->UpdateExtensionPref( 139 ExtensionPrefs::Get(profile)->UpdateExtensionPref(
140 extension->id(), kPrefNeverActivatedSinceLoaded, 140 extension->id(), kPrefNeverActivatedSinceLoaded,
141 new base::FundamentalValue(true)); 141 new base::Value(true));
142 } 142 }
143 143
144 void InputImeAPI::OnExtensionUnloaded(content::BrowserContext* browser_context, 144 void InputImeAPI::OnExtensionUnloaded(content::BrowserContext* browser_context,
145 const Extension* extension, 145 const Extension* extension,
146 UnloadedExtensionInfo::Reason reason) { 146 UnloadedExtensionInfo::Reason reason) {
147 InputImeEventRouter* event_router = 147 InputImeEventRouter* event_router =
148 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context)); 148 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context));
149 if (event_router) { 149 if (event_router) {
150 // Records the extension is not the last active IME engine. 150 // Records the extension is not the last active IME engine.
151 ExtensionPrefs::Get(Profile::FromBrowserContext(browser_context)) 151 ExtensionPrefs::Get(Profile::FromBrowserContext(browser_context))
152 ->UpdateExtensionPref(extension->id(), kPrefLastActiveEngine, 152 ->UpdateExtensionPref(extension->id(), kPrefLastActiveEngine,
153 new base::FundamentalValue(false)); 153 new base::Value(false));
154 event_router->DeleteInputMethodEngine(extension->id()); 154 event_router->DeleteInputMethodEngine(extension->id());
155 } 155 }
156 } 156 }
157 157
158 void InputImeAPI::OnListenerAdded(const EventListenerInfo& details) {} 158 void InputImeAPI::OnListenerAdded(const EventListenerInfo& details) {}
159 159
160 InputImeEventRouter::InputImeEventRouter(Profile* profile) 160 InputImeEventRouter::InputImeEventRouter(Profile* profile)
161 : InputImeEventRouterBase(profile), active_engine_(nullptr) {} 161 : InputImeEventRouterBase(profile), active_engine_(nullptr) {}
162 162
163 InputImeEventRouter::~InputImeEventRouter() { 163 InputImeEventRouter::~InputImeEventRouter() {
164 if (active_engine_) 164 if (active_engine_)
165 DeleteInputMethodEngine(active_engine_->GetExtensionId()); 165 DeleteInputMethodEngine(active_engine_->GetExtensionId());
166 } 166 }
167 167
168 InputMethodEngineBase* InputImeEventRouter::GetActiveEngine( 168 InputMethodEngineBase* InputImeEventRouter::GetActiveEngine(
169 const std::string& extension_id) { 169 const std::string& extension_id) {
170 return (ui::IMEBridge::Get()->GetCurrentEngineHandler() && 170 return (ui::IMEBridge::Get()->GetCurrentEngineHandler() &&
171 active_engine_ && 171 active_engine_ &&
172 active_engine_->GetExtensionId() == extension_id) 172 active_engine_->GetExtensionId() == extension_id)
173 ? active_engine_ 173 ? active_engine_
174 : nullptr; 174 : nullptr;
175 } 175 }
176 176
177 void InputImeEventRouter::SetActiveEngine(const std::string& extension_id) { 177 void InputImeEventRouter::SetActiveEngine(const std::string& extension_id) {
178 // Records the extension is the last active IME engine. 178 // Records the extension is the last active IME engine.
179 ExtensionPrefs::Get(GetProfile()) 179 ExtensionPrefs::Get(GetProfile())
180 ->UpdateExtensionPref(extension_id, kPrefLastActiveEngine, 180 ->UpdateExtensionPref(extension_id, kPrefLastActiveEngine,
181 new base::FundamentalValue(true)); 181 new base::Value(true));
182 if (active_engine_) { 182 if (active_engine_) {
183 if (active_engine_->GetExtensionId() == extension_id) { 183 if (active_engine_->GetExtensionId() == extension_id) {
184 active_engine_->Enable(std::string()); 184 active_engine_->Enable(std::string());
185 ui::IMEBridge::Get()->SetCurrentEngineHandler(active_engine_); 185 ui::IMEBridge::Get()->SetCurrentEngineHandler(active_engine_);
186 return; 186 return;
187 } 187 }
188 // Records the extension is not the last active IME engine. 188 // Records the extension is not the last active IME engine.
189 ExtensionPrefs::Get(GetProfile()) 189 ExtensionPrefs::Get(GetProfile())
190 ->UpdateExtensionPref(active_engine_->GetExtensionId(), 190 ->UpdateExtensionPref(active_engine_->GetExtensionId(),
191 kPrefLastActiveEngine, 191 kPrefLastActiveEngine,
192 new base::FundamentalValue(false)); 192 new base::Value(false));
193 DeleteInputMethodEngine(active_engine_->GetExtensionId()); 193 DeleteInputMethodEngine(active_engine_->GetExtensionId());
194 } 194 }
195 195
196 std::unique_ptr<input_method::InputMethodEngine> engine( 196 std::unique_ptr<input_method::InputMethodEngine> engine(
197 new input_method::InputMethodEngine()); 197 new input_method::InputMethodEngine());
198 std::unique_ptr<InputMethodEngineBase::Observer> observer( 198 std::unique_ptr<InputMethodEngineBase::Observer> observer(
199 new ImeObserverNonChromeOS(extension_id, GetProfile())); 199 new ImeObserverNonChromeOS(extension_id, GetProfile()));
200 engine->Initialize(std::move(observer), extension_id.c_str(), GetProfile()); 200 engine->Initialize(std::move(observer), extension_id.c_str(), GetProfile());
201 engine->Enable(std::string()); 201 engine->Enable(std::string());
202 active_engine_ = engine.release(); 202 active_engine_ = engine.release();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 never_activated_since_loaded && 234 never_activated_since_loaded &&
235 prefs->ReadPrefAsBoolean(extension_id(), kPrefLastActiveEngine, 235 prefs->ReadPrefAsBoolean(extension_id(), kPrefLastActiveEngine,
236 &last_active_ime_engine) && 236 &last_active_ime_engine) &&
237 last_active_ime_engine) { 237 last_active_ime_engine) {
238 // If the extension is the last active IME engine, and the API is called at 238 // If the extension is the last active IME engine, and the API is called at
239 // loading the extension, we can tell the API is called from restarting 239 // loading the extension, we can tell the API is called from restarting
240 // chrome. No need for user gesture checking. 240 // chrome. No need for user gesture checking.
241 event_router->SetActiveEngine(extension_id()); 241 event_router->SetActiveEngine(extension_id());
242 ExtensionPrefs::Get(profile)->UpdateExtensionPref( 242 ExtensionPrefs::Get(profile)->UpdateExtensionPref(
243 extension_id(), kPrefNeverActivatedSinceLoaded, 243 extension_id(), kPrefNeverActivatedSinceLoaded,
244 new base::FundamentalValue(false)); 244 new base::Value(false));
245 return RespondNow(NoArguments()); 245 return RespondNow(NoArguments());
246 } 246 }
247 // The API has already been called at least once. 247 // The API has already been called at least once.
248 ExtensionPrefs::Get(profile)->UpdateExtensionPref( 248 ExtensionPrefs::Get(profile)->UpdateExtensionPref(
249 extension_id(), kPrefNeverActivatedSinceLoaded, 249 extension_id(), kPrefNeverActivatedSinceLoaded,
250 new base::FundamentalValue(false)); 250 new base::Value(false));
251 251
252 // Otherwise, this API is only allowed to be called from a user action. 252 // Otherwise, this API is only allowed to be called from a user action.
253 if (!user_gesture()) 253 if (!user_gesture())
254 return RespondNow(Error(kErrorNotCalledFromUserAction)); 254 return RespondNow(Error(kErrorNotCalledFromUserAction));
255 255
256 // Disable using the warning bubble for testing. 256 // Disable using the warning bubble for testing.
257 if (disable_bubble_for_testing_) { 257 if (disable_bubble_for_testing_) {
258 event_router->SetActiveEngine(extension_id()); 258 event_router->SetActiveEngine(extension_id());
259 return RespondNow(NoArguments()); 259 return RespondNow(NoArguments());
260 } 260 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 Respond(Error(kErrorNoActiveEngine)); 302 Respond(Error(kErrorNoActiveEngine));
303 return; 303 return;
304 } 304 }
305 event_router->SetActiveEngine(extension_id()); 305 event_router->SetActiveEngine(extension_id());
306 306
307 if (status == ImeWarningBubblePermissionStatus::GRANTED_AND_NEVER_SHOW) { 307 if (status == ImeWarningBubblePermissionStatus::GRANTED_AND_NEVER_SHOW) {
308 // Updates the extension preference if user checks the 'Never show this 308 // Updates the extension preference if user checks the 'Never show this
309 // again' check box. So we can activate the extension directly next time. 309 // again' check box. So we can activate the extension directly next time.
310 ExtensionPrefs::Get(profile)->UpdateExtensionPref( 310 ExtensionPrefs::Get(profile)->UpdateExtensionPref(
311 extension_id(), kPrefWarningBubbleNeverShow, 311 extension_id(), kPrefWarningBubbleNeverShow,
312 new base::FundamentalValue(true)); 312 new base::Value(true));
313 } 313 }
314 314
315 Respond(NoArguments()); 315 Respond(NoArguments());
316 } 316 }
317 317
318 ExtensionFunction::ResponseAction InputImeDeactivateFunction::Run() { 318 ExtensionFunction::ResponseAction InputImeDeactivateFunction::Run() {
319 if (!IsInputImeEnabled()) 319 if (!IsInputImeEnabled())
320 return RespondNow(Error(kErrorAPIDisabled)); 320 return RespondNow(Error(kErrorAPIDisabled));
321 321
322 InputMethodEngine* engine = 322 InputMethodEngine* engine =
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 extension(), render_frame_host(), 360 extension(), render_frame_host(),
361 options.url.get() ? *options.url : url::kAboutBlankURL, 361 options.url.get() ? *options.url : url::kAboutBlankURL,
362 options.window_type == input_ime::WINDOW_TYPE_FOLLOWCURSOR 362 options.window_type == input_ime::WINDOW_TYPE_FOLLOWCURSOR
363 ? ui::ImeWindow::FOLLOW_CURSOR 363 ? ui::ImeWindow::FOLLOW_CURSOR
364 : ui::ImeWindow::NORMAL, 364 : ui::ImeWindow::NORMAL,
365 bounds, &error); 365 bounds, &error);
366 if (!frame_id) 366 if (!frame_id)
367 return RespondNow(Error(error)); 367 return RespondNow(Error(error));
368 368
369 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); 369 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue());
370 result->Set("frameId", new base::FundamentalValue(frame_id)); 370 result->Set("frameId", new base::Value(frame_id));
371 371
372 return RespondNow(OneArgument(std::move(result))); 372 return RespondNow(OneArgument(std::move(result)));
373 } 373 }
374 374
375 ExtensionFunction::ResponseAction InputImeShowWindowFunction::Run() { 375 ExtensionFunction::ResponseAction InputImeShowWindowFunction::Run() {
376 if (!IsInputImeEnabled()) 376 if (!IsInputImeEnabled())
377 return RespondNow(Error(kErrorAPIDisabled)); 377 return RespondNow(Error(kErrorAPIDisabled));
378 378
379 InputMethodEngine* engine = 379 InputMethodEngine* engine =
380 GetActiveEngine(browser_context(), extension_id()); 380 GetActiveEngine(browser_context(), extension_id());
(...skipping 17 matching lines...) Expand all
398 return RespondNow(Error(kErrorNoActiveEngine)); 398 return RespondNow(Error(kErrorNoActiveEngine));
399 399
400 std::unique_ptr<api::input_ime::HideWindow::Params> params( 400 std::unique_ptr<api::input_ime::HideWindow::Params> params(
401 api::input_ime::HideWindow::Params::Create(*args_)); 401 api::input_ime::HideWindow::Params::Create(*args_));
402 EXTENSION_FUNCTION_VALIDATE(params.get()); 402 EXTENSION_FUNCTION_VALIDATE(params.get());
403 engine->HideImeWindow(params->window_id); 403 engine->HideImeWindow(params->window_id);
404 return RespondNow(NoArguments()); 404 return RespondNow(NoArguments());
405 } 405 }
406 406
407 } // namespace extensions 407 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698