aboutsummaryrefslogtreecommitdiffstats
path: root/extension
diff options
context:
space:
mode:
authorOmar Rizwan <omar.rizwan@gmail.com>2019-02-25 13:02:25 -0800
committerOmar Rizwan <omar.rizwan@gmail.com>2019-02-25 13:02:25 -0800
commit784ec83696d9ecedc10ede022a035e671dd21607 (patch)
treea459ee535e22ce53c344dc53452050d511428a67 /extension
parent90181466bd12553abef43f165b7b8a2c7ad2f1c3 (diff)
Rewrite and refactor C half. No more shared memory! It's fast!
Three C modules: - tabfs (main thread; talks to FUSE) - common (tabfs<->ws communication helpers) - ws (side thread; talks to browser over WebSocket) It's single-threaded, but I don't think that matters anyway.
Diffstat (limited to 'extension')
-rw-r--r--extension/background.js30
1 files changed, 20 insertions, 10 deletions
diff --git a/extension/background.js b/extension/background.js
index 8a1d808..a0e0294 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -69,6 +69,8 @@ function pathComponent(path, i) {
return components[i >= 0 ? i : components.length + i];
}
+const debugged = {};
+
const router = {
"tabs": {
/* "last-focused": {
@@ -98,18 +100,24 @@ const router = {
}
},
"tree": {
- async open(path) {
- const debuggee = {tabId: parseInt(pathComponent(path, -2))};
- await new Promise(resolve => chrome.debugger.attach(debuggee, "1.2", resolve));
- chrome.debugger.sendCommand(debuggee, "Page.getResourceTree", {}, function(result) {
- console.log(result);
- });
+ async opendir(path) {
+ const tabId = parseInt(pathComponent(path, -2));
+ if (!debugged[tabId]) {
+ await new Promise(resolve => chrome.debugger.attach({tabId}, "1.2", resolve));
+ debugged[tabId] = 0;
+ }
+ debugged[tabId] += 1;
+ return 0;
},
- async read(path) {
-
+ async readdir(path) {
+ const tabId = parseInt(pathComponent(path, -2));
+ if (!debugged[tabId]) throw new UnixError(unix.EIO);
+ const result = await new Promise(resolve => chrome.debugger.sendCommand({tabId}, "Page.getResourceTree", {}, resolve));
+ const frameTree = result.frameTree;
+ return frameTree.resources.map(r => String(r.contentSize));
},
- async close(path) {
-
+ async releasedir(path) {
+ return 0;
}
}
}
@@ -182,6 +190,7 @@ async function releasedir(path) {
let ws;
async function onmessage(event) {
const req = JSON.parse(event.data);
+ console.log('req', req);
let response = { op: req.op, error: unix.EIO };
/* console.time(req.op + ':' + req.path);*/
@@ -238,6 +247,7 @@ async function onmessage(event) {
/* console.timeEnd(req.op + ':' + req.path);*/
response.id = req.id;
+ console.log('resp', response);
ws.send(JSON.stringify(response));
};