| 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 from chrome_remote_control import google_credentials_backend |
| 6 import logging |
| 7 import json |
| 8 |
| 9 class BrowserCredentials(object): |
| 10 def __init__(self): |
| 11 self._config = None |
| 12 self._config_file = None |
| 13 |
| 14 self._credentials_backends = \ |
| 15 [google_credentials_backend.GoogleCredentialsBackend(self)] |
| 16 |
| 17 def _GetCredentialsBackend(self, credentials_type): |
| 18 for backend in self._credentials_backends: |
| 19 if credentials_type == backend.label: |
| 20 return backend |
| 21 |
| 22 def LoginNeeded(self, credentials_type, tab): |
| 23 backend = self._GetCredentialsBackend(credentials_type) |
| 24 if backend: |
| 25 backend.LoginNeeded(tab) |
| 26 else: |
| 27 logging.warning('Credentials not implemented: "%s"', credentials_type) |
| 28 |
| 29 def LoginNoLongerNeeded(self, credentials_type, tab): |
| 30 backend = self._GetCredentialsBackend(credentials_type) |
| 31 if backend: |
| 32 backend.LoginNoLongerNeeded(tab) |
| 33 else: |
| 34 logging.warning('Credentials not implemented: "%s"', credentials_type) |
| 35 |
| 36 def _ReadConfigFile(self): |
| 37 try: |
| 38 with open(self._config_file, 'r') as f: |
| 39 contents = f.read() |
| 40 return json.loads(contents) |
| 41 except SyntaxError, e: |
| 42 logging.info('Could not read %s: %s', self._config_file, |
| 43 str(e)) |
| 44 |
| 45 def GetConfig(self, config): |
| 46 if self._config is None: |
| 47 self._config = self._ReadConfigFile() |
| 48 |
| 49 for key in self._config: |
| 50 if self._config.get(key) is not None and key in config: |
| 51 config[key] = self._config.get(key) |
| 52 |
| 53 return config |
| 54 |
| 55 def GetCredentialsConfigFile(self): |
| 56 return self._config_file |
| 57 |
| 58 def SetCredentialsConfigFile(self, credentials_path): |
| 59 self._config_file = credentials_path |
| OLD | NEW |