Skip to content

Commit 05eb3f0

Browse files
committed
Implement namespace properties and type methods
Fixes #24
1 parent 0e6829c commit 05eb3f0

File tree

22 files changed

+640
-43
lines changed

22 files changed

+640
-43
lines changed
Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package browserSettings
22

3+
import types.Setting
4+
35
/**
46
* How images should be animated in the browser. */
57
typealias ImageAnimationBehavior = String
@@ -8,4 +10,83 @@ typealias ImageAnimationBehavior = String
810
* After which mouse event context menus should popup. */
911
typealias ContextMenuMouseEvent = String
1012

11-
external class BrowserSettingsNamespace
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 <code>mouseup</code> and
32+
<code>mousedown</code>.
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 <code>normal</code>.
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+
}

declarations/src/main/kotlin/contentScripts/contentScripts.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,14 @@ class RegisteredContentScriptOptions(
3131
)
3232

3333
/**
34-
* An object that represents a content script registered programmatically */
35-
typealias RegisteredContentScript = Any
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<Any>
41+
}
3642

3743
external class ContentScriptsNamespace {
3844
/**

declarations/src/main/kotlin/devtools/devtools.kt

Lines changed: 119 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,36 @@ import manifest.ExtensionURL
44
import webextensions.Event
55
import kotlin.js.Promise
66

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+
718
/**
819
* A resource within the inspected page, such as a document, a script, or an image.
9-
* @param url The URL of the resource.
1020
*/
11-
class Resource(
21+
external class Resource {
22+
/**
23+
* The URL of the resource.
24+
*/
1225
var url: String
13-
)
26+
27+
/**
28+
* Gets the content of the resource.
29+
*/
30+
fun getContent(): Promise<String>
31+
32+
/**
33+
* Sets the content of the resource.
34+
*/
35+
fun setContent(content: String, commit: Boolean): Promise<Error?>
36+
}
1437

1538
/**
1639
* The options parameter can contain one or more options.
@@ -57,6 +80,11 @@ class ReloadOptions(
5780
)
5881

5982
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+
6088
/**
6189
* Evaluates a JavaScript expression in the context of the main frame of the inspected page. The
6290
expression must evaluate to a JSON-compliant object, otherwise an exception is thrown.
@@ -78,8 +106,14 @@ external class InspectedWindowNamespace {
78106

79107
/**
80108
* Represents a network request for a document resource (script, image and so on). See HAR
81-
Specification for reference. */
82-
typealias Request = Any
109+
Specification for reference.
110+
*/
111+
external class Request {
112+
/**
113+
* Returns content of the response body.
114+
*/
115+
fun getContent(): Promise<String>
116+
}
83117

84118
/**
85119
* A HAR log. See HAR specification for details.
@@ -113,24 +147,79 @@ external class NetworkNamespace {
113147
}
114148

115149
/**
116-
* Represents the Elements panel. */
117-
typealias ElementsPanel = Any
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<ExtensionSidebarPane>
157+
}
118158

119159
/**
120-
* Represents the Sources panel. */
121-
typealias SourcesPanel = Any
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+
}
122168

123169
/**
124-
* Represents a panel created by extension. */
125-
typealias ExtensionPanel = Any
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+
}
126182

127183
/**
128-
* A sidebar created by the extension. */
129-
typealias ExtensionSidebarPane = Any
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<Any>
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<Any>
202+
203+
/**
204+
* Sets an HTML page to be displayed in the sidebar pane.
205+
*/
206+
fun setPage(path: ExtensionURL): Promise<Any>
207+
}
130208

131209
/**
132-
* A button created by the extension. */
133-
typealias Button = Any
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+
<code>null</code>, the corresponding attributes are not updated.
216+
*/
217+
fun update(
218+
iconPath: String? = definedExternally,
219+
tooltipText: String? = definedExternally,
220+
disabled: Boolean? = definedExternally
221+
)
222+
}
134223

135224
/**
136225
* Path of the panel's icon relative to the extension directory, or an empty string to use the
@@ -144,6 +233,21 @@ external class PanelsNamespace {
144233
* @param themeName The name of the current devtools theme. */
145234
val onThemeChanged: Event<(themeName: String) -> Unit>
146235

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+
147251
// /**
148252
// * Creates an extension panel.
149253
// */

declarations/src/main/kotlin/events/events.kt

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,53 @@ class Rule(
1717
)
1818

1919
/**
20-
* An object which allows the addition and removal of listeners for a Chrome event. */
21-
typealias Event = Any
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 <em>callback</em> to an event.
25+
*/
26+
fun addListener(callback: () -> Unit)
27+
28+
/**
29+
* Deregisters an event listener <em>callback</em> 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<Rule>,
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<String>? = 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<String>? = definedExternally,
64+
callback: (() -> Unit)? = definedExternally
65+
)
66+
}
2267

2368
/**
2469
* Filters URLs for various criteria. See <a href='events#filtered'>event filtering</a>. All

declarations/src/main/kotlin/extension/extension.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ class GetBackgroundPageResult() {
5151
}
5252

5353
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 <var>undefined</var>.
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+
5467
/**
5568
* Converts a relative path within an extension install directory to a fully-qualified URL.
5669
*/

declarations/src/main/kotlin/manifest/manifest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package manifest
22

33
import experiments.ExperimentAPI
44
import extensionTypes.RunAt
5+
import kotlin.Suppress
56

67
typealias OptionalPermission = Any
78

declarations/src/main/kotlin/menus/menus.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ external class MenusNamespace {
247247
*/
248248
val onHidden: Event<() -> Unit>
249249

250+
/**
251+
* The maximum number of top level extension items that can be added to an extension action
252+
context menu. Any items beyond this limit will be ignored.
253+
*/
254+
var ACTION_MENU_TOP_LEVEL_LIMIT: Double
255+
250256
/**
251257
* Creates a new context menu item. Note that if an error occurs during creation, you may not
252258
find out until the creation callback fires (the details will be in

declarations/src/main/kotlin/permissions/permissions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package permissions
22

3+
import kotlin.js.Promise
34
import manifest.MatchPattern
45
import manifest.OptionalPermission
56
import manifest.Permission
6-
import kotlin.js.Promise
77

88
class Permissions(var permissions: Array<OptionalPermission>? = null, var origins:
99
Array<MatchPattern>? = null)

0 commit comments

Comments
 (0)