Skip to content

Commit 808fc3f

Browse files
committed
Add devtools panel with enable / disable switch, make recording per-tab.
1 parent ec0b1aa commit 808fc3f

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

chromium/background.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// TODO: This keeps around history across "clear history" events. Fix that.
2-
var switchPlannerMode = true;
2+
var switchPlannerEnabledFor = {};
33
var switchPlannerInfo = {};
44
console.log("XXX TESTING XXX");
55

@@ -147,7 +147,7 @@ function onBeforeRequest(details) {
147147

148148
// In Switch Planner Mode, record any non-rewriteable
149149
// HTTP URIs by parent hostname, along with the resource type.
150-
if (switchPlannerMode && uri.protocol() !== "https") {
150+
if (uri.protocol() !== "https") {
151151
// In order to figure out the document requesting this resource,
152152
// have to get the tab. TODO: any cheaper way?
153153
// XXX: Because this is async it's actually inaccurate during quick page
@@ -406,3 +406,14 @@ chrome.tabs.onReplaced.addListener(function(addedTabId, removedTabId) {
406406
// Listen for cookies set/updated and secure them if applicable. This function is async/nonblocking,
407407
// so we also use onBeforeSendHeaders to prevent a small window where cookies could be stolen.
408408
chrome.cookies.onChanged.addListener(onCookieChanged);
409+
410+
// Listen for connection from the DevTools panel so we can set up communication.
411+
chrome.runtime.onMessage.addListener(function(message){
412+
console.log(message);
413+
if (message.hasOwnProperty('enable')) {
414+
var enable = message.enable;
415+
switchPlannerEnabledFor[message.tabId] = enable;
416+
if (!enable)
417+
switchPlannerInfo = {};
418+
}
419+
});

chromium/manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"default_popup": "popup.html",
2929
"default_title": "__MSG_about_ext_name__"
3030
},
31+
"devtools_page": "devtools.html",
3132
"permissions": [
3233
"webRequest",
3334
"webRequestBlocking",

chromium/popup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function createRuleLine(ruleset) {
6262
}
6363

6464
function gotTab(tab) {
65-
if (backgroundPage.switchPlannerMode) {
65+
if (backgroundPage.switchPlannerEnabledFor[tab.id]) {
6666
// XXX: Call URI here, but it's not in-scope. Need to make it in-scope.
6767
var tab_hostname = tab.url.match(/https?:\/\/([^\/]*)/)[1];
6868

0 commit comments

Comments
 (0)