diff options
author | Einar Egilsson <einar@einaregilsson.com> | 2015-09-21 15:08:59 +0000 |
---|---|---|
committer | Einar Egilsson <einar@einaregilsson.com> | 2015-09-21 15:08:59 +0000 |
commit | a41cc90f3c401d08cf75a693a0698320b61b8d99 (patch) | |
tree | c41cf00a83dac214ad2725663abaeee826dbe778 /js/firefox | |
parent | 720c2643cd4bcfbc63b67d7d74c476496c805b8b (diff) |
Almost fully working Firefox
Diffstat (limited to 'js/firefox')
-rw-r--r-- | js/firefox/background-shim.js | 25 | ||||
-rw-r--r-- | js/firefox/page-shim.js | 14 |
2 files changed, 35 insertions, 4 deletions
diff --git a/js/firefox/background-shim.js b/js/firefox/background-shim.js index 453feff..83e4cc7 100644 --- a/js/firefox/background-shim.js +++ b/js/firefox/background-shim.js @@ -1,4 +1,5 @@ -var self = require("sdk/self"); +var self = require('sdk/self'); +var tabs = require('sdk/tabs'); const {Cu} = require('chrome'); @@ -80,9 +81,6 @@ var panel = panels.Panel({ function attachedPage(worker) { function sendReply(originalMessage, reply) { - if (JSON.stringify(reply) == "{}") { - throw 'fuck'; - } var msg = {messageId:originalMessage.messageId, payload:reply}; console.info('background sending message: ' + JSON.stringify(msg)); worker.port.emit('message', msg); @@ -99,6 +97,25 @@ function attachedPage(worker) { chrome.storage.local.set(message.payload, function(data) { sendReply(message, data); }); + } else if (message.messageType == 'tabs.query') { + var result = []; + for (let tab of tabs) { + if (tab.url == message.payload.url) { + result.push({id:tab.id, url:tab.url}); + } + } + sendReply(message, result); + } else if (message.messageType == 'tabs.update') { + for (let tab of tabs) { + if (tab.id == message.payload.tabId) { + tab.activate(); + sendReply(message, tab); + } + } + sendReply(message, null); + } else if (message.messageType == 'tabs.create') { + tabs.open(message.payload.url); + sendReply(message, null); } }); } diff --git a/js/firefox/page-shim.js b/js/firefox/page-shim.js index 3531fa4..b6d750a 100644 --- a/js/firefox/page-shim.js +++ b/js/firefox/page-shim.js @@ -1,6 +1,10 @@ (function() { //Communication functions for + if (typeof chrome !== 'undefined') { + return; + } + var messageId = 1; var callbacks = {}; function send(type, message, callback) { @@ -49,11 +53,21 @@ tabs : { query : function(data, callback) { + send('tabs.query', data, callback); + }, + create : function(data, callback) { + send('tabs.create', data, callback); }, update : function(tabId, options, callback) { + if (!options.active) { + throw 'Unexpected update call'; + } + + options.tabId = tabId; + send('tabs.update', options, callback); } }, |