Bug 861496 - Replace #ifdef MOZ_SYS_MSG by a preference. r=fabrice
authorKevin Grandon <kgrandon@mozilla.com>
Fri, 26 Apr 2013 12:17:25 +0200
changeset 140991 556eb3bb629852bbb3834adce7fac927e9ca77eb
parent 140990 8d69a81abff9f5d3eec4077251a2c9242c4c1e6f
child 140992 6c2e3ea6afa6ae4569322c0c50709b4802368436
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfabrice
bugs861496
milestone23.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 861496 - Replace #ifdef MOZ_SYS_MSG by a preference. r=fabrice
b2g/app/b2g.js
b2g/confvars.sh
configure.in
dom/activities/src/Activity.h
dom/apps/src/Webapps.jsm
dom/base/Navigator.cpp
dom/base/Navigator.h
dom/base/nsDOMClassInfo.cpp
modules/libpref/src/init/all.js
--- a/b2g/app/b2g.js
+++ b/b2g/app/b2g.js
@@ -512,16 +512,18 @@ pref("extensions.getAddons.cache.enabled
 
 // Context Menu
 pref("ui.click_hold_context_menus", true);
 pref("ui.click_hold_context_menus.delay", 750);
 
 // Enable device storage
 pref("device.storage.enabled", true);
 
+// Enable system message
+pref("dom.sysmsg.enabled", true);
 pref("media.plugins.enabled", false);
 pref("media.omx.enabled", true);
 
 // Disable printing (particularly, window.print())
 pref("dom.disable_window_print", true);
 
 // Disable window.showModalDialog
 pref("dom.disable_window_showModalDialog", true);
@@ -668,9 +670,9 @@ pref("general.useragent.enable_overrides
 pref("b2g.version", @MOZ_B2G_VERSION@);
 
 // Disable console buffering to save memory.
 pref("consoleservice.buffered", false);
 
 #ifdef MOZ_WIDGET_GONK
 // Performance testing suggests 2k is a better page size for SQLite.
 pref("toolkit.storage.pageSize", 2048);
-#endif
\ No newline at end of file
+#endif
--- a/b2g/confvars.sh
+++ b/b2g/confvars.sh
@@ -42,17 +42,16 @@ else
 MOZ_XULRUNNER=
 fi
 
 MOZ_MEDIA_NAVIGATOR=1
 
 MOZ_APP_ID={3c2e2abc-06d4-11e1-ac3b-374f68613e61}
 MOZ_EXTENSION_MANAGER=1
 
-MOZ_SYS_MSG=1
 MOZ_TIME_MANAGER=1
 
 MOZ_B2G_CERTDATA=1
 MOZ_PAY=1
 MOZ_TOOLKIT_SEARCH=
 MOZ_PLACES=
 MOZ_B2G=1
 MOZ_FOLD_LIBS=1
--- a/configure.in
+++ b/configure.in
@@ -4258,17 +4258,16 @@ NECKO_PROTOCOLS_DEFAULT="about data file
 USE_ARM_KUSER=
 BUILD_CTYPES=1
 MOZ_USE_NATIVE_POPUP_WINDOWS=
 MOZ_ANDROID_HISTORY=
 MOZ_WEBSMS_BACKEND=
 MOZ_ANDROID_WALLPAPER=
 MOZ_ANDROID_BEAM=
 ACCESSIBILITY=1
-MOZ_SYS_MSG=
 MOZ_TIME_MANAGER=
 MOZ_PAY=
 MOZ_AUDIO_CHANNEL_MANAGER=
 NSS_NO_LIBPKIX=
 
 case "$target_os" in
     mingw*)
         NS_ENABLE_TSF=1
@@ -7638,24 +7637,16 @@ MOZ_ARG_ENABLE_BOOL(b2g-bt,
     MOZ_B2G_BT=1,
     MOZ_B2G_BT= )
 if test -n "$MOZ_B2G_BT"; then
     AC_DEFINE(MOZ_B2G_BT)
 fi
 AC_SUBST(MOZ_B2G_BT)
 
 dnl ========================================================
-dnl = Enable Support for System Messages API
-dnl ========================================================
-if test -n "$MOZ_SYS_MSG"; then
-    AC_DEFINE(MOZ_SYS_MSG)
-fi
-AC_SUBST(MOZ_SYS_MSG)
-
-dnl ========================================================
 dnl = Enable Support for Time Manager API
 dnl ========================================================
 if test -n "$MOZ_TIME_MANAGER"; then
     AC_DEFINE(MOZ_TIME_MANAGER)
 fi
 AC_SUBST(MOZ_TIME_MANAGER)
 
 dnl ========================================================
--- a/dom/activities/src/Activity.h
+++ b/dom/activities/src/Activity.h
@@ -3,16 +3,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_activities_Activity_h
 #define mozilla_dom_activities_Activity_h
 
 #include "DOMRequest.h"
 #include "mozilla/dom/BindingDeclarations.h"
 #include "nsIActivityProxy.h"
+#include "mozilla/Preferences.h"
 
 #define NS_DOMACTIVITY_CID                          \
  {0x1c5b0930, 0xc90c, 0x4e9c, {0xaf, 0x4e, 0xb0, 0xb7, 0xa6, 0x59, 0xb4, 0xed}}
 
 #define NS_DOMACTIVITY_CONTRACTID "@mozilla.org/dom/activity;1"
 
 namespace mozilla {
 namespace dom {
@@ -23,21 +24,17 @@ public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(Activity, DOMRequest)
 
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
   static bool PrefEnabled()
   {
-#ifdef MOZ_SYS_MSG
-    return true;
-#else
-    return false;
-#endif
+    return Preferences::GetBool("dom.sysmsg.enabled", false);
   }
 
   static already_AddRefed<Activity>
   Constructor(const GlobalObject& aOwner,
               nsIDOMMozActivityOptions* aOptions,
               ErrorResult& aRv)
   {
     nsRefPtr<Activity> activity = new Activity();
--- a/dom/apps/src/Webapps.jsm
+++ b/dom/apps/src/Webapps.jsm
@@ -20,16 +20,24 @@ Cu.import("resource://gre/modules/Permis
 Cu.import("resource://gre/modules/OfflineCacheInstaller.jsm");
 Cu.import("resource://gre/modules/SystemMessagePermissionsChecker.jsm");
 Cu.import("resource://gre/modules/AppDownloadManager.jsm");
 
 function debug(aMsg) {
   //dump("-*-*- Webapps.jsm : " + aMsg + "\n");
 }
 
+let cachedSysMsgPref = null;
+function supportSystemMessages() {
+  if (_sysMsgPref === null) {
+    cachedSysMsgPref = Services.prefs.getBoolPref("dom.sysmsg.enabled");
+  }
+  return cachedSysMsgPref;
+}
+
 // Minimum delay between two progress events while downloading, in ms.
 const MIN_PROGRESS_EVENT_DELAY = 1000;
 
 const WEBAPP_RUNTIME = Services.appinfo.ID == "webapprt@mozilla.org";
 
 XPCOMUtils.defineLazyGetter(this, "NetUtil", function() {
   Cu.import("resource://gre/modules/NetUtil.jsm");
   return NetUtil;
@@ -175,31 +183,31 @@ this.DOMApplicationRegistry = {
 
   // Registers all the activities and system messages.
   registerAppsHandlers: function registerAppsHandlers(aRunUpdate) {
     this.notifyAppsRegistryStart();
     let ids = [];
     for (let id in this.webapps) {
       ids.push({ id: id });
     }
-#ifdef MOZ_SYS_MSG
-    this._processManifestForIds(ids, aRunUpdate);
-#else
-    // Read the CSPs. If MOZ_SYS_MSG is defined this is done on
-    // _processManifestForIds so as to not reading the manifests
-    // twice
-    this._readManifests(ids, (function readCSPs(aResults) {
-      aResults.forEach(function registerManifest(aResult) {
-        this.webapps[aResult.id].csp = aResult.manifest.csp || "";
-      }, this);
-    }).bind(this));
-
-    // Nothing else to do but notifying we're ready.
-    this.notifyAppsRegistryReady();
-#endif
+    if (supportSystemMessages()) {
+      this._processManifestForIds(ids, aRunUpdate);
+    } else {
+      // Read the CSPs. If MOZ_SYS_MSG is defined this is done on
+      // _processManifestForIds so as to not reading the manifests
+      // twice
+      this._readManifests(ids, (function readCSPs(aResults) {
+        aResults.forEach(function registerManifest(aResult) {
+          this.webapps[aResult.id].csp = aResult.manifest.csp || "";
+        }, this);
+      }).bind(this));
+
+      // Nothing else to do but notifying we're ready.
+      this.notifyAppsRegistryReady();
+    }
   },
 
   updatePermissionsForApp: function updatePermissionsForApp(aId) {
     if (!this.webapps[aId]) {
       return;
     }
 
     // Install the permissions for this app, as if we were updating
@@ -434,17 +442,16 @@ this.DOMApplicationRegistry = {
       else
         onAppsLoaded();
 #else
       onAppsLoaded();
 #endif
     }).bind(this));
   },
 
-#ifdef MOZ_SYS_MSG
   // |aEntryPoint| is either the entry_point name or the null in which case we
   // use the root of the manifest.
   _registerSystemMessagesForEntryPoint: function(aManifest, aApp, aEntryPoint) {
     let root = aManifest;
     if (aEntryPoint && aManifest.entry_points[aEntryPoint]) {
       root = aManifest.entry_points[aEntryPoint];
     }
 
@@ -652,17 +659,16 @@ this.DOMApplicationRegistry = {
         app.name = manifest.name;
         app.csp = manifest.csp || "";
         this._registerSystemMessages(manifest, app);
         appsToRegister.push({ manifest: manifest, app: app });
       }, this);
       this._registerActivitiesForApps(appsToRegister, aRunUpdate);
     }).bind(this));
   },
-#endif
 
   observe: function(aSubject, aTopic, aData) {
     if (aTopic == "xpcom-shutdown") {
       this.messages.forEach((function(msgName) {
         ppmm.removeMessageListener(msgName, this);
       }).bind(this));
       Services.obs.removeObserver(this, "xpcom-shutdown");
       ppmm = null;
@@ -1279,26 +1285,27 @@ this.DOMApplicationRegistry = {
     return [toHexString(hash.charCodeAt(i)) for (i in hash)].join("");
   },
 
   // Updates the activities and system message handlers.
   // aOldManifest can be null if we don't have any handler to unregister.
   updateAppHandlers: function(aOldManifest, aNewManifest, aApp) {
     debug("updateAppHandlers: old=" + aOldManifest + " new=" + aNewManifest);
     this.notifyAppsRegistryStart();
-#ifdef MOZ_SYS_MSG
-    if (aOldManifest) {
-      this._unregisterActivities(aOldManifest, aApp);
+
+    if (supportSystemMessages()) {
+      if (aOldManifest) {
+        this._unregisterActivities(aOldManifest, aApp);
+      }
+      this._registerSystemMessages(aNewManifest, aApp);
+      this._registerActivities(aNewManifest, aApp, true);
+    } else {
+      // Nothing else to do but notifying we're ready.
+      this.notifyAppsRegistryReady();
     }
-    this._registerSystemMessages(aNewManifest, aApp);
-    this._registerActivities(aNewManifest, aApp, true);
-#else
-    // Nothing else to do but notifying we're ready.
-    this.notifyAppsRegistryReady();
-#endif
   },
 
   checkForUpdate: function(aData, aMm) {
     debug("checkForUpdate for " + aData.manifestURL);
 
     function sendError(aError) {
       aData.error = aError;
       aMm.sendAsyncMessage("Webapps:CheckForUpdate:Return:KO", aData);
@@ -2481,21 +2488,21 @@ this.DOMApplicationRegistry = {
       this._clearPrivateData(app.localId, false);
 
       // Then notify observers.
       Services.obs.notifyObservers(aMm, "webapps-uninstall", JSON.stringify(aData));
 
       let appNote = JSON.stringify(AppsUtils.cloneAppObject(app));
       appNote.id = id;
 
-#ifdef MOZ_SYS_MSG
-      this._readManifests([{ id: id }], (function unregisterManifest(aResult) {
-        this._unregisterActivities(aResult[0].manifest, app);
-      }).bind(this));
-#endif
+      if (supportSystemMessages()) {
+        this._readManifests([{ id: id }], (function unregisterManifest(aResult) {
+          this._unregisterActivities(aResult[0].manifest, app);
+        }).bind(this));
+      }
 
       let dir = this._getAppDir(id);
       try {
         dir.remove(true);
       } catch (e) {}
 
       delete this.webapps[id];
 
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -220,21 +220,19 @@ Navigator::Invalidate()
 #ifdef MOZ_B2G_BT
   if (mBluetooth) {
     mBluetooth = nullptr;
   }
 #endif
 
   mCameraManager = nullptr;
 
-#ifdef MOZ_SYS_MSG
   if (mMessagesManager) {
     mMessagesManager = nullptr;
   }
-#endif
 
 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
   if (mAudioChannelManager) {
     mAudioChannelManager = nullptr;
   }
 #endif
 
   uint32_t len = mDeviceStorageStores.Length();
@@ -1406,17 +1404,16 @@ Navigator::GetMozBluetooth(nsIDOMBluetoo
   bluetooth.forget(aBluetooth);
   return NS_OK;
 }
 #endif //MOZ_B2G_BT
 
 //*****************************************************************************
 //    nsNavigator::nsIDOMNavigatorSystemMessages
 //*****************************************************************************
-#ifdef MOZ_SYS_MSG
 nsresult
 Navigator::EnsureMessagesManager()
 {
   if (mMessagesManager) {
     return NS_OK;
   }
 
   nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
@@ -1434,44 +1431,43 @@ Navigator::EnsureMessagesManager()
   JS::Value prop_val = JSVAL_VOID;
   rv = gpi->Init(window, &prop_val);
   NS_ENSURE_SUCCESS(rv, rv);
 
   mMessagesManager = messageManager.forget();
 
   return NS_OK;
 }
-#endif
 
 NS_IMETHODIMP
 Navigator::MozHasPendingMessage(const nsAString& aType, bool *aResult)
 {
-#ifdef MOZ_SYS_MSG
+  if (!Preferences::GetBool("dom.sysmsg.enabled", false)) {
+    return NS_ERROR_NOT_IMPLEMENTED;
+  }
+
   *aResult = false;
   nsresult rv = EnsureMessagesManager();
   NS_ENSURE_SUCCESS(rv, rv);
 
   return mMessagesManager->MozHasPendingMessage(aType, aResult);
-#else
-  return NS_ERROR_NOT_IMPLEMENTED;
-#endif
 }
 
 NS_IMETHODIMP
 Navigator::MozSetMessageHandler(const nsAString& aType,
                                 nsIDOMSystemMessageCallback *aCallback)
 {
-#ifdef MOZ_SYS_MSG
+  if (!Preferences::GetBool("dom.sysmsg.enabled", false)) {
+    return NS_ERROR_NOT_IMPLEMENTED;
+  }
+
   nsresult rv = EnsureMessagesManager();
   NS_ENSURE_SUCCESS(rv, rv);
 
   return mMessagesManager->MozSetMessageHandler(aType, aCallback);
-#else
-  return NS_ERROR_NOT_IMPLEMENTED;
-#endif
 }
 
 //*****************************************************************************
 //    Navigator::nsIDOMNavigatorTime
 //*****************************************************************************
 #ifdef MOZ_TIME_MANAGER
 NS_IMETHODIMP
 Navigator::GetMozTime(nsIDOMMozTimeManager** aTime)
--- a/dom/base/Navigator.h
+++ b/dom/base/Navigator.h
@@ -181,20 +181,19 @@ public:
    */
   void SetWindow(nsPIDOMWindow *aInnerWindow);
 
   /**
    * Called when the inner window navigates to a new page.
    */
   void OnNavigation();
 
-#ifdef MOZ_SYS_MSG
   // Helper to initialize mMessagesManager.
   nsresult EnsureMessagesManager();
-#endif
+
   NS_DECL_NSIDOMNAVIGATORCAMERA
 
 private:
   bool CheckPermission(const char* type);
 
   nsRefPtr<nsMimeTypeArray> mMimeTypes;
   nsRefPtr<nsPluginArray> mPlugins;
   nsRefPtr<Geolocation> mGeolocation;
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -276,16 +276,18 @@
 #include "mozilla/dom/indexedDB/IDBKeyRange.h"
 #include "mozilla/dom/indexedDB/IDBIndex.h"
 
 using mozilla::dom::indexedDB::IDBWrapperCache;
 using mozilla::dom::workers::ResolveWorkerClasses;
 
 #include "nsIDOMMediaQueryList.h"
 
+#include "mozilla/dom/Activity.h"
+
 #include "nsDOMTouchEvent.h"
 
 #include "nsWrapperCacheInlines.h"
 #include "mozilla/dom/HTMLCollectionBinding.h"
 
 #include "BatteryManager.h"
 #include "nsIDOMPowerManager.h"
 #include "nsIDOMWakeLock.h"
@@ -1657,19 +1659,18 @@ nsDOMClassInfo::Init()
     DOM_CLASSINFO_MAP_ENTRY(nsIMozNavigatorMobileConnection)
     DOM_CLASSINFO_MAP_ENTRY(nsIMozNavigatorCellBroadcast)
     DOM_CLASSINFO_MAP_ENTRY(nsIMozNavigatorVoicemail)
 #endif
 #ifdef MOZ_B2G_BT
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMNavigatorBluetooth)
 #endif
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMNavigatorCamera)
-#ifdef MOZ_SYS_MSG
-    DOM_CLASSINFO_MAP_ENTRY(nsIDOMNavigatorSystemMessages)
-#endif
+    DOM_CLASSINFO_MAP_CONDITIONAL_ENTRY(nsIDOMNavigatorSystemMessages,
+                                        Activity::PrefEnabled())
 #ifdef MOZ_TIME_MANAGER
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozNavigatorTime)
 #endif
 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
     DOM_CLASSINFO_MAP_ENTRY(nsIMozNavigatorAudioChannelManager)
 #endif
 
   DOM_CLASSINFO_MAP_END
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -746,16 +746,19 @@ pref("dom.xbl_scopes", true);
 pref("dom.omit_components_in_content", true);
 
 // Don't use new input types
 pref("dom.experimental_forms", false);
 
 // Don't enable <input type=range> yet:
 pref("dom.experimental_forms_range", true);
 
+// Enables system messages and activities
+pref("dom.sysmsg.enabled", false);
+
 // Allocation Threshold for Workers
 pref("dom.workers.mem.gc_allocation_threshold_mb", 30);
 
 // Parsing perf prefs. For now just mimic what the old code did.
 #ifndef XP_WIN
 pref("content.sink.pending_event_mode", 0);
 #endif