From 5717c1426e51b6509fe28326614c1445f5187d1b Mon Sep 17 00:00:00 2001 From: Wes Johnston Date: Tue, 4 Oct 2011 15:43:31 -0700 Subject: [PATCH] Backout df94ebdc86fe and 0a11abbdc4d9 --- mobile/chrome/content/browser-ui.js | 144 ++++++------------ mobile/chrome/content/extensions.js | 38 +---- mobile/chrome/tests/Makefile.in | 1 - .../addons/browser_locale1/chrome.manifest | 4 - mobile/chrome/tests/browser_addons_locales.js | 64 -------- 5 files changed, 45 insertions(+), 206 deletions(-) delete mode 100644 mobile/chrome/tests/addons/browser_locale1/chrome.manifest delete mode 100644 mobile/chrome/tests/browser_addons_locales.js diff --git a/mobile/chrome/content/browser-ui.js b/mobile/chrome/content/browser-ui.js index f8a09c7e902..7788e0405be 100644 --- a/mobile/chrome/content/browser-ui.js +++ b/mobile/chrome/content/browser-ui.js @@ -438,7 +438,6 @@ var BrowserUI = { // We can delay some initialization until after startup. We wait until // the first page is shown, then dispatch a UIReadyDelayed event. - DelayedStartupHandler.init(); messageManager.addMessageListener("pageshow", function() { if (getBrowser().currentURI.spec == "about:blank") return; @@ -457,87 +456,62 @@ var BrowserUI = { return IndexedDB.receiveMessage(aMessage); }); - // Keep startup actions chunked into smaller units of work - DelayedStartupHandler.registerAction({ - desc: "Load panel XBL bindings, event listeners, and observers", - run: function() { - // Load xbl bindings - Elements.panelUI.hidden = false; + // Delay the panel UI and Sync initialization. + window.addEventListener("UIReadyDelayed", function(aEvent) { + window.removeEventListener(aEvent.type, arguments.callee, false); - // Listen tabs event - Elements.tabs.addEventListener("TabSelect", BrowserUI, true); - Elements.tabs.addEventListener("TabOpen", BrowserUI, true); - Elements.tabs.addEventListener("TabRemove", BrowserUI, true); + // We unhide the panelUI so the XBL and settings can initialize + Elements.panelUI.hidden = false; - Services.prefs.addObserver("browser.ui.layout.tablet", BrowserUI, false); - Services.obs.addObserver(BrowserSearch, "browser-search-engine-modified", false); - messageManager.addMessageListener("Browser:MozApplicationManifest", OfflineApps); + // Login Manager and Form History initialization + Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager); + Cc["@mozilla.org/satchel/form-history;1"].getService(Ci.nsIFormHistory2); - // If some add-ons were disabled during during an application update, alert user - let addonIDs = AddonManager.getStartupChanges("disabled"); - if (addonIDs.length > 0) { - let disabledStrings = Strings.browser.GetStringFromName("alertAddonsDisabled"); - let label = PluralForm.get(addonIDs.length, disabledStrings).replace("#1", addonIDs.length); - let image = "chrome://browser/skin/images/alert-addons-30.png"; - - let alerts = Cc["@mozilla.org/toaster-alerts-service;1"].getService(Ci.nsIAlertsService); - alerts.showAlertNotification(image, Strings.browser.GetStringFromName("alertAddons"), label, false, "", null); - } - } - }); + // Listen tabs event + Elements.tabs.addEventListener("TabSelect", BrowserUI, true); + Elements.tabs.addEventListener("TabOpen", BrowserUI, true); + Elements.tabs.addEventListener("TabRemove", BrowserUI, true); - DelayedStartupHandler.registerAction({ - desc: "Load LoginManager and FormHistory components", - run: function() { - Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager); - Cc["@mozilla.org/satchel/form-history;1"].getService(Ci.nsIFormHistory2); - } - }); - - - DelayedStartupHandler.registerAction({ - desc: "Initialize Extension, Downloads, and Console views", - run: function() { - // Init the tool panel views - ExtensionsView.init(); - DownloadsView.init(); - ConsoleView.init(); - } - }); + // Init the tool panel views + ExtensionsView.init(); + DownloadsView.init(); + ConsoleView.init(); #ifdef MOZ_SERVICES_SYNC - DelayedStartupHandler.registerAction({ - desc: "Initialize Sync", - run: function() { - // Init the sync system - WeaveGlue.init(); - } - }); + // Init the sync system + WeaveGlue.init(); #endif - DelayedStartupHandler.registerAction({ - desc: "Initialize helper objects", - run: function() { - BadgeHandlers.register(BrowserUI._edit.popup); - FormHelperUI.init(); - FindHelperUI.init(); - FullScreenVideo.init(); - NewTabPopup.init(); - WebappsUI.init(); - CapturePickerUI.init(); + Services.prefs.addObserver("browser.ui.layout.tablet", BrowserUI, false); + Services.obs.addObserver(BrowserSearch, "browser-search-engine-modified", false); + messageManager.addMessageListener("Browser:MozApplicationManifest", OfflineApps); + + // Init helpers + BadgeHandlers.register(BrowserUI._edit.popup); + FormHelperUI.init(); + FindHelperUI.init(); + FullScreenVideo.init(); + NewTabPopup.init(); + WebappsUI.init(); + CapturePickerUI.init(); + + // If some add-ons were disabled during during an application update, alert user + let addonIDs = AddonManager.getStartupChanges("disabled"); + if (addonIDs.length > 0) { + let disabledStrings = Strings.browser.GetStringFromName("alertAddonsDisabled"); + let label = PluralForm.get(addonIDs.length, disabledStrings).replace("#1", addonIDs.length); + let image = "chrome://browser/skin/images/alert-addons-30.png"; + + let alerts = Cc["@mozilla.org/toaster-alerts-service;1"].getService(Ci.nsIAlertsService); + alerts.showAlertNotification(image, Strings.browser.GetStringFromName("alertAddons"), label, false, "", null); } - }); #ifdef MOZ_UPDATER - DelayedStartupHandler.registerAction( - desc: "Setup the updater service", - run: function() { - // Check for updates in progress - let updatePrompt = Cc["@mozilla.org/updates/update-prompt;1"].createInstance(Ci.nsIUpdatePrompt); - updatePrompt.checkForUpdates(); - } - }); + // Check for updates in progress + let updatePrompt = Cc["@mozilla.org/updates/update-prompt;1"].createInstance(Ci.nsIUpdatePrompt); + updatePrompt.checkForUpdates(); #endif + }, false); let panels = document.getElementById("panel-items"); let panelViews = { // Use strings to avoid lazy-loading objects too soon. @@ -1339,33 +1313,3 @@ var BrowserUI = { } } }; - - -let DelayedStartupHandler = { - init: function() { - window.addEventListener("UIReadyDelayed", this, false); - }, - - _actions: [], - registerAction: function(aAction) { - this._actions.push(aAction); - }, - - handleEvent: function(aEvent) { - window.removeEventListener("UIReadyDelayed", this, false); - this._processActions(); - }, - - _processActions: function() { - let action = this._actions.shift(); - if (action) { - let start = Date.now(); - action.run(); - let totalTime = Date.now() - start; -#ifndef MOZ_OFFICIAL_BRANDING - Services.console.logStringMessage("DelayedAction: " + action.desc + " (" + totalTime + "ms)"); -#endif - setTimeout(this._processActions.bind(this), 50); - } - } -} diff --git a/mobile/chrome/content/extensions.js b/mobile/chrome/content/extensions.js index 431cdb1edcd..423feaf0d5e 100644 --- a/mobile/chrome/content/extensions.js +++ b/mobile/chrome/content/extensions.js @@ -59,11 +59,6 @@ XPCOMUtils.defineLazyGetter(this, "AddonRepository", function() { return AddonRepository; }); -XPCOMUtils.defineLazyGetter(this, "NetUtil", function() { - Cu.import("resource://gre/modules/NetUtil.jsm"); - return NetUtil; -}); - var ExtensionsView = { _strings: {}, _list: null, @@ -421,34 +416,6 @@ var ExtensionsView = { aItem.setAttribute("opType", opType); }, - _getLocalesInAddon: function(aAddon, aCallback) { - if (!aCallback || typeof aCallback != "function") - throw "_getLocalesInAddon requires a callback function"; - - let uri = aAddon.getResourceURI("chrome.manifest"); - NetUtil.asyncFetch(uri, function(aStream, aResult, aRequest) { - var data = NetUtil.readInputStreamToString(aStream, aStream.available()); - let reg = new RegExp("locale browser ([a-zA-Z\-]*)", "g"); - let res = reg.exec(data) - let list = []; - while(res) { - if (list.indexOf(res[1]) == -1) - list.push(res[1]); - res = reg.exec(data); - } - if (aCallback) - aCallback(list); - }); - }, - - _resetLanguagePref: function(aAddon) { - this._getLocalesInAddon(aAddon, function(aLocales) { - let currentLocale = Services.prefs.getCharPref("general.useragent.locale"); - if (aLocales.indexOf(currentLocale) > -1) - Services.prefs.clearUserPref("general.useragent.locale"); - }); - }, - disable: function ev_disable(aItem) { let opType; if (aItem.getAttribute("type") == "search") { @@ -459,7 +426,7 @@ var ExtensionsView = { aItem.addon.userDisabled = true; aItem.setAttribute("isDisabled", true); } else if (aItem.getAttribute("type") == "locale") { - this._resetLanguagePref(aItem.addon); + Services.prefs.clearUserPref("general.useragent.locale"); aItem.addon.userDisabled = true; aItem.setAttribute("isDisabled", true); } else { @@ -508,9 +475,6 @@ var ExtensionsView = { } else { this._list.removeChild(aItem); } - - if (aItem.getAttribute("type") == "locale") - this._resetLanguagePref(aItem.addon); } }, diff --git a/mobile/chrome/tests/Makefile.in b/mobile/chrome/tests/Makefile.in index 60579c0f3a0..13fb01a3e09 100644 --- a/mobile/chrome/tests/Makefile.in +++ b/mobile/chrome/tests/Makefile.in @@ -56,7 +56,6 @@ _BROWSER_FILES = \ remote_formsZoom.js \ remote_vkb.js \ browser_addons.js \ - browser_addons_locales.js \ browser_appmenu.js \ browser_autocompletesearch.js\ browser_awesomescreen.js \ diff --git a/mobile/chrome/tests/addons/browser_locale1/chrome.manifest b/mobile/chrome/tests/addons/browser_locale1/chrome.manifest deleted file mode 100644 index a909200d5b0..00000000000 --- a/mobile/chrome/tests/addons/browser_locale1/chrome.manifest +++ /dev/null @@ -1,4 +0,0 @@ -locale mozapps te-st chrome # locale -locale browser te-st chrome # duplicate locale -locale browser te-st-a chrome # second locale -locale branding te-st-3 chrome # wrong component diff --git a/mobile/chrome/tests/browser_addons_locales.js b/mobile/chrome/tests/browser_addons_locales.js deleted file mode 100644 index 1d9bc1add66..00000000000 --- a/mobile/chrome/tests/browser_addons_locales.js +++ /dev/null @@ -1,64 +0,0 @@ -var localeList = serverRoot + "locales_list.sjs"; -var PREF_LOCALE_LIST = "extensions.getLocales.get.url"; - -Components.utils.import("resource://gre/modules/Services.jsm"); -Components.utils.import("resource://gre/modules/LocaleRepository.jsm"); -Components.utils.import("resource://gre/modules/AddonManager.jsm"); - -function test() { - waitForExplicitFinish(); - runNextTest(); -} - -function end_test() { - Services.prefs.clearUserPref(PREF_LOCALE_LIST); -} - -registerCleanupFunction(end_test); - -gTests.push({ - addon: null, - desc: "Test the values returned from _getLocalesInAddon", - run: function() { - Services.prefs.setCharPref(PREF_LOCALE_LIST, localeList); - LocaleRepository.getLocales(this.listLoaded.bind(this)); - }, - - listLoaded: function(aLocales) { - is(aLocales.length, 1, "Correct number of locales were found"); - aLocales[0].addon.install.addListener(this); - aLocales[0].addon.install.install(); - }, - - onInstallEnded: function(aInstall, aAddon) { - aInstall.removeListener(this); - this.addon = aAddon; - info("Installed " + aAddon.id); - - try { - ExtensionsView._getLocalesInAddon(aAddon, null); - ok(false, "_getLocalesInAddon should have thrown with a null callback"); - } catch(ex) { - ok(ex, "_getLocalesInAddon requires a callback") - } - - try { - ExtensionsView._getLocalesInAddon(aAddon, "foo"); - ok(false, "_getLocalesInAddons should have thrown without a non-function callback"); - } catch(ex) { - ok(ex, "_getLocalesInAddon requires the callback be a function") - } - - ExtensionsView._getLocalesInAddon(aAddon, this.gotLocales.bind(this)); - }, - - gotLocales: function(aLocales) { - is(aLocales.length, 2, "Correct number of locales were found"); - ok(aLocales.indexOf("te-st") > -1, "te-st locale found"); - ok(aLocales.indexOf("te-st-a") > -1, "te-st-a locale found"); - - // locales can't be restartless yet, so we can't really test the uninstall code - this.addon.install.cancel(); - runNextTest(); - } -});