Skip to content

Commit

Permalink
ThinBridge: Check redirection for existing tabs on startup
Browse files Browse the repository at this point in the history
Signed-off-by: Fujimoto Seiji <fujimoto@clear-code.com>
  • Loading branch information
Fujimoto Seiji committed Jul 2, 2021
1 parent 494d211 commit 6f16a9c
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,20 @@ var ThinBridgeTalkClient = {
},

configure: function() {
var server = configs.talkServerName;
var query = new String('C chrome');

chrome.runtime.sendNativeMessage(server, query, (resp) => {
chrome.runtime.sendNativeMessage(configs.talkServerName, query, (resp) => {
if (chrome.runtime.lastError) {
console.log('Cannot fetch config', JSON.stringify(chrome.runtime.lastError));
return;
}
var isStartup = (this.cached == null);
this.cached = resp.config;
debug('[Talk] configure', resp.config);
console.log('Fetch config', JSON.stringify(this.cached));

if (isStartup) {
this.handleStartup(this.cached);
}
});
},

Expand Down Expand Up @@ -500,6 +508,20 @@ var ThinBridgeTalkClient = {
return true;
},

/* Handle startup tabs preceding to onBeforeRequest */
handleStartup: function(tbconfig) {
chrome.tabs.query({}, (tabs) => {
tabs.forEach((tab) => {
var url = tab.url || tab.pendingUrl;
console.log(`handleStartup ${url} (tab=${tab.id})`);
if (this.isRedirectURL(tbconfig, url)) {
console.log(`* Redirect to another browser`);
this.redirect(url, tab.id, tbconfig.CloseEmptyTab);
}
});
});
},

/* Callback for webRequest.onBeforeRequest */
onBeforeRequest: function(details) {
var tbconfig = this.cached;
Expand Down

0 comments on commit 6f16a9c

Please sign in to comment.