@@ -33,15 +33,7 @@ var commitHistoryURLPrefix = 'https://github.com/gorhill/httpswitchboard/commits
3333
3434/******************************************************************************/
3535
36- var getHTTPSB = function ( ) {
37- return chrome . extension . getBackgroundPage ( ) . HTTPSB ;
38- } ;
39-
40- /******************************************************************************/
41-
4236var backupUserDataToFile = function ( ) {
43- var httpsb = getHTTPSB ( ) ;
44-
4537 var allUserData = {
4638 timeStamp : Date . now ( ) ,
4739 version : '' ,
@@ -63,22 +55,22 @@ var backupUserDataToFile = function() {
6355
6456 var userBlacklistReady = function ( details ) {
6557 allUserData . ubiquitousBlacklist = details . content ;
66- httpsb . assets . get ( httpsb . userWhitelistPath , userWhitelistReady ) ;
58+ messaging . ask ( { what : 'readUserUbiquitousAllowRules' } , userWhitelistReady ) ;
6759 } ;
6860
6961 var ruleDataReady = function ( store ) {
7062 allUserData . version = store . version ;
7163 allUserData . scopes = store . scopes ;
7264 allUserData . remoteBlacklists = store . remoteBlacklists ;
73- httpsb . assets . get ( httpsb . userBlacklistPath , userBlacklistReady ) ;
65+ messaging . ask ( { what : 'readUserUbiquitousBlockRules' } , userBlacklistReady ) ;
7466 } ;
7567
7668 var userSettingsReady = function ( store ) {
7769 allUserData . userSettings = store ;
7870 chrome . storage . local . get ( [ 'version' , 'scopes' , 'remoteBlacklists' ] , ruleDataReady ) ;
7971 } ;
8072
81- chrome . storage . local . get ( httpsb . userSettings , userSettingsReady ) ;
73+ messaging . ask ( { what : 'readUserSettings' } , userSettingsReady ) ;
8274} ;
8375
8476/******************************************************************************/
@@ -99,7 +91,6 @@ var restoreUserDataFromFile = function() {
9991 } ;
10092
10193 var restoreBackup = function ( data ) {
102- var httpsb = getHTTPSB ( ) ;
10394 chrome . storage . local . set ( data . userSettings , doCountdown ) ;
10495 var store = {
10596 'version' : data . version ,
@@ -111,8 +102,18 @@ var restoreUserDataFromFile = function() {
111102 store . remoteBlacklists = data . remoteBlacklists ;
112103 }
113104 chrome . storage . local . set ( store , doCountdown ) ;
114- httpsb . assets . put ( httpsb . userBlacklistPath , data . ubiquitousBlacklist , doCountdown ) ;
115- httpsb . assets . put ( httpsb . userWhitelistPath , data . ubiquitousWhitelist , doCountdown ) ;
105+ messaging . ask ( {
106+ what : 'writeUserUbiquitousBlockRules' ,
107+ content : data . ubiquitousBlacklist
108+ } ,
109+ doCountdown
110+ ) ;
111+ messaging . ask ( {
112+ what : 'writeUserUbiquitousAllowRules' ,
113+ content : data . ubiquitousWhitelist
114+ } ,
115+ doCountdown
116+ ) ;
116117 } ;
117118
118119 var validateBackup = function ( s ) {
@@ -172,7 +173,7 @@ var restoreUserDataFromFile = function() {
172173/******************************************************************************/
173174
174175var resetUserData = function ( ) {
175- chrome . runtime . sendMessage ( {
176+ messaging . tell ( {
176177 what : 'gotoExtensionURL' ,
177178 url : 'setup.html'
178179 } ) ;
@@ -221,40 +222,53 @@ var renderAssetList = function(details) {
221222/******************************************************************************/
222223
223224var updateAssets = function ( ) {
224- var httpsb = getHTTPSB ( ) ;
225225 setAssetListClassBit ( 2 , true ) ;
226226 var onDone = function ( details ) {
227227 if ( details . changedCount !== 0 ) {
228- httpsb . loadUpdatableAssets ( ) ;
228+ messaging . tell ( { what : 'loadUpdatableAssets' } ) ;
229229 }
230230 } ;
231- httpsb . assetUpdater . update ( updateList , onDone ) ;
231+ messaging . ask ( { what : 'launchAssetUpdater' , list : updateList } , onDone ) ;
232232} ;
233233
234234/******************************************************************************/
235235
236236var updateAssetsList = function ( ) {
237- getHTTPSB ( ) . assetUpdater . getList ( renderAssetList ) ;
237+ messaging . ask ( { what : 'getAssetUpdaterList' } , renderAssetList ) ;
238238} ;
239239
240240/******************************************************************************/
241241
242242// Updating all assets could be done from elsewhere and if so the
243243// list here needs to be updated.
244244
245- var onMessage = function ( request ) {
246- if ( request && request . what === 'allLocalAssetsUpdated' ) {
247- updateAssetsList ( ) ;
245+ var onAnnounce = function ( msg ) {
246+ switch ( msg . what ) {
247+ case 'allLocalAssetsUpdated' :
248+ updateAssetsList ( ) ;
249+ break ;
250+
251+ default :
252+ break ;
248253 }
249254} ;
250- chrome . runtime . onMessage . addListener ( onMessage ) ;
255+
256+ messaging . start ( 'about.js' ) ;
257+ messaging . listen ( onAnnounce ) ;
251258
252259/******************************************************************************/
253260
254261( function ( ) {
255- var httpsb = getHTTPSB ( ) ;
256- $ ( '#aboutVersion' ) . html ( httpsb . manifest . version ) ;
257- $ ( '#aboutStorageUsed' ) . html ( chrome . i18n . getMessage ( 'aboutStorageUsed' ) . replace ( '{{storageUsed}}' , httpsb . storageQuota ? ( httpsb . storageUsed / httpsb . storageQuota * 100 ) . toFixed ( 1 ) : 0 ) ) ;
262+ $ ( '#aboutVersion' ) . html ( chrome . runtime . getManifest ( ) . version ) ;
263+ var renderStats = function ( details ) {
264+ var template = chrome . i18n . getMessage ( 'aboutStorageUsed' ) ;
265+ var percent = 0 ;
266+ if ( details . storageQuota ) {
267+ percent = ( details . storageUsed / details . storageQuota * 100 ) . toFixed ( 1 ) ;
268+ }
269+ $ ( '#aboutStorageUsed' ) . html ( template . replace ( '{{storageUsed}}' , percent ) ) ;
270+ } ;
271+ messaging . ask ( { what : 'getSomeStats' } , renderStats ) ;
258272} ) ( ) ;
259273
260274/******************************************************************************/
0 commit comments