Skip to content

Commit d22c1c5

Browse files
committed
Add details page
1 parent 11aa454 commit d22c1c5

File tree

6 files changed

+89
-22
lines changed

6 files changed

+89
-22
lines changed

chromium/_locales/en/messages.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@
9999
"message": "Switch Planner"
100100
},
101101
"switch_planner_description": {
102-
"message": "This hostname loaded HTTP resources that couldn't be translated to HTTPS, from these other hostnames: "
103-
}
102+
"message": "Unrewritten HTTP resources:"
103+
},
104104
"chrome_stable_rules": {
105105
"message": "Stable rules"
106106
},

chromium/background.js

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
// TODO: This keeps around history across "clear history" events. Fix that.
12
var switchPlannerMode = true;
2-
var switchPlanner = {};
3+
var switchPlannerInfo = {};
34
console.log("XXX TESTING XXX");
45

56
var all_rules = new RuleSets();
@@ -209,14 +210,14 @@ function writeToSwitchPlanner(type, tab_host, resource_host, resource_url, rewri
209210
// TODO: Maybe also count rewritten URLs separately.
210211
if (rewritten_url != null) return;
211212

212-
if (!switchPlanner[tab_host])
213-
switchPlanner[tab_host] = {};
214-
if (!switchPlanner[tab_host][resource_host])
215-
switchPlanner[tab_host][resource_host] = {};
216-
if (!switchPlanner[tab_host][resource_host][active_content])
217-
switchPlanner[tab_host][resource_host][active_content] = {};
213+
if (!switchPlannerInfo[tab_host])
214+
switchPlannerInfo[tab_host] = {};
215+
if (!switchPlannerInfo[tab_host][resource_host])
216+
switchPlannerInfo[tab_host][resource_host] = {};
217+
if (!switchPlannerInfo[tab_host][resource_host][active_content])
218+
switchPlannerInfo[tab_host][resource_host][active_content] = {};
218219

219-
switchPlanner[tab_host][resource_host][active_content][resource_url] = 1;
220+
switchPlannerInfo[tab_host][resource_host][active_content][resource_url] = 1;
220221
}
221222

222223
// Return the number of properties in an object. For associative maps, this is
@@ -230,27 +231,36 @@ function objSize(obj) {
230231
return size;
231232
}
232233

233-
// Format the switch planner output for presentation to a user.
234+
// Make an array of asset hosts by score so we can sort them,
235+
// presenting the most important ones first.
234236
function sortSwitchPlanner(tab_host) {
235-
var output = "";
236-
237237
var asset_host_list = [];
238-
var parentInfo = switchPlanner[tab_host];
239-
// Make an array of asset hosts by score so we can sort them,
240-
// presenting the most important ones first.
238+
var parentInfo = switchPlannerInfo[tab_host];
241239
for (var asset_host in parentInfo) {
242240
var ah = parentInfo[asset_host];
243241
var activeCount = objSize(ah[1]);
244242
var passiveCount = objSize(ah[0]);
245-
asset_host_list.push([activeCount * 100 + passiveCount, activeCount, passiveCount, asset_host]);
243+
var score = activeCount * 100 + passiveCount;
244+
asset_host_list.push([score, activeCount, passiveCount, asset_host]);
246245
}
247246
asset_host_list.sort(function(a,b){return a[0]-b[0]});
247+
return asset_host_list;
248+
}
249+
250+
// Format the switch planner output for presentation to a user.
251+
function switchPlannerSmallHtml(tab_host) {
252+
var asset_host_list = sortSwitchPlanner(tab_host);
253+
if (asset_host_list.length == 0) {
254+
return "<b>none</b>";
255+
}
256+
257+
var output = "";
248258
for (var i = asset_host_list.length - 1; i >= 0; i--) {
249259
var host = asset_host_list[i][3];
250260
var activeCount = asset_host_list[i][1];
251261
var passiveCount = asset_host_list[i][2];
252262

253-
output += host + ": ";
263+
output += "<b>" + host + "</b>: ";
254264
if (activeCount > 0) {
255265
output += activeCount + " active";
256266
if (passiveCount > 0)
@@ -259,7 +269,41 @@ function sortSwitchPlanner(tab_host) {
259269
if (passiveCount > 0) {
260270
output += passiveCount + " passive";
261271
}
262-
output += "\n";
272+
output += "<br/>";
273+
}
274+
return output;
275+
}
276+
277+
function linksFromKeys(map) {
278+
if (typeof map == 'undefined') return "";
279+
var output = "";
280+
for (var key in map) {
281+
if (map.hasOwnProperty(key)) {
282+
output += "<a href='" + key + "'>" + key + "</a><br/>";
283+
}
284+
}
285+
return output;
286+
}
287+
288+
function switchPlannerDetailsHtml(tab_host) {
289+
var asset_host_list = sortSwitchPlanner(tab_host);
290+
var output = "";
291+
292+
for (var i = asset_host_list.length - 1; i >= 0; i--) {
293+
var host = asset_host_list[i][3];
294+
var activeCount = asset_host_list[i][1];
295+
var passiveCount = asset_host_list[i][2];
296+
297+
output += "<b>" + host + "</b>: ";
298+
if (activeCount > 0) {
299+
output += activeCount + " active<br/>";
300+
output += linksFromKeys(switchPlannerInfo[tab_host][host][1]);
301+
}
302+
if (passiveCount > 0) {
303+
output += "<br/>" + passiveCount + " passive<br/>";
304+
output += linksFromKeys(switchPlannerInfo[tab_host][host][0]);
305+
}
306+
output += "<br/>";
263307
}
264308
return output;
265309
}

chromium/popup.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ <h1 i18n="about_ext_name"></h1>
1515
<section id="SwitchPlanner" class="switchplanner">
1616
<h3 i18n="switch_planner">Switch Planner</h3>
1717
<p class="description" i18n="switch_planner_description"></p>
18+
<a id=SwitchPlannerDetails href="javascript:void(0);">details</a>
1819
</section>
1920
<section id="StableRules" class="rules">
2021
<h3 i18n="chrome_stable_rules"></h3>

chromium/popup.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,21 @@ function createRuleLine(ruleset) {
6262
function gotTab(tab) {
6363
if (backgroundPage.switchPlannerMode) {
6464
// XXX: Call URI here, but it's not in-scope. Need to make it in-scope.
65-
var tab_host = tab.url.match(/https?:\/\/([^\/]*)/)[1];
65+
var tab_hostname = tab.url.match(/https?:\/\/([^\/]*)/)[1];
66+
67+
var detailsLink = document.getElementById("SwitchPlannerDetails");
68+
detailsLink.onclick = function() {
69+
window.open("switch-planner.html?host=" + tab_hostname);
70+
};
71+
6672
var switchPlannerTextDiv = document.createElement("div");
67-
var switchPlannerText = backgroundPage.sortSwitchPlanner(tab_host);
73+
var switchPlannerText = backgroundPage.switchPlannerSmallHtml(tab_hostname);
6874
switchPlannerTextDiv.innerHTML = switchPlannerText;
69-
switchPlannerDiv.appendChild(switchPlannerTextDiv);
75+
switchPlannerDiv.className = "switch_planner_info";
7076
switchPlannerDiv.style.position = "static";
7177
switchPlannerDiv.style.visibility = "visible";
78+
79+
switchPlannerDiv.insertBefore(switchPlannerTextDiv, detailsLink);
7280
}
7381

7482
var rulesets = backgroundPage.activeRulesets.getRulesets(tab.id);

chromium/switch-planner.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<head>
2+
<title></title>
3+
<script src="switch-planner.js"></script>
4+
</head>
5+
<body>
6+
<div id=content />
7+
</body>

chromium/switch-planner.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
window.onload = function() {
2+
var backgroundPage = chrome.extension.getBackgroundPage();
3+
var hostname = document.location.search.match(/host=([^&]*)/)[1];
4+
document.getElementById("content").innerHTML =
5+
backgroundPage.switchPlannerDetailsHtml(hostname);
6+
};
7+

0 commit comments

Comments
 (0)