1424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)# Copyright 2013 The Chromium Authors. All rights reserved.
2c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)# Use of this source code is governed by a BSD-style license that can be
3c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)# found in the LICENSE file.
4c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
5010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)from telemetry.core import exceptions
6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)from telemetry.core.backends.chrome import inspector_backend_list
75c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liufrom telemetry.core.backends.chrome import oobe
8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
96e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class MiscWebContentsBackend(inspector_backend_list.InspectorBackendList):
11a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  """A dynamic sequence of web contents not related to tabs and extensions.
12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  Provides acccess to chrome://oobe/login page.
14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  """
15c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
16c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  def __init__(self, browser_backend):
17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    super(MiscWebContentsBackend, self).__init__(
18010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)        browser_backend, backend_wrapper=oobe.Oobe)
19c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  @property
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  def oobe_exists(self):
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    """Lightweight property to determine if the oobe webui is visible."""
23010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    try:
24010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      return bool(len(self))
25010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    except (exceptions.BrowserGoneException,
26010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)            exceptions.BrowserConnectionGoneException,
27010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)            exceptions.TabCrashException):
28010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      return False
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
30c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  def GetOobe(self):
31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    if not len(self):
32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      return None
33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return self[0]
34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  def ShouldIncludeContext(self, context):
36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return context.get('url').startswith('chrome://oobe')
37