Chromium Code Reviews| Index: create_standalone_js.py |
| diff --git a/create_standalone_js.py b/create_standalone_js.py |
| index 3a18a8118232ecebf5f85a22b4458dde1eb30a9d..301bde7d0ad8614bb36a94e59ee4ae17336f769b 100644 |
| --- a/create_standalone_js.py |
| +++ b/create_standalone_js.py |
| @@ -4,12 +4,15 @@ |
| """Converts gwt-compiled javascript to standalone javascript |
| -gwt-compiled javascript is in the form of an html file that is expected to be |
| -loaded into its own iframe (with some extra work done in the embedding page). |
| -This reads such a compiled file and converts it to standalone javascript that |
| -can be loaded in the main frame of a page. |
| +gwt-compiled javascript is in the form of an js file that is expected to be |
| +loaded into its own script tag. This reads such a compiled file and converts it |
| +to standalone javascript that can be loaded as Chrome does. |
| """ |
| +# TODO(cjhopman): The proper way to do this is to write a gwt Linker |
| +# (gwt.core.ext.Linker) and use that for compilation. See |
| +# http://crbug.com/437113 |
| + |
| import glob |
| import optparse |
| import os |
| @@ -18,36 +21,27 @@ import sys |
| def ExtractJavascript(content): |
| """ Extracts javascript from within <script> tags in content. """ |
| - scriptre = re.compile('<script>(<!--)?(?P<inner>.*?)(-->)?</script>', |
| - re.MULTILINE | re.DOTALL) |
| - result = '' |
| - for match in scriptre.finditer(content): |
| - result += match.group('inner') |
| - return result |
| - |
| -def FindInputPath(indir): |
| - """ Finds the path to a file of the form |
| - in/dir/DC2C3039DDCBB4AD9B63A9D3E25A0BDF.cache.html |
| - |
| - There should only be one such file in indir. |
| - """ |
| - files = glob.glob(os.path.join(indir, '*.cache.html')) |
| - if len(files) != 1: |
| - print 'Unable to find input path: ', files |
| - return None |
| - return files[0] |
| + lines = content.split('\n'); |
| + for i, l in enumerate(lines): |
| + marker = 'domdistiller();' |
|
nyquist
2014/12/02 06:31:03
Any reason why |marker| is defined inside the loop
cjhopman
2014/12/02 20:10:35
Done.
|
| + if l.startswith(marker): |
| + return '\n'.join( |
| + [l[len(marker):]] + |
|
nyquist
2014/12/02 06:31:03
Maybe add a tiny comment about including everythin
cjhopman
2014/12/02 20:10:35
Done.
|
| + lines[i + 1:-1] + |
| + [lines[-1].replace( |
| + 'if (domdistiller) domdistiller.onScriptLoad(gwtOnLoad);', |
| + 'gwtOnLoad(undefined, \'domdistiller\', \'\', 0);') |
| + ]) |
| + raise Exception('Failed to find marker line') |
| def main(argv): |
| parser = optparse.OptionParser() |
| - parser.add_option('-i', '--indir') |
| + parser.add_option('-i', '--infile') |
| parser.add_option('-o', '--outfile') |
| options, _ = parser.parse_args(argv) |
| - if options.indir: |
| - inpath = FindInputPath(options.indir) |
| - if not inpath: |
| - return 1 |
| - infile = open(inpath, 'r') |
| + if options.infile: |
| + infile = open(options.infile, 'r') |
| else: |
| print 'Reading input from stdin' |
| infile = sys.stdin |
| @@ -62,7 +56,6 @@ def main(argv): |
| # case for the standalone js. |
| compiledJs = compiledJs.replace('var $wnd = parent', 'var $wnd = window') |
| outfile.write(ExtractJavascript(compiledJs)) |
| - outfile.write('gwtOnLoad(undefined,"domdistiller","",0);\n') |
| return 0 |