From 0484f93c1e0712806ceef8841364c5dab485b98a Mon Sep 17 00:00:00 2001
From: Nikolai Ommundsen Posts a message to the embedded web content as long as the embedded content is displaying a page from the target origin. This method is available once the page has completed loading. Listen for the contentload event and then call the method. The guest will be able to send replies to the embedder by posting message to event.source on the message event it receives. This API is identical to the HTML5 postMessage API for communication between web pages. The embedder may listen for replies by adding a message event listener to its own frame. Posts a message to the embedded web content as long as the embedded content is displaying a page from the target origin. This method is available once the page has completed loading. Listen for the contentload event and then call the method. The guest will be able to send replies to the embedder by posting message to event.source on the message event it receives. This API is identical to the HTML5 postMessage API for communication between web pages. The embedder may listen for replies by adding a message event listener to its own frame. To illustrate how usage differs from the extensions webRequest API, consider the following example code which blocks any guest requests for URLs which match *://www.evil.com/*: To illustrate how usage differs from the extensions webRequest API, consider the following example code which blocks any guest requests for URLs which match *://www.evil.com/*: Additionally, this interface supports declarative webRequest rules through onRequest and onMessage events. See declarativeWebRequest for API details.webview and interact with the web content, initiate navigations in an embedded web page, react to error events that happen within it, and more (see Usage).
+ * Use the webview tag to actively load live content from the web over the network and embed it in your Chrome App. Your app can control the appearance of the webview and interact with the web content, initiate navigations in an embedded web page, react to error events that happen within it, and more (see Usage).
*/
namespace webview {
/** Options that determine what data should be cleared by `clearData`. */
@@ -4611,7 +4661,7 @@ declare namespace chrome {
*/
interface InjectDetails {
/**
- * @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.
+ * @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 InjectDetails
*/
@@ -4717,21 +4767,21 @@ declare namespace chrome {
/**
* The different contexts a menu can appear in. Specifying 'all' is equivalent to the combination of all other contexts.
* Enum values:
- * "all"
- * "page"
- * "frame"
- * "selection"
- * "link"
- * "editable"
- * "image"
- * "video"
- * "audio" */
- export type ContextType = "all" | "page" | "frame" | "selection" | "link" | "editable" | "image" | "video" | "audio";
+ * 'all'
+ * 'page'
+ * 'frame'
+ * 'selection'
+ * 'link'
+ * 'editable'
+ * 'image'
+ * 'video'
+ * 'audio' */
+ export type ContextType = 'all' | 'page' | 'frame' | 'selection' | 'link' | 'editable' | 'image' | 'video' | 'audio';
/**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. */
interface InjectDetails {
/**
- * @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.
+ * @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.
*/
code?: string
@@ -4787,7 +4837,7 @@ declare namespace chrome {
js?: InjectionItems
/**
- * @description The soonest that the JavaScript or CSS will be injected into the tab. Defaults to "document_idle".
+ * @description The soonest that the JavaScript or CSS will be injected into the tab. Defaults to 'document_idle'.
*/
run_at?: chrome.extensionTypes.RunAt;
@@ -4820,7 +4870,7 @@ declare namespace chrome {
id?: string
/**
- * @description The text to be displayed in the item; this is required unless type is 'separator'. When the context is 'selection', you can use %s within the string to show the selected text. For example, if this parameter's value is "Translate '%s' to Pig Latin" and the user selects the word "cool", the context menu item for the selection is "Translate 'cool' to Pig Latin".
+ * @description The text to be displayed in the item; this is required unless type is 'separator'. When the context is 'selection', you can use %s within the string to show the selected text. For example, if this parameter's value is 'Translate '%s' to Pig Latin' and the user selects the word 'cool', the context menu item for the selection is 'Translate 'cool' to Pig Latin'.
*/
title?: string
@@ -4956,7 +5006,7 @@ declare namespace chrome {
interface ContentWindow {
/**
- * @description webview.request.onBeforeRequest.addListener(
+ /**Interface which provides access to webRequest events on the guest page. See the chrome.webRequest extensions API for details on webRequest life cycle and related concepts.
webview.request.onBeforeRequest.addListener(
function(details) { return {cancel: true}; },
- {urls: ["*://www.evil.com/*"]},
- ["blocking"]);
var rule = {
+ {urls: ['*://www.evil.com/*']},
+ ['blocking']);Additionally, this interface supports declarative webRequest rules through onRequest and onMessage events. See declarativeWebRequest for API details.
Note that conditions and actions for declarative webview webRequests should be instantiated from their chrome.webViewRequest.* counterparts. The following example code declaratively blocks all requests to 'example.com' on the webview myWebview:var rule = {
conditions: [
new chrome.webViewRequest.RequestMatcher({ url: { hostSuffix: 'example.com' } })
],
@@ -5156,13 +5206,13 @@ declare namespace chrome {
/**
* Defines the how zooming is handled in the webview.
* Enum values:
- * "per-origin"
+ * 'per-origin'
* * Zoom changes will persist in the zoomed page's origin, i.e. all other webviews in the same partition that are navigated to that same origin will be zoomed as well. Moreover, per-origin zoom changes are saved with the origin, meaning that when navigating to other pages in the same origin, they will all be zoomed to the same zoom factor.
- * "per-view"
+ * 'per-view'
* * Zoom changes only take effect in this webview, and zoom changes in other webviews will not affect the zooming of this webview. Also, per-view zoom changes are reset on navigation; navigating a webview will always load pages with their per-origin zoom factors (within the scope of the partition).
- * "disabled"
+ * 'disabled'
* * Disables all zooming in the webview. The content will revert to the default zoom level, and all attempted zoom changes will be ignored. */
- export type ZoomMode = "per-origin" | "per-view" | "disabled";
+ export type ZoomMode = 'per-origin' | 'per-view' | 'disabled';
/**
* @description Queries audio state.
@@ -5206,7 +5256,7 @@ declare namespace chrome {
{
name: 'anotherRule',
matches: ['http://www.bar.com/*'],
- js: { code: "document.body.style.backgroundColor = 'red';" },
+ js: { code: 'document.body.style.backgroundColor = 'red';' },
run_at: 'document_end'
}]);
...
@@ -5256,7 +5306,7 @@ declare namespace chrome {
export function clearData(options: ClearDataOptions, types: ClearDataTypeSet, callback?: () => void): void;
/**
- * @description Injects JavaScript code into the guest page.
The following sample code uses script injection to set the guest page's background color to red:
webview.executeScript({ code: "document.body.style.backgroundColor = 'red'" });
+ * @description Injects JavaScript code into the guest page.
The following sample code uses script injection to set the guest page's background color to red:
webview.executeScript({ code: 'document.body.style.backgroundColor = 'red'' });
* @param {any} details Details of the script to run.
* @param {any} [object Object]
*/
@@ -5277,7 +5327,7 @@ declare namespace chrome {
export function forward(callback?: (success: boolean) => void): void;
/**
- * @description Returns Chrome's internal process ID for the guest web page's current process, allowing embedders to know how many guests would be affected by terminating the process. Two guests will share a process only if they belong to the same app and have the same storage partition ID. The call is synchronous and returns the embedder's cached notion of the current process ID. The process ID isn't the same as the operating system's process ID.
+ * @description Returns Chrome's internal process ID for the guest web page's current process, allowing embedders to know how many guests would be affected by terminating the process. Two guests will share a process only if they belong to the same app and have the same storage partition ID. The call is synchronous and returns the embedder's cached notion of the current process ID. The process ID isn't the same as the operating system's process ID.
*/
export function getProcessId(): void;
@@ -5328,7 +5378,7 @@ declare namespace chrome {
export function reload(): void;
/**
- * @description Removes content scripts from a webview.
The following example removes "myRule" which was added before.
webview.removeContentScripts(['myRule']);
You can remove all the rules by calling:
webview.removeContentScripts();
+ * @description Removes content scripts from a webview.
The following example removes 'myRule' which was added before.
webview.removeContentScripts(['myRule']);
You can remove all the rules by calling:
webview.removeContentScripts();
* @param {any[]} scriptNameList A list of names of content scripts that will be removed. If the list is empty, all the content scripts added to the webview will be removed.
*/
export function removeContentScripts(scriptNameList?: any[]): void;
@@ -5396,7 +5446,7 @@ declare namespace chrome {
/**
* @description Fired when the guest window fires a load event, i.e., when a new document is loaded. This does not include page navigation within the current document or asynchronous resource loads. The following example code modifies the default font size of the guest's body element after the page loads:
webview.addEventListener('contentload', function() {
- webview.executeScript({ code: 'document.body.style.fontSize = "42px"' });
+ webview.executeScript({ code: 'document.body.style.fontSize = '42px'' });
});
*/
@@ -5428,7 +5478,7 @@ declare namespace chrome {
export var findupdate: chrome.events.Event;
/**
- * @description Fired when a top-level load has aborted without committing. An error message will be printed to the console unless the event is default-prevented. Note: When a resource load is aborted, a loadabort event will eventually be followed by a loadstop event, even if all committed loads since the last loadstop event (if any) were aborted.
Note: When the load of either an about URL or a JavaScript URL is aborted, loadabort will be fired and then the webview will be navigated to 'about:blank'.
+ * @description Fired when a top-level load has aborted without committing. An error message will be printed to the console unless the event is default-prevented. Note: When a resource load is aborted, a loadabort event will eventually be followed by a loadstop event, even if all committed loads since the last loadstop event (if any) were aborted.
Note: When the load of either an about URL or a JavaScript URL is aborted, loadabort will be fired and then the webview will be navigated to 'about:blank'.
* @param {any} [object Object]
*/
@@ -5456,7 +5506,7 @@ declare namespace chrome {
export var loadstart: chrome.events.Event;
/**
- * @description Fired when all frame-level loads in a guest page (including all its subframes) have completed. This includes navigation within the current document as well as subframe document-level loads, but does not include asynchronous resource loads. This event fires every time the number of document-level loads transitions from one (or more) to zero. For example, if a page that has already finished loading (i.e., loadstop already fired once) creates a new iframe which loads a page, then a second loadstop will fire when the iframe page load completes. This pattern is commonly observed on pages that load ads. Note: When a committed load is aborted, a loadstop event will eventually follow a loadabort event, even if all committed loads since the last loadstop event (if any) were aborted.
+ * @description Fired when all frame-level loads in a guest page (including all its subframes) have completed. This includes navigation within the current document as well as subframe document-level loads, but does not include asynchronous resource loads. This event fires every time the number of document-level loads transitions from one (or more) to zero. For example, if a page that has already finished loading (i.e., loadstop already fired once) creates a new iframe which loads a page, then a second loadstop will fire when the iframe page load completes. This pattern is commonly observed on pages that load ads. Note: When a committed load is aborted, a loadstop event will eventually follow a loadabort event, even if all committed loads since the last loadstop event (if any) were aborted.
*/
export function loadstop(event: chrome.events.Event): void;
From 5f5f1cd60485c20cdf0e039703e04b8303a398c1 Mon Sep 17 00:00:00 2001
From: Nikolai Ommundsen
Date: Thu, 14 Jun 2018 10:25:43 +0200
Subject: [PATCH 02/16] Removed old declaration for extensions only according
to the docs
---
types/chrome-apps/index.d.ts | 12 ------------
1 file changed, 12 deletions(-)
diff --git a/types/chrome-apps/index.d.ts b/types/chrome-apps/index.d.ts
index b18397317c..094fcc7347 100644
--- a/types/chrome-apps/index.d.ts
+++ b/types/chrome-apps/index.d.ts
@@ -243,18 +243,6 @@ declare namespace chrome {
export var onAlarm: AlarmEvent;
}
-
- ////////////////////
- // App
- ////////////////////
- namespace app {
- interface AppDetails extends chrome.runtime.Manifest {
- id: string;
- }
-
- export function getDetails(): AppDetails;
- }
-
////////////////////
// App Runtime
////////////////////
From 65a66ea68fdf67bad55542bee034ef46b5ea3d7a Mon Sep 17 00:00:00 2001
From: Nikolai Ommundsen
Date: Thu, 14 Jun 2018 10:35:14 +0200
Subject: [PATCH 03/16] Updated definitions of chrome.runtime
---
types/chrome-apps/index.d.ts | 68 ++++++++++++++++++++++++++++++++++--
1 file changed, 66 insertions(+), 2 deletions(-)
diff --git a/types/chrome-apps/index.d.ts b/types/chrome-apps/index.d.ts
index 094fcc7347..7d3ea8dfa9 100644
--- a/types/chrome-apps/index.d.ts
+++ b/types/chrome-apps/index.d.ts
@@ -252,27 +252,91 @@ declare namespace chrome {
'about_page' | 'keyboard' | 'extensions_page' | 'management_api' | 'ephemeral_app' |
'background' | 'kiosk' | 'chrome_internal' | 'test' | 'installed_notification' | 'context_menu';
+ interface EmbedRequest {
+ /**
+ * Optional developer specified data that the app to be embedded can use when making an embedding decision.
+ */
+ data?: any;
+ /**
+ * Allows embedderId to embed this app in an element. The url specifies the content to embed.
+ */
+ allow: (url: string) => void;
+ /**
+ * Prevents embedderId from embedding this app in an element.
+ */
+ deny: () => void;
+ }
+
interface LaunchData {
+ /**
+ * The ID of the file or URL handler that the app is being invoked with. Handler IDs are the top-level keys in the file_handlers and/or url_handlers dictionaries in the manifest.
+ */
id?: string;
+ /**
+ * The file entries for the onLaunched event triggered by a matching file handler in the file_handlers manifest key.
+ */
items?: LaunchDataItem[];
+ /**
+ * The URL for the onLaunched event triggered by a matching URL handler in the url_handlers manifest key.
+ */
url?: string;
+ /**
+ * The referrer URL for the onLaunched event triggered by a matching URL handler in the url_handlers manifest key.
+ */
referrerUrl?: string;
+ /**
+ * Whether the app is being launched in a Chrome OS kiosk session.
+ */
isKioskSession?: boolean;
+ /**
+ * Whether the app is being launched in a Chrome OS public session.
+ * @since Since Chrome 47.
+ */
isPublicSession?: boolean;
+ /**
+ * Where the app is launched from.
+ */
source?: LaunchSource;
- actionData?: {};
+ /**
+ * Contains data that specifies the ActionType this app was launched with. This is null if the app was not launched with a specific action intent.
+ * ______________________________________________________________________________
+ * | enum of "new_note" | actionType | new_note |
+ * | | | The user wants to quickly take a new note. |
+ * |____________________|____________|____________________________________________|
+ * @since Since Chrome 54.
+ */
+ actionData?: Object;
}
interface LaunchDataItem {
+ /**
+ * Entry for the item
+ */
entry: FileEntry;
- type: string;
+ /**
+ * The MIME type of the file.
+ */
+ type?: string;
}
+ interface EmbedRequestedEvent extends chrome.events.Event<(request: EmbedRequest) => void> { }
+
interface LaunchedEvent extends chrome.events.Event<(launchData: LaunchData) => void> { }
interface RestartedEvent extends chrome.events.Event<() => void> { }
+ /**
+ * Fired when an embedding app requests to embed this app. This event is only available on dev channel with the flag --enable-app-view.
+ * @since Since Chrome 38.
+ */
+ export var onEmbedRequest: EmbedRequestedEvent;
+ /**
+ * Fired when an app is launched from the launcher.
+ */
export var onLaunched: LaunchedEvent;
+ /**
+ * Fired at Chrome startup to apps that were running when Chrome last shut down, or when apps have been requested to restart from their previous state for other reasons (e.g. when the user revokes access to an app's retained files the runtime will restart the app). In these situations if apps do not have an onRestarted handler they will be sent an onLaunched event instead.
+ */
export var onRestarted: RestartedEvent;
}
From d21bf5a20bd86bfbb6abfca7736199b980510428 Mon Sep 17 00:00:00 2001
From: Nikolai Ommundsen
Date: Thu, 14 Jun 2018 11:17:01 +0200
Subject: [PATCH 04/16] Updated chrome.app.window typings
---
types/chrome-apps/index.d.ts | 321 ++++++++++++++++++++++++++++++-----
1 file changed, 280 insertions(+), 41 deletions(-)
diff --git a/types/chrome-apps/index.d.ts b/types/chrome-apps/index.d.ts
index 7d3ea8dfa9..47f874dd21 100644
--- a/types/chrome-apps/index.d.ts
+++ b/types/chrome-apps/index.d.ts
@@ -14,10 +14,14 @@
// Accessibility Features
////////////////////
/**
- * Use the chrome.accessibilityFeatures API to manage Chrome's accessibility features. This API relies on the ChromeSetting prototype of the type API for getting and setting individual accessibility features. In order to get feature states the extension must request accessibilityFeatures.read permission. For modifying feature state, the extension needs accessibilityFeatures.modify permission. Note that accessibilityFeatures.modify does not imply accessibilityFeatures.read permission.
- * @since Availability: Since Chrome 37.
+ * Use the chrome.accessibilityFeatures API to manage Chrome's accessibility features.
+ * This API relies on the ChromeSetting prototype of the type API for getting and setting individual accessibility features.
+ * In order to get feature states the extension must request accessibilityFeatures.read permission.
+ * For modifying feature state, the extension needs accessibilityFeatures.modify permission.
+ * Note that accessibilityFeatures.modify does not imply accessibilityFeatures.read permission.
* Permissions: 'accessibilityFeatures.read' (For read access); 'accessibilityFeatures.modify' (For modifications; Note that accessibilityFeatures.modify does not imply accessibilityFeatures.read permission.)
* Important: This API works only on Chrome OS.
+ * @since Availability: Since Chrome 37.
*/
declare namespace chrome {
namespace accessibilityFeatures {
@@ -161,8 +165,8 @@ declare namespace chrome {
////////////////////
/**
* Use the chrome.alarms API to schedule code to run periodically or at a specified time in the future.
- * Availability: Since Chrome 22.
* Permissions: 'alarms'
+ * @since Availability: Since Chrome 22.
*/
namespace alarms {
interface AlarmCreateInfo {
@@ -187,14 +191,19 @@ declare namespace chrome {
/**
* Creates an alarm. Near the time(s) specified by alarmInfo, the onAlarm event is fired. If there is another alarm with the same name (or no name if none is specified), it will be cancelled and replaced by this alarm.
- * In order to reduce the load on the user's machine, Chrome limits alarms to at most once every 1 minute but may delay them an arbitrary amount more. That is, setting delayInMinutes or periodInMinutes to less than 1 will not be honored and will cause a warning. when can be set to less than 1 minute after 'now' without warning but won't actually cause the alarm to fire for at least 1 minute.
+ * In order to reduce the load on the user's machine, Chrome limits alarms to at most once every 1 minute but may delay them an arbitrary amount more.
+ * That is, setting delayInMinutes or periodInMinutes to less than 1 will not be honored and will cause a warning.
+ * `when` can be set to less than 1 minute after 'now' without warning but won't actually cause the alarm to fire for at least 1 minute.
* To help you debug your app or extension, when you've loaded it unpacked, there's no limit to how often the alarm can fire.
* @param alarmInfo Describes when the alarm should fire. The initial time must be specified by either when or delayInMinutes (but not both). If periodInMinutes is set, the alarm will repeat every periodInMinutes minutes after the initial event. If neither when or delayInMinutes is set for a repeating alarm, periodInMinutes is used as the default for delayInMinutes.
*/
export function create(alarmInfo: AlarmCreateInfo): void;
/**
- * Creates an alarm. Near the time(s) specified by alarmInfo, the onAlarm event is fired. If there is another alarm with the same name (or no name if none is specified), it will be cancelled and replaced by this alarm.
- * In order to reduce the load on the user's machine, Chrome limits alarms to at most once every 1 minute but may delay them an arbitrary amount more. That is, setting delayInMinutes or periodInMinutes to less than 1 will not be honored and will cause a warning. when can be set to less than 1 minute after 'now' without warning but won't actually cause the alarm to fire for at least 1 minute.
+ * Creates an alarm. Near the time(s) specified by alarmInfo, the onAlarm event is fired.
+ * If there is another alarm with the same name (or no name if none is specified), it will be cancelled and replaced by this alarm.
+ * In order to reduce the load on the user's machine, Chrome limits alarms to at most once every 1 minute but may delay them an arbitrary amount more.
+ * That is, setting delayInMinutes or periodInMinutes to less than 1 will not be honored and will cause a warning.
+ * `when` can be set to less than 1 minute after 'now' without warning but won't actually cause the alarm to fire for at least 1 minute.
* To help you debug your app or extension, when you've loaded it unpacked, there's no limit to how often the alarm can fire.
* @param name Optional name to identify this alarm. Defaults to the empty string.
* @param alarmInfo Describes when the alarm should fire. The initial time must be specified by either when or delayInMinutes (but not both). If periodInMinutes is set, the alarm will repeat every periodInMinutes minutes after the initial event. If neither when or delayInMinutes is set for a repeating alarm, periodInMinutes is used as the default for delayInMinutes.
@@ -203,39 +212,39 @@ declare namespace chrome {
/**
* Gets an array of all the alarms.
* @param callback The callback parameter should be a function that looks like this:
- * function(array of Alarm alarms) {...};
+ * @example function(array of Alarm alarms) {...};
*/
export function getAll(callback: (alarms: Alarm[]) => void): void;
/**
* Clears all alarms.
* @param callback If you specify the callback parameter, it should be a function that looks like this:
- * function(boolean wasCleared) {...};
+ * @example function(boolean wasCleared) {...};
*/
export function clearAll(callback?: (wasCleared: boolean) => void): void;
/**
* Clears the alarm with the given name.
* @param name The name of the alarm to clear. Defaults to the empty string.
* @param callback If you specify the callback parameter, it should be a function that looks like this:
- * function(boolean wasCleared) {...};
+ * @example function(boolean wasCleared) {...};
*/
export function clear(name?: string, callback?: (wasCleared: boolean) => void): void;
/**
* Clears the alarm without a name.
* @param callback If you specify the callback parameter, it should be a function that looks like this:
- * function(boolean wasCleared) {...};
+ * @example function(boolean wasCleared) {...};
*/
export function clear(callback: (wasCleared: boolean) => void): void;
/**
* Retrieves details about the specified alarm.
* @param callback The callback parameter should be a function that looks like this:
- * function( Alarm alarm) {...};
+ * @example function( Alarm alarm) {...};
*/
export function get(callback: (alarm: Alarm) => void): void;
/**
* Retrieves details about the specified alarm.
* @param name The name of the alarm to get. Defaults to the empty string.
* @param callback The callback parameter should be a function that looks like this:
- * function( Alarm alarm) {...};
+ * @example function( Alarm alarm) {...};
*/
export function get(name: string, callback: (alarm: Alarm) => void): void;
@@ -246,6 +255,12 @@ declare namespace chrome {
////////////////////
// App Runtime
////////////////////
+
+ /**
+ * Use the chrome.app.runtime API to manage the app lifecycle.
+ * The app runtime manages app installation, controls the event page, and can shut down the app at anytime.
+ * @since Availability: Since Chrome 24.
+ */
namespace app.runtime {
type LaunchSource = 'untracked' | 'app_launcher' | 'new_tab_page' | 'reload' | 'restart' |
'load_and_launch' | 'command_line' | 'file_handler' | 'url_handler' | 'system_tray' |
@@ -269,7 +284,8 @@ declare namespace chrome {
interface LaunchData {
/**
- * The ID of the file or URL handler that the app is being invoked with. Handler IDs are the top-level keys in the file_handlers and/or url_handlers dictionaries in the manifest.
+ * The ID of the file or URL handler that the app is being invoked with.
+ * Handler IDs are the top-level keys in the file_handlers and/or url_handlers dictionaries in the manifest.
*/
id?: string;
/**
@@ -335,7 +351,10 @@ declare namespace chrome {
*/
export var onLaunched: LaunchedEvent;
/**
- * Fired at Chrome startup to apps that were running when Chrome last shut down, or when apps have been requested to restart from their previous state for other reasons (e.g. when the user revokes access to an app's retained files the runtime will restart the app). In these situations if apps do not have an onRestarted handler they will be sent an onLaunched event instead.
+ * Fired at Chrome startup to apps that were running when Chrome last shut down,
+ * or when apps have been requested to restart from their previous state for other reasons
+ * (e.g. when the user revokes access to an app's retained files the runtime will restart the app).
+ * In these situations if apps do not have an onRestarted handler they will be sent an onLaunched event instead.
*/
export var onRestarted: RestartedEvent;
}
@@ -343,6 +362,13 @@ declare namespace chrome {
////////////////////
// App Window
////////////////////
+ /**
+ * Use the chrome.app.window API to create windows.
+ * Windows have an optional frame with title bar and size controls.
+ * They are not associated with any Chrome browser windows.
+ * See the Window State Sample for a demonstration of these options.
+ * @since Availability: Since Chrome 24.
+ */
namespace app.window {
interface ContentBounds {
left?: number;
@@ -352,113 +378,326 @@ declare namespace chrome {
}
interface BoundsSpecification {
+ /** The X coordinate of the content or window. */
left?: number;
+ /** The Y coordinate of the content or window. */
top?: number;
+ /** The width of the content or window. */
width?: number;
+ /** The height of the content or window. */
height?: number;
+ /** The minimum width of the content or window. */
minWidth?: number;
+ /** The minimum height of the content or window. */
minHeight?: number;
+ /** The maximum width of the content or window. */
maxWidth?: number;
+ /** The maximum height of the content or window. */
maxHeight?: number;
}
interface Bounds {
+ /** This property can be used to read or write the current X coordinate of the content or window. */
left: number;
+ /** This property can be used to read or write the current Y coordinate of the content or window. */
top: number;
+ /** This property can be used to read or write the current width of the content or window. */
width: number;
+ /** This property can be used to read or write the current height of the content or window. */
height: number;
- minWidth?: number;
- minHeight?: number;
- maxWidth?: number;
- maxHeight?: number;
+ /** This property can be used to read or write the current minimum width of the content or window. A value of null indicates 'unspecified'. */
+ minWidth?: number | null;
+ /** This property can be used to read or write the current minimum height of the content or window. A value of null indicates 'unspecified'. */
+ minHeight?: number | null;
+ /** This property can be used to read or write the current maximum width of the content or window. A value of null indicates 'unspecified'. */
+ maxWidth?: number | null;
+ /** This property can be used to read or write the current maximum height of the content or window. A value of null indicates 'unspecified'. */
+ maxHeight?: number | null;
+ /** Set the left and top position of the content or window. */
setPosition(left: number, top: number): void;
+ /** Set the width and height of the content or window. */
setSize(width: number, height: number): void;
- setMinimumSize(minWidth: number, minHeight: number): void;
- setMaximumSize(maxWidth: number, maxHeight: number): void;
+ /** Set the minimum size constraints of the content or window.
+ * The minimum width or height can be set to null to remove the constraint.
+ * A value of undefined will leave a constraint unchanged.
+ **/
+ setMinimumSize(minWidth: number | null | undefined, minHeight: number | null | undefined): void;
+ /**
+ * Set the maximum size constraints of the content or window.
+ * The maximum width or height can be set to null to remove the constraint.
+ * A value of undefined will leave a constraint unchanged.
+ */
+ setMaximumSize(maxWidth: number | null | undefined, maxHeight: number | null | undefined): void;
}
interface FrameOptions {
- type?: string;
+ /**
+ * Frame type: none or chrome (defaults to chrome).
+ *
+ * For none, the -webkit-app-region CSS property can be used to apply draggability to the app's window.
+ * -webkit-app-region: drag can be used to mark regions draggable. no-drag can be used to disable this style on nested elements.
+ */
+ type: 'none';
+ }
+ interface FrameOptionsChrome {
+ /**
+ * Frame type: none or chrome (defaults to chrome).
+ *
+ * For none, the -webkit-app-region CSS property can be used to apply draggability to the app's window.
+ * -webkit-app-region: drag can be used to mark regions draggable. no-drag can be used to disable this style on nested elements.
+ */
+ type?: 'chrome';
+ /**
+ * Allows the frame color to be set. Frame coloring is only available if the frame type is chrome.
+ * @since Frame coloring is new in Chrome 36.
+ */
color?: string;
+ /**
+ * Allows the frame color of the window when active to be set. Frame coloring is only available if the frame type is chrome.
+ * Frame coloring is only available if the frame type is chrome.
+ * @since Frame coloring is new in Chrome 36.
+ */
activeColor?: string;
+ /**
+ * Allows the frame color of the window when inactive to be set differently to the active color. Frame coloring is only available if the frame type is chrome.
+ * inactiveColor must be used in conjunction with color.
+ * @since Frame coloring is new in Chrome 36.
+ */
inactiveColor?: string;
}
interface CreateWindowOptions {
+ /**
+ * Id to identify the window.
+ *
+ * This will be used to remember the size and position of the window and restore that geometry when a window with the same id is later opened.
+ * If a window with a given id is created while another window with the same id already exists,
+ * the currently opened window will be focused instead of creating a new window.
+ */
id?: string;
+ /**
+ * Used to specify the initial position, initial size and constraints of the window's content (excluding window decorations).
+ * If an id is also specified and a window with a matching id has been shown before, the remembered bounds will be used instead.
+ * Note that the padding between the inner and outer bounds is determined by the OS.
+ * Therefore setting the same bounds property for both the innerBounds and outerBounds will result in an error.
+ * @since This property is new in Chrome 36.
+ */
innerBounds?: BoundsSpecification;
+ /**
+ * Used to specify the initial position, initial size and constraints of the window (including window decorations such as the title bar and frame).
+ * If an id is also specified and a window with a matching id has been shown before, the remembered bounds will be used instead.
+ * Note that the padding between the inner and outer bounds is determined by the OS.
+ * Therefore setting the same bounds property for both the innerBounds and outerBounds will result in an error.
+ * @since This property is new in Chrome 36.
+ */
outerBounds?: BoundsSpecification;
+ /**
+ * Minimum width of the window.
+ * @deprecated Deprecated since Chrome 36. Use innerBounds or outerBounds.
+ */
minWidth?: number;
+ /**
+ * Minimum height of the window.
+ * @deprecated Deprecated since Chrome 36. Use innerBounds or outerBounds.
+ */
minHeight?: number;
+ /**
+ * Maximum width of the window.
+ * @deprecated Deprecated since Chrome 36. Use innerBounds or outerBounds.
+ */
maxWidth?: number;
+ /**
+ * Maximum height of the window.
+ * @deprecated Deprecated since Chrome 36. Use innerBounds or outerBounds.
+ */
maxHeight?: number;
+ /** Type of window to create */
+ type?: 'shell';
/**
- * @description
- * @type {(string | FrameOptions)} string ('none', 'chrome') or FrameOptions
- * @memberof CreateWindowOptions
+ * If true, the window will have its own shelf icon.
+ * Otherwise the window will be grouped in the shelf with other windows that are associated with the app.
+ * Defaults to false.
+ * If showInShelf is set to true you need to specify an id for the window.
+ * @since Since Chrome 54.
+ */
+ showInShelf: boolean;
+ /**
+ * URL of the window icon. A window can have its own icon when showInShelf is set to true. The URL should be a global or an extension local URL.
+ * @since Since Chrome 54.
+ */
+ icon: string;
+ /**
+ * Frame type: none or chrome (defaults to chrome).
+ * For none, the -webkit-app-region CSS property can be used to apply draggability to the app's window.
+ * -webkit-app-region: drag can be used to mark regions draggable. no-drag can be used to disable this style on nested elements.
+ * @since Use of FrameOptions is new in M36.
+ */
+ frame?: 'none' | 'chrome' | FrameOptions | FrameOptionsChrome;
+ /**
+ * Size and position of the content in the window (excluding the titlebar).
+ * If an id is also specified and a window with a matching id has been shown before,
+ * the remembered bounds of the window will be used instead.
+ * @deprecated Deprecated since Chrome 36. Use innerBounds or outerBounds.
*/
- frame?: string | FrameOptions;
bounds?: ContentBounds;
- alphaEnabled?: boolean;
/**
- * @description
- * @type {string} 'normal', 'fullscreen', 'maximized', 'minimized'
- * @memberof CreateWindowOptions
+ * The initial state of the window, allowing it to be created already fullscreen, maximized, or minimized. Defaults to 'normal'.
+ */
+ state?: 'normal' | 'fullscreen' | 'maximized' | 'minimized';
+ /**
+ * If true, the window will be created in a hidden state. Call show() on the window to show it once it has been created. Defaults to false.
*/
- state?: string;
hidden?: boolean;
+ /**
+ * If true, the window will be resizable by the user. Defaults to true.
+ */
resizable?: boolean;
+ /**
+ * @deprecated Deprecated since Chrome 34. Multiple windows with the same id is no longer supported.
+ * By default if you specify an id for the window,
+ * the window will only be created if another window with the same id doesn't already exist.
+ * If a window with the same id already exists that window is activated instead.
+ * If you do want to create multiple windows with the same id, you can set this property to false.
+ */
singleton?: boolean;
+ /**
+ * If true, the window will stay above most other windows.
+ * If there are multiple windows of this kind, the currently focused window will be in the foreground.
+ * @requires alwaysOnTopWindows-permission.
+ * Defaults to false.
+ * Call setAlwaysOnTop() on the window to change this property after creation.
+ */
alwaysOnTop?: boolean;
+ /** If true, the window will be focused when created. Defaults to true. */
focused?: boolean;
+ /**
+ * If true, and supported by the platform, the window will be visible on all workspaces.
+ * @since Since Chrome 39.
+ */
visibleOnAllWorkspaces?: boolean;
}
interface AppWindow {
+ /** Focus the window. */
focus: () => void;
+ /**
+ * Fullscreens the window.
+ * The user will be able to restore the window by pressing ESC.
+ * An application can prevent the fullscreen state to be left when ESC is pressed by requesting the
+ * app.window.fullscreen.overrideEsc permission and canceling the event by calling .preventDefault(),
+ * in the keydown and keyup handlers, like this:
+ * @example window.onkeydown = window.onkeyup = function(e) { if (e.keyCode == 27 <<--``ESC``) { e.preventDefault(); }
+ * Note window.fullscreen() will cause the entire window to become fullscreen and does not require a user gesture.
+ * The HTML5 fullscreen API can also be used to enter fullscreen mode(see Web APIs for more details).
+ **/
fullscreen: () => void;
+ /** Is the window fullscreen? This will be true if the window has been created fullscreen or was made fullscreen via the AppWindow or HTML5 fullscreen APIs. */
isFullscreen: () => boolean;
+ /** Minimize the window. */
minimize: () => void;
+ /** Is the window minimized? */
isMinimized: () => boolean;
+ /** Maximize the window. */
maximize: () => void;
+ /** Is the window maximized? */
isMaximized: () => boolean;
+ /** Restore the window, exiting a maximized, minimized, or fullscreen state. */
restore: () => void;
+ /**
+ * Move the window to the position (|left|, |top|).
+ * @deprecated Deprecated since Chrome 43. Use outerBounds.
+ */
moveTo: (left: number, top: number) => void;
+ /**
+ * Resize the window to |width|x|height| pixels in size.
+ * @deprecated Deprecated since Chrome 43. Use outerBounds.
+ */
resizeTo: (width: number, height: number) => void;
+ /** Draw attention to the window. */
drawAttention: () => void;
+ /** Clear attention to the window. */
clearAttention: () => void;
+ /** Close the window. */
close: () => void;
- show: () => void;
+ /** Show the window. Does nothing if the window is already visible. Focus the window if |focused| is set to true or omitted. */
+ show: (focused?: boolean) => void;
+ /** Hide the window. Does nothing if the window is already hidden. */
hide: () => void;
+ /**
+ * @deprecated Deprecated since Chrome 36. Use innerBounds or outerBounds.
+ * @description Get the window's inner bounds as a ContentBounds object.
+ */
getBounds: () => ContentBounds;
+ /**
+ * Set the window's inner bounds.
+ * @deprecated Deprecated since Chrome 36. Use innerBounds or outerBounds.
+ */
setBounds: (bounds: ContentBounds) => void;
+ /** Is the window always on top? */
isAlwaysOnTop: () => boolean;
+ /** Set whether the window should stay above most other windows. Requires the alwaysOnTopWindows permission. */
setAlwaysOnTop: (alwaysOnTop: boolean) => void;
+ /** Set whether the window is visible on all workspaces. (Only for platforms that support this). */
setVisibleOnAllWorkspaces: (alwaysVisible: boolean) => void;
+ /** The JavaScript 'window' object for the created child. */
contentWindow: Window;
+ /** The id the window was created with. */
id: string;
+ /**
+ * The position, size and constraints of the window's content, which does not include window decorations.
+ * @since This property is new in Chrome 36.
+ * */
innerBounds: Bounds;
+ /**
+ * The position, size and constraints of the window, which includes window decorations, such as the title bar and frame.
+ * @since This property is new in Chrome 36.
+ */
outerBounds: Bounds;
- onBoundsChanged: WindowEvent;
- onClosed: WindowEvent;
- onFullscreened: WindowEvent;
- onMaximized: WindowEvent;
- onMinimized: WindowEvent;
- onRestored: WindowEvent;
}
-
+ /**
+ * The size and position of a window can be specified in a number of different ways. The most simple option is not specifying anything at all, in which case a default size and platform dependent position will be used.
+ * To set the position, size and constraints of the window, use the innerBounds or outerBounds properties. Inner bounds do not include window decorations. Outer bounds include the window's title bar and frame. Note that the padding between the inner and outer bounds is determined by the OS. Therefore setting the same property for both inner and outer bounds is considered an error (for example, setting both innerBounds.left and outerBounds.left).
+ * To automatically remember the positions of windows you can give them ids. If a window has an id, This id is used to remember the size and position of the window whenever it is moved or resized. This size and position is then used instead of the specified bounds on subsequent opening of a window with the same id. If you need to open a window with an id at a location other than the remembered default, you can create it hidden, move it to the desired location, then show it.
+ *
+ * @param url
+ * @param [options]
+ * @param [callback] Called in the creating window (parent) before the load event is called in the created window (child). The parent can set fields or functions on the child usable from onload. E.g. background.js: function(createdWindow) { createdWindow.contentWindow.foo = function () { }; }; window.js: window.onload = function () { foo(); } If you specify the callback parameter, it should be a function that looks like this: function(AppWindow createdWindow) {...};
+ */
export function create(url: string, options?: CreateWindowOptions, callback?: (created_window: AppWindow) => void): void;
+ /**
+ * Returns an AppWindow object for the current script context (ie JavaScript 'window' object). This can also be called on a handle to a script context for another page, for example: otherWindow.chrome.app.window.current().
+ */
export function current(): AppWindow;
+ /**
+ * Gets an AppWindow with the given id. If no window with the given id exists null is returned. This method is new in Chrome 33.
+ */
export function get(id: string): AppWindow;
+ /**
+ * Gets an array of all currently created app windows. This method is new in Chrome 33.
+ */
export function getAll(): AppWindow[];
+ /**
+ * Whether the current platform supports windows being visible on all workspaces.
+ */
export function canSetVisibleOnAllWorkspaces(): boolean;
interface WindowEvent extends chrome.events.Event<() => void> { }
+ /** Fired when the window is resized. */
export var onBoundsChanged: WindowEvent;
+ /**
+ * Fired when the window is closed.
+ * Note, this should be listened to from a window other than the window being closed, for example from the background page.
+ * This is because the window being closed will be in the process of being torn down when the event is fired,
+ * which means not all APIs in the window's script context will be functional.
+ */
export var onClosed: WindowEvent;
+ /** Fired when the window is fullscreened (either via the AppWindow or HTML5 APIs). */
export var onFullscreened: WindowEvent;
+ /** Fired when the window is maximized. */
export var onMaximized: WindowEvent;
+ /** Fired when the window is minimized. */
export var onMinimized: WindowEvent;
+ /** Fired when the window is restored from being minimized or maximized. */
export var onRestored: WindowEvent;
}
@@ -545,15 +784,15 @@ declare namespace chrome {
addListener(callback: (devices: AudioDeviceInfo[]) => void): void;
}
/**
- * @description Device properties by which to filter the list of returned audio devices. If the filter is not set or set to {}, returned device list will contain all available audio devices.
+ * Device properties by which to filter the list of returned audio devices. If the filter is not set or set to {}, returned device list will contain all available audio devices.
*/
interface Filter {
/**
- * @description If set, only audio devices whose stream type is included in this list will satisfy the filter.
+ * If set, only audio devices whose stream type is included in this list will satisfy the filter.
*/
streamTypes?: StreamType[];
/**
- * @description If set, only audio devices whose active state matches this value will satisfy the filter.
+ * If set, only audio devices whose active state matches this value will satisfy the filter.
*/
isActive?: boolean;
}
From dc39bd3e67d45ed71b77819bb87c3cd4da673449 Mon Sep 17 00:00:00 2001
From: Nikolai Ommundsen
Date: Thu, 14 Jun 2018 11:25:25 +0200
Subject: [PATCH 05/16] Added missing docs to chrome.bluetooth
---
types/chrome-apps/index.d.ts | 59 ++++++++++++++++++++++++++----------
1 file changed, 43 insertions(+), 16 deletions(-)
diff --git a/types/chrome-apps/index.d.ts b/types/chrome-apps/index.d.ts
index 47f874dd21..82ab48dbc5 100644
--- a/types/chrome-apps/index.d.ts
+++ b/types/chrome-apps/index.d.ts
@@ -9,21 +9,21 @@
///////////////
// WebView ref: https://chromium.googlesource.com/chromium/src/+/68.0.3432.1/chrome/common/extensions/api/webview_tag.json
///////////////
-
-////////////////////
-// Accessibility Features
-////////////////////
-/**
- * Use the chrome.accessibilityFeatures API to manage Chrome's accessibility features.
- * This API relies on the ChromeSetting prototype of the type API for getting and setting individual accessibility features.
- * In order to get feature states the extension must request accessibilityFeatures.read permission.
- * For modifying feature state, the extension needs accessibilityFeatures.modify permission.
- * Note that accessibilityFeatures.modify does not imply accessibilityFeatures.read permission.
- * Permissions: 'accessibilityFeatures.read' (For read access); 'accessibilityFeatures.modify' (For modifications; Note that accessibilityFeatures.modify does not imply accessibilityFeatures.read permission.)
- * Important: This API works only on Chrome OS.
- * @since Availability: Since Chrome 37.
- */
declare namespace chrome {
+
+ ////////////////////
+ // Accessibility Features
+ ////////////////////
+ /**
+ * Use the chrome.accessibilityFeatures API to manage Chrome's accessibility features.
+ * This API relies on the ChromeSetting prototype of the type API for getting and setting individual accessibility features.
+ * In order to get feature states the extension must request accessibilityFeatures.read permission.
+ * For modifying feature state, the extension needs accessibilityFeatures.modify permission.
+ * Note that accessibilityFeatures.modify does not imply accessibilityFeatures.read permission.
+ * Permissions: 'accessibilityFeatures.read' (For read access); 'accessibilityFeatures.modify' (For modifications; Note that accessibilityFeatures.modify does not imply accessibilityFeatures.read permission.)
+ * Important: This API works only on Chrome OS.
+ * @since Availability: Since Chrome 37.
+ */
namespace accessibilityFeatures {
interface AccessibilityFeaturesGetArg {
/** Optional. Whether to return the value that applies to the incognito session (default false). */
@@ -706,8 +706,9 @@ declare namespace chrome {
// Audio
////////////////////
/**
- * The chrome.audio API is provided to allow users to get information about and control the audio devices attached to the system. This API is currently only implemented for ChromeOS.
- * @since Chrome 59
+ * The chrome.audio API is provided to allow users to get information about and control the audio devices attached to the system.
+ * This API is currently only implemented for ChromeOS.
+ * @since Since Chrome 59.
*/
namespace audio {
export type StreamType = 'INPUT' | 'OUTPUT';
@@ -836,37 +837,63 @@ declare namespace chrome {
*/
namespace bluetooth {
interface AdapterState {
+ /** The address of the adapter, in the format 'XX:XX:XX:XX:XX:XX'. */
address: string;
+ /** The human-readable name of the adapter. */
name: string;
+ /** Indicates whether or not the adapter has power. */
powered: boolean;
+ /** Indicates whether or not the adapter is available (i.e. enabled). */
available: boolean;
+ /** Indicates whether or not the adapter is currently discovering. */
discovering: boolean;
}
interface Device {
+ /** The address of the device, in the format 'XX:XX:XX:XX:XX:XX'. */
address: string;
+ /** The human-readable name of the device. */
name?: string;
+ /** The class of the device, a bit-field defined by http://www.bluetooth.org/en-us/specification/assigned-numbers/baseband. */
deviceClass?: number;
+ /** The Device ID record of the device, where available. */
vendorIdSource?: 'bluetooth' | 'usb';
vendorId?: number;
productId?: number;
deviceId?: number;
+ /**
+ * The type of the device, if recognized by Chrome.
+ * This is obtained from the |deviceClass| field and only represents a small fraction of the possible device types.
+ * When in doubt you should use the |deviceClass| field directly.
+ */
type?: 'computer' | 'phone' | 'modem' | 'audio' | 'carAudio' | 'video' | 'peripheral' | 'joystick' | 'gamepad' | 'keyboard' | 'mouse' | 'tablet' | 'keyboardMouseCombo';
+ /** Indicates whether or not the device is paired with the system. */
paired?: boolean;
+ /** Indicates whether the device is currently connected to the system. */
connected?: boolean;
/**
+ * Indicates whether the device is currently connecting to the system.
* @since Chrome 48
*/
connecting?: boolean;
/**
+ * Indicates whether the device is connectable.
* @since Chrome 48
*/
connectable?: boolean;
+ /**
+ * UUIDs of protocols, profiles and services advertised by the device.
+ * For classic Bluetooth devices, this list is obtained from EIR data and SDP tables.
+ * For Low Energy devices, this list is obtained from AD and GATT primary services.
+ * For dual mode devices this may be obtained from both.
+ */
uuids?: string[];
/**
+ * The received signal strength, in dBm. This field is avaliable and valid only during discovery. Outside of discovery it's value is not specified.
* @since Chrome 44
*/
inquiryRssi: number;
/**
+ * The transmitted power level. This field is avaliable only for LE devices that include this field in AD. It is avaliable and valid only during discovery.
* @since Chrome 44
*/
inquiryTxPower: number;
From 49afea15e603400ff2aa65f68c8db310dd445182 Mon Sep 17 00:00:00 2001
From: Nikolai Ommundsen
Date: Thu, 14 Jun 2018 11:30:05 +0200
Subject: [PATCH 06/16] chrome.bluetoothLowEnergy WIP
---
types/chrome-apps/index.d.ts | 31 +++++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)
diff --git a/types/chrome-apps/index.d.ts b/types/chrome-apps/index.d.ts
index 82ab48dbc5..2a4fa9c4ed 100644
--- a/types/chrome-apps/index.d.ts
+++ b/types/chrome-apps/index.d.ts
@@ -946,10 +946,33 @@ declare namespace chrome {
* Note: With Chrome 56, users can select nearby Bluetooth Low Energy devices to provide to web sites that use the Web Bluetooth API.
*/
namespace bluetoothLowEnergy {
- /**
- * NOT IMPLEMENTED YET
- * @see https://developer.chrome.com/apps/bluetoothLowEnergy
- * */
+ interface Service {
+ /** The UUID of the service, e.g. 0000180d-0000-1000-8000-00805f9b34fb. */
+ uuid: string;
+ /** Indicates whether the type of this service is primary or secondary. */
+ isPrimary: boolean;
+ /**
+ * Returns the identifier assigned to this service.
+ * Use the instance ID to distinguish between services from a peripheral with the same UUID and to make function calls that take in a service identifier.
+ * Present, if this instance represents a remote service.
+ **/
+ instanceId?: string;
+ /**
+ * The device address of the remote peripheral that the GATT service belongs to.
+ * Present, if this instance represents a remote service.
+ */
+ deviceAddress?: string;
+ }
+ interface Characteristic {
+ // WIP
+ }
+ export function connect(deviceAddress: string, callback: () => void): void;
+ export function connect(deviceAddress: string, properties: { persistent: boolean }, callback: () => void): void;
+ export function disconnect(deviceAddress: string, callback: () => void): void;
+
+ /*
+ WORK IN PROGRESS
+ */
}
/**
* Use the chrome.bluetoothSocket API to send and receive data to Bluetooth devices using RFCOMM and L2CAP connections.
From b3db8aba26cc60ba4a38de72cbe8f23280211864 Mon Sep 17 00:00:00 2001
From: Nikolai Ommundsen
Date: Thu, 14 Jun 2018 11:51:18 +0200
Subject: [PATCH 07/16] Added missing typings in chrome.fileSystem
---
types/chrome-apps/index.d.ts | 90 +++++++++++++++++++++++++++++++++++-
1 file changed, 88 insertions(+), 2 deletions(-)
diff --git a/types/chrome-apps/index.d.ts b/types/chrome-apps/index.d.ts
index 2a4fa9c4ed..e914dd8e56 100644
--- a/types/chrome-apps/index.d.ts
+++ b/types/chrome-apps/index.d.ts
@@ -981,7 +981,7 @@ declare namespace chrome {
* Important: This API works only on OS X, Windows and Chrome OS.
*/
namespace bluetoothSocket {
- /** NOT IMPLEMENTED YET */
+ /* NOT IMPLEMENTED YET */
}
////////////////////
@@ -1530,32 +1530,118 @@ declare namespace chrome {
////////////////////
// FileSystem
////////////////////
+ /**
+ * Use the chrome.fileSystem API to create, read, navigate, and write to the user's local file system.
+ * With this API, Chrome Apps can read and write to a user-selected location.
+ * For example, a text editor app can use the API to read and write local documents.
+ * All failures are notified via chrome.runtime.lastError.
+ */
namespace fileSystem {
interface AcceptOptions {
+ /**
+ * This is the optional text description for this option.
+ * If not present, a description will be automatically generated;
+ * typically containing an expanded list of valid extensions (e.g. "text/html" may expand to "*.html, *.htm").
+ */
description?: string;
+ /**
+ * Mime-types to accept, e.g. "image/jpeg" or "audio/*". One of mimeTypes or extensions must contain at least one valid element.
+ */
mimeTypes?: string[];
+ /**
+ * Extensions to accept, e.g. "jpg", "gif", "crx".
+ */
extensions?: string[];
}
interface ChooseEntryOptions {
- type?: string;
+ /**
+ * Type of the prompt to show. The default is 'openFile'.
+ * openFile
+ * - Prompts the user to open an existing file and returns a FileEntry on success. From Chrome 31 onwards, the FileEntry will be writable if the application has the 'write' permission under 'fileSystem'; otherwise, the FileEntry will be read-only.
+ * openWritableFile
+ * - Prompts the user to open an existing file and returns a writable FileEntry on success. Calls using this type will fail with a runtime error if the application doesn't have the 'write' permission under 'fileSystem'.
+ * saveFile
+ * - Prompts the user to open an existing file or a new file and returns a writable FileEntry on success. Calls using this type will fail with a runtime error if the application doesn't have the 'write' permission under 'fileSystem'.
+ * openDirectory
+ * - Prompts the user to open a directory and returns a DirectoryEntry on success. Calls using this type will fail with a runtime error if the application doesn't have the 'directory' permission under 'fileSystem'. If the application has the 'write' permission under 'fileSystem', the returned DirectoryEntry will be writable; otherwise it will be read-only. New in Chrome 31.
+ */
+ type?: 'openFile' | 'openWritableFile' | 'saveFile' | 'openDirectory';
+ /** The suggested file name that will be presented to the user as the default name to read or write. This is optional. */
suggestedName?: string;
+ /** The optional list of accept options for this file opener. Each option will be presented as a unique group to the end-user. */
accepts?: AcceptOptions[];
+ /**
+ * Whether to accept all file types, in addition to the options specified in the accepts argument.
+ * The default is true. If the accepts field is unset or contains no valid entries, this will always be reset to true.
+ */
acceptsAllTypes?: boolean;
+ /**
+ * Whether to accept multiple files. This is only supported for openFile and openWritableFile.
+ * The callback to chooseEntry will be called with a list of entries if this is set to true. Otherwise it will be called with a single Entry.
+ */
acceptsMultiple?: boolean;
}
+ type ChildChangeType = 'created' | 'removed' | 'changed';
+
+ interface Volume {
+ /** The ID of the requested volume. */
+ volumeId: string;
+ /** Whether the requested file system should be writable. The default is read-only. */
+ writable?: boolean;
+ }
+
+ /**
+ * Get the display path of an Entry object.
+ * The display path is based on the full path of the file or directory on the local file system, but may be made more readable for display purposes.
+ */
export function getDisplayPath(entry: Entry, callback: (displayPath: string) => void): void;
+ /**
+ * Get a writable Entry from another Entry. This call will fail with a runtime error if the application does not have the 'write' permission under 'fileSystem'.
+ * If entry is a DirectoryEntry, this call will fail if the application does not have the 'directory' permission under 'fileSystem'.
+ */
export function getWritableEntry(entry: Entry, callback: (entry: Entry) => void): void;
+ /** Gets whether this Entry is writable or not. */
export function isWritableEntry(entry: Entry, callback: (isWritable: boolean) => void): void;
+ /** Ask the user to choose a file or directory. */
export function chooseEntry(callback: (entry: Entry) => void): void;
+ /** Ask the user to choose a file or directory. */
export function chooseEntry(callback: (fileEntries: FileEntry[]) => void): void;
+ /** Ask the user to choose a file or directory. */
export function chooseEntry(options: ChooseEntryOptions, callback: (entry: Entry) => void): void;
+ /** Ask the user to choose a file or directory. */
export function chooseEntry(options: ChooseEntryOptions, callback: (fileEntries: FileEntry[]) => void): void;
+ /** Returns the file entry with the given id if it can be restored. This call will fail with a runtime error otherwise. */
export function restoreEntry(id: string, callback: (entry: Entry) => void): void;
+ /** Returns whether the app has permission to restore the entry with the given id. */
export function isRestorable(id: string, callback: (isRestorable: boolean) => void): void;
+ /**
+ * Returns an id that can be passed to restoreEntry to regain access to a given file entry.
+ * Only the 500 most recently used entries are retained, where calls to retainEntry and restoreEntry count as use.
+ * If the app has the 'retainEntries' permission under 'fileSystem', entries are retained indefinitely.
+ * Otherwise, entries are retained only while the app is running and across restarts.
+ * */
export function retainEntry(entry: Entry): string;
+ /**
+ * Requests access to a file system for a volume represented by options.volumeId.
+ * If options.writable is set to true, then the file system will be writable.
+ * Otherwise, it will be read-only.
+ * The writable option requires the "fileSystem": {"write"} permission in the manifest.
+ * Available to kiosk apps running in kiosk session only.
+ * For manual-launch kiosk mode, a confirmation dialog will be shown on top of the active app window.
+ * In case of an error, fileSystem will be undefined, and chrome.runtime.lastError will be set.
+ */
+ export function requestFileSystem(options: Volume, callback: (fileSystem: FileSystem) => void): void;
+ /**
+ * Returns a list of volumes available for requestFileSystem().
+ * The "fileSystem": {"requestFileSystem"} manifest permission is required.
+ * Available to kiosk apps running in the kiosk session only.
+ * In case of an error, volumes will be undefined, and chrome.runtime.lastError will be set.
+ */
+ export function getVolumeList(callback: (volumes: Volume[]) => void): void;
+ export var onVolumeListChanged: chrome.events.Event<(object: Volume[]) => void>;
}
From 5f4458e4f17fa7f9a623b17cc6684f54e75723ec Mon Sep 17 00:00:00 2001
From: Nikolai Ommundsen
Date: Thu, 14 Jun 2018 12:04:52 +0200
Subject: [PATCH 08/16] Relocate webview methods
---
types/chrome-apps/index.d.ts | 746 ++++++++++++++++++-----------------
1 file changed, 382 insertions(+), 364 deletions(-)
diff --git a/types/chrome-apps/index.d.ts b/types/chrome-apps/index.d.ts
index e914dd8e56..92e8a85c65 100644
--- a/types/chrome-apps/index.d.ts
+++ b/types/chrome-apps/index.d.ts
@@ -5129,10 +5129,378 @@ declare namespace chrome {
* @extends {Element}
*/
interface HTMLWebViewElement extends Element {
- executeScript?: (details: InjectDetails, callback?: (result: any) => void) => void;
src: string;
contentWindow: Window;
addEventListener(type: K, listener: (this: HTMLWebViewElement, ev: WebViewElementEventMap[K]) => any, useCapture?: boolean): void;
+ /**
+ * @description Queries audio state.
+ * @param {any} [object Object]
+ */
+ getAudioState(callback: (audible: boolean) => void): void;
+
+ /**
+ * @description Sets audio mute state of the webview.
+ * @param {boolean} mute Mute audio value
+ */
+ setAudioMuted(mute: boolean): void;
+
+ /**
+ * @description Queries whether audio is muted.
+ * @param {any} [object Object]
+ */
+ isAudioMuted(callback: (muted: boolean) => void): void;
+
+ /**
+ * @description Captures the visible region of the webview.
+ * @param {(dataUrl: string) => void} callback A data URL which encodes an image of the visible area of the captured tab. May be assigned to the 'src' property of an HTML Image element for display.
+ */
+ captureVisibleRegion(callback: (dataUrl: string) => void): void;
+ /**
+ * @description Captures the visible region of the webview.
+ * @param {*} options
+ * @param {(dataUrl: string) => void} callback
+ */
+ captureVisibleRegion(options: chrome.extensionTypes.ImageDetails, callback: (dataUrl: string) => void): void;
+
+ /**
+ * Adds content script injection rules to the webview.
+ * When the webview navigates to a page matching one or more rules, the associated scripts will be injected.
+ * You can programmatically add rules or update existing rules.
+ * The following example adds two rules to the webview: 'myRule' and 'anotherRule'.
+ * webview.addContentScripts([
+ * {
+ * name: 'myRule',
+ * matches: ['http://www.foo.com/*'],
+ * css: { files: ['mystyles.css'] },
+ * js: { files: ['jquery.js', 'myscript.js'] },
+ * run_at: 'document_start'
+ * },
+ * {
+ * name: 'anotherRule',
+ * matches: ['http://www.bar.com/*'],
+ * js: { code: 'document.body.style.backgroundColor = 'red';' },
+ * run_at: 'document_end'
+ * }]);
+ * ...
+ *
+ * // Navigates webview.
+ * webview.src = 'http://www.foo.com';
+ * You can defer addContentScripts call until you needs to inject scripts.
+ * The following example shows how to overwrite an existing rule.
+ *
+ * webview.addContentScripts([{
+ * name: 'rule',
+ * matches: ['http://www.foo.com/*'],
+ * js: { files: ['scriptA.js'] },
+ * run_at: 'document_start'}]);
+ *
+ * // Do something.
+ * webview.src = 'http://www.foo.com/*';
+ * ...
+ * // Overwrite 'rule' defined before.
+ * webview.addContentScripts([{
+ * name: 'rule',
+ * matches: ['http://www.bar.com/*'],
+ * js: { files: ['scriptB.js'] },
+ * run_at: 'document_end'}]);
+ * If webview has been naviagted to the origin (e.g., foo.com) and calls webview.addContentScripts to add 'myRule',
+ * you need to wait for next navigation to make the scripts injected.
+ * If you want immediate injection, executeScript will do the right thing.
+ * Rules are preserved even if the guest process crashes or is killed or even if the webview is reparented.
+ * Refer to the /extensions/content_scripts documentation for more details.
+ * @param {ContentScriptDetails[]} contentScriptList Details of the content scripts to add.
+ */
+ addContentScripts(contentScriptList: ContentScriptDetails[]): void;
+
+ /**
+ * @description Navigates backward one history entry if possible. Equivalent to go(-1).
+ * @param {(success: boolean) => void} [callback] Called after the navigation has either failed or completed successfully. Success parameter indicates whether the navigation was successful.
+ */
+ back(callback?: (success: boolean) => void): void;
+
+ /**
+ * @description Indicates whether or not it is possible to navigate backward through history. The state of this function is cached, and updated before each loadcommit, so the best place to call it is on loadcommit.
+ */
+ canGoBack(): void;
+
+ /**
+ * @description Indicates whether or not it is possible to navigate forward through history. The state of this function is cached, and updated before each loadcommit, so the best place to call it is on loadcommit.
+ */
+ canGoForward(): void;
+
+ /**
+ * @description Clears browsing data for the webview partition.
+ * @param {any} options Options determining which data to clear.
+ * @param {any} types The types of data to be cleared.
+ * @param {any} [object Object]
+ */
+ clearData(options: ClearDataOptions, types: ClearDataTypeSet, callback?: () => void): void;
+
+ /**
+ * @description Injects JavaScript code into the guest page.
The following sample code uses script injection to set the guest page's background color to red:
webview.executeScript({ code: 'document.body.style.backgroundColor = 'red'' });
+ * @param {any} details Details of the script to run.
+ * @param {any} [object Object]
+ */
+ executeScript(details: InjectDetails, callback?: (result?: any[]) => void): void;
+
+ /**
+ * @description Initiates a find-in-page request.
+ * @param {string} searchText The string to find in the page.
+ * @param {any} options Options for the find request.
+ * @param {any} [object Object]
+ */
+ find(searchText: string, options?: FindOptions, callback?: (results?: any) => void): void;
+
+ /**
+ * @description Navigates forward one history entry if possible. Equivalent to go(1).
+ * @param {any} [object Object]
+ */
+ forward(callback?: (success: boolean) => void): void;
+
+ /**
+ * @description Returns Chrome's internal process ID for the guest web page's current process, allowing embedders to know how many guests would be affected by terminating the process. Two guests will share a process only if they belong to the same app and have the same storage partition ID. The call is synchronous and returns the embedder's cached notion of the current process ID. The process ID isn't the same as the operating system's process ID.
+ */
+ getProcessId(): void;
+
+ /**
+ * @description Returns the user agent string used by the webview for guest page requests.
+ */
+ getUserAgent(): void;
+
+ /**
+ * @description Gets the current zoom factor.
+ * @param {any} [object Object]
+ */
+ getZoom(callback: (zoomFactor: number) => void): void;
+
+ /**
+ * @description Gets the current zoom mode.
+ * @param {any} [object Object]
+ */
+ getZoomMode(callback: (ZoomMode: any) => void): void;
+
+ /**
+ * @description Navigates to a history entry using a history index relative to the current navigation. If the requested navigation is impossible, this method has no effect.
+ * @param {number} relativeIndex Relative history index to which the webview should be navigated. For example, a value of 2 will navigate forward 2 history entries if possible; a value of -3 will navigate backward 3 entries.
+ * @param {any} [object Object]
+ */
+ go(relativeIndex: number, callback?: (success: boolean) => void): void;
+
+ /**
+ * @description Injects CSS into the guest page.
+ * @param {any} details Details of the CSS to insert.
+ * @param {any} [object Object]
+ */
+ insertCSS(details: InjectDetails, callback?: () => void): void;
+
+ /**
+ * @description Indicates whether or not the webview's user agent string has been overridden by $(ref:webviewTag.setUserAgentOverride).
+ */
+ isUserAgentOverridden(): void;
+
+ /**
+ * @description Prints the contents of the webview. This is equivalent to calling scripted print function from the webview itself.
+ */
+ print(): void;
+
+ /**
+ * @description Reloads the current top-level page.
+ */
+ reload(): void;
+
+ /**
+ * @description Removes content scripts from a webview.
+ * @description The following example removes 'myRule' which was added before.
+ * @example webview.removeContentScripts(['myRule']);
+ * @description You can remove all the rules by calling:
+ * @example webview.removeContentScripts();
+ * @param {any[]} scriptNameList A list of names of content scripts that will be removed. If the list is empty, all the content scripts added to the webview will be removed.
+ */
+ removeContentScripts(scriptNameList?: any[]): void;
+
+ /**
+ * @description Override the user agent string used by the webview for guest page requests.
+ * @param {string} userAgent The user agent string to use.
+ */
+ setUserAgentOverride(userAgent: string): void;
+
+ /**
+ * @description Changes the zoom factor of the page. The scope and persistence of this change are determined by the webview's current zoom mode (see $(ref:webviewTag.ZoomMode)).
+ * @param {number} zoomFactor The new zoom factor.
+ * @param {any} [object Object]
+ */
+ setZoom(zoomFactor: number, callback?: () => void): void;
+
+ /**
+ * @description Sets the zoom mode of the webview.
+ * @param {any} ZoomMode Defines how zooming is handled in the webview.
+ * @param {any} [object Object]
+ */
+ setZoomMode(ZoomMode: ZoomMode, callback?: () => void): void;
+
+ /**
+ * @description Stops loading the current webview navigation if in progress.
+ */
+ stop(): void;
+
+ /**
+ * @description Ends the current find session (clearing all highlighting) and cancels all find requests in progress.
+ * @param {string} action Determines what to do with the active match after the find session has ended. clear will clear the highlighting over the active match; keep will keep the active match highlighted; activate will keep the active match highlighted and simulate a user click on that match. The default action is keep.
+ */
+ stopFinding(action?: string): void;
+
+ /**
+ * @description Loads a data URL with a specified base URL used for relative links. Optionally, a virtual URL can be provided to be shown to the user instead of the data URL.
+ * @param {string} dataUrl The data URL to load.
+ * @param {string} baseUrl The base URL that will be used for relative links.
+ * @param {string} virtualUrl The URL that will be displayed to the user (in the address bar).
+ */
+ loadDataWithBaseUrl(dataUrl: string, baseUrl: string, virtualUrl?: string): void;
+
+ /**
+ * @description Forcibly kills the guest web page's renderer process. This may affect multiple webview tags in the current app if they share the same process, but it will not affect webview tags in other apps.
+ */
+ terminate(): void;
+
+ /**
+ * @description Fired when the guest window attempts to close itself.The following example code navigates the webview to about:blank when the guest attempts to close itself.
webview.addEventListener('close', function() {
+ webview.src = 'about:blank';
+ });
+ */
+
+ close(event: chrome.events.Event): void;
+
+ /**
+ * @description Fired when the guest window logs a console message.The following example code forwards all log messages to the embedder's console without regard for log level or other properties.
webview.addEventListener('consolemessage', function(e) {
+ console.log('Guest page logged a message: ', e.message);
+ });
+ * @param {any} [object Object]
+ */
+
+ consolemessage: chrome.events.Event;
+
+ /**
+ * @description Fired when the guest window fires a load event, i.e., when a new document is loaded. This does not include page navigation within the current document or asynchronous resource loads. The following example code modifies the default font size of the guest's body element after the page loads:
webview.addEventListener('contentload', function() {
+ webview.executeScript({ code: 'document.body.style.fontSize = '42px'' });
+ });
+ */
+
+ contentload: (event: chrome.events.Event) => void;
+
+ /**
+ * @description Fired when the guest window attempts to open a modal dialog via window.alert, window.confirm, or window.prompt.Handling this event will block the guest process until each event listener returns or the dialog object becomes unreachable (if preventDefault() was called.)
The default behavior is to cancel the dialog.
+ * @param {any} [object Object]
+ */
+
+ dialog: chrome.events.Event;
+
+ /**
+ * @description Fired when the process rendering the guest web content has exited.The following example code will show a farewell message whenever the guest page crashes:
webview.addEventListener('exit', function(e) {
+ if (e.reason === 'crash') {
+ webview.src = 'data:text/plain,Goodbye, world!';
+ }
+ });
+ * @param {any} [object Object]
+ */
+
+ exit: chrome.events.Event;
+
+ /**
+ * @description Fired when new find results are available for an active find request. This might happen multiple times for a single find request as matches are found.
+ * @param {any} [object Object]
+ */
+
+ findupdate: chrome.events.Event;
+
+ /**
+ * @description Fired when a top-level load has aborted without committing. An error message will be printed to the console unless the event is default-prevented. Note: When a resource load is aborted, a loadabort event will eventually be followed by a loadstop event, even if all committed loads since the last loadstop event (if any) were aborted.
Note: When the load of either an about URL or a JavaScript URL is aborted, loadabort will be fired and then the webview will be navigated to 'about:blank'.
+ * @param {any} [object Object]
+ */
+
+ loadabort: chrome.events.Event;
+
+ /**
+ * @description Fired when a load has committed. This includes navigation within the current document as well as subframe document-level loads, but does not include asynchronous resource loads.
+ * @param {any} [object Object]
+ */
+
+ loadcommit: chrome.events.Event;
+
+ /**
+ * @description Fired when a top-level load request has redirected to a different URL.
+ * @param {any} [object Object]
+ */
+
+ loadredirect: chrome.events.Event;
+
+ /**
+ * @description Fired when a load has begun.
+ * @param {any} [object Object]
+ */
+
+ loadstart: chrome.events.Event;
+
+ /**
+ * @description Fired when all frame-level loads in a guest page (including all its subframes) have completed. This includes navigation within the current document as well as subframe document-level loads, but does not include asynchronous resource loads. This event fires every time the number of document-level loads transitions from one (or more) to zero. For example, if a page that has already finished loading (i.e., loadstop already fired once) creates a new iframe which loads a page, then a second loadstop will fire when the iframe page load completes. This pattern is commonly observed on pages that load ads. Note: When a committed load is aborted, a loadstop event will eventually follow a loadabort event, even if all committed loads since the last loadstop event (if any) were aborted.
+ */
+
+ loadstop(event: chrome.events.Event): void;
+
+ /**
+ * @description Fired when the guest page attempts to open a new browser window.The following example code will create and navigate a new webview in the embedder for each requested new window:
webview.addEventListener('newwindow', function(e) {
+ var newWebview = document.createElement('webview');
+ document.body.appendChild(newWebview);
+ e.window.attach(newWebview);
+ });
+ * @param {any} [object Object]
+ */
+
+ newwindow: chrome.events.Event;
+
+ /**
+ * @description Fired when the guest page needs to request special permission from the embedder.The following example code will grant the guest page access to the webkitGetUserMedia API. Note that an app using this example code must itself specify audioCapture and/or videoCapture manifest permissions:
webview.addEventListener('permissionrequest', function(e) {
+ if (e.permission === 'media') {
+ e.request.allow();
+ }
+ });
+ * @param {any} [object Object]
+ */
+
+ permissionrequest: chrome.events.Event;
+
+ /**
+ * @description Fired when the process rendering the guest web content has become responsive again after being unresponsive.The following example code will fade the webview element in or out as it becomes responsive or unresponsive:
webview.style.webkitTransition = 'opacity 250ms';
+ webview.addEventListener('unresponsive', function() {
+ webview.style.opacity = '0.5';
+ });
+ webview.addEventListener('responsive', function() {
+ webview.style.opacity = '1';
+ });
+ * @param {any} [object Object]
+ */
+
+ responsive: chrome.events.Event;
+
+ /**
+ * @description Fired when the embedded web content has been resized via autosize. Only fires if autosize is enabled.
+ * @param {any} [object Object]
+ */
+
+ sizechanged: chrome.events.Event;
+
+ /**
+ * @description Fired when the process rendering the guest web content has become unresponsive. This event will be generated once with a matching responsive event if the guest begins to respond again.
+ * @param {any} [object Object]
+ */
+
+ unresponsive: chrome.events.Event;
+
+ /**
+ * @description Fired when the page's zoom changes.
+ * @param {any} [object Object]
+ */
+
+ zoomchange: chrome.events.Event;
}
/**Options that determine what data should be cleared by clearData. */
@@ -5595,7 +5963,11 @@ declare namespace chrome {
deny(): void;
}
- /**Describes a rectangle in screen coordinates.
The containment semantics are array-like; that is, the coordinate (left, top) is considered to be contained by the rectangle, but the coordinate (left + width, top) is not.
*/
+ /**
+ * Fescribes a rectangle in screen coordinates.
+ * The containment semantics are array-like; that is, the coordinate (left, top) is considered to be contained by the rectangle,
+ * but the coordinate (left + width, top) is not.
+ **/
interface SelectionRect {
/**
@@ -5618,16 +5990,14 @@ declare namespace chrome {
*/
height: number
}
- /**Interface which provides access to webRequest events on the guest page. See the chrome.webRequest extensions API for details on webRequest life cycle and related concepts.To illustrate how usage differs from the extensions webRequest API, consider the following example code which blocks any guest requests for URLs which match *://www.evil.com/*:
webview.request.onBeforeRequest.addListener(
- function(details) { return {cancel: true}; },
- {urls: ['*://www.evil.com/*']},
- ['blocking']);Additionally, this interface supports declarative webRequest rules through onRequest and onMessage events. See declarativeWebRequest for API details.
Note that conditions and actions for declarative webview webRequests should be instantiated from their chrome.webViewRequest.* counterparts. The following example code declaratively blocks all requests to 'example.com' on the webview myWebview:var rule = {
- conditions: [
- new chrome.webViewRequest.RequestMatcher({ url: { hostSuffix: 'example.com' } })
- ],
- actions: [ new chrome.webViewRequest.CancelRequest() ]
- };
- myWebview.request.onRequest.addRules([rule]); */
+ /**
+ * @description Interface which provides access to webRequest events on the guest page. See the chrome.webRequest extensions API for details on webRequest life cycle and related concepts.To illustrate how usage differs from the extensions webRequest API, consider the following example code which blocks any guest requests for URLs which match *://www.evil.com/*:
webview.request.onBeforeRequest.addListener(
+ * @example function(details) { return {cancel: true}; }, {urls: ['*://www.evil.com/*']}, ['blocking']);
+ * @description Additionally, this interface supports declarative webRequest rules through onRequest and onMessage events.
+ * @see http://developer.chrome.com/extensions/declarativeWebRequest.htmldeclarativeWebRequest
+ * @description Note that conditions and actions for declarative webview webRequests should be instantiated from their chrome.webViewRequest.* counterparts. The following example code declaratively blocks all requests to 'example.com' on the webview myWebview:
+ * @example var rule = { conditions: [ new chrome.webViewRequest.RequestMatcher({ url: { hostSuffix: 'example.com' } }) ], actions: [ new chrome.webViewRequest.CancelRequest() ] }; myWebview.request.onRequest.addRules([rule]);
+ **/
interface WebRequestEventInterface {
}
/**
@@ -5641,358 +6011,6 @@ declare namespace chrome {
* * Disables all zooming in the webview. The content will revert to the default zoom level, and all attempted zoom changes will be ignored. */
export type ZoomMode = 'per-origin' | 'per-view' | 'disabled';
- /**
- * @description Queries audio state.
- * @param {any} [object Object]
- */
- export function getAudioState(callback: (audible: boolean) => void): void;
-
- /**
- * @description Sets audio mute state of the webview.
- * @param {boolean} mute Mute audio value
- */
- export function setAudioMuted(mute: boolean): void;
-
- /**
- * @description Queries whether audio is muted.
- * @param {any} [object Object]
- */
- export function isAudioMuted(callback: (muted: boolean) => void): void;
-
- /**
- * @description Captures the visible region of the webview.
- * @param {(dataUrl: string) => void} callback A data URL which encodes an image of the visible area of the captured tab. May be assigned to the 'src' property of an HTML Image element for display.
- */
- export function captureVisibleRegion(callback: (dataUrl: string) => void): void;
- /**
- * @description Captures the visible region of the webview.
- * @param {*} options
- * @param {(dataUrl: string) => void} callback
- */
- export function captureVisibleRegion(options: chrome.extensionTypes.ImageDetails, callback: (dataUrl: string) => void): void;
-
- /**
- * @description Adds content script injection rules to the webview. When the webview navigates to a page matching one or more rules, the associated scripts will be injected. You can programmatically add rules or update existing rules.
The following example adds two rules to the webview: 'myRule' and 'anotherRule'.
webview.addContentScripts([
- {
- name: 'myRule',
- matches: ['http://www.foo.com/*'],
- css: { files: ['mystyles.css'] },
- js: { files: ['jquery.js', 'myscript.js'] },
- run_at: 'document_start'
- },
- {
- name: 'anotherRule',
- matches: ['http://www.bar.com/*'],
- js: { code: 'document.body.style.backgroundColor = 'red';' },
- run_at: 'document_end'
- }]);
- ...
-
- // Navigates webview.
- webview.src = 'http://www.foo.com';You can defer addContentScripts call until you needs to inject scripts.
The following example shows how to overwrite an existing rule.
webview.addContentScripts([{
- name: 'rule',
- matches: ['http://www.foo.com/*'],
- js: { files: ['scriptA.js'] },
- run_at: 'document_start'}]);
-
- // Do something.
- webview.src = 'http://www.foo.com/*';
- ...
- // Overwrite 'rule' defined before.
- webview.addContentScripts([{
- name: 'rule',
- matches: ['http://www.bar.com/*'],
- js: { files: ['scriptB.js'] },
- run_at: 'document_end'}]);If webview has been naviagted to the origin (e.g., foo.com) and calls webview.addContentScripts to add 'myRule', you need to wait for next navigation to make the scripts injected. If you want immediate injection, executeScript will do the right thing.
Rules are preserved even if the guest process crashes or is killed or even if the webview is reparented.
Refer to the content scripts documentation for more details.
- * @param {ContentScriptDetails[]} contentScriptList Details of the content scripts to add.
- */
- export function addContentScripts(contentScriptList: ContentScriptDetails[]): void;
-
- /**
- * @description Navigates backward one history entry if possible. Equivalent to go(-1).
- * @param {(success: boolean) => void} [callback] Called after the navigation has either failed or completed successfully. Success parameter indicates whether the navigation was successful.
- */
- export function back(callback?: (success: boolean) => void): void;
-
- /**
- * @description Indicates whether or not it is possible to navigate backward through history. The state of this function is cached, and updated before each loadcommit, so the best place to call it is on loadcommit.
- */
- export function canGoBack(): void;
-
- /**
- * @description Indicates whether or not it is possible to navigate forward through history. The state of this function is cached, and updated before each loadcommit, so the best place to call it is on loadcommit.
- */
- export function canGoForward(): void;
-
- /**
- * @description Clears browsing data for the webview partition.
- * @param {any} options Options determining which data to clear.
- * @param {any} types The types of data to be cleared.
- * @param {any} [object Object]
- */
- export function clearData(options: ClearDataOptions, types: ClearDataTypeSet, callback?: () => void): void;
-
- /**
- * @description Injects JavaScript code into the guest page.
The following sample code uses script injection to set the guest page's background color to red:
webview.executeScript({ code: 'document.body.style.backgroundColor = 'red'' });
- * @param {any} details Details of the script to run.
- * @param {any} [object Object]
- */
- export function executeScript(details: InjectDetails, callback?: (result?: any[]) => void): void;
-
- /**
- * @description Initiates a find-in-page request.
- * @param {string} searchText The string to find in the page.
- * @param {any} options Options for the find request.
- * @param {any} [object Object]
- */
- export function find(searchText: string, options?: FindOptions, callback?: (results?: any) => void): void;
-
- /**
- * @description Navigates forward one history entry if possible. Equivalent to go(1).
- * @param {any} [object Object]
- */
- export function forward(callback?: (success: boolean) => void): void;
-
- /**
- * @description Returns Chrome's internal process ID for the guest web page's current process, allowing embedders to know how many guests would be affected by terminating the process. Two guests will share a process only if they belong to the same app and have the same storage partition ID. The call is synchronous and returns the embedder's cached notion of the current process ID. The process ID isn't the same as the operating system's process ID.
- */
- export function getProcessId(): void;
-
- /**
- * @description Returns the user agent string used by the webview for guest page requests.
- */
- export function getUserAgent(): void;
-
- /**
- * @description Gets the current zoom factor.
- * @param {any} [object Object]
- */
- export function getZoom(callback: (zoomFactor: number) => void): void;
-
- /**
- * @description Gets the current zoom mode.
- * @param {any} [object Object]
- */
- export function getZoomMode(callback: (ZoomMode: any) => void): void;
-
- /**
- * @description Navigates to a history entry using a history index relative to the current navigation. If the requested navigation is impossible, this method has no effect.
- * @param {number} relativeIndex Relative history index to which the webview should be navigated. For example, a value of 2 will navigate forward 2 history entries if possible; a value of -3 will navigate backward 3 entries.
- * @param {any} [object Object]
- */
- export function go(relativeIndex: number, callback?: (success: boolean) => void): void;
-
- /**
- * @description Injects CSS into the guest page.
- * @param {any} details Details of the CSS to insert.
- * @param {any} [object Object]
- */
- export function insertCSS(details: InjectDetails, callback?: () => void): void;
-
- /**
- * @description Indicates whether or not the webview's user agent string has been overridden by $(ref:webviewTag.setUserAgentOverride).
- */
- export function isUserAgentOverridden(): void;
-
- /**
- * @description Prints the contents of the webview. This is equivalent to calling scripted print function from the webview itself.
- */
- export function print(): void;
-
- /**
- * @description Reloads the current top-level page.
- */
- export function reload(): void;
-
- /**
- * @description Removes content scripts from a webview.
The following example removes 'myRule' which was added before.
webview.removeContentScripts(['myRule']);
You can remove all the rules by calling:
webview.removeContentScripts();
- * @param {any[]} scriptNameList A list of names of content scripts that will be removed. If the list is empty, all the content scripts added to the webview will be removed.
- */
- export function removeContentScripts(scriptNameList?: any[]): void;
-
- /**
- * @description Override the user agent string used by the webview for guest page requests.
- * @param {string} userAgent The user agent string to use.
- */
- export function setUserAgentOverride(userAgent: string): void;
-
- /**
- * @description Changes the zoom factor of the page. The scope and persistence of this change are determined by the webview's current zoom mode (see $(ref:webviewTag.ZoomMode)).
- * @param {number} zoomFactor The new zoom factor.
- * @param {any} [object Object]
- */
- export function setZoom(zoomFactor: number, callback?: () => void): void;
-
- /**
- * @description Sets the zoom mode of the webview.
- * @param {any} ZoomMode Defines how zooming is handled in the webview.
- * @param {any} [object Object]
- */
- export function setZoomMode(ZoomMode: ZoomMode, callback?: () => void): void;
-
- /**
- * @description Stops loading the current webview navigation if in progress.
- */
- export function stop(): void;
-
- /**
- * @description Ends the current find session (clearing all highlighting) and cancels all find requests in progress.
- * @param {string} action Determines what to do with the active match after the find session has ended. clear will clear the highlighting over the active match; keep will keep the active match highlighted; activate will keep the active match highlighted and simulate a user click on that match. The default action is keep.
- */
- export function stopFinding(action?: string): void;
-
- /**
- * @description Loads a data URL with a specified base URL used for relative links. Optionally, a virtual URL can be provided to be shown to the user instead of the data URL.
- * @param {string} dataUrl The data URL to load.
- * @param {string} baseUrl The base URL that will be used for relative links.
- * @param {string} virtualUrl The URL that will be displayed to the user (in the address bar).
- */
- export function loadDataWithBaseUrl(dataUrl: string, baseUrl: string, virtualUrl?: string): void;
-
- /**
- * @description Forcibly kills the guest web page's renderer process. This may affect multiple webview tags in the current app if they share the same process, but it will not affect webview tags in other apps.
- */
- export function terminate(): void;
-
- /**
- * @description Fired when the guest window attempts to close itself.The following example code navigates the webview to about:blank when the guest attempts to close itself.
webview.addEventListener('close', function() {
- webview.src = 'about:blank';
- });
- */
-
- export function close(event: chrome.events.Event): void;
-
- /**
- * @description Fired when the guest window logs a console message.The following example code forwards all log messages to the embedder's console without regard for log level or other properties.
webview.addEventListener('consolemessage', function(e) {
- console.log('Guest page logged a message: ', e.message);
- });
- * @param {any} [object Object]
- */
-
- export var consolemessage: chrome.events.Event;
-
- /**
- * @description Fired when the guest window fires a load event, i.e., when a new document is loaded. This does not include page navigation within the current document or asynchronous resource loads. The following example code modifies the default font size of the guest's body element after the page loads:
webview.addEventListener('contentload', function() {
- webview.executeScript({ code: 'document.body.style.fontSize = '42px'' });
- });
- */
-
- export var contentload: (event: chrome.events.Event) => void;
-
- /**
- * @description Fired when the guest window attempts to open a modal dialog via window.alert, window.confirm, or window.prompt.Handling this event will block the guest process until each event listener returns or the dialog object becomes unreachable (if preventDefault() was called.)
The default behavior is to cancel the dialog.
- * @param {any} [object Object]
- */
-
- export var dialog: chrome.events.Event;
-
- /**
- * @description Fired when the process rendering the guest web content has exited.The following example code will show a farewell message whenever the guest page crashes:
webview.addEventListener('exit', function(e) {
- if (e.reason === 'crash') {
- webview.src = 'data:text/plain,Goodbye, world!';
- }
- });
- * @param {any} [object Object]
- */
-
- export var exit: chrome.events.Event;
-
- /**
- * @description Fired when new find results are available for an active find request. This might happen multiple times for a single find request as matches are found.
- * @param {any} [object Object]
- */
-
- export var findupdate: chrome.events.Event;
-
- /**
- * @description Fired when a top-level load has aborted without committing. An error message will be printed to the console unless the event is default-prevented. Note: When a resource load is aborted, a loadabort event will eventually be followed by a loadstop event, even if all committed loads since the last loadstop event (if any) were aborted.
Note: When the load of either an about URL or a JavaScript URL is aborted, loadabort will be fired and then the webview will be navigated to 'about:blank'.
- * @param {any} [object Object]
- */
-
- export var loadabort: chrome.events.Event;
-
- /**
- * @description Fired when a load has committed. This includes navigation within the current document as well as subframe document-level loads, but does not include asynchronous resource loads.
- * @param {any} [object Object]
- */
-
- export var loadcommit: chrome.events.Event;
-
- /**
- * @description Fired when a top-level load request has redirected to a different URL.
- * @param {any} [object Object]
- */
-
- export var loadredirect: chrome.events.Event;
-
- /**
- * @description Fired when a load has begun.
- * @param {any} [object Object]
- */
-
- export var loadstart: chrome.events.Event;
-
- /**
- * @description Fired when all frame-level loads in a guest page (including all its subframes) have completed. This includes navigation within the current document as well as subframe document-level loads, but does not include asynchronous resource loads. This event fires every time the number of document-level loads transitions from one (or more) to zero. For example, if a page that has already finished loading (i.e., loadstop already fired once) creates a new iframe which loads a page, then a second loadstop will fire when the iframe page load completes. This pattern is commonly observed on pages that load ads. Note: When a committed load is aborted, a loadstop event will eventually follow a loadabort event, even if all committed loads since the last loadstop event (if any) were aborted.
- */
-
- export function loadstop(event: chrome.events.Event): void;
-
- /**
- * @description Fired when the guest page attempts to open a new browser window.The following example code will create and navigate a new webview in the embedder for each requested new window:
webview.addEventListener('newwindow', function(e) {
- var newWebview = document.createElement('webview');
- document.body.appendChild(newWebview);
- e.window.attach(newWebview);
- });
- * @param {any} [object Object]
- */
-
- export var newwindow: chrome.events.Event;
-
- /**
- * @description Fired when the guest page needs to request special permission from the embedder.The following example code will grant the guest page access to the webkitGetUserMedia API. Note that an app using this example code must itself specify audioCapture and/or videoCapture manifest permissions:
webview.addEventListener('permissionrequest', function(e) {
- if (e.permission === 'media') {
- e.request.allow();
- }
- });
- * @param {any} [object Object]
- */
-
- export var permissionrequest: chrome.events.Event;
-
- /**
- * @description Fired when the process rendering the guest web content has become responsive again after being unresponsive.The following example code will fade the webview element in or out as it becomes responsive or unresponsive:
webview.style.webkitTransition = 'opacity 250ms';
- webview.addEventListener('unresponsive', function() {
- webview.style.opacity = '0.5';
- });
- webview.addEventListener('responsive', function() {
- webview.style.opacity = '1';
- });
- * @param {any} [object Object]
- */
-
- export var responsive: chrome.events.Event;
-
- /**
- * @description Fired when the embedded web content has been resized via autosize. Only fires if autosize is enabled.
- * @param {any} [object Object]
- */
-
- export var sizechanged: chrome.events.Event;
-
- /**
- * @description Fired when the process rendering the guest web content has become unresponsive. This event will be generated once with a matching responsive event if the guest begins to respond again.
- * @param {any} [object Object]
- */
-
- export var unresponsive: chrome.events.Event;
-
- /**
- * @description Fired when the page's zoom changes.
- * @param {any} [object Object]
- */
-
- export var zoomchange: chrome.events.Event;
/**IConsolemessage (Auto generated interface) */
interface IConsolemessage {
From 1046b4f81f1853c02b275b20916cac10f04c5b98 Mon Sep 17 00:00:00 2001
From: Nikolai Ommundsen
Date: Thu, 14 Jun 2018 13:16:11 +0200
Subject: [PATCH 09/16] Webview typings fixed and doc updates. Tests updated.
---
types/chrome-apps/index.d.ts | 289 +++++++++++++++++++++-----------
types/chrome-apps/test/index.ts | 33 +++-
2 files changed, 222 insertions(+), 100 deletions(-)
diff --git a/types/chrome-apps/index.d.ts b/types/chrome-apps/index.d.ts
index 92e8a85c65..f0f0ed11b3 100644
--- a/types/chrome-apps/index.d.ts
+++ b/types/chrome-apps/index.d.ts
@@ -652,7 +652,27 @@ declare namespace chrome {
* @since This property is new in Chrome 36.
*/
outerBounds: Bounds;
+
+
+ /** Fired when the window is resized. */
+ onBoundsChanged: WindowEvent;
+ /**
+ * Fired when the window is closed.
+ * Note, this should be listened to from a window other than the window being closed, for example from the background page.
+ * This is because the window being closed will be in the process of being torn down when the event is fired,
+ * which means not all APIs in the window's script context will be functional.
+ */
+ onClosed: WindowEvent;
+ /** Fired when the window is fullscreened (either via the AppWindow or HTML5 APIs). */
+ onFullscreened: WindowEvent;
+ /** Fired when the window is maximized. */
+ onMaximized: WindowEvent;
+ /** Fired when the window is minimized. */
+ onMinimized: WindowEvent;
+ /** Fired when the window is restored from being minimized or maximized. */
+ onRestored: WindowEvent;
}
+ interface WindowEvent extends chrome.events.Event<() => void> { }
/**
* The size and position of a window can be specified in a number of different ways. The most simple option is not specifying anything at all, in which case a default size and platform dependent position will be used.
* To set the position, size and constraints of the window, use the innerBounds or outerBounds properties. Inner bounds do not include window decorations. Outer bounds include the window's title bar and frame. Note that the padding between the inner and outer bounds is determined by the OS. Therefore setting the same property for both inner and outer bounds is considered an error (for example, setting both innerBounds.left and outerBounds.left).
@@ -679,26 +699,6 @@ declare namespace chrome {
* Whether the current platform supports windows being visible on all workspaces.
*/
export function canSetVisibleOnAllWorkspaces(): boolean;
-
- interface WindowEvent extends chrome.events.Event<() => void> { }
-
- /** Fired when the window is resized. */
- export var onBoundsChanged: WindowEvent;
- /**
- * Fired when the window is closed.
- * Note, this should be listened to from a window other than the window being closed, for example from the background page.
- * This is because the window being closed will be in the process of being torn down when the event is fired,
- * which means not all APIs in the window's script context will be functional.
- */
- export var onClosed: WindowEvent;
- /** Fired when the window is fullscreened (either via the AppWindow or HTML5 APIs). */
- export var onFullscreened: WindowEvent;
- /** Fired when the window is maximized. */
- export var onMaximized: WindowEvent;
- /** Fired when the window is minimized. */
- export var onMinimized: WindowEvent;
- /** Fired when the window is restored from being minimized or maximized. */
- export var onRestored: WindowEvent;
}
@@ -5101,40 +5101,136 @@ declare namespace chrome {
file?: string
}
- interface WebViewElementEventMap {
- 'close': Event,
- 'consolemessage': IConsolemessage,
- 'contentload': Event,
- 'dialog': IDialog,
- 'exit': IExit,
- 'findupdate': IFindupdate,
- 'loadabort': ILoadabort,
- 'loadcommit': ILoadcommit,
- 'loadredirect': ILoadredirect,
- 'loadstart': ILoadstart,
- 'loadstop': Event,
- 'newwindow': INewwindow,
- 'permissionrequest': IPermissionrequest,
- 'responsive': IResponsive,
- 'sizechanged': ISizechanged,
- 'unresponsive': IUnresponsive,
- 'zoomchange': IZoomchange,
- }
-
-
/**
- * @description
- * @export
- * @interface HTMLWebViewElement
- * @extends {Element}
+ * @description WebView element from html
*/
interface HTMLWebViewElement extends Element {
+ /**
+ * This sets the guest content's window.name object.
+ */
+ name: string;
+ /**
+ * Returns the visible URL. Mirrors the logic in the browser's omnibox: either returning a pending new navigation if initiated by the embedder page, or the last committed navigation. Writing to this attribute initiates top-level navigation.
+ * Assigning src its own value will reload the current page.
+ * The src attribute cannot be cleared or removed once it has been set, unless the webview is removed from the DOM.
+ * The src attribute can also accept data URLs, such as "data:text/plain,Hello, world!".
+ */
src: string;
- contentWindow: Window;
- addEventListener(type: K, listener: (this: HTMLWebViewElement, ev: WebViewElementEventMap[K]) => any, useCapture?: boolean): void;
+ /**
+ * Storage partition ID used by the webview tag. If the storage partition ID starts with persist: (partition="persist:googlepluswidgets"), the webview will use a persistent storage partition available to all guests in the app with the same storage partition ID. If the ID is unset or if there is no 'persist': prefix, the webview will use an in-memory storage partition. This value can only be modified before the first navigation, since the storage partition of an active renderer process cannot change. Subsequent attempts to modify the value will fail with a DOM exception. By assigning the same partition ID, multiple webviews can share the same storage partition.
+ */
+ partition?: string;
+ /**
+ * If present, portions of the embedder could be visible through the webview, where the contents are transparent. Without allowtransparency enabled, no part of the embedder will be shown through the webview, even if elements exist that are specified as transparent.
+ * This does not affect transparency within the contents of the webview itself.
+ */
+ allowtransparency?: boolean;
+ /**
+ * If "on", the webview container will automatically resize within the bounds specified by the attributes minwidth, minheight, maxwidth, and maxheight.
+ * These constraints do not impact the webview UNLESS autosize is enabled.
+ * When autosize is enabled, the webview container size cannot be less than the minimum values or greater than the maximum.
+ */
+ autosize?: 'on';
+ /**
+ * Object reference which can be used to post messages into the guest page.
+ */
+ contentWindow: ContentWindow;
+ /** Interface which provides access to webRequest events on the guest page. */
+ request: WebRequestEventInterface;
+ /** Similar to chrome's ContextMenus API, but applies to webview instead of browser. Use the webview.contextMenus API to add items to webview's context menu. You can choose what types of objects your context menu additions apply to, such as images, hyperlinks, and pages. */
+ contextMenus: webview.ContextMenus;
+ /**
+ * Fired when the guest window attempts to close itself.
+ * The following example code navigates the webview to about:blank when the guest attempts to close itself.
+ */
+ addEventListener(type: 'close', listener: (this: HTMLWebViewElement) => void, useCapture?: boolean): void;
+ /**
+ * Fired when the guest window logs a console message.
+ * The following example code forwards all log messages to the embedder's console without regard for log level or other properties.
+ */
+ addEventListener(type: 'consolemessage', listener: (this: HTMLWebViewElement, ev: IConsoleMessage) => void, useCapture?: boolean): void;
+ /**
+ * Fired when the guest window fires a load event, i.e., when a new document is loaded. This does not include page navigation within the current document or asynchronous resource loads.
+ * The following example code modifies the default font size of the guest's body element after the page loads:
+ * @example
+ * webview.addEventListener('contentload', function() {
+ * webview.executeScript({ code: 'document.body.style.fontSize = "42px"' })
+ * });
+ */
+ addEventListener(type: 'contentload', listener: (this: HTMLWebViewElement) => void, useCapture?: boolean): void;
+ /**
+ * Fired when the guest window attempts to open a modal dialog via window.alert, window.confirm, or window.prompt.
+ * Handling this event will block the guest process until each event listener returns or the dialog object becomes unreachable (if preventDefault() was called.)
+ * The default behavior is to cancel the dialog.
+ */
+ addEventListener(type: 'dialog', listener: (this: HTMLWebViewElement, ev: IDialog) => void, useCapture?: boolean): void;
+ /**
+ * Fired when the process rendering the guest web content has exited.
+ */
+ addEventListener(type: 'exit', listener: (this: HTMLWebViewElement, ev: IExit) => void, useCapture?: boolean): void;
+ /**
+ * Fired when new find results are available for an active find request. This might happen multiple times for a single find request as matches are found.
+ */
+ addEventListener(type: 'findupdate', listener: (this: HTMLWebViewElement, ev: IFindupdate) => void, useCapture?: boolean): void;
+ /**
+ * Fired when a top-level load has aborted without committing. An error message will be printed to the console unless the event is default-prevented.
+ * Note: When a resource load is aborted, a loadabort event will eventually be followed by a loadstop event, even if all committed loads since the last loadstop event (if any) were aborted.
+ * Note: When the load of either an about URL or a JavaScript URL is aborted, loadabort will be fired and then the webview will be navigated to 'about:blank'.
+ */
+ addEventListener(type: 'loadabort', listener: (this: HTMLWebViewElement, ev: ILoadabort) => void, useCapture?: boolean): void;
+ /**
+ * Fired when a load has committed. This includes navigation within the current document as well as subframe document-level loads, but does not include asynchronous resource loads.
+ */
+ addEventListener(type: 'loadcommit', listener: (this: HTMLWebViewElement, ev: ILoadcommit) => void, useCapture?: boolean): void;
+ /**
+ * Fired when a top-level load request has redirected to a different URL.
+ */
+ addEventListener(type: 'loadredirect', listener: (this: HTMLWebViewElement, ev: ILoadredirect) => void, useCapture?: boolean): void;
+ /**
+ * Fired when a load has begun.
+ */
+ addEventListener(type: 'loadstart', listener: (this: HTMLWebViewElement, ev: ILoadstart) => void, useCapture?: boolean): void;
+ /**
+ * Fired when all frame-level loads in a guest page (including all its subframes) have completed.
+ * This includes navigation within the current document as well as subframe document-level loads, but does not include asynchronous resource loads.
+ * This event fires every time the number of document-level loads transitions from one (or more) to zero. For example, if a page that has already finished loading (i.e., loadstop already fired once) creates a new iframe which loads a page, then a second loadstop will fire when the iframe page load completes.
+ * This pattern is commonly observed on pages that load ads.
+ * Note: When a committed load is aborted, a loadstop event will eventually follow a loadabort event, even if all committed loads since the last loadstop event (if any) were aborted.
+ */
+ addEventListener(type: 'loadstop', listener: (this: HTMLWebViewElement) => void, useCapture?: boolean): void;
+ /**
+ * Fired when the guest page attempts to open a new browser window.
+ * The following example code will create and navigate a new webview in the embedder for each requested new window:
+ * @example
+ * webview.addEventListener('newwindow', function(e) {
+ * var newWebview = document.createElement('webview');
+ * document.body.appendChild(newWebview);
+ * e.window.attach(newWebview);
+ * });
+ */
+ addEventListener(type: 'newwindow', listener: (this: HTMLWebViewElement, ev: INewwindow) => void, useCapture?: boolean): void;
+ /**
+ * Fired when the guest page needs to request special permission from the embedder.
+ * The following example code will grant the guest page access to the webkitGetUserMedia API.
+ * Note that an app using this example code must itself specify audioCapture and/or videoCapture manifest permissions:
+ * @example
+ * webview.addEventListener('permissionrequest', function(e) {
+ * if (e.permission === 'media') {
+ * e.request.allow();
+ * }
+ * });
+ */
+ addEventListener(type: 'permissionrequest', listener: (this: HTMLWebViewElement, ev: IPermissionrequest) => void, useCapture?: boolean): void;
+ /** Fired when the process rendering the guest web content has become responsive again after being unresponsive. */
+ addEventListener(type: 'response', listener: (this: HTMLWebViewElement, ev: IResponsive) => void, useCapture?: boolean): void;
+ /** Fired when the embedded web content has been resized via autosize. Only fires if autosize is enabled. */
+ addEventListener(type: 'sizechanged', listener: (this: HTMLWebViewElement, ev: ISizechanged) => void, useCapture?: boolean): void;
+ /** Fired when the process rendering the guest web content has become unresponsive. This event will be generated once with a matching responsive event if the guest begins to respond again. */
+ addEventListener(type: 'unresponsive', listener: (this: HTMLWebViewElement, ev: IUnresponsive) => void, useCapture?: boolean): void;
+ /** Fired when the page's zoom changes. */
+ addEventListener(type: 'zoomchange', listener: (this: HTMLWebViewElement, ev: IZoomchange) => void, useCapture?: boolean): void;
/**
* @description Queries audio state.
- * @param {any} [object Object]
*/
getAudioState(callback: (audible: boolean) => void): void;
@@ -5146,7 +5242,6 @@ declare namespace chrome {
/**
* @description Queries whether audio is muted.
- * @param {any} [object Object]
*/
isAudioMuted(callback: (muted: boolean) => void): void;
@@ -5230,30 +5325,30 @@ declare namespace chrome {
/**
* @description Clears browsing data for the webview partition.
- * @param {any} options Options determining which data to clear.
- * @param {any} types The types of data to be cleared.
- * @param {any} [object Object]
+ * @param options Options determining which data to clear.
+ * @param types The types of data to be cleared.
+ * @param callback
*/
clearData(options: ClearDataOptions, types: ClearDataTypeSet, callback?: () => void): void;
/**
* @description Injects JavaScript code into the guest page.
The following sample code uses script injection to set the guest page's background color to red:
webview.executeScript({ code: 'document.body.style.backgroundColor = 'red'' });
- * @param {any} details Details of the script to run.
- * @param {any} [object Object]
+ * @param details Details of the script to run.
+ * @param callback
*/
executeScript(details: InjectDetails, callback?: (result?: any[]) => void): void;
/**
* @description Initiates a find-in-page request.
* @param {string} searchText The string to find in the page.
- * @param {any} options Options for the find request.
- * @param {any} [object Object]
+ * @param options Options for the find request.
+ * @param callback
*/
find(searchText: string, options?: FindOptions, callback?: (results?: any) => void): void;
/**
* @description Navigates forward one history entry if possible. Equivalent to go(1).
- * @param {any} [object Object]
+ * @param callback
*/
forward(callback?: (success: boolean) => void): void;
@@ -5269,27 +5364,27 @@ declare namespace chrome {
/**
* @description Gets the current zoom factor.
- * @param {any} [object Object]
+ * @param callback
*/
getZoom(callback: (zoomFactor: number) => void): void;
/**
* @description Gets the current zoom mode.
- * @param {any} [object Object]
+ * @param callback
*/
getZoomMode(callback: (ZoomMode: any) => void): void;
/**
* @description Navigates to a history entry using a history index relative to the current navigation. If the requested navigation is impossible, this method has no effect.
* @param {number} relativeIndex Relative history index to which the webview should be navigated. For example, a value of 2 will navigate forward 2 history entries if possible; a value of -3 will navigate backward 3 entries.
- * @param {any} [object Object]
+ * @param callback
*/
go(relativeIndex: number, callback?: (success: boolean) => void): void;
/**
* @description Injects CSS into the guest page.
- * @param {any} details Details of the CSS to insert.
- * @param {any} [object Object]
+ * @param details Details of the CSS to insert.
+ * @param callback
*/
insertCSS(details: InjectDetails, callback?: () => void): void;
@@ -5327,14 +5422,14 @@ declare namespace chrome {
/**
* @description Changes the zoom factor of the page. The scope and persistence of this change are determined by the webview's current zoom mode (see $(ref:webviewTag.ZoomMode)).
* @param {number} zoomFactor The new zoom factor.
- * @param {any} [object Object]
+ * @param callback
*/
setZoom(zoomFactor: number, callback?: () => void): void;
/**
* @description Sets the zoom mode of the webview.
- * @param {any} ZoomMode Defines how zooming is handled in the webview.
- * @param {any} [object Object]
+ * @param ZoomMode Defines how zooming is handled in the webview.
+ * @param callback
*/
setZoomMode(ZoomMode: ZoomMode, callback?: () => void): void;
@@ -5374,10 +5469,10 @@ declare namespace chrome {
* @description Fired when the guest window logs a console message.The following example code forwards all log messages to the embedder's console without regard for log level or other properties.
webview.addEventListener('consolemessage', function(e) {
console.log('Guest page logged a message: ', e.message);
});
- * @param {any} [object Object]
+ * @param callback
*/
- consolemessage: chrome.events.Event;
+ consolemessage: chrome.events.Event;
/**
* @description Fired when the guest window fires a load event, i.e., when a new document is loaded. This does not include page navigation within the current document or asynchronous resource loads. The following example code modifies the default font size of the guest's body element after the page loads:
webview.addEventListener('contentload', function() {
@@ -5389,7 +5484,7 @@ declare namespace chrome {
/**
* @description Fired when the guest window attempts to open a modal dialog via window.alert, window.confirm, or window.prompt.Handling this event will block the guest process until each event listener returns or the dialog object becomes unreachable (if preventDefault() was called.)
The default behavior is to cancel the dialog.
- * @param {any} [object Object]
+ * @param callback
*/
dialog: chrome.events.Event;
@@ -5400,42 +5495,42 @@ declare namespace chrome {
webview.src = 'data:text/plain,Goodbye, world!';
}
});
- * @param {any} [object Object]
+ * @param callback
*/
exit: chrome.events.Event;
/**
* @description Fired when new find results are available for an active find request. This might happen multiple times for a single find request as matches are found.
- * @param {any} [object Object]
+ * @param callback
*/
findupdate: chrome.events.Event;
/**
* @description Fired when a top-level load has aborted without committing. An error message will be printed to the console unless the event is default-prevented. Note: When a resource load is aborted, a loadabort event will eventually be followed by a loadstop event, even if all committed loads since the last loadstop event (if any) were aborted.
Note: When the load of either an about URL or a JavaScript URL is aborted, loadabort will be fired and then the webview will be navigated to 'about:blank'.
- * @param {any} [object Object]
+ * @param callback
*/
loadabort: chrome.events.Event;
/**
* @description Fired when a load has committed. This includes navigation within the current document as well as subframe document-level loads, but does not include asynchronous resource loads.
- * @param {any} [object Object]
+ * @param callback
*/
loadcommit: chrome.events.Event;
/**
* @description Fired when a top-level load request has redirected to a different URL.
- * @param {any} [object Object]
+ * @param callback
*/
loadredirect: chrome.events.Event;
/**
* @description Fired when a load has begun.
- * @param {any} [object Object]
+ * @param callback
*/
loadstart: chrome.events.Event;
@@ -5452,7 +5547,7 @@ declare namespace chrome {
document.body.appendChild(newWebview);
e.window.attach(newWebview);
});
- * @param {any} [object Object]
+ * @param callback
*/
newwindow: chrome.events.Event;
@@ -5463,7 +5558,7 @@ declare namespace chrome {
e.request.allow();
}
});
- * @param {any} [object Object]
+ * @param callback
*/
permissionrequest: chrome.events.EventPosts a message to the embedded web content as long as the embedded content is displaying a page from the target origin. This method is available once the page has completed loading. Listen for the contentload event and then call the method.
The guest will be able to send replies to the embedder by posting message to event.source on the message event it receives.
This API is identical to the HTML5 postMessage API for communication between web pages. The embedder may listen for replies by adding a message event listener to its own frame.
- * @param {any} message Message object to send to the guest. + * @param message Message object to send to the guest. * @param {string} targetOrigin Specifies what the origin of the guest window must be for the event to be dispatched. */ postMessage(message: any, targetOrigin: string): void; @@ -6011,13 +6106,18 @@ declare namespace chrome { * * Disables all zooming in the webview. The content will revert to the default zoom level, and all attempted zoom changes will be ignored. */ export type ZoomMode = 'per-origin' | 'per-view' | 'disabled'; - /**IConsolemessage (Auto generated interface) */ - interface IConsolemessage { + export enum ConsoleMessageLevel { + LOG_VERBOSE = -1, + LOG_INFO = 0, + LOG_WARNING = 1, + LOG_ERROR = 2 + } + interface IConsoleMessage { /** * @description The severity level of the log message. Ranges from -1 to 2. LOG_VERBOSE (console.debug) = -1, LOG_INFO (console.log, console.info) = 0, LOG_WARNING (console.warn) = 1, LOG_ERROR (console.error) = 2. */ - level: number + level: ConsoleMessageLevel; /** * @description The logged message contents. @@ -6034,7 +6134,6 @@ declare namespace chrome { */ sourceId: string } - /**IDialog (Auto generated interface) */ interface IDialog { /** @@ -6052,7 +6151,6 @@ declare namespace chrome { */ dialog: DialogController } - /**IExit (Auto generated interface) */ interface IExit { /** @@ -6065,7 +6163,6 @@ declare namespace chrome { */ reason: 'normal' | 'abnormal' | 'crash' | 'kill' } - /**IFindupdate (Auto generated interface) */ interface IFindupdate { /** @@ -6098,7 +6195,6 @@ declare namespace chrome { */ finalUpdate: string } - /**ILoadabort (Auto generated interface) */ interface ILoadabort { /** @@ -6121,7 +6217,6 @@ declare namespace chrome { */ reason: 'ERR_ABORTED' | 'ERR_INVALID_URL' | 'ERR_DISALLOWED_URL_SCHEME' | 'ERR_BLOCKED_BY_CLIENT' | 'ERR_ADDRESS_UNREACHABLE' | 'ERR_EMPTY_RESPONSE' | 'ERR_FILE_NOT_FOUND' | 'ERR_UNKNOWN_URL_SCHEME' } - /**ILoadcommit (Auto generated interface) */ interface ILoadcommit { /** diff --git a/types/chrome-apps/test/index.ts b/types/chrome-apps/test/index.ts index f976fc57b4..67a8c6213e 100644 --- a/types/chrome-apps/test/index.ts +++ b/types/chrome-apps/test/index.ts @@ -1,7 +1,7 @@ import runtime = chrome.app.runtime; import cwindow = chrome.app.window; -var createOptions: cwindow.CreateWindowOptions = { +const createOptions: cwindow.CreateWindowOptions = { id: "My Window", bounds: { left: 0, @@ -324,5 +324,32 @@ function testSystemNetwork() { }); } -import webview = chrome.webview; -let element: webview.HTMLWebViewElement; +let wve: chrome.webview.HTMLWebViewElement = (