From 80c9c14437aa04c1cec61705b7a8402ec93cdce4 Mon Sep 17 00:00:00 2001 From: Yuan Xulei Date: Thu, 26 Sep 2013 15:10:56 +0800 Subject: [PATCH] Bug 920831 - MozInputMethod's init should only return undefined. r=bz --- dom/base/Navigator.cpp | 11 ++++++++++ dom/base/Navigator.h | 4 ++++ dom/inputmethod/MozKeyboard.js | 20 ------------------- .../mochitest/general/test_interfaces.html | 1 - dom/webidl/InputMethod.webidl | 1 + 5 files changed, 16 insertions(+), 21 deletions(-) diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index d5a968e5a9aa..4c9f615f216d 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -1786,6 +1786,17 @@ bool Navigator::HasPushNotificationsSupport(JSContext* /* unused */, return win && Preferences::GetBool("services.push.enabled", false) && CheckPermission(win, "push"); } +#ifdef MOZ_B2G +/* static */ +bool Navigator::HasInputMethodSupport(JSContext* /* unused */, + JSObject* aGlobal) +{ + nsCOMPtr win = GetWindowFromGlobal(aGlobal); + return Preferences::GetBool("dom.mozInputMethod.testing", false) || + (win && CheckPermission(win, "keyboard")); +} +#endif + /* static */ already_AddRefed Navigator::GetWindowFromGlobal(JSObject* aGlobal) diff --git a/dom/base/Navigator.h b/dom/base/Navigator.h index d92cd52a009a..1ec9b3de7789 100644 --- a/dom/base/Navigator.h +++ b/dom/base/Navigator.h @@ -300,6 +300,10 @@ public: static bool HasPushNotificationsSupport(JSContext* /* unused */, JSObject* aGlobal); +#ifdef MOZ_B2G + static bool HasInputMethodSupport(JSContext* /* unused */, JSObject* aGlobal); +#endif + nsPIDOMWindow* GetParentObject() const { return GetWindow(); diff --git a/dom/inputmethod/MozKeyboard.js b/dom/inputmethod/MozKeyboard.js index 0462944a5356..c46fbf93b688 100644 --- a/dom/inputmethod/MozKeyboard.js +++ b/dom/inputmethod/MozKeyboard.js @@ -199,8 +199,6 @@ MozKeyboard.prototype = { } }; -const TESTING_ENABLED_PREF = "dom.mozInputMethod.testing"; - /* * A WeakMap to map input method iframe window to its active status. */ @@ -317,24 +315,6 @@ MozInputMethod.prototype = { }), init: function mozInputMethodInit(win) { - // Check if we're in testing mode. - let isTesting = false; - try { - isTesting = Services.prefs.getBoolPref(TESTING_ENABLED_PREF); - } catch (e) {} - - // Don't bypass the permission check if not in testing mode. - if (!isTesting) { - let principal = win.document.nodePrincipal; - let perm = Services.perms - .testExactPermissionFromPrincipal(principal, "keyboard"); - if (perm != Ci.nsIPermissionManager.ALLOW_ACTION) { - dump("No permission to use the keyboard API for " + - principal.origin + "\n"); - return; - } - } - this._window = win; this._mgmt = new MozInputMethodManager(win); this.innerWindowID = win.QueryInterface(Ci.nsIInterfaceRequestor) diff --git a/dom/tests/mochitest/general/test_interfaces.html b/dom/tests/mochitest/general/test_interfaces.html index f418a4b058a6..1b1ad04c5d47 100644 --- a/dom/tests/mochitest/general/test_interfaces.html +++ b/dom/tests/mochitest/general/test_interfaces.html @@ -324,7 +324,6 @@ var interfaceNamesInGlobalScope = {name: "MozEmergencyCbModeEvent", b2g: true}, {name: "MozIccManager", b2g: true}, {name: "MozInputContext", b2g: true}, - {name: "MozInputMethod", b2g: true}, {name: "MozInputMethodManager", b2g: true}, "MozMmsEvent", "MozMmsMessage", diff --git a/dom/webidl/InputMethod.webidl b/dom/webidl/InputMethod.webidl index c28b3d5e0304..ee6a14b63c42 100644 --- a/dom/webidl/InputMethod.webidl +++ b/dom/webidl/InputMethod.webidl @@ -6,6 +6,7 @@ [JSImplementation="@mozilla.org/b2g-inputmethod;1", NavigatorProperty="mozInputMethod", + Func="Navigator::HasInputMethodSupport", Pref="dom.mozInputMethod.enabled"] interface MozInputMethod : EventTarget { // Input Method Manager contain a few global methods expose to apps