33var switchPlannerEnabledFor = { } ;
44// Detailed information recorded when the HTTPS Switch Planner is active.
55// Structure is:
6- // switchPlannerInfo[tabId][resource_host][active_content][url];
6+ // switchPlannerInfo[tabId]["rw"/"nrw"[resource_host][active_content][url];
7+ // rw / nrw stand for "rewritten" versus "not rewritten"
78var switchPlannerInfo = { } ;
89
910var all_rules = new RuleSets ( ) ;
@@ -183,7 +184,7 @@ var passiveTypes = { main_frame: 1, sub_frame: 1, image: 1, xmlhttprequest: 1};
183184function writeToSwitchPlanner ( type , tab_id , resource_host , resource_url , rewritten_url ) {
184185 var rw = "rw" ;
185186 if ( rewritten_url == null )
186- rw = "no " ;
187+ rw = "nrw " ;
187188
188189 var active_content = 0 ;
189190 if ( activeTypes [ type ] ) {
@@ -195,18 +196,17 @@ function writeToSwitchPlanner(type, tab_id, resource_host, resource_url, rewritt
195196 active_content = 1 ;
196197 }
197198
198- // Only add if we were unable to rewrite this URL.
199- // TODO: Maybe also count rewritten URLs separately.
200- if ( rewritten_url != null ) return ;
201-
202- if ( ! switchPlannerInfo [ tab_id ] )
199+ if ( ! switchPlannerInfo [ tab_id ] ) {
203200 switchPlannerInfo [ tab_id ] = { } ;
204- if ( ! switchPlannerInfo [ tab_id ] [ resource_host ] )
205- switchPlannerInfo [ tab_id ] [ resource_host ] = { } ;
206- if ( ! switchPlannerInfo [ tab_id ] [ resource_host ] [ active_content ] )
207- switchPlannerInfo [ tab_id ] [ resource_host ] [ active_content ] = { } ;
201+ switchPlannerInfo [ tab_id ] [ "rw" ] = { } ;
202+ switchPlannerInfo [ tab_id ] [ "nrw" ] = { } ;
203+ }
204+ if ( ! switchPlannerInfo [ tab_id ] [ rw ] [ resource_host ] )
205+ switchPlannerInfo [ tab_id ] [ rw ] [ resource_host ] = { } ;
206+ if ( ! switchPlannerInfo [ tab_id ] [ rw ] [ resource_host ] [ active_content ] )
207+ switchPlannerInfo [ tab_id ] [ rw ] [ resource_host ] [ active_content ] = { } ;
208208
209- switchPlannerInfo [ tab_id ] [ resource_host ] [ active_content ] [ resource_url ] = 1 ;
209+ switchPlannerInfo [ tab_id ] [ rw ] [ resource_host ] [ active_content ] [ resource_url ] = 1 ;
210210}
211211
212212// Return the number of properties in an object. For associative maps, this is
@@ -222,9 +222,13 @@ function objSize(obj) {
222222
223223// Make an array of asset hosts by score so we can sort them,
224224// presenting the most important ones first.
225- function sortSwitchPlanner ( tab_id ) {
225+ function sortSwitchPlanner ( tab_id , rewritten ) {
226226 var asset_host_list = [ ] ;
227- var tabInfo = switchPlannerInfo [ tab_id ] ;
227+ if ( typeof switchPlannerInfo [ tab_id ] === 'undefined' ||
228+ typeof switchPlannerInfo [ tab_id ] [ rewritten ] === 'undefined' ) {
229+ return [ ] ;
230+ }
231+ var tabInfo = switchPlannerInfo [ tab_id ] [ rewritten ] ;
228232 for ( var asset_host in tabInfo ) {
229233 var ah = tabInfo [ asset_host ] ;
230234 var activeCount = objSize ( ah [ 1 ] ) ;
@@ -237,8 +241,8 @@ function sortSwitchPlanner(tab_id) {
237241}
238242
239243// Format the switch planner output for presentation to a user.
240- function switchPlannerSmallHtml ( tab_id ) {
241- var asset_host_list = sortSwitchPlanner ( tab_id ) ;
244+ function switchPlannerSmallHtmlSection ( tab_id , rewritten ) {
245+ var asset_host_list = sortSwitchPlanner ( tab_id , rewritten ) ;
242246 if ( asset_host_list . length == 0 ) {
243247 return "<b>none</b>" ;
244248 }
@@ -263,6 +267,19 @@ function switchPlannerSmallHtml(tab_id) {
263267 return output ;
264268}
265269
270+ function switchPlannerRenderSections ( tab_id , f ) {
271+ return "Unrewritten HTTP resources loaded from this tab (enable HTTPS on " +
272+ "these domains and add them to HTTPS Everywhere):<br/>" +
273+ f ( tab_id , "nrw" ) +
274+ "<br/>Resources rewritten successfully from this tab (update these " +
275+ "in your source code):<br/>" +
276+ f ( tab_id , "rw" ) ;
277+ }
278+
279+ function switchPlannerSmallHtml ( tab_id ) {
280+ return switchPlannerRenderSections ( tab_id , switchPlannerSmallHtmlSection ) ;
281+ }
282+
266283function linksFromKeys ( map ) {
267284 if ( typeof map == 'undefined' ) return "" ;
268285 var output = "" ;
@@ -275,7 +292,11 @@ function linksFromKeys(map) {
275292}
276293
277294function switchPlannerDetailsHtml ( tab_id ) {
278- var asset_host_list = sortSwitchPlanner ( tab_id ) ;
295+ return switchPlannerRenderSections ( tab_id , switchPlannerDetailsHtmlSection ) ;
296+ }
297+
298+ function switchPlannerDetailsHtmlSection ( tab_id , rewritten ) {
299+ var asset_host_list = sortSwitchPlanner ( tab_id , rewritten ) ;
279300 var output = "" ;
280301
281302 for ( var i = asset_host_list . length - 1 ; i >= 0 ; i -- ) {
@@ -286,11 +307,11 @@ function switchPlannerDetailsHtml(tab_id) {
286307 output += "<b>" + host + "</b>: " ;
287308 if ( activeCount > 0 ) {
288309 output += activeCount + " active<br/>" ;
289- output += linksFromKeys ( switchPlannerInfo [ tab_id ] [ host ] [ 1 ] ) ;
310+ output += linksFromKeys ( switchPlannerInfo [ tab_id ] [ rewritten ] [ host ] [ 1 ] ) ;
290311 }
291312 if ( passiveCount > 0 ) {
292313 output += "<br/>" + passiveCount + " passive<br/>" ;
293- output += linksFromKeys ( switchPlannerInfo [ tab_id ] [ host ] [ 0 ] ) ;
314+ output += linksFromKeys ( switchPlannerInfo [ tab_id ] [ rewritten ] [ host ] [ 0 ] ) ;
294315 }
295316 output += "<br/>" ;
296317 }
0 commit comments