diff options
Diffstat (limited to 'data/extensions/https-everywhere@eff.org/pages/devtools')
4 files changed, 196 insertions, 0 deletions
diff --git a/data/extensions/https-everywhere@eff.org/pages/devtools/index.html b/data/extensions/https-everywhere@eff.org/pages/devtools/index.html new file mode 100644 index 0000000..02711dc --- /dev/null +++ b/data/extensions/https-everywhere@eff.org/pages/devtools/index.html @@ -0,0 +1,10 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title></title> + <script src="../send-message.js"></script> + <script src="ux.js"></script> + </head> + <body></body> +</html> diff --git a/data/extensions/https-everywhere@eff.org/pages/devtools/panel-ux.js b/data/extensions/https-everywhere@eff.org/pages/devtools/panel-ux.js new file mode 100644 index 0000000..2cd6a56 --- /dev/null +++ b/data/extensions/https-everywhere@eff.org/pages/devtools/panel-ux.js @@ -0,0 +1,131 @@ +"use strict"; + +function e(id) { + return document.getElementById(id); +} + +/** + * Send message to main extension for HTML to display + * @param type: enable/disable + */ +function sendMessage(type) { + chrome.runtime.sendMessage({ + type: type, + tabId: chrome.devtools.inspectedWindow.tabId, + }); +} + +/** + * Turn on the Switch Planner recording mode, and hide the long description. + */ +function enableSwitchPlanner() { + sendMessage("enable"); + e("SwitchPlannerDescription").style.display = "none"; + e("SwitchPlannerDetails").style.display = "block"; + // Hack: Fetch and display summary information from background page + // once per second. + setInterval(display, 1000); + chrome.devtools.inspectedWindow.reload(); +} + +/** + * Disable the switch planner and reload, so any state is forgotten and + * the long description is restored. + */ +function disableSwitchPlanner() { + sendMessage("disable"); + document.location.reload(); +} + +/** + * Fetch summary HTML of the planner results from the background page for + * display in the devtools panel. + */ +function display() { + chrome.runtime.sendMessage({ + type: "getHosts", + tabId: chrome.devtools.inspectedWindow.tabId, + }, function(response) { + var switch_planner_details = e("SwitchPlannerDetails"); + while (switch_planner_details.firstChild) { + switch_planner_details.removeChild(switch_planner_details.firstChild); + } + + var nrw_text_div = document.createElement("div"); + nrw_text_div.innerText = "Unrewritten HTTP resources loaded from this tab (enable HTTPS on these domains and add them to HTTPS Everywhere):" + var nrw_div = switchPlannerSmallHtmlSection(response.nrw); + var rw_text_div = document.createElement("div"); + rw_text_div.style.marginTop = "20px"; + rw_text_div.innerText = "Resources rewritten successfully from this tab (update these in your source code):" + var rw_div = switchPlannerSmallHtmlSection(response.rw); + + switch_planner_details.appendChild(nrw_text_div); + switch_planner_details.appendChild(nrw_div); + switch_planner_details.appendChild(rw_text_div); + switch_planner_details.appendChild(rw_div); + + e("SwitchPlannerResults").style.display = "block"; + }); +} + +/** +* Format the switch planner output for presentation to a user. +* */ +function switchPlannerSmallHtmlSection(asset_host_list) { + var wrapper_div = document.createElement("div"); + if (asset_host_list.length == 0) { + wrapper_div.style.fontWeight = "bold"; + wrapper_div.innerText = "none"; + return wrapper_div; + } + + for (var i = asset_host_list.length - 1; i >= 0; i--) { + var host = asset_host_list[i][3]; + var activeCount = asset_host_list[i][1]; + var passiveCount = asset_host_list[i][2]; + + var div = document.createElement("div"); + var b = document.createElement("b"); + b.innerText = host; + div.appendChild(b); + + var text_arr = []; + if (activeCount > 0) { + text_arr.push(activeCount + " active"); + } + if (passiveCount > 0) { + text_arr.push(passiveCount + " passive"); + } + div.appendChild(document.createTextNode(": " + text_arr.join(', '))); + + wrapper_div.appendChild(div); + } + return wrapper_div; +} + +window.onload = function() { + // Open a connection to the background page. Right now this is only used + // by the background page so it knows when the devtools pane has closed. + // We don't receive messages from the background page currently, though that + // may be a future improvement. Sending messages to the background page doesn't + // require an existing connection. + chrome.runtime.connect({ name: "devtools-page" }); + + var checkbox = e("SwitchPlannerCheckbox"); + checkbox.addEventListener("change", function() { + if (checkbox.checked) { + enableSwitchPlanner(); + } else { + disableSwitchPlanner(); + } + }); + + e("SwitchPlannerDetailsLink").addEventListener("click", function() { + window.open("/pages/switch-planner/index.html?tab=" + chrome.devtools.inspectedWindow.tabId); + }); + // Since this is rendered in a devtools console, we have to make clicks on the + // link open a new window. + e("MixedContentLink").addEventListener("click", function(e) { + window.open(e.target.href); + }); +}; diff --git a/data/extensions/https-everywhere@eff.org/pages/devtools/panel.html b/data/extensions/https-everywhere@eff.org/pages/devtools/panel.html new file mode 100644 index 0000000..f5f6859 --- /dev/null +++ b/data/extensions/https-everywhere@eff.org/pages/devtools/panel.html @@ -0,0 +1,38 @@ +<!doctype html> +<html> + <head> + <meta charset="utf-8"> + <title></title> + <style> + html { + background: #fff; + color: #000; + } + </style> + </head> + <body> + <div id="SwitchPlanner"> + <input type="checkbox" id="SwitchPlannerCheckbox"> + <label for="SwitchPlannerCheckbox">Enable HTTPS Switch Planner mode (reloads page).</label> + <br> + <div id="SwitchPlannerDescription"> + <p>Switch Planner mode helps prepare for your site's switch to HTTPS by generating a report of external HTTP + resources that might not yet be available on HTTPS.</p> + <p>After enabling, navigate around your site and try to exercise all functionality in order to get a + comprehensive list of external resources.</p> + <p>For each group of resources listed as "Unrewritten," find out whether they are available on HTTPS. If so: + add a rule to HTTPS Everywhere! If not: try to make them available over HTTPS or use a different resource or + provider. Otherwise your site will generate <a id="MixedContentLink" + href="https://developer.mozilla.org/en-US/docs/Security/MixedContent#Mixed_passive.2Fdisplay_content">Mixed + Content</a> (passive or active) errors when you turn on HTTPS.</p> + <p>For most accurate results, disable ad blockers before using. Closing this panel will deactivate Switch + Planner mode and clear stored data.</p> + </div> + <div id="SwitchPlannerResults" style="display: none"> + <div id="SwitchPlannerDetails"></div> + <a id="SwitchPlannerDetailsLink" href="javascript:void 0">details</a> + </div> + </div> + <script src="panel-ux.js"></script> + </body> +</html> diff --git a/data/extensions/https-everywhere@eff.org/pages/devtools/ux.js b/data/extensions/https-everywhere@eff.org/pages/devtools/ux.js new file mode 100644 index 0000000..8244cbf --- /dev/null +++ b/data/extensions/https-everywhere@eff.org/pages/devtools/ux.js @@ -0,0 +1,17 @@ +/* global sendMessage */ + +"use strict"; + +const defaultOptions = { + showDevtoolsTab: true +}; + +sendMessage("get_option", defaultOptions, item => { + if (item.showDevtoolsTab) { + chrome.devtools.panels.create("HTTPS Everywhere", + "/images/icons/icon-active-38.png", + "/pages/devtools/panel.html", + function() { } + ); + } +}); |