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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# DO NOT EDIT THIS FILE!
#
# This file is generated from the CDP specification. If you need to make
# changes, edit the generator and regenerate all of the modules.
#
# CDP domain: ApplicationCache (experimental)
from __future__ import annotations
from .util import event_class, T_JSON_DICT
from dataclasses import dataclass
import enum
import typing
from . import page
 
 
@dataclass
class ApplicationCacheResource:
    '''
    Detailed application cache resource information.
    '''
    #: Resource url.
    url: str
 
    #: Resource size.
    size: int
 
    #: Resource type.
    type_: str
 
    def to_json(self):
        json = dict()
        json['url'] = self.url
        json['size'] = self.size
        json['type'] = self.type_
        return json
 
    @classmethod
    def from_json(cls, json):
        return cls(
            url=str(json['url']),
            size=int(json['size']),
            type_=str(json['type']),
        )
 
 
@dataclass
class ApplicationCache:
    '''
    Detailed application cache information.
    '''
    #: Manifest URL.
    manifest_url: str
 
    #: Application cache size.
    size: float
 
    #: Application cache creation time.
    creation_time: float
 
    #: Application cache update time.
    update_time: float
 
    #: Application cache resources.
    resources: typing.List[ApplicationCacheResource]
 
    def to_json(self):
        json = dict()
        json['manifestURL'] = self.manifest_url
        json['size'] = self.size
        json['creationTime'] = self.creation_time
        json['updateTime'] = self.update_time
        json['resources'] = [i.to_json() for i in self.resources]
        return json
 
    @classmethod
    def from_json(cls, json):
        return cls(
            manifest_url=str(json['manifestURL']),
            size=float(json['size']),
            creation_time=float(json['creationTime']),
            update_time=float(json['updateTime']),
            resources=[ApplicationCacheResource.from_json(i) for i in json['resources']],
        )
 
 
@dataclass
class FrameWithManifest:
    '''
    Frame identifier - manifest URL pair.
    '''
    #: Frame identifier.
    frame_id: page.FrameId
 
    #: Manifest URL.
    manifest_url: str
 
    #: Application cache status.
    status: int
 
    def to_json(self):
        json = dict()
        json['frameId'] = self.frame_id.to_json()
        json['manifestURL'] = self.manifest_url
        json['status'] = self.status
        return json
 
    @classmethod
    def from_json(cls, json):
        return cls(
            frame_id=page.FrameId.from_json(json['frameId']),
            manifest_url=str(json['manifestURL']),
            status=int(json['status']),
        )
 
 
def enable() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
    '''
    Enables application cache domain notifications.
    '''
    cmd_dict: T_JSON_DICT = {
        'method': 'ApplicationCache.enable',
    }
    json = yield cmd_dict
 
 
def get_application_cache_for_frame(
        frame_id: page.FrameId
    ) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,ApplicationCache]:
    '''
    Returns relevant application cache data for the document in given frame.
 
    :param frame_id: Identifier of the frame containing document whose application cache is retrieved.
    :returns: Relevant application cache data for the document in given frame.
    '''
    params: T_JSON_DICT = dict()
    params['frameId'] = frame_id.to_json()
    cmd_dict: T_JSON_DICT = {
        'method': 'ApplicationCache.getApplicationCacheForFrame',
        'params': params,
    }
    json = yield cmd_dict
    return ApplicationCache.from_json(json['applicationCache'])
 
 
def get_frames_with_manifests() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,typing.List[FrameWithManifest]]:
    '''
    Returns array of frame identifiers with manifest urls for each frame containing a document
    associated with some application cache.
 
    :returns: Array of frame identifiers with manifest urls for each frame containing a document associated with some application cache.
    '''
    cmd_dict: T_JSON_DICT = {
        'method': 'ApplicationCache.getFramesWithManifests',
    }
    json = yield cmd_dict
    return [FrameWithManifest.from_json(i) for i in json['frameIds']]
 
 
def get_manifest_for_frame(
        frame_id: page.FrameId
    ) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,str]:
    '''
    Returns manifest URL for document in the given frame.
 
    :param frame_id: Identifier of the frame containing document whose manifest is retrieved.
    :returns: Manifest URL for document in the given frame.
    '''
    params: T_JSON_DICT = dict()
    params['frameId'] = frame_id.to_json()
    cmd_dict: T_JSON_DICT = {
        'method': 'ApplicationCache.getManifestForFrame',
        'params': params,
    }
    json = yield cmd_dict
    return str(json['manifestURL'])
 
 
@event_class('ApplicationCache.applicationCacheStatusUpdated')
@dataclass
class ApplicationCacheStatusUpdated:
    #: Identifier of the frame containing document whose application cache updated status.
    frame_id: page.FrameId
    #: Manifest URL.
    manifest_url: str
    #: Updated application cache status.
    status: int
 
    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> ApplicationCacheStatusUpdated:
        return cls(
            frame_id=page.FrameId.from_json(json['frameId']),
            manifest_url=str(json['manifestURL']),
            status=int(json['status'])
        )
 
 
@event_class('ApplicationCache.networkStateUpdated')
@dataclass
class NetworkStateUpdated:
    is_now_online: bool
 
    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> NetworkStateUpdated:
        return cls(
            is_now_online=bool(json['isNowOnline'])
        )