@@ -38,26 +38,33 @@ var switchPlannerInfo = {};
3838
3939// Is HTTPSe enabled, or has it been manually disabled by the user?
4040var isExtensionEnabled = true ;
41- // The setBadgeText API has an abandoned bug: https://crbug.com/170413
42- chrome . browserAction . setBadgeText ( { text : "" } ) ;
4341
4442// Load prefs about whether http nowhere is on. Structure is:
4543// { httpNowhere: true/false }
4644var httpNowhereOn = false ;
4745storage . get ( { httpNowhere : false } , function ( item ) {
4846 httpNowhereOn = item . httpNowhere ;
49- setIconColor ( ) ;
47+ updateState ( ) ;
5048} ) ;
5149chrome . storage . onChanged . addListener ( function ( changes , areaName ) {
5250 if ( areaName === 'sync' || areaName === 'local' ) {
5351 for ( var key in changes ) {
5452 if ( key === 'httpNowhere' ) {
5553 httpNowhereOn = changes [ key ] . newValue ;
56- setIconColor ( ) ;
54+ updateState ( ) ;
5755 }
5856 }
5957 }
6058} ) ;
59+ chrome . tabs . onActivated . addListener ( function ( ) {
60+ updateState ( ) ;
61+ } ) ;
62+ chrome . windows . onFocusChanged . addListener ( function ( ) {
63+ updateState ( ) ;
64+ } ) ;
65+ chrome . webNavigation . onCompleted . addListener ( function ( ) {
66+ updateState ( ) ;
67+ } ) ;
6168
6269/**
6370* Load stored user rules
@@ -88,26 +95,35 @@ loadStoredUserRules();
8895
8996/**
9097 * Set the icon color correctly
91- * Depending on http-nowhere it should be red/default
98+ * inactive: extension is enabled, but no rules were triggered on this page.
99+ * blocking: extension is in "block all HTTP requests" mode.
100+ * active: extension is enabled and rewrote URLs on this page.
101+ * disabled: extension is disabled from the popup menu.
92102 */
93- var setIconColor = function ( ) {
94- var newIconPath = httpNowhereOn ? './icon38-red.png' : './icon38.png' ;
95- chrome . browserAction . setIcon ( {
96- path : newIconPath
103+ var updateState = function ( ) {
104+ chrome . tabs . query ( { active : true , currentWindow : true } , function ( tabs ) {
105+ if ( ! tabs || tabs . length === 0 ) {
106+ return ;
107+ }
108+ var applied = activeRulesets . getRulesets ( tabs [ 0 ] . id )
109+ var iconState = "inactive" ;
110+ if ( ! isExtensionEnabled ) {
111+ iconState = "disabled" ;
112+ } else if ( httpNowhereOn ) {
113+ iconState = "blocking" ;
114+ } else if ( applied ) {
115+ iconState = "active" ;
116+ }
117+ chrome . browserAction . setIcon ( {
118+ path : {
119+ "38" : "icons/icon-" + iconState + "-38.png"
120+ }
121+ } ) ;
122+ chrome . browserAction . setTitle ( {
123+ title : "HTTPS Everywhere (" + iconState + ")"
124+ } ) ;
97125 } ) ;
98- } ;
99-
100- /*
101- for (var v in localStorage) {
102- log(DBUG, "localStorage["+v+"]: "+localStorage[v]);
103- }
104-
105- var rs = all_rules.potentiallyApplicableRulesets("www.google.com");
106- for (r in rs) {
107- log(DBUG, rs[r].name +": "+ rs[r].active);
108- log(DBUG, rs[r].name +": "+ rs[r].default_state);
109126}
110- */
111127
112128/**
113129 * Adds a new user rule
0 commit comments