Home | History | Annotate | Download | only in core
      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 Close(self):
     21     """Closes this page.
     22 
     23     Not all browsers or browser versions support this method.
     24     Be sure to check browser.supports_tab_control."""
     25     self._inspector_backend.Close()
     26 
     27   def WaitForDocumentReadyStateToBeComplete(self,
     28       timeout=DEFAULT_WEB_CONTENTS_TIMEOUT):
     29     self._inspector_backend.WaitForDocumentReadyStateToBeComplete(timeout)
     30 
     31   def WaitForDocumentReadyStateToBeInteractiveOrBetter(self,
     32       timeout=DEFAULT_WEB_CONTENTS_TIMEOUT):
     33     self._inspector_backend.WaitForDocumentReadyStateToBeInteractiveOrBetter(
     34         timeout)
     35 
     36   def ExecuteJavaScript(self, expr, timeout=DEFAULT_WEB_CONTENTS_TIMEOUT):
     37     """Executes expr in JavaScript. Does not return the result.
     38 
     39     If the expression failed to evaluate, EvaluateException will be raised.
     40     """
     41     self._inspector_backend.ExecuteJavaScript(expr, timeout)
     42 
     43   def EvaluateJavaScript(self, expr, timeout=DEFAULT_WEB_CONTENTS_TIMEOUT):
     44     """Evalutes expr in JavaScript and returns the JSONized result.
     45 
     46     Consider using ExecuteJavaScript for cases where the result of the
     47     expression is not needed.
     48 
     49     If evaluation throws in JavaScript, a Python EvaluateException will
     50     be raised.
     51 
     52     If the result of the evaluation cannot be JSONized, then an
     53     EvaluationException will be raised.
     54     """
     55     return self._inspector_backend.EvaluateJavaScript(expr, timeout)
     56 
     57   @property
     58   def message_output_stream(self):
     59     return self._inspector_backend.message_output_stream
     60 
     61   @message_output_stream.setter
     62   def message_output_stream(self, stream):
     63     self._inspector_backend.message_output_stream = stream
     64 
     65   @property
     66   def timeline_model(self):
     67     return self._inspector_backend.timeline_model
     68 
     69   def StartTimelineRecording(self):
     70     self._inspector_backend.StartTimelineRecording()
     71 
     72   def StopTimelineRecording(self):
     73     self._inspector_backend.StopTimelineRecording()
     74