From caba7e406d9bee4f454d4ff51140e821f09aac5d Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Sat, 1 Dec 2018 23:40:09 +0100 Subject: [BASILISK] Make Basilisk front-end use Weave --- .../basilisk/base/content/browser-syncui.js | 35 +++++----------------- application/basilisk/base/content/browser.js | 2 +- 2 files changed, 8 insertions(+), 29 deletions(-) (limited to 'application/basilisk/base') diff --git a/application/basilisk/base/content/browser-syncui.js b/application/basilisk/base/content/browser-syncui.js index 51bcb15d5..64290a2a9 100644 --- a/application/basilisk/base/content/browser-syncui.js +++ b/application/basilisk/base/content/browser-syncui.js @@ -293,17 +293,13 @@ var gSyncUI = { */ openSetup: function SUI_openSetup(wizardType, entryPoint = "syncbutton") { - if (this.weaveService.fxAccountsEnabled) { - this.openPrefs(entryPoint); - } else { - let win = Services.wm.getMostRecentWindow("Weave:AccountSetup"); - if (win) - win.focus(); - else { - window.openDialog("chrome://browser/content/sync/setup.xul", - "weaveSetup", "centerscreen,chrome,resizable=no", - wizardType); - } + let win = Services.wm.getMostRecentWindow("Weave:AccountSetup"); + if (win) + win.focus(); + else { + window.openDialog("chrome://browser/content/sync/setup.xul", + "weaveSetup", "centerscreen,chrome,resizable=no", + wizardType); } }, @@ -328,23 +324,6 @@ var gSyncUI = { gFxAccounts.openSignInAgainPage(entryPoint); }, - openSyncedTabsPanel() { - let placement = CustomizableUI.getPlacementOfWidget("sync-button"); - let area = placement ? placement.area : CustomizableUI.AREA_NAVBAR; - let anchor = document.getElementById("sync-button") || - document.getElementById("PanelUI-menu-button"); - if (area == CustomizableUI.AREA_PANEL) { - // The button is in the panel, so we need to show the panel UI, then our - // subview. - PanelUI.show().then(() => { - PanelUI.showSubView("PanelUI-remotetabs", anchor, area); - }).catch(Cu.reportError); - } else { - // It is placed somewhere else - just try and show it. - PanelUI.showSubView("PanelUI-remotetabs", anchor, area); - } - }, - /* After Sync is initialized we perform a once-only check for the sync button being in "customize purgatory" and if so, move it to the panel. This is done primarily for profiles created before SyncedTabs landed, diff --git a/application/basilisk/base/content/browser.js b/application/basilisk/base/content/browser.js index d45956191..9fb997a42 100644 --- a/application/basilisk/base/content/browser.js +++ b/application/basilisk/base/content/browser.js @@ -6347,7 +6347,7 @@ function checkEmptyPageOrigin(browser = gBrowser.selectedBrowser, } function BrowserOpenSyncTabs() { - gSyncUI.openSyncedTabsPanel(); + switchToTabHavingURI("about:sync-tabs", true); } /** -- cgit v1.2.3 From aaaa4564b699fc6e8b059303987a56dbad42753f Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Sun, 2 Dec 2018 22:26:33 +0100 Subject: [BASILISK] Make CUI's PanelUI work with Weave. --- .../basilisk/base/content/browser-fxaccounts.js | 43 ++++++---------------- 1 file changed, 12 insertions(+), 31 deletions(-) (limited to 'application/basilisk/base') diff --git a/application/basilisk/base/content/browser-fxaccounts.js b/application/basilisk/base/content/browser-fxaccounts.js index 94a591f1e..cfd9758b6 100644 --- a/application/basilisk/base/content/browser-fxaccounts.js +++ b/application/basilisk/base/content/browser-fxaccounts.js @@ -153,11 +153,6 @@ var gFxAccounts = { profileInfoEnabled = Services.prefs.getBoolPref("identity.fxaccounts.profile_image.enabled"); } catch (e) { } - // Bail out if FxA is disabled. - if (!this.weave.fxAccountsEnabled) { - return Promise.resolve(); - } - this.panelUIFooter.hidden = false; // Make sure the button is disabled in customization mode. @@ -176,6 +171,7 @@ var gFxAccounts = { let defaultLabel = this.panelUIStatus.getAttribute("defaultlabel"); let errorLabel = this.panelUIStatus.getAttribute("errorlabel"); let unverifiedLabel = this.panelUIStatus.getAttribute("unverifiedlabel"); + let settingslabel = this.panelUIStatus.getAttribute("settingslabel"); // The localization string is for the signed in text, but it's the default text as well let defaultTooltiptext = this.panelUIStatus.getAttribute("signedinTooltiptext"); @@ -191,34 +187,19 @@ var gFxAccounts = { this.panelUIFooter.removeAttribute("fxastatus"); this.panelUIFooter.removeAttribute("fxaprofileimage"); this.panelUIAvatar.style.removeProperty("list-style-image"); - let showErrorBadge = false; - if (userData) { - // At this point we consider the user as logged-in (but still can be in an error state) - if (this.loginFailed) { - let tooltipDescription = this.strings.formatStringFromName("reconnectDescription", [userData.email], 1); - this.panelUIFooter.setAttribute("fxastatus", "error"); - this.panelUILabel.setAttribute("label", errorLabel); - this.panelUIStatus.setAttribute("tooltiptext", tooltipDescription); - showErrorBadge = true; - } else if (!userData.verified) { - let tooltipDescription = this.strings.formatStringFromName("verifyDescription", [userData.email], 1); - this.panelUIFooter.setAttribute("fxastatus", "error"); - this.panelUIFooter.setAttribute("unverified", "true"); - this.panelUILabel.setAttribute("label", unverifiedLabel); - this.panelUIStatus.setAttribute("tooltiptext", tooltipDescription); - showErrorBadge = true; - } else { - this.panelUIFooter.setAttribute("fxastatus", "signedin"); - this.panelUILabel.setAttribute("label", userData.email); - } - if (profileInfoEnabled) { - this.panelUIFooter.setAttribute("fxaprofileimage", "enabled"); - } + + if (Weave.Status.service == Weave.CLIENT_NOT_CONFIGURED) { + // Leave the default state + return; } - if (showErrorBadge) { - gMenuButtonBadgeManager.addBadge(gMenuButtonBadgeManager.BADGEID_FXA, "fxa-needs-authentication"); + + if (this.loginFailed) { + this.panelUIFooter.setAttribute("fxastatus", "error"); + this.panelUILabel.setAttribute("label", errorLabel); } else { - gMenuButtonBadgeManager.removeBadge(gMenuButtonBadgeManager.BADGEID_FXA); + this.panelUIFooter.setAttribute("fxastatus", "signedin"); + this.panelUILabel.setAttribute("label", settingslabel); + this.panelUIStatus.setAttribute("tooltiptext", ""); } } -- cgit v1.2.3 From 5df97df2fc3f0e9a3895da0d478d76694cf9c171 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Mon, 10 Dec 2018 12:27:23 +0100 Subject: Restore quota view/warnings to Basilisk. --- .../basilisk/base/content/browser-syncui.js | 47 ++++ application/basilisk/base/content/sync/quota.js | 279 +++++++++++++++++++++ application/basilisk/base/content/sync/quota.xul | 65 +++++ application/basilisk/base/jar.mn | 2 + 4 files changed, 393 insertions(+) create mode 100644 application/basilisk/base/content/sync/quota.js create mode 100644 application/basilisk/base/content/sync/quota.xul (limited to 'application/basilisk/base') diff --git a/application/basilisk/base/content/browser-syncui.js b/application/basilisk/base/content/browser-syncui.js index 64290a2a9..3a57140f2 100644 --- a/application/basilisk/base/content/browser-syncui.js +++ b/application/basilisk/base/content/browser-syncui.js @@ -19,6 +19,7 @@ var gSyncUI = { _obs: ["weave:service:sync:start", "weave:service:sync:finish", "weave:service:sync:error", + "weave:service:quota:remaining", "weave:service:setup-complete", "weave:service:login:start", "weave:service:login:finish", @@ -246,6 +247,21 @@ var gSyncUI = { this.updateUI(); }, + onQuotaNotice: function onQuotaNotice(subject, data) { + let title = this._stringBundle.GetStringFromName("warning.sync.quota.label"); + let description = this._stringBundle.GetStringFromName("warning.sync.quota.description"); + let buttons = []; + buttons.push(new Weave.NotificationButton( + this._stringBundle.GetStringFromName("error.sync.viewQuotaButton.label"), + this._stringBundle.GetStringFromName("error.sync.viewQuotaButton.accesskey"), + function() { gSyncUI.openQuotaDialog(); return true; } + )); + + let notification = new Weave.Notification( + title, description, null, Weave.Notifications.PRIORITY_WARNING, buttons); + Weave.Notifications.replaceTitle(notification); + }, + _getAppName: function () { let brand = new StringBundle("chrome://branding/locale/brand.properties"); return brand.get("brandShortName"); @@ -435,6 +451,32 @@ var gSyncUI = { } }, + onSyncError: function SUI_onSyncError() { + this.log.debug("onSyncError: login=${login}, sync=${sync}", Weave.Status); + let title = this._stringBundle.GetStringFromName("error.sync.title"); + let error = Weave.Utils.getErrorString(Weave.Status.sync); + let description = + this._stringBundle.formatStringFromName("error.sync.description", [error], 1); + let priority = Weave.Notifications.PRIORITY_WARNING; + let buttons = []; + + if (Weave.Status.sync == Weave.OVER_QUOTA) { + description = this._stringBundle.GetStringFromName("error.sync.quota.description"); + buttons.push(new Weave.NotificationButton( + this._stringBundle.GetStringFromName("error.sync.viewQuotaButton.label"), + this._stringBundle.GetStringFromName("error.sync.viewQuotaButton.accesskey"), + function() { gSyncUI.openQuotaDialog(); return true; } ) + ); + // Only show the notification bar on Quota error. the panel will show the rest. + let notification = + new Weave.Notification(title, description, null, priority, buttons); + Weave.Notifications.replaceTitle(notification); + } + + this.updateUI(); + }, + + observe: function SUI_observe(subject, topic, data) { this.log.debug("observed", topic); if (this._unloaded) { @@ -466,12 +508,17 @@ var gSyncUI = { // Do nothing. break; case "weave:ui:sync:error": + this.onSyncError(); + break; case "weave:service:setup-complete": case "weave:service:login:finish": case "weave:service:login:start": case "weave:service:start-over": this.updateUI(); break; + case "weave:service:quota:remaining": + this.onQuotaNotice(); + break; case "weave:ui:login:error": case "weave:service:login:error": this.onLoginError(); diff --git a/application/basilisk/base/content/sync/quota.js b/application/basilisk/base/content/sync/quota.js new file mode 100644 index 000000000..1285a8d54 --- /dev/null +++ b/application/basilisk/base/content/sync/quota.js @@ -0,0 +1,279 @@ +/* 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/. */ + +const Ci = Components.interfaces; +const Cc = Components.classes; +const Cr = Components.results; +const Cu = Components.utils; + +Cu.import("resource://services-sync/main.js"); +Cu.import("resource://gre/modules/DownloadUtils.jsm"); + +var gSyncQuota = { + + init: function init() { + this.bundle = document.getElementById("quotaStrings"); + let caption = document.getElementById("treeCaption"); + caption.firstChild.nodeValue = this.bundle.getString("quota.treeCaption.label"); + + gUsageTreeView.init(); + this.tree = document.getElementById("usageTree"); + this.tree.view = gUsageTreeView; + + this.loadData(); + }, + + loadData: function loadData() { + this._usage_req = Weave.Service.getStorageInfo(Weave.INFO_COLLECTION_USAGE, + function (error, usage) { + delete gSyncQuota._usage_req; + // displayUsageData handles null values, so no need to check 'error'. + gUsageTreeView.displayUsageData(usage); + }); + + let usageLabel = document.getElementById("usageLabel"); + let bundle = this.bundle; + + this._quota_req = Weave.Service.getStorageInfo(Weave.INFO_QUOTA, + function (error, quota) { + delete gSyncQuota._quota_req; + + if (error) { + usageLabel.value = bundle.getString("quota.usageError.label"); + return; + } + let used = gSyncQuota.convertKB(quota[0]); + if (!quota[1]) { + // No quota on the server. + usageLabel.value = bundle.getFormattedString( + "quota.usageNoQuota.label", used); + return; + } + let percent = Math.round(100 * quota[0] / quota[1]); + let total = gSyncQuota.convertKB(quota[1]); + usageLabel.value = bundle.getFormattedString( + "quota.usagePercentage.label", [percent].concat(used).concat(total)); + }); + }, + + onCancel: function onCancel() { + if (this._usage_req) { + this._usage_req.abort(); + } + if (this._quota_req) { + this._quota_req.abort(); + } + return true; + }, + + onAccept: function onAccept() { + let engines = gUsageTreeView.getEnginesToDisable(); + for each (let engine in engines) { + Weave.Service.engineManager.get(engine).enabled = false; + } + if (engines.length) { + // The 'Weave' object will disappear once the window closes. + let Service = Weave.Service; + Weave.Utils.nextTick(function() { Service.sync(); }); + } + return this.onCancel(); + }, + + convertKB: function convertKB(value) { + return DownloadUtils.convertByteUnits(value * 1024); + } + +}; + +var gUsageTreeView = { + + _ignored: {keys: true, + meta: true, + clients: true}, + + /* + * Internal data structures underlaying the tree. + */ + _collections: [], + _byname: {}, + + init: function init() { + let retrievingLabel = gSyncQuota.bundle.getString("quota.retrieving.label"); + for each (let engine in Weave.Service.engineManager.getEnabled()) { + if (this._ignored[engine.name]) + continue; + + // Some engines use the same pref, which means they can only be turned on + // and off together. We need to combine them here as well. + let existing = this._byname[engine.prefName]; + if (existing) { + existing.engines.push(engine.name); + continue; + } + + let obj = {name: engine.prefName, + title: this._collectionTitle(engine), + engines: [engine.name], + enabled: true, + sizeLabel: retrievingLabel}; + this._collections.push(obj); + this._byname[engine.prefName] = obj; + } + }, + + _collectionTitle: function _collectionTitle(engine) { + try { + return gSyncQuota.bundle.getString( + "collection." + engine.prefName + ".label"); + } catch (ex) { + return engine.Name; + } + }, + + /* + * Process the quota information as returned by info/collection_usage. + */ + displayUsageData: function displayUsageData(data) { + for each (let coll in this._collections) { + coll.size = 0; + // If we couldn't retrieve any data, just blank out the label. + if (!data) { + coll.sizeLabel = ""; + continue; + } + + for each (let engineName in coll.engines) + coll.size += data[engineName] || 0; + let sizeLabel = ""; + sizeLabel = gSyncQuota.bundle.getFormattedString( + "quota.sizeValueUnit.label", gSyncQuota.convertKB(coll.size)); + coll.sizeLabel = sizeLabel; + } + let sizeColumn = this.treeBox.columns.getNamedColumn("size"); + this.treeBox.invalidateColumn(sizeColumn); + }, + + /* + * Handle click events on the tree. + */ + onTreeClick: function onTreeClick(event) { + if (event.button == 2) + return; + + let cell = this.treeBox.getCellAt(event.clientX, event.clientY); + if (cell.col && cell.col.id == "enabled") + this.toggle(cell.row); + }, + + /* + * Toggle enabled state of an engine. + */ + toggle: function toggle(row) { + // Update the tree + let collection = this._collections[row]; + collection.enabled = !collection.enabled; + this.treeBox.invalidateRow(row); + + // Display which ones will be removed + let freeup = 0; + let toremove = []; + for each (collection in this._collections) { + if (collection.enabled) + continue; + toremove.push(collection.name); + freeup += collection.size; + } + + let caption = document.getElementById("treeCaption"); + if (!toremove.length) { + caption.className = ""; + caption.firstChild.nodeValue = gSyncQuota.bundle.getString( + "quota.treeCaption.label"); + return; + } + + // Tycho: toremove = [this._byname[coll].title for each (coll in toremove)]; + let toremovetitles = []; + for (let coll in toremove) { + toremovetitles.push(this._byname[coll].title); + } + + toremovetitles = toremovetitles.join(gSyncQuota.bundle.getString("quota.list.separator")); + caption.firstChild.nodeValue = gSyncQuota.bundle.getFormattedString( + "quota.removal.label", [toremovetitles]); + if (freeup) + caption.firstChild.nodeValue += gSyncQuota.bundle.getFormattedString( + "quota.freeup.label", gSyncQuota.convertKB(freeup)); + caption.className = "captionWarning"; + }, + + /* + * Return a list of engines (or rather their pref names) that should be + * disabled. + */ + getEnginesToDisable: function getEnginesToDisable() { + // Tycho: return [coll.name for each (coll in this._collections) if (!coll.enabled)]; + let engines = []; + for each (let coll in this._collections) { + if (!coll.enabled) { + engines.push(coll.name); + } + } + return engines; + }, + + // nsITreeView + + get rowCount() { + return this._collections.length; + }, + + getRowProperties: function(index) { return ""; }, + getCellProperties: function(row, col) { return ""; }, + getColumnProperties: function(col) { return ""; }, + isContainer: function(index) { return false; }, + isContainerOpen: function(index) { return false; }, + isContainerEmpty: function(index) { return false; }, + isSeparator: function(index) { return false; }, + isSorted: function() { return false; }, + canDrop: function(index, orientation, dataTransfer) { return false; }, + drop: function(row, orientation, dataTransfer) {}, + getParentIndex: function(rowIndex) {}, + hasNextSibling: function(rowIndex, afterIndex) { return false; }, + getLevel: function(index) { return 0; }, + getImageSrc: function(row, col) {}, + + getCellValue: function(row, col) { + return this._collections[row].enabled; + }, + + getCellText: function getCellText(row, col) { + let collection = this._collections[row]; + switch (col.id) { + case "collection": + return collection.title; + case "size": + return collection.sizeLabel; + default: + return ""; + } + }, + + setTree: function setTree(tree) { + this.treeBox = tree; + }, + + toggleOpenState: function(index) {}, + cycleHeader: function(col) {}, + selectionChanged: function() {}, + cycleCell: function(row, col) {}, + isEditable: function(row, col) { return false; }, + isSelectable: function (row, col) { return false; }, + setCellValue: function(row, col, value) {}, + setCellText: function(row, col, value) {}, + performAction: function(action) {}, + performActionOnRow: function(action, row) {}, + performActionOnCell: function(action, row, col) {} + +}; diff --git a/application/basilisk/base/content/sync/quota.xul b/application/basilisk/base/content/sync/quota.xul new file mode 100644 index 000000000..99e6ed78b --- /dev/null +++ b/application/basilisk/base/content/sync/quota.xul @@ -0,0 +1,65 @@ + + + + + + + + + + +%brandDTD; +%syncBrandDTD; +%syncQuotaDTD; +]> + + +