From 324fb0e9ac62b09f216bb22114e98fd3d72e357d Mon Sep 17 00:00:00 2001 From: Nikolai Ommundsen Date: Tue, 21 Nov 2017 13:01:33 +0100 Subject: [PATCH] Chrome: Webview element type declarations (WIP) --- types/chrome/chrome-app.d.ts | 2 +- types/chrome/chrome-webview.d.ts | 87 ++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 types/chrome/chrome-webview.d.ts diff --git a/types/chrome/chrome-app.d.ts b/types/chrome/chrome-app.d.ts index 5b75130b6a..4cd96aea8a 100644 --- a/types/chrome/chrome-app.d.ts +++ b/types/chrome/chrome-app.d.ts @@ -1,6 +1,6 @@ // Type definitions for Chrome packaged application development // Project: http://developer.chrome.com/apps/ -// Definitions by: Adam Lay , MIZUNE Pine , MIZUSHIMA Junki , Ingvar Stepanyan , Nikolai Ommundsen +// Definitions by: Adam Lay , MIZUNE Pine , MIZUSHIMA Junki , Ingvar Stepanyan , Nikolai Ommundsen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// diff --git a/types/chrome/chrome-webview.d.ts b/types/chrome/chrome-webview.d.ts new file mode 100644 index 0000000000..8c7bff8ac7 --- /dev/null +++ b/types/chrome/chrome-webview.d.ts @@ -0,0 +1,87 @@ +/// +// Project: http://developer.chrome.com/apps/ +// Definitions by: Nikolai Ommundsen +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 +// +// WebView ref: https://chromium.googlesource.com/chromium/src/+/a0d56194380757b87d9d687786acd8cb4284b3fa/chrome/common/extensions/api/webview_tag.json +// + +export interface WebViewWindowEvent extends chrome.events.Event<() => void> {}; + +export interface WebViewConsoleEvent extends Event { + /** + * @description The severity level of the log message. Ranges from 0 to 4. + * @type {number} + * @memberof ConsoleEvent + */ + level: number, + /** + * @description The logged message contents. + * @type {string} + * @memberof ConsoleEvent + */ + message: string, + /** + * @description The line number of the message source. + * @type {number} + * @memberof ConsoleEvent + */ + line: number, + /** + * @description A string identifying the resource which logged the message. + * @type {string} + * @memberof ConsoleEvent + */ + sourceId: string +} + + /** Description of a declarative rule for handling events. */ + export interface WebViewRule { + /** Optional priority of this rule. Defaults to 100. */ + priority?: number; + /** List of conditions that can trigger the actions. */ + conditions: any[]; + /** Optional. Optional identifier that allows referencing this rule. */ + id?: string; + /** List of actions that are triggered if one of the condtions is fulfilled. */ + actions: any[]; + /** + * @description Tags can be used to annotate rules and perform operations on sets of rules.ยจ + * @since Chrome 28 + * @type {string[]} + * @memberof WebViewRule + */ + tags?: string[]; + } + + /** + * @description Details of the script or CSS to inject. Either the code or the file property must be set, but both may not be set at the same time. + * @export + * @interface InjectDetails + */ + export interface WebViewInjectDetails { + /** + * @description JavaScript or CSS code to inject.

Warning:
Be careful using the code parameter. Incorrect use of it may open your app to cross site scripting attacks. + * @type {string} + * @memberof WebViewInjectDetails + */ + code?: string, + /** + * @description JavaScript or CSS file to inject. + * @type {string} + * @memberof WebViewInjectDetails + */ + file?: string + } + +export interface ChromeWebViewElementEventMap extends ElementEventMap { + 'message': WebViewConsoleEvent +} +export interface HTMLChromeWebViewElement extends Element { + executeScript?: (details: WebViewInjectDetails, callback?: (result: any) => void) => void, + src: string, + contentWindow: Window + addEventListener(type: K, listener: (this: HTMLChromeWebViewElement, ev: ChromeWebViewElementEventMap[K]) => any, useCapture?: boolean): void; + addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void; +}