├── .gitignore ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── declarations ├── src │ └── main │ │ └── kotlin │ │ ├── contextMenus │ │ └── contextMenus.kt │ │ ├── clipboard │ │ └── clipboard.kt │ │ ├── dns │ │ └── dns.kt │ │ ├── pkcs11 │ │ └── pkcs11.kt │ │ ├── experiments │ │ └── experiments.kt │ │ ├── search │ │ └── search.kt │ │ ├── permissions │ │ └── permissions.kt │ │ ├── idle │ │ └── idle.kt │ │ ├── identity │ │ └── identity.kt │ │ ├── topSites │ │ └── topSites.kt │ │ ├── theme │ │ └── theme.kt │ │ ├── commands │ │ └── commands.kt │ │ ├── find │ │ └── find.kt │ │ ├── contentScripts │ │ └── contentScripts.kt │ │ ├── test │ │ └── test.kt │ │ ├── i18n │ │ └── i18n.kt │ │ ├── geckoProfiler │ │ └── geckoProfiler.kt │ │ ├── alarms │ │ └── alarms.kt │ │ ├── extensionTypes │ │ └── extensionTypes.kt │ │ ├── userScripts │ │ └── userScripts.kt │ │ ├── browserSettings │ │ └── browserSettings.kt │ │ ├── types │ │ └── types.kt │ │ ├── extension │ │ └── extension.kt │ │ ├── sessions │ │ └── sessions.kt │ │ ├── contextualIdentities │ │ └── contextualIdentities.kt │ │ ├── omnibox │ │ └── omnibox.kt │ │ ├── webextensions │ │ └── browser.kt │ │ ├── privacy │ │ └── privacy.kt │ │ ├── proxy │ │ └── proxy.kt │ │ ├── storage │ │ └── storage.kt │ │ ├── browsingData │ │ └── browsingData.kt │ │ ├── history │ │ └── history.kt │ │ ├── notifications │ │ └── notifications.kt │ │ ├── management │ │ └── management.kt │ │ ├── events │ │ └── events.kt │ │ ├── pageAction │ │ └── pageAction.kt │ │ ├── telemetry │ │ └── telemetry.kt │ │ ├── sidebarAction │ │ └── sidebarAction.kt │ │ ├── bookmarks │ │ └── bookmarks.kt │ │ ├── browserAction │ │ └── browserAction.kt │ │ ├── devtools │ │ └── devtools.kt │ │ ├── webNavigation │ │ └── webNavigation.kt │ │ ├── cookies │ │ └── cookies.kt │ │ └── windows │ │ └── windows.kt └── build.gradle ├── src └── main │ └── kotlin │ └── de │ └── rakhman │ └── webextensions │ ├── Utils.kt │ ├── serialization │ └── ParameterAdapter.kt │ ├── model.kt │ ├── main.kt │ └── merging.kt ├── README.md ├── gradlew.bat ├── gradlew └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | /.gradle 3 | /schemas 4 | build 5 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'webextension-declaration-generator' 2 | 3 | include ':declarations' 4 | 5 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cypressious/kotlin-webextensions-declarations/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Nov 25 16:23:58 CET 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-bin.zip 7 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/contextMenus/contextMenus.kt: -------------------------------------------------------------------------------- 1 | package contextMenus 2 | 3 | /** 4 | * The different contexts a menu can appear in. Specifying 'all' is equivalent to the combination of 5 | all other contexts except for 'tab' and 'tools_menu'. */ 6 | typealias ContextType = String 7 | 8 | external class ContextMenusNamespace 9 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/clipboard/clipboard.kt: -------------------------------------------------------------------------------- 1 | package clipboard 2 | 3 | import kotlin.js.Promise 4 | 5 | /** 6 | * The image data to be copied. */ 7 | typealias ImageData = Any 8 | 9 | external class ClipboardNamespace { 10 | /** 11 | * Copy an image to the clipboard. The image is re-encoded before it is written to the 12 | clipboard. If the image is invalid, the clipboard is not modified. 13 | */ 14 | fun setImageData(imageData: ImageData, imageType: String): Promise 15 | } 16 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/dns/dns.kt: -------------------------------------------------------------------------------- 1 | package dns 2 | 3 | import kotlin.js.Promise 4 | 5 | /** 6 | * An object encapsulating a DNS Record. 7 | * @param canonicalName The canonical hostname for this record. this value is empty if the record 8 | was not fetched with the 'canonical_name' flag. 9 | * @param isTRR Record retreived with TRR. 10 | */ 11 | class DNSRecord( 12 | var canonicalName: String? = null, 13 | var isTRR: String, 14 | var addresses: Array 15 | ) 16 | 17 | typealias ResolveFlags = Array 18 | 19 | external class DnsNamespace { 20 | /** 21 | * Resolves a hostname to a DNS record. 22 | */ 23 | fun resolve(hostname: String, flags: ResolveFlags? = definedExternally): Promise 24 | } 25 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/pkcs11/pkcs11.kt: -------------------------------------------------------------------------------- 1 | package pkcs11 2 | 3 | import kotlin.js.Promise 4 | 5 | external class Pkcs11Namespace { 6 | /** 7 | * checks whether a PKCS#11 module, given by name, is installed 8 | */ 9 | fun isModuleInstalled(name: String): Promise 10 | 11 | /** 12 | * Install a PKCS#11 module with a given name 13 | */ 14 | fun installModule(name: String, flags: Int? = definedExternally): Promise 15 | 16 | /** 17 | * Remove an installed PKCS#11 module from firefox 18 | */ 19 | fun uninstallModule(name: String): Promise 20 | 21 | /** 22 | * Enumerate a module's slots, each with their name and whether a token is present 23 | */ 24 | fun getModuleSlots(name: String): Promise 25 | } 26 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/experiments/experiments.kt: -------------------------------------------------------------------------------- 1 | package experiments 2 | 3 | class ExperimentAPI( 4 | var schema: ExperimentURL, 5 | var parent: Parent? = null, 6 | var child: Child? = null 7 | ) 8 | 9 | typealias ExperimentURL = String 10 | 11 | typealias APIPaths = Array 12 | 13 | typealias APIPath = Array 14 | 15 | typealias APIEvents = Array 16 | 17 | typealias APIEvent = String 18 | 19 | typealias APIParentScope = String 20 | 21 | typealias APIChildScope = String 22 | 23 | class Parent( 24 | var events: APIEvents? = null, 25 | var paths: APIPaths? = null, 26 | var script: ExperimentURL, 27 | var scopes: Array? = null 28 | ) 29 | 30 | class Child( 31 | var paths: APIPaths, 32 | var script: ExperimentURL, 33 | var scopes: Array 34 | ) 35 | 36 | external class ExperimentsNamespace 37 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/search/search.kt: -------------------------------------------------------------------------------- 1 | package search 2 | 3 | import kotlin.js.Promise 4 | 5 | /** 6 | * An object encapsulating a search engine 7 | */ 8 | class SearchEngine( 9 | var name: String, 10 | var isDefault: Boolean, 11 | var alias: String? = null, 12 | var favIconUrl: String? = null 13 | ) 14 | 15 | /** 16 | * @param query Terms to search for. 17 | * @param engine Search engine to use. Uses the default if not specified. 18 | * @param tabId The ID of the tab for the search results. If not specified, a new tab is created. 19 | */ 20 | class SearchProperties( 21 | var query: String, 22 | var engine: String? = null, 23 | var tabId: Int? = null 24 | ) 25 | 26 | external class SearchNamespace { 27 | /** 28 | * Gets a list of search engines. 29 | */ 30 | fun get(): Promise 31 | 32 | /** 33 | * Perform a search. 34 | */ 35 | fun search(searchProperties: SearchProperties): Promise 36 | } 37 | -------------------------------------------------------------------------------- /src/main/kotlin/de/rakhman/webextensions/Utils.kt: -------------------------------------------------------------------------------- 1 | package de.rakhman.webextensions 2 | 3 | internal fun String.escapeIfKeyword() = if (isKeyword) "`${this}`" else this 4 | 5 | internal val String.isKeyword get() = KEYWORDS.contains(this) 6 | 7 | // https://github.com/JetBrains/kotlin/blob/master/core/descriptors/src/org/jetbrains/kotlin/renderer/KeywordStringsGenerated.java 8 | private val KEYWORDS = setOf( 9 | "package", 10 | "as", 11 | "typealias", 12 | "class", 13 | "this", 14 | "super", 15 | "val", 16 | "var", 17 | "fun", 18 | "for", 19 | "null", 20 | "true", 21 | "false", 22 | "is", 23 | "in", 24 | "throw", 25 | "return", 26 | "break", 27 | "continue", 28 | "object", 29 | "if", 30 | "try", 31 | "else", 32 | "while", 33 | "do", 34 | "when", 35 | "interface", 36 | "typeof" 37 | ) 38 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/permissions/permissions.kt: -------------------------------------------------------------------------------- 1 | package permissions 2 | 3 | import kotlin.js.Promise 4 | import manifest.MatchPattern 5 | import manifest.OptionalPermission 6 | import manifest.Permission 7 | 8 | class Permissions(var permissions: Array? = null, var origins: 9 | Array? = null) 10 | 11 | class AnyPermissions(var permissions: Array? = null, var origins: Array? = 12 | null) 13 | 14 | external class PermissionsNamespace { 15 | /** 16 | * Get a list of all the extension's permissions. 17 | */ 18 | fun getAll(): Promise 19 | 20 | /** 21 | * Check if the extension has the given permissions. 22 | */ 23 | fun contains(permissions: AnyPermissions): Promise 24 | 25 | /** 26 | * Request the given permissions. 27 | */ 28 | fun request(permissions: Permissions): Promise 29 | 30 | /** 31 | * Relinquish the given permissions. 32 | */ 33 | fun remove(permissions: Permissions): Promise 34 | } 35 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/idle/idle.kt: -------------------------------------------------------------------------------- 1 | package idle 2 | 3 | import kotlin.js.Promise 4 | import webextensions.Event 5 | 6 | typealias IdleState = String 7 | 8 | external class IdleNamespace { 9 | /** 10 | * Fired when the system changes to an active or idle state. The event fires with "idle" if the 11 | the user has not generated any input for a specified number of seconds, and "active" 12 | when the user generates input on an idle system. 13 | * 14 | * @param newState null */ 15 | val onStateChanged: Event<(newState: IdleState) -> Unit> 16 | 17 | /** 18 | * Returns "idle" if the user has not generated any input for a specified number of seconds, or 19 | "active" otherwise. 20 | */ 21 | fun queryState(detectionIntervalInSeconds: Int): Promise 22 | 23 | /** 24 | * Sets the interval, in seconds, used to determine when the system is in an idle state for 25 | onStateChanged events. The default interval is 60 seconds. 26 | */ 27 | fun setDetectionInterval(intervalInSeconds: Int) 28 | } 29 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/identity/identity.kt: -------------------------------------------------------------------------------- 1 | package identity 2 | 3 | import kotlin.js.Promise 4 | import manifest.HttpURL 5 | 6 | /** 7 | * An object encapsulating an OAuth account id. 8 | * @param id A unique identifier for the account. This ID will not change for the lifetime of the 9 | account. 10 | */ 11 | class AccountInfo( 12 | var id: String 13 | ) 14 | 15 | class Details( 16 | var interactive: Boolean? = null, 17 | var account: AccountInfo? = null, 18 | var scopes: Array? = null 19 | ) 20 | 21 | class Userinfo(var email: String, var id: String) 22 | 23 | class Details2(var token: String) 24 | 25 | class Userinfo2(var email: String, var id: String) 26 | 27 | class Details3(var url: HttpURL, var interactive: Boolean? = null) 28 | 29 | external class IdentityNamespace { 30 | /** 31 | * Starts an auth flow at the specified URL. 32 | */ 33 | fun launchWebAuthFlow(details: Details3): Promise 34 | 35 | /** 36 | * Generates a redirect URL to be used in |launchWebAuthFlow|. 37 | */ 38 | fun getRedirectURL(path: String? = definedExternally): String 39 | } 40 | -------------------------------------------------------------------------------- /declarations/build.gradle: -------------------------------------------------------------------------------- 1 | version publish_version 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } 7 | } 8 | dependencies { 9 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 10 | } 11 | } 12 | 13 | apply plugin: 'kotlin2js' 14 | apply plugin: 'maven-publish' 15 | 16 | repositories { 17 | jcenter() 18 | maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } 19 | } 20 | 21 | dependencies { 22 | compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version" 23 | } 24 | 25 | compileKotlin2Js { 26 | kotlinOptions.sourceMap = true 27 | } 28 | 29 | task sourceJar(type: Jar) { 30 | from sourceSets.main.kotlin 31 | } 32 | 33 | publishing { 34 | publications { 35 | maven(MavenPublication) { 36 | groupId 'de.rakhman.webextensions-declarations' 37 | artifactId 'webextensions-declarations' 38 | version publish_version 39 | 40 | from components.java 41 | 42 | artifact sourceJar { 43 | classifier "sources" 44 | } 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kotlin WebExtensions API Declarations 2 | 3 | A generator for Kotlin JS declarations for the Firefox WebExtensions API from the offical schema files. This repo also contains the ready-made generated declarations. 4 | 5 | The schema is taken from https://github.com/mozilla/gecko-dev/tree/master/browser/components/extensions/schemas and https://github.com/mozilla/gecko-dev/tree/master/toolkit/components/extensions/schemas. 6 | 7 | See KotlinConf 2018 talk: [Building a Browser Extension with Kotlin](https://kotlinconf.com/talks/#session=21914) 8 | 9 | See https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions 10 | 11 | ## Example projects 12 | 13 | - https://github.com/cypressious/webextension-search-kotlin-docs 14 | - https://github.com/cypressious/second-firefox-extension-kotlin 15 | 16 | 17 | ## How to use in a Gradle project 18 | 19 | You can include the declarations in your project by using jitpack.io. 20 | 21 | In your `build.gradle` add 22 | 23 | ```groovy 24 | repositories { 25 | // ... 26 | maven { url 'https://jitpack.io' } 27 | } 28 | ``` 29 | 30 | and 31 | 32 | ```groovy 33 | dependencies { 34 | // ... 35 | compile 'com.github.cypressious.kotlin-webextensions-declarations:webextensions-declarations:v0.4' 36 | } 37 | ``` 38 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/topSites/topSites.kt: -------------------------------------------------------------------------------- 1 | package topSites 2 | 3 | import kotlin.js.Promise 4 | 5 | /** 6 | * An object encapsulating a most visited URL, such as the URLs on the new tab page. 7 | * @param url The most visited URL. 8 | * @param title The title of the page. 9 | * @param favicon Data URL for the favicon, if available. 10 | */ 11 | class MostVisitedURL( 12 | var url: String, 13 | var title: String? = null, 14 | var favicon: String? = null 15 | ) 16 | 17 | /** 18 | * @param limit The number of top sites to return, defaults to the value used by Firefox 19 | * @param onePerDomain Limit the result to a single top site link per domain 20 | * @param includeBlocked Include sites that the user has blocked from appearing on the Firefox new 21 | tab. 22 | * @param includeFavicon Include sites favicon if available. 23 | */ 24 | class Options( 25 | var providers: Array? = null, 26 | var limit: Int? = null, 27 | var onePerDomain: Boolean? = null, 28 | var includeBlocked: Boolean? = null, 29 | var includeFavicon: Boolean? = null 30 | ) 31 | 32 | external class TopSitesNamespace { 33 | /** 34 | * Gets a list of top sites. 35 | */ 36 | fun get(options: Options? = definedExternally): Promise> 37 | } 38 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/theme/theme.kt: -------------------------------------------------------------------------------- 1 | package theme 2 | 3 | import kotlin.js.Promise 4 | import manifest.ThemeType 5 | import webextensions.Event 6 | 7 | /** 8 | * Info provided in the onUpdated listener. 9 | * @param theme The new theme after update 10 | * @param windowId The id of the window the theme has been applied to 11 | */ 12 | class ThemeUpdateInfo( 13 | var theme: Theme, 14 | var windowId: Int? = null 15 | ) 16 | 17 | /** 18 | * The new theme after update */ 19 | typealias Theme = Any 20 | 21 | external class ThemeNamespace { 22 | /** 23 | * Fired when a new theme has been applied 24 | * 25 | * @param updateInfo Details of the theme update */ 26 | val onUpdated: Event<(updateInfo: ThemeUpdateInfo) -> Unit> 27 | 28 | /** 29 | * Returns the current theme for the specified window or the last focused window. 30 | */ 31 | fun getCurrent(windowId: Int? = definedExternally): Promise 32 | 33 | /** 34 | * Make complete updates to the theme. Resolves when the update has completed. 35 | */ 36 | fun update(windowId: Int? = definedExternally, details: ThemeType): Promise 37 | 38 | /** 39 | * Removes the updates made to the theme. 40 | */ 41 | fun reset(windowId: Int? = definedExternally): Promise 42 | } 43 | -------------------------------------------------------------------------------- /src/main/kotlin/de/rakhman/webextensions/serialization/ParameterAdapter.kt: -------------------------------------------------------------------------------- 1 | package de.rakhman.webextensions.serialization 2 | 3 | import com.google.gson.Gson 4 | import com.google.gson.TypeAdapter 5 | import com.google.gson.TypeAdapterFactory 6 | import com.google.gson.reflect.TypeToken 7 | import com.google.gson.stream.JsonReader 8 | import com.google.gson.stream.JsonToken 9 | import com.google.gson.stream.JsonWriter 10 | import de.rakhman.webextensions.Parameter 11 | 12 | 13 | class ParameterAdapterFactory : TypeAdapterFactory { 14 | 15 | @Suppress("UNCHECKED_CAST") 16 | override fun create(gson: Gson, type: TypeToken): TypeAdapter? { 17 | if (type.rawType != Parameter::class.java) return null 18 | 19 | val defaultAdapter = gson.getDelegateAdapter(this, type) as TypeAdapter 20 | return ParameterAdapter(defaultAdapter) as TypeAdapter 21 | } 22 | 23 | class ParameterAdapter( 24 | private val defaultAdapter: TypeAdapter 25 | ) : TypeAdapter() { 26 | 27 | override fun write(out: JsonWriter, value: Parameter) { 28 | defaultAdapter.write(out, value) 29 | } 30 | 31 | override fun read(`in`: JsonReader): Parameter? { 32 | if (`in`.peek() != JsonToken.BEGIN_OBJECT) { 33 | `in`.skipValue() 34 | return null 35 | } 36 | return defaultAdapter.read(`in`) 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /declarations/src/main/kotlin/commands/commands.kt: -------------------------------------------------------------------------------- 1 | package commands 2 | 3 | import kotlin.js.Promise 4 | import manifest.KeyName 5 | import webextensions.Event 6 | 7 | /** 8 | * @param name The name of the Extension Command 9 | * @param description The Extension Command description 10 | * @param shortcut The shortcut active for this command, or blank if not active. 11 | */ 12 | class Command( 13 | var name: String? = null, 14 | var description: String? = null, 15 | var shortcut: String? = null 16 | ) 17 | 18 | /** 19 | * The new description for the command. 20 | * @param name The name of the command. 21 | * @param description The new description for the command. 22 | */ 23 | class Detail( 24 | var name: String, 25 | var description: String? = null, 26 | var shortcut: KeyName? = null 27 | ) 28 | 29 | external class CommandsNamespace { 30 | /** 31 | * Fired when a registered command is activated using a keyboard shortcut. 32 | * 33 | * @param command null */ 34 | val onCommand: Event<(command: String) -> Unit> 35 | 36 | /** 37 | * Update the details of an already defined command. 38 | */ 39 | fun update(detail: Detail): Promise 40 | 41 | /** 42 | * Reset a command's details to what is specified in the manifest. 43 | */ 44 | fun reset(name: String): Promise 45 | 46 | /** 47 | * Returns all the registered extension commands for this extension and their shortcut (if 48 | active). 49 | */ 50 | fun getAll(): Promise> 51 | } 52 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/find/find.kt: -------------------------------------------------------------------------------- 1 | package find 2 | 3 | import kotlin.js.Promise 4 | 5 | /** 6 | * Search parameters. 7 | * @param tabId Tab to query. Defaults to the active tab. 8 | * @param caseSensitive Find only ranges with case sensitive match. 9 | * @param entireWord Find only ranges that match entire word. 10 | * @param includeRectData Return rectangle data which describes visual position of search results. 11 | * @param includeRangeData Return range data which provides range data in a serializable form. 12 | */ 13 | class Params( 14 | var tabId: Int? = null, 15 | var caseSensitive: Boolean? = null, 16 | var entireWord: Boolean? = null, 17 | var includeRectData: Boolean? = null, 18 | var includeRangeData: Boolean? = null 19 | ) 20 | 21 | /** 22 | * highlightResults parameters 23 | * @param rangeIndex Found range to be highlighted. Default highlights all ranges. 24 | * @param tabId Tab to highlight. Defaults to the active tab. 25 | * @param noScroll Don't scroll to highlighted item. 26 | */ 27 | class Params2( 28 | var rangeIndex: Int? = null, 29 | var tabId: Int? = null, 30 | var noScroll: Boolean? = null 31 | ) 32 | 33 | external class FindNamespace { 34 | /** 35 | * Search for text in document and store found ranges in array, in document order. 36 | */ 37 | fun find(queryphrase: String, params: Params? = definedExternally): Promise 38 | 39 | /** 40 | * Highlight a range 41 | */ 42 | fun highlightResults(params: Params2? = definedExternally): Promise 43 | 44 | /** 45 | * Remove all highlighting from previous searches. 46 | */ 47 | fun removeHighlighting(tabId: Int? = definedExternally): Promise 48 | } 49 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/contentScripts/contentScripts.kt: -------------------------------------------------------------------------------- 1 | package contentScripts 2 | 3 | import extensionTypes.ExtensionFileOrCode 4 | import extensionTypes.RunAt 5 | import kotlin.js.Promise 6 | import manifest.MatchPattern 7 | 8 | /** 9 | * Details of a content script registered programmatically 10 | * @param css The list of CSS files to inject 11 | * @param js The list of JS files to inject 12 | * @param allFrames If allFrames is true, implies that the JavaScript or CSS should be 13 | injected into all frames of current page. By default, it's false and is only 14 | injected into the top frame. 15 | * @param matchAboutBlank If matchAboutBlank is true, then the code is also injected in about:blank 16 | and about:srcdoc frames if your extension has access to its parent document. Code cannot be 17 | inserted in top-level about:-frames. By default it is false. 18 | * @param runAt The soonest that the JavaScript or CSS will be injected into the tab. Defaults to 19 | "document_idle". 20 | */ 21 | class RegisteredContentScriptOptions( 22 | var matches: Array, 23 | var excludeMatches: Array? = null, 24 | var includeGlobs: Array? = null, 25 | var excludeGlobs: Array? = null, 26 | var css: Array? = null, 27 | var js: Array? = null, 28 | var allFrames: Boolean? = null, 29 | var matchAboutBlank: Boolean? = null, 30 | var runAt: RunAt? = null 31 | ) 32 | 33 | /** 34 | * An object that represents a content script registered programmatically 35 | */ 36 | external class RegisteredContentScript { 37 | /** 38 | * Unregister a content script registered programmatically 39 | */ 40 | fun unregister(): Promise 41 | } 42 | 43 | external class ContentScriptsNamespace { 44 | /** 45 | * Register a content script programmatically 46 | */ 47 | fun register(contentScriptOptions: RegisteredContentScriptOptions): Promise 48 | } 49 | -------------------------------------------------------------------------------- /src/main/kotlin/de/rakhman/webextensions/model.kt: -------------------------------------------------------------------------------- 1 | package de.rakhman.webextensions 2 | 3 | data class Namespace( 4 | val namespace: String, 5 | val description: String?, 6 | val types: List?, 7 | val properties: Map?, 8 | val functions: List?, 9 | val events: List? 10 | ) 11 | 12 | data class Type( 13 | val id: String?, 14 | val type: String?, 15 | val properties: Map?, 16 | val description: String?, 17 | val `$extend`: String?, 18 | val choices: List?, 19 | val actual: Boolean, 20 | val items: Parameter?, 21 | val additionalProperties: Parameter?, 22 | val patternProperties: Map?, 23 | val functions: List?, 24 | val isExternal: Boolean = false 25 | ) 26 | 27 | data class Function( 28 | val name: String, 29 | val type: String, 30 | val description: String?, 31 | val async: Any?, 32 | val parameters: List?, 33 | val deprecated: String?, 34 | val unsupported: Boolean, 35 | val returns: Parameter?, 36 | val patternProperties: Map? 37 | ) 38 | 39 | data class Parameter( 40 | val type: String? = null, 41 | val name: String? = null, 42 | val description: String? = null, 43 | val optional: Boolean = false, 44 | val properties: Map? = null, 45 | val deprecated: String? = null, 46 | val `$ref`: String? = null, 47 | val parameters: List? = null, 48 | val items: Parameter? = null, 49 | val choices: List? = null, 50 | val unsupported: Boolean = false, 51 | val additionalProperties: Parameter? = null, 52 | val patternProperties: Map? = null, 53 | val value: Any? = null 54 | ) 55 | 56 | data class Event( 57 | val name: String, 58 | val unsupported: Boolean, 59 | val deprecated: String?, 60 | val type: String?, 61 | val description: String?, 62 | val parameters: List? 63 | ) 64 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/test/test.kt: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import kotlin.js.Promise 4 | import webextensions.Event 5 | 6 | typealias ExpectedError = Any 7 | 8 | typealias Promise = Any 9 | 10 | typealias Test = Any 11 | 12 | external class TestNamespace { 13 | /** 14 | * Used to test sending messages to extensions. 15 | * 16 | * @param message null 17 | * @param argument null */ 18 | val onMessage: Event<(message: String, argument: dynamic) -> Unit> 19 | 20 | /** 21 | * Notifies the browser process that test code running in the extension failed. This is only 22 | used for internal unit testing. 23 | */ 24 | fun notifyFail(message: String) 25 | 26 | /** 27 | * Notifies the browser process that test code running in the extension passed. This is only 28 | used for internal unit testing. 29 | */ 30 | fun notifyPass(message: String? = definedExternally) 31 | 32 | /** 33 | * Logs a message during internal unit testing. 34 | */ 35 | fun log(message: String) 36 | 37 | /** 38 | * Sends a string message to the browser process, generating a Notification that C++ test code 39 | can wait for. 40 | */ 41 | fun sendMessage(arg1: dynamic = definedExternally, arg2: dynamic = definedExternally) 42 | 43 | fun fail(message: dynamic = definedExternally) 44 | 45 | fun succeed(message: dynamic = definedExternally) 46 | 47 | fun assertTrue(test: dynamic = definedExternally, message: String? = definedExternally) 48 | 49 | fun assertFalse(test: dynamic = definedExternally, message: String? = definedExternally) 50 | 51 | fun assertEq( 52 | expected: dynamic = definedExternally, 53 | actual: dynamic = definedExternally, 54 | message: String? = definedExternally 55 | ) 56 | 57 | fun assertRejects( 58 | promise: Promise, 59 | expectedError: ExpectedError? = definedExternally, 60 | message: String? = definedExternally 61 | ): Promise 62 | 63 | fun assertThrows( 64 | func: () -> Unit, 65 | expectedError: ExpectedError? = definedExternally, 66 | message: String? = definedExternally 67 | ) 68 | } 69 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/i18n/i18n.kt: -------------------------------------------------------------------------------- 1 | package i18n 2 | 3 | import kotlin.js.Promise 4 | 5 | /** 6 | * An ISO language code such as en or fr. For a complete list of languages 7 | supported by this method, see kLanguageInfoTable. 9 | For an unknown language, und will be returned, which means that [percentage] of 10 | the text is unknown to CLD */ 11 | typealias LanguageCode = String 12 | 13 | /** 14 | * DetectedLanguage object that holds detected ISO language code and its percentage in the input 15 | string 16 | * @param percentage The percentage of the detected language 17 | */ 18 | class Languages( 19 | var language: LanguageCode, 20 | var percentage: Int 21 | ) 22 | 23 | /** 24 | * LanguageDetectionResult object that holds detected langugae reliability and array of 25 | DetectedLanguage 26 | * @param isReliable CLD detected language reliability 27 | * @param languages array of detectedLanguage 28 | */ 29 | class Result( 30 | var isReliable: Boolean, 31 | var languages: Array 32 | ) 33 | 34 | external class I18nNamespace { 35 | /** 36 | * Gets the accept-languages of the browser. This is different from the locale used by the 37 | browser; to get the locale, use $(ref:i18n.getUILanguage). 38 | */ 39 | fun getAcceptLanguages(): Promise> 40 | 41 | /** 42 | * Gets the localized string for the specified message. If the message is missing, this method 43 | returns an empty string (''). If the format of the getMessage() call is 44 | wrong — for example, messageName is not a string or the 45 | substitutions array has more than 9 elements — this method returns 46 | undefined. 47 | */ 48 | fun getMessage(messageName: String, substitutions: dynamic = definedExternally): String 49 | 50 | /** 51 | * Gets the browser UI language of the browser. This is different from 52 | $(ref:i18n.getAcceptLanguages) which returns the preferred user languages. 53 | */ 54 | fun getUILanguage(): String 55 | 56 | /** 57 | * Detects the language of the provided text using CLD. 58 | */ 59 | fun detectLanguage(text: String): Promise 60 | } 61 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/geckoProfiler/geckoProfiler.kt: -------------------------------------------------------------------------------- 1 | package geckoProfiler 2 | 3 | import kotlin.js.Promise 4 | import webextensions.Event 5 | 6 | typealias ProfilerFeature = String 7 | 8 | typealias supports = String 9 | 10 | /** 11 | * @param bufferSize The maximum size in bytes of the buffer used to store profiling data. A larger 12 | value allows capturing a profile that covers a greater amount of time. 13 | * @param windowLength The length of the window of time that's kept in the buffer. Any collected 14 | samples are discarded as soon as they are older than the number of seconds specified in this 15 | setting. Zero means no duration restriction. 16 | * @param interval Interval in milliseconds between samples of profiling data. A smaller value will 17 | increase the detail of the profiles captured. 18 | * @param features A list of active features for the profiler. 19 | * @param threads A list of thread names for which to capture profiles. 20 | */ 21 | class Settings( 22 | var bufferSize: Int, 23 | var windowLength: Float? = null, 24 | var interval: Float, 25 | var features: Array, 26 | var threads: Array? = null 27 | ) 28 | 29 | external class GeckoProfilerNamespace { 30 | /** 31 | * Fires when the profiler starts/stops running. 32 | * 33 | * @param isRunning Whether the profiler is running or not. Pausing the profiler will not affect 34 | this value. */ 35 | val onRunning: Event<(isRunning: Boolean) -> Unit> 36 | 37 | /** 38 | * Starts the profiler with the specified settings. 39 | */ 40 | fun start(settings: Settings): Promise 41 | 42 | /** 43 | * Stops the profiler and discards any captured profile data. 44 | */ 45 | fun stop(): Promise 46 | 47 | /** 48 | * Pauses the profiler, keeping any profile data that is already written. 49 | */ 50 | fun pause(): Promise 51 | 52 | /** 53 | * Resumes the profiler with the settings that were initially used to start it. 54 | */ 55 | fun resume(): Promise 56 | 57 | /** 58 | * Gathers the profile data from the current profiling session. 59 | */ 60 | fun getProfile(): Promise 61 | 62 | /** 63 | * Gathers the profile data from the current profiling session. The returned promise resolves to 64 | an array buffer that contains a JSON string. 65 | */ 66 | fun getProfileAsArrayBuffer(): Promise 67 | 68 | /** 69 | * Gets the debug symbols for a particular library. 70 | */ 71 | fun getSymbols(debugName: String, breakpadId: String): Promise 72 | } 73 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/alarms/alarms.kt: -------------------------------------------------------------------------------- 1 | package alarms 2 | 3 | import kotlin.js.Promise 4 | import webextensions.Event 5 | 6 | /** 7 | * @param name Name of this alarm. 8 | * @param scheduledTime Time when the alarm is scheduled to fire, in milliseconds past the epoch. 9 | * @param periodInMinutes When present, signals that the alarm triggers periodically after so many 10 | minutes. 11 | */ 12 | class Alarm( 13 | var name: String, 14 | var scheduledTime: Float, 15 | var periodInMinutes: Float? = null 16 | ) 17 | 18 | /** 19 | * Details about the alarm. The alarm first fires either at 'when' milliseconds past the epoch (if 20 | 'when' is provided), after 'delayInMinutes' minutes from the current time (if 21 | 'delayInMinutes' is provided instead), or after 'periodInMinutes' minutes from the current 22 | time (if only 'periodInMinutes' is provided). Users should never provide both 'when' and 23 | 'delayInMinutes'. If 'periodInMinutes' is provided, then the alarm recurs repeatedly after 24 | that many minutes. 25 | * @param when Time when the alarm is scheduled to first fire, in milliseconds past the epoch. 26 | * @param delayInMinutes Number of minutes from the current time after which the alarm should first 27 | fire. 28 | * @param periodInMinutes Number of minutes after which the alarm should recur repeatedly. 29 | */ 30 | class AlarmInfo( 31 | var `when`: Float? = null, 32 | var delayInMinutes: Float? = null, 33 | var periodInMinutes: Float? = null 34 | ) 35 | 36 | external class AlarmsNamespace { 37 | /** 38 | * Fired when an alarm has expired. Useful for transient background pages. 39 | * 40 | * @param name The alarm that has expired. */ 41 | val onAlarm: Event<(name: Alarm) -> Unit> 42 | 43 | /** 44 | * Creates an alarm. After the delay is expired, the onAlarm event is fired. If there is another 45 | alarm with the same name (or no name if none is specified), it will be cancelled and 46 | replaced by this alarm. 47 | */ 48 | fun create(name: String? = definedExternally, alarmInfo: AlarmInfo) 49 | 50 | /** 51 | * Retrieves details about the specified alarm. 52 | */ 53 | fun get(name: String? = definedExternally): Promise 54 | 55 | /** 56 | * Gets an array of all the alarms. 57 | */ 58 | fun getAll(): Promise> 59 | 60 | /** 61 | * Clears the alarm with the given name. 62 | */ 63 | fun clear(name: String? = definedExternally): Promise 64 | 65 | /** 66 | * Clears all alarms. 67 | */ 68 | fun clearAll(): Promise 69 | } 70 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/extensionTypes/extensionTypes.kt: -------------------------------------------------------------------------------- 1 | package extensionTypes 2 | 3 | /** 4 | * The format of an image. */ 5 | typealias ImageFormat = String 6 | 7 | /** 8 | * Details about the format and quality of an image. 9 | * @param format The format of the resulting image. Default is "jpeg". 10 | * @param quality When format is "jpeg", controls the quality of the resulting image. 11 | This value is ignored for PNG images. As quality is decreased, the resulting image will 12 | have more visual artifacts, and the number of bytes needed to store it will decrease. 13 | */ 14 | class ImageDetails( 15 | var format: ImageFormat? = null, 16 | var quality: Int? = null 17 | ) 18 | 19 | /** 20 | * The soonest that the JavaScript or CSS will be injected into the tab. */ 21 | typealias RunAt = String 22 | 23 | /** 24 | * The origin of the CSS to inject, this affects the cascading order (priority) of the stylesheet. 25 | */ 26 | typealias CSSOrigin = String 27 | 28 | /** 29 | * Details of the script or CSS to inject. Either the code or the file property must be set, but 30 | both may not be set at the same time. 31 | * @param code JavaScript or CSS code to inject.

Warning:
Be careful using the 32 | code parameter. Incorrect use of it may open your extension to cross site scripting attacks. 34 | * @param file JavaScript or CSS file to inject. 35 | * @param allFrames If allFrames is true, implies that the JavaScript or CSS should be 36 | injected into all frames of current page. By default, it's false and is only 37 | injected into the top frame. 38 | * @param matchAboutBlank If matchAboutBlank is true, then the code is also injected in about:blank 39 | and about:srcdoc frames if your extension has access to its parent document. Code cannot be 40 | inserted in top-level about:-frames. By default it is false. 41 | * @param frameId The ID of the frame to inject the script into. This may not be used in combination 42 | with allFrames. 43 | * @param runAt The soonest that the JavaScript or CSS will be injected into the tab. Defaults to 44 | "document_idle". 45 | * @param cssOrigin The css origin of the stylesheet to inject. Defaults to "author". 46 | */ 47 | class InjectDetails( 48 | var code: String? = null, 49 | var file: String? = null, 50 | var allFrames: Boolean? = null, 51 | var matchAboutBlank: Boolean? = null, 52 | var frameId: Int? = null, 53 | var runAt: RunAt? = null, 54 | var cssOrigin: CSSOrigin? = null 55 | ) 56 | 57 | typealias Date = Any 58 | 59 | typealias ExtensionFileOrCode = Any 60 | 61 | /** 62 | * A plain JSON value */ 63 | typealias PlainJSONValue = Any 64 | 65 | external class ExtensionTypesNamespace 66 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/userScripts/userScripts.kt: -------------------------------------------------------------------------------- 1 | package userScripts 2 | 3 | import extensionTypes.ExtensionFileOrCode 4 | import extensionTypes.PlainJSONValue 5 | import extensionTypes.RunAt 6 | import kotlin.js.Promise 7 | import manifest.MatchPattern 8 | import webextensions.Event 9 | 10 | /** 11 | * Details of a user script 12 | * @param js The list of JS files to inject 13 | * @param scriptMetadata An opaque user script metadata value 14 | * @param allFrames If allFrames is true, implies that the JavaScript should be 15 | injected into all frames of current page. By default, it's false and is only 16 | injected into the top frame. 17 | * @param matchAboutBlank If matchAboutBlank is true, then the code is also injected in about:blank 18 | and about:srcdoc frames if your extension has access to its parent document. Code cannot be 19 | inserted in top-level about:-frames. By default it is false. 20 | * @param runAt The soonest that the JavaScript will be injected into the tab. Defaults to 21 | "document_idle". 22 | */ 23 | class UserScriptOptions( 24 | var js: Array? = null, 25 | var scriptMetadata: PlainJSONValue? = null, 26 | var matches: Array, 27 | var excludeMatches: Array? = null, 28 | var includeGlobs: Array? = null, 29 | var excludeGlobs: Array? = null, 30 | var allFrames: Boolean? = null, 31 | var matchAboutBlank: Boolean? = null, 32 | var runAt: RunAt? = null 33 | ) 34 | 35 | /** 36 | * An object that represents a user script registered programmatically 37 | */ 38 | external class RegisteredUserScript { 39 | /** 40 | * Unregister a user script registered programmatically 41 | */ 42 | fun unregister(): Promise 43 | } 44 | 45 | /** 46 | * A plain object whose properties are exported as userScript globals */ 47 | typealias SourceObject = Any 48 | 49 | /** 50 | * @param metadata The userScript metadata (as set in userScripts.register) 51 | * @param global The userScript global 52 | * @param defineGlobals Exports all the properties of a given plain object as userScript globals 53 | * @param export Convert a given value to make it accessible to the userScript code 54 | */ 55 | class UserScript( 56 | var metadata: dynamic, 57 | var global: dynamic, 58 | var defineGlobals: () -> Unit, 59 | var export: () -> Unit 60 | ) 61 | 62 | external class UserScriptsNamespace { 63 | /** 64 | * Event called when a new userScript global has been created 65 | * 66 | * @param userScript null */ 67 | val onBeforeScript: Event<(userScript: UserScript) -> Unit> 68 | 69 | /** 70 | * Register a user script programmatically given its $(ref:userScripts.UserScriptOptions), and 71 | resolves to a $(ref:userScripts.RegisteredUserScript) instance 72 | */ 73 | fun register(userScriptOptions: UserScriptOptions): Promise 74 | } 75 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/browserSettings/browserSettings.kt: -------------------------------------------------------------------------------- 1 | package browserSettings 2 | 3 | import types.Setting 4 | 5 | /** 6 | * How images should be animated in the browser. */ 7 | typealias ImageAnimationBehavior = String 8 | 9 | /** 10 | * After which mouse event context menus should popup. */ 11 | typealias ContextMenuMouseEvent = String 12 | 13 | external class BrowserSettingsNamespace { 14 | /** 15 | * Allows or disallows pop-up windows from opening in response to user events. 16 | */ 17 | var allowPopupsForUserEvents: Setting 18 | 19 | /** 20 | * Enables or disables the browser cache. 21 | */ 22 | var cacheEnabled: Setting 23 | 24 | /** 25 | * This boolean setting controls whether the selected tab can be closed with a double click. 26 | */ 27 | var closeTabsByDoubleClick: Setting 28 | 29 | /** 30 | * Controls after which mouse event context menus popup. This setting's value is of type 31 | ContextMenuMouseEvent, which has possible values of mouseup and 32 | mousedown. 33 | */ 34 | var contextMenuShowEvent: Setting 35 | 36 | /** 37 | * Returns the value of the overridden home page. Read-only. 38 | */ 39 | var homepageOverride: Setting 40 | 41 | /** 42 | * Controls the behaviour of image animation in the browser. This setting's value is of type 43 | ImageAnimationBehavior, defaulting to normal. 44 | */ 45 | var imageAnimationBehavior: Setting 46 | 47 | /** 48 | * Returns the value of the overridden new tab page. Read-only. 49 | */ 50 | var newTabPageOverride: Setting 51 | 52 | /** 53 | * Controls where new tabs are opened. `afterCurrent` will open all new tabs next to the current 54 | tab, `relatedAfterCurrent` will open only related tabs next to the current tab, and 55 | `atEnd` will open all tabs at the end of the tab strip. The default is 56 | `relatedAfterCurrent`. 57 | */ 58 | var newTabPosition: Setting 59 | 60 | /** 61 | * This boolean setting controls whether bookmarks are opened in the current tab or in a new 62 | tab. 63 | */ 64 | var openBookmarksInNewTabs: Setting 65 | 66 | /** 67 | * This boolean setting controls whether search results are opened in the current tab or in a 68 | new tab. 69 | */ 70 | var openSearchResultsInNewTabs: Setting 71 | 72 | /** 73 | * This boolean setting controls whether urlbar results are opened in the current tab or in a 74 | new tab. 75 | */ 76 | var openUrlbarResultsInNewTabs: Setting 77 | 78 | /** 79 | * Disables webAPI notifications. 80 | */ 81 | var webNotificationsDisabled: Setting 82 | 83 | /** 84 | * This setting controls whether the user-chosen colors override the page's colors. 85 | */ 86 | var overrideDocumentColors: Setting 87 | 88 | /** 89 | * This setting controls whether the document's fonts are used. 90 | */ 91 | var useDocumentFonts: Setting 92 | } 93 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/types/types.kt: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import kotlin.js.Promise 4 | 5 | /** 6 | * Which setting to consider. 7 | * @param incognito Whether to return the value that applies to the incognito session (default 8 | false). 9 | */ 10 | class Details( 11 | var incognito: Boolean? = null 12 | ) 13 | 14 | /** 15 | * Details of the currently effective value. 16 | * @param value The value of the setting. 17 | * @param levelOfControl The level of control of the setting. 18 | * @param incognitoSpecific Whether the effective value is specific to the incognito 19 | session.
This property will only be present if the incognito 20 | property in the details parameter of get() was true. 21 | */ 22 | class Details2( 23 | var value: dynamic, 24 | var levelOfControl: LevelOfControl, 25 | var incognitoSpecific: Boolean? = null 26 | ) 27 | 28 | /** 29 | * Which setting to change. 30 | * @param value The value of the setting.
Note that every setting has a specific value type, 31 | which is described together with the setting. An extension should not set a value 32 | of a different type. 33 | * @param scope Where to set the setting (default: regular). 34 | */ 35 | class Details3( 36 | var value: dynamic, 37 | var scope: SettingScope? = null 38 | ) 39 | 40 | /** 41 | * Which setting to clear. 42 | * @param scope Where to clear the setting (default: regular). 43 | */ 44 | class Details4( 45 | var scope: SettingScope? = null 46 | ) 47 | 48 | /** 49 | * The scope of the Setting. One of
  • regular: setting for the regular profile 50 | (which is inherited by the incognito profile if not overridden 51 | elsewhere),
  • regular_only: setting for the regular profile only (not 52 | inherited by the incognito profile),
  • incognito_persistent: setting for 53 | the incognito profile that survives browser restarts (overrides regular 54 | preferences),
  • incognito_session_only: setting for the incognito profile 55 | that can only be set during an incognito session and is deleted when the incognito session 56 | ends (overrides regular and incognito_persistent preferences).
Only 57 | regular is supported by Firefox at this time. */ 58 | typealias SettingScope = String 59 | 60 | /** 61 | * One of
  • not_controllable: cannot be controlled by any 62 | extension
  • controlled_by_other_extensions: controlled by extensions with 63 | higher precedence
  • controllable_by_this_extension: can be controlled by 64 | this extension
  • controlled_by_this_extension: controlled by this 65 | extension
*/ 66 | typealias LevelOfControl = String 67 | 68 | external class Setting { 69 | /** 70 | * Gets the value of a setting. 71 | */ 72 | fun get(details: Details): Promise 73 | 74 | /** 75 | * Sets the value of a setting. 76 | */ 77 | fun set(details: Details3): Promise 78 | 79 | /** 80 | * Clears the setting, restoring any default value. 81 | */ 82 | fun clear(details: Details4): Promise 83 | } 84 | 85 | external class TypesNamespace 86 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/extension/extension.kt: -------------------------------------------------------------------------------- 1 | package extension 2 | 3 | import kotlin.Suppress 4 | import kotlin.js.Promise 5 | 6 | /** 7 | * The type of extension view. */ 8 | typealias ViewType = String 9 | 10 | /** 11 | * Set for the lifetime of a callback if an ansychronous extension api has resulted in an error. If 12 | no error has occured lastError will be undefined. 13 | * @param message Description of the error that has taken place. 14 | */ 15 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 16 | class LastError( 17 | var message: String 18 | ) { 19 | inline operator fun get(key: String): dynamic = asDynamic()[key] 20 | inline operator fun set(key: String, value: dynamic) { 21 | asDynamic()[key] = value 22 | } 23 | } 24 | 25 | /** 26 | * @param type The type of view to get. If omitted, returns all views (including background pages 27 | and tabs). Valid values: 'tab', 'popup', 'sidebar'. 28 | * @param windowId The window to restrict the search to. If omitted, returns all views. 29 | * @param tabId Find a view according to a tab id. If this field is omitted, returns all views. 30 | */ 31 | class FetchProperties( 32 | var type: ViewType? = null, 33 | var windowId: Int? = null, 34 | var tabId: Int? = null 35 | ) 36 | 37 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 38 | class GetViewsResult() { 39 | inline operator fun get(key: String): dynamic = asDynamic()[key] 40 | inline operator fun set(key: String, value: dynamic) { 41 | asDynamic()[key] = value 42 | } 43 | } 44 | 45 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 46 | class GetBackgroundPageResult() { 47 | inline operator fun get(key: String): dynamic = asDynamic()[key] 48 | inline operator fun set(key: String, value: dynamic) { 49 | asDynamic()[key] = value 50 | } 51 | } 52 | 53 | external class ExtensionNamespace { 54 | /** 55 | * Set for the lifetime of a callback if an ansychronous extension api has resulted in an error. 56 | If no error has occured lastError will be undefined. 57 | */ 58 | var lastError: LastError? 59 | 60 | /** 61 | * True for content scripts running inside incognito tabs, and for extension pages running 62 | inside an incognito process. The latter only applies to extensions with 'split' 63 | incognito_behavior. 64 | */ 65 | var inIncognitoContext: Boolean? 66 | 67 | /** 68 | * Converts a relative path within an extension install directory to a fully-qualified URL. 69 | */ 70 | fun getURL(path: String): String 71 | 72 | /** 73 | * Returns an array of the JavaScript 'window' objects for each of the pages running inside the 74 | current extension. 75 | */ 76 | fun getViews(fetchProperties: FetchProperties? = definedExternally): Array 77 | 78 | /** 79 | * Returns the JavaScript 'window' object for the background page running inside the current 80 | extension. Returns null if the extension has no background page. 81 | */ 82 | fun getBackgroundPage(): GetBackgroundPageResult? 83 | 84 | /** 85 | * Retrieves the state of the extension's access to Incognito-mode (as determined by the 86 | user-controlled 'Allowed in Incognito' checkbox. 87 | */ 88 | fun isAllowedIncognitoAccess(): Promise 89 | 90 | /** 91 | * Retrieves the state of the extension's access to the 'file://' scheme (as determined by the 92 | user-controlled 'Allow access to File URLs' checkbox. 93 | */ 94 | fun isAllowedFileSchemeAccess(): Promise 95 | } 96 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/sessions/sessions.kt: -------------------------------------------------------------------------------- 1 | package sessions 2 | 3 | import kotlin.js.Promise 4 | import tabs.Tab 5 | import webextensions.Event 6 | import windows.Window 7 | 8 | /** 9 | * @param maxResults The maximum number of entries to be fetched in the requested list. Omit this 10 | parameter to fetch the maximum number of entries ($(ref:sessions.MAX_SESSION_RESULTS)). 11 | */ 12 | class Filter( 13 | var maxResults: Int? = null 14 | ) 15 | 16 | /** 17 | * @param lastModified The time when the window or tab was closed or modified, represented in 18 | milliseconds since the epoch. 19 | * @param tab The $(ref:tabs.Tab), if this entry describes a tab. Either this or 20 | $(ref:sessions.Session.window) will be set. 21 | * @param window The $(ref:windows.Window), if this entry describes a window. Either this or 22 | $(ref:sessions.Session.tab) will be set. 23 | */ 24 | class Session( 25 | var lastModified: Int, 26 | var tab: Tab? = null, 27 | var window: Window? = null 28 | ) 29 | 30 | /** 31 | * @param deviceName The name of the foreign device. 32 | * @param sessions A list of open window sessions for the foreign device, sorted from most recently 33 | to least recently modified session. 34 | */ 35 | class Device( 36 | var info: String, 37 | var deviceName: String, 38 | var sessions: Array 39 | ) 40 | 41 | external class SessionsNamespace { 42 | /** 43 | * Fired when recently closed tabs and/or windows are changed. This event does not monitor 44 | synced sessions changes. 45 | */ 46 | val onChanged: Event<() -> Unit> 47 | 48 | /** 49 | * The maximum number of $(ref:sessions.Session) that will be included in a requested list. 50 | */ 51 | var MAX_SESSION_RESULTS: Double 52 | 53 | /** 54 | * Forget a recently closed tab. 55 | */ 56 | fun forgetClosedTab(windowId: Int, sessionId: String): Promise 57 | 58 | /** 59 | * Forget a recently closed window. 60 | */ 61 | fun forgetClosedWindow(sessionId: String): Promise 62 | 63 | /** 64 | * Gets the list of recently closed tabs and/or windows. 65 | */ 66 | fun getRecentlyClosed(filter: Filter? = definedExternally): Promise> 67 | 68 | /** 69 | * Reopens a $(ref:windows.Window) or $(ref:tabs.Tab), with an optional callback to run when the 70 | entry has been restored. 71 | */ 72 | fun restore(sessionId: String? = definedExternally): Promise 73 | 74 | /** 75 | * Set a key/value pair on a given tab. 76 | */ 77 | fun setTabValue( 78 | tabId: Int, 79 | key: String, 80 | value: dynamic 81 | ): Promise 82 | 83 | /** 84 | * Retrieve a value that was set for a given key on a given tab. 85 | */ 86 | fun getTabValue(tabId: Int, key: String): Promise 87 | 88 | /** 89 | * Remove a key/value pair that was set on a given tab. 90 | */ 91 | fun removeTabValue(tabId: Int, key: String): Promise 92 | 93 | /** 94 | * Set a key/value pair on a given window. 95 | */ 96 | fun setWindowValue( 97 | windowId: Int, 98 | key: String, 99 | value: dynamic 100 | ): Promise 101 | 102 | /** 103 | * Retrieve a value that was set for a given key on a given window. 104 | */ 105 | fun getWindowValue(windowId: Int, key: String): Promise 106 | 107 | /** 108 | * Remove a key/value pair that was set on a given window. 109 | */ 110 | fun removeWindowValue(windowId: Int, key: String): Promise 111 | } 112 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/contextualIdentities/contextualIdentities.kt: -------------------------------------------------------------------------------- 1 | package contextualIdentities 2 | 3 | import kotlin.js.Promise 4 | import webextensions.Event 5 | 6 | /** 7 | * Represents information about a contextual identity. 8 | * @param name The name of the contextual identity. 9 | * @param icon The icon name of the contextual identity. 10 | * @param iconUrl The icon url of the contextual identity. 11 | * @param color The color name of the contextual identity. 12 | * @param colorCode The color hash of the contextual identity. 13 | * @param cookieStoreId The cookie store ID of the contextual identity. 14 | */ 15 | class ContextualIdentity( 16 | var name: String, 17 | var icon: String, 18 | var iconUrl: String, 19 | var color: String, 20 | var colorCode: String, 21 | var cookieStoreId: String 22 | ) 23 | 24 | /** 25 | * Information to filter the contextual identities being retrieved. 26 | * @param name Filters the contextual identity by name. 27 | */ 28 | class Details( 29 | var name: String? = null 30 | ) 31 | 32 | /** 33 | * Details about the contextual identity being created. 34 | * @param name The name of the contextual identity. 35 | * @param color The color of the contextual identity. 36 | * @param icon The icon of the contextual identity. 37 | */ 38 | class Details2( 39 | var name: String, 40 | var color: String, 41 | var icon: String 42 | ) 43 | 44 | /** 45 | * Details about the contextual identity being created. 46 | * @param name The name of the contextual identity. 47 | * @param color The color of the contextual identity. 48 | * @param icon The icon of the contextual identity. 49 | */ 50 | class Details3( 51 | var name: String? = null, 52 | var color: String? = null, 53 | var icon: String? = null 54 | ) 55 | 56 | /** 57 | * @param contextualIdentity Contextual identity that has been updated 58 | */ 59 | class ChangeInfo( 60 | var contextualIdentity: ContextualIdentity 61 | ) 62 | 63 | /** 64 | * @param contextualIdentity Contextual identity that has been created 65 | */ 66 | class ChangeInfo2( 67 | var contextualIdentity: ContextualIdentity 68 | ) 69 | 70 | /** 71 | * @param contextualIdentity Contextual identity that has been removed 72 | */ 73 | class ChangeInfo3( 74 | var contextualIdentity: ContextualIdentity 75 | ) 76 | 77 | external class ContextualIdentitiesNamespace { 78 | /** 79 | * Fired when a container is updated. 80 | * 81 | * @param changeInfo null */ 82 | val onUpdated: Event<(changeInfo: ChangeInfo) -> Unit> 83 | 84 | /** 85 | * Fired when a new container is created. 86 | * 87 | * @param changeInfo null */ 88 | val onCreated: Event<(changeInfo: ChangeInfo2) -> Unit> 89 | 90 | /** 91 | * Fired when a container is removed. 92 | * 93 | * @param changeInfo null */ 94 | val onRemoved: Event<(changeInfo: ChangeInfo3) -> Unit> 95 | 96 | /** 97 | * Retrieves information about a single contextual identity. 98 | */ 99 | fun get(cookieStoreId: String): Promise 100 | 101 | /** 102 | * Retrieves all contextual identities 103 | */ 104 | fun query(details: Details): Promise 105 | 106 | /** 107 | * Creates a contextual identity with the given data. 108 | */ 109 | fun create(details: Details2): Promise 110 | 111 | /** 112 | * Updates a contextual identity with the given data. 113 | */ 114 | fun update(cookieStoreId: String, details: Details3): Promise 115 | 116 | /** 117 | * Deletes a contetual identity by its cookie Store ID. 118 | */ 119 | fun remove(cookieStoreId: String): Promise 120 | } 121 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/omnibox/omnibox.kt: -------------------------------------------------------------------------------- 1 | package omnibox 2 | 3 | import webextensions.Event 4 | 5 | /** 6 | * The style type. */ 7 | typealias DescriptionStyleType = String 8 | 9 | /** 10 | * The window disposition for the omnibox query. This is the recommended context to display results. 11 | For example, if the omnibox command is to navigate to a certain URL, a disposition of 12 | 'newForegroundTab' means the navigation should take place in a new selected tab. */ 13 | typealias OnInputEnteredDisposition = String 14 | 15 | /** 16 | * A suggest result. 17 | * @param content The text that is put into the URL bar, and that is sent to the extension when the 18 | user chooses this entry. 19 | * @param description The text that is displayed in the URL dropdown. Can contain XML-style markup 20 | for styling. The supported tags are 'url' (for a literal URL), 'match' (for highlighting 21 | text that matched what the user's query), and 'dim' (for dim helper text). The styles can be 22 | nested, eg. dimmed match. You must escape the five predefined 23 | entities to display them as text: stackoverflow.com/a/1091953/89484 24 | */ 25 | class SuggestResult( 26 | var content: String, 27 | var description: String 28 | ) 29 | 30 | /** 31 | * A suggest result. 32 | * @param description The text that is displayed in the URL dropdown. 33 | */ 34 | class DefaultSuggestResult( 35 | var description: String 36 | ) 37 | 38 | /** 39 | * The style ranges for the description, as provided by the extension. 40 | * @param type The style type 41 | */ 42 | class DescriptionStyles( 43 | var offset: Int, 44 | var type: DescriptionStyleType, 45 | var length: Int? = null 46 | ) 47 | 48 | /** 49 | * The style ranges for the description, as provided by ToValue(). 50 | */ 51 | class DescriptionStylesRaw(var offset: Int, var type: Int) 52 | 53 | /** 54 | * The style ranges for the description, as provided by the extension. 55 | * @param type The style type 56 | */ 57 | class DescriptionStyles2( 58 | var offset: Int, 59 | var type: DescriptionStyleType, 60 | var length: Int? = null 61 | ) 62 | 63 | /** 64 | * The style ranges for the description, as provided by ToValue(). 65 | */ 66 | class DescriptionStylesRaw2(var offset: Int, var type: Int) 67 | 68 | external class OmniboxNamespace { 69 | /** 70 | * User has started a keyword input session by typing the extension's keyword. This is 71 | guaranteed to be sent exactly once per input session, and before any onInputChanged 72 | events. 73 | */ 74 | val onInputStarted: Event<() -> Unit> 75 | 76 | /** 77 | * User has changed what is typed into the omnibox. 78 | * 79 | * @param text null 80 | * @param suggest A callback passed to the onInputChanged event used for sending suggestions 81 | back to the browser. */ 82 | val onInputChanged: Event<(text: String, suggest: () -> Unit) -> Unit> 83 | 84 | /** 85 | * User has accepted what is typed into the omnibox. 86 | * 87 | * @param text null 88 | * @param disposition null */ 89 | val onInputEntered: Event<(text: String, disposition: OnInputEnteredDisposition) -> Unit> 90 | 91 | /** 92 | * User has ended the keyword input session without accepting the input. 93 | */ 94 | val onInputCancelled: Event<() -> Unit> 95 | 96 | /** 97 | * Sets the description and styling for the default suggestion. The default suggestion is the 98 | text that is displayed in the first suggestion row underneath the URL bar. 99 | */ 100 | fun setDefaultSuggestion(suggestion: DefaultSuggestResult) 101 | } 102 | -------------------------------------------------------------------------------- /src/main/kotlin/de/rakhman/webextensions/main.kt: -------------------------------------------------------------------------------- 1 | package de.rakhman.webextensions 2 | 3 | import com.beust.jcommander.JCommander 4 | import com.beust.jcommander.Parameter 5 | import com.google.gson.GsonBuilder 6 | import com.google.gson.reflect.TypeToken 7 | import de.rakhman.webextensions.serialization.ParameterAdapterFactory 8 | import org.eclipse.egit.github.core.client.GitHubClient 9 | import org.eclipse.egit.github.core.service.ContentsService 10 | import org.eclipse.egit.github.core.service.RepositoryService 11 | import org.eclipse.egit.github.core.util.EncodingUtils 12 | import java.io.ByteArrayInputStream 13 | import java.io.File 14 | import java.io.InputStream 15 | import java.io.InputStreamReader 16 | import java.nio.file.FileVisitOption 17 | import java.nio.file.Files 18 | import java.nio.file.Path 19 | 20 | fun main(args: Array) { 21 | 22 | val arguments = Args() 23 | JCommander.newBuilder() 24 | .addObject(arguments) 25 | .build() 26 | .parse(*args) 27 | 28 | val streams = when (SourceArg.valueOf(arguments.source)) { 29 | SourceArg.Github -> getFromGithub(arguments.apiToken) 30 | SourceArg.File -> getFromFiles(File(arguments.filePath)) 31 | } 32 | 33 | val gson = GsonBuilder() 34 | .registerTypeAdapterFactory(ParameterAdapterFactory()) 35 | .create() 36 | 37 | val type = object : TypeToken>() {}.type 38 | 39 | val list = streams 40 | .flatMap { 41 | InputStreamReader(it).use { reader -> 42 | gson.fromJson>(reader, type).asSequence() 43 | } 44 | } 45 | .toList() 46 | 47 | val dir = File(arguments.outputPath).apply { 48 | mkdirs() 49 | deleteRecursively() 50 | mkdir() 51 | } 52 | 53 | Generator(dir).generate(list) 54 | } 55 | 56 | class Args { 57 | @Parameter(names = ["-s", "--source"]) 58 | var source: String = SourceArg.Github.name 59 | 60 | @Parameter(names = ["--apiToken"], description = "Optional Github OAuth 2 API token. Not using a token can lead to hitting the quota limit quickly.") 61 | var apiToken: String? = null 62 | 63 | @Parameter(names = ["--filePath"], description = "Optional path to schema files. Default ist 'schemas'") 64 | var filePath: String? = "schemas" 65 | 66 | @Parameter(names = ["-o", "--outputPath"], description = "Optional path for output. Default is 'declarations/src/main/kotlin'") 67 | var outputPath: String? = "declarations/src/main/kotlin" 68 | } 69 | 70 | enum class SourceArg { 71 | Github, File 72 | } 73 | 74 | private fun File.deleteRecur() { 75 | Files.walk(this.toPath(), FileVisitOption.FOLLOW_LINKS) 76 | .sorted(Comparator.reverseOrder()) 77 | .map(Path::toFile) 78 | .forEach { it.delete() } 79 | } 80 | 81 | private fun getFromFiles(file: File): Sequence { 82 | return file 83 | .listFiles { f: File -> f.extension == "json" } 84 | .asSequence() 85 | .map { it.inputStream() } 86 | } 87 | 88 | private fun getFromGithub(token: String?): Sequence { 89 | val client = GitHubClient().apply { token?.let { setOAuth2Token(it) } } 90 | 91 | val repository = RepositoryService(client).getRepository("mozilla", "gecko-dev") 92 | 93 | val contentsService = ContentsService(client) 94 | 95 | val contents = 96 | contentsService.getContents(repository, "browser/components/extensions/schemas/") + 97 | contentsService.getContents(repository, "toolkit/components/extensions/schemas/") 98 | 99 | return contents 100 | .asSequence() 101 | .filter { it.name.endsWith(".json") } 102 | .flatMap { contentsService.getContents(repository, it.path).asSequence() } 103 | .map { ByteArrayInputStream(EncodingUtils.fromBase64(it.content)) } 104 | } 105 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/webextensions/browser.kt: -------------------------------------------------------------------------------- 1 | package webextensions 2 | 3 | import alarms.AlarmsNamespace 4 | import bookmarks.BookmarksNamespace 5 | import browserAction.BrowserActionNamespace 6 | import browserSettings.BrowserSettingsNamespace 7 | import browsingData.BrowsingDataNamespace 8 | import clipboard.ClipboardNamespace 9 | import commands.CommandsNamespace 10 | import contentScripts.ContentScriptsNamespace 11 | import contextMenus.ContextMenusNamespace 12 | import contextualIdentities.ContextualIdentitiesNamespace 13 | import cookies.CookiesNamespace 14 | import devtools.DevtoolsNamespace 15 | import dns.DnsNamespace 16 | import downloads.DownloadsNamespace 17 | import events.EventsNamespace 18 | import experiments.ExperimentsNamespace 19 | import extension.ExtensionNamespace 20 | import extensionTypes.ExtensionTypesNamespace 21 | import find.FindNamespace 22 | import geckoProfiler.GeckoProfilerNamespace 23 | import history.HistoryNamespace 24 | import i18n.I18nNamespace 25 | import identity.IdentityNamespace 26 | import idle.IdleNamespace 27 | import management.ManagementNamespace 28 | import manifest.ManifestNamespace 29 | import menus.MenusNamespace 30 | import notifications.NotificationsNamespace 31 | import omnibox.OmniboxNamespace 32 | import pageAction.PageActionNamespace 33 | import permissions.PermissionsNamespace 34 | import pkcs11.Pkcs11Namespace 35 | import privacy.PrivacyNamespace 36 | import proxy.ProxyNamespace 37 | import runtime.RuntimeNamespace 38 | import search.SearchNamespace 39 | import sessions.SessionsNamespace 40 | import sidebarAction.SidebarActionNamespace 41 | import storage.StorageNamespace 42 | import tabs.TabsNamespace 43 | import telemetry.TelemetryNamespace 44 | import test.TestNamespace 45 | import theme.ThemeNamespace 46 | import topSites.TopSitesNamespace 47 | import types.TypesNamespace 48 | import userScripts.UserScriptsNamespace 49 | import webNavigation.WebNavigationNamespace 50 | import webRequest.WebRequestNamespace 51 | import windows.WindowsNamespace 52 | 53 | external class Browser { 54 | val alarms: AlarmsNamespace 55 | 56 | val manifest: ManifestNamespace 57 | 58 | val bookmarks: BookmarksNamespace 59 | 60 | val browserAction: BrowserActionNamespace 61 | 62 | val browserSettings: BrowserSettingsNamespace 63 | 64 | val browsingData: BrowsingDataNamespace 65 | 66 | val clipboard: ClipboardNamespace 67 | 68 | val commands: CommandsNamespace 69 | 70 | val contentScripts: ContentScriptsNamespace 71 | 72 | val contextualIdentities: ContextualIdentitiesNamespace 73 | 74 | val cookies: CookiesNamespace 75 | 76 | val devtools: DevtoolsNamespace 77 | 78 | val dns: DnsNamespace 79 | 80 | val downloads: DownloadsNamespace 81 | 82 | val events: EventsNamespace 83 | 84 | val experiments: ExperimentsNamespace 85 | 86 | val extension: ExtensionNamespace 87 | 88 | val extensionTypes: ExtensionTypesNamespace 89 | 90 | val find: FindNamespace 91 | 92 | val geckoProfiler: GeckoProfilerNamespace 93 | 94 | val history: HistoryNamespace 95 | 96 | val i18n: I18nNamespace 97 | 98 | val identity: IdentityNamespace 99 | 100 | val idle: IdleNamespace 101 | 102 | val management: ManagementNamespace 103 | 104 | val contextMenus: ContextMenusNamespace 105 | 106 | val menus: MenusNamespace 107 | 108 | val notifications: NotificationsNamespace 109 | 110 | val omnibox: OmniboxNamespace 111 | 112 | val pageAction: PageActionNamespace 113 | 114 | val permissions: PermissionsNamespace 115 | 116 | val pkcs11: Pkcs11Namespace 117 | 118 | val privacy: PrivacyNamespace 119 | 120 | val proxy: ProxyNamespace 121 | 122 | val runtime: RuntimeNamespace 123 | 124 | val search: SearchNamespace 125 | 126 | val sessions: SessionsNamespace 127 | 128 | val sidebarAction: SidebarActionNamespace 129 | 130 | val storage: StorageNamespace 131 | 132 | val tabs: TabsNamespace 133 | 134 | val telemetry: TelemetryNamespace 135 | 136 | val test: TestNamespace 137 | 138 | val theme: ThemeNamespace 139 | 140 | val topSites: TopSitesNamespace 141 | 142 | val types: TypesNamespace 143 | 144 | val userScripts: UserScriptsNamespace 145 | 146 | val webNavigation: WebNavigationNamespace 147 | 148 | val webRequest: WebRequestNamespace 149 | 150 | val windows: WindowsNamespace 151 | } 152 | 153 | external class Event { 154 | fun addListener(listener: T) 155 | 156 | fun removeListener(listener: T) 157 | 158 | fun hasListener(listener: T): Boolean 159 | } 160 | 161 | external val browser: Browser 162 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/privacy/privacy.kt: -------------------------------------------------------------------------------- 1 | package privacy 2 | 3 | import types.Setting 4 | 5 | /** 6 | * The IP handling policy of WebRTC. */ 7 | typealias IPHandlingPolicy = String 8 | 9 | external class NetworkNamespace { 10 | /** 11 | * If enabled, the browser attempts to speed up your web browsing experience by pre-resolving 12 | DNS entries, prerendering sites (<link rel='prefetch' ...>), and 13 | preemptively opening TCP and SSL connections to servers. This preference's value is a 14 | boolean, defaulting to true. 15 | */ 16 | var networkPredictionEnabled: Setting 17 | 18 | /** 19 | * Allow users to enable and disable RTCPeerConnections (aka WebRTC). 20 | */ 21 | var peerConnectionEnabled: Setting 22 | 23 | /** 24 | * Allow users to specify the media performance/privacy tradeoffs which impacts how WebRTC 25 | traffic will be routed and how much local address information is exposed. This 26 | preference's value is of type IPHandlingPolicy, defaulting to default. 27 | */ 28 | var webRTCIPHandlingPolicy: Setting 29 | } 30 | 31 | external class ServicesNamespace { 32 | /** 33 | * If enabled, the password manager will ask if you want to save passwords. This preference's 34 | value is a boolean, defaulting to true. 35 | */ 36 | var passwordSavingEnabled: Setting 37 | } 38 | 39 | /** 40 | * The mode for tracking protection. */ 41 | typealias TrackingProtectionModeOption = String 42 | 43 | /** 44 | * The settings for cookies. 45 | * @param behavior The type of cookies to allow. 46 | * @param nonPersistentCookies Whether to create all cookies as nonPersistent (i.e., session) 47 | cookies. 48 | */ 49 | class CookieConfig( 50 | var behavior: String? = null, 51 | var nonPersistentCookies: Boolean? = null 52 | ) 53 | 54 | external class WebsitesNamespace { 55 | /** 56 | * If enabled, the browser sends auditing pings when requested by a website (<a 57 | ping>). The value of this preference is of type boolean, and the default value 58 | is true. 59 | */ 60 | var hyperlinkAuditingEnabled: Setting 61 | 62 | /** 63 | * If enabled, the browser sends referer headers with your requests. Yes, the name 64 | of this preference doesn't match the misspelled header. No, we're not going to change 65 | it. The value of this preference is of type boolean, and the default value is 66 | true. 67 | */ 68 | var referrersEnabled: Setting 69 | 70 | /** 71 | * If enabled, the browser attempts to appear similar to other users by reporting generic 72 | information to websites. This can prevent websites from uniquely identifying users. 73 | Examples of data that is spoofed include number of CPU cores, precision of JavaScript 74 | timers, the local timezone, and disabling features such as GamePad support, and the 75 | WebSpeech and Navigator APIs. The value of this preference is of type boolean, and the 76 | default value is false. 77 | */ 78 | var resistFingerprinting: Setting 79 | 80 | /** 81 | * If enabled, the browser will associate all data (including cookies, HSTS data, cached images, 82 | and more) for any third party domains with the domain in the address bar. This prevents 83 | third party trackers from using directly stored information to identify you across 84 | different websites, but may break websites where you login with a third party account 85 | (such as a Facebook or Google login.) The value of this preference is of type boolean, 86 | and the default value is false. 87 | */ 88 | var firstPartyIsolate: Setting 89 | 90 | /** 91 | * Allow users to specify the mode for tracking protection. This setting's value is of type 92 | TrackingProtectionModeOption, defaulting to private_browsing_only. 93 | */ 94 | var trackingProtectionMode: Setting 95 | 96 | /** 97 | * Allow users to specify the default settings for allowing cookies, as well as whether all 98 | cookies should be created as non-persistent cookies. This setting's value is of type 99 | CookieConfig. 100 | */ 101 | var cookieConfig: Setting 102 | } 103 | 104 | external class PrivacyNamespace { 105 | val network: NetworkNamespace 106 | 107 | val services: ServicesNamespace 108 | 109 | val websites: WebsitesNamespace 110 | } 111 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/proxy/proxy.kt: -------------------------------------------------------------------------------- 1 | package proxy 2 | 3 | import kotlin.Deprecated 4 | import kotlin.js.Promise 5 | import types.Setting 6 | import webRequest.HttpHeaders 7 | import webRequest.ResourceType 8 | import webextensions.Event 9 | 10 | /** 11 | * An object which describes proxy settings. 12 | * @param proxyType The type of proxy to use. 13 | * @param http The address of the http proxy, can include a port. 14 | * @param httpProxyAll Use the http proxy server for all protocols. 15 | * @param ftp The address of the ftp proxy, can include a port. 16 | * @param ssl The address of the ssl proxy, can include a port. 17 | * @param socks The address of the socks proxy, can include a port. 18 | * @param socksVersion The version of the socks proxy. 19 | * @param passthrough A list of hosts which should not be proxied. 20 | * @param autoConfigUrl A URL to use to configure the proxy. 21 | * @param autoLogin Do not prompt for authentication if password is saved. 22 | * @param proxyDNS Proxy DNS when using SOCKS v5. 23 | */ 24 | class ProxyConfig( 25 | var proxyType: String? = null, 26 | var http: String? = null, 27 | var httpProxyAll: Boolean? = null, 28 | var ftp: String? = null, 29 | var ssl: String? = null, 30 | var socks: String? = null, 31 | var socksVersion: Int? = null, 32 | var passthrough: String? = null, 33 | var autoConfigUrl: String? = null, 34 | var autoLogin: Boolean? = null, 35 | var proxyDNS: Boolean? = null 36 | ) 37 | 38 | /** 39 | * @param requestId The ID of the request. Request IDs are unique within a browser session. As a 40 | result, they could be used to relate different events of the same request. 41 | * @param method Standard HTTP method. 42 | * @param frameId The value 0 indicates that the request happens in the main frame; a positive value 43 | indicates the ID of a subframe in which the request happens. If the document of a 44 | (sub-)frame is loaded (type is main_frame or 45 | sub_frame), frameId indicates the ID of this frame, not the ID of 46 | the outer frame. Frame IDs are unique within a tab. 47 | * @param parentFrameId ID of frame that wraps the frame which sent the request. Set to -1 if no 48 | parent frame exists. 49 | * @param originUrl URL of the resource that triggered this request. 50 | * @param documentUrl URL of the page into which the requested resource will be loaded. 51 | * @param tabId The ID of the tab in which the request takes place. Set to -1 if the request isn't 52 | related to a tab. 53 | * @param type How the requested resource will be used. 54 | * @param timeStamp The time when this signal is triggered, in milliseconds since the epoch. 55 | * @param ip The server IP address that the request was actually sent to. Note that it may be a 56 | literal IPv6 address. 57 | * @param fromCache Indicates if this response was fetched from disk cache. 58 | * @param requestHeaders The HTTP request headers that are going to be sent out with this request. 59 | */ 60 | class Details( 61 | var requestId: String, 62 | var url: String, 63 | var method: String, 64 | var frameId: Int, 65 | var parentFrameId: Int, 66 | var originUrl: String? = null, 67 | var documentUrl: String? = null, 68 | var tabId: Int, 69 | var type: ResourceType, 70 | var timeStamp: Float, 71 | var ip: String? = null, 72 | var fromCache: Boolean, 73 | var requestHeaders: HttpHeaders? = null 74 | ) 75 | 76 | typealias Error = Any 77 | 78 | typealias Error2 = Any 79 | 80 | external class ProxyNamespace { 81 | /** 82 | * Fired when proxy data is needed for a request. 83 | * 84 | * @param details null */ 85 | val onRequest: Event<(details: Details) -> Unit> 86 | 87 | /** 88 | * Notifies about proxy script errors. 89 | * 90 | * @param error null */ 91 | val onError: Event<(error: Error) -> Unit> 92 | 93 | /** 94 | * Please use $(ref:proxy.onError). 95 | * 96 | * @param error null */ 97 | val onProxyError: Event<(error: Error2) -> Unit> 98 | 99 | /** 100 | * Configures proxy settings. This setting's value is an object of type ProxyConfig. 101 | */ 102 | var settings: Setting 103 | 104 | /** 105 | * Registers the proxy script for the extension. 106 | */ 107 | fun register(url: String): Promise 108 | 109 | /** 110 | * Unregisters the proxy script for the extension. 111 | */ 112 | fun unregister(): Promise 113 | 114 | /** 115 | * Registers the proxy script for the extension. 116 | */ 117 | @Deprecated("Please use $(ref:proxy.register)") 118 | fun registerProxyScript(url: String): Promise 119 | } 120 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/storage/storage.kt: -------------------------------------------------------------------------------- 1 | package storage 2 | 3 | import kotlin.Suppress 4 | import kotlin.js.Promise 5 | import webextensions.Event 6 | 7 | /** 8 | * Storage items to return in the callback, where the values are replaced with those from storage if 9 | they exist. 10 | */ 11 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 12 | class Keys() { 13 | inline operator fun get(key: String): dynamic = asDynamic()[key] 14 | inline operator fun set(key: String, value: dynamic) { 15 | asDynamic()[key] = value 16 | } 17 | } 18 | 19 | /** 20 | * A single key to get, list of keys to get, or a dictionary specifying default values (see 21 | description of the object). An empty list or object will return an empty result object. 22 | Pass in null to get the entire contents of storage. */ 23 | typealias Keys2 = Any 24 | 25 | /** 26 | * Object with items in their key-value mappings. 27 | */ 28 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 29 | class Items() { 30 | inline operator fun get(key: String): dynamic = asDynamic()[key] 31 | inline operator fun set(key: String, value: dynamic) { 32 | asDynamic()[key] = value 33 | } 34 | } 35 | 36 | /** 37 | * A single key or list of keys to get the total usage for. An empty list will return 0. Pass in 38 | null to get the total usage of all of storage. */ 39 | typealias Keys3 = Any 40 | 41 | /** 42 | *

An object which gives each key/value pair to update storage with. Any other key/value pairs in 43 | storage will not be affected.

Primitive values such as numbers will serialize as 44 | expected. Values with a typeof "object" and 45 | "function" will typically serialize to {}, with the exception of 46 | Array (serializes as expected), Date, and Regex 47 | (serialize using their String representation).

48 | */ 49 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 50 | class Items2() { 51 | inline operator fun get(key: String): dynamic = asDynamic()[key] 52 | inline operator fun set(key: String, value: dynamic) { 53 | asDynamic()[key] = value 54 | } 55 | } 56 | 57 | /** 58 | * A single key or a list of keys for items to remove. */ 59 | typealias Keys4 = Any 60 | 61 | /** 62 | * @param oldValue The old value of the item, if there was an old value. 63 | * @param newValue The new value of the item, if there is a new value. 64 | */ 65 | class StorageChange( 66 | var oldValue: dynamic = null, 67 | var newValue: dynamic = null 68 | ) 69 | 70 | external class StorageArea { 71 | /** 72 | * Gets one or more items from storage. 73 | */ 74 | fun get(keys: String): Promise 75 | 76 | /** 77 | * Gets one or more items from storage. 78 | */ 79 | fun get(keys: Array): Promise 80 | 81 | /** 82 | * Gets one or more items from storage. 83 | */ 84 | fun get(keys: Keys): Promise 85 | 86 | /** 87 | * Gets the amount of space (in bytes) being used by one or more items. 88 | */ 89 | fun getBytesInUse(keys: String): Promise 90 | 91 | /** 92 | * Gets the amount of space (in bytes) being used by one or more items. 93 | */ 94 | fun getBytesInUse(keys: Array): Promise 95 | 96 | /** 97 | * Sets multiple items. 98 | */ 99 | fun set(items: Items2): Promise 100 | 101 | /** 102 | * Removes one or more items from storage. 103 | */ 104 | fun remove(keys: String): Promise 105 | 106 | /** 107 | * Removes one or more items from storage. 108 | */ 109 | fun remove(keys: Array): Promise 110 | 111 | /** 112 | * Removes all items from storage. 113 | */ 114 | fun clear(): Promise 115 | } 116 | 117 | /** 118 | * Object mapping each key that changed to its corresponding $(ref:storage.StorageChange) for that 119 | item. 120 | */ 121 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 122 | class Changes() { 123 | inline operator fun get(key: String): StorageChange = asDynamic()[key] 124 | inline operator fun set(key: String, value: StorageChange) { 125 | asDynamic()[key] = value 126 | } 127 | } 128 | 129 | external class StorageNamespace { 130 | /** 131 | * Fired when one or more items change. 132 | * 133 | * @param changes Object mapping each key that changed to its corresponding 134 | $(ref:storage.StorageChange) for that item. 135 | * @param areaName The name of the storage area ("sync", "local" or 136 | "managed") the changes are for. */ 137 | val onChanged: Event<(changes: Changes, areaName: String) -> Unit> 138 | 139 | /** 140 | * Items in the sync storage area are synced by the browser. 141 | */ 142 | var sync: StorageArea 143 | 144 | /** 145 | * Items in the local storage area are local to each machine. 146 | */ 147 | var local: StorageArea 148 | 149 | /** 150 | * Items in the managed storage area are set by administrators or native 151 | applications, and are read-only for the extension; trying to modify this namespace 152 | results in an error. 153 | */ 154 | var managed: StorageArea 155 | } 156 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/browsingData/browsingData.kt: -------------------------------------------------------------------------------- 1 | package browsingData 2 | 3 | import extensionTypes.Date 4 | import kotlin.js.Promise 5 | 6 | /** 7 | * Options that determine exactly what data will be removed. 8 | * @param since Remove data accumulated on or after this date, represented in milliseconds since the 9 | epoch (accessible via the getTime method of the JavaScript Date 10 | object). If absent, defaults to 0 (which would remove all browsing data). 11 | * @param hostnames Only remove data associated with these hostnames (only applies to cookies and 12 | localStorage). 13 | * @param originTypes An object whose properties specify which origin types ought to be cleared. If 14 | this object isn't specified, it defaults to clearing only "unprotected" origins. Please 15 | ensure that you really want to remove application data before adding 'protectedWeb' 16 | or 'extensions'. 17 | */ 18 | class RemovalOptions( 19 | var since: Date? = null, 20 | var hostnames: Array? = null, 21 | var originTypes: OriginTypes? = null 22 | ) 23 | 24 | /** 25 | * A set of data types. Missing data types are interpreted as false. 26 | * @param cache The browser's cache. Note: when removing data, this clears the entire 27 | cache: it is not limited to the range you specify. 28 | * @param cookies The browser's cookies. 29 | * @param downloads The browser's download list. 30 | * @param formData The browser's stored form data. 31 | * @param history The browser's history. 32 | * @param indexedDB Websites' IndexedDB data. 33 | * @param localStorage Websites' local storage data. 34 | * @param serverBoundCertificates Server-bound certificates. 35 | * @param passwords Stored passwords. 36 | * @param pluginData Plugins' data. 37 | * @param serviceWorkers Service Workers. 38 | */ 39 | class DataTypeSet( 40 | var cache: Boolean? = null, 41 | var cookies: Boolean? = null, 42 | var downloads: Boolean? = null, 43 | var formData: Boolean? = null, 44 | var history: Boolean? = null, 45 | var indexedDB: Boolean? = null, 46 | var localStorage: Boolean? = null, 47 | var serverBoundCertificates: Boolean? = null, 48 | var passwords: Boolean? = null, 49 | var pluginData: Boolean? = null, 50 | var serviceWorkers: Boolean? = null 51 | ) 52 | 53 | /** 54 | * An object whose properties specify which origin types ought to be cleared. If this object isn't 55 | specified, it defaults to clearing only "unprotected" origins. Please ensure that you 56 | really want to remove application data before adding 'protectedWeb' or 57 | 'extensions'. 58 | * @param unprotectedWeb Normal websites. 59 | * @param protectedWeb Websites that have been installed as hosted applications (be careful!). 60 | * @param extension Extensions and packaged applications a user has installed (be _really_ 61 | careful!). 62 | */ 63 | class OriginTypes( 64 | var unprotectedWeb: Boolean? = null, 65 | var protectedWeb: Boolean? = null, 66 | var extension: Boolean? = null 67 | ) 68 | 69 | /** 70 | * @param dataToRemove All of the types will be present in the result, with values of 71 | true if they are both selected to be removed and permitted to be removed, 72 | otherwise false. 73 | * @param dataRemovalPermitted All of the types will be present in the result, with values of 74 | true if they are permitted to be removed (e.g., by enterprise policy) and 75 | false if not. 76 | */ 77 | class Result( 78 | var options: RemovalOptions, 79 | var dataToRemove: DataTypeSet, 80 | var dataRemovalPermitted: DataTypeSet 81 | ) 82 | 83 | external class BrowsingDataNamespace { 84 | /** 85 | * Reports which types of data are currently selected in the 'Clear browsing data' settings UI. 86 | Note: some of the data types included in this API are not available in the settings UI, 87 | and some UI settings control more than one data type listed here. 88 | */ 89 | fun settings(): Promise 90 | 91 | /** 92 | * Clears various types of browsing data stored in a user's profile. 93 | */ 94 | fun remove(options: RemovalOptions, dataToRemove: DataTypeSet): Promise 95 | 96 | /** 97 | * Clears the browser's cache. 98 | */ 99 | fun removeCache(options: RemovalOptions): Promise 100 | 101 | /** 102 | * Clears the browser's cookies and server-bound certificates modified within a particular 103 | timeframe. 104 | */ 105 | fun removeCookies(options: RemovalOptions): Promise 106 | 107 | /** 108 | * Clears the browser's list of downloaded files (not the downloaded files themselves). 109 | */ 110 | fun removeDownloads(options: RemovalOptions): Promise 111 | 112 | /** 113 | * Clears the browser's stored form data (autofill). 114 | */ 115 | fun removeFormData(options: RemovalOptions): Promise 116 | 117 | /** 118 | * Clears the browser's history. 119 | */ 120 | fun removeHistory(options: RemovalOptions): Promise 121 | 122 | /** 123 | * Clears websites' local storage data. 124 | */ 125 | fun removeLocalStorage(options: RemovalOptions): Promise 126 | 127 | /** 128 | * Clears plugins' data. 129 | */ 130 | fun removePluginData(options: RemovalOptions): Promise 131 | 132 | /** 133 | * Clears the browser's stored passwords. 134 | */ 135 | fun removePasswords(options: RemovalOptions): Promise 136 | } 137 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/history/history.kt: -------------------------------------------------------------------------------- 1 | package history 2 | 3 | import extensionTypes.Date 4 | import kotlin.js.Promise 5 | import webextensions.Event 6 | 7 | /** 8 | * The $(topic:transition-types)[transition type] for this visit from its referrer. */ 9 | typealias TransitionType = String 10 | 11 | /** 12 | * An object encapsulating one result of a history query. 13 | * @param id The unique identifier for the item. 14 | * @param url The URL navigated to by a user. 15 | * @param title The title of the page when it was last loaded. 16 | * @param lastVisitTime When this page was last loaded, represented in milliseconds since the epoch. 17 | * @param visitCount The number of times the user has navigated to this page. 18 | * @param typedCount The number of times the user has navigated to this page by typing in the 19 | address. 20 | */ 21 | class HistoryItem( 22 | var id: String, 23 | var url: String? = null, 24 | var title: String? = null, 25 | var lastVisitTime: Float? = null, 26 | var visitCount: Int? = null, 27 | var typedCount: Int? = null 28 | ) 29 | 30 | /** 31 | * An object encapsulating one visit to a URL. 32 | * @param id The unique identifier for the item. 33 | * @param visitId The unique identifier for this visit. 34 | * @param visitTime When this visit occurred, represented in milliseconds since the epoch. 35 | * @param referringVisitId The visit ID of the referrer. 36 | * @param transition The $(topic:transition-types)[transition type] for this visit from its 37 | referrer. 38 | */ 39 | class VisitItem( 40 | var id: String, 41 | var visitId: String, 42 | var visitTime: Float? = null, 43 | var referringVisitId: String, 44 | var transition: TransitionType 45 | ) 46 | 47 | /** 48 | * @param text A free-text query to the history service. Leave empty to retrieve all pages. 49 | * @param startTime Limit results to those visited after this date. If not specified, this defaults 50 | to 24 hours in the past. 51 | * @param endTime Limit results to those visited before this date. 52 | * @param maxResults The maximum number of results to retrieve. Defaults to 100. 53 | */ 54 | class Query( 55 | var text: String, 56 | var startTime: Date? = null, 57 | var endTime: Date? = null, 58 | var maxResults: Int? = null 59 | ) 60 | 61 | /** 62 | * @param url The URL for which to retrieve visit information. It must be in the format as returned 63 | from a call to history.search. 64 | */ 65 | class Details( 66 | var url: String 67 | ) 68 | 69 | /** 70 | * @param url The URL to add. Must be a valid URL that can be added to history. 71 | * @param title The title of the page. 72 | * @param transition The $(topic:transition-types)[transition type] for this visit from its 73 | referrer. 74 | * @param visitTime The date when this visit occurred. 75 | */ 76 | class Details2( 77 | var url: String, 78 | var title: String? = null, 79 | var transition: TransitionType? = null, 80 | var visitTime: Date? = null 81 | ) 82 | 83 | /** 84 | * @param url The URL to remove. 85 | */ 86 | class Details3( 87 | var url: String 88 | ) 89 | 90 | /** 91 | * @param startTime Items added to history after this date. 92 | * @param endTime Items added to history before this date. 93 | */ 94 | class Range( 95 | var startTime: Date, 96 | var endTime: Date 97 | ) 98 | 99 | /** 100 | * @param allHistory True if all history was removed. If true, then urls will be empty. 101 | */ 102 | class Removed( 103 | var allHistory: Boolean, 104 | var urls: Array 105 | ) 106 | 107 | /** 108 | * @param url The URL for which the title has changed 109 | * @param title The new title for the URL. 110 | */ 111 | class Changed( 112 | var url: String, 113 | var title: String 114 | ) 115 | 116 | external class HistoryNamespace { 117 | /** 118 | * Fired when a URL is visited, providing the HistoryItem data for that URL. This event fires 119 | before the page has loaded. 120 | * 121 | * @param result null */ 122 | val onVisited: Event<(result: HistoryItem) -> Unit> 123 | 124 | /** 125 | * Fired when one or more URLs are removed from the history service. When all visits have been 126 | removed the URL is purged from history. 127 | * 128 | * @param removed null */ 129 | val onVisitRemoved: Event<(removed: Removed) -> Unit> 130 | 131 | /** 132 | * Fired when the title of a URL is changed in the browser history. 133 | * 134 | * @param changed null */ 135 | val onTitleChanged: Event<(changed: Changed) -> Unit> 136 | 137 | /** 138 | * Searches the history for the last visit time of each page matching the query. 139 | */ 140 | fun search(query: Query): Promise> 141 | 142 | /** 143 | * Retrieves information about visits to a URL. 144 | */ 145 | fun getVisits(details: Details): Promise> 146 | 147 | /** 148 | * Adds a URL to the history with a default visitTime of the current time and a default 149 | $(topic:transition-types)[transition type] of "link". 150 | */ 151 | fun addUrl(details: Details2): Promise 152 | 153 | /** 154 | * Removes all occurrences of the given URL from the history. 155 | */ 156 | fun deleteUrl(details: Details3): Promise 157 | 158 | /** 159 | * Removes all items within the specified date range from the history. Pages will not be 160 | removed from the history unless all visits fall within the range. 161 | */ 162 | fun deleteRange(range: Range): Promise 163 | 164 | /** 165 | * Deletes all items from the history. 166 | */ 167 | fun deleteAll(): Promise 168 | } 169 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/notifications/notifications.kt: -------------------------------------------------------------------------------- 1 | package notifications 2 | 3 | import kotlin.Suppress 4 | import kotlin.js.Promise 5 | import webextensions.Event 6 | 7 | typealias TemplateType = String 8 | 9 | typealias PermissionLevel = String 10 | 11 | /** 12 | * @param title Title of one item of a list notification. 13 | * @param message Additional details about this item. 14 | */ 15 | class NotificationItem( 16 | var title: String, 17 | var message: String 18 | ) 19 | 20 | /** 21 | * @param type Which type of notification to display. 22 | * @param iconUrl A URL to the sender's avatar, app icon, or a thumbnail for image notifications. 23 | * @param appIconMaskUrl A URL to the app icon mask. 24 | * @param title Title of the notification (e.g. sender name for email). 25 | * @param message Main notification content. 26 | * @param contextMessage Alternate notification content with a lower-weight font. 27 | * @param priority Priority ranges from -2 to 2. -2 is lowest priority. 2 is highest. Zero is 28 | default. 29 | * @param eventTime A timestamp associated with the notification, in milliseconds past the epoch. 30 | * @param imageUrl A URL to the image thumbnail for image-type notifications. 31 | * @param items Items for multi-item notifications. 32 | * @param progress Current progress ranges from 0 to 100. 33 | * @param isClickable Whether to show UI indicating that the app will visibly respond to clicks on 34 | the body of a notification. 35 | */ 36 | class CreateNotificationOptions( 37 | var type: TemplateType, 38 | var iconUrl: String? = null, 39 | var appIconMaskUrl: String? = null, 40 | var title: String, 41 | var message: String, 42 | var contextMessage: String? = null, 43 | var priority: Int? = null, 44 | var eventTime: Float? = null, 45 | var imageUrl: String? = null, 46 | var items: Array? = null, 47 | var progress: Int? = null, 48 | var isClickable: Boolean? = null 49 | ) 50 | 51 | /** 52 | * @param type Which type of notification to display. 53 | * @param iconUrl A URL to the sender's avatar, app icon, or a thumbnail for image notifications. 54 | * @param appIconMaskUrl A URL to the app icon mask. 55 | * @param title Title of the notification (e.g. sender name for email). 56 | * @param message Main notification content. 57 | * @param contextMessage Alternate notification content with a lower-weight font. 58 | * @param priority Priority ranges from -2 to 2. -2 is lowest priority. 2 is highest. Zero is 59 | default. 60 | * @param eventTime A timestamp associated with the notification, in milliseconds past the epoch. 61 | * @param imageUrl A URL to the image thumbnail for image-type notifications. 62 | * @param items Items for multi-item notifications. 63 | * @param progress Current progress ranges from 0 to 100. 64 | * @param isClickable Whether to show UI indicating that the app will visibly respond to clicks on 65 | the body of a notification. 66 | */ 67 | class UpdateNotificationOptions( 68 | var type: TemplateType? = null, 69 | var iconUrl: String? = null, 70 | var appIconMaskUrl: String? = null, 71 | var title: String? = null, 72 | var message: String? = null, 73 | var contextMessage: String? = null, 74 | var priority: Int? = null, 75 | var eventTime: Float? = null, 76 | var imageUrl: String? = null, 77 | var items: Array? = null, 78 | var progress: Int? = null, 79 | var isClickable: Boolean? = null 80 | ) 81 | 82 | class Buttons(var title: String, var iconUrl: String? = null) 83 | 84 | class Buttons2(var title: String, var iconUrl: String? = null) 85 | 86 | /** 87 | * The set of notifications currently in the system. 88 | */ 89 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 90 | class Notifications() { 91 | inline operator fun get(key: String): CreateNotificationOptions = asDynamic()[key] 92 | inline operator fun set(key: String, value: CreateNotificationOptions) { 93 | asDynamic()[key] = value 94 | } 95 | } 96 | 97 | external class NotificationsNamespace { 98 | /** 99 | * Fired when the notification closed, either by the system or by user action. 100 | * 101 | * @param notificationId The notificationId of the closed notification. 102 | * @param byUser True if the notification was closed by the user. */ 103 | val onClosed: Event<(notificationId: String, byUser: Boolean) -> Unit> 104 | 105 | /** 106 | * Fired when the user clicked in a non-button area of the notification. 107 | * 108 | * @param notificationId The notificationId of the clicked notification. */ 109 | val onClicked: Event<(notificationId: String) -> Unit> 110 | 111 | /** 112 | * Fired when the user pressed a button in the notification. 113 | * 114 | * @param notificationId The notificationId of the clicked notification. 115 | * @param buttonIndex The index of the button clicked by the user. */ 116 | val onButtonClicked: Event<(notificationId: String, buttonIndex: Float) -> Unit> 117 | 118 | /** 119 | * Fired when the notification is shown. 120 | * 121 | * @param notificationId The notificationId of the shown notification. */ 122 | val onShown: Event<(notificationId: String) -> Unit> 123 | 124 | /** 125 | * Creates and displays a notification. 126 | */ 127 | fun create(notificationId: String? = definedExternally, options: CreateNotificationOptions): 128 | Promise 129 | 130 | /** 131 | * Clears an existing notification. 132 | */ 133 | fun clear(notificationId: String): Promise 134 | 135 | /** 136 | * Retrieves all the notifications. 137 | */ 138 | fun getAll(): Promise 139 | } 140 | -------------------------------------------------------------------------------- /src/main/kotlin/de/rakhman/webextensions/merging.kt: -------------------------------------------------------------------------------- 1 | package de.rakhman.webextensions 2 | 3 | fun merge(list: List): Namespace { 4 | require(list.isNotEmpty()) 5 | 6 | val types = mergeTypes(list.flatMap { it.types ?: emptyList() }) 7 | 8 | val properties = list 9 | .flatMap { it.properties?.entries ?: emptySet() } 10 | .associate { it.key to it.value.resolve(it.key, types) } 11 | .takeUnless { it.isEmpty() } 12 | 13 | val functions = list 14 | .flatMap { it.functions?.map { it.resolve(types) } ?: emptyList() } 15 | .takeUnless { it.isEmpty() } 16 | 17 | val events = list 18 | .flatMap { it.events?.map { it.resolve(types) } ?: emptyList() } 19 | .takeUnless { it.isEmpty() } 20 | 21 | return Namespace( 22 | namespace = list.first().namespace, 23 | description = list.mapNotNull { it.description }.firstOrNull(), 24 | types = types.values.toList().takeUnless { it.isEmpty() }, 25 | properties = properties, 26 | functions = functions, 27 | events = events 28 | ) 29 | } 30 | 31 | private fun mergeTypes(types: List): MutableMap { 32 | val result = mutableMapOf() 33 | 34 | result.putAll(types 35 | .map { it.copy(functions = it.functions?.map { it.resolve(result) }) } 36 | .groupingBy { it.id ?: it.`$extend` } 37 | .reduceTo(mutableMapOf()) { key, left, right -> 38 | Type( 39 | id = key, 40 | description = left.description ?: right.description, 41 | type = left.type ?: right.type, 42 | properties = (left.properties.orEmpty() + right.properties.orEmpty()).takeUnless { it.isEmpty() }, 43 | choices = (left.choices.orEmpty() + right.choices.orEmpty()).takeUnless { it.isEmpty() }, 44 | `$extend` = null, 45 | actual = false, 46 | items = left.items ?: right.items, 47 | additionalProperties = left.additionalProperties ?: right.additionalProperties, 48 | patternProperties = (left.patternProperties.orEmpty() + right.patternProperties.orEmpty()).takeUnless { it.isEmpty() }, 49 | functions = (left.functions.orEmpty() + right.functions.orEmpty()).takeUnless { it.isEmpty() } 50 | ) 51 | }) 52 | 53 | for ((key, value) in result.toMap()) { 54 | if (key == null) continue 55 | 56 | result[key] = value.copy( 57 | properties = value.properties?.entries?.associate { 58 | it.key to it.value.resolve( 59 | it.key, 60 | result 61 | ) 62 | }, 63 | items = value.items?.resolve(key, result) 64 | ) 65 | } 66 | 67 | return result 68 | } 69 | 70 | private fun Event.resolve(types: MutableMap): Event { 71 | return copy( 72 | parameters = parameters?.map { it.resolve(it.name!!, types) } 73 | ) 74 | } 75 | 76 | private fun Function.resolve(types: MutableMap): Function { 77 | return copy( 78 | parameters = parameters?.map { 79 | it.resolve( 80 | it.name!!, 81 | types, 82 | it.name != async, 83 | it.name == async 84 | ) 85 | }, 86 | returns = returns?.resolve(name + "Result", types) 87 | ) 88 | } 89 | 90 | private fun Parameter.resolve( 91 | name: String, 92 | types: MutableMap, 93 | actual: Boolean = false, 94 | isReturn: Boolean = false 95 | ): Parameter { 96 | if (type == "function") return copy(parameters = parameters?.map { 97 | it.resolve( 98 | it.name ?: name, 99 | types 100 | ) 101 | }) 102 | if (type == "array") return copy(items = items?.resolve(name, types, actual)) 103 | if (type != "object" && 104 | choices == null && 105 | parameters == null && 106 | additionalProperties == null && 107 | patternProperties == null 108 | ) { 109 | return this 110 | } 111 | 112 | val parameters = parameters?.map { it.resolve(it.name!!, types, actual) } 113 | val choices = choices?.map { it.resolve(name, types, actual) } 114 | val additionalProperties = additionalProperties?.resolve(name, types) 115 | val patternProperties = patternProperties?.mapValues { it.value.resolve(name, types) } 116 | 117 | var typeName = name.capitalize() 118 | var counter = 1 119 | 120 | while (types.containsKey(typeName)) typeName = name.capitalize() + ++counter 121 | 122 | if (!isReturn) { 123 | val previous = types.put( 124 | typeName, Type( 125 | id = typeName, 126 | type = null, 127 | properties = properties?.map { 128 | it.key to it.value.resolve( 129 | it.key, 130 | types, 131 | actual 132 | ) 133 | }?.toMap(), 134 | description = description, 135 | `$extend` = null, 136 | choices = null, 137 | actual = actual, 138 | items = null, 139 | additionalProperties = additionalProperties, 140 | patternProperties = patternProperties, 141 | functions = null 142 | ) 143 | ) 144 | 145 | require(previous == null) { 146 | "A type with the name $typeName already existed" 147 | } 148 | } 149 | 150 | return copy( 151 | type = null, 152 | properties = null, 153 | `$ref` = typeName, 154 | parameters = parameters, 155 | choices = choices, 156 | additionalProperties = null, 157 | patternProperties = null 158 | ) 159 | } -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/management/management.kt: -------------------------------------------------------------------------------- 1 | package management 2 | 3 | import kotlin.js.Promise 4 | import manifest.ExtensionID 5 | import manifest.HttpURL 6 | import webextensions.Event 7 | 8 | /** 9 | * Information about an icon belonging to an extension. 10 | * @param size A number representing the width and height of the icon. Likely values include (but 11 | are not limited to) 128, 48, 24, and 16. 12 | * @param url The URL for this icon image. To display a grayscale version of the icon (to indicate 13 | that an extension is disabled, for example), append ?grayscale=true to the URL. 14 | */ 15 | class IconInfo( 16 | var size: Int, 17 | var url: String 18 | ) 19 | 20 | /** 21 | * A reason the item is disabled. */ 22 | typealias ExtensionDisabledReason = String 23 | 24 | /** 25 | * The type of this extension, 'extension' or 'theme'. */ 26 | typealias ExtensionType = String 27 | 28 | /** 29 | * How the extension was installed. One of
development: The extension was loaded 30 | unpacked in developer mode,
normal: The extension was installed normally via 31 | an .xpi file,
sideload: The extension was installed by other software on the 32 | machine,
other: The extension was installed by other means. */ 33 | typealias ExtensionInstallType = String 34 | 35 | /** 36 | * Information about an installed extension. 37 | * @param id The extension's unique identifier. 38 | * @param name The name of this extension. 39 | * @param shortName A short version of the name of this extension. 40 | * @param description The description of this extension. 41 | * @param version The version of this extension. 42 | * @param versionName The version name of this extension 43 | if the manifest specified one. 44 | * @param mayDisable Whether this extension can be disabled or uninstalled by the user. 45 | * @param enabled Whether it is currently enabled or disabled. 46 | * @param disabledReason A reason the item is disabled. 47 | * @param type The type of this extension, 'extension' or 'theme'. 48 | * @param homepageUrl The URL of the homepage of this extension. 49 | * @param updateUrl The update URL of this extension. 50 | * @param optionsUrl The url for the item's options page, if it has one. 51 | * @param icons A list of icon information. Note that this just reflects what was declared in the 52 | manifest, and the actual image at that url may be larger or smaller than what was declared, 53 | so you might consider using explicit width and height attributes on img tags referencing 54 | these images. See the manifest documentation on icons for more 55 | details. 56 | * @param permissions Returns a list of API based permissions. 57 | * @param hostPermissions Returns a list of host based permissions. 58 | * @param installType How the extension was installed. 59 | */ 60 | class ExtensionInfo( 61 | var id: String, 62 | var name: String, 63 | var shortName: String? = null, 64 | var description: String, 65 | var version: String, 66 | var versionName: String? = null, 67 | var mayDisable: Boolean, 68 | var enabled: Boolean, 69 | var disabledReason: ExtensionDisabledReason? = null, 70 | var type: ExtensionType, 71 | var homepageUrl: String? = null, 72 | var updateUrl: String? = null, 73 | var optionsUrl: String, 74 | var icons: Array? = null, 75 | var permissions: Array? = null, 76 | var hostPermissions: Array? = null, 77 | var installType: ExtensionInstallType 78 | ) 79 | 80 | /** 81 | * @param url URL pointing to the XPI file on addons.mozilla.org or similar. 82 | * @param hash A hash of the XPI file, using sha256 or stronger. 83 | */ 84 | class Options( 85 | var url: HttpURL, 86 | var hash: String? = null 87 | ) 88 | 89 | class Result(var id: ExtensionID) 90 | 91 | /** 92 | * @param showConfirmDialog Whether or not a confirm-uninstall dialog should prompt the user. 93 | Defaults to false. 94 | * @param dialogMessage The message to display to a user when being asked to confirm removal of the 95 | extension. 96 | */ 97 | class Options2( 98 | var showConfirmDialog: Boolean? = null, 99 | var dialogMessage: String? = null 100 | ) 101 | 102 | external class ManagementNamespace { 103 | /** 104 | * Fired when an addon has been disabled. 105 | * 106 | * @param info null */ 107 | val onDisabled: Event<(info: ExtensionInfo) -> Unit> 108 | 109 | /** 110 | * Fired when an addon has been enabled. 111 | * 112 | * @param info null */ 113 | val onEnabled: Event<(info: ExtensionInfo) -> Unit> 114 | 115 | /** 116 | * Fired when an addon has been installed. 117 | * 118 | * @param info null */ 119 | val onInstalled: Event<(info: ExtensionInfo) -> Unit> 120 | 121 | /** 122 | * Fired when an addon has been uninstalled. 123 | * 124 | * @param info null */ 125 | val onUninstalled: Event<(info: ExtensionInfo) -> Unit> 126 | 127 | /** 128 | * Returns a list of information about installed extensions. 129 | */ 130 | fun getAll(): Promise> 131 | 132 | /** 133 | * Returns information about the installed extension that has the given ID. 134 | */ 135 | fun get(id: ExtensionID): Promise 136 | 137 | /** 138 | * Installs and enables a theme extension from the given url. 139 | */ 140 | fun install(options: Options): Promise 141 | 142 | /** 143 | * Returns information about the calling extension. Note: This function can be used without 144 | requesting the 'management' permission in the manifest. 145 | */ 146 | fun getSelf(): Promise 147 | 148 | /** 149 | * Uninstalls the calling extension. Note: This function can be used without requesting the 150 | 'management' permission in the manifest. 151 | */ 152 | fun uninstallSelf(options: Options2? = definedExternally): Promise 153 | 154 | /** 155 | * Enables or disables the given add-on. 156 | */ 157 | fun setEnabled(id: String, enabled: Boolean): Promise 158 | } 159 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/events/events.kt: -------------------------------------------------------------------------------- 1 | package events 2 | 3 | /** 4 | * Description of a declarative rule for handling events. 5 | * @param id Optional identifier that allows referencing this rule. 6 | * @param tags Tags can be used to annotate rules and perform operations on sets of rules. 7 | * @param conditions List of conditions that can trigger the actions. 8 | * @param actions List of actions that are triggered if one of the condtions is fulfilled. 9 | * @param priority Optional priority of this rule. Defaults to 100. 10 | */ 11 | class Rule( 12 | var id: String? = null, 13 | var tags: Array? = null, 14 | var conditions: Array, 15 | var actions: Array, 16 | var priority: Int? = null 17 | ) 18 | 19 | /** 20 | * An object which allows the addition and removal of listeners for a Chrome event. 21 | */ 22 | external class Event { 23 | /** 24 | * Registers an event listener callback to an event. 25 | */ 26 | fun addListener(callback: () -> Unit) 27 | 28 | /** 29 | * Deregisters an event listener callback from an event. 30 | */ 31 | fun removeListener(callback: () -> Unit) 32 | 33 | fun hasListener(callback: () -> Unit): Boolean 34 | 35 | fun hasListeners(): Boolean 36 | 37 | /** 38 | * Registers rules to handle events. 39 | */ 40 | fun addRules( 41 | eventName: String, 42 | webViewInstanceId: Int, 43 | rules: Array, 44 | callback: (() -> Unit)? = definedExternally 45 | ) 46 | 47 | /** 48 | * Returns currently registered rules. 49 | */ 50 | fun getRules( 51 | eventName: String, 52 | webViewInstanceId: Int, 53 | ruleIdentifiers: Array? = definedExternally, 54 | callback: () -> Unit 55 | ) 56 | 57 | /** 58 | * Unregisters currently registered rules. 59 | */ 60 | fun removeRules( 61 | eventName: String, 62 | webViewInstanceId: Int, 63 | ruleIdentifiers: Array? = definedExternally, 64 | callback: (() -> Unit)? = definedExternally 65 | ) 66 | } 67 | 68 | /** 69 | * Filters URLs for various criteria. See event filtering. All 70 | criteria are case sensitive. 71 | * @param hostContains Matches if the host name of the URL contains a specified string. To test 72 | whether a host name component has a prefix 'foo', use hostContains: '.foo'. This matches 73 | 'www.foobar.com' and 'foo.com', because an implicit dot is added at the beginning of the 74 | host name. Similarly, hostContains can be used to match against component suffix ('foo.') 75 | and to exactly match against components ('.foo.'). Suffix- and exact-matching for the last 76 | components need to be done separately using hostSuffix, because no implicit dot is added at 77 | the end of the host name. 78 | * @param hostEquals Matches if the host name of the URL is equal to a specified string. 79 | * @param hostPrefix Matches if the host name of the URL starts with a specified string. 80 | * @param hostSuffix Matches if the host name of the URL ends with a specified string. 81 | * @param pathContains Matches if the path segment of the URL contains a specified string. 82 | * @param pathEquals Matches if the path segment of the URL is equal to a specified string. 83 | * @param pathPrefix Matches if the path segment of the URL starts with a specified string. 84 | * @param pathSuffix Matches if the path segment of the URL ends with a specified string. 85 | * @param queryContains Matches if the query segment of the URL contains a specified string. 86 | * @param queryEquals Matches if the query segment of the URL is equal to a specified string. 87 | * @param queryPrefix Matches if the query segment of the URL starts with a specified string. 88 | * @param querySuffix Matches if the query segment of the URL ends with a specified string. 89 | * @param urlContains Matches if the URL (without fragment identifier) contains a specified string. 90 | Port numbers are stripped from the URL if they match the default port number. 91 | * @param urlEquals Matches if the URL (without fragment identifier) is equal to a specified string. 92 | Port numbers are stripped from the URL if they match the default port number. 93 | * @param urlMatches Matches if the URL (without fragment identifier) matches a specified regular 94 | expression. Port numbers are stripped from the URL if they match the default port number. 95 | The regular expressions use the RE2 syntax. 97 | * @param originAndPathMatches Matches if the URL without query segment and fragment identifier 98 | matches a specified regular expression. Port numbers are stripped from the URL if they match 99 | the default port number. The regular expressions use the RE2 syntax. 101 | * @param urlPrefix Matches if the URL (without fragment identifier) starts with a specified string. 102 | Port numbers are stripped from the URL if they match the default port number. 103 | * @param urlSuffix Matches if the URL (without fragment identifier) ends with a specified string. 104 | Port numbers are stripped from the URL if they match the default port number. 105 | * @param schemes Matches if the scheme of the URL is equal to any of the schemes specified in the 106 | array. 107 | * @param ports Matches if the port of the URL is contained in any of the specified port lists. For 108 | example [80, 443, [1000, 1200]] matches all requests on port 80, 443 and in the 109 | range 1000-1200. 110 | */ 111 | class UrlFilter( 112 | var hostContains: String? = null, 113 | var hostEquals: String? = null, 114 | var hostPrefix: String? = null, 115 | var hostSuffix: String? = null, 116 | var pathContains: String? = null, 117 | var pathEquals: String? = null, 118 | var pathPrefix: String? = null, 119 | var pathSuffix: String? = null, 120 | var queryContains: String? = null, 121 | var queryEquals: String? = null, 122 | var queryPrefix: String? = null, 123 | var querySuffix: String? = null, 124 | var urlContains: String? = null, 125 | var urlEquals: String? = null, 126 | var urlMatches: String? = null, 127 | var originAndPathMatches: String? = null, 128 | var urlPrefix: String? = null, 129 | var urlSuffix: String? = null, 130 | var schemes: Array? = null, 131 | var ports: Array? = null 132 | ) 133 | 134 | typealias Ports = Any 135 | 136 | external class EventsNamespace 137 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/pageAction/pageAction.kt: -------------------------------------------------------------------------------- 1 | package pageAction 2 | 3 | import kotlin.Suppress 4 | import kotlin.js.Promise 5 | import tabs.Tab 6 | import webextensions.Event 7 | 8 | /** 9 | * Pixel data for an image. Must be an ImageData object (for example, from a canvas 10 | element). 11 | */ 12 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 13 | class ImageDataType() { 14 | inline operator fun get(key: String): dynamic = asDynamic()[key] 15 | inline operator fun set(key: String, value: dynamic) { 16 | asDynamic()[key] = value 17 | } 18 | } 19 | 20 | /** 21 | * @param tabId Specify the tab to get the shownness from. 22 | */ 23 | class Details( 24 | var tabId: Int 25 | ) 26 | 27 | /** 28 | * The tooltip string. */ 29 | typealias Title = Any 30 | 31 | /** 32 | * @param tabId The id of the tab for which you want to modify the page action. 33 | * @param title The tooltip string. 34 | */ 35 | class Details2( 36 | var tabId: Int, 37 | var title: Title 38 | ) 39 | 40 | /** 41 | * @param tabId Specify the tab to get the title from. 42 | */ 43 | class Details3( 44 | var tabId: Int 45 | ) 46 | 47 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 48 | class ImageData() { 49 | inline operator fun get(key: String): ImageDataType = asDynamic()[key] 50 | inline operator fun set(key: String, value: ImageDataType) { 51 | asDynamic()[key] = value 52 | } 53 | } 54 | 55 | /** 56 | * Either an ImageData object or a dictionary {size -> ImageData} representing icon to be set. If 57 | the icon is specified as a dictionary, the actual image to be used is chosen depending on 58 | screen's pixel density. If the number of image pixels that fit into one screen space unit 59 | equals scale, then image with size scale * 19 will be selected. 60 | Initially only scales 1 and 2 will be supported. At least one image must be specified. Note 61 | that 'details.imageData = foo' is equivalent to 'details.imageData = {'19': foo}' */ 62 | typealias ImageData2 = Any 63 | 64 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 65 | class Path() { 66 | inline operator fun get(key: String): String = asDynamic()[key] 67 | inline operator fun set(key: String, value: String) { 68 | asDynamic()[key] = value 69 | } 70 | } 71 | 72 | /** 73 | * Either a relative image path or a dictionary {size -> relative image path} pointing to icon to be 74 | set. If the icon is specified as a dictionary, the actual image to be used is chosen 75 | depending on screen's pixel density. If the number of image pixels that fit into one screen 76 | space unit equals scale, then image with size scale * 19 will be 77 | selected. Initially only scales 1 and 2 will be supported. At least one image must be 78 | specified. Note that 'details.path = foo' is equivalent to 'details.imageData = {'19': foo}' 79 | */ 80 | typealias Path2 = Any 81 | 82 | /** 83 | * @param tabId The id of the tab for which you want to modify the page action. 84 | * @param imageData Either an ImageData object or a dictionary {size -> ImageData} representing icon 85 | to be set. If the icon is specified as a dictionary, the actual image to be used is chosen 86 | depending on screen's pixel density. If the number of image pixels that fit into one screen 87 | space unit equals scale, then image with size scale * 19 will be 88 | selected. Initially only scales 1 and 2 will be supported. At least one image must be 89 | specified. Note that 'details.imageData = foo' is equivalent to 'details.imageData = {'19': 90 | foo}' 91 | * @param path Either a relative image path or a dictionary {size -> relative image path} pointing 92 | to icon to be set. If the icon is specified as a dictionary, the actual image to be used is 93 | chosen depending on screen's pixel density. If the number of image pixels that fit into one 94 | screen space unit equals scale, then image with size scale * 19 95 | will be selected. Initially only scales 1 and 2 will be supported. At least one image must 96 | be specified. Note that 'details.path = foo' is equivalent to 'details.imageData = {'19': 97 | foo}' 98 | */ 99 | class Details4( 100 | var tabId: Int, 101 | var imageData: ImageData2? = null, 102 | var path: Path2? = null 103 | ) 104 | 105 | /** 106 | * The html file to show in a popup. If set to the empty string (''), no popup is shown. */ 107 | typealias Popup = Any 108 | 109 | /** 110 | * @param tabId The id of the tab for which you want to modify the page action. 111 | * @param popup The html file to show in a popup. If set to the empty string (''), no popup is 112 | shown. 113 | */ 114 | class Details5( 115 | var tabId: Int, 116 | var popup: Popup 117 | ) 118 | 119 | /** 120 | * @param tabId Specify the tab to get the popup from. 121 | */ 122 | class Details6( 123 | var tabId: Int 124 | ) 125 | 126 | external class PageActionNamespace { 127 | /** 128 | * Fired when a page action icon is clicked. This event will not fire if the page action has a 129 | popup. 130 | * 131 | * @param tab null */ 132 | val onClicked: Event<(tab: Tab) -> Unit> 133 | 134 | /** 135 | * Shows the page action. The page action is shown whenever the tab is selected. 136 | */ 137 | fun show(tabId: Int): Promise 138 | 139 | /** 140 | * Hides the page action. 141 | */ 142 | fun hide(tabId: Int): Promise 143 | 144 | /** 145 | * Checks whether the page action is shown. 146 | */ 147 | fun isShown(details: Details): Promise 148 | 149 | /** 150 | * Sets the title of the page action. This is displayed in a tooltip over the page action. 151 | */ 152 | fun setTitle(details: Details2) 153 | 154 | /** 155 | * Gets the title of the page action. 156 | */ 157 | fun getTitle(details: Details3): Promise 158 | 159 | /** 160 | * Sets the icon for the page action. The icon can be specified either as the path to an image 161 | file or as the pixel data from a canvas element, or as dictionary of either one of 162 | those. Either the path or the imageData property must be specified. 163 | */ 164 | fun setIcon(details: Details4): Promise 165 | 166 | /** 167 | * Sets the html document to be opened as a popup when the user clicks on the page action's 168 | icon. 169 | */ 170 | fun setPopup(details: Details5): Promise 171 | 172 | /** 173 | * Gets the html document set as the popup for this page action. 174 | */ 175 | fun getPopup(details: Details6): Promise 176 | 177 | /** 178 | * Opens the extension page action in the active window. 179 | */ 180 | fun openPopup(): Promise 181 | } 182 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/telemetry/telemetry.kt: -------------------------------------------------------------------------------- 1 | package telemetry 2 | 3 | import kotlin.Suppress 4 | import kotlin.js.Promise 5 | 6 | /** 7 | * Type of scalar: 'count' for numeric values, 'string' for string values, 'boolean' for boolean 8 | values. Maps to nsITelemetry.SCALAR_TYPE_*. */ 9 | typealias ScalarType = String 10 | 11 | /** 12 | * Represents registration data for a Telemetry scalar. 13 | * @param keyed True if this is a keyed scalar. 14 | * @param record_on_release True if this data should be recorded on release. 15 | * @param expired True if this scalar entry is expired. This allows recording it without error, but 16 | it will be discarded. 17 | */ 18 | class ScalarData( 19 | var kind: ScalarType, 20 | var keyed: Boolean? = null, 21 | var record_on_release: Boolean? = null, 22 | var expired: Boolean? = null 23 | ) 24 | 25 | /** 26 | * Represents registration data for a Telemetry event. 27 | * @param methods List of methods for this event entry. 28 | * @param objects List of objects for this event entry. 29 | * @param extra_keys List of allowed extra keys for this event entry. 30 | * @param record_on_release True if this data should be recorded on release. 31 | * @param expired True if this event entry is expired. This allows recording it without error, but 32 | it will be discarded. 33 | */ 34 | class EventData( 35 | var methods: Array, 36 | var objects: Array, 37 | var extra_keys: Array, 38 | var record_on_release: Boolean? = null, 39 | var expired: Boolean? = null 40 | ) 41 | 42 | /** 43 | * The data payload for the ping. 44 | */ 45 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 46 | class Message() { 47 | inline operator fun get(key: String): dynamic = asDynamic()[key] 48 | inline operator fun set(key: String, value: dynamic) { 49 | asDynamic()[key] = value 50 | } 51 | } 52 | 53 | /** 54 | * Set to override the environment data. 55 | */ 56 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 57 | class OverrideEnvironment() { 58 | inline operator fun get(key: String): dynamic = asDynamic()[key] 59 | inline operator fun set(key: String, value: dynamic) { 60 | asDynamic()[key] = value 61 | } 62 | } 63 | 64 | /** 65 | * Options object. 66 | * @param addClientId True if the ping should contain the client id. 67 | * @param addEnvironment True if the ping should contain the environment data. 68 | * @param overrideEnvironment Set to override the environment data. 69 | * @param usePingSender If true, send the ping using the PingSender. 70 | */ 71 | class Options( 72 | var addClientId: Boolean? = null, 73 | var addEnvironment: Boolean? = null, 74 | var overrideEnvironment: OverrideEnvironment? = null, 75 | var usePingSender: Boolean? = null 76 | ) 77 | 78 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 79 | class Value() { 80 | inline operator fun get(key: String): dynamic = asDynamic()[key] 81 | inline operator fun set(key: String, value: dynamic) { 82 | asDynamic()[key] = value 83 | } 84 | } 85 | 86 | /** 87 | * The value to set the scalar to */ 88 | typealias Value2 = Any 89 | 90 | /** 91 | * An optional object of the form (string -> string). It should only contain registered extra keys. 92 | */ 93 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 94 | class Extra() { 95 | inline operator fun get(key: String): String = asDynamic()[key] 96 | inline operator fun set(key: String, value: String) { 97 | asDynamic()[key] = value 98 | } 99 | } 100 | 101 | /** 102 | * An object that contains registration data for multiple scalars. Each property name is the scalar 103 | name, and the corresponding property value is an object of ScalarData type. 104 | */ 105 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 106 | class Data() { 107 | inline operator fun get(key: String): ScalarData = asDynamic()[key] 108 | inline operator fun set(key: String, value: ScalarData) { 109 | asDynamic()[key] = value 110 | } 111 | } 112 | 113 | /** 114 | * An object that contains registration data for 1+ events. Each property name is the category name, 115 | and the corresponding property value is an object of EventData type. 116 | */ 117 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 118 | class Data2() { 119 | inline operator fun get(key: String): EventData = asDynamic()[key] 120 | inline operator fun set(key: String, value: EventData) { 121 | asDynamic()[key] = value 122 | } 123 | } 124 | 125 | external class TelemetryNamespace { 126 | /** 127 | * Submits a custom ping to the Telemetry back-end. See submitExternalPing inside 128 | TelemetryController.jsm for more details. 129 | */ 130 | fun submitPing( 131 | type: String, 132 | message: Message, 133 | options: Options 134 | ): Promise 135 | 136 | /** 137 | * Checks if Telemetry is enabled. 138 | */ 139 | fun canUpload(): Promise 140 | 141 | /** 142 | * Adds the value to the given scalar. 143 | */ 144 | fun scalarAdd(name: String, value: Int): Promise 145 | 146 | /** 147 | * Sets the named scalar to the given value. Throws if the value type doesn't match the scalar 148 | type. 149 | */ 150 | fun scalarSet(name: String, value: String): Promise 151 | 152 | /** 153 | * Sets the named scalar to the given value. Throws if the value type doesn't match the scalar 154 | type. 155 | */ 156 | fun scalarSet(name: String, value: Boolean): Promise 157 | 158 | /** 159 | * Sets the named scalar to the given value. Throws if the value type doesn't match the scalar 160 | type. 161 | */ 162 | fun scalarSet(name: String, value: Int): Promise 163 | 164 | /** 165 | * Sets the named scalar to the given value. Throws if the value type doesn't match the scalar 166 | type. 167 | */ 168 | fun scalarSet(name: String, value: Value): Promise 169 | 170 | /** 171 | * Sets the scalar to the maximum of the current and the passed value 172 | */ 173 | fun scalarSetMaximum(name: String, value: Int): Promise 174 | 175 | /** 176 | * Record an event in Telemetry. Throws when trying to record an unknown event. 177 | */ 178 | fun recordEvent( 179 | category: String, 180 | method: String, 181 | `object`: String, 182 | value: Int? = definedExternally, 183 | extra: Extra? = definedExternally 184 | ): Promise 185 | 186 | /** 187 | * Register new scalars to record them from addons. See nsITelemetry.idl for more details. 188 | */ 189 | fun registerScalars(category: String, data: Data): Promise 190 | 191 | /** 192 | * Register new events to record them from addons. See nsITelemetry.idl for more details. 193 | */ 194 | fun registerEvents(category: String, data: Data2): Promise 195 | 196 | /** 197 | * Enable recording of events in a category. Events default to recording disabled. This allows 198 | to toggle recording for all events in the specified category. 199 | */ 200 | fun setEventRecordingEnabled(category: String, enabled: Boolean): Promise 201 | } 202 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/sidebarAction/sidebarAction.kt: -------------------------------------------------------------------------------- 1 | package sidebarAction 2 | 3 | import kotlin.Suppress 4 | import kotlin.js.Promise 5 | 6 | /** 7 | * Pixel data for an image. Must be an ImageData object (for example, from a canvas 8 | element). 9 | */ 10 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 11 | class ImageDataType() { 12 | inline operator fun get(key: String): dynamic = asDynamic()[key] 13 | inline operator fun set(key: String, value: dynamic) { 14 | asDynamic()[key] = value 15 | } 16 | } 17 | 18 | /** 19 | * The string the sidebar action should display when moused over. */ 20 | typealias Title = Any 21 | 22 | /** 23 | * @param title The string the sidebar action should display when moused over. 24 | * @param tabId Sets the sidebar title for the tab specified by tabId. Automatically resets when the 25 | tab is closed. 26 | * @param windowId Sets the sidebar title for the window specified by windowId. 27 | */ 28 | class Details( 29 | var title: Title, 30 | var tabId: Int? = null, 31 | var windowId: Int? = null 32 | ) 33 | 34 | /** 35 | * @param tabId Specify the tab to get the title from. If no tab nor window is specified, the global 36 | title is returned. 37 | * @param windowId Specify the window to get the title from. If no tab nor window is specified, the 38 | global title is returned. 39 | */ 40 | class Details2( 41 | var tabId: Int? = null, 42 | var windowId: Int? = null 43 | ) 44 | 45 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 46 | class ImageData() { 47 | inline operator fun get(key: String): ImageDataType = asDynamic()[key] 48 | inline operator fun set(key: String, value: ImageDataType) { 49 | asDynamic()[key] = value 50 | } 51 | } 52 | 53 | /** 54 | * Either an ImageData object or a dictionary {size -> ImageData} representing icon to be set. If 55 | the icon is specified as a dictionary, the actual image to be used is chosen depending on 56 | screen's pixel density. If the number of image pixels that fit into one screen space unit 57 | equals scale, then image with size scale * 19 will be selected. 58 | Initially only scales 1 and 2 will be supported. At least one image must be specified. Note 59 | that 'details.imageData = foo' is equivalent to 'details.imageData = {'19': foo}' */ 60 | typealias ImageData2 = Any 61 | 62 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 63 | class Path() { 64 | inline operator fun get(key: String): String = asDynamic()[key] 65 | inline operator fun set(key: String, value: String) { 66 | asDynamic()[key] = value 67 | } 68 | } 69 | 70 | /** 71 | * Either a relative image path or a dictionary {size -> relative image path} pointing to icon to be 72 | set. If the icon is specified as a dictionary, the actual image to be used is chosen 73 | depending on screen's pixel density. If the number of image pixels that fit into one screen 74 | space unit equals scale, then image with size scale * 19 will be 75 | selected. Initially only scales 1 and 2 will be supported. At least one image must be 76 | specified. Note that 'details.path = foo' is equivalent to 'details.imageData = {'19': foo}' 77 | */ 78 | typealias Path2 = Any 79 | 80 | /** 81 | * @param imageData Either an ImageData object or a dictionary {size -> ImageData} representing icon 82 | to be set. If the icon is specified as a dictionary, the actual image to be used is chosen 83 | depending on screen's pixel density. If the number of image pixels that fit into one screen 84 | space unit equals scale, then image with size scale * 19 will be 85 | selected. Initially only scales 1 and 2 will be supported. At least one image must be 86 | specified. Note that 'details.imageData = foo' is equivalent to 'details.imageData = {'19': 87 | foo}' 88 | * @param path Either a relative image path or a dictionary {size -> relative image path} pointing 89 | to icon to be set. If the icon is specified as a dictionary, the actual image to be used is 90 | chosen depending on screen's pixel density. If the number of image pixels that fit into one 91 | screen space unit equals scale, then image with size scale * 19 92 | will be selected. Initially only scales 1 and 2 will be supported. At least one image must 93 | be specified. Note that 'details.path = foo' is equivalent to 'details.imageData = {'19': 94 | foo}' 95 | * @param tabId Sets the sidebar icon for the tab specified by tabId. Automatically resets when the 96 | tab is closed. 97 | * @param windowId Sets the sidebar icon for the window specified by windowId. 98 | */ 99 | class Details3( 100 | var imageData: ImageData2? = null, 101 | var path: Path2? = null, 102 | var tabId: Int? = null, 103 | var windowId: Int? = null 104 | ) 105 | 106 | /** 107 | * The url to the html file to show in a sidebar. If set to the empty string (''), no sidebar is 108 | shown. */ 109 | typealias Panel = Any 110 | 111 | /** 112 | * @param tabId Sets the sidebar url for the tab specified by tabId. Automatically resets when the 113 | tab is closed. 114 | * @param windowId Sets the sidebar url for the window specified by windowId. 115 | * @param panel The url to the html file to show in a sidebar. If set to the empty string (''), no 116 | sidebar is shown. 117 | */ 118 | class Details4( 119 | var tabId: Int? = null, 120 | var windowId: Int? = null, 121 | var panel: Panel 122 | ) 123 | 124 | /** 125 | * @param tabId Specify the tab to get the panel from. If no tab nor window is specified, the global 126 | panel is returned. 127 | * @param windowId Specify the window to get the panel from. If no tab nor window is specified, the 128 | global panel is returned. 129 | */ 130 | class Details5( 131 | var tabId: Int? = null, 132 | var windowId: Int? = null 133 | ) 134 | 135 | /** 136 | * @param windowId Specify the window to get the openness from. 137 | */ 138 | class Details6( 139 | var windowId: Int? = null 140 | ) 141 | 142 | external class SidebarActionNamespace { 143 | /** 144 | * Sets the title of the sidebar action. This shows up in the tooltip. 145 | */ 146 | fun setTitle(details: Details): Promise 147 | 148 | /** 149 | * Gets the title of the sidebar action. 150 | */ 151 | fun getTitle(details: Details2): Promise 152 | 153 | /** 154 | * Sets the icon for the sidebar action. The icon can be specified either as the path to an 155 | image file or as the pixel data from a canvas element, or as dictionary of either one of 156 | those. Either the path or the imageData property must 157 | be specified. 158 | */ 159 | fun setIcon(details: Details3): Promise 160 | 161 | /** 162 | * Sets the url to the html document to be opened in the sidebar when the user clicks on the 163 | sidebar action's icon. 164 | */ 165 | fun setPanel(details: Details4): Promise 166 | 167 | /** 168 | * Gets the url to the html document set as the panel for this sidebar action. 169 | */ 170 | fun getPanel(details: Details5): Promise 171 | 172 | /** 173 | * Opens the extension sidebar in the active window. 174 | */ 175 | fun open(): Promise 176 | 177 | /** 178 | * Closes the extension sidebar in the active window if the sidebar belongs to the extension. 179 | */ 180 | fun close(): Promise 181 | 182 | /** 183 | * Checks whether the sidebar action is open. 184 | */ 185 | fun isOpen(details: Details6): Promise 186 | } 187 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/bookmarks/bookmarks.kt: -------------------------------------------------------------------------------- 1 | package bookmarks 2 | 3 | import kotlin.js.Promise 4 | import webextensions.Event 5 | 6 | /** 7 | * Indicates the reason why this node is unmodifiable. The managed value indicates that 8 | this node was configured by the system administrator or by the custodian of a supervised 9 | user. Omitted if the node can be modified by the user and the extension (default). */ 10 | typealias BookmarkTreeNodeUnmodifiable = String 11 | 12 | /** 13 | * Indicates the type of a BookmarkTreeNode, which can be one of bookmark, folder or separator. */ 14 | typealias BookmarkTreeNodeType = String 15 | 16 | /** 17 | * A node (either a bookmark or a folder) in the bookmark tree. Child nodes are ordered within 18 | their parent folder. 19 | * @param id The unique identifier for the node. IDs are unique within the current profile, and they 20 | remain valid even after the browser is restarted. 21 | * @param parentId The id of the parent folder. Omitted for the root node. 22 | * @param index The 0-based position of this node within its parent folder. 23 | * @param url The URL navigated to when a user clicks the bookmark. Omitted for folders. 24 | * @param title The text displayed for the node. 25 | * @param dateAdded When this node was created, in milliseconds since the epoch (new 26 | Date(dateAdded)). 27 | * @param dateGroupModified When the contents of this folder last changed, in milliseconds since the 28 | epoch. 29 | * @param unmodifiable Indicates the reason why this node is unmodifiable. The managed 30 | value indicates that this node was configured by the system administrator or by the 31 | custodian of a supervised user. Omitted if the node can be modified by the user and the 32 | extension (default). 33 | * @param type Indicates the type of the BookmarkTreeNode, which can be one of bookmark, folder or 34 | separator. 35 | * @param children An ordered list of children of this node. 36 | */ 37 | class BookmarkTreeNode( 38 | var id: String, 39 | var parentId: String? = null, 40 | var index: Int? = null, 41 | var url: String? = null, 42 | var title: String, 43 | var dateAdded: Float? = null, 44 | var dateGroupModified: Float? = null, 45 | var unmodifiable: BookmarkTreeNodeUnmodifiable? = null, 46 | var type: BookmarkTreeNodeType? = null, 47 | var children: Array? = null 48 | ) 49 | 50 | /** 51 | * Object passed to the create() function. 52 | * @param parentId Defaults to the Other Bookmarks folder. 53 | * @param type Indicates the type of BookmarkTreeNode to create, which can be one of bookmark, 54 | folder or separator. 55 | */ 56 | class CreateDetails( 57 | var parentId: String? = null, 58 | var index: Int? = null, 59 | var title: String? = null, 60 | var url: String? = null, 61 | var type: BookmarkTreeNodeType? = null 62 | ) 63 | 64 | /** 65 | * A single string-valued id, or an array of string-valued ids */ 66 | typealias IdOrIdList = Any 67 | 68 | /** 69 | * An object specifying properties and values to match when searching. Produces bookmarks matching 70 | all properties. 71 | * @param query A string of words and quoted phrases that are matched against bookmark URLs and 72 | titles. 73 | * @param url The URL of the bookmark; matches verbatim. Note that folders have no URL. 74 | * @param title The title of the bookmark; matches verbatim. 75 | */ 76 | class Query( 77 | var query: String? = null, 78 | var url: String? = null, 79 | var title: String? = null 80 | ) 81 | 82 | /** 83 | * Either a string of words and quoted phrases that are matched against bookmark URLs and titles, or 84 | an object. If an object, the properties query, url, and 85 | title may be specified and bookmarks matching all specified properties will be 86 | produced. */ 87 | typealias Query2 = Any 88 | 89 | class Destination(var parentId: String? = null, var index: Int? = null) 90 | 91 | class Changes(var title: String? = null, var url: String? = null) 92 | 93 | class RemoveInfo( 94 | var parentId: String, 95 | var index: Int, 96 | var node: BookmarkTreeNode 97 | ) 98 | 99 | class ChangeInfo(var title: String, var url: String? = null) 100 | 101 | class MoveInfo( 102 | var parentId: String, 103 | var index: Int, 104 | var oldParentId: String, 105 | var oldIndex: Int 106 | ) 107 | 108 | class ReorderInfo(var childIds: Array) 109 | 110 | external class BookmarksNamespace { 111 | /** 112 | * Fired when a bookmark or folder is created. 113 | * 114 | * @param id null 115 | * @param bookmark null */ 116 | val onCreated: Event<(id: String, bookmark: BookmarkTreeNode) -> Unit> 117 | 118 | /** 119 | * Fired when a bookmark or folder is removed. When a folder is removed recursively, a single 120 | notification is fired for the folder, and none for its contents. 121 | * 122 | * @param id null 123 | * @param removeInfo null */ 124 | val onRemoved: Event<(id: String, removeInfo: RemoveInfo) -> Unit> 125 | 126 | /** 127 | * Fired when a bookmark or folder changes. Note: Currently, only title and url changes 128 | trigger this. 129 | * 130 | * @param id null 131 | * @param changeInfo null */ 132 | val onChanged: Event<(id: String, changeInfo: ChangeInfo) -> Unit> 133 | 134 | /** 135 | * Fired when a bookmark or folder is moved to a different parent folder. 136 | * 137 | * @param id null 138 | * @param moveInfo null */ 139 | val onMoved: Event<(id: String, moveInfo: MoveInfo) -> Unit> 140 | 141 | /** 142 | * Retrieves the specified BookmarkTreeNode(s). 143 | */ 144 | fun get(idOrIdList: String): Promise> 145 | 146 | /** 147 | * Retrieves the specified BookmarkTreeNode(s). 148 | */ 149 | fun get(idOrIdList: Array): Promise> 150 | 151 | /** 152 | * Retrieves the children of the specified BookmarkTreeNode id. 153 | */ 154 | fun getChildren(id: String): Promise> 155 | 156 | /** 157 | * Retrieves the recently added bookmarks. 158 | */ 159 | fun getRecent(numberOfItems: Int): Promise> 160 | 161 | /** 162 | * Retrieves the entire Bookmarks hierarchy. 163 | */ 164 | fun getTree(): Promise> 165 | 166 | /** 167 | * Retrieves part of the Bookmarks hierarchy, starting at the specified node. 168 | */ 169 | fun getSubTree(id: String): Promise> 170 | 171 | /** 172 | * Searches for BookmarkTreeNodes matching the given query. Queries specified with an object 173 | produce BookmarkTreeNodes matching all specified properties. 174 | */ 175 | fun search(query: String): Promise> 176 | 177 | /** 178 | * Searches for BookmarkTreeNodes matching the given query. Queries specified with an object 179 | produce BookmarkTreeNodes matching all specified properties. 180 | */ 181 | fun search(query: Query): Promise> 182 | 183 | /** 184 | * Creates a bookmark or folder under the specified parentId. If url is NULL or missing, it 185 | will be a folder. 186 | */ 187 | fun create(bookmark: CreateDetails): Promise 188 | 189 | /** 190 | * Moves the specified BookmarkTreeNode to the provided location. 191 | */ 192 | fun move(id: String, destination: Destination): Promise 193 | 194 | /** 195 | * Updates the properties of a bookmark or folder. Specify only the properties that you want to 196 | change; unspecified properties will be left unchanged. Note: Currently, only 197 | 'title' and 'url' are supported. 198 | */ 199 | fun update(id: String, changes: Changes): Promise 200 | 201 | /** 202 | * Removes a bookmark or an empty bookmark folder. 203 | */ 204 | fun remove(id: String): Promise 205 | 206 | /** 207 | * Recursively removes a bookmark folder. 208 | */ 209 | fun removeTree(id: String): Promise 210 | } 211 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/browserAction/browserAction.kt: -------------------------------------------------------------------------------- 1 | package browserAction 2 | 3 | import kotlin.Suppress 4 | import kotlin.js.Promise 5 | import tabs.Tab 6 | import webextensions.Event 7 | 8 | /** 9 | * Specifies to which tab or window the value should be set, or from which one it should be 10 | retrieved. If no tab nor window is specified, the global value is set or retrieved. 11 | * @param tabId When setting a value, it will be specific to the specified tab, and will 12 | automatically reset when the tab navigates. When getting, specifies the tab to get the value 13 | from; if there is no tab-specific value, the window one will be inherited. 14 | * @param windowId When setting a value, it will be specific to the specified window. When getting, 15 | specifies the window to get the value from; if there is no window-specific value, the global 16 | one will be inherited. 17 | */ 18 | class Details( 19 | var tabId: Int? = null, 20 | var windowId: Int? = null 21 | ) 22 | 23 | typealias ColorArray = Array 24 | 25 | /** 26 | * Pixel data for an image. Must be an ImageData object (for example, from a canvas 27 | element). 28 | */ 29 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 30 | class ImageDataType() { 31 | inline operator fun get(key: String): dynamic = asDynamic()[key] 32 | inline operator fun set(key: String, value: dynamic) { 33 | asDynamic()[key] = value 34 | } 35 | } 36 | 37 | /** 38 | * An array of four integers in the range [0,255] that make up the RGBA color of the badge. For 39 | example, opaque red is [255, 0, 0, 255]. Can also be a string with a CSS value, 40 | with opaque red being #FF0000 or #F00. */ 41 | typealias ColorValue = Any 42 | 43 | /** 44 | * The string the browser action should display when moused over. */ 45 | typealias Title = Any 46 | 47 | /** 48 | * @param title The string the browser action should display when moused over. 49 | */ 50 | class Details2( 51 | var title: Title 52 | ) 53 | 54 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 55 | class ImageData() { 56 | inline operator fun get(key: String): ImageDataType = asDynamic()[key] 57 | inline operator fun set(key: String, value: ImageDataType) { 58 | asDynamic()[key] = value 59 | } 60 | } 61 | 62 | /** 63 | * Either an ImageData object or a dictionary {size -> ImageData} representing icon to be set. If 64 | the icon is specified as a dictionary, the actual image to be used is chosen depending on 65 | screen's pixel density. If the number of image pixels that fit into one screen space unit 66 | equals scale, then image with size scale * 19 will be selected. 67 | Initially only scales 1 and 2 will be supported. At least one image must be specified. Note 68 | that 'details.imageData = foo' is equivalent to 'details.imageData = {'19': foo}' */ 69 | typealias ImageData2 = Any 70 | 71 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 72 | class Path() { 73 | inline operator fun get(key: String): String = asDynamic()[key] 74 | inline operator fun set(key: String, value: String) { 75 | asDynamic()[key] = value 76 | } 77 | } 78 | 79 | /** 80 | * Either a relative image path or a dictionary {size -> relative image path} pointing to icon to be 81 | set. If the icon is specified as a dictionary, the actual image to be used is chosen 82 | depending on screen's pixel density. If the number of image pixels that fit into one screen 83 | space unit equals scale, then image with size scale * 19 will be 84 | selected. Initially only scales 1 and 2 will be supported. At least one image must be 85 | specified. Note that 'details.path = foo' is equivalent to 'details.imageData = {'19': foo}' 86 | */ 87 | typealias Path2 = Any 88 | 89 | /** 90 | * @param imageData Either an ImageData object or a dictionary {size -> ImageData} representing icon 91 | to be set. If the icon is specified as a dictionary, the actual image to be used is chosen 92 | depending on screen's pixel density. If the number of image pixels that fit into one screen 93 | space unit equals scale, then image with size scale * 19 will be 94 | selected. Initially only scales 1 and 2 will be supported. At least one image must be 95 | specified. Note that 'details.imageData = foo' is equivalent to 'details.imageData = {'19': 96 | foo}' 97 | * @param path Either a relative image path or a dictionary {size -> relative image path} pointing 98 | to icon to be set. If the icon is specified as a dictionary, the actual image to be used is 99 | chosen depending on screen's pixel density. If the number of image pixels that fit into one 100 | screen space unit equals scale, then image with size scale * 19 101 | will be selected. Initially only scales 1 and 2 will be supported. At least one image must 102 | be specified. Note that 'details.path = foo' is equivalent to 'details.imageData = {'19': 103 | foo}' 104 | */ 105 | class Details3( 106 | var imageData: ImageData2? = null, 107 | var path: Path2? = null 108 | ) 109 | 110 | /** 111 | * The html file to show in a popup. If set to the empty string (''), no popup is shown. */ 112 | typealias Popup = Any 113 | 114 | /** 115 | * @param popup The html file to show in a popup. If set to the empty string (''), no popup is 116 | shown. 117 | */ 118 | class Details4( 119 | var popup: Popup 120 | ) 121 | 122 | /** 123 | * Any number of characters can be passed, but only about four can fit in the space. */ 124 | typealias Text = Any 125 | 126 | /** 127 | * @param text Any number of characters can be passed, but only about four can fit in the space. 128 | */ 129 | class Details5( 130 | var text: Text 131 | ) 132 | 133 | class Details6(var color: ColorValue) 134 | 135 | class Details7(var color: ColorValue) 136 | 137 | external class BrowserActionNamespace { 138 | /** 139 | * Fired when a browser action icon is clicked. This event will not fire if the browser action 140 | has a popup. 141 | * 142 | * @param tab null */ 143 | val onClicked: Event<(tab: Tab) -> Unit> 144 | 145 | /** 146 | * Sets the title of the browser action. This shows up in the tooltip. 147 | */ 148 | fun setTitle(details: Details2): Promise 149 | 150 | /** 151 | * Gets the title of the browser action. 152 | */ 153 | fun getTitle(details: Details): Promise 154 | 155 | /** 156 | * Sets the icon for the browser action. The icon can be specified either as the path to an 157 | image file or as the pixel data from a canvas element, or as dictionary of either one of 158 | those. Either the path or the imageData property must be specified. 159 | */ 160 | fun setIcon(details: Details3): Promise 161 | 162 | /** 163 | * Sets the html document to be opened as a popup when the user clicks on the browser action's 164 | icon. 165 | */ 166 | fun setPopup(details: Details4): Promise 167 | 168 | /** 169 | * Gets the html document set as the popup for this browser action. 170 | */ 171 | fun getPopup(details: Details): Promise 172 | 173 | /** 174 | * Sets the badge text for the browser action. The badge is displayed on top of the icon. 175 | */ 176 | fun setBadgeText(details: Details5): Promise 177 | 178 | /** 179 | * Gets the badge text of the browser action. If no tab nor window is specified is specified, 180 | the global badge text is returned. 181 | */ 182 | fun getBadgeText(details: Details): Promise 183 | 184 | /** 185 | * Sets the background color for the badge. 186 | */ 187 | fun setBadgeBackgroundColor(details: Details6): Promise 188 | 189 | /** 190 | * Gets the background color of the browser action badge. 191 | */ 192 | fun getBadgeBackgroundColor(details: Details): Promise 193 | 194 | /** 195 | * Sets the text color for the badge. 196 | */ 197 | fun setBadgeTextColor(details: Details7): Promise 198 | 199 | /** 200 | * Gets the text color of the browser action badge. 201 | */ 202 | fun getBadgeTextColor(details: Details): Promise 203 | 204 | /** 205 | * Enables the browser action for a tab. By default, browser actions are enabled. 206 | */ 207 | fun enable(tabId: Int? = definedExternally): Promise 208 | 209 | /** 210 | * Disables the browser action for a tab. 211 | */ 212 | fun disable(tabId: Int? = definedExternally): Promise 213 | 214 | /** 215 | * Checks whether the browser action is enabled. 216 | */ 217 | fun isEnabled(details: Details): Promise 218 | 219 | /** 220 | * Opens the extension popup window in the active window. 221 | */ 222 | fun openPopup(): Promise 223 | } 224 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/devtools/devtools.kt: -------------------------------------------------------------------------------- 1 | package devtools 2 | 3 | import manifest.ExtensionURL 4 | import webextensions.Event 5 | import kotlin.js.Promise 6 | 7 | /** 8 | * Set to undefined if the resource content was set successfully; describes error otherwise. 9 | */ 10 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 11 | class Error() { 12 | inline operator fun get(key: String): dynamic = asDynamic()[key] 13 | inline operator fun set(key: String, value: dynamic) { 14 | asDynamic()[key] = value 15 | } 16 | } 17 | 18 | /** 19 | * A resource within the inspected page, such as a document, a script, or an image. 20 | */ 21 | external class Resource { 22 | /** 23 | * The URL of the resource. 24 | */ 25 | var url: String 26 | 27 | /** 28 | * Gets the content of the resource. 29 | */ 30 | fun getContent(): Promise 31 | 32 | /** 33 | * Sets the content of the resource. 34 | */ 35 | fun setContent(content: String, commit: Boolean): Promise 36 | } 37 | 38 | /** 39 | * The options parameter can contain one or more options. 40 | */ 41 | class Options() 42 | 43 | /** 44 | * An object providing details if an exception occurred while evaluating the expression. 45 | * @param isError Set if the error occurred on the DevTools side before the expression is evaluated. 46 | * @param code Set if the error occurred on the DevTools side before the expression is evaluated. 47 | * @param description Set if the error occurred on the DevTools side before the expression is 48 | evaluated. 49 | * @param details Set if the error occurred on the DevTools side before the expression is evaluated, 50 | contains the array of the values that may be substituted into the description string to 51 | provide more information about the cause of the error. 52 | * @param isException Set if the evaluated code produces an unhandled exception. 53 | * @param value Set if the evaluated code produces an unhandled exception. 54 | */ 55 | class ExceptionInfo( 56 | var isError: Boolean, 57 | var code: String, 58 | var description: String, 59 | var details: Array, 60 | var isException: Boolean, 61 | var value: String 62 | ) 63 | 64 | /** 65 | * @param ignoreCache When true, the loader will bypass the cache for all inspected page resources 66 | loaded before the load event is fired. The effect is similar to pressing 67 | Ctrl+Shift+R in the inspected window or within the Developer Tools window. 68 | * @param userAgent If specified, the string will override the value of the User-Agent 69 | HTTP header that's sent while loading the resources of the inspected page. The string will 70 | also override the value of the navigator.userAgent property that's returned to 71 | any scripts that are running within the inspected page. 72 | * @param injectedScript If specified, the script will be injected into every frame of the inspected 73 | page immediately upon load, before any of the frame's scripts. The script will not be 74 | injected after subsequent reloads—for example, if the user presses Ctrl+R. 75 | */ 76 | class ReloadOptions( 77 | var ignoreCache: Boolean? = null, 78 | var userAgent: String? = null, 79 | var injectedScript: String? = null 80 | ) 81 | 82 | external class InspectedWindowNamespace { 83 | /** 84 | * The ID of the tab being inspected. This ID may be used with chrome.tabs.* API. 85 | */ 86 | var tabId: Int 87 | 88 | /** 89 | * Evaluates a JavaScript expression in the context of the main frame of the inspected page. The 90 | expression must evaluate to a JSON-compliant object, otherwise an exception is thrown. 91 | The eval function can report either a DevTools-side error or a JavaScript exception that 92 | occurs during evaluation. In either case, the result parameter of the 93 | callback is undefined. In the case of a DevTools-side error, the 94 | isException parameter is non-null and has isError set to true 95 | and code set to an error code. In the case of a JavaScript error, 96 | isException is set to true and value is set to the string 97 | value of thrown object. 98 | */ 99 | fun eval(expression: String, options: Options? = definedExternally): Promise 100 | 101 | /** 102 | * Reloads the inspected page. 103 | */ 104 | fun reload(reloadOptions: ReloadOptions? = definedExternally) 105 | } 106 | 107 | /** 108 | * Represents a network request for a document resource (script, image and so on). See HAR 109 | Specification for reference. 110 | */ 111 | external class Request { 112 | /** 113 | * Returns content of the response body. 114 | */ 115 | fun getContent(): Promise 116 | } 117 | 118 | /** 119 | * A HAR log. See HAR specification for details. 120 | */ 121 | @Suppress("NOTHING_TO_INLINE", "UnsafeCastFromDynamic") 122 | class HarLog() { 123 | inline operator fun get(key: String): dynamic = asDynamic()[key] 124 | inline operator fun set(key: String, value: dynamic) { 125 | asDynamic()[key] = value 126 | } 127 | } 128 | 129 | external class NetworkNamespace { 130 | /** 131 | * Fired when a network request is finished and all request data are available. 132 | * 133 | * @param request Description of a network request in the form of a HAR entry. See HAR 134 | specification for details. */ 135 | val onRequestFinished: Event<(request: Request) -> Unit> 136 | 137 | /** 138 | * Fired when the inspected window navigates to a new page. 139 | * 140 | * @param url URL of the new page. */ 141 | val onNavigated: Event<(url: String) -> Unit> 142 | 143 | /** 144 | * Returns HAR log that contains all known network requests. 145 | */ 146 | fun getHAR(): Promise 147 | } 148 | 149 | /** 150 | * Represents the Elements panel. 151 | */ 152 | external class ElementsPanel { 153 | /** 154 | * Creates a pane within panel's sidebar. 155 | */ 156 | fun createSidebarPane(title: String): Promise 157 | } 158 | 159 | /** 160 | * Represents the Sources panel. 161 | */ 162 | external class SourcesPanel { 163 | /** 164 | * Creates a pane within panel's sidebar. 165 | */ 166 | fun createSidebarPane(title: String, callback: (() -> Unit)? = definedExternally) 167 | } 168 | 169 | /** 170 | * Represents a panel created by extension. 171 | */ 172 | external class ExtensionPanel { 173 | /** 174 | * Appends a button to the status bar of the panel. 175 | */ 176 | fun createStatusBarButton( 177 | iconPath: String, 178 | tooltipText: String, 179 | disabled: Boolean 180 | ): Button 181 | } 182 | 183 | /** 184 | * A sidebar created by the extension. 185 | */ 186 | external class ExtensionSidebarPane { 187 | /** 188 | * Sets the height of the sidebar. 189 | */ 190 | fun setHeight(height: String) 191 | 192 | /** 193 | * Sets an expression that is evaluated within the inspected page. The result is displayed in 194 | the sidebar pane. 195 | */ 196 | fun setExpression(expression: String, rootTitle: String? = definedExternally): Promise 197 | 198 | /** 199 | * Sets a JSON-compliant object to be displayed in the sidebar pane. 200 | */ 201 | fun setObject(jsonObject: String, rootTitle: String? = definedExternally): Promise 202 | 203 | /** 204 | * Sets an HTML page to be displayed in the sidebar pane. 205 | */ 206 | fun setPage(path: ExtensionURL): Promise 207 | } 208 | 209 | /** 210 | * A button created by the extension. 211 | */ 212 | external class Button { 213 | /** 214 | * Updates the attributes of the button. If some of the arguments are omitted or 215 | null, the corresponding attributes are not updated. 216 | */ 217 | fun update( 218 | iconPath: String? = definedExternally, 219 | tooltipText: String? = definedExternally, 220 | disabled: Boolean? = definedExternally 221 | ) 222 | } 223 | 224 | /** 225 | * Path of the panel's icon relative to the extension directory, or an empty string to use the 226 | default extension icon as the panel icon. */ 227 | typealias IconPath = Any 228 | 229 | external class PanelsNamespace { 230 | /** 231 | * Fired when the devtools theme changes. 232 | * 233 | * @param themeName The name of the current devtools theme. */ 234 | val onThemeChanged: Event<(themeName: String) -> Unit> 235 | 236 | /** 237 | * Elements panel. 238 | */ 239 | var elements: ElementsPanel 240 | 241 | /** 242 | * Sources panel. 243 | */ 244 | var sources: SourcesPanel 245 | 246 | /** 247 | * The name of the current devtools theme. 248 | */ 249 | var themeName: String 250 | 251 | // /** 252 | // * Creates an extension panel. 253 | // */ 254 | // fun create( 255 | // title: String, 256 | // iconPath: String, 257 | // pagePath: ExtensionURL 258 | // ): Promise 259 | 260 | /** 261 | * Creates an extension panel. 262 | */ 263 | fun create( 264 | title: String, 265 | iconPath: ExtensionURL, 266 | pagePath: ExtensionURL 267 | ): Promise 268 | } 269 | 270 | external class DevtoolsNamespace { 271 | val inspectedWindow: InspectedWindowNamespace 272 | 273 | val network: NetworkNamespace 274 | 275 | val panels: PanelsNamespace 276 | } 277 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/webNavigation/webNavigation.kt: -------------------------------------------------------------------------------- 1 | package webNavigation 2 | 3 | import events.UrlFilter 4 | import kotlin.js.Promise 5 | import webextensions.Event 6 | 7 | /** 8 | * Cause of the navigation. The same transition types as defined in the history API are used. These 9 | are the same transition types as defined in the $(topic:transition_types)[history API] 10 | except with "start_page" in place of "auto_toplevel" (for 11 | backwards compatibility). */ 12 | typealias TransitionType = String 13 | 14 | typealias TransitionQualifier = String 15 | 16 | class EventUrlFilters(var url: Array) 17 | 18 | /** 19 | * Information about the frame to retrieve information about. 20 | * @param tabId The ID of the tab in which the frame is. 21 | * @param processId The ID of the process runs the renderer for this tab. 22 | * @param frameId The ID of the frame in the given tab. 23 | */ 24 | class Details( 25 | var tabId: Int, 26 | var processId: Int? = null, 27 | var frameId: Int 28 | ) 29 | 30 | /** 31 | * Information about the requested frame, null if the specified frame ID and/or tab ID are invalid. 32 | * @param errorOccurred True if the last navigation in this frame was interrupted by an error, i.e. 33 | the onErrorOccurred event fired. 34 | * @param url The URL currently associated with this frame, if the frame identified by the frameId 35 | existed at one point in the given tab. The fact that an URL is associated with a given 36 | frameId does not imply that the corresponding frame still exists. 37 | * @param tabId The ID of the tab in which the frame is. 38 | * @param frameId The ID of the frame. 0 indicates that this is the main frame; a positive value 39 | indicates the ID of a subframe. 40 | * @param parentFrameId ID of frame that wraps the frame. Set to -1 of no parent frame exists. 41 | */ 42 | class Details2( 43 | var errorOccurred: Boolean? = null, 44 | var url: String, 45 | var tabId: Int, 46 | var frameId: Int, 47 | var parentFrameId: Int 48 | ) 49 | 50 | /** 51 | * Information about the tab to retrieve all frames from. 52 | * @param tabId The ID of the tab. 53 | */ 54 | class Details3( 55 | var tabId: Int 56 | ) 57 | 58 | /** 59 | * @param errorOccurred True if the last navigation in this frame was interrupted by an error, i.e. 60 | the onErrorOccurred event fired. 61 | * @param tabId The ID of the tab in which the frame is. 62 | * @param frameId The ID of the frame. 0 indicates that this is the main frame; a positive value 63 | indicates the ID of a subframe. 64 | * @param parentFrameId ID of frame that wraps the frame. Set to -1 of no parent frame exists. 65 | * @param url The URL currently associated with this frame. 66 | */ 67 | class Details4( 68 | var errorOccurred: Boolean? = null, 69 | var tabId: Int, 70 | var frameId: Int, 71 | var parentFrameId: Int, 72 | var url: String 73 | ) 74 | 75 | /** 76 | * @param tabId The ID of the tab in which the navigation is about to occur. 77 | * @param frameId 0 indicates the navigation happens in the tab content window; a positive value 78 | indicates navigation in a subframe. Frame IDs are unique for a given tab and process. 79 | * @param parentFrameId ID of frame that wraps the frame. Set to -1 of no parent frame exists. 80 | * @param timeStamp The time when the browser was about to start the navigation, in milliseconds 81 | since the epoch. 82 | */ 83 | class Details5( 84 | var tabId: Int, 85 | var url: String, 86 | var frameId: Int, 87 | var parentFrameId: Int, 88 | var timeStamp: Float 89 | ) 90 | 91 | /** 92 | * @param tabId The ID of the tab in which the navigation occurs. 93 | * @param frameId 0 indicates the navigation happens in the tab content window; a positive value 94 | indicates navigation in a subframe. Frame IDs are unique within a tab. 95 | * @param timeStamp The time when the navigation was committed, in milliseconds since the epoch. 96 | */ 97 | class Details6( 98 | var tabId: Int, 99 | var url: String, 100 | var frameId: Int, 101 | var timeStamp: Float 102 | ) 103 | 104 | /** 105 | * @param tabId The ID of the tab in which the navigation occurs. 106 | * @param frameId 0 indicates the navigation happens in the tab content window; a positive value 107 | indicates navigation in a subframe. Frame IDs are unique within a tab. 108 | * @param timeStamp The time when the page's DOM was fully constructed, in milliseconds since the 109 | epoch. 110 | */ 111 | class Details7( 112 | var tabId: Int, 113 | var url: String, 114 | var frameId: Int, 115 | var timeStamp: Float 116 | ) 117 | 118 | /** 119 | * @param tabId The ID of the tab in which the navigation occurs. 120 | * @param frameId 0 indicates the navigation happens in the tab content window; a positive value 121 | indicates navigation in a subframe. Frame IDs are unique within a tab. 122 | * @param timeStamp The time when the document finished loading, in milliseconds since the epoch. 123 | */ 124 | class Details8( 125 | var tabId: Int, 126 | var url: String, 127 | var frameId: Int, 128 | var timeStamp: Float 129 | ) 130 | 131 | /** 132 | * @param tabId The ID of the tab in which the navigation occurs. 133 | * @param frameId 0 indicates the navigation happens in the tab content window; a positive value 134 | indicates navigation in a subframe. Frame IDs are unique within a tab. 135 | * @param timeStamp The time when the error occurred, in milliseconds since the epoch. 136 | */ 137 | class Details9( 138 | var tabId: Int, 139 | var url: String, 140 | var frameId: Int, 141 | var timeStamp: Float 142 | ) 143 | 144 | /** 145 | * @param sourceTabId The ID of the tab in which the navigation is triggered. 146 | * @param sourceProcessId The ID of the process runs the renderer for the source tab. 147 | * @param sourceFrameId The ID of the frame with sourceTabId in which the navigation is triggered. 0 148 | indicates the main frame. 149 | * @param url The URL to be opened in the new window. 150 | * @param tabId The ID of the tab in which the url is opened 151 | * @param timeStamp The time when the browser was about to create a new view, in milliseconds since 152 | the epoch. 153 | */ 154 | class Details10( 155 | var sourceTabId: Int, 156 | var sourceProcessId: Int, 157 | var sourceFrameId: Int, 158 | var url: String, 159 | var tabId: Int, 160 | var timeStamp: Float 161 | ) 162 | 163 | /** 164 | * @param tabId The ID of the tab in which the navigation occurs. 165 | * @param frameId 0 indicates the navigation happens in the tab content window; a positive value 166 | indicates navigation in a subframe. Frame IDs are unique within a tab. 167 | * @param timeStamp The time when the navigation was committed, in milliseconds since the epoch. 168 | */ 169 | class Details11( 170 | var tabId: Int, 171 | var url: String, 172 | var frameId: Int, 173 | var timeStamp: Float 174 | ) 175 | 176 | /** 177 | * @param replacedTabId The ID of the tab that was replaced. 178 | * @param tabId The ID of the tab that replaced the old tab. 179 | * @param timeStamp The time when the replacement happened, in milliseconds since the epoch. 180 | */ 181 | class Details12( 182 | var replacedTabId: Int, 183 | var tabId: Int, 184 | var timeStamp: Float 185 | ) 186 | 187 | /** 188 | * @param tabId The ID of the tab in which the navigation occurs. 189 | * @param frameId 0 indicates the navigation happens in the tab content window; a positive value 190 | indicates navigation in a subframe. Frame IDs are unique within a tab. 191 | * @param timeStamp The time when the navigation was committed, in milliseconds since the epoch. 192 | */ 193 | class Details13( 194 | var tabId: Int, 195 | var url: String, 196 | var frameId: Int, 197 | var timeStamp: Float 198 | ) 199 | 200 | external class WebNavigationNamespace { 201 | /** 202 | * Fired when a navigation is about to occur. 203 | * 204 | * @param details null */ 205 | val onBeforeNavigate: Event<(details: Details5) -> Unit> 206 | 207 | /** 208 | * Fired when a navigation is committed. The document (and the resources it refers to, such as 209 | images and subframes) might still be downloading, but at least part of the document has 210 | been received from the server and the browser has decided to switch to the new document. 211 | * 212 | * @param details null */ 213 | val onCommitted: Event<(details: Details6) -> Unit> 214 | 215 | /** 216 | * Fired when the page's DOM is fully constructed, but the referenced resources may not finish 217 | loading. 218 | * 219 | * @param details null */ 220 | val onDOMContentLoaded: Event<(details: Details7) -> Unit> 221 | 222 | /** 223 | * Fired when a document, including the resources it refers to, is completely loaded and 224 | initialized. 225 | * 226 | * @param details null */ 227 | val onCompleted: Event<(details: Details8) -> Unit> 228 | 229 | /** 230 | * Fired when an error occurs and the navigation is aborted. This can happen if either a network 231 | error occurred, or the user aborted the navigation. 232 | * 233 | * @param details null */ 234 | val onErrorOccurred: Event<(details: Details9) -> Unit> 235 | 236 | /** 237 | * Fired when a new window, or a new tab in an existing window, is created to host a navigation. 238 | * 239 | * @param details null */ 240 | val onCreatedNavigationTarget: Event<(details: Details10) -> Unit> 241 | 242 | /** 243 | * Fired when the reference fragment of a frame was updated. All future events for that frame 244 | will use the updated URL. 245 | * 246 | * @param details null */ 247 | val onReferenceFragmentUpdated: Event<(details: Details11) -> Unit> 248 | 249 | /** 250 | * Fired when the contents of the tab is replaced by a different (usually previously 251 | pre-rendered) tab. 252 | * 253 | * @param details null */ 254 | val onTabReplaced: Event<(details: Details12) -> Unit> 255 | 256 | /** 257 | * Fired when the frame's history was updated to a new URL. All future events for that frame 258 | will use the updated URL. 259 | * 260 | * @param details null */ 261 | val onHistoryStateUpdated: Event<(details: Details13) -> Unit> 262 | 263 | /** 264 | * Retrieves information about the given frame. A frame refers to an <iframe> or a 265 | <frame> of a web page and is identified by a tab ID and a frame ID. 266 | */ 267 | fun getFrame(details: Details): Promise 268 | 269 | /** 270 | * Retrieves information about all frames of a given tab. 271 | */ 272 | fun getAllFrames(details: Details3): Promise?> 273 | } 274 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/cookies/cookies.kt: -------------------------------------------------------------------------------- 1 | package cookies 2 | 3 | import kotlin.js.Promise 4 | import webextensions.Event 5 | 6 | /** 7 | * A cookie's 'SameSite' state (https://tools.ietf.org/html/draft-west-first-party-cookies). 8 | 'no_restriction' corresponds to a cookie set without a 'SameSite' attribute, 'lax' to 9 | 'SameSite=Lax', and 'strict' to 'SameSite=Strict'. */ 10 | typealias SameSiteStatus = String 11 | 12 | /** 13 | * Represents information about an HTTP cookie. 14 | * @param name The name of the cookie. 15 | * @param value The value of the cookie. 16 | * @param domain The domain of the cookie (e.g. "www.google.com", "example.com"). 17 | * @param hostOnly True if the cookie is a host-only cookie (i.e. a request's host must exactly 18 | match the domain of the cookie). 19 | * @param path The path of the cookie. 20 | * @param secure True if the cookie is marked as Secure (i.e. its scope is limited to secure 21 | channels, typically HTTPS). 22 | * @param httpOnly True if the cookie is marked as HttpOnly (i.e. the cookie is inaccessible to 23 | client-side scripts). 24 | * @param sameSite The cookie's same-site status (i.e. whether the cookie is sent with cross-site 25 | requests). 26 | * @param session True if the cookie is a session cookie, as opposed to a persistent cookie with an 27 | expiration date. 28 | * @param expirationDate The expiration date of the cookie as the number of seconds since the UNIX 29 | epoch. Not provided for session cookies. 30 | * @param storeId The ID of the cookie store containing this cookie, as provided in 31 | getAllCookieStores(). 32 | * @param firstPartyDomain The first-party domain of the cookie. 33 | */ 34 | class Cookie( 35 | var name: String, 36 | var value: String, 37 | var domain: String, 38 | var hostOnly: Boolean, 39 | var path: String, 40 | var secure: Boolean, 41 | var httpOnly: Boolean, 42 | var sameSite: SameSiteStatus, 43 | var session: Boolean, 44 | var expirationDate: Float? = null, 45 | var storeId: String, 46 | var firstPartyDomain: String 47 | ) 48 | 49 | /** 50 | * Represents a cookie store in the browser. An incognito mode window, for instance, uses a separate 51 | cookie store from a non-incognito window. 52 | * @param id The unique identifier for the cookie store. 53 | * @param tabIds Identifiers of all the browser tabs that share this cookie store. 54 | * @param incognito Indicates if this is an incognito cookie store 55 | */ 56 | class CookieStore( 57 | var id: String, 58 | var tabIds: Array, 59 | var incognito: Boolean 60 | ) 61 | 62 | /** 63 | * The underlying reason behind the cookie's change. If a cookie was inserted, or removed via an 64 | explicit call to $(ref:cookies.remove), "cause" will be "explicit". If a cookie was 65 | automatically removed due to expiry, "cause" will be "expired". If a cookie was removed due 66 | to being overwritten with an already-expired expiration date, "cause" will be set to 67 | "expired_overwrite". If a cookie was automatically removed due to garbage collection, 68 | "cause" will be "evicted". If a cookie was automatically removed due to a "set" call that 69 | overwrote it, "cause" will be "overwrite". Plan your response accordingly. */ 70 | typealias OnChangedCause = String 71 | 72 | /** 73 | * Details to identify the cookie being retrieved. 74 | * @param url The URL with which the cookie to retrieve is associated. This argument may be a full 75 | URL, in which case any data following the URL path (e.g. the query string) is simply 76 | ignored. If host permissions for this URL are not specified in the manifest file, the API 77 | call will fail. 78 | * @param name The name of the cookie to retrieve. 79 | * @param storeId The ID of the cookie store in which to look for the cookie. By default, the 80 | current execution context's cookie store will be used. 81 | * @param firstPartyDomain The first-party domain which the cookie to retrieve is associated. This 82 | attribute is required if First-Party Isolation is enabled. 83 | */ 84 | class Details( 85 | var url: String, 86 | var name: String, 87 | var storeId: String? = null, 88 | var firstPartyDomain: String? = null 89 | ) 90 | 91 | /** 92 | * Information to filter the cookies being retrieved. 93 | * @param url Restricts the retrieved cookies to those that would match the given URL. 94 | * @param name Filters the cookies by name. 95 | * @param domain Restricts the retrieved cookies to those whose domains match or are subdomains of 96 | this one. 97 | * @param path Restricts the retrieved cookies to those whose path exactly matches this string. 98 | * @param secure Filters the cookies by their Secure property. 99 | * @param session Filters out session vs. persistent cookies. 100 | * @param storeId The cookie store to retrieve cookies from. If omitted, the current execution 101 | context's cookie store will be used. 102 | * @param firstPartyDomain Restricts the retrieved cookies to those whose first-party domains match 103 | this one. This attribute is required if First-Party Isolation is enabled. To not filter by a 104 | specific first-party domain, use `null` or `undefined`. 105 | */ 106 | class Details2( 107 | var url: String? = null, 108 | var name: String? = null, 109 | var domain: String? = null, 110 | var path: String? = null, 111 | var secure: Boolean? = null, 112 | var session: Boolean? = null, 113 | var storeId: String? = null, 114 | var firstPartyDomain: String 115 | ) 116 | 117 | /** 118 | * Details about the cookie being set. 119 | * @param url The request-URI to associate with the setting of the cookie. This value can affect the 120 | default domain and path values of the created cookie. If host permissions for this URL are 121 | not specified in the manifest file, the API call will fail. 122 | * @param name The name of the cookie. Empty by default if omitted. 123 | * @param value The value of the cookie. Empty by default if omitted. 124 | * @param domain The domain of the cookie. If omitted, the cookie becomes a host-only cookie. 125 | * @param path The path of the cookie. Defaults to the path portion of the url parameter. 126 | * @param secure Whether the cookie should be marked as Secure. Defaults to false. 127 | * @param httpOnly Whether the cookie should be marked as HttpOnly. Defaults to false. 128 | * @param sameSite The cookie's same-site status. 129 | * @param expirationDate The expiration date of the cookie as the number of seconds since the UNIX 130 | epoch. If omitted, the cookie becomes a session cookie. 131 | * @param storeId The ID of the cookie store in which to set the cookie. By default, the cookie is 132 | set in the current execution context's cookie store. 133 | * @param firstPartyDomain The first-party domain of the cookie. This attribute is required if 134 | First-Party Isolation is enabled. 135 | */ 136 | class Details3( 137 | var url: String, 138 | var name: String? = null, 139 | var value: String? = null, 140 | var domain: String? = null, 141 | var path: String? = null, 142 | var secure: Boolean? = null, 143 | var httpOnly: Boolean? = null, 144 | var sameSite: SameSiteStatus? = null, 145 | var expirationDate: Float? = null, 146 | var storeId: String? = null, 147 | var firstPartyDomain: String? = null 148 | ) 149 | 150 | /** 151 | * Information to identify the cookie to remove. 152 | * @param url The URL associated with the cookie. If host permissions for this URL are not specified 153 | in the manifest file, the API call will fail. 154 | * @param name The name of the cookie to remove. 155 | * @param storeId The ID of the cookie store to look in for the cookie. If unspecified, the cookie 156 | is looked for by default in the current execution context's cookie store. 157 | * @param firstPartyDomain The first-party domain associated with the cookie. This attribute is 158 | required if First-Party Isolation is enabled. 159 | */ 160 | class Details4( 161 | var url: String, 162 | var name: String, 163 | var storeId: String? = null, 164 | var firstPartyDomain: String? = null 165 | ) 166 | 167 | /** 168 | * Contains details about the cookie that's been removed. If removal failed for any reason, this 169 | will be "null", and $(ref:runtime.lastError) will be set. 170 | * @param url The URL associated with the cookie that's been removed. 171 | * @param name The name of the cookie that's been removed. 172 | * @param storeId The ID of the cookie store from which the cookie was removed. 173 | * @param firstPartyDomain The first-party domain associated with the cookie that's been removed. 174 | */ 175 | class Details5( 176 | var url: String, 177 | var name: String, 178 | var storeId: String, 179 | var firstPartyDomain: String 180 | ) 181 | 182 | /** 183 | * @param removed True if a cookie was removed. 184 | * @param cookie Information about the cookie that was set or removed. 185 | * @param cause The underlying reason behind the cookie's change. 186 | */ 187 | class ChangeInfo( 188 | var removed: Boolean, 189 | var cookie: Cookie, 190 | var cause: OnChangedCause 191 | ) 192 | 193 | external class CookiesNamespace { 194 | /** 195 | * Fired when a cookie is set or removed. As a special case, note that updating a cookie's 196 | properties is implemented as a two step process: the cookie to be updated is first 197 | removed entirely, generating a notification with "cause" of "overwrite" . Afterwards, a 198 | new cookie is written with the updated values, generating a second notification with 199 | "cause" "explicit". 200 | * 201 | * @param changeInfo null */ 202 | val onChanged: Event<(changeInfo: ChangeInfo) -> Unit> 203 | 204 | /** 205 | * Retrieves information about a single cookie. If more than one cookie of the same name exists 206 | for the given URL, the one with the longest path will be returned. For cookies with the 207 | same path length, the cookie with the earliest creation time will be returned. 208 | */ 209 | fun get(details: Details): Promise 210 | 211 | /** 212 | * Retrieves all cookies from a single cookie store that match the given information. The 213 | cookies returned will be sorted, with those with the longest path first. If multiple 214 | cookies have the same path length, those with the earliest creation time will be first. 215 | */ 216 | fun getAll(details: Details2): Promise> 217 | 218 | /** 219 | * Sets a cookie with the given cookie data; may overwrite equivalent cookies if they exist. 220 | */ 221 | fun set(details: Details3): Promise 222 | 223 | /** 224 | * Deletes a cookie by name. 225 | */ 226 | fun remove(details: Details4): Promise 227 | 228 | /** 229 | * Lists all existing cookie stores. 230 | */ 231 | fun getAllCookieStores(): Promise> 232 | } 233 | -------------------------------------------------------------------------------- /declarations/src/main/kotlin/windows/windows.kt: -------------------------------------------------------------------------------- 1 | package windows 2 | 3 | import kotlin.js.Promise 4 | import tabs.Tab 5 | import webextensions.Event 6 | 7 | /** 8 | * The type of browser window this is. Under some circumstances a Window may not be assigned type 9 | property, for example when querying closed windows from the $(ref:sessions) API. */ 10 | typealias WindowType = String 11 | 12 | /** 13 | * The state of this browser window. Under some circumstances a Window may not be assigned state 14 | property, for example when querying closed windows from the $(ref:sessions) API. */ 15 | typealias WindowState = String 16 | 17 | /** 18 | * @param id The ID of the window. Window IDs are unique within a browser session. Under some 19 | circumstances a Window may not be assigned an ID, for example when querying windows using 20 | the $(ref:sessions) API, in which case a session ID may be present. 21 | * @param focused Whether the window is currently the focused window. 22 | * @param top The offset of the window from the top edge of the screen in pixels. Under some 23 | circumstances a Window may not be assigned top property, for example when querying closed 24 | windows from the $(ref:sessions) API. 25 | * @param left The offset of the window from the left edge of the screen in pixels. Under some 26 | circumstances a Window may not be assigned left property, for example when querying closed 27 | windows from the $(ref:sessions) API. 28 | * @param width The width of the window, including the frame, in pixels. Under some circumstances a 29 | Window may not be assigned width property, for example when querying closed windows from the 30 | $(ref:sessions) API. 31 | * @param height The height of the window, including the frame, in pixels. Under some circumstances 32 | a Window may not be assigned height property, for example when querying closed windows from 33 | the $(ref:sessions) API. 34 | * @param tabs Array of $(ref:tabs.Tab) objects representing the current tabs in the window. 35 | * @param incognito Whether the window is incognito. 36 | * @param type The type of browser window this is. 37 | * @param state The state of this browser window. 38 | * @param alwaysOnTop Whether the window is set to be always on top. 39 | * @param sessionId The session ID used to uniquely identify a Window obtained from the 40 | $(ref:sessions) API. 41 | * @param title The title of the window. Read-only. 42 | */ 43 | class Window( 44 | var id: Int? = null, 45 | var focused: Boolean, 46 | var top: Int? = null, 47 | var left: Int? = null, 48 | var width: Int? = null, 49 | var height: Int? = null, 50 | var tabs: Array? = null, 51 | var incognito: Boolean, 52 | var type: WindowType? = null, 53 | var state: WindowState? = null, 54 | var alwaysOnTop: Boolean, 55 | var sessionId: String? = null, 56 | var title: String? = null 57 | ) 58 | 59 | /** 60 | * Specifies what type of browser window to create. The 'panel' and 'detached_panel' types create a 61 | popup unless the '--enable-panels' flag is set. */ 62 | typealias CreateType = String 63 | 64 | /** 65 | * Specifies whether the $(ref:windows.Window) returned should contain a list of the $(ref:tabs.Tab) 66 | objects. 67 | * @param populate If true, the $(ref:windows.Window) returned will have a tabs property 68 | that contains a list of the $(ref:tabs.Tab) objects. The Tab objects only 69 | contain the url, title and favIconUrl properties if 70 | the extension's manifest file includes the "tabs" permission. 71 | * @param windowTypes windowTypes is deprecated and ignored on Firefox. 72 | */ 73 | class GetInfo( 74 | var populate: Boolean? = null, 75 | var windowTypes: Array? = null 76 | ) 77 | 78 | /** 79 | * Specifies properties used to filter the $(ref:windows.Window) returned and to determine whether 80 | they should contain a list of the $(ref:tabs.Tab) objects. 81 | * @param windowTypes If set, the $(ref:windows.Window) returned will be filtered based on its type. 82 | If unset the default filter is set to ['app', 'normal', 'panel', 'popup'], with 83 | 'app' and 'panel' window types limited to the extension's own 84 | windows. 85 | */ 86 | class GetInfo2( 87 | var windowTypes: Array? = null 88 | ) 89 | 90 | /** 91 | * A URL or array of URLs to open as tabs in the window. Fully-qualified URLs must include a scheme 92 | (i.e. 'http://www.google.com', not 'www.google.com'). Relative URLs will be relative to the 93 | current page within the extension. Defaults to the New Tab Page. */ 94 | typealias Url = Any 95 | 96 | /** 97 | * @param url A URL or array of URLs to open as tabs in the window. Fully-qualified URLs must 98 | include a scheme (i.e. 'http://www.google.com', not 'www.google.com'). Relative URLs will be 99 | relative to the current page within the extension. Defaults to the New Tab Page. 100 | * @param tabId The id of the tab for which you want to adopt to the new window. 101 | * @param left The number of pixels to position the new window from the left edge of the screen. If 102 | not specified, the new window is offset naturally from the last focused window. This value 103 | is ignored for panels. 104 | * @param top The number of pixels to position the new window from the top edge of the screen. If 105 | not specified, the new window is offset naturally from the last focused window. This value 106 | is ignored for panels. 107 | * @param width The width in pixels of the new window, including the frame. If not specified 108 | defaults to a natural width. 109 | * @param height The height in pixels of the new window, including the frame. If not specified 110 | defaults to a natural height. 111 | * @param incognito Whether the new window should be an incognito window. 112 | * @param type Specifies what type of browser window to create. The 'panel' and 'detached_panel' 113 | types create a popup unless the '--enable-panels' flag is set. 114 | * @param state The initial state of the window. The 'minimized', 'maximized' and 'fullscreen' 115 | states cannot be combined with 'left', 'top', 'width' or 'height'. 116 | * @param allowScriptsToClose Allow scripts to close the window. 117 | * @param cookieStoreId The CookieStoreId to use for all tabs that were created when the window is 118 | opened. 119 | * @param titlePreface A string to add to the beginning of the window title. 120 | */ 121 | class CreateData( 122 | var url: Url? = null, 123 | var tabId: Int? = null, 124 | var left: Int? = null, 125 | var top: Int? = null, 126 | var width: Int? = null, 127 | var height: Int? = null, 128 | var incognito: Boolean? = null, 129 | var type: CreateType? = null, 130 | var state: WindowState? = null, 131 | var allowScriptsToClose: Boolean? = null, 132 | var cookieStoreId: String? = null, 133 | var titlePreface: String? = null 134 | ) 135 | 136 | /** 137 | * @param left The offset from the left edge of the screen to move the window to in pixels. This 138 | value is ignored for panels. 139 | * @param top The offset from the top edge of the screen to move the window to in pixels. This value 140 | is ignored for panels. 141 | * @param width The width to resize the window to in pixels. This value is ignored for panels. 142 | * @param height The height to resize the window to in pixels. This value is ignored for panels. 143 | * @param focused If true, brings the window to the front. If false, brings the next window in the 144 | z-order to the front. 145 | * @param drawAttention If true, causes the window to be displayed in a manner that draws the user's 146 | attention to the window, without changing the focused window. The effect lasts until the 147 | user changes focus to the window. This option has no effect if the window already has focus. 148 | Set to false to cancel a previous draw attention request. 149 | * @param state The new state of the window. The 'minimized', 'maximized' and 'fullscreen' states 150 | cannot be combined with 'left', 'top', 'width' or 'height'. 151 | * @param titlePreface A string to add to the beginning of the window title. 152 | */ 153 | class UpdateInfo( 154 | var left: Int? = null, 155 | var top: Int? = null, 156 | var width: Int? = null, 157 | var height: Int? = null, 158 | var focused: Boolean? = null, 159 | var drawAttention: Boolean? = null, 160 | var state: WindowState? = null, 161 | var titlePreface: String? = null 162 | ) 163 | 164 | external class WindowsNamespace { 165 | /** 166 | * Fired when a window is created. 167 | * 168 | * @param window Details of the window that was created. */ 169 | val onCreated: Event<(window: Window) -> Unit> 170 | 171 | /** 172 | * Fired when a window is removed (closed). 173 | * 174 | * @param windowId ID of the removed window. */ 175 | val onRemoved: Event<(windowId: Int) -> Unit> 176 | 177 | /** 178 | * Fired when the currently focused window changes. Will be $(ref:windows.WINDOW_ID_NONE) if all 179 | browser windows have lost focus. Note: On some Linux window managers, WINDOW_ID_NONE 180 | will always be sent immediately preceding a switch from one browser window to another. 181 | * 182 | * @param windowId ID of the newly focused window. */ 183 | val onFocusChanged: Event<(windowId: Int) -> Unit> 184 | 185 | /** 186 | * The windowId value that represents the absence of a browser window. 187 | */ 188 | var WINDOW_ID_NONE: Double 189 | 190 | /** 191 | * The windowId value that represents the $(topic:current-window)[current window]. 192 | */ 193 | var WINDOW_ID_CURRENT: Double 194 | 195 | /** 196 | * Gets details about a window. 197 | */ 198 | fun get(windowId: Int, getInfo: GetInfo? = definedExternally): Promise 199 | 200 | /** 201 | * Gets the $(topic:current-window)[current window]. 202 | */ 203 | fun getCurrent(getInfo: GetInfo? = definedExternally): Promise 204 | 205 | /** 206 | * Gets the window that was most recently focused — typically the window 'on top'. 207 | */ 208 | fun getLastFocused(getInfo: GetInfo? = definedExternally): Promise 209 | 210 | /** 211 | * Gets all windows. 212 | */ 213 | fun getAll(getInfo: GetInfo2? = definedExternally): Promise> 214 | 215 | /** 216 | * Creates (opens) a new browser with any optional sizing, position or default URL provided. 217 | */ 218 | fun create(createData: CreateData? = definedExternally): Promise 219 | 220 | /** 221 | * Updates the properties of a window. Specify only the properties that you want to change; 222 | unspecified properties will be left unchanged. 223 | */ 224 | fun update(windowId: Int, updateInfo: UpdateInfo): Promise 225 | 226 | /** 227 | * Removes (closes) a window, and all the tabs inside it. 228 | */ 229 | fun remove(windowId: Int): Promise 230 | } 231 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------