Browse Source

this fixes #1013, #1062 (draft)

pull/2/head
gorhill 10 years ago
parent
commit
ce549b283a
  1. 46
      platform/chromium/vapi-background.js

46
platform/chromium/vapi-background.js

@ -55,6 +55,8 @@ vAPI.app.restart = function() {
/******************************************************************************/ /******************************************************************************/
// chrome.storage.local.get(null, function(bin){ console.debug('%o', bin); });
vAPI.storage = chrome.storage.local; vAPI.storage = chrome.storage.local;
/******************************************************************************/ /******************************************************************************/
@ -74,6 +76,7 @@ vAPI.noTabId = '-1';
vAPI.tabs.registerListeners = function() { vAPI.tabs.registerListeners = function() {
var onNavigationClient = this.onNavigation || noopFunc; var onNavigationClient = this.onNavigation || noopFunc;
var onPopupClient = this.onPopup || noopFunc; var onPopupClient = this.onPopup || noopFunc;
var onUpdatedClient = this.onUpdated || noopFunc;
// https://developer.chrome.com/extensions/webNavigation // https://developer.chrome.com/extensions/webNavigation
// [onCreatedNavigationTarget ->] // [onCreatedNavigationTarget ->]
@ -160,6 +163,13 @@ vAPI.tabs.registerListeners = function() {
popupCandidateTest(details); popupCandidateTest(details);
}; };
var onUpdated = function(tabId, changeInfo, tab) {
if ( changeInfo.url && popupCandidateTest({ tabId: tabId, url: changeInfo.url }) ) {
return;
}
onUpdatedClient(tabId, changeInfo, tab);
};
var onCommitted = function(details) { var onCommitted = function(details) {
if ( details.frameId !== 0 ) { if ( details.frameId !== 0 ) {
return; return;
@ -175,10 +185,7 @@ vAPI.tabs.registerListeners = function() {
chrome.webNavigation.onCreatedNavigationTarget.addListener(onCreatedNavigationTarget); chrome.webNavigation.onCreatedNavigationTarget.addListener(onCreatedNavigationTarget);
chrome.webNavigation.onBeforeNavigate.addListener(onBeforeNavigate); chrome.webNavigation.onBeforeNavigate.addListener(onBeforeNavigate);
chrome.webNavigation.onCommitted.addListener(onCommitted); chrome.webNavigation.onCommitted.addListener(onCommitted);
if ( typeof this.onUpdated === 'function' ) {
chrome.tabs.onUpdated.addListener(this.onUpdated);
}
chrome.tabs.onUpdated.addListener(onUpdated);
if ( typeof this.onClosed === 'function' ) { if ( typeof this.onClosed === 'function' ) {
chrome.tabs.onRemoved.addListener(this.onClosed); chrome.tabs.onRemoved.addListener(this.onClosed);
@ -308,6 +315,37 @@ vAPI.tabs.open = function(details) {
/******************************************************************************/ /******************************************************************************/
// Replace the URL of a tab. Noop if the tab does not exist.
vAPI.tabs.replace = function(tabId, url) {
var targetURL = url;
if ( typeof targetURL !== 'string' || targetURL === '' ) {
return;
}
// extension pages
if ( /^[\w-]{2,}:/.test(targetURL) !== true ) {
targetURL = vAPI.getURL(targetURL);
}
if ( typeof tabId !== 'number' ) {
tabId = parseInt(tabId, 10);
if ( isNaN(tabId) ) {
return;
}
}
chrome.tabs.update(tabId, { url: targetURL }, function() {
// this prevent console error
if ( chrome.runtime.lastError ) {
return;
}
});
};
/******************************************************************************/
vAPI.tabs.remove = function(tabId) { vAPI.tabs.remove = function(tabId) {
var onTabRemoved = function() { var onTabRemoved = function() {
if ( vAPI.lastError() ) { if ( vAPI.lastError() ) {

Loading…
Cancel
Save