From 8518e00ce1013978bebde2c8ddf36766c982ab87 Mon Sep 17 00:00:00 2001 From: Alessio Vanni Date: Thu, 4 Jul 2019 17:54:50 +0200 Subject: Make vapi-cloud its own file --- js/vapi-cloud.js | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 js/vapi-cloud.js (limited to 'js/vapi-cloud.js') diff --git a/js/vapi-cloud.js b/js/vapi-cloud.js new file mode 100644 index 0000000..b3d1b80 --- /dev/null +++ b/js/vapi-cloud.js @@ -0,0 +1,161 @@ +/******************************************************************************* + + ηMatrix - a browser extension to black/white list requests. + Copyright (C) 2014-2019 The uMatrix/uBlock Origin authors + Copyright (C) 2019 Alessio Vanni + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see {http://www.gnu.org/licenses/}. + + Home: https://gitlab.com/vannilla/ematrix + uMatrix Home: https://github.com/gorhill/uMatrix +*/ + +'use strict'; + +/******************************************************************************/ + +(function () { + const {classes: Cc, interfaces: Ci, utils: Cu} = Components; + Cu.import('resource://gre/modules/Services.jsm'); + + let vAPI = self.vAPI; // Guaranteed to be initialized by vapi-background.js + + vAPI.cloud = (function () { + let extensionBranchPath = 'extensions.' + location.host; + let cloudBranchPath = extensionBranchPath + '.cloudStorage'; + + // https://github.com/gorhill/uBlock/issues/80#issuecomment-132081658 + // We must use get/setComplexValue in order to properly handle strings + // with unicode characters. + let iss = Ci.nsISupportsString; + let argstr = Components.classes['@mozilla.org/supports-string;1'] + .createInstance(iss); + + let options = { + defaultDeviceName: '', + deviceName: '' + }; + + // User-supplied device name. + try { + options.deviceName = Services.prefs + .getBranch(extensionBranchPath + '.') + .getComplexValue('deviceName', iss) + .data; + } catch(ex) { + // Ignore + } + + var getDefaultDeviceName = function() { + var name = ''; + try { + name = Services.prefs + .getBranch('services.sync.client.') + .getComplexValue('name', iss) + .data; + } catch(ex) { + // Ignore + } + + return name || window.navigator.platform || window.navigator.oscpu; + }; + + let start = function (dataKeys) { + let extensionBranch = + Services.prefs.getBranch(extensionBranchPath + '.'); + let syncBranch = + Services.prefs.getBranch('services.sync.prefs.sync.'); + + // Mark config entries as syncable + argstr.data = ''; + let dataKey; + for (let i=0; i