OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Prepares a Chrome HTML file by inlining resources and adding references to | 6 """Prepares a Chrome HTML file by inlining resources and adding references to |
7 high DPI resources and removing references to unsupported scale factors. | 7 high DPI resources and removing references to unsupported scale factors. |
8 | 8 |
9 This is a small gatherer that takes a HTML file, looks for src attributes | 9 This is a small gatherer that takes a HTML file, looks for src attributes |
10 and inlines the specified file, producing one HTML file with no external | 10 and inlines the specified file, producing one HTML file with no external |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 # Distribution string to replace with distribution. | 27 # Distribution string to replace with distribution. |
28 DIST_SUBSTR = '%DISTRIBUTION%' | 28 DIST_SUBSTR = '%DISTRIBUTION%' |
29 | 29 |
30 | 30 |
31 # Matches a chrome theme source URL. | 31 # Matches a chrome theme source URL. |
32 _THEME_SOURCE = lazy_re.compile('chrome://theme/IDR_[A-Z0-9_]*') | 32 _THEME_SOURCE = lazy_re.compile('chrome://theme/IDR_[A-Z0-9_]*') |
33 # Matches CSS image urls with the capture group 'filename'. | 33 # Matches CSS image urls with the capture group 'filename'. |
34 _CSS_IMAGE_URLS = lazy_re.compile( | 34 _CSS_IMAGE_URLS = lazy_re.compile( |
35 '(?P<attribute>content|background|[\w-]*-image):[ ]*' + | 35 '(?P<attribute>content|background|[\w-]*-image):[ ]*' + |
36 'url\((?:\'|\")(?P<filename>[^"\'\)\(]*)(?:\'|\")') | 36 'url\((?P<quote>"|\'|)(?P<filename>[^"\'()]*)(?P=quote)') |
37 # Matches CSS image sets. | 37 # Matches CSS image sets. |
38 _CSS_IMAGE_SETS = lazy_re.compile( | 38 _CSS_IMAGE_SETS = lazy_re.compile( |
39 '(?P<attribute>content|background|[\w-]*-image):[ ]*' + | 39 '(?P<attribute>content|background|[\w-]*-image):[ ]*' + |
40 '-webkit-image-set\((?P<images>' + | 40 '-webkit-image-set\((?P<images>' + |
41 '([,\n ]*url\((\'|\")[^"\'\)\(]*(\'|\")\)[ ]*[0-9.]*x)*)\)', | 41 '([,\n ]*url\((?P<quote>"|\'|)[^"\'()]*(?P=quote)\)[ ]*[0-9.]*x)*)\)', |
42 re.MULTILINE) | 42 re.MULTILINE) |
43 # Matches a single image in a CSS image set with the capture group scale. | 43 # Matches a single image in a CSS image set with the capture group scale. |
44 _CSS_IMAGE_SET_IMAGE = lazy_re.compile( | 44 _CSS_IMAGE_SET_IMAGE = lazy_re.compile( |
45 '[,\n ]*url\((\'|\")[^"\'\)\(]*(\'|\")\)[ ]*(?P<scale>[0-9.]*x)', | 45 '[,\n ]*url\((?P<quote>"|\'|)[^"\'()]*(?P=quote)\)[ ]*(?P<scale>[0-9.]*x)', |
46 re.MULTILINE) | 46 re.MULTILINE) |
47 | 47 |
48 | 48 |
49 def InsertImageSet( | 49 def InsertImageSet( |
50 src_match, base_path, scale_factors, distribution): | 50 src_match, base_path, scale_factors, distribution): |
51 """Regex replace function which inserts -webkit-image-set. | 51 """Regex replace function which inserts -webkit-image-set. |
52 | 52 |
53 Takes a regex match for url('path'). If the file is local, checks for | 53 Takes a regex match for url('path'). If the file is local, checks for |
54 files of the same name in folders corresponding to the supported scale | 54 files of the same name in folders corresponding to the supported scale |
55 factors. If the file is from a chrome://theme/ source, inserts the | 55 factors. If the file is from a chrome://theme/ source, inserts the |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 allow_external_script = self.allow_external_script_, | 222 allow_external_script = self.allow_external_script_, |
223 rewrite_function=lambda fp, t, d: ProcessImageSets( | 223 rewrite_function=lambda fp, t, d: ProcessImageSets( |
224 fp, t, self.scale_factors_, d)) | 224 fp, t, self.scale_factors_, d)) |
225 else: | 225 else: |
226 distribution = html_inline.GetDistribution() | 226 distribution = html_inline.GetDistribution() |
227 self.inlined_text_ = ProcessImageSets( | 227 self.inlined_text_ = ProcessImageSets( |
228 os.path.dirname(filename), | 228 os.path.dirname(filename), |
229 util.ReadFile(filename, 'utf-8'), | 229 util.ReadFile(filename, 'utf-8'), |
230 self.scale_factors_, | 230 self.scale_factors_, |
231 distribution) | 231 distribution) |
OLD | NEW |