|
@ -111,10 +111,9 @@ vAPI.tabs = { |
|
|
// update doesn't accept index, must use move
|
|
|
// update doesn't accept index, must use move
|
|
|
chrome.tabs.update(details.tabId, _details, function(tab) { |
|
|
chrome.tabs.update(details.tabId, _details, function(tab) { |
|
|
// if the tab doesn't exist
|
|
|
// if the tab doesn't exist
|
|
|
if (chrome.runtime.lastError) { |
|
|
|
|
|
|
|
|
if ( vAPI.lastError() ) { |
|
|
chrome.tabs.create(_details); |
|
|
chrome.tabs.create(_details); |
|
|
} |
|
|
|
|
|
else if (details.index !== undefined) { |
|
|
|
|
|
|
|
|
} else if ( details.index !== undefined ) { |
|
|
chrome.tabs.move(tab.id, {index: details.index}); |
|
|
chrome.tabs.move(tab.id, {index: details.index}); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
@ -195,7 +194,7 @@ vAPI.tabs = { |
|
|
|
|
|
|
|
|
vAPI.setIcon = function(tabId, img, badge) { |
|
|
vAPI.setIcon = function(tabId, img, badge) { |
|
|
var onIconReady = function() { |
|
|
var onIconReady = function() { |
|
|
if ( chrome.runtime.lastError ) { |
|
|
|
|
|
|
|
|
if ( vAPI.lastError() ) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -213,6 +212,7 @@ vAPI.setIcon = function(tabId, img, badge) { |
|
|
vAPI.messaging = { |
|
|
vAPI.messaging = { |
|
|
ports: {}, |
|
|
ports: {}, |
|
|
listeners: {}, |
|
|
listeners: {}, |
|
|
|
|
|
connector: null, |
|
|
|
|
|
|
|
|
listen: function(listenerName, callback) { |
|
|
listen: function(listenerName, callback) { |
|
|
this.listeners[listenerName] = callback; |
|
|
this.listeners[listenerName] = callback; |
|
@ -226,7 +226,7 @@ vAPI.messaging = { |
|
|
this.connector = function(port) { |
|
|
this.connector = function(port) { |
|
|
var onMessage = function(request) { |
|
|
var onMessage = function(request) { |
|
|
var callback = function(response) { |
|
|
var callback = function(response) { |
|
|
if (chrome.runtime.lastError || response === undefined) { |
|
|
|
|
|
|
|
|
if ( vAPI.lastError() || response === undefined ) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -239,17 +239,19 @@ vAPI.messaging = { |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Default handler
|
|
|
var listener = connector(request.msg, port.sender, callback); |
|
|
var listener = connector(request.msg, port.sender, callback); |
|
|
|
|
|
if ( listener !== null ) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if ( listener === null ) { |
|
|
|
|
|
|
|
|
// Specific handler
|
|
|
listener = vAPI.messaging.listeners[request.portName]; |
|
|
listener = vAPI.messaging.listeners[request.portName]; |
|
|
|
|
|
|
|
|
if ( typeof listener === 'function' ) { |
|
|
if ( typeof listener === 'function' ) { |
|
|
listener(request.msg, port.sender, callback); |
|
|
listener(request.msg, port.sender, callback); |
|
|
} else { |
|
|
} else { |
|
|
console.error('µBlock> messaging > unknown request: %o', request); |
|
|
console.error('µBlock> messaging > unknown request: %o', request); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
var onDisconnect = function(port) { |
|
|
var onDisconnect = function(port) { |
|
|