Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Jun 5, 2016
1 parent 12900a5 commit 367df65
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions platform/firefox/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ var winWatcher = (function() {
/******************************************************************************/

var getTabBrowser = function(win) {
return win.gBrowser || null;
return win && win.gBrowser || null;
};

/******************************************************************************/
Expand Down Expand Up @@ -889,9 +889,6 @@ vAPI.tabs.open = function(details) {
}
}

var win = winWatcher.getCurrentWindow();
var tabBrowser = getTabBrowser(win);

// Open in a standalone window
if ( details.popup === true ) {
Services.ww.openWindow(
Expand All @@ -904,6 +901,12 @@ vAPI.tabs.open = function(details) {
return;
}

var win = winWatcher.getCurrentWindow();
var tabBrowser = getTabBrowser(win);
if ( tabBrowser === null ) {
return;
}

if ( details.index === -1 ) {
details.index = tabBrowser.browsers.indexOf(tabBrowser.selectedBrowser) + 1;
}
Expand Down Expand Up @@ -936,7 +939,9 @@ vAPI.tabs.replace = function(tabId, url) {
/******************************************************************************/

vAPI.tabs._remove = function(tab, tabBrowser) {
tabBrowser.removeTab(tab);
if ( tabBrowser ) {
tabBrowser.removeTab(tab);
}
};

/******************************************************************************/
Expand Down Expand Up @@ -979,7 +984,9 @@ vAPI.tabs.select = function(tab) {
win.focus();

var tabBrowser = getTabBrowser(win);
tabBrowser.selectedTab = tab;
if ( tabBrowser ) {
tabBrowser.selectedTab = tab;
}
};

/******************************************************************************/
Expand Down Expand Up @@ -1031,17 +1038,17 @@ var tabWatcher = (function() {
if ( !win ) {
return -1;
}
var tabbrowser = getTabBrowser(win);
if ( !tabbrowser ) {
var tabBrowser = getTabBrowser(win);
if ( tabBrowser === null ) {
return -1;
}
// This can happen, for example, the `view-source:` window, there is
// no tabbrowser object, the browser object sits directly in the
// window.
if ( tabbrowser === browser ) {
if ( tabBrowser === browser ) {
return 0;
}
return tabbrowser.browsers.indexOf(browser);
return tabBrowser.browsers.indexOf(browser);
};

var indexFromTarget = function(target) {
Expand All @@ -1057,14 +1064,14 @@ var tabWatcher = (function() {
if ( !win ) {
return null;
}
var tabbrowser = getTabBrowser(win);
if ( !tabbrowser ) {
var tabBrowser = getTabBrowser(win);
if ( tabBrowser === null ) {
return null;
}
if ( !tabbrowser.tabs || i >= tabbrowser.tabs.length ) {
if ( !tabBrowser.tabs || i >= tabBrowser.tabs.length ) {
return null;
}
return tabbrowser.tabs[i];
return tabBrowser.tabs[i];
};

var browserFromTarget = function(target) {
Expand Down Expand Up @@ -1300,7 +1307,7 @@ var tabWatcher = (function() {
vAPI.contextMenu.unregister(win.document);

var tabBrowser = getTabBrowser(win);
if ( !tabBrowser ) {
if ( tabBrowser === null ) {
return;
}

Expand Down Expand Up @@ -1413,7 +1420,11 @@ vAPI.setIcon = function(tabId, iconId, badge) {
} else {
win = winWatcher.getCurrentWindow();
}
var curTabId = tabWatcher.tabIdFromTarget(getTabBrowser(win).selectedTab);
var tabBrowser = getTabBrowser(win);
if ( tabBrowser === null ) {
return;
}
var curTabId = tabWatcher.tabIdFromTarget(tabBrowser.selectedTab);
var tb = vAPI.toolbarButton;

// from 'TabSelect' event
Expand Down

0 comments on commit 367df65

Please sign in to comment.