OLD | NEW |
| (Empty) |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 DEFAULT_WEB_CONTENTS_TIMEOUT = 60 | |
6 | |
7 # TODO(achuith, dtu, nduca): Add unit tests specifically for WebContents, | |
8 # independent of Tab. | |
9 class WebContents(object): | |
10 """Represents web contents in the browser""" | |
11 def __init__(self, inspector_backend): | |
12 self._inspector_backend = inspector_backend | |
13 | |
14 def __del__(self): | |
15 self.Disconnect() | |
16 | |
17 def Disconnect(self): | |
18 self._inspector_backend.Disconnect() | |
19 | |
20 def WaitForDocumentReadyStateToBeComplete(self, | |
21 timeout=DEFAULT_WEB_CONTENTS_TIMEOUT): | |
22 self._inspector_backend.WaitForDocumentReadyStateToBeComplete(timeout) | |
23 | |
24 def WaitForDocumentReadyStateToBeInteractiveOrBetter(self, | |
25 timeout=DEFAULT_WEB_CONTENTS_TIMEOUT): | |
26 self._inspector_backend.WaitForDocumentReadyStateToBeInteractiveOrBetter( | |
27 timeout) | |
28 | |
29 def ExecuteJavaScript(self, expr, timeout=DEFAULT_WEB_CONTENTS_TIMEOUT): | |
30 """Executes expr in JavaScript. Does not return the result. | |
31 | |
32 If the expression failed to evaluate, EvaluateException will be raised. | |
33 """ | |
34 self._inspector_backend.ExecuteJavaScript(expr, timeout) | |
35 | |
36 def EvaluateJavaScript(self, expr, timeout=DEFAULT_WEB_CONTENTS_TIMEOUT): | |
37 """Evalutes expr in JavaScript and returns the JSONized result. | |
38 | |
39 Consider using ExecuteJavaScript for cases where the result of the | |
40 expression is not needed. | |
41 | |
42 If evaluation throws in JavaScript, a Python EvaluateException will | |
43 be raised. | |
44 | |
45 If the result of the evaluation cannot be JSONized, then an | |
46 EvaluationException will be raised. | |
47 """ | |
48 return self._inspector_backend.EvaluateJavaScript(expr, timeout) | |
49 | |
50 @property | |
51 def message_output_stream(self): | |
52 return self._inspector_backend.message_output_stream | |
53 | |
54 @message_output_stream.setter | |
55 def message_output_stream(self, stream): | |
56 self._inspector_backend.message_output_stream = stream | |
57 | |
58 @property | |
59 def timeline_model(self): | |
60 return self._inspector_backend.timeline_model | |
61 | |
62 def StartTimelineRecording(self): | |
63 self._inspector_backend.StartTimelineRecording() | |
64 | |
65 def StopTimelineRecording(self): | |
66 self._inspector_backend.StopTimelineRecording() | |
OLD | NEW |