-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add add-tab action and command to link to add-tab-button
- Loading branch information
1 parent
c12c8dc
commit 01d93ba
Showing
5 changed files
with
96 additions
and
2 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
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,50 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
/** | ||
* @typedef {import("components/actions/Action.sys.mjs").ActionDispatchEvent<T>} ActionDispatchEvent | ||
* @template T | ||
*/ | ||
|
||
const { Action } = ChromeUtils.importESModule( | ||
"resource://gre/modules/Action.sys.mjs" | ||
); | ||
|
||
export class BrowserTabsAddTabAction extends Action { | ||
static id = "browser.tabs.add_tab"; | ||
|
||
constructor() { | ||
super(); | ||
} | ||
|
||
/** | ||
* The name of this action | ||
*/ | ||
get name() { | ||
return "Create tab"; | ||
} | ||
|
||
/** | ||
* Performs this action | ||
* @param {ActionDispatchEvent<{ url: string | string[] }>} event | ||
*/ | ||
run(event) { | ||
const { args } = event.detail; | ||
|
||
if (!args.url) throw new Error("No 'url' argument supplied!"); | ||
|
||
const win = event.target.ownerGlobal; | ||
const { gDot } = win; | ||
|
||
const params = { | ||
triggeringPrincipal: | ||
Services.scriptSecurityManager.getSystemPrincipal() | ||
}; | ||
|
||
gDot.tabs.createTabs( | ||
Array.isArray(args.url) ? args.url : [args.url], | ||
params | ||
); | ||
} | ||
} |
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
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,42 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
const { Command } = ChromeUtils.importESModule( | ||
"resource://gre/modules/Command.sys.mjs" | ||
); | ||
|
||
const { StartPage } = ChromeUtils.importESModule( | ||
"resource:///modules/StartPage.sys.mjs" | ||
); | ||
|
||
export class AddTabCommand extends Command { | ||
constructor(subscription, area) { | ||
super(subscription, area); | ||
|
||
this.label = "New Tab"; | ||
this.label_auxiliary = "Open a new tab"; | ||
this.icon = "add"; | ||
} | ||
|
||
/** | ||
* Performs this command | ||
* | ||
* @param {{ urls?: string[], url?: string }} args | ||
*/ | ||
run(args) { | ||
let urls = []; | ||
|
||
if (args.url || args.urls) { | ||
if (args.url) urls.push(args.url); | ||
|
||
urls = urls.concat(args.urls || []); | ||
} else { | ||
urls = StartPage.getHomePage(); | ||
} | ||
|
||
for (const url of urls) { | ||
this.actions.run("browser.tabs.add_tab", { url }); | ||
} | ||
} | ||
} |
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