Skip to content

Commit

Permalink
Enhance ZenGlanceManager to conditionally open tabs based on domain d…
Browse files Browse the repository at this point in the history
…ifferences and refactor tab open handling
  • Loading branch information
mauro-balades committed Jan 22, 2025
1 parent d618181 commit c9f9766
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 13 deletions.
28 changes: 24 additions & 4 deletions src/browser/base/content/browser-js.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js
index ccd83c15d0d73a1e53bdbfdfbe6fed43a26c961d..f18a6abf7debb97539a4cdf8422315b4dff08adb 100644
index 9a65dcc7ad41ab961907c95338e023b173d4f474..9477e0c115ed3c4a670f1ac63846b6de01bf8b8c 100644
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -32,6 +32,7 @@ ChromeUtils.defineESModuleGetters(this, {
Expand All @@ -10,7 +10,7 @@ index ccd83c15d0d73a1e53bdbfdfbe6fed43a26c961d..f18a6abf7debb97539a4cdf8422315b4
DevToolsSocketStatus:
"resource://devtools/shared/security/DevToolsSocketStatus.sys.mjs",
DownloadUtils: "resource://gre/modules/DownloadUtils.sys.mjs",
@@ -632,6 +633,15 @@ XPCOMUtils.defineLazyPreferenceGetter(
@@ -630,6 +631,15 @@ XPCOMUtils.defineLazyPreferenceGetter(
false
);

Expand All @@ -26,7 +26,7 @@ index ccd83c15d0d73a1e53bdbfdfbe6fed43a26c961d..f18a6abf7debb97539a4cdf8422315b4
customElements.setElementCreationCallback("screenshots-buttons", () => {
Services.scriptloader.loadSubScript(
"chrome://browser/content/screenshots/screenshots-buttons.js",
@@ -3438,6 +3448,11 @@ var XULBrowserWindow = {
@@ -3440,6 +3450,11 @@ var XULBrowserWindow = {
AboutReaderParent.updateReaderButton(gBrowser.selectedBrowser);
TranslationsParent.onLocationChange(gBrowser.selectedBrowser);

Expand All @@ -38,7 +38,27 @@ index ccd83c15d0d73a1e53bdbfdfbe6fed43a26c961d..f18a6abf7debb97539a4cdf8422315b4
PictureInPicture.updateUrlbarToggle(gBrowser.selectedBrowser);

if (!gMultiProcessBrowser) {
@@ -7289,6 +7304,12 @@ var gDialogBox = {
@@ -4435,7 +4450,7 @@ nsBrowserAccess.prototype = {
// Passing a null-URI to only create the content window,
// and pass true for aSkipLoad to prevent loading of
// about:blank
- return this.getContentWindowOrOpenURIInFrame(
+ let res = this.getContentWindowOrOpenURIInFrame(
null,
aParams,
aWhere,
@@ -4443,6 +4458,10 @@ nsBrowserAccess.prototype = {
aName,
true
);
+ if (typeof window.gZenGlanceManager !== "undefined" && window.toolbar.visible) {
+ window.gZenGlanceManager.onTabOpen(res, aURI);
+ }
+ return res;
},

openURIInFrame: function browser_openURIInFrame(
@@ -7281,6 +7300,12 @@ var gDialogBox = {
parentElement.showModal();
this._didOpenHTMLDialog = true;

Expand Down
33 changes: 24 additions & 9 deletions src/browser/base/zen-components/ZenGlanceManager.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
init() {
window.addEventListener('keydown', this.onKeyDown.bind(this));
window.addEventListener('TabClose', this.onTabClose.bind(this));
window.addEventListener('TabOpen', this.onTabOpen.bind(this));

XPCOMUtils.defineLazyPreferenceGetter(
this._lazyPref,
Expand Down Expand Up @@ -77,7 +76,7 @@
return this.#currentBrowser;
}

openGlance(data, existingTab = null) {
openGlance(data, existingTab = null, ownerTab = null) {
if (this.#currentBrowser) {
return;
}
Expand All @@ -94,7 +93,7 @@
this.browserWrapper?.removeAttribute('has-finished-animation');
this.overlay?.removeAttribute('post-fade-out');

const currentTab = gBrowser.selectedTab;
const currentTab = ownerTab ?? gBrowser.selectedTab;

this.animatingOpen = true;
this._animating = true;
Expand Down Expand Up @@ -308,21 +307,37 @@
}
}

shouldOpenTabInGlance(tab) {
tabDomainsDiffer(tab1, url2) {
try {
if (!tab1) {
return true;
}
let url1 = tab1.linkedBrowser.currentURI.spec;
if (url1.startsWith('about:')) {
return true;
}
return Services.io.newURI(url1).host !== url2.host;
} catch (e) {
return true;
}
}

shouldOpenTabInGlance(tab, uri) {
let owner = tab.owner;
return (
owner &&
owner.getAttribute('zen-essential') === 'true' &&
this._lazyPref.SHOULD_OPEN_EXTERNAL_TABS_IN_GLANCE &&
owner.linkedBrowser?.docShellIsActive &&
owner.linkedBrowser?.browsingContext?.isAppTab
owner.linkedBrowser?.browsingContext?.isAppTab &&
this.tabDomainsDiffer(owner, uri)
);
}

onTabOpen(event) {
let tab = event.target;
if (this.shouldOpenTabInGlance(tab)) {
this.openGlance({ url: undefined, x: 0, y: 0, width: 0, height: 0 }, tab);
onTabOpen(browser, uri) {
let tab = gBrowser.getTabForBrowser(browser);
if (this.shouldOpenTabInGlance(tab, uri)) {
this.openGlance({ url: undefined, x: 0, y: 0, width: 0, height: 0 }, tab, tab.owner);
}
}

Expand Down

0 comments on commit c9f9766

Please sign in to comment.