diff --git a/b2g/installer/package-manifest.in b/b2g/installer/package-manifest.in index b5298c66eed..dbfb41b43e0 100644 --- a/b2g/installer/package-manifest.in +++ b/b2g/installer/package-manifest.in @@ -351,6 +351,8 @@ @BINPATH@/components/BrowserElementParent.js @BINPATH@/components/ContactManager.js @BINPATH@/components/ContactManager.manifest +@BINPATH@/components/NavigatorPropertyHelper.js +@BINPATH@/components/NavigatorPropertyHelper.manifest @BINPATH@/components/PermissionSettings.js @BINPATH@/components/PermissionSettings.manifest @BINPATH@/components/PermissionPromptService.js diff --git a/browser/installer/package-manifest.in b/browser/installer/package-manifest.in index 938dea995a4..de18d5c1101 100644 --- a/browser/installer/package-manifest.in +++ b/browser/installer/package-manifest.in @@ -514,6 +514,8 @@ @BINPATH@/components/PermissionSettings.manifest @BINPATH@/components/ContactManager.js @BINPATH@/components/ContactManager.manifest +@BINPATH@/components/NavigatorPropteryHelper.js +@BINPATH@/components/NavigatorPropertyHelper.manifest @BINPATH@/components/AlarmsManager.js @BINPATH@/components/AlarmsManager.manifest @BINPATH@/components/TCPSocket.js diff --git a/dom/base/Makefile.in b/dom/base/Makefile.in index b9b862b96b8..378705268a4 100644 --- a/dom/base/Makefile.in +++ b/dom/base/Makefile.in @@ -21,6 +21,8 @@ EXTRA_COMPONENTS = \ SiteSpecificUserAgent.manifest \ ConsoleAPI.js \ ConsoleAPI.manifest \ + NavigatorPropertyHelper.js \ + NavigatorPropertyHelper.manifest \ $(NULL) EXTRA_JS_MODULES = ConsoleAPIStorage.jsm \ diff --git a/dom/base/NavigatorPropertyHelper.js b/dom/base/NavigatorPropertyHelper.js new file mode 100644 index 00000000000..8db334ddc9a --- /dev/null +++ b/dom/base/NavigatorPropertyHelper.js @@ -0,0 +1,66 @@ +/* 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/. */ + +"use strict"; + +const DEBUG = false; +function debug(s) { dump("-*- NavigatorPropertyHelper: " + s + "\n"); } + +const Ci = Components.interfaces; +const Cu = Components.utils; + +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); +Cu.import("resource://gre/modules/Services.jsm"); + +function NavigatorPropertyHelper() { }; + +NavigatorPropertyHelper.prototype = { + + classID : Components.ID("{f0d03420-a0ce-11e2-9e96-0800200c9a66}"), + QueryInterface : XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakReference]), + + observe: function observe(subject, topic, data) { + if (DEBUG) debug("topic: " + topic + ", data: " + data); + let cm = Components.classes["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager); + switch (topic) { + case 'app-startup': + let enumerator = cm.enumerateCategory("JavaScript-navigator-property-maybe"); + while (enumerator.hasMoreElements()) { + let entry = enumerator.getNext().QueryInterface(Ci.nsISupportsCString); + let keyVal = cm.getCategoryEntry("JavaScript-navigator-property-maybe", entry).split(','); + try { + if (Services.prefs.getBoolPref(entry)) { + if (DEBUG) debug("enable: " + keyVal[0]); + cm.addCategoryEntry("JavaScript-navigator-property", keyVal[0], keyVal[1], false, false); + } + } catch (ex) { + if (DEBUG) debug("no pref found: " + entry); + } + Services.prefs.addObserver(entry, this, true); + } + break; + case 'nsPref:changed': + let keyVal = cm.getCategoryEntry("JavaScript-navigator-property-maybe", data).split(','); + let key = keyVal[0]; + let val = keyVal[1]; + try { + if (Services.prefs.getBoolPref(data)) { + if (DEBUG) debug("enable: " + key); + cm.addCategoryEntry("JavaScript-navigator-property", key, val, false, false); + } else { + if (DEBUG) debug("disable: " + key); + cm.deleteCategoryEntry("JavaScript-navigator-property", key, false); + } + } catch (ex) { + if (DEBUG) debug("no pref found: " + data); + cm.deleteCategoryEntry("JavaScript-navigator-property", key, false); + } + break; + default: + if (DEBUG) debug("unknown topic: " + topic); + } + }, +} + +this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NavigatorPropertyHelper]) diff --git a/dom/base/NavigatorPropertyHelper.manifest b/dom/base/NavigatorPropertyHelper.manifest new file mode 100644 index 00000000000..8d3c50e96a8 --- /dev/null +++ b/dom/base/NavigatorPropertyHelper.manifest @@ -0,0 +1,3 @@ +component {f0d03420-a0ce-11e2-9e96-0800200c9a66} NavigatorPropertyHelper.js +contract @mozilla.org/navigatorPropertyHelper;1 {f0d03420-a0ce-11e2-9e96-0800200c9a66} +category app-startup NavigatorPropertyHelper service,@mozilla.org/navigatorPropertyHelper;1 \ No newline at end of file diff --git a/dom/contacts/ContactManager.js b/dom/contacts/ContactManager.js index 28d54db45a5..c0ca8d16738 100644 --- a/dom/contacts/ContactManager.js +++ b/dom/contacts/ContactManager.js @@ -700,10 +700,6 @@ ContactManager.prototype = { }, init: function(aWindow) { - // Set navigator.mozContacts to null. - if (!Services.prefs.getBoolPref("dom.mozContacts.enabled")) - return null; - this.initHelper(aWindow, ["Contacts:Find:Return:OK", "Contacts:Find:Return:KO", "Contacts:Clear:Return:OK", "Contacts:Clear:Return:KO", "Contact:Save:Return:OK", "Contact:Save:Return:KO", diff --git a/dom/contacts/ContactManager.manifest b/dom/contacts/ContactManager.manifest index 6bbe3c5b33d..95226cc852f 100644 --- a/dom/contacts/ContactManager.manifest +++ b/dom/contacts/ContactManager.manifest @@ -22,4 +22,4 @@ category JavaScript-global-constructor mozContact @mozilla.org/contact;1 component {1d70322b-f11b-4f19-9586-7bf291f212aa} ContactManager.js contract @mozilla.org/contactManager;1 {1d70322b-f11b-4f19-9586-7bf291f212aa} -category JavaScript-navigator-property mozContacts @mozilla.org/contactManager;1 +category JavaScript-navigator-property-maybe dom.mozContacts.enabled mozContacts,@mozilla.org/contactManager;1 diff --git a/dom/contacts/tests/test_contacts_basics.html b/dom/contacts/tests/test_contacts_basics.html index 7eeefe87fcd..5459ee8c340 100644 --- a/dom/contacts/tests/test_contacts_basics.html +++ b/dom/contacts/tests/test_contacts_basics.html @@ -228,11 +228,13 @@ function checkContacts(contact1, contact2) { } } +function tests() { + var req; var index = 0; var mozContacts = window.navigator.mozContacts; - +ok(mozContacts, "mozContacts exists"); var steps = [ function () { ok(true, "Deleting database"); @@ -1245,11 +1247,12 @@ function permissionTest() { } } -var gContactsEnabled = SpecialPowers.getBoolPref("dom.mozContacts.enabled"); -SimpleTest.waitForExplicitFinish(); -addLoadEvent(permissionTest); +permissionTest(); +}; -ok(true, "test passed"); +var gContactsEnabled = SpecialPowers.getBoolPref("dom.mozContacts.enabled"); +addLoadEvent(tests); +SimpleTest.waitForExplicitFinish(); diff --git a/mobile/android/installer/package-manifest.in b/mobile/android/installer/package-manifest.in index 231d8c5e795..d2fd884e9ed 100644 --- a/mobile/android/installer/package-manifest.in +++ b/mobile/android/installer/package-manifest.in @@ -261,6 +261,8 @@ @BINPATH@/components/ConsoleAPI.js @BINPATH@/components/ContactManager.js @BINPATH@/components/ContactManager.manifest +@BINPATH@/components/NavigatorPropteryHelper.js +@BINPATH@/components/NavigatorPropertyHelper.manifest @BINPATH@/components/SettingsManager.js @BINPATH@/components/SettingsManager.manifest @BINPATH@/components/SettingsService.js