Add additional comments

This commit is contained in:
hensm
2021-05-04 12:20:31 +01:00
parent 7854208b64
commit 453274307f
6 changed files with 30 additions and 32 deletions

View File

@@ -32,7 +32,6 @@ let menuIdWhitelistRecommended: MenuId;
const whitelistChildMenuPatterns = new Map<MenuId, string>(); const whitelistChildMenuPatterns = new Map<MenuId, string>();
export async function initMenus() { export async function initMenus() {
logger.info("init (menus)"); logger.info("init (menus)");
@@ -90,7 +89,6 @@ browser.menus.onClicked.addListener(async (info, tab) => {
return; return;
} }
if (tab?.id === undefined) { if (tab?.id === undefined) {
throw logger.error("Menu handler tab ID not found."); throw logger.error("Menu handler tab ID not found.");
} }
@@ -192,7 +190,6 @@ browser.menus.onShown.addListener(async info => {
return; return;
} }
/** /**
* If page URL doesn't exist, we're not on a page and have * If page URL doesn't exist, we're not on a page and have
* nothing to whitelist, so disable the menu and return. * nothing to whitelist, so disable the menu and return.
@@ -206,7 +203,6 @@ browser.menus.onShown.addListener(async info => {
return; return;
} }
const url = new URL(info.pageUrl); const url = new URL(info.pageUrl);
const urlHasOrigin = url.origin !== "null"; const urlHasOrigin = url.origin !== "null";
@@ -224,13 +220,11 @@ browser.menus.onShown.addListener(async info => {
return; return;
} }
// Enable the whitelist menu // Enable the whitelist menu
browser.menus.update(menuIdWhitelist, { browser.menus.update(menuIdWhitelist, {
enabled: true enabled: true
}); });
for (const [ menuId ] of whitelistChildMenuPatterns) { for (const [ menuId ] of whitelistChildMenuPatterns) {
// Clear all page-specific temporary menus // Clear all page-specific temporary menus
if (menuId !== menuIdWhitelistRecommended) { if (menuId !== menuIdWhitelistRecommended) {
@@ -240,7 +234,6 @@ browser.menus.onShown.addListener(async info => {
whitelistChildMenuPatterns.delete(menuId); whitelistChildMenuPatterns.delete(menuId);
} }
// If there is more than one subdomain, get the base domain // If there is more than one subdomain, get the base domain
const baseDomain = (url.hostname.match(/\./g) || []).length > 1 const baseDomain = (url.hostname.match(/\./g) || []).length > 1
? url.hostname.substring(url.hostname.indexOf(".") + 1) ? url.hostname.substring(url.hostname.indexOf(".") + 1)
@@ -254,7 +247,6 @@ browser.menus.onShown.addListener(async info => {
const patternWildcardSubdomain = `${url.protocol}//*.${baseDomain}/*`; const patternWildcardSubdomain = `${url.protocol}//*.${baseDomain}/*`;
const patternWildcardProtocolAndSubdomain = `*://*.${baseDomain}/*`; const patternWildcardProtocolAndSubdomain = `*://*.${baseDomain}/*`;
// Update recommended menu item // Update recommended menu item
browser.menus.update(menuIdWhitelistRecommended, { browser.menus.update(menuIdWhitelistRecommended, {
title: _("contextAddToWhitelistRecommended", patternRecommended) title: _("contextAddToWhitelistRecommended", patternRecommended)
@@ -274,7 +266,6 @@ browser.menus.onShown.addListener(async info => {
whitelistSearchMenuId, patternSearch); whitelistSearchMenuId, patternSearch);
} }
/** /**
* Split URL path into segments and add menu items for each * Split URL path into segments and add menu items for each
* partial path as the segments are removed. * partial path as the segments are removed.
@@ -308,7 +299,6 @@ browser.menus.onShown.addListener(async info => {
} }
} }
const wildcardProtocolMenuId = browser.menus.create({ const wildcardProtocolMenuId = browser.menus.create({
title: _("contextAddToWhitelistAdvancedAdd" title: _("contextAddToWhitelistAdvancedAdd"
, patternWildcardProtocol) , patternWildcardProtocol)

View File

@@ -4,6 +4,9 @@ interface TypedEvents {
[key: string]: any; [key: string]: any;
} }
/**
* Provides a typed interface to EventTarget objects.
*/
export class TypedEventTarget<T extends TypedEvents> extends EventTarget { export class TypedEventTarget<T extends TypedEvents> extends EventTarget {
// @ts-ignore // @ts-ignore
public addEventListener<K extends keyof T>( public addEventListener<K extends keyof T>(

View File

@@ -1,5 +1,8 @@
"use strict"; "use strict";
/**
* Provides a typed interface to MessagePort objects.
*/
export interface TypedMessagePort<T> extends MessagePort { export interface TypedMessagePort<T> extends MessagePort {
postMessage(message: T, transfer: Transferable[]): void; postMessage(message: T, transfer: Transferable[]): void;
postMessage(message: T, options?: PostMessageOptions): void; postMessage(message: T, options?: PostMessageOptions): void;

View File

@@ -1,7 +1,7 @@
"use strict"; "use strict";
/** /**
* Allows typed access to a runtime.Port object. * Provides a typed interface to runtime.Port objects.
*/ */
export interface TypedPort<T> export interface TypedPort<T>
extends Omit<browser.runtime.Port extends Omit<browser.runtime.Port

View File

@@ -2,20 +2,17 @@
import semver from "semver"; import semver from "semver";
import { TypedPort } from "./TypedPort";
import logger from "./logger"; import logger from "./logger";
import { Message, Port } from "../messaging"; import { Port } from "../messaging";
import nativeMessaging from "./nativeMessaging"; import nativeMessaging from "./nativeMessaging";
import options from "./options"; import options from "./options";
import { ReceiverDevice } from "../types";
import { ReceiverSelectionCast
, ReceiverSelectionStop } from "../background/receiverSelector/ReceiverSelector";
export const BRIDGE_TIMEOUT = 5000; export const BRIDGE_TIMEOUT = 5000;
/**
* Creates a bridge instance and returns a message port.
*/
async function connect(): Promise<Port> { async function connect(): Promise<Port> {
const applicationName = await options.get("bridgeApplicationName"); const applicationName = await options.get("bridgeApplicationName");
const bridgePort = nativeMessaging.connectNative(applicationName) as const bridgePort = nativeMessaging.connectNative(applicationName) as
@@ -47,6 +44,12 @@ export interface BridgeInfo {
export class BridgeConnectionError extends Error {} export class BridgeConnectionError extends Error {}
export class BridgeTimedOutError extends Error {} export class BridgeTimedOutError extends Error {}
/**
* Creates a temporary bridge to query the version info,
* compares the version to the extension version using semver
* rules to determine compatiblity, then returns a
* BridgeInfo object.
*/
const getInfo = () => new Promise<BridgeInfo>(async (resolve, reject) => { const getInfo = () => new Promise<BridgeInfo>(async (resolve, reject) => {
const applicationName = await options.get("bridgeApplicationName"); const applicationName = await options.get("bridgeApplicationName");
if (!applicationName) { if (!applicationName) {

View File

@@ -1,33 +1,32 @@
"use strict"; "use strict";
/** /**
* Cast sender API loader script URL. * Cast Chrome Sender SDK loader script.
* *
* Since the actual cast sender API script is hosted locally * Since the actual SDK script is hosted locally within Chrome,
* within Chrome, this script just acts a loader script for * this script just acts a loader script whilst also doing some
* the real script whilst also doing some UA string * UA string checking.
* checking.
*/ */
export const CAST_LOADER_SCRIPT_URL = export const CAST_LOADER_SCRIPT_URL =
"https://www.gstatic.com/cv/js/sender/v1/cast_sender.js"; "https://www.gstatic.com/cv/js/sender/v1/cast_sender.js";
/** /**
* Framework API loader script URL. * Cast Chrome Sender Framework API loader script.
* *
* Same URL as the usual loader script, but the additional * Same URL as the usual loader script, but the additional
* search parameter is checked from within the script and * search parameter is checked from within the script and
* the framework API script is conditionally loaded in * the framework API script is conditionally loaded in
* addition to the regular API script. * addition to the regular SDK script.
*/ */
export const CAST_FRAMEWORK_LOADER_SCRIPT_URL = export const CAST_FRAMEWORK_LOADER_SCRIPT_URL =
`${CAST_LOADER_SCRIPT_URL}?loadCastFramework=1`; `${CAST_LOADER_SCRIPT_URL}?loadCastFramework=1`;
/** /**
* Cast API script URLs. * Cast extension URLs.
* *
* Cast functionality in Chrome was previously provided by * Cast functionality in Chrome was previously provided by
* an extension. The cast API script is still provided via * an extension. The cast SDK scripts are still provided via
* chrome-extension URLs for compatibility reasons. * chrome-extension: URLs for compatibility reasons (?).
*/ */
export const CAST_SCRIPT_URLS = [ export const CAST_SCRIPT_URLS = [
"chrome-extension://pkedcjkdefgpdelpbcmbmeomcjbeemfm/cast_sender.js" "chrome-extension://pkedcjkdefgpdelpbcmbmeomcjbeemfm/cast_sender.js"
@@ -35,11 +34,11 @@ export const CAST_SCRIPT_URLS = [
]; ];
/** /**
* Framework API script URL. * Cast Chrome Sender Framework API script.
* *
* Unlike the basic cast sender API, the framework API is * The Cast Application Framework (CAF) is implemented as a
* not hosted locally within Chrome and is the only script * wrapper around the base SDK, and ditributed remotely, as
* fetched directly from Google servers. * opposed to within the cast extension.
*/ */
export const CAST_FRAMEWORK_SCRIPT_URL = export const CAST_FRAMEWORK_SCRIPT_URL =
"https://www.gstatic.com/cast/sdk/libs/sender/1.0/cast_framework.js"; "https://www.gstatic.com/cast/sdk/libs/sender/1.0/cast_framework.js";