mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
Minor code review
This commit is contained in:
parent
bad1506f20
commit
e3f8a612f4
@ -37,35 +37,47 @@ vAPI.Tabs = class extends vAPI.Tabs {
|
|||||||
this.onCreatedHandler(tab);
|
this.onCreatedHandler(tab);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onCreatedHandler(tab) {
|
onCreatedHandler(tab) {
|
||||||
if ( typeof tab.openerTabId === 'number' ) { return; }
|
if ( typeof tab.openerTabId === 'number' ) { return; }
|
||||||
if ( tab.index !== 0 ) { return; }
|
if ( tab.index !== 0 ) { return; }
|
||||||
if ( tab.url !== '' ) { return; }
|
if ( tab.url !== '' ) { return; }
|
||||||
this.tabIds.add(tab.id);
|
this.tabIds.add(tab.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
onCreatedNavigationTargetHandler(details) {
|
onCreatedNavigationTargetHandler(details) {
|
||||||
this.tabIds.delete(details.tabId);
|
this.tabIds.delete(details.tabId);
|
||||||
super.onCreatedNavigationTargetHandler(details);
|
super.onCreatedNavigationTargetHandler(details);
|
||||||
}
|
}
|
||||||
|
|
||||||
onCommittedHandler(details) {
|
onCommittedHandler(details) {
|
||||||
if ( details.frameId === 0 && this.tabIds.has(details.tabId) ) {
|
if ( details.frameId === 0 ) {
|
||||||
this.tabIds.delete(details.tabId);
|
this.synthesizeNavigationTargetEvent(details);
|
||||||
webext.tabs.get(details.tabId).then(tab => {
|
|
||||||
if ( tab === null ) { return; }
|
|
||||||
this.onCreatedNavigationTargetHandler({
|
|
||||||
tabId: tab.id,
|
|
||||||
sourceTabId: tab.id,
|
|
||||||
sourceFrameId: 0,
|
|
||||||
url: tab.url,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
super.onCommittedHandler(details);
|
super.onCommittedHandler(details);
|
||||||
}
|
}
|
||||||
|
|
||||||
onRemovedHandler(tabId, details) {
|
onRemovedHandler(tabId, details) {
|
||||||
this.tabIds.delete(tabId);
|
this.tabIds.delete(tabId);
|
||||||
super.onRemovedHandler(tabId, details);
|
super.onRemovedHandler(tabId, details);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
synthesizeNavigationTargetEvent(details) {
|
||||||
|
if ( this.tabIds.has(details.tabId) === false ) { return; }
|
||||||
|
this.tabIds.delete(details.tabId);
|
||||||
|
if (
|
||||||
|
Array.isArray(details.transitionQualifiers) === false ||
|
||||||
|
details.transitionQualifiers.includes('client_redirect') === false
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.onCreatedNavigationTargetHandler({
|
||||||
|
tabId: details.tabId,
|
||||||
|
sourceTabId: details.tabId,
|
||||||
|
sourceFrameId: 0,
|
||||||
|
url: details.url,
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -96,6 +108,7 @@ vAPI.Tabs = class extends vAPI.Tabs {
|
|||||||
super();
|
super();
|
||||||
this.suspendedTabIds = new Set();
|
this.suspendedTabIds = new Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
normalizeDetails(details) {
|
normalizeDetails(details) {
|
||||||
// Chromium 63+ supports the `initiator` property, which contains
|
// Chromium 63+ supports the `initiator` property, which contains
|
||||||
// the URL of the origin from which the network request was made.
|
// the URL of the origin from which the network request was made.
|
||||||
@ -142,6 +155,7 @@ vAPI.Tabs = class extends vAPI.Tabs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.reddit.com/r/uBlockOrigin/comments/9vcrk3/
|
// https://www.reddit.com/r/uBlockOrigin/comments/9vcrk3/
|
||||||
// Some types can be mapped from 'other', thus include 'other' if and
|
// Some types can be mapped from 'other', thus include 'other' if and
|
||||||
// only if the caller is interested in at least one of those types.
|
// only if the caller is interested in at least one of those types.
|
||||||
@ -165,10 +179,12 @@ vAPI.Tabs = class extends vAPI.Tabs {
|
|||||||
}
|
}
|
||||||
return Array.from(out);
|
return Array.from(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
suspendOneRequest(details) {
|
suspendOneRequest(details) {
|
||||||
this.suspendedTabIds.add(details.tabId);
|
this.suspendedTabIds.add(details.tabId);
|
||||||
return { cancel: true };
|
return { cancel: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
unsuspendAllRequests() {
|
unsuspendAllRequests() {
|
||||||
for ( const tabId of this.suspendedTabIds ) {
|
for ( const tabId of this.suspendedTabIds ) {
|
||||||
vAPI.tabs.reload(tabId);
|
vAPI.tabs.reload(tabId);
|
||||||
|
@ -455,12 +455,15 @@ const PageStore = class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
titleFromDetails(details) {
|
titleFromDetails(details) {
|
||||||
if ( details instanceof Object && details.title !== undefined ) {
|
if (
|
||||||
this.title = details.title;
|
details instanceof Object === false ||
|
||||||
return true;
|
details.title === undefined
|
||||||
}
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
this.title = µb.orphanizeString(details.title.slice(0, 128));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
disposeFrameStores() {
|
disposeFrameStores() {
|
||||||
for ( const frameStore of this.frames.values() ) {
|
for ( const frameStore of this.frames.values() ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user