OLD | NEW |
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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 141 |
142 void InputImeAPI::OnExtensionLoaded(content::BrowserContext* browser_context, | 142 void InputImeAPI::OnExtensionLoaded(content::BrowserContext* browser_context, |
143 const Extension* extension) { | 143 const Extension* extension) { |
144 // No-op if called multiple times. | 144 // No-op if called multiple times. |
145 ui::IMEBridge::Initialize(); | 145 ui::IMEBridge::Initialize(); |
146 | 146 |
147 // Set the preference kPrefNeverActivatedSinceLoaded true to indicate | 147 // Set the preference kPrefNeverActivatedSinceLoaded true to indicate |
148 // input.ime.activate API has been never called since loaded. | 148 // input.ime.activate API has been never called since loaded. |
149 Profile* profile = Profile::FromBrowserContext(browser_context); | 149 Profile* profile = Profile::FromBrowserContext(browser_context); |
150 ExtensionPrefs::Get(profile)->UpdateExtensionPref( | 150 ExtensionPrefs::Get(profile)->UpdateExtensionPref( |
151 extension->id(), kPrefNeverActivatedSinceLoaded, | 151 extension->id(), kPrefNeverActivatedSinceLoaded, new base::Value(true)); |
152 new base::FundamentalValue(true)); | |
153 } | 152 } |
154 | 153 |
155 void InputImeAPI::OnExtensionUnloaded(content::BrowserContext* browser_context, | 154 void InputImeAPI::OnExtensionUnloaded(content::BrowserContext* browser_context, |
156 const Extension* extension, | 155 const Extension* extension, |
157 UnloadedExtensionInfo::Reason reason) { | 156 UnloadedExtensionInfo::Reason reason) { |
158 InputImeEventRouter* event_router = | 157 InputImeEventRouter* event_router = |
159 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context)); | 158 GetInputImeEventRouter(Profile::FromBrowserContext(browser_context)); |
160 if (event_router) { | 159 if (event_router) { |
161 // Records the extension is not the last active IME engine. | 160 // Records the extension is not the last active IME engine. |
162 ExtensionPrefs::Get(Profile::FromBrowserContext(browser_context)) | 161 ExtensionPrefs::Get(Profile::FromBrowserContext(browser_context)) |
163 ->UpdateExtensionPref(extension->id(), kPrefLastActiveEngine, | 162 ->UpdateExtensionPref(extension->id(), kPrefLastActiveEngine, |
164 new base::FundamentalValue(false)); | 163 new base::Value(false)); |
165 event_router->DeleteInputMethodEngine(extension->id()); | 164 event_router->DeleteInputMethodEngine(extension->id()); |
166 } | 165 } |
167 } | 166 } |
168 | 167 |
169 void InputImeAPI::OnListenerAdded(const EventListenerInfo& details) {} | 168 void InputImeAPI::OnListenerAdded(const EventListenerInfo& details) {} |
170 | 169 |
171 InputImeEventRouter::InputImeEventRouter(Profile* profile) | 170 InputImeEventRouter::InputImeEventRouter(Profile* profile) |
172 : InputImeEventRouterBase(profile), active_engine_(nullptr) {} | 171 : InputImeEventRouterBase(profile), active_engine_(nullptr) {} |
173 | 172 |
174 InputImeEventRouter::~InputImeEventRouter() { | 173 InputImeEventRouter::~InputImeEventRouter() { |
175 if (active_engine_) | 174 if (active_engine_) |
176 DeleteInputMethodEngine(active_engine_->GetExtensionId()); | 175 DeleteInputMethodEngine(active_engine_->GetExtensionId()); |
177 } | 176 } |
178 | 177 |
179 InputMethodEngineBase* InputImeEventRouter::GetActiveEngine( | 178 InputMethodEngineBase* InputImeEventRouter::GetActiveEngine( |
180 const std::string& extension_id) { | 179 const std::string& extension_id) { |
181 return (ui::IMEBridge::Get()->GetCurrentEngineHandler() && | 180 return (ui::IMEBridge::Get()->GetCurrentEngineHandler() && |
182 active_engine_ && | 181 active_engine_ && |
183 active_engine_->GetExtensionId() == extension_id) | 182 active_engine_->GetExtensionId() == extension_id) |
184 ? active_engine_ | 183 ? active_engine_ |
185 : nullptr; | 184 : nullptr; |
186 } | 185 } |
187 | 186 |
188 void InputImeEventRouter::SetActiveEngine(const std::string& extension_id) { | 187 void InputImeEventRouter::SetActiveEngine(const std::string& extension_id) { |
189 // Records the extension is the last active IME engine. | 188 // Records the extension is the last active IME engine. |
190 ExtensionPrefs::Get(GetProfile()) | 189 ExtensionPrefs::Get(GetProfile()) |
191 ->UpdateExtensionPref(extension_id, kPrefLastActiveEngine, | 190 ->UpdateExtensionPref(extension_id, kPrefLastActiveEngine, |
192 new base::FundamentalValue(true)); | 191 new base::Value(true)); |
193 if (active_engine_) { | 192 if (active_engine_) { |
194 if (active_engine_->GetExtensionId() == extension_id) { | 193 if (active_engine_->GetExtensionId() == extension_id) { |
195 active_engine_->Enable(std::string()); | 194 active_engine_->Enable(std::string()); |
196 ui::IMEBridge::Get()->SetCurrentEngineHandler(active_engine_); | 195 ui::IMEBridge::Get()->SetCurrentEngineHandler(active_engine_); |
197 return; | 196 return; |
198 } | 197 } |
199 // Records the extension is not the last active IME engine. | 198 // Records the extension is not the last active IME engine. |
200 ExtensionPrefs::Get(GetProfile()) | 199 ExtensionPrefs::Get(GetProfile()) |
201 ->UpdateExtensionPref(active_engine_->GetExtensionId(), | 200 ->UpdateExtensionPref(active_engine_->GetExtensionId(), |
202 kPrefLastActiveEngine, | 201 kPrefLastActiveEngine, new base::Value(false)); |
203 new base::FundamentalValue(false)); | |
204 DeleteInputMethodEngine(active_engine_->GetExtensionId()); | 202 DeleteInputMethodEngine(active_engine_->GetExtensionId()); |
205 } | 203 } |
206 | 204 |
207 std::unique_ptr<input_method::InputMethodEngine> engine( | 205 std::unique_ptr<input_method::InputMethodEngine> engine( |
208 new input_method::InputMethodEngine()); | 206 new input_method::InputMethodEngine()); |
209 std::unique_ptr<InputMethodEngineBase::Observer> observer( | 207 std::unique_ptr<InputMethodEngineBase::Observer> observer( |
210 new ImeObserverNonChromeOS(extension_id, GetProfile())); | 208 new ImeObserverNonChromeOS(extension_id, GetProfile())); |
211 engine->Initialize(std::move(observer), extension_id.c_str(), GetProfile()); | 209 engine->Initialize(std::move(observer), extension_id.c_str(), GetProfile()); |
212 engine->Enable(std::string()); | 210 engine->Enable(std::string()); |
213 active_engine_ = engine.release(); | 211 active_engine_ = engine.release(); |
(...skipping 30 matching lines...) Expand all Loading... |
244 &never_activated_since_loaded) && | 242 &never_activated_since_loaded) && |
245 never_activated_since_loaded && | 243 never_activated_since_loaded && |
246 prefs->ReadPrefAsBoolean(extension_id(), kPrefLastActiveEngine, | 244 prefs->ReadPrefAsBoolean(extension_id(), kPrefLastActiveEngine, |
247 &last_active_ime_engine) && | 245 &last_active_ime_engine) && |
248 last_active_ime_engine) { | 246 last_active_ime_engine) { |
249 // If the extension is the last active IME engine, and the API is called at | 247 // If the extension is the last active IME engine, and the API is called at |
250 // loading the extension, we can tell the API is called from restarting | 248 // loading the extension, we can tell the API is called from restarting |
251 // chrome. No need for user gesture checking. | 249 // chrome. No need for user gesture checking. |
252 event_router->SetActiveEngine(extension_id()); | 250 event_router->SetActiveEngine(extension_id()); |
253 ExtensionPrefs::Get(profile)->UpdateExtensionPref( | 251 ExtensionPrefs::Get(profile)->UpdateExtensionPref( |
254 extension_id(), kPrefNeverActivatedSinceLoaded, | 252 extension_id(), kPrefNeverActivatedSinceLoaded, new base::Value(false)); |
255 new base::FundamentalValue(false)); | |
256 return RespondNow(NoArguments()); | 253 return RespondNow(NoArguments()); |
257 } | 254 } |
258 // The API has already been called at least once. | 255 // The API has already been called at least once. |
259 ExtensionPrefs::Get(profile)->UpdateExtensionPref( | 256 ExtensionPrefs::Get(profile)->UpdateExtensionPref( |
260 extension_id(), kPrefNeverActivatedSinceLoaded, | 257 extension_id(), kPrefNeverActivatedSinceLoaded, new base::Value(false)); |
261 new base::FundamentalValue(false)); | |
262 | 258 |
263 // Otherwise, this API is only allowed to be called from a user action. | 259 // Otherwise, this API is only allowed to be called from a user action. |
264 if (!user_gesture()) | 260 if (!user_gesture()) |
265 return RespondNow(Error(kErrorNotCalledFromUserAction)); | 261 return RespondNow(Error(kErrorNotCalledFromUserAction)); |
266 | 262 |
267 // Disable using the warning bubble for testing. | 263 // Disable using the warning bubble for testing. |
268 if (disable_bubble_for_testing_) { | 264 if (disable_bubble_for_testing_) { |
269 event_router->SetActiveEngine(extension_id()); | 265 event_router->SetActiveEngine(extension_id()); |
270 return RespondNow(NoArguments()); | 266 return RespondNow(NoArguments()); |
271 } | 267 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 if (!event_router) { | 308 if (!event_router) { |
313 Respond(Error(kErrorNoActiveEngine)); | 309 Respond(Error(kErrorNoActiveEngine)); |
314 return; | 310 return; |
315 } | 311 } |
316 event_router->SetActiveEngine(extension_id()); | 312 event_router->SetActiveEngine(extension_id()); |
317 | 313 |
318 if (status == ImeWarningBubblePermissionStatus::GRANTED_AND_NEVER_SHOW) { | 314 if (status == ImeWarningBubblePermissionStatus::GRANTED_AND_NEVER_SHOW) { |
319 // Updates the extension preference if user checks the 'Never show this | 315 // Updates the extension preference if user checks the 'Never show this |
320 // again' check box. So we can activate the extension directly next time. | 316 // again' check box. So we can activate the extension directly next time. |
321 ExtensionPrefs::Get(profile)->UpdateExtensionPref( | 317 ExtensionPrefs::Get(profile)->UpdateExtensionPref( |
322 extension_id(), kPrefWarningBubbleNeverShow, | 318 extension_id(), kPrefWarningBubbleNeverShow, new base::Value(true)); |
323 new base::FundamentalValue(true)); | |
324 } | 319 } |
325 | 320 |
326 Respond(NoArguments()); | 321 Respond(NoArguments()); |
327 } | 322 } |
328 | 323 |
329 ExtensionFunction::ResponseAction InputImeDeactivateFunction::Run() { | 324 ExtensionFunction::ResponseAction InputImeDeactivateFunction::Run() { |
330 if (!IsInputImeEnabled()) | 325 if (!IsInputImeEnabled()) |
331 return RespondNow(Error(kErrorAPIDisabled)); | 326 return RespondNow(Error(kErrorAPIDisabled)); |
332 | 327 |
333 InputMethodEngine* engine = | 328 InputMethodEngine* engine = |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 extension(), render_frame_host(), | 366 extension(), render_frame_host(), |
372 options.url.get() ? *options.url : url::kAboutBlankURL, | 367 options.url.get() ? *options.url : url::kAboutBlankURL, |
373 options.window_type == input_ime::WINDOW_TYPE_FOLLOWCURSOR | 368 options.window_type == input_ime::WINDOW_TYPE_FOLLOWCURSOR |
374 ? ui::ImeWindow::FOLLOW_CURSOR | 369 ? ui::ImeWindow::FOLLOW_CURSOR |
375 : ui::ImeWindow::NORMAL, | 370 : ui::ImeWindow::NORMAL, |
376 bounds, &error); | 371 bounds, &error); |
377 if (!frame_id) | 372 if (!frame_id) |
378 return RespondNow(Error(error)); | 373 return RespondNow(Error(error)); |
379 | 374 |
380 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 375 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
381 result->Set("frameId", new base::FundamentalValue(frame_id)); | 376 result->Set("frameId", new base::Value(frame_id)); |
382 | 377 |
383 return RespondNow(OneArgument(std::move(result))); | 378 return RespondNow(OneArgument(std::move(result))); |
384 } | 379 } |
385 | 380 |
386 ExtensionFunction::ResponseAction InputImeShowWindowFunction::Run() { | 381 ExtensionFunction::ResponseAction InputImeShowWindowFunction::Run() { |
387 if (!IsInputImeEnabled()) | 382 if (!IsInputImeEnabled()) |
388 return RespondNow(Error(kErrorAPIDisabled)); | 383 return RespondNow(Error(kErrorAPIDisabled)); |
389 | 384 |
390 InputMethodEngine* engine = | 385 InputMethodEngine* engine = |
391 GetActiveEngine(browser_context(), extension_id()); | 386 GetActiveEngine(browser_context(), extension_id()); |
(...skipping 17 matching lines...) Expand all Loading... |
409 return RespondNow(Error(kErrorNoActiveEngine)); | 404 return RespondNow(Error(kErrorNoActiveEngine)); |
410 | 405 |
411 std::unique_ptr<api::input_ime::HideWindow::Params> params( | 406 std::unique_ptr<api::input_ime::HideWindow::Params> params( |
412 api::input_ime::HideWindow::Params::Create(*args_)); | 407 api::input_ime::HideWindow::Params::Create(*args_)); |
413 EXTENSION_FUNCTION_VALIDATE(params.get()); | 408 EXTENSION_FUNCTION_VALIDATE(params.get()); |
414 engine->HideImeWindow(params->window_id); | 409 engine->HideImeWindow(params->window_id); |
415 return RespondNow(NoArguments()); | 410 return RespondNow(NoArguments()); |
416 } | 411 } |
417 | 412 |
418 } // namespace extensions | 413 } // namespace extensions |
OLD | NEW |