aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/firefox/background-shim.js25
-rw-r--r--js/firefox/page-shim.js14
-rw-r--r--js/popup.js2
3 files changed, 36 insertions, 5 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);
}
},
diff --git a/js/popup.js b/js/popup.js
index 1e9d353..5305f13 100644
--- a/js/popup.js
+++ b/js/popup.js
@@ -27,7 +27,7 @@ angular.module('popupApp', []).controller('PopupCtrl', ['$scope', function($s) {
close();
});
} else {
- open(url);
+ chrome.tabs.create({url:url, active:true});
}
});
};