Bug 920831 - MozInputMethod's init should only return undefined. r=bz
☠☠ backed out by 5e3d6f3b13a5 ☠ ☠
authorYuan Xulei <xyuan@mozilla.com>
Thu, 26 Sep 2013 15:10:56 +0800
changeset 149073 51a41b1393057cf040ae035f3496261a9581e23e
parent 149072 ca0f0d8b8cd6dec1c822b47052d62b0011dca40f
child 149074 5e3d6f3b13a536204705f4508a5a0f6bb98076b8
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersbz
bugs920831
milestone27.0a1
Bug 920831 - MozInputMethod's init should only return undefined. r=bz
dom/base/Navigator.cpp
dom/base/Navigator.h
dom/inputmethod/MozKeyboard.js
dom/tests/mochitest/general/test_interfaces.html
dom/webidl/InputMethod.webidl
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -1781,16 +1781,27 @@ bool Navigator::HasUserMediaSupport(JSCo
 /* static */
 bool Navigator::HasPushNotificationsSupport(JSContext* /* unused */,
                                             JSObject* aGlobal)
 {
   nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
   return win && Preferences::GetBool("services.push.enabled", false) && CheckPermission(win, "push");
 }
 
+#ifdef MOZ_B2G
+/* static */
+bool Navigator::HasInputMethodSupport(JSContext* /* unused */,
+                                      JSObject* aGlobal)
+{
+  nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
+  return Preferences::GetBool("dom.mozInputMethod.testing", false) ||
+         (win && CheckPermission(win, "keyboard"));
+}
+#endif
+
 /* static */
 already_AddRefed<nsPIDOMWindow>
 Navigator::GetWindowFromGlobal(JSObject* aGlobal)
 {
   nsCOMPtr<nsPIDOMWindow> win =
     do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(aGlobal));
   MOZ_ASSERT(!win || win->IsInnerWindow());
   return win.forget();
--- a/dom/base/Navigator.h
+++ b/dom/base/Navigator.h
@@ -295,16 +295,20 @@ public:
 #ifdef MOZ_MEDIA_NAVIGATOR
   static bool HasUserMediaSupport(JSContext* /* unused */,
                                   JSObject* /* unused */);
 #endif // MOZ_MEDIA_NAVIGATOR
 
   static bool HasPushNotificationsSupport(JSContext* /* unused */,
                                           JSObject* aGlobal);
 
+#ifdef MOZ_B2G
+  static bool HasInputMethodSupport(JSContext* /* unused */, JSObject* aGlobal);
+#endif
+
   nsPIDOMWindow* GetParentObject() const
   {
     return GetWindow();
   }
 
   virtual JSObject* WrapObject(JSContext* cx,
                                JS::Handle<JSObject*> scope) MOZ_OVERRIDE;
 
--- a/dom/inputmethod/MozKeyboard.js
+++ b/dom/inputmethod/MozKeyboard.js
@@ -194,18 +194,16 @@ MozKeyboard.prototype = {
 
   observe: function mozKeyboardObserve(subject, topic, data) {
     let wId = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
     if (wId == this.innerWindowID)
       this.uninit();
   }
 };
 
-const TESTING_ENABLED_PREF = "dom.mozInputMethod.testing";
-
 /*
  * A WeakMap to map input method iframe window to its active status.
  */
 let WindowMap = {
   // WeakMap of <window, boolean> pairs.
   _map: null,
 
   /*
@@ -312,34 +310,16 @@ MozInputMethod.prototype = {
     "classID": Components.ID("{4607330d-e7d2-40a4-9eb8-43967eae0142}"),
     "contractID": "@mozilla.org/b2g-inputmethod;1",
     "interfaces": [Ci.nsIInputMethod],
     "flags": Ci.nsIClassInfo.DOM_OBJECT,
     "classDescription": "B2G Input Method"
   }),
 
   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)
                             .getInterface(Ci.nsIDOMWindowUtils)
                             .currentInnerWindowID;
 
     Services.obs.addObserver(this, "inner-window-destroyed", false);
     cpmm.addMessageListener('Keyboard:FocusChange', this);
--- a/dom/tests/mochitest/general/test_interfaces.html
+++ b/dom/tests/mochitest/general/test_interfaces.html
@@ -319,17 +319,16 @@ var interfaceNamesInGlobalScope =
     "MozConnection",
     "mozContact",
     "MozContactChangeEvent",
     "MozCSSKeyframeRule",
     "MozCSSKeyframesRule",
     {name: "MozEmergencyCbModeEvent", b2g: true},
     {name: "MozIccManager", b2g: true},
     {name: "MozInputContext", b2g: true},
-    {name: "MozInputMethod", b2g: true},
     {name: "MozInputMethodManager", b2g: true},
     "MozMmsEvent",
     "MozMmsMessage",
     {name: "MozMobileConnection", b2g: true},
     "MozMobileMessageManager",
     "MozMobileMessageThread",
     "MozNamedAttrMap",
     {name: "MozOtaStatusEvent", b2g: true},
--- a/dom/webidl/InputMethod.webidl
+++ b/dom/webidl/InputMethod.webidl
@@ -1,16 +1,17 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
 [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
   readonly attribute MozInputMethodManager mgmt;
 
   // Fired when the input context changes, include changes from and to null.
   // The new InputContext instance will be available in the event
   // object under |inputcontext| property.  When it changes to null it