forked from playwright-community/playwright-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchannel_owner.go
70 lines (62 loc) · 1.59 KB
/
channel_owner.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
package playwright
import (
"sync"
)
type channelOwner struct {
sync.RWMutex
eventEmitter
objectType string
guid string
channel *channel
objects map[string]*channelOwner
connection *connection
initializer map[string]interface{}
parent *channelOwner
}
func (c *channelOwner) dispose() {
// Clean up from parent and connection.
if c.parent != nil {
delete(c.parent.objects, c.guid)
}
delete(c.connection.objects, c.guid)
// Dispose all children.
for _, object := range c.objects {
object.dispose()
}
c.objects = make(map[string]*channelOwner)
}
func (c *channelOwner) createChannelOwner(self interface{}, parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) {
c.objectType = objectType
c.guid = guid
c.parent = parent
c.objects = make(map[string]*channelOwner)
c.initializer = initializer
if c.parent != nil {
c.connection = parent.connection
c.parent.objects[guid] = c
}
if c.connection != nil {
c.connection.objects[guid] = c
}
c.channel = newChannel(c.connection, guid)
c.channel.object = self
c.initEventEmitter()
}
type rootChannelOwner struct {
channelOwner
}
func (r *rootChannelOwner) initialize() (*Playwright, error) {
result, err := r.channel.Send("initialize", map[string]interface{}{
"sdkLanguage": "javascript",
})
if err != nil {
return nil, err
}
return fromChannel(result).(*Playwright), nil
}
func newRootChannelOwner(connection *connection) *rootChannelOwner {
c := &rootChannelOwner{}
c.connection = connection
c.createChannelOwner(c, nil, "Root", "", make(map[string]interface{}))
return c
}