Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; |
michael@0 | 6 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 7 | Cu.import("resource://services-sync/main.js"); |
michael@0 | 8 | |
michael@0 | 9 | let gProgressBar; |
michael@0 | 10 | let gCounter = 0; |
michael@0 | 11 | |
michael@0 | 12 | function onLoad(event) { |
michael@0 | 13 | Services.obs.addObserver(onEngineSync, "weave:engine:sync:finish", false); |
michael@0 | 14 | Services.obs.addObserver(onEngineSync, "weave:engine:sync:error", false); |
michael@0 | 15 | Services.obs.addObserver(onServiceSync, "weave:service:sync:finish", false); |
michael@0 | 16 | Services.obs.addObserver(onServiceSync, "weave:service:sync:error", false); |
michael@0 | 17 | |
michael@0 | 18 | gProgressBar = document.getElementById('uploadProgressBar'); |
michael@0 | 19 | |
michael@0 | 20 | if (Services.prefs.getPrefType("services.sync.firstSync") != Ci.nsIPrefBranch.PREF_INVALID) { |
michael@0 | 21 | gProgressBar.hidden = false; |
michael@0 | 22 | } |
michael@0 | 23 | else { |
michael@0 | 24 | gProgressBar.hidden = true; |
michael@0 | 25 | } |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function onUnload(event) { |
michael@0 | 29 | cleanUpObservers(); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | function cleanUpObservers() { |
michael@0 | 33 | try { |
michael@0 | 34 | Services.obs.removeObserver(onEngineSync, "weave:engine:sync:finish"); |
michael@0 | 35 | Services.obs.removeObserver(onEngineSync, "weave:engine:sync:error"); |
michael@0 | 36 | Services.obs.removeObserver(onServiceSync, "weave:service:sync:finish"); |
michael@0 | 37 | Services.obs.removeObserver(onServiceSync, "weave:service:sync:error"); |
michael@0 | 38 | } |
michael@0 | 39 | catch (e) { |
michael@0 | 40 | // may be double called by unload & exit. Ignore. |
michael@0 | 41 | } |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | function onEngineSync(subject, topic, data) { |
michael@0 | 45 | // The Clients engine syncs first. At this point we don't necessarily know |
michael@0 | 46 | // yet how many engines will be enabled, so we'll ignore the Clients engine |
michael@0 | 47 | // and evaluate how many engines are enabled when the first "real" engine |
michael@0 | 48 | // syncs. |
michael@0 | 49 | if (data == "clients") { |
michael@0 | 50 | return; |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | if (!gCounter && |
michael@0 | 54 | Services.prefs.getPrefType("services.sync.firstSync") != Ci.nsIPrefBranch.PREF_INVALID) { |
michael@0 | 55 | gProgressBar.max = Weave.Service.engineManager.getEnabled().length; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | gCounter += 1; |
michael@0 | 59 | gProgressBar.setAttribute("value", gCounter); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | function onServiceSync(subject, topic, data) { |
michael@0 | 63 | // To address the case where 0 engines are synced, we will fill the |
michael@0 | 64 | // progress bar so the user knows that the sync has finished. |
michael@0 | 65 | gProgressBar.setAttribute("value", gProgressBar.max); |
michael@0 | 66 | cleanUpObservers(); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | function closeTab() { |
michael@0 | 70 | window.close(); |
michael@0 | 71 | } |