Bug 674725 - Part F - .mozSms returns null if the platform doesn't have SMS supports. r=smaug
authorMounir Lamouri <mounir.lamouri@gmail.com>
Mon, 21 Nov 2011 16:16:24 +0100
changeset 81570 8456fe6baadd504f3c25385263457f4bf7503350
parent 81569 85e1daf906070daf2ef756c2884b5ecbc2728908
child 81571 4ff83006b7bcd20da1623a5a6a02aa18de7c0596
push id628
push userclegnitto@mozilla.com
push dateWed, 21 Dec 2011 14:41:57 +0000
treeherdermozilla-aurora@24a61ad789e8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs674725
milestone11.0a1
Bug 674725 - Part F - .mozSms returns null if the platform doesn't have SMS supports. r=smaug
dom/base/Navigator.cpp
dom/base/Navigator.h
dom/sms/interfaces/nsISmsService.idl
dom/sms/src/android/SmsService.cpp
dom/sms/src/fallback/SmsService.cpp
dom/sms/tests/test_sms_basics.html
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -65,16 +65,17 @@
 #include "nsIJSContextStack.h"
 #include "nsCharSeparatedTokenizer.h"
 #include "nsContentUtils.h"
 #include "nsUnicharUtils.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Telemetry.h"
 #include "BatteryManager.h"
 #include "SmsManager.h"
+#include "nsISmsService.h"
 
 // This should not be in the namespace.
 DOMCI_DATA(Navigator, mozilla::dom::Navigator)
 
 namespace mozilla {
 namespace dom {
 
 static const char sJSStackContractID[] = "@mozilla.org/js/xpc/ContextStack;1";
@@ -830,21 +831,33 @@ Navigator::IsSmsAllowed() const
       return true;
     }
   }
 
   // The current page hasn't been whitelisted.
   return false;
 }
 
+bool
+Navigator::IsSmsSupported() const
+{
+  nsCOMPtr<nsISmsService> smsService = do_GetService(SMSSERVICE_CONTRACTID);
+  NS_ENSURE_TRUE(smsService, false);
+
+  bool result = false;
+  smsService->HasSupport(&result);
+
+  return result;
+}
+
 NS_IMETHODIMP
 Navigator::GetMozSms(nsIDOMMozSmsManager** aSmsManager)
 {
   if (!mSmsManager) {
-    if (!IsSmsAllowed()) {
+    if (!IsSmsSupported() || !IsSmsAllowed()) {
       *aSmsManager = nsnull;
       return NS_OK;
     }
 
     mSmsManager = new sms::SmsManager();
   }
 
   NS_ADDREF(*aSmsManager = mSmsManager);
--- a/dom/base/Navigator.h
+++ b/dom/base/Navigator.h
@@ -100,16 +100,17 @@ public:
   nsresult RefreshMIMEArray();
 
   static bool HasDesktopNotificationSupport();
 
   PRInt64 SizeOf() const;
 
 private:
   bool IsSmsAllowed() const;
+  bool IsSmsSupported() const;
 
   static bool sDoNotTrackEnabled;
 
   nsRefPtr<nsMimeTypeArray> mMimeTypes;
   nsRefPtr<nsPluginArray> mPlugins;
   nsRefPtr<nsGeolocation> mGeolocation;
   nsRefPtr<nsDesktopNotificationCenter> mNotification;
   nsRefPtr<battery::BatteryManager> mBatteryManager;
--- a/dom/sms/interfaces/nsISmsService.idl
+++ b/dom/sms/interfaces/nsISmsService.idl
@@ -32,16 +32,17 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsISupports.idl"
 
 %{C++
-#define NS_SMSSERVICE_CID { 0xd2d16fd7, 0x291e, 0x4dee, { 0xa2, 0xbf, 0x47, 0x75, 0xe5, 0x2e, 0xc3, 0xb3 } }
+#define NS_SMSSERVICE_CID { 0xbada3cb8, 0xa568, 0x4dff, { 0xb5, 0x43, 0x52, 0xbb, 0xb3, 0x14, 0x31, 0x21 } }
 #define SMSSERVICE_CONTRACTID "@mozilla.org/sms/smsservice;1"
 %}
 
-[scriptable, function, uuid(37bde671-23be-4713-9487-2e9e606c1ae4)]
+[scriptable, function, uuid(abc95960-c689-4985-a226-7c96d27e2cd8)]
 interface nsISmsService : nsISupports
 {
+  boolean hasSupport();
 };
--- a/dom/sms/src/android/SmsService.cpp
+++ b/dom/sms/src/android/SmsService.cpp
@@ -38,11 +38,18 @@
 #include "SmsService.h"
 
 namespace mozilla {
 namespace dom {
 namespace sms {
 
 NS_IMPL_ISUPPORTS1(SmsService, nsISmsService)
 
+NS_IMETHODIMP
+SmsService::HasSupport(bool* aHasSupport)
+{
+  *aHasSupport = true;
+  return NS_OK;
+}
+
 } // namespace sms
 } // namespace dom
 } // namespace mozilla
--- a/dom/sms/src/fallback/SmsService.cpp
+++ b/dom/sms/src/fallback/SmsService.cpp
@@ -38,11 +38,18 @@
 #include "SmsService.h"
 
 namespace mozilla {
 namespace dom {
 namespace sms {
 
 NS_IMPL_ISUPPORTS1(SmsService, nsISmsService)
 
+NS_IMETHODIMP
+SmsService::HasSupport(bool* aHasSupport)
+{
+  *aHasSupport = false;
+  return NS_OK;
+}
+
 } // namespace sms
 } // namespace dom
 } // namespace mozilla
--- a/dom/sms/tests/test_sms_basics.html
+++ b/dom/sms/tests/test_sms_basics.html
@@ -16,16 +16,22 @@
 /** Test for WebSMS **/
 
 function checkSmsDisabled() {
   ok('mozSms' in frames[0].navigator, "navigator.mozSms should exist");
   is(navigator.mozSms, null, "navigator.mozSms should return null");
 }
 
 function checkSmsEnabled() {
+  // WebSms is disabled on all platforms except Android for the moment.
+  if (navigator.appVersion.indexOf("Android") == -1) {
+    checkSmsDisabled();
+    return;
+  }
+
   ok('mozSms' in frames[0].navigator, "navigator.mozSms should exist");
   ok(frames[0].navigator.mozSms, "navigator.mozSms returns an object");
   ok(frames[0].navigator.mozSms instanceof MozSmsManager, "navigator.mozSms is an SmsManager object");
 }
 
 function checkInterface(aInterface) {
   ok(!(aInterface in window), aInterface + " should be prefixed");
   ok(("Moz" + aInterface) in window, aInterface + " should be prefixed");