| Index: tools/chrome_remote_control/chrome_remote_control/credentials_backend.py
|
| diff --git a/tools/chrome_remote_control/chrome_remote_control/credentials_backend.py b/tools/chrome_remote_control/chrome_remote_control/credentials_backend.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c4dac87875161daddd105f98bcde20a09a0dfc15
|
| --- /dev/null
|
| +++ b/tools/chrome_remote_control/chrome_remote_control/credentials_backend.py
|
| @@ -0,0 +1,83 @@
|
| +# Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +# Use of this source code is governed by a BSD-style license that can be
|
| +# found in the LICENSE file.
|
| +
|
| +import chrome_remote_control.util as util
|
| +import json
|
| +import os
|
| +import logging
|
| +
|
| +class CredentialsBackend(object):
|
| + label = None
|
| + _config_file = os.path.join(os.path.dirname(__file__), '..', '..', 'gpu',
|
| + 'page_sets', 'credentials.json')
|
| + _config = None
|
| +
|
| + def __init__(self):
|
| + pass
|
| +
|
| + def LoginNeeded(self, tab):
|
| + raise NotImplementedError()
|
| +
|
| + def LoginNoLongerNeeded(self, tab):
|
| + raise NotImplementedError()
|
| +
|
| + @classmethod
|
| + def _ReadConfigFile(cls):
|
| + try:
|
| + with open(cls._config_file, 'r') as f:
|
| + contents = f.read()
|
| + return json.loads(contents)
|
| + except SyntaxError, e:
|
| + logging.info('Could not read %s: %s', cls._config_file,
|
| + str(e))
|
| +
|
| + @classmethod
|
| + def GetConfig(cls, config):
|
| + if cls._config is None:
|
| + cls._config = cls._ReadConfigFile()
|
| +
|
| + for key in cls._config:
|
| + if cls._config.get(key) is not None and key in config:
|
| + config[key] = cls._config.get(key)
|
| +
|
| + return config
|
| +
|
| + @classmethod
|
| + def ResetConfig(cls):
|
| + cls._config = None
|
| +
|
| + @staticmethod
|
| + def SubmitForm(form_id, tab):
|
| + """Submits the given form ID, and returns after it has been submitted.
|
| +
|
| + Args:
|
| + form_id: the id attribute of the form to submit.
|
| + """
|
| + js = 'document.getElementById("%s").submit();' % form_id
|
| +
|
| + tab.runtime.Execute(js)
|
| +
|
| + @staticmethod
|
| + def WaitForFormToLoad(form_id, tab):
|
| + def IsFormLoaded():
|
| + return tab.runtime.Evaluate(
|
| + 'document.querySelector("#%s")!== null' % form_id)
|
| +
|
| + # Wait until the form is submitted and the page completes loading.
|
| + util.WaitFor(lambda: IsFormLoaded(), 60) # pylint: disable=W0108
|
| +
|
| + @classmethod
|
| + def SubmitFormAndWait(cls, form_id, tab):
|
| + cls.SubmitForm(form_id, tab)
|
| +
|
| + def IsLoginStillHappening():
|
| + return tab.runtime.Evaluate(
|
| + 'document.querySelector("#%s")!== null' % form_id)
|
| +
|
| + # Wait until the form is submitted and the page completes loading.
|
| + util.WaitFor(lambda: not IsLoginStillHappening(), 60)
|
| +
|
| + @classmethod
|
| + def SetCredentialsConfigFile(cls, credentials_path):
|
| + cls._config_file = credentials_path
|
|
|