| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 | 6 |
| 7 """Takes the JSON files in components/domain_reliability/baked_in_configs and | 7 """Takes the JSON files in components/domain_reliability/baked_in_configs and |
| 8 encodes their contents as an array of C strings that gets compiled in to Chrome | 8 encodes their contents as an array of C strings that gets compiled in to Chrome |
| 9 and loaded at runtime.""" | 9 and loaded at runtime.""" |
| 10 | 10 |
| 11 | 11 |
| 12 import json | 12 import json |
| 13 import os | 13 import os |
| 14 import sys | 14 import sys |
| 15 | 15 |
| 16 | 16 |
| 17 # A whitelist of domains that the script will accept when baking configs in to | 17 # A whitelist of domains that the script will accept when baking configs in to |
| 18 # Chrome, to ensure incorrect ones are not added accidentally. Subdomains of | 18 # Chrome, to ensure incorrect ones are not added accidentally. Subdomains of |
| 19 # whitelist entries are also allowed (e.g. maps.google.com, ssl.gstatic.com). | 19 # whitelist entries are also allowed (e.g. maps.google.com, ssl.gstatic.com). |
| 20 DOMAIN_WHITELIST = ('google.com', 'gstatic.com', 'youtube.com') | 20 DOMAIN_WHITELIST = ('2mdn.net', 'admob.com', 'doubleclick.net', 'ggpht.com', |
| 21 'google.com', 'googleadservices.com', 'googleapis.com', |
| 22 'googlesyndication.com', 'googleusercontent.com', |
| 23 'googlevideo.com', 'gstatic.com', 'gvt1.com', 'youtube.com') |
| 21 | 24 |
| 22 | 25 |
| 23 CC_HEADER = """// Copyright (C) 2014 The Chromium Authors. All rights reserved. | 26 CC_HEADER = """// Copyright (C) 2014 The Chromium Authors. All rights reserved. |
| 24 // Use of this source code is governed by a BSD-style license that can be | 27 // Use of this source code is governed by a BSD-style license that can be |
| 25 // found in the LICENSE file. | 28 // found in the LICENSE file. |
| 26 | 29 |
| 27 // AUTOGENERATED FILE. DO NOT EDIT. | 30 // AUTOGENERATED FILE. DO NOT EDIT. |
| 28 // | 31 // |
| 29 // (Update configs in components/domain_reliability/baked_in_configs and list | 32 // (Update configs in components/domain_reliability/baked_in_configs and list |
| 30 // configs in components/domain_reliability.gypi instead.) | 33 // configs in components/domain_reliability.gypi instead.) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 74 |
| 72 | 75 |
| 73 def main(): | 76 def main(): |
| 74 if len(sys.argv) < 3: | 77 if len(sys.argv) < 3: |
| 75 print >> sys.stderr, ('Usage: %s <JSON files...> <output C++ file>' % | 78 print >> sys.stderr, ('Usage: %s <JSON files...> <output C++ file>' % |
| 76 sys.argv[0]) | 79 sys.argv[0]) |
| 77 print >> sys.stderr, sys.modules[__name__].__doc__ | 80 print >> sys.stderr, sys.modules[__name__].__doc__ |
| 78 return 1 | 81 return 1 |
| 79 | 82 |
| 80 cpp_code = CC_HEADER | 83 cpp_code = CC_HEADER |
| 84 found_invalid_config = False |
| 81 for json_file in sys.argv[1:-1]: | 85 for json_file in sys.argv[1:-1]: |
| 82 with open(json_file, 'r') as f: | 86 with open(json_file, 'r') as f: |
| 83 json_text = f.read() | 87 json_text = f.read() |
| 84 config = json.loads(json_text) | 88 config = json.loads(json_text) |
| 85 if 'monitored_domain' not in config: | 89 if 'monitored_domain' not in config: |
| 86 print >> sys.stderr ('%s: no monitored_domain found' % json_file) | 90 print >> sys.stderr, ('%s: no monitored_domain found' % json_file) |
| 87 return 1 | 91 found_invalid_config = True |
| 92 continue |
| 88 domain = config['monitored_domain'] | 93 domain = config['monitored_domain'] |
| 89 if not domain_is_whitelisted(domain): | 94 if not domain_is_whitelisted(domain): |
| 90 print >> sys.stderr ('%s: monitored_domain "%s" not in whitelist' % | 95 print >> sys.stderr, ('%s: monitored_domain "%s" not in whitelist' % |
| 91 (json_file, domain)) | 96 (json_file, domain)) |
| 92 return 1 | 97 found_invalid_config = True |
| 98 continue |
| 93 cpp_code += " // " + json_file + ":\n" | 99 cpp_code += " // " + json_file + ":\n" |
| 94 cpp_code += quote_and_wrap_text(json_text) + ",\n" | 100 cpp_code += quote_and_wrap_text(json_text) + ",\n" |
| 95 cpp_code += "\n" | 101 cpp_code += "\n" |
| 96 cpp_code += CC_FOOTER | 102 cpp_code += CC_FOOTER |
| 97 | 103 |
| 104 if found_invalid_config: |
| 105 return 1 |
| 106 |
| 98 with open(sys.argv[-1], 'wb') as f: | 107 with open(sys.argv[-1], 'wb') as f: |
| 99 f.write(cpp_code) | 108 f.write(cpp_code) |
| 100 | 109 |
| 101 return 0 | 110 return 0 |
| 102 | 111 |
| 103 | 112 |
| 104 if __name__ == '__main__': | 113 if __name__ == '__main__': |
| 105 sys.exit(main()) | 114 sys.exit(main()) |
| OLD | NEW |