Transfered Web APIs to another file

This commit is contained in:
Nikolai Ommundsen
2018-08-24 11:11:56 +02:00
parent cd3e2542b4
commit d84a9b95fb
5 changed files with 258 additions and 20 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
// Type definitions for Chrome packaged application development
// Project: http://developer.chrome.com/apps/
// Definitions by: Nikolai Ommundsen <https://github.com/niikoo>, Adam Lay <https://github.com/AdamLay>, MIZUNE Pine <https://github.com/pine613>, MIZUSHIMA Junki <https://github.com/mzsm>, Ingconst Stepanyan <https://github.com/RReverser>, Adam Pyle <https://github.com/pyle>, Matthew Kimber <https://github.com/matthewkimber>, otiai10 <https://github.com/otiai10>, couven92 <https://github.com/couven92>, RReverser <https://github.com/rreverser>, sreimer15 <https://github.com/sreimer15>
// Definitions by: Nikolai Ommundsen <https://github.com/niikoo>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
+33 -13
View File
@@ -7,6 +7,7 @@
/// <reference types='filesystem'/>
/// <reference path='./appview.d.ts'/>
/// <reference path='./webview.d.ts'/>
/// <reference path='./web-apis.d.ts'/>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// WebView ref //
@@ -9943,33 +9944,53 @@ declare namespace chrome {
* The chrome.types API contains type declarations for Chrome.
*/
namespace types {
/**
* The scope of the ChromeSetting. One of
* regular: setting for the regular profile (which is inherited by the incognito profile if not overridden elsewhere),
* regular_only: setting for the regular profile only (not inherited by the incognito profile),
* incognito_persistent: setting for the incognito profile that survives browser restarts (overrides regular preferences),
* incognito_session_only: setting for the incognito profile that can only be set during an incognito session and is deleted
* when the incognito session ends (overrides regular and incognito_persistent preferences).
*/
type ChromeSettingScope = "regular" | "regular_only" | "incognito_persistent" | "incognito_session_only";
/**
* One of
* not_controllable: cannot be controlled by any extension
* controlled_by_other_extensions: controlled by extensions with higher precedence
* controllable_by_this_extension: can be controlled by this app
* controlled_by_this_extension: controlled by this app
*/
type LevelOfControl = "not_controllable" | "controlled_by_other_extensions" | "controllable_by_this_extension" | "controlled_by_this_extension";
interface ChromeSettingClearDetails {
/**
* Optional.
* The scope of the ChromeSetting. One of
* regular: setting for the regular profile (which is inherited by the incognito profile if not overridden elsewhere),
* regular_only: setting for the regular profile only (not inherited by the incognito profile),
* incognito_persistent: setting for the incognito profile that survives browser restarts (overrides regular preferences),
* incognito_session_only: setting for the incognito profile that can only be set during an incognito session and is deleted when the incognito session ends (overrides regular and incognito_persistent preferences).
* incognito_session_only: setting for the incognito profile that can only be set during an incognito session and is deleted
* when the incognito session ends (overrides regular and incognito_persistent preferences).
*/
scope?: string;
scope?: ChromeSettingScope;
}
interface ChromeSettingSetDetails extends ChromeSettingClearDetails {
/**
* The value of the setting.
* Note that every setting has a specific value type, which is described together with the setting. An extension should not set a value of a different type.
* Note that every setting has a specific value type,
* which is described together with the setting.
* An app should not set a value of a different type.
*/
value: any;
/**
* Optional.
* The scope of the ChromeSetting. One of
* regular: setting for the regular profile (which is inherited by the incognito profile if not overridden elsewhere),
* regular_only: setting for the regular profile only (not inherited by the incognito profile),
* incognito_persistent: setting for the incognito profile that survives browser restarts (overrides regular preferences),
* incognito_session_only: setting for the incognito profile that can only be set during an incognito session and is deleted when the incognito session ends (overrides regular and incognito_persistent preferences).
* incognito_session_only: setting for the incognito profile that can only be set during an incognito session and is deleted
* when the incognito session ends (overrides regular and incognito_persistent preferences).
*/
scope?: string;
scope?: ChromeSettingScope;
}
interface ChromeSettingGetDetails {
@@ -9983,6 +10004,8 @@ declare namespace chrome {
type DetailsCallback = (details: ChromeSettingGetResultDetails) => void;
interface ChromeSettingGetResultDetails {
/** The value of the setting. */
value: any;
/**
* One of
* not_controllable: cannot be controlled by any extension
@@ -9991,10 +10014,7 @@ declare namespace chrome {
* controlled_by_this_extension: controlled by this app
*/
levelOfControl: string;
/** The value of the setting. */
value: any;
/**
* Optional.
* Whether the effective value is specific to the incognito session.
* This property will only be present if the incognito property in the details parameter of get() was true.
*/
@@ -10010,7 +10030,7 @@ declare namespace chrome {
* @param details Which setting to change.
* @param callback Called at the completion of the set operation.
*/
set(details: ChromeSettingSetDetails, callback?: Function): void;
set(details: ChromeSettingSetDetails, callback?: () => void): void;
/**
* Gets the value of a setting.
* @param details Which setting to consider.
@@ -10021,7 +10041,7 @@ declare namespace chrome {
* @param details Which setting to clear.
* @param callback Called at the completion of the clear operation.
*/
clear(details: ChromeSettingClearDetails, callback?: Function): void;
clear(details: ChromeSettingClearDetails, callback?: () => void): void;
/** Fired after the setting changes. */
onChange: ChromeSettingChangedEvent;
}
@@ -11421,7 +11441,7 @@ declare namespace chrome {
////////////
// EXPORT //
////////////
interface Window {
declare interface Window extends ChromeWindow {
chrome: typeof chrome;
WebView: typeof HTMLWebViewElement;
AppView: typeof HTMLAppViewElement;
+80 -2
View File
@@ -8,9 +8,87 @@ import runtime = chrome.app.runtime;
const cwindow = chrome.app.window;
// #region FORBIDDEN APIs
// Will give warnings via IntelliSense.
localStorage.getItem('hei');
document.open();
document.close();
document.write();
document.write('forbidden');
Document.prototype.write.call(document, 'Hello, world');
window.addEventListener('beforeunload', () => { });
// #endregion
// #region Web APIs
///
/// HTML5 Audio
///
var audioCtx = new window.AudioContext(); // define audio context
// Webkit/blink browsers need prefix, Safari won't work without window.
var drawVisual; // requestAnimationFrame
var analyser = audioCtx.createAnalyser();
var distortion = audioCtx.createWaveShaper();
var gainNode = audioCtx.createGain();
var biquadFilter = audioCtx.createBiquadFilter();
navigator.getUserMedia({
audio: true
},
(stream) => {
const source = audioCtx.createMediaStreamSource(stream);
source.connect(analyser);
analyser.connect(distortion);
distortion.connect(biquadFilter);
biquadFilter.connect(gainNode);
gainNode.connect(audioCtx.destination); // connecting the different audio graph nodes together
},
(error) => {
console.error(error);
}
);
///
/// HTML5 Canvas
///
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
if (ctx) {
ctx.fillStyle = 'green';
ctx.fillRect(10, 10, 100, 100);
}
///
/// Fullscreen API
///
const elem = document.createElement('video');
if (elem.requestFullscreen) {
elem.requestFullscreen();
}
document.webkitCancelFullScreen()
///
/// Geolocation API
///
window.onload = () => {
navigator.geolocation.getCurrentPosition((position) => {
console.log('lat', position.coords.latitude, 'lon', position.coords.longitude);
});
};
///
/// WebKit APIs
///
const mediaStream = new window.webkitMediaStream();
const rtcPeerConnection = new window.webkitRTCPeerConnection();
// #endregion
// #region Manifest
+4 -4
View File
@@ -1,10 +1,6 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es2017",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
@@ -13,6 +9,10 @@
"typeRoots": [
"../"
],
"lib": [
"es2017",
"dom"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
+140
View File
@@ -0,0 +1,140 @@
// Type definitions for Chrome packaged application development
// Project: http://developer.chrome.com/apps/
// Definitions by: Nikolai Ommundsen <https://github.com/niikoo>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
/////////////////////////
// WEB APIs & Warnings //
/////////////////////////
/**
* Only warnings since:
* 1. It's not possible as of now to override or remove something from *Window* or *Document*.
* 2. It may also cause other unforseen consequences if it's removed (and if it was possible).
* @see[Disallowed]
*/
/**
* Chrome app - Web APIs
* @see[Docs]{@link https://developer.chrome.com/apps/api_other}
*/
interface ChromeWindow {
///
/// Disabled Web Features
/// https://developer.chrome.com/apps/app_deprecated
///
/**
* ❗ alert is not available in packaged apps. ❗
* Work-around: Use a custom lightbox / popup.
*/
alert(message?: any): void;
/**
* ❗ confirm is not available in packaged apps. ❗
* Work-around: Use a custom lightbox / popup.
*/
confirm(message?: string): boolean;
/**
* ❗ window.location is not available in packaged apps. ❗
* Links open up with the system web browser.
*/
location: Location;
/**
* ❗ window.history is not available in packaged apps. ❗
* Links open up with the system web browser.
*/
readonly history: History;
///
/// Other APIs
///
AudioContext: typeof AudioContext;
//////////////////////////
// WebKit prefixed APIs //
//////////////////////////
webkitMediaStream: typeof MediaStream;
webkitRTCPeerConnection: typeof RTCPeerConnection;
}
interface Document {
/**
* ❗ document.cookie is not available in packaged apps. ❗
* Packaged app pages are not rendered on the server, so there is no need to use these.
*/
cookie: string;
/**
* ❗ document.close is not available in packaged apps. ❗
*/
close(): void;
/**
* ❗ document.open is not available in packaged apps. ❗
*/
open(url?: string, name?: string, features?: string, replace?: boolean): Document;
/**
* ❗ document.write is not available in packaged apps. ❗
*/
write(...content: string[]): void;
}
/**
* ❗ iframes are not available in packaged apps, use webviews instead. ❗
*/
interface HTMLIFrameElement { }
/**
* ❗ Modal dialogs are not available in packaged apps, use lightbox/popup instead. ❗
*/
interface HTMLDialogElement { }
interface HTMLElement {
/**
* @requires Permissions: 'app.window.fullscreen', 'app.window.fullscreen.overrideEsc'
* @description
* In Chrome Apps, fullscreen is entered without prompting the user or providing
* exit instructions. HTML5 fullscreen requires the app.window.fullscreen permission
* in the manifest. In normal webpages, the browser intercepts the ESC key to exit
* pointer lock ensuring a consistent escape method for users. That is also the
* behavior in Chrome Apps unless the app.window.fullscreen.overrideEsc permission
* is used to enable the app to call preventDefault on keydown and keyup events.
*
* Then to exit fullscreen, the document exposes a method for that:
* @example
* document.webkitExitFullscreen();
*/
webkitRequestFullscreen(): void;
}
interface HTMLElement {
/**
* ❗ Unprefixed version are not available as of Chrome 68, in Chrome apps ❗
*/
requestFullscreen(): void;
/**
* ❗ Unprefixed version are not available as of Chrome 68, in Chrome apps ❗
*/
exitrequestFullscreen(): void;
/**
* @requires Permissions: 'pointerLock'
*/
requestPointerLock(): void;
/**
* @requires Permissions: 'pointerLock'
*/
exitPointerLock(): void;
}
interface Navigator {
/**
* If you provide the 'geolocation' in your Chrome app it will allow the app to
* use the proposed HTML5 geolocation API without prompting the user for permission.
* @see Permissions: 'geolocation'
*/
readonly geolocation: Geolocation;
}
/**
* ❗ window.localStorage is not available in packaged apps. Use chrome.storage.local instead. ❗
*/
declare var localStorage: typeof localStorage;