-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Does not build
- Loading branch information
Showing
27 changed files
with
1,262 additions
and
759 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "actors", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "content", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "extensions", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/// @ts-check | ||
/// <reference types="@browser/link" /> | ||
import { lazyESModuleGetters } from 'resource://app/modules/TypedImportUtils.sys.mjs' | ||
|
||
const lazy = lazyESModuleGetters({ | ||
ActorManagerParent: 'resource://gre/modules/ActorManagerParent.sys.mjs', | ||
}) | ||
|
||
const JS_PROCESS_ACTORS = {} | ||
const JS_WINDOW_ACTORS = { | ||
ClickHandler: { | ||
parent: { esModuleURI: 'resource://app/actors/ClickHandlerParent.sys.mjs' }, | ||
child: { | ||
esModuleURI: 'resource://app/actors/ClickHandlerChild.sys.mjs', | ||
events: { | ||
chromelinkclick: { capture: true, mozSystemGroup: true }, | ||
}, | ||
}, | ||
|
||
allFrames: true, | ||
}, | ||
|
||
ContextMenu: { | ||
parent: { | ||
esModuleURI: 'resource://app/actors/ContextMenuParent.sys.mjs', | ||
}, | ||
|
||
child: { | ||
esModuleURI: 'resource://app/actors/ContextMenuChild.sys.mjs', | ||
events: { | ||
contextmenu: { mozSystemGroup: true }, | ||
}, | ||
}, | ||
|
||
messageManagerGroups: ['browsers'], | ||
allFrames: true, | ||
}, | ||
|
||
LinkHandler: { | ||
parent: { | ||
esModuleURI: 'resource://app/actors/LinkHandlerParent.sys.mjs', | ||
}, | ||
child: { | ||
esModuleURI: 'resource://app/actors/LinkHandlerChild.sys.mjs', | ||
events: { | ||
DOMHeadElementParsed: {}, | ||
DOMLinkAdded: {}, | ||
DOMLinkChanged: {}, | ||
pageshow: {}, | ||
// The `pagehide` event is only used to clean up state which will not be | ||
// present if the actor hasn't been created. | ||
pagehide: { createActor: false }, | ||
}, | ||
}, | ||
messageManagerGroups: ['browsers'], | ||
}, | ||
} | ||
|
||
export class BrowserGlue { | ||
QueryInterface = ChromeUtils.generateQI(['nsIObserver']) | ||
|
||
constructor() { | ||
lazy.ActorManagerParent.addJSProcessActors(JS_PROCESS_ACTORS) | ||
lazy.ActorManagerParent.addJSWindowActors(JS_WINDOW_ACTORS) | ||
} | ||
|
||
// nsIObserver impl | ||
observe(aSubject, aTopic, aData) { | ||
// eslint-disable-next-line no-console | ||
console.log({ aSubject, aTopic, aData }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/// @ts-check | ||
/// <reference types="@browser/link" /> | ||
import mitt from 'resource://app/modules/mitt.sys.mjs' | ||
|
||
/** @type {import('resource://app/modules/BrowserWindowTracker.sys.mjs')['WindowTracker']} */ | ||
export const WindowTracker = { | ||
nextWindowId: 0, | ||
|
||
events: mitt(), | ||
|
||
activeWindow: null, | ||
registeredWindows: new Map(), | ||
|
||
/** | ||
* Registers a new browser window to be tracked | ||
* | ||
* @param w The window to register | ||
*/ | ||
registerWindow(w) { | ||
w.windowApi.id = this.nextWindowId++ | ||
this.registeredWindows.set(w.windowApi.id, w) | ||
this.events.emit('windowCreated', w) | ||
}, | ||
|
||
removeWindow(w) { | ||
this.registeredWindows.delete(w.windowApi.id) | ||
this.events.emit('windowDestroyed', w) | ||
}, | ||
|
||
getWindowById(wid) { | ||
return this.registeredWindows.get(wid) | ||
}, | ||
|
||
getWindowWithBrowser(browser) { | ||
for (const window of this.registeredWindows.values()) { | ||
const tab = window.windowApi.tabs.tabs.find( | ||
(t) => t.getTabId() === browser.browserId, | ||
) | ||
if (tab) return { window, tab } | ||
} | ||
return null | ||
}, | ||
|
||
focusWindow(id) { | ||
this.activeWindow = id | ||
this.events.emit('focus', this.getActiveWindow()) | ||
}, | ||
|
||
getActiveWindow() { | ||
return this.registeredWindows.get(this.activeWindow ?? -1) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/// @ts-check | ||
/// <reference types="@browser/link" /> | ||
import mitt from 'resource://app/modules/mitt.sys.mjs' | ||
|
||
/** | ||
* @typedef {import('resource://app/modules/EPageActions.sys.mjs').PageActionImpl} PageActionImpl | ||
*/ | ||
|
||
/** @implements {PageActionImpl} */ | ||
export class PageAction { | ||
/** @type {import('resource://app/modules/EPageActions.sys.mjs').PageActionImpl['events']} */ | ||
events = mitt() | ||
|
||
tooltip | ||
popupUrl | ||
showMatches | ||
hideMatches | ||
/** @type {Record<number, string>} */ | ||
icons | ||
|
||
showTabIds = new Set() | ||
hideTabIds = new Set() | ||
|
||
/** | ||
* @param {import('resource://app/modules/EPageActions.sys.mjs').PageActionOptions<string[]>} data | ||
*/ | ||
constructor(data) { | ||
this.tooltip = data.tooltip | ||
this.popupUrl = data.popupUrl | ||
this.showMatches = new MatchPatternSet(data.showMatches || []) | ||
this.hideMatches = new MatchPatternSet(data.hideMatches || []) | ||
} | ||
|
||
/** | ||
* @param {string} url | ||
* @param {number} tabId | ||
* @returns {boolean} | ||
*/ | ||
shouldShow(url, tabId) { | ||
const urlMatch = | ||
this.showMatches.matches(url) && | ||
!this.hideMatches.matches(url, true) && | ||
!this.hideTabIds.has(tabId) | ||
const idMatch = this.showTabIds.has(tabId) | ||
|
||
return urlMatch || idMatch | ||
} | ||
|
||
/** | ||
* @param {Record<number, string>} icons | ||
*/ | ||
setIcons(icons) { | ||
this.icons = icons | ||
this.events.emit('updateIcon', icons) | ||
} | ||
|
||
/** | ||
* @param {number} id | ||
*/ | ||
addShow(id) { | ||
this.showTabIds.add(id) | ||
this.hideTabIds.delete(id) | ||
} | ||
|
||
/** | ||
* @param {number} id | ||
*/ | ||
addHide(id) { | ||
this.hideTabIds.add(id) | ||
this.showTabIds.delete(id) | ||
} | ||
} | ||
|
||
/** @type {import('resource://app/modules/EPageActions.sys.mjs')['EPageActions']} */ | ||
export const EPageActions = { | ||
/** @type {import('resource://app/modules/EPageActions.sys.mjs')['EPageActions']['events']} */ | ||
events: mitt(), | ||
|
||
PageAction, | ||
pageActions: new Map(), | ||
|
||
/** | ||
* @param {string} extensionId | ||
* @param {PageAction} pageAction | ||
*/ | ||
registerPageAction(extensionId, pageAction) { | ||
if (EPageActions.pageActions.has(extensionId)) { | ||
EPageActions.removePageAction(extensionId) | ||
} | ||
|
||
EPageActions.pageActions.set(extensionId, pageAction) | ||
EPageActions.events.emit('register', { | ||
action: pageAction, | ||
extension: extensionId, | ||
}) | ||
}, | ||
|
||
/** | ||
* @param {string} extensionId | ||
*/ | ||
removePageAction(extensionId) { | ||
const action = EPageActions.pageActions.get(extensionId) | ||
if (!action) return | ||
|
||
EPageActions.pageActions.delete(extensionId) | ||
EPageActions.events.emit('remove', { action, extension: extensionId }) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/// @ts-check | ||
/// <reference types="@browser/link" /> | ||
|
||
/** @type {typeof import('resource://app/modules/TypedImportUtils.sys.mjs').lazyESModuleGetters} */ | ||
export const lazyESModuleGetters = (modules) => { | ||
/** @type {any} */ | ||
const lazy = {} | ||
ChromeUtils.defineESModuleGetters(lazy, modules) | ||
return lazy | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "@browser/modules", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"dependencies": { | ||
"@browser/link": "workspace:*" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "components", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "@browser/link", | ||
"version": "1.0.0", | ||
"description": "", | ||
"types": "./types/_link.d.ts", | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"gecko-types": "github:quark-platform/gecko-types", | ||
"mitt": "^3.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// This is the root file that will be imported everywhere. Add your new files | ||
// here to have them show up globally | ||
|
||
/// <reference types="gecko-types" /> | ||
|
||
/// <reference path="./globals/Cr.d.ts" /> | ||
/// <reference path="./globals/Elements.d.ts" /> | ||
/// <reference path="./globals/MatchPattern.d.ts" /> | ||
/// <reference path="./globals/MessageManager.d.ts" /> | ||
|
||
/// <reference path="./interfaces/GenericDeferred.d.ts" /> | ||
|
||
/// <reference path="./modules/AppConstants.d.ts" /> | ||
/// <reference path="./modules/BrowserWindowTracker.d.ts" /> | ||
/// <reference path="./modules/EPageActions.d.ts" /> | ||
/// <reference path="./modules/mitt.d.ts" /> | ||
/// <reference path="./modules/typedImport.d.ts" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare let Cr: Record<string, nsresult> |
Oops, something went wrong.