aboutsummaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/operations.ts33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/shared/operations.ts b/src/shared/operations.ts
index 0f0d0c0..2b03d9d 100644
--- a/src/shared/operations.ts
+++ b/src/shared/operations.ts
@@ -78,6 +78,9 @@ export const MARK_JUMP_PREFIX = 'mark.jump.prefix';
// Repeat
export const REPEAT_LAST = 'repeat.last';
+// Internal
+export const INTERNAL_OPEN_URL = 'internal.open.url';
+
export interface CancelOperation {
type: typeof CANCEL;
}
@@ -298,6 +301,14 @@ export interface RepeatLastOperation {
type: typeof REPEAT_LAST;
}
+export interface InternalOpenUrl {
+ type: typeof INTERNAL_OPEN_URL;
+ url: string;
+ newTab?: boolean;
+ newWindow?: boolean;
+ background?: boolean;
+}
+
export type Operation =
CancelOperation |
AddonEnableOperation |
@@ -350,7 +361,8 @@ export type Operation =
FindPrevOperation |
MarkSetPrefixOperation |
MarkJumpPrefixOperation |
- RepeatLastOperation;
+ RepeatLastOperation |
+ InternalOpenUrl;
const assertOptionalBoolean = (obj: any, name: string) => {
if (Object.prototype.hasOwnProperty.call(obj, name) &&
@@ -366,6 +378,13 @@ const assertRequiredNumber = (obj: any, name: string) => {
}
};
+const assertRequiredString = (obj: any, name: string) => {
+ if (!Object.prototype.hasOwnProperty.call(obj, name) ||
+ typeof obj[name] !== 'string') {
+ throw new TypeError(`Missing string parameter '${name}`);
+ }
+};
+
// eslint-disable-next-line complexity, max-lines-per-function
export const valueOf = (o: any): Operation => {
if (!Object.prototype.hasOwnProperty.call(o, 'type')) {
@@ -409,6 +428,18 @@ export const valueOf = (o: any): Operation => {
type: URLS_PASTE,
newTab: Boolean(typeof o.newTab === undefined ? false : o.newTab),
};
+ case INTERNAL_OPEN_URL:
+ assertOptionalBoolean(o, 'newTab');
+ assertOptionalBoolean(o, 'newWindow');
+ assertOptionalBoolean(o, 'background');
+ assertRequiredString(o, 'url');
+ return {
+ type: INTERNAL_OPEN_URL,
+ url: o.url,
+ newTab: Boolean(typeof o.newTab === undefined ? false : o.newTab),
+ newWindow: Boolean(typeof o.newWindow === undefined ? false : o.newWindow), // eslint-disable-line max-len
+ background: Boolean(typeof o.background === undefined ? true : o.background), // eslint-disable-line max-len
+ };
case CANCEL:
case ADDON_ENABLE:
case ADDON_DISABLE: