From bfabbf39dab52da414cb4c462af71a1896aa540b Mon Sep 17 00:00:00 2001 From: Thomas Rientjes Date: Wed, 27 Jun 2018 14:43:05 +0200 Subject: [PATCH] Resolve #228 by implementing a new icon state --- core/state-manager.js | 65 +++++++++++++++++- .../action/{icon18.png => icon18-default.png} | Bin icons/action/icon18-disabled.png | Bin 0 -> 596 bytes .../action/{icon19.png => icon19-default.png} | Bin icons/action/icon19-disabled.png | Bin 0 -> 629 bytes .../action/{icon32.png => icon32-default.png} | Bin icons/action/icon32-disabled.png | Bin 0 -> 1026 bytes .../action/{icon36.png => icon36-default.png} | Bin icons/action/icon36-disabled.png | Bin 0 -> 1143 bytes .../action/{icon38.png => icon38-default.png} | Bin icons/action/icon38-disabled.png | Bin 0 -> 1183 bytes .../action/{icon64.png => icon64-default.png} | Bin manifest.json | 12 ++-- modules/internal/wrappers.js | 7 ++ 14 files changed, 75 insertions(+), 9 deletions(-) rename icons/action/{icon18.png => icon18-default.png} (100%) create mode 100644 icons/action/icon18-disabled.png rename icons/action/{icon19.png => icon19-default.png} (100%) create mode 100644 icons/action/icon19-disabled.png rename icons/action/{icon32.png => icon32-default.png} (100%) create mode 100644 icons/action/icon32-disabled.png rename icons/action/{icon36.png => icon36-default.png} (100%) create mode 100644 icons/action/icon36-disabled.png rename icons/action/{icon38.png => icon38-default.png} (100%) create mode 100644 icons/action/icon38-disabled.png rename icons/action/{icon64.png => icon64-default.png} (100%) diff --git a/core/state-manager.js b/core/state-manager.js index 31a021f..681bfec 100644 --- a/core/state-manager.js +++ b/core/state-manager.js @@ -123,15 +123,24 @@ stateManager._removeTab = function (tabIdentifier) { stateManager._updateTab = function (details) { - let tabIdentifier, frameIdentifier; + let tabDomain, domainIsWhitelisted, tabIdentifier, frameIdentifier; + + tabDomain = helpers.extractDomainFromUrl(details.url); + domainIsWhitelisted = stateManager._domainIsWhitelisted(tabDomain); - tabIdentifier = details.tabId; frameIdentifier = details.frameId; + tabIdentifier = details.tabId; - if (tabIdentifier === -1 || frameIdentifier !== 0) { + if (frameIdentifier !== 0 || tabIdentifier === -1) { return; } + if (domainIsWhitelisted) { + stateManager._setIconDisabled(tabIdentifier); + } else { + stateManager._setIconDefault(tabIdentifier); + } + chrome.browserAction.setTitle({ 'tabId': tabIdentifier, 'title': 'Decentraleyes' @@ -182,12 +191,62 @@ stateManager._removeIconBadgeFromTab = function (tab) { stateManager._clearBadgeText(tab.id); }; +stateManager._domainIsWhitelisted = function (domain) { + + if (domain !== null) { + + let whitelistRecord, isWhitelisted; + + whitelistRecord = requestAnalyzer.whitelistedDomains[domain]; + isWhitelisted = Boolean(whitelistRecord); + + return isWhitelisted; + } + + return false; +}; + +stateManager._setIconDefault = function (tabIdentifier) { + + wrappers.setIcon({ + 'path': stateManager.defaultIconPath, + 'tabId': tabIdentifier + }); +}; + +stateManager._setIconDisabled = function (tabIdentifier) { + + wrappers.setIcon({ + 'path': stateManager.disabledIconPath, + 'tabId': tabIdentifier + }); +}; + /** * Initializations */ stateManager.requests = {}; stateManager.tabs = {}; + +stateManager.defaultIconPath = { + '18': chrome.runtime.getURL('icons/action/icon18-default.png'), + '19': chrome.runtime.getURL('icons/action/icon19-default.png'), + '32': chrome.runtime.getURL('icons/action/icon32-default.png'), + '36': chrome.runtime.getURL('icons/action/icon36-default.png'), + '38': chrome.runtime.getURL('icons/action/icon38-default.png'), + '64': chrome.runtime.getURL('icons/action/icon64-default.png') +}; + +stateManager.disabledIconPath = { + '18': chrome.runtime.getURL('icons/action/icon18-disabled.png'), + '19': chrome.runtime.getURL('icons/action/icon19-disabled.png'), + '32': chrome.runtime.getURL('icons/action/icon32-disabled.png'), + '36': chrome.runtime.getURL('icons/action/icon36-disabled.png'), + '38': chrome.runtime.getURL('icons/action/icon38-disabled.png'), + '64': chrome.runtime.getURL('icons/action/icon64-disabled.png') +}; + stateManager.validHosts = []; for (let mapping in mappings) { diff --git a/icons/action/icon18.png b/icons/action/icon18-default.png similarity index 100% rename from icons/action/icon18.png rename to icons/action/icon18-default.png diff --git a/icons/action/icon18-disabled.png b/icons/action/icon18-disabled.png new file mode 100644 index 0000000000000000000000000000000000000000..a068a8c834e0aef5160502717388f223e587c4ba GIT binary patch literal 596 zcmV-a0;~OrP)MNvL>BTocggbeNl)!}0MkE-o%` zb#;Zs#l=9f%euO{*MTHY2s449p&?kURydtbKiF(Gu(VKQ_k_e{Z!(C(zv747=SfB>VgO&}y~e9KkGLG#Y(nUo`GX@CP806>YBP}fr>FMbxDk}0gZf$LeZBI{+{3pjhcSh^{Aw8f{%A*WzQ6?lL z1Q8`AB}F9KBw#X`px5g?%B-xcAfnvd+;BuvT3IM1R|1)tnTU&v6J%#+qpGS3jg5_% zot>4yVyl`>hhIw2(b0j+%S$l~v3zK1YQoXck@RwVd)t5f9Pe#9P4EvUCMG;hKRi6d z;NT!Q8Nt-llq@NAa5x<3@9$Tc_xWD?GYZXIG__CRAVV1*9u7Vc^_bN=Dl7zgdwV4# z9|D=^+S(cn27@9o6K|D&AlXYQ$5riYtT=L-fjyfho@l~7b;L~f=gsLH5LY+YWDDx~ i{eR(e=FDM6*9QPXTT;DwBu3T%0000=4Qhe;ITFe(^rPyu7@NS|UE}Hg9SYhtkqg8WW5?F`Dz%~g&^M@Lo|A0OAL?1sN7nJ*0a z`T4ZDxhc-HzrRm2Gcz5 z1THQviV%tq4i41*^73*ypdQM$;Eeph*wfRajKRUdW<-L}&`@QstgJ*drlBr@><^?$ zi1qdL%IM|gr6u$6@qt~3pGp~ChKGk~c6L^BK!JgQS~4isk%_VU&2=2W@O@P(?+BDWRQ#p+(*pR903- zhlhu>y}eB}H8r}^Q6R~$dX`ybyfJt|T?9Usl$1!x73tjE9JRHzQAo%q7WPZEY>>?Cgk>7U)S6q8b))&hj7jP=*~jLkLg;g&@EI)6>&b zS662`lRfY|>3GkCk}BuJij3^ZK#4skn_n P00000NkvXXu0mjf_xvYr literal 0 HcmV?d00001 diff --git a/icons/action/icon32.png b/icons/action/icon32-default.png similarity index 100% rename from icons/action/icon32.png rename to icons/action/icon32-default.png diff --git a/icons/action/icon32-disabled.png b/icons/action/icon32-disabled.png new file mode 100644 index 0000000000000000000000000000000000000000..60344fde9bb497e24dab179da9e081f034079a9b GIT binary patch literal 1026 zcmV+d1pWJoP)HNDCC zu$Xgpcl7Yzclhr*#vo%3U`#|sMOE_OK|KFgTwL6%kNsaC8~up!kg>=hm)K%Nu&A&9 zGjUQ<($j3@3S-j)vBVDJR$yS@6Q0N;A|l@6jrCTBlarGvBO`-yb8`v6zxnFzgw#bw zM!xHc9M{GhhNY3z)KqF}YNDyBDOy`wBZ=ABSxQSwvlB7Ow!g6@XXklSlJiqgdwV;r ztgL{@79AZOPERt+cZt`;YAAXaE=YjgAq7SJGkLJ7F4FT~p}EiGA+LD=;4 zGy#i?i!?MegxhlKoL5Zb>>!`O+x7Q`QAs*CH%B!!HE=>{&?~n1z@O=k=W9&Dn@2}S zNs{;U^iX_!yeA@urwI6mJS;5i86H?MCMqf_Tsv22Xefn*gus|3QB_qHb#--7QBjec z+hFeJar*D|iOI=H6ZzQK7{$iMs(H>4bnV(TI&|m|?ccwj0Q?(c{FEk=($Z38XLWUz zva+(|E&PmBd)pYu%*-Tt`t0m%6Zz@WrxmfpsZ*y+A{rYTbz8VyDZm#3s*Hi^>T1)5 z@$qrfhRc^PgUA+Fu3S;;)6>)8%*ugNQc~nIR6)RqF@U$y1mFZ}ad>z*9XN2nQNY22 z2Tiwt&@3!0q=bY7Ne)axz`8MjSk?sK4b@^lKR*z-LO?)(+i2J{3Fz!p*e+4llO?rXiqC6dy!`POfnF>{&>N7|F?t06z%$&BF!?3JRi=Cr?UpjNzHoIwY^!+FC>wZq&-&??&sj zBq#9%Wo2c^4V0LeNOGP_Dm{4c08n19lMfCKDrZJjRW@WQ#)ocJ6123m=%rVk!U^2e zP;YOq%&7mChQswv=yQ}vyPAMgpcI3^iaaMLhbAT_BstnR>D1ettiF)#_buI6Yip}A zAcWwA5QE$fAY&@Q0!YQ^tmN}v)wxw!M!Tdf5?ARR3kwVK>VZbfHk~KmR<%JZP&l<$ z^5NlObXM-0Qqh)=>KjqTIy*aQd3o897!|anq(r>AB1c>9{Ban)!yB4~0kmW&P>2wu zYJ?hqr$Wrjx7N|+cyjq6MtP$@V^10Kj$J0ciCp7}Ty)IevY}YUj>oPy*x|~(efY_Z wpWbXdhSAL!(te)zFv@s7it#5Czv9;J-=~2+1^M^FRR91007*qoM6N<$f_G=`S^xk5 literal 0 HcmV?d00001 diff --git a/icons/action/icon36.png b/icons/action/icon36-default.png similarity index 100% rename from icons/action/icon36.png rename to icons/action/icon36-default.png diff --git a/icons/action/icon36-disabled.png b/icons/action/icon36-disabled.png new file mode 100644 index 0000000000000000000000000000000000000000..8abada525c511ceb9ea6aacb024a8fd9ba728fa0 GIT binary patch literal 1143 zcmV--1c>{IP)eWBl+4OXJv`Q+NudDml<=*R@{`vd+ zKN}Db@LOPDpbtwuOBc)Nj0~|C{!X7hePd8i(8qjG8p~A{av;^X zfV;cmCZEbDT+uKW!&dyG%tgNK)@Ng@rLY!d>COA0w0hNo`Vw9VkOG86LboT67GXb0( zOI2AyA@KO%99cObA%Xh)`*E0UiHeG{1C<{c8F`yo+<3}LSy@>$IXUSFW@2K3IOXjC z!SaWdFr1oi%8L;vXU?24Ja~F~nudpm;YJ9JkB`HWl#-I-B*?Ea)T=re4#J!GhZ=EV zMn;AqOm}xT<>cg0SXkIXWnM#keEiL#b-oZ6L_|cu>@o;k2att=kX`q+Sp3q&ACb;7 z%-Gl%@h#?cC)^>+4ei{S9}yiXY{|hg(U(tA>$e+qP|@4l1}+@kAU20H{p+fP-aswY0S8 zl#U-iZVV#Hi4!Mg^|&gdwP^8(VylcJ0Cj60P(NgM6&4oils0ePY#RtxQUx~0tx@0) z0_dz*m1Ur`v^1U4s#U9O1Fc!J#%U&A0MI$@10r7rLT4A1R<2xW7YOik0_xE|U~EA7 z*I>H3x?}~Uw_PBV1E)a40IC!}q7Idpmm_wR4f5c@gSLSV9XjL`s0?kx%Yg!F5Msj; zX8rp0#CzL^5z_t_r!9czCR)9EwIR&fwQI@K(^EbS8D<6aC!RGgIt7CG`ud`6=)e%f zd-m*s6?JQosiUK#h)Zg1Z8e&eP!3+!nroiX?A+1OfvSq})y$0$rHfKiQ_%}`nOjg$ zpo|}}+kdM%XkcJKw^40vEzD}$is|X;%4xHtq(oke%X~izgy9H7lCS`6MBYeiidGXL zVg=1qIp6^hnJnqFvxRS!=jr#QMK~Or7=oc;=H=y4W@aV?u0V`nv^5-gu})!~4~$-^ zfznNd?ms^PjKQ?&V)p8|hZj^xu0vqY2L>62;8wvDS-trI^*AqVk?I57fsGx3AiL`8 z>x~`*%|1RpkJ@^@a-Dbtvx&S3e}~y&F{3zv;3pOS0W|a$84kG* z#5v$07+L^eR2cz%S`T#KA!u9b9U6WB?dLTC)tLcneI`=O2LRdl?Gi=&pfmsg002ov JPDHLkV1g+Y7#08k literal 0 HcmV?d00001 diff --git a/icons/action/icon38.png b/icons/action/icon38-default.png similarity index 100% rename from icons/action/icon38.png rename to icons/action/icon38-default.png diff --git a/icons/action/icon38-disabled.png b/icons/action/icon38-disabled.png new file mode 100644 index 0000000000000000000000000000000000000000..469c00a899c8108ece6b434ba4c4274a516e39ed GIT binary patch literal 1183 zcmV;Q1YrA#P)>*Bp1G|RpmDU_X^?U)eI*w|G8i__B5OgC?CZl=7v zJW5PVgmnPz-yr2CTc`MuI(hQsE&M}^ei7oMzrSBesIIP#!otFo$~~f!$=&SJ9)9tY zegPAuj*bpV2t;8;teH&wt0$JL|1l>gM`HWagr3=3c`NE+qZA0DO09^j1tqQPp4hGcKOL%ym(RS#%ZBW0yh02 z{mb(5a+1O_uJ-KNV@gVIJy=zfJ9X+5NpIjtlf=+Y`DE>CYipAMkGSv?T)cR(Bw>gp zOO}v4(okml`ueD-sL1Hp$_BAI?ZxTSr=_(()KBQpp+mMw0kG`h!-t(_W-Evd${3J` zv0iBB&Yg~k0lRnac1mp6iWtl-gWfSQe2g1n_4;(i8K;p#9LRLuzkk1DVzPADK)Vcn zI(P0I6%-U8JJAR#1?SG4YnK$(x~cwoAa>ZP;Fc|0Y!id)T@X7Zy9(P_v0{ZKsWofX zxSa|9_8mEL({mH(h9MG<@|_l0X7BO_I$Mlt!@y(0KQHH{-Knwpv% z5ke?rWMrrU9T;JJ=k%uM8weVe5nQ5Z4WA?f*Q1CgBqW%XmtHo&+iq`sUSS30W+eed z^1_7+8tm4&T*h;b35kTb9=Cz4Xox``F~FE7v(M`#-hHfeDWlm1p?1bXj!A3@hKs_UlLt!nidCkq$=6`>mUFP;N1z!LF002ovPDHLkV1gijL3scG literal 0 HcmV?d00001 diff --git a/icons/action/icon64.png b/icons/action/icon64-default.png similarity index 100% rename from icons/action/icon64.png rename to icons/action/icon64-default.png diff --git a/manifest.json b/manifest.json index 806d9ae..d6742d2 100644 --- a/manifest.json +++ b/manifest.json @@ -32,12 +32,12 @@ "browser_action": { "default_icon": { - "18": "icons/action/icon18.png", - "19": "icons/action/icon19.png", - "32": "icons/action/icon32.png", - "36": "icons/action/icon36.png", - "38": "icons/action/icon38.png", - "64": "icons/action/icon64.png" + "18": "icons/action/icon18-default.png", + "19": "icons/action/icon19-default.png", + "32": "icons/action/icon32-default.png", + "36": "icons/action/icon36-default.png", + "38": "icons/action/icon38-default.png", + "64": "icons/action/icon64-default.png" }, "default_popup": "pages/popup/popup.html", "browser_style": false diff --git a/modules/internal/wrappers.js b/modules/internal/wrappers.js index faf1033..9800786 100644 --- a/modules/internal/wrappers.js +++ b/modules/internal/wrappers.js @@ -36,3 +36,10 @@ wrappers.setBadgeText = function (details) { chrome.browserAction.setBadgeText(details); } }; + +wrappers.setIcon = function (details) { + + if (chrome.browserAction.setIcon !== undefined) { + chrome.browserAction.setIcon(details); + } +};