Skip to content

Commit 4a1216d

Browse files
committed
Address PR comments.
1 parent f045568 commit 4a1216d

File tree

7 files changed

+20
-57
lines changed

7 files changed

+20
-57
lines changed

src/browser/base/content/zen-assets.jar.inc.mn

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@
5252
content/browser/zen-styles/zen-gradient-generator.css (../../zen/workspaces/zen-gradient-generator.css)
5353

5454
content/browser/zen-components/ZenKeyboardShortcuts.mjs (../../zen/kbs/ZenKeyboardShortcuts.mjs)
55-
content/browser/zen/modules/ZenAirTrafficControl.mjs (../../zen/modules/ZenAirTrafficControl.mjs)
56-
content/browser/zen/modules/ZenAirTrafficControlIntegration.mjs (../../zen/modules/ZenAirTrafficControlIntegration.mjs)
55+
56+
content/browser/zen-components/ZenAirTrafficControl.mjs (../../zen/atc/ZenAirTrafficControl.mjs)
57+
content/browser/zen-components/ZenAirTrafficControlIntegration.mjs (../../zen/atc/ZenAirTrafficControlIntegration.mjs)
5758

5859
content/browser/zen-components/ZenPinnedTabsStorage.mjs (../../zen/tabs/ZenPinnedTabsStorage.mjs)
5960
content/browser/zen-components/ZenPinnedTabManager.mjs (../../zen/tabs/ZenPinnedTabManager.mjs)

src/browser/components/preferences/zen-air-traffic-control.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
const { ZenAirTrafficControl } = ChromeUtils.importESModule(
6-
'chrome://browser/content/zen/modules/ZenAirTrafficControl.mjs'
6+
'chrome://browser/content/zen-components/ZenAirTrafficControl.mjs'
77
);
88

99
var gZenAirTrafficControlPane = {

src/browser/modules/BrowserDOMWindow-sys-mjs.patch

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/browser/modules/BrowserDOMWindow.sys.mjs b/browser/modules/BrowserDOMWindow.sys.mjs
2-
index 2bc4918c15b5ea80e486db66d20bb9668b9e29c0..c73cc27d443623b935c8243ed165acc399571bb6 100644
2+
index 2bc4918c15b5ea80e486db66d20bb9668b9e29c0..261ac326fe233df89b1a33870e0fbcf384783122 100644
33
--- a/browser/modules/BrowserDOMWindow.sys.mjs
44
+++ b/browser/modules/BrowserDOMWindow.sys.mjs
55
@@ -42,7 +42,6 @@ export class BrowserDOMWindow {
@@ -10,27 +10,23 @@ index 2bc4918c15b5ea80e486db66d20bb9668b9e29c0..c73cc27d443623b935c8243ed165acc3
1010
constructor(win) {
1111
this.win = win;
1212
}
13-
@@ -151,14 +150,45 @@ export class BrowserDOMWindow {
13+
@@ -151,6 +150,34 @@ export class BrowserDOMWindow {
1414
console.error("openURI should only be called with a valid URI");
1515
throw Components.Exception("", Cr.NS_ERROR_FAILURE);
1616
}
1717
+
1818
+ // Zen Air Traffic Control integration - intercept external links
1919
+ if (aURI && (aFlags & Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL)) {
2020
+ try {
21-
+ const { ZenAirTrafficControlIntegration } = ChromeUtils.importESModule(
22-
+ "chrome://browser/content/zen/modules/ZenAirTrafficControlIntegration.mjs"
23-
+ );
24-
+
25-
+ const decision = ZenAirTrafficControlIntegration.handleExternalLink(
21+
+ const decision = this.win.ZenAirTrafficControlIntegration.handleExternalLink(
2622
+ aURI,
2723
+ aWhere,
2824
+ this.win
2925
+ );
3026
+
3127
+ if (decision) {
3228
+ // Execute the routing and return the browsing context
33-
+ const browsingContext = ZenAirTrafficControlIntegration.executeRouting(
29+
+ const browsingContext = this.win.ZenAirTrafficControlIntegration.executeRouting(
3430
+ decision,
3531
+ aURI,
3632
+ this.win
@@ -49,16 +45,7 @@ index 2bc4918c15b5ea80e486db66d20bb9668b9e29c0..c73cc27d443623b935c8243ed165acc3
4945
return this.getContentWindowOrOpenURI(
5046
aURI,
5147
aOpenWindowInfo,
52-
aWhere,
53-
aFlags,
54-
aTriggeringPrincipal,
55-
- aCsp,
56-
- false
57-
+ aCsp
58-
);
59-
}
60-
61-
@@ -362,7 +392,7 @@ export class BrowserDOMWindow {
48+
@@ -362,7 +389,7 @@ export class BrowserDOMWindow {
6249
// Passing a null-URI to only create the content window,
6350
// and pass true for aSkipLoad to prevent loading of
6451
// about:blank
@@ -67,7 +54,7 @@ index 2bc4918c15b5ea80e486db66d20bb9668b9e29c0..c73cc27d443623b935c8243ed165acc3
6754
null,
6855
aParams,
6956
aWhere,
70-
@@ -370,6 +400,10 @@ export class BrowserDOMWindow {
57+
@@ -370,6 +397,10 @@ export class BrowserDOMWindow {
7158
aName,
7259
true
7360
);

src/zen/modules/ZenAirTrafficControl.mjs renamed to src/zen/atc/ZenAirTrafficControl.mjs

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
// --- helpers --------------------------------------------------------------
6-
75
const escapeRegExp = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
86

97
const MATCHER_FACTORIES = {
@@ -13,33 +11,27 @@ const MATCHER_FACTORIES = {
1311
endsWith: (v) => new RegExp(`${escapeRegExp(v)}$`, 'i'),
1412
regex: (v) => new RegExp(v, 'i'),
1513
};
16-
1714
const VALID_MATCH_TYPES = Object.keys(MATCHER_FACTORIES);
1815

19-
// Environment helpers (Firefox chrome JS) ----------------------------------
2016
const PREF_KEY = 'zen.airTrafficControl.rules';
2117
const readPref = () => Services.prefs.getStringPref(PREF_KEY, '[]');
2218
const writePref = (json) => Services.prefs.setStringPref(PREF_KEY, json);
2319

24-
// --- class ----------------------------------------------------------------
2520
class ZenAirTrafficControlImpl {
2621
_rules = [];
2722
_initialized = false;
2823

29-
/* --------------------------------------------------------------------- */
3024
init() {
3125
if (this._initialized) return;
32-
this._loadRules();
26+
this.loadRules();
3327
this._initialized = true;
3428
}
3529

36-
// Convenience – auto-initialise on first public call.
3730
_ensureInit() {
3831
if (!this._initialized) this.init();
3932
}
4033

41-
/* --------------------------------------------------------------------- */
42-
_loadRules() {
34+
loadRules() {
4335
try {
4436
this._rules = JSON.parse(readPref());
4537
this._sortRules();
@@ -49,7 +41,7 @@ class ZenAirTrafficControlImpl {
4941
}
5042
}
5143

52-
_saveRules() {
44+
saveRules() {
5345
try {
5446
writePref(JSON.stringify(this._rules));
5547
} catch (e) {
@@ -61,7 +53,6 @@ class ZenAirTrafficControlImpl {
6153
this._rules.sort((a, b) => a.createdAt - b.createdAt);
6254
}
6355

64-
/* --------------------------------------------------------------------- */
6556
_validateRuleShape({ matchType, matchValue, workspaceId }) {
6657
if (!VALID_MATCH_TYPES.includes(matchType)) {
6758
throw new Error(`ZenATC: invalid matchType '${matchType}'`);
@@ -74,7 +65,6 @@ class ZenAirTrafficControlImpl {
7465
}
7566
}
7667

77-
/* --------------------------------------------------------------------- */
7868
createRule(rule) {
7969
this._ensureInit();
8070
this._validateRuleShape(rule);
@@ -88,7 +78,7 @@ class ZenAirTrafficControlImpl {
8878

8979
this._rules.push(newRule);
9080
this._sortRules();
91-
this._saveRules();
81+
this.saveRules();
9282
return newRule;
9383
}
9484

@@ -101,22 +91,20 @@ class ZenAirTrafficControlImpl {
10191
this._validateRuleShape(updated);
10292

10393
this._rules[idx] = updated;
104-
this._saveRules();
94+
this.saveRules();
10595
}
10696

10797
deleteRule(uuid) {
10898
this._ensureInit();
10999
this._rules = this._rules.filter((r) => r.uuid !== uuid);
110-
this._saveRules();
100+
this.saveRules();
111101
}
112102

113-
/* --------------------------------------------------------------------- */
114103
getRules() {
115104
this._ensureInit();
116105
return [...this._rules];
117106
}
118107

119-
/* --------------------------------------------------------------------- */
120108
_createMatcher(rule) {
121109
const factory = MATCHER_FACTORIES[rule.matchType];
122110
return factory(rule.matchValue);
@@ -127,26 +115,13 @@ class ZenAirTrafficControlImpl {
127115
return this._rules.find((r) => r.enabled && this._createMatcher(r).test(url)) || null;
128116
}
129117

130-
/* --------------------------------------------------------------------- */
131118
routeURL(url, _context = {}) {
132119
this._ensureInit();
133120
const rule = this._findFirstMatchingRule(url);
134121
if (!rule) return null;
135122
return { rule, workspaceId: rule.workspaceId };
136123
}
137124

138-
/* --------------------------------------------------------------------- */
139-
// Compatibility wrappers ------------------------------------------------
140-
/** Reload rules from storage (primarily used by tests/UI). */
141-
loadRules() {
142-
this._loadRules();
143-
}
144-
145-
/** Persist current rule list to storage (primarily used by tests/UI). */
146-
saveRules() {
147-
this._saveRules();
148-
}
149-
150125
/** Return *all* enabled rules that match the given URL. */
151126
findMatchingRules(url) {
152127
this._ensureInit();
@@ -161,5 +136,4 @@ class ZenAirTrafficControlImpl {
161136
}
162137
}
163138

164-
// Single exported instance (backward-compatible with previous object export)
165139
export const ZenAirTrafficControl = new ZenAirTrafficControlImpl();

src/zen/modules/ZenAirTrafficControlIntegration.mjs renamed to src/zen/atc/ZenAirTrafficControlIntegration.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const lazy = {};
66

77
ChromeUtils.defineLazyGetter(lazy, 'ZenAirTrafficControl', () => {
88
const { ZenAirTrafficControl } = ChromeUtils.importESModule(
9-
'chrome://browser/content/zen/modules/ZenAirTrafficControl.mjs'
9+
'chrome://browser/content/zen-components/ZenAirTrafficControl.mjs'
1010
);
1111
return ZenAirTrafficControl;
1212
});

src/zen/common/ZenStartup.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@
6868
_initAirTrafficControl() {
6969
try {
7070
const { ZenAirTrafficControl } = ChromeUtils.importESModule(
71-
'chrome://browser/content/zen/modules/ZenAirTrafficControl.mjs'
71+
'chrome://browser/content/zen-components/ZenAirTrafficControl.mjs'
7272
);
7373

7474
const { ZenAirTrafficControlIntegration } = ChromeUtils.importESModule(
75-
'chrome://browser/content/zen/modules/ZenAirTrafficControlIntegration.mjs'
75+
'chrome://browser/content/zen-components/ZenAirTrafficControlIntegration.mjs'
7676
);
7777

7878
ZenAirTrafficControl.init();

src/zen/workspaces/ZenWorkspaces.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,6 +2280,7 @@ var gZenWorkspaces = new (class extends ZenMultiWindowFeature {
22802280
// routed workspace, and then the workspace gets switched back to the previously
22812281
// active workspace.
22822282
if (tab.hasAttribute('zen-atc-created')) {
2283+
tab.removeAttribute('zen-atc-created');
22832284
return;
22842285
}
22852286

0 commit comments

Comments
 (0)