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

Unified Diff: chrome/browser/extensions/api/input_ime/input_ime_api_nonchromeos.cc

Issue 1847343002: Allow input.ime.activate() to be called from a non-user-action for the first time. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename |allow_to_active| as |warning_bubble_never_show|. Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/input_ime/input_ime_api_nonchromeos.cc
diff --git a/chrome/browser/extensions/api/input_ime/input_ime_api_nonchromeos.cc b/chrome/browser/extensions/api/input_ime/input_ime_api_nonchromeos.cc
index f60069b547aade20d8ee9189f9f51828226ea8f2..ac018a3c11842b36e3e639873c418cda3805d057 100644
--- a/chrome/browser/extensions/api/input_ime/input_ime_api_nonchromeos.cc
+++ b/chrome/browser/extensions/api/input_ime/input_ime_api_nonchromeos.cc
@@ -46,6 +46,10 @@ const char kErrorNotCalledFromUserAction[] =
// A preference determining whether to hide the warning bubble next time.
const char kPrefWarningBubbleNeverShow[] = "skip_ime_warning_bubble";
+// A preference to see whether it is the first time to call input.ime.activate
+// since the extension is loaded.
+const char kPrefImeActivatedCalledBefore[] = "ime_activate_called_before";
+
bool IsInputImeEnabled() {
return !base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableInputImeAPI);
@@ -123,6 +127,10 @@ void InputImeAPI::OnExtensionLoaded(content::BrowserContext* browser_context,
const Extension* extension) {
// No-op if called multiple times.
ui::IMEBridge::Initialize();
+ Profile* profile = Profile::FromBrowserContext(browser_context);
+ ExtensionPrefs::Get(profile)->UpdateExtensionPref(
+ extension->id(), kPrefImeActivatedCalledBefore,
+ new base::FundamentalValue(false));
}
void InputImeAPI::OnExtensionUnloaded(content::BrowserContext* browser_context,
@@ -194,7 +202,31 @@ ExtensionFunction::ResponseAction InputImeActivateFunction::Run() {
if (!event_router)
return RespondNow(Error(kErrorNoActiveEngine));
- // This API is only allowed to be called from a user action.
+ ExtensionPrefs* prefs = ExtensionPrefs::Get(profile);
+ bool warning_bubble_never_show = false;
+ bool ime_activated_called = false;
+
+ if (prefs->ReadPrefAsBoolean(extension_id(), kPrefImeActivatedCalledBefore,
+ &ime_activated_called) &&
+ prefs->ReadPrefAsBoolean(extension_id(), kPrefWarningBubbleNeverShow,
+ &warning_bubble_never_show) &&
+ !ime_activated_called &&
+ warning_bubble_never_show) {
+ // If it the first time that the extension call input.ime.activate() since
+ // loaded, we allow it to be automatically activated from a non user action.
+ event_router->SetActiveEngine(extension_id());
+ ExtensionPrefs::Get(profile)->UpdateExtensionPref(
+ extension_id(), kPrefImeActivatedCalledBefore,
+ new base::FundamentalValue(true));
+ return RespondNow(NoArguments());
+ }
+
+ ExtensionPrefs::Get(profile)->UpdateExtensionPref(
+ extension_id(), kPrefImeActivatedCalledBefore,
+ new base::FundamentalValue(true));
+
+ // If not the first time, this API is only allowed to be called from a user
+ // action.
if (!user_gesture())
return RespondNow(Error(kErrorNotCalledFromUserAction));
@@ -204,11 +236,7 @@ ExtensionFunction::ResponseAction InputImeActivateFunction::Run() {
return RespondNow(NoArguments());
}
- ExtensionPrefs* prefs = ExtensionPrefs::Get(profile);
- bool allowed_to_activate = false;
- if (prefs->ReadPrefAsBoolean(extension_id(), kPrefWarningBubbleNeverShow,
- &allowed_to_activate) &&
- allowed_to_activate) {
+ if (warning_bubble_never_show) {
// If user allows to activate the extension without showing the warning
// bubble, sets the active engine directly.
// Otherwise, the extension will be activated when the user presses the 'OK'
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698