Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / third_party / tvcm / tvcm / html_generation_controller.py
1 # Copyright 2013 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 """This module contains the Module class and other classes for resources.
5
6 The Module class represents a module in the trace viewer system. A module has
7 a name, and may require a variety of other resources, such as stylesheets,
8 template objects, raw javascript, or other modules.
9
10 Other resources include HTML templates, raw javascript files, and stylesheets.
11 """
12
13 import os
14 import re
15 from tvcm import style_sheet
16
17
18 class HTMLGenerationController(object):
19   def __init__(self):
20     self.current_module = None
21
22   def GetHTMLForStylesheetHRef(self, href):
23     return None
24
25   def GetHTMLForInlineStylesheet(self, contents):
26     if self.current_module == None:
27       if re.search('url\(.+\)', contents):
28         raise Exception('Default HTMLGenerationController cannot handle inline style urls')
29       return contents
30
31     module_dirname = os.path.dirname(self.current_module.resource.absolute_path)
32     ss = style_sheet.ParsedStyleSheet(
33         self.current_module.loader, module_dirname, contents)
34     return ss.contents_with_inlined_images