-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathextension.go
76 lines (65 loc) · 2.76 KB
/
extension.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package chrome
import "github.com/gopherjs/gopherjs/js"
type Extension struct {
o *js.Object
LastError *js.Object
InIncognitoContext bool
}
func NewExtension(extensionObj *js.Object) *Extension {
e := new(Extension)
e.o = extensionObj
if extensionObj.String() != "undefined" {
e.LastError = e.o.Get("lastError")
e.InIncognitoContext = e.o.Get("inIncognitoContext").Bool()
}
return e
}
/*
* Methods:
*/
// GetURL converts a relative path within an extension install directory to a fully-qualified URL.
func (e *Extension) GetURL(path string) {
e.o.Call("getURL", path)
}
// GetViews returns an array of the JavaScript 'window' objects for each of the pages running inside the current extension.
// Fix this and the other functions to return Window objects instead of js.Object or whatever else
func (e *Extension) GetViews(fetchProperties Object) []Window {
windows := []Window{}
windowObjs := e.o.Call("getViews", fetchProperties)
for i := 0; i < windowObjs.Length(); i++ {
window := windowObjs.Index(i)
windows = append(windows, Window{Object: window})
}
return windows
}
// GetBackgroundPage returns the JavaScript 'window' object for the background page running inside
// the current extension. Returns null if the extension has no background page.
func (e *Extension) GetBackgroundPage() Window {
return Window{Object: e.o.Call("getBackgroundPage")}
}
// GetExtensionTabs returns an array of the JavaScript 'window' objects for each of the tabs running inside
// the current extension. If windowId is specified, returns only the 'window' objects of tabs attached to the specified window.
func (e *Extension) GetExtensionTabs(windowId int) []Window {
windows := []Window{}
windowObjs := e.o.Call("getExtensionTabs", windowId)
for i := 0; i < windowObjs.Length(); i++ {
window := windowObjs.Index(i)
windows = append(windows, Window{Object: window})
}
return windows
}
// IsAllowedIncognitoAccess retrieves the state of the extension's access to Incognito-mode
// (as determined by the user-controlled 'Allowed in Incognito' checkbox.
func (e *Extension) IsAllowedIncognitoAccess(callback func(isAllowedAccess bool)) {
e.o.Call("isAllowedIncognitoAccess", callback)
}
// IsAllowedFileSchemeAccess retrieves the state of the extension's access to the 'file://'
// scheme (as determined by the user-controlled 'Allow access to File URLs' checkbox.
func (e *Extension) IsAllowedFileSchemeAccess(callback func(isAllowedAccess bool)) {
e.o.Call("isAllowedFileSchemeAccess", callback)
}
// SetUpdateUrlData sets the value of the ap CGI parameter used in the extension's update URL.
// This value is ignored for extensions that are hosted in the Chrome Extension Gallery.
func (e *Extension) SetUpdateUrlData(data string) {
e.o.Call("setUpdateUrlData", data)
}