Bug 838146 part 5. Implement remaining MOZ_B2G_RIL-conditional WebIDL APIs on Navigator. r=smaug, sr=sicking
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 12 Jul 2013 10:36:22 -0400
changeset 138633 738f332df9f360905f21dda9e82f9729a4bf4127
parent 138632 e0fe0a7cc385f8312689749a2a2602b0d36d0981
child 138634 8fcca099a7c3f9ab6ec40240449009c781fa2a9b
push id24964
push userryanvm@gmail.com
push dateTue, 16 Jul 2013 20:04:09 +0000
treeherderautoland@fd10ead17ace [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, sicking
bugs838146
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 838146 part 5. Implement remaining MOZ_B2G_RIL-conditional WebIDL APIs on Navigator. r=smaug, sr=sicking
dom/base/Navigator.cpp
dom/base/Navigator.h
dom/bindings/Bindings.conf
dom/webidl/Navigator.webidl
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -1446,31 +1446,45 @@ Navigator::GetMozMobileMessage()
 
 //*****************************************************************************
 //    Navigator::nsIMozNavigatorCellBroadcast
 //*****************************************************************************
 
 NS_IMETHODIMP
 Navigator::GetMozCellBroadcast(nsIDOMMozCellBroadcast** aCellBroadcast)
 {
-  *aCellBroadcast = nullptr;
+  if (!mCellBroadcast &&
+      !CheckPermission("cellbroadcast")) {
+    *aCellBroadcast = nullptr;
+    return NS_OK;
+  }
 
+  ErrorResult rv;
+  NS_IF_ADDREF(*aCellBroadcast = GetMozCellBroadcast(rv));
+  return rv.ErrorCode();
+}
+
+nsIDOMMozCellBroadcast*
+Navigator::GetMozCellBroadcast(ErrorResult& aRv)
+{
+  // Callers (either the XPCOM method or the WebIDL binding) are responsible for
+  // the permission check here.
   if (!mCellBroadcast) {
-    NS_ENSURE_STATE(mWindow);
-
-    if (!CheckPermission("cellbroadcast")) {
-      return NS_OK;
+    if (!mWindow) {
+      aRv.Throw(NS_ERROR_UNEXPECTED);
+      return nullptr;
     }
 
-    nsresult rv = NS_NewCellBroadcast(mWindow, getter_AddRefs(mCellBroadcast));
-    NS_ENSURE_SUCCESS(rv, rv);
+    aRv = NS_NewCellBroadcast(mWindow, getter_AddRefs(mCellBroadcast));
+    if (aRv.Failed()) {
+      return nullptr;
+    }
   }
 
-  NS_ADDREF(*aCellBroadcast = mCellBroadcast);
-  return NS_OK;
+  return mCellBroadcast;
 }
 
 //*****************************************************************************
 //    nsNavigator::nsIDOMNavigatorTelephony
 //*****************************************************************************
 
 NS_IMETHODIMP
 Navigator::GetMozTelephony(nsIDOMTelephony** aTelephony)
@@ -1506,55 +1520,82 @@ Navigator::GetMozTelephony(ErrorResult& 
 
 //*****************************************************************************
 //    nsNavigator::nsINavigatorVoicemail
 //*****************************************************************************
 
 NS_IMETHODIMP
 Navigator::GetMozVoicemail(nsIDOMMozVoicemail** aVoicemail)
 {
-  *aVoicemail = nullptr;
+  if (!mVoicemail &&
+      !CheckPermission("voicemail")) {
+    *aVoicemail = nullptr;
+    return NS_OK;
+  }
 
+  ErrorResult rv;
+  NS_IF_ADDREF(*aVoicemail = GetMozVoicemail(rv));
+  return rv.ErrorCode();
+}
+
+nsIDOMMozVoicemail*
+Navigator::GetMozVoicemail(ErrorResult& aRv)
+{
+  // Callers (either the XPCOM method or the WebIDL binding) are responsible for
+  // the permission check here.
   if (!mVoicemail) {
-    NS_ENSURE_STATE(mWindow);
-    if (!CheckPermission("voicemail")) {
-      return NS_OK;
+    if (!mWindow) {
+      aRv.Throw(NS_ERROR_UNEXPECTED);
+      return nullptr;
     }
 
-    nsresult rv = NS_NewVoicemail(mWindow, getter_AddRefs(mVoicemail));
-    NS_ENSURE_SUCCESS(rv, rv);
+    aRv = NS_NewVoicemail(mWindow, getter_AddRefs(mVoicemail));
+    if (aRv.Failed()) {
+      return nullptr;
+    }
   }
 
-  NS_ADDREF(*aVoicemail = mVoicemail);
-  return NS_OK;
+  return mVoicemail;
 }
 
 //*****************************************************************************
 //    nsNavigator::nsIMozNavigatorIccManager
 //*****************************************************************************
 
 NS_IMETHODIMP
 Navigator::GetMozIccManager(nsIDOMMozIccManager** aIccManager)
 {
-  *aIccManager = nullptr;
+  if (!mIccManager &&
+      !CheckPermission("mobileconnection")) {
+    *aIccManager = nullptr;
+    return NS_OK;
+  }
 
+  ErrorResult rv;
+  NS_IF_ADDREF(*aIccManager = GetMozIccManager(rv));
+  return rv.ErrorCode();
+}
+
+nsIDOMMozIccManager*
+Navigator::GetMozIccManager(ErrorResult& aRv)
+{
+  // Callers (either the XPCOM method or the WebIDL binding) are responsible for
+  // the permission check here.
   if (!mIccManager) {
-    NS_ENSURE_STATE(mWindow);
-    NS_ENSURE_TRUE(mWindow->GetDocShell(), NS_OK);
-
-    if (!CheckPermission("mobileconnection")) {
-      return NS_OK;
+    if (!mWindow) {
+      aRv.Throw(NS_ERROR_UNEXPECTED);
+      return nullptr;
     }
+    NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr);
 
     mIccManager = new icc::IccManager();
     mIccManager->Init(mWindow);
   }
 
-  NS_ADDREF(*aIccManager = mIccManager);
-  return NS_OK;
+  return mIccManager;
 }
 
 #endif // MOZ_B2G_RIL
 
 #ifdef MOZ_GAMEPAD
 //*****************************************************************************
 //    Navigator::nsINavigatorGamepads
 //*****************************************************************************
@@ -1617,31 +1658,42 @@ Navigator::GetMozConnection()
 
 #ifdef MOZ_B2G_RIL
 //*****************************************************************************
 //    Navigator::nsINavigatorMobileConnection
 //*****************************************************************************
 NS_IMETHODIMP
 Navigator::GetMozMobileConnection(nsIDOMMozMobileConnection** aMobileConnection)
 {
-  *aMobileConnection = nullptr;
+  if (!mMobileConnection &&
+      !CheckPermission("mobileconnection") &&
+      !CheckPermission("mobilenetwork")) {
+    return NS_OK;
+  }
 
+  ErrorResult rv;
+  NS_IF_ADDREF(*aMobileConnection = GetMozMobileConnection(rv));
+  return rv.ErrorCode();
+}
+
+nsIDOMMozMobileConnection*
+Navigator::GetMozMobileConnection(ErrorResult& aRv)
+{
+  // Callers (either the XPCOM method or the WebIDL binding) are responsible for
+  // the permission check here.
   if (!mMobileConnection) {
-    NS_ENSURE_STATE(mWindow);
-    if (!CheckPermission("mobileconnection") &&
-        !CheckPermission("mobilenetwork")) {
-      return NS_OK;
+    if (!mWindow) {
+      aRv.Throw(NS_ERROR_UNEXPECTED);
+      return nullptr;
     }
-
     mMobileConnection = new network::MobileConnection();
     mMobileConnection->Init(mWindow);
   }
 
-  NS_ADDREF(*aMobileConnection = mMobileConnection);
-  return NS_OK;
+  return mMobileConnection;
 }
 #endif // MOZ_B2G_RIL
 
 #ifdef MOZ_B2G_BT
 //*****************************************************************************
 //    nsNavigator::nsIDOMNavigatorBluetooth
 //*****************************************************************************
 
@@ -1993,16 +2045,53 @@ Navigator::HasCameraSupport(JSContext* /
 #ifdef MOZ_B2G_RIL
 /* static */
 bool
 Navigator::HasTelephonySupport(JSContext* /* unused */, JSObject* aGlobal)
 {
   nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
   return win && telephony::Telephony::CheckPermission(win);
 }
+
+/* static */
+bool
+Navigator::HasMobileConnectionSupport(JSContext* /* unused */,
+                                      JSObject* aGlobal)
+{
+  nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
+  return win && (CheckPermission(win, "mobileconnection") ||
+                 CheckPermission(win, "mobilenetwork"));
+}
+
+/* static */
+bool
+Navigator::HasCellBroadcastSupport(JSContext* /* unused */,
+                                   JSObject* aGlobal)
+{
+  nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
+  return win && CheckPermission(win, "cellbroadcast");
+}
+
+/* static */
+bool
+Navigator::HasVoicemailSupport(JSContext* /* unused */,
+                               JSObject* aGlobal)
+{
+  nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
+  return win && CheckPermission(win, "voicemail");
+}
+
+/* static */
+bool
+Navigator::HasIccManagerSupport(JSContext* /* unused */,
+                                JSObject* aGlobal)
+{
+  nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
+  return win && CheckPermission(win, "mobileconnection");
+}
 #endif // MOZ_B2G_RIL
 
 /* static */
 already_AddRefed<nsPIDOMWindow>
 Navigator::GetWindowFromGlobal(JSObject* aGlobal)
 {
   nsCOMPtr<nsPIDOMWindow> win =
     do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(aGlobal));
--- a/dom/base/Navigator.h
+++ b/dom/base/Navigator.h
@@ -303,17 +303,21 @@ public:
   nsIDOMMozConnection* GetMozConnection();
   nsDOMCameraManager* GetMozCameras(ErrorResult& aRv);
   void MozSetMessageHandler(const nsAString& aType,
                             systemMessageCallback* aCallback,
                             ErrorResult& aRv);
   bool MozHasPendingMessage(const nsAString& aType, ErrorResult& aRv);
 #ifdef MOZ_B2G_RIL
   nsIDOMTelephony* GetMozTelephony(ErrorResult& aRv);
-#endif
+  nsIDOMMozMobileConnection* GetMozMobileConnection(ErrorResult& aRv);
+  nsIDOMMozCellBroadcast* GetMozCellBroadcast(ErrorResult& aRv);
+  nsIDOMMozVoicemail* GetMozVoicemail(ErrorResult& aRv);
+  nsIDOMMozIccManager* GetMozIccManager(ErrorResult& aRv);
+#endif // MOZ_B2G_RIL
 
 
   // WebIDL helper methods
   static bool HasBatterySupport(JSContext* /* unused*/, JSObject* /*unused */);
   static bool HasPowerSupport(JSContext* /* unused */, JSObject* aGlobal);
   static bool HasIdleSupport(JSContext* /* unused */, JSObject* aGlobal);
   static bool HasWakeLockSupport(JSContext* /* unused*/, JSObject* /*unused */);
   static bool HasDesktopNotificationSupport(JSContext* /* unused*/,
@@ -324,16 +328,24 @@ public:
   static bool HasSmsSupport(JSContext* /* unused */, JSObject* aGlobal);
   static bool HasMobileMessageSupport(JSContext* /* unused */,
                                       JSObject* aGlobal);
   static bool HasCameraSupport(JSContext* /* unused */,
                                JSObject* aGlobal);
 #ifdef MOZ_B2G_RIL
   static bool HasTelephonySupport(JSContext* /* unused */,
                                   JSObject* aGlobal);
+  static bool HasMobileConnectionSupport(JSContext* /* unused */,
+                                         JSObject* aGlobal);
+  static bool HasCellBroadcastSupport(JSContext* /* unused */,
+                                      JSObject* aGlobal);
+  static bool HasVoicemailSupport(JSContext* /* unused */,
+                                  JSObject* aGlobal);
+  static bool HasIccManagerSupport(JSContext* /* unused */,
+                                   JSObject* aGlobal);
 #endif // MOZ_B2G_RIL
   nsPIDOMWindow* GetParentObject() const
   {
     return GetWindow();
   }
 
 private:
   bool CheckPermission(const char* type);
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -1702,31 +1702,35 @@ addExternalIface('HitRegionOptions', nat
 addExternalIface('IDBDatabase', nativeType='nsIIDBDatabase')
 addExternalIface('IDBOpenDBRequest', nativeType='nsIIDBOpenDBRequest')
 addExternalIface('imgINotificationObserver', nativeType='imgINotificationObserver')
 addExternalIface('imgIRequest', nativeType='imgIRequest', notflattened=True)
 addExternalIface('LockedFile')
 addExternalIface('MediaList')
 addExternalIface('MenuBuilder', nativeType='nsIMenuBuilder', notflattened=True)
 addExternalIface('MozBoxObject', nativeType='nsIBoxObject')
+addExternalIface('MozCellBroadcast')
 addExternalIface('MozConnection', headerFile='nsIDOMConnection.h')
 addExternalIface('MozControllers', nativeType='nsIControllers')
 addExternalIface('MozFrameLoader', nativeType='nsIFrameLoader', notflattened=True)
+addExternalIface('MozIccManager', headerFile='nsIDOMIccManager.h')
+addExternalIface('MozMobileConnection', headerFile='nsIDOMMobileConnection.h')
 addExternalIface('MozMobileMessageManager', headerFile='nsIDOMMobileMessageManager.h')
 addExternalIface('MozObserver', nativeType='nsIObserver', notflattened=True)
 addExternalIface('MozPowerManager', headerFile='nsIDOMPowerManager.h')
 addExternalIface('MozRDFCompositeDataSource', nativeType='nsIRDFCompositeDataSource',
                  notflattened=True)
 addExternalIface('MozRDFResource', nativeType='nsIRDFResource', notflattened=True)
 addExternalIface('MozSmsManager', headerFile='nsIDOMSmsManager.h')
 addExternalIface('MozTelephony', nativeType='nsIDOMTelephony')
 addExternalIface('MozTreeBoxObject', nativeType='nsITreeBoxObject',
                  notflattened=True)
 addExternalIface('MozTreeColumn', nativeType='nsITreeColumn',
                  headerFile='nsITreeColumns.h')
+addExternalIface('MozVoicemail')
 addExternalIface('MozWakeLock', headerFile='nsIDOMWakeLock.h')
 addExternalIface('MozXULTemplateBuilder', nativeType='nsIXULTemplateBuilder')
 addExternalIface('nsIControllers', nativeType='nsIControllers')
 addExternalIface('nsIInputStreamCallback', nativeType='nsIInputStreamCallback',
                  headerFile='nsIAsyncInputStream.h')
 addExternalIface('nsIStreamListener', nativeType='nsIStreamListener', notflattened=True)
 addExternalIface('nsISupports', nativeType='nsISupports')
 addExternalIface('nsIEditor', nativeType='nsIEditor', notflattened=True)
--- a/dom/webidl/Navigator.webidl
+++ b/dom/webidl/Navigator.webidl
@@ -262,9 +262,37 @@ partial interface Navigator {
 
 #ifdef MOZ_B2G_RIL
 interface MozTelephony;
 // nsIDOMNavigatorTelephony
 partial interface Navigator {
   [Throws, Func="Navigator::HasTelephonySupport"]
   readonly attribute MozTelephony? mozTelephony;
 };
+
+// nsIMozNavigatorMobileConnection
+interface MozMobileConnection;
+partial interface Navigator {
+  [Throws, Func="Navigator::HasMobileConnectionSupport"]
+  readonly attribute MozMobileConnection mozMobileConnection;
+};
+
+// nsIMozNavigatorCellBroadcast
+interface MozCellBroadcast;
+partial interface Navigator {
+  [Throws, Func="Navigator::HasCellBroadcastSupport"]
+  readonly attribute MozCellBroadcast mozCellBroadcast;
+};
+
+// nsIMozNavigatorVoicemail
+interface MozVoicemail;
+partial interface Navigator {
+  [Throws, Func="Navigator::HasVoicemailSupport"]
+  readonly attribute MozVoicemail mozVoicemail;
+};
+
+// nsIMozNavigatorIccManager
+interface MozIccManager;
+partial interface Navigator {
+  [Throws, Func="Navigator::HasIccManagerSupport"]
+  readonly attribute MozIccManager? mozIccManager;
+};
 #endif // MOZ_B2G_RIL