Browse Source

Code styling

pull/2/head
Deathamns 10 years ago
committed by gorhill
parent
commit
2a2fa8da75
  1. 66
      platform/firefox/vapi-background.js

66
platform/firefox/vapi-background.js

@ -55,8 +55,8 @@ vAPI.app.restart = function() {};
/******************************************************************************/
// list of things that needs to be destroyed when disabling the extension
// only functions should be added to it
// List of things that needs to be destroyed when disabling the extension
// Only functions should be added to it
vAPI.unload = [];
@ -88,6 +88,7 @@ var SQLite = {
SQLite.db.asyncClose();
});
},
run: function(query, values, callback) {
if ( !this.db ) {
this.open();
@ -135,6 +136,7 @@ var SQLite = {
vAPI.storage = {
QUOTA_BYTES: 100 * 1024 * 1024,
sqlWhere: function(col, params) {
if ( params > 0 ) {
params = Array(params + 1).join('?, ').slice(0, -2);
@ -143,6 +145,7 @@ vAPI.storage = {
return '';
},
get: function(details, callback) {
if ( typeof callback !== 'function' ) {
return;
@ -153,12 +156,10 @@ vAPI.storage = {
if ( details !== null ) {
if ( Array.isArray(details) ) {
values = details;
}
else if (typeof details === 'object') {
} else if ( typeof details === 'object' ) {
defaults = true;
values = Object.keys(details);
}
else {
} else {
values = [details.toString()];
}
}
@ -185,6 +186,7 @@ vAPI.storage = {
}
);
},
set: function(details, callback) {
var key, values = [], placeholders = [];
@ -205,6 +207,7 @@ vAPI.storage = {
callback
);
},
remove: function(keys, callback) {
if ( typeof keys === 'string' ) {
keys = [keys];
@ -216,10 +219,12 @@ vAPI.storage = {
callback
);
},
clear: function(callback) {
SQLite.run('DELETE FROM settings');
SQLite.run('VACUUM', null, callback);
},
getBytesInUse: function(keys, callback) {
if ( typeof callback !== 'function' ) {
return;
@ -244,12 +249,14 @@ var windowWatcher = {
vAPI.tabs.onClosed(tabId);
delete vAPI.tabIcons[tabId];
},
onTabSelect: function(e) {
vAPI.setIcon(
vAPI.tabs.getTabId(e.target),
e.target.ownerDocument.defaultView
);
},
onReady: function(e) {
if ( e ) {
this.removeEventListener(e.type, windowWatcher.onReady);
@ -276,6 +283,7 @@ var windowWatcher = {
// when new window is opened TabSelect doesn't run on the selected tab?
},
observe: function(win, topic) {
if ( topic === 'domwindowopened' ) {
win.addEventListener('DOMContentLoaded', this.onReady);
@ -299,8 +307,7 @@ var tabsProgressListener = {
tabId: tabId,
url: browser.currentURI.spec
});
}
else {
} else {
vAPI.tabs.onNavigation({
frameId: 0,
tabId: tabId,
@ -386,8 +393,7 @@ vAPI.tabs.get = function(tabId, callback) {
if ( tabId === null ) {
tab = Services.wm.getMostRecentWindow('navigator:browser').gBrowser.selectedTab;
tabId = vAPI.tabs.getTabId(tab);
}
else {
} else {
windows = this.getWindows();
for ( var win of windows ) {
@ -402,7 +408,7 @@ vAPI.tabs.get = function(tabId, callback) {
}
// for internal use
if (tab && callback === undefined) {
if ( tab && typeof callback !== 'function' ) {
return tab;
}
@ -477,7 +483,7 @@ vAPI.tabs.open = function(details) {
return null;
}
// extension pages
if (!/^[\w-]{2,}:/.test(details.url)) {
if ( /^[\w-]{2,}:/.test(details.url) === false ) {
details.url = vAPI.getURL(details.url);
}
@ -568,7 +574,7 @@ vAPI.tabs.injectScript = function(tabId, details, callback) {
location.host + ':broadcast',
JSON.stringify({
broadcast: true,
portName: 'vAPI',
channelName: 'vAPI',
msg: {
cmd: 'injectScript',
details: details
@ -594,8 +600,7 @@ vAPI.setIcon = function(tabId, iconStatus, badge) {
// from 'TabSelect' event
if ( tabId === undefined ) {
tabId = curTabId;
}
else if (badge !== undefined) {
} else if ( badge !== undefined ) {
vAPI.tabIcons[tabId] = {
badge: badge,
img: iconStatus === 'on'
@ -793,9 +798,9 @@ vAPI.messaging.onMessage = function({target, data}) {
.chromeEventHandler.ownerDocument.defaultView.messageManager;
}
var listenerId = data.portName.split('|');
var listenerId = data.channelName.split('|');
var requestId = data.requestId;
var portName = listenerId[1];
var channelName = listenerId[1];
listenerId = listenerId[0];
var callback = vAPI.messaging.NOOPFUNC;
@ -803,14 +808,13 @@ vAPI.messaging.onMessage = function({target, data}) {
callback = function(response) {
var message = JSON.stringify({
requestId: requestId,
portName: portName,
channelName: channelName,
msg: response !== undefined ? response : null
});
if ( messageManager.sendAsyncMessage ) {
messageManager.sendAsyncMessage(listenerId, message);
}
else {
} else {
messageManager.broadcastAsyncMessage(listenerId, message);
}
};
@ -824,7 +828,7 @@ vAPI.messaging.onMessage = function({target, data}) {
// Specific handler
var r = vAPI.messaging.UNHANDLED;
var listener = vAPI.messaging.listeners[portName];
var listener = vAPI.messaging.listeners[channelName];
if ( typeof listener === 'function' ) {
r = listener(data.msg, sender, callback);
}
@ -897,6 +901,7 @@ var httpObserver = {
frameId: null,
parentFrameId: null
},
QueryInterface: (function() {
var {XPCOMUtils} = Cu['import']('resource://gre/modules/XPCOMUtils.jsm', {});
return XPCOMUtils.generateQI([
@ -904,16 +909,19 @@ var httpObserver = {
Ci.nsISupportsWeakReference
]);
})(),
register: function() {
Services.obs.addObserver(httpObserver, 'http-on-opening-request', true);
// Services.obs.addObserver(httpObserver, 'http-on-modify-request', true);
Services.obs.addObserver(httpObserver, 'http-on-examine-response', true);
},
unregister: function() {
Services.obs.removeObserver(httpObserver, 'http-on-opening-request');
// Services.obs.removeObserver(httpObserver, 'http-on-modify-request');
Services.obs.removeObserver(httpObserver, 'http-on-examine-response');
},
observe: function(httpChannel, topic) {
// No need for QueryInterface if this check is performed?
if ( !(httpChannel instanceof Ci.nsIHttpChannel) ) {
@ -1003,8 +1011,7 @@ var httpObserver = {
if ( result.cancel === true ) {
httpChannel.cancel(this.ABORT);
}
else if (result.redirectUrl) {
} else if ( result.redirectUrl ) {
httpChannel.redirectionLimit = 1;
httpChannel.redirectTo(
Services.io.newURI(result.redirectUrl, null, null)
@ -1079,7 +1086,7 @@ vAPI.contextMenu.displayMenuItem = function(e) {
var gContextMenu = doc.defaultView.gContextMenu;
var menuitem = doc.getElementById(vAPI.contextMenu.menuItemId);
if (!/^https?$/.test(gContextMenu.browser.currentURI.scheme)) {
if ( /^https?$/.test(gContextMenu.browser.currentURI.scheme) === false) {
menuitem.hidden = true;
return;
}
@ -1155,8 +1162,7 @@ vAPI.contextMenu.create = function(details, callback) {
if ( Array.isArray(this.contexts) && this.contexts.length ) {
this.contexts = this.contexts.indexOf('all') === -1 ? this.contexts : null;
}
else {
} else {
// default in Chrome
this.contexts = ['page'];
}
@ -1170,13 +1176,9 @@ vAPI.contextMenu.create = function(details, callback) {
if ( gContextMenu.inFrame ) {
details.frameUrl = gContextMenu.focusedWindow.location.href;
}
else if (gContextMenu.onImage
|| gContextMenu.onAudio
|| gContextMenu.onVideo) {
} else if ( gContextMenu.onImage || gContextMenu.onAudio || gContextMenu.onVideo ) {
details.srcUrl = gContextMenu.mediaURL;
}
else if (gContextMenu.onLink) {
} else if ( gContextMenu.onLink ) {
details.linkUrl = gContextMenu.linkURL;
}

Loading…
Cancel
Save