diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:35:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:35:49 +0000 |
commit | d8bbc7858622b6d9c278469aab701ca0b609cddf (patch) | |
tree | eff41dc61d9f714852212739e6b3738b82a2af87 /third_party/libwebrtc/moz-patch-stack/0097.patch | |
parent | Releasing progress-linux version 125.0.3-1~progress7.99u1. (diff) | |
download | firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip |
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | third_party/libwebrtc/moz-patch-stack/0097.patch | 36922 |
1 files changed, 35049 insertions, 1873 deletions
diff --git a/third_party/libwebrtc/moz-patch-stack/0097.patch b/third_party/libwebrtc/moz-patch-stack/0097.patch index 56c8dca72b..1faafdf8cf 100644 --- a/third_party/libwebrtc/moz-patch-stack/0097.patch +++ b/third_party/libwebrtc/moz-patch-stack/0097.patch @@ -1,2186 +1,35362 @@ -From: Dan Minor <dminor@mozilla.com> -Date: Thu, 24 Sep 2020 18:28:00 +0000 -Subject: Bug 1665166 - Move media/webrtc/trunk/* to third-party/libwebrtc; - r=ng +From: Nico Grunbaum <na-g@nostrum.com> +Date: Fri, 30 Apr 2021 21:51:00 +0000 +Subject: Bug 1654112 - Add grit dep for building webrtc on android; r=mjf -Differential Revision: https://phabricator.services.mozilla.com/D91317 -Mercurial Revision: https://hg.mozilla.org/mozilla-central/rev/57e3c54bd7b9a0203e19ff1df272d24bb551ed29 +Differential Revision: https://phabricator.services.mozilla.com/D114027 +Mercurial Revision: https://hg.mozilla.org/mozilla-central/rev/3cce5e6938f0df87bd9ab12a5f556aceb93dfa1d --- - tools/clang/OWNERS | 2 + - tools/clang/plugins/ChromeClassTester.cpp | 294 ++++++++++++ - tools/clang/plugins/ChromeClassTester.h | 84 ++++ - tools/clang/plugins/FindBadConstructs.cpp | 435 ++++++++++++++++++ - tools/clang/plugins/Makefile | 19 + - tools/clang/plugins/OWNERS | 1 + - tools/clang/plugins/README.chromium | 4 + - tools/clang/plugins/tests/base_refcounted.cpp | 72 +++ - tools/clang/plugins/tests/base_refcounted.h | 121 +++++ - tools/clang/plugins/tests/base_refcounted.txt | 23 + - .../clang/plugins/tests/inline_copy_ctor.cpp | 5 + - tools/clang/plugins/tests/inline_copy_ctor.h | 12 + - .../clang/plugins/tests/inline_copy_ctor.txt | 5 + - tools/clang/plugins/tests/inline_ctor.cpp | 25 + - tools/clang/plugins/tests/inline_ctor.h | 21 + - tools/clang/plugins/tests/inline_ctor.txt | 8 + - tools/clang/plugins/tests/missing_ctor.cpp | 23 + - tools/clang/plugins/tests/missing_ctor.h | 19 + - tools/clang/plugins/tests/missing_ctor.txt | 6 + - .../tests/nested_class_inline_ctor.cpp | 5 + - .../plugins/tests/nested_class_inline_ctor.h | 22 + - .../tests/nested_class_inline_ctor.txt | 8 + - .../plugins/tests/overridden_methods.cpp | 38 ++ - .../clang/plugins/tests/overridden_methods.h | 54 +++ - .../plugins/tests/overridden_methods.txt | 20 + - tools/clang/plugins/tests/test.sh | 72 +++ - tools/clang/plugins/tests/virtual_methods.cpp | 36 ++ - tools/clang/plugins/tests/virtual_methods.h | 39 ++ - tools/clang/plugins/tests/virtual_methods.txt | 8 + - tools/clang/scripts/package.sh | 87 ++++ - tools/clang/scripts/plugin_flags.sh | 24 + - tools/clang/scripts/update.py | 34 ++ - tools/clang/scripts/update.sh | 286 ++++++++++++ - 33 files changed, 1912 insertions(+) - create mode 100644 tools/clang/OWNERS - create mode 100644 tools/clang/plugins/ChromeClassTester.cpp - create mode 100644 tools/clang/plugins/ChromeClassTester.h - create mode 100644 tools/clang/plugins/FindBadConstructs.cpp - create mode 100644 tools/clang/plugins/Makefile - create mode 100644 tools/clang/plugins/OWNERS - create mode 100644 tools/clang/plugins/README.chromium - create mode 100644 tools/clang/plugins/tests/base_refcounted.cpp - create mode 100644 tools/clang/plugins/tests/base_refcounted.h - create mode 100644 tools/clang/plugins/tests/base_refcounted.txt - create mode 100644 tools/clang/plugins/tests/inline_copy_ctor.cpp - create mode 100644 tools/clang/plugins/tests/inline_copy_ctor.h - create mode 100644 tools/clang/plugins/tests/inline_copy_ctor.txt - create mode 100644 tools/clang/plugins/tests/inline_ctor.cpp - create mode 100644 tools/clang/plugins/tests/inline_ctor.h - create mode 100644 tools/clang/plugins/tests/inline_ctor.txt - create mode 100644 tools/clang/plugins/tests/missing_ctor.cpp - create mode 100644 tools/clang/plugins/tests/missing_ctor.h - create mode 100644 tools/clang/plugins/tests/missing_ctor.txt - create mode 100644 tools/clang/plugins/tests/nested_class_inline_ctor.cpp - create mode 100644 tools/clang/plugins/tests/nested_class_inline_ctor.h - create mode 100644 tools/clang/plugins/tests/nested_class_inline_ctor.txt - create mode 100644 tools/clang/plugins/tests/overridden_methods.cpp - create mode 100644 tools/clang/plugins/tests/overridden_methods.h - create mode 100644 tools/clang/plugins/tests/overridden_methods.txt - create mode 100755 tools/clang/plugins/tests/test.sh - create mode 100644 tools/clang/plugins/tests/virtual_methods.cpp - create mode 100644 tools/clang/plugins/tests/virtual_methods.h - create mode 100644 tools/clang/plugins/tests/virtual_methods.txt - create mode 100755 tools/clang/scripts/package.sh - create mode 100755 tools/clang/scripts/plugin_flags.sh - create mode 100755 tools/clang/scripts/update.py - create mode 100755 tools/clang/scripts/update.sh + tools/grit/.gitignore | 1 + + tools/grit/BUILD.gn | 48 + + tools/grit/MANIFEST.in | 3 + + tools/grit/OWNERS | 8 + + tools/grit/PRESUBMIT.py | 22 + + tools/grit/README.md | 19 + + tools/grit/grit.py | 31 + + tools/grit/grit/__init__.py | 19 + + tools/grit/grit/clique.py | 491 +++ + tools/grit/grit/clique_unittest.py | 265 ++ + tools/grit/grit/constants.py | 23 + + tools/grit/grit/exception.py | 139 + + tools/grit/grit/extern/BogoFP.py | 22 + + tools/grit/grit/extern/FP.py | 72 + + tools/grit/grit/extern/__init__.py | 0 + tools/grit/grit/extern/tclib.py | 503 +++ + tools/grit/grit/format/__init__.py | 8 + + tools/grit/grit/format/android_xml.py | 212 ++ + .../grit/grit/format/android_xml_unittest.py | 149 + + tools/grit/grit/format/c_format.py | 95 + + tools/grit/grit/format/c_format_unittest.py | 81 + + .../grit/grit/format/chrome_messages_json.py | 59 + + .../format/chrome_messages_json_unittest.py | 190 + + tools/grit/grit/format/data_pack.py | 321 ++ + tools/grit/grit/format/data_pack_unittest.py | 102 + + .../grit/grit/format/gen_predetermined_ids.py | 144 + + .../format/gen_predetermined_ids_unittest.py | 46 + + tools/grit/grit/format/gzip_string.py | 46 + + .../grit/grit/format/gzip_string_unittest.py | 65 + + tools/grit/grit/format/html_inline.py | 602 ++++ + .../grit/grit/format/html_inline_unittest.py | 927 +++++ + tools/grit/grit/format/minifier.py | 45 + + .../grit/grit/format/policy_templates_json.py | 26 + + .../format/policy_templates_json_unittest.py | 207 ++ + tools/grit/grit/format/rc.py | 474 +++ + tools/grit/grit/format/rc_header.py | 48 + + tools/grit/grit/format/rc_header_unittest.py | 138 + + tools/grit/grit/format/rc_unittest.py | 415 +++ + tools/grit/grit/format/resource_map.py | 159 + + .../grit/grit/format/resource_map_unittest.py | 345 ++ + tools/grit/grit/gather/__init__.py | 8 + + tools/grit/grit/gather/admin_template.py | 62 + + .../grit/gather/admin_template_unittest.py | 115 + + tools/grit/grit/gather/chrome_html.py | 377 ++ + .../grit/grit/gather/chrome_html_unittest.py | 610 ++++ + tools/grit/grit/gather/chrome_scaled_image.py | 157 + + .../gather/chrome_scaled_image_unittest.py | 209 ++ + tools/grit/grit/gather/interface.py | 172 + + tools/grit/grit/gather/json_loader.py | 27 + + tools/grit/grit/gather/policy_json.py | 325 ++ + .../grit/grit/gather/policy_json_unittest.py | 347 ++ + tools/grit/grit/gather/rc.py | 343 ++ + tools/grit/grit/gather/rc_unittest.py | 372 ++ + tools/grit/grit/gather/regexp.py | 82 + + tools/grit/grit/gather/skeleton_gatherer.py | 149 + + tools/grit/grit/gather/tr_html.py | 743 ++++ + tools/grit/grit/gather/tr_html_unittest.py | 524 +++ + tools/grit/grit/gather/txt.py | 38 + + tools/grit/grit/gather/txt_unittest.py | 35 + + tools/grit/grit/grd_reader.py | 238 ++ + tools/grit/grit/grd_reader_unittest.py | 346 ++ + tools/grit/grit/grit-todo.xml | 62 + + tools/grit/grit/grit_runner.py | 334 ++ + tools/grit/grit/grit_runner_unittest.py | 42 + + tools/grit/grit/lazy_re.py | 46 + + tools/grit/grit/lazy_re_unittest.py | 40 + + tools/grit/grit/node/__init__.py | 8 + + tools/grit/grit/node/base.py | 670 ++++ + tools/grit/grit/node/base_unittest.py | 259 ++ + tools/grit/grit/node/brotli_util.py | 29 + + tools/grit/grit/node/custom/__init__.py | 8 + + tools/grit/grit/node/custom/filename.py | 29 + + .../grit/node/custom/filename_unittest.py | 34 + + tools/grit/grit/node/empty.py | 64 + + tools/grit/grit/node/include.py | 170 + + tools/grit/grit/node/include_unittest.py | 134 + + tools/grit/grit/node/mapping.py | 60 + + tools/grit/grit/node/message.py | 362 ++ + tools/grit/grit/node/message_unittest.py | 380 ++ + tools/grit/grit/node/misc.py | 707 ++++ + tools/grit/grit/node/misc_unittest.py | 590 ++++ + tools/grit/grit/node/mock_brotli.py | 10 + + tools/grit/grit/node/node_io.py | 117 + + tools/grit/grit/node/node_io_unittest.py | 182 + + tools/grit/grit/node/structure.py | 375 ++ + tools/grit/grit/node/structure_unittest.py | 178 + + tools/grit/grit/node/variant.py | 41 + + tools/grit/grit/pseudo.py | 129 + + tools/grit/grit/pseudo_rtl.py | 104 + + tools/grit/grit/pseudo_unittest.py | 55 + + tools/grit/grit/shortcuts.py | 93 + + tools/grit/grit/shortcuts_unittest.py | 79 + + tools/grit/grit/tclib.py | 246 ++ + tools/grit/grit/tclib_unittest.py | 180 + + tools/grit/grit/test_suite_all.py | 34 + + tools/grit/grit/testdata/GoogleDesktop.adm | 945 +++++ + tools/grit/grit/testdata/README.txt | 87 + + tools/grit/grit/testdata/about.html | 45 + + tools/grit/grit/testdata/android.xml | 24 + + tools/grit/grit/testdata/bad_browser.html | 16 + + tools/grit/grit/testdata/browser.html | 42 + + tools/grit/grit/testdata/buildinfo.grd | 46 + + tools/grit/grit/testdata/cache_prefix.html | 24 + + .../grit/grit/testdata/cache_prefix_file.html | 25 + + tools/grit/grit/testdata/chat_result.html | 24 + + .../chrome/app/generated_resources.grd | 199 ++ + tools/grit/grit/testdata/chrome_html.html | 6 + + .../grit/testdata/default_100_percent/a.png | Bin 0 -> 159 bytes + .../grit/testdata/default_100_percent/b.png | 1 + + tools/grit/grit/testdata/del_footer.html | 8 + + tools/grit/grit/testdata/del_header.html | 60 + + tools/grit/grit/testdata/deleted.html | 21 + + tools/grit/grit/testdata/depfile.grd | 18 + + tools/grit/grit/testdata/details.html | 10 + + .../grit/testdata/duplicate-name-input.xml | 26 + + tools/grit/grit/testdata/email_result.html | 34 + + tools/grit/grit/testdata/email_thread.html | 10 + + tools/grit/grit/testdata/error.html | 8 + + tools/grit/grit/testdata/explicit_web.html | 11 + + tools/grit/grit/testdata/footer.html | 14 + + .../grit/testdata/generated_resources_fr.xtb | 3079 +++++++++++++++++ + .../grit/testdata/generated_resources_iw.xtb | 4 + + .../grit/testdata/generated_resources_no.xtb | 4 + + tools/grit/grit/testdata/grit_part.grdp | 5 + + tools/grit/grit/testdata/header.html | 39 + + tools/grit/grit/testdata/homepage.html | 37 + + tools/grit/grit/testdata/hover.html | 177 + + tools/grit/grit/testdata/include_test.html | 31 + + tools/grit/grit/testdata/included_sample.html | 1 + + tools/grit/grit/testdata/indexing_speed.html | 58 + + tools/grit/grit/testdata/install_prefs.html | 92 + + tools/grit/grit/testdata/install_prefs2.html | 52 + + .../grit/testdata/klonk-alternate-skeleton.rc | Bin 0 -> 1088 bytes + tools/grit/grit/testdata/klonk.ico | Bin 0 -> 766 bytes + tools/grit/grit/testdata/klonk.rc | Bin 0 -> 9824 bytes + .../grit/grit/testdata/ko_oem_enable_bug.html | 1 + + .../grit/testdata/ko_oem_non_admin_bug.html | 1 + + tools/grit/grit/testdata/mini.html | 36 + + tools/grit/grit/testdata/oem_enable.html | 106 + + tools/grit/grit/testdata/oem_non_admin.html | 39 + + tools/grit/grit/testdata/onebox.html | 21 + + tools/grit/grit/testdata/oneclick.html | 34 + + tools/grit/grit/testdata/password.html | 37 + + tools/grit/grit/testdata/preferences.html | 234 ++ + tools/grit/grit/testdata/preprocess_test.html | 7 + + tools/grit/grit/testdata/privacy.html | 35 + + tools/grit/grit/testdata/quit_apps.html | 49 + + tools/grit/grit/testdata/recrawl.html | 30 + + tools/grit/grit/testdata/resource_ids | 13 + + tools/grit/grit/testdata/script.html | 38 + + tools/grit/grit/testdata/searchbox.html | 22 + + tools/grit/grit/testdata/sidebar_h.html | 82 + + tools/grit/grit/testdata/sidebar_v.html | 267 ++ + tools/grit/grit/testdata/simple-input.xml | 52 + + tools/grit/grit/testdata/simple.html | 3 + + tools/grit/grit/testdata/source.rc | 57 + + .../grit/testdata/special_100_percent/a.png | Bin 0 -> 159 bytes + tools/grit/grit/testdata/status.html | 44 + + .../grit/testdata/structure_variables.html | 4 + + tools/grit/grit/testdata/substitute.grd | 31 + + tools/grit/grit/testdata/substitute.xmb | 10 + + .../grit/grit/testdata/substitute_no_ids.grd | 31 + + tools/grit/grit/testdata/substitute_tmpl.grd | 31 + + tools/grit/grit/testdata/test_css.css | 1 + + tools/grit/grit/testdata/test_html.html | 1 + + tools/grit/grit/testdata/test_js.js | 1 + + tools/grit/grit/testdata/test_svg.svg | 1 + + tools/grit/grit/testdata/test_text.txt | 1 + + tools/grit/grit/testdata/time_related.html | 11 + + tools/grit/grit/testdata/toolbar_about.html | 138 + + .../grit/testdata/tools/grit/resource_ids | 176 + + tools/grit/grit/testdata/transl.rc | 56 + + tools/grit/grit/testdata/versions.html | 7 + + tools/grit/grit/testdata/whitelist.txt | 4 + + .../grit/testdata/whitelist_resources.grd | 54 + + .../grit/grit/testdata/whitelist_strings.grd | 23 + + tools/grit/grit/tool/__init__.py | 8 + + tools/grit/grit/tool/android2grd.py | 484 +++ + tools/grit/grit/tool/android2grd_unittest.py | 181 + + tools/grit/grit/tool/build.py | 556 +++ + tools/grit/grit/tool/build_unittest.py | 341 ++ + tools/grit/grit/tool/buildinfo.py | 78 + + tools/grit/grit/tool/buildinfo_unittest.py | 90 + + tools/grit/grit/tool/count.py | 52 + + tools/grit/grit/tool/diff_structures.py | 119 + + .../grit/tool/diff_structures_unittest.py | 46 + + tools/grit/grit/tool/interface.py | 62 + + tools/grit/grit/tool/menu_from_parts.py | 79 + + tools/grit/grit/tool/newgrd.py | 85 + + tools/grit/grit/tool/newgrd_unittest.py | 51 + + tools/grit/grit/tool/postprocess_interface.py | 29 + + tools/grit/grit/tool/postprocess_unittest.py | 64 + + tools/grit/grit/tool/preprocess_interface.py | 25 + + tools/grit/grit/tool/preprocess_unittest.py | 50 + + tools/grit/grit/tool/rc2grd.py | 418 +++ + tools/grit/grit/tool/rc2grd_unittest.py | 163 + + tools/grit/grit/tool/resize.py | 295 ++ + tools/grit/grit/tool/test.py | 24 + + tools/grit/grit/tool/transl2tc.py | 251 ++ + tools/grit/grit/tool/transl2tc_unittest.py | 133 + + tools/grit/grit/tool/unit.py | 43 + + .../grit/tool/update_resource_ids/__init__.py | 305 ++ + .../grit/tool/update_resource_ids/assigner.py | 286 ++ + .../update_resource_ids/assigner_unittest.py | 154 + + .../grit/tool/update_resource_ids/common.py | 101 + + .../grit/tool/update_resource_ids/parser.py | 231 ++ + .../grit/tool/update_resource_ids/reader.py | 83 + + tools/grit/grit/tool/xmb.py | 295 ++ + tools/grit/grit/tool/xmb_unittest.py | 132 + + tools/grit/grit/util.py | 691 ++++ + tools/grit/grit/util_unittest.py | 118 + + tools/grit/grit/xtb_reader.py | 140 + + tools/grit/grit/xtb_reader_unittest.py | 110 + + tools/grit/grit_info.py | 173 + + tools/grit/grit_rule.gni | 485 +++ + tools/grit/minify_with_uglify.py | 44 + + tools/grit/minimize_css.py | 105 + + tools/grit/minimize_css_unittest.py | 58 + + tools/grit/pak_util.py | 223 ++ + tools/grit/repack.gni | 189 + + tools/grit/setup.py | 46 + + tools/grit/stamp_grit_sources.py | 57 + + tools/grit/third_party/six/LICENSE | 18 + + tools/grit/third_party/six/README | 16 + + tools/grit/third_party/six/README.chromium | 13 + + tools/grit/third_party/six/__init__.py | 868 +++++ + 226 files changed, 33440 insertions(+) + create mode 100644 tools/grit/.gitignore + create mode 100644 tools/grit/BUILD.gn + create mode 100644 tools/grit/MANIFEST.in + create mode 100644 tools/grit/OWNERS + create mode 100644 tools/grit/PRESUBMIT.py + create mode 100644 tools/grit/README.md + create mode 100644 tools/grit/grit.py + create mode 100644 tools/grit/grit/__init__.py + create mode 100644 tools/grit/grit/clique.py + create mode 100644 tools/grit/grit/clique_unittest.py + create mode 100644 tools/grit/grit/constants.py + create mode 100644 tools/grit/grit/exception.py + create mode 100644 tools/grit/grit/extern/BogoFP.py + create mode 100644 tools/grit/grit/extern/FP.py + create mode 100644 tools/grit/grit/extern/__init__.py + create mode 100644 tools/grit/grit/extern/tclib.py + create mode 100644 tools/grit/grit/format/__init__.py + create mode 100644 tools/grit/grit/format/android_xml.py + create mode 100644 tools/grit/grit/format/android_xml_unittest.py + create mode 100644 tools/grit/grit/format/c_format.py + create mode 100644 tools/grit/grit/format/c_format_unittest.py + create mode 100644 tools/grit/grit/format/chrome_messages_json.py + create mode 100644 tools/grit/grit/format/chrome_messages_json_unittest.py + create mode 100644 tools/grit/grit/format/data_pack.py + create mode 100644 tools/grit/grit/format/data_pack_unittest.py + create mode 100644 tools/grit/grit/format/gen_predetermined_ids.py + create mode 100644 tools/grit/grit/format/gen_predetermined_ids_unittest.py + create mode 100644 tools/grit/grit/format/gzip_string.py + create mode 100644 tools/grit/grit/format/gzip_string_unittest.py + create mode 100644 tools/grit/grit/format/html_inline.py + create mode 100644 tools/grit/grit/format/html_inline_unittest.py + create mode 100644 tools/grit/grit/format/minifier.py + create mode 100644 tools/grit/grit/format/policy_templates_json.py + create mode 100644 tools/grit/grit/format/policy_templates_json_unittest.py + create mode 100644 tools/grit/grit/format/rc.py + create mode 100644 tools/grit/grit/format/rc_header.py + create mode 100644 tools/grit/grit/format/rc_header_unittest.py + create mode 100644 tools/grit/grit/format/rc_unittest.py + create mode 100644 tools/grit/grit/format/resource_map.py + create mode 100644 tools/grit/grit/format/resource_map_unittest.py + create mode 100644 tools/grit/grit/gather/__init__.py + create mode 100644 tools/grit/grit/gather/admin_template.py + create mode 100644 tools/grit/grit/gather/admin_template_unittest.py + create mode 100644 tools/grit/grit/gather/chrome_html.py + create mode 100644 tools/grit/grit/gather/chrome_html_unittest.py + create mode 100644 tools/grit/grit/gather/chrome_scaled_image.py + create mode 100644 tools/grit/grit/gather/chrome_scaled_image_unittest.py + create mode 100644 tools/grit/grit/gather/interface.py + create mode 100644 tools/grit/grit/gather/json_loader.py + create mode 100644 tools/grit/grit/gather/policy_json.py + create mode 100644 tools/grit/grit/gather/policy_json_unittest.py + create mode 100644 tools/grit/grit/gather/rc.py + create mode 100644 tools/grit/grit/gather/rc_unittest.py + create mode 100644 tools/grit/grit/gather/regexp.py + create mode 100644 tools/grit/grit/gather/skeleton_gatherer.py + create mode 100644 tools/grit/grit/gather/tr_html.py + create mode 100644 tools/grit/grit/gather/tr_html_unittest.py + create mode 100644 tools/grit/grit/gather/txt.py + create mode 100644 tools/grit/grit/gather/txt_unittest.py + create mode 100644 tools/grit/grit/grd_reader.py + create mode 100644 tools/grit/grit/grd_reader_unittest.py + create mode 100644 tools/grit/grit/grit-todo.xml + create mode 100644 tools/grit/grit/grit_runner.py + create mode 100644 tools/grit/grit/grit_runner_unittest.py + create mode 100644 tools/grit/grit/lazy_re.py + create mode 100644 tools/grit/grit/lazy_re_unittest.py + create mode 100644 tools/grit/grit/node/__init__.py + create mode 100644 tools/grit/grit/node/base.py + create mode 100644 tools/grit/grit/node/base_unittest.py + create mode 100644 tools/grit/grit/node/brotli_util.py + create mode 100644 tools/grit/grit/node/custom/__init__.py + create mode 100644 tools/grit/grit/node/custom/filename.py + create mode 100644 tools/grit/grit/node/custom/filename_unittest.py + create mode 100644 tools/grit/grit/node/empty.py + create mode 100644 tools/grit/grit/node/include.py + create mode 100644 tools/grit/grit/node/include_unittest.py + create mode 100644 tools/grit/grit/node/mapping.py + create mode 100644 tools/grit/grit/node/message.py + create mode 100644 tools/grit/grit/node/message_unittest.py + create mode 100644 tools/grit/grit/node/misc.py + create mode 100644 tools/grit/grit/node/misc_unittest.py + create mode 100644 tools/grit/grit/node/mock_brotli.py + create mode 100644 tools/grit/grit/node/node_io.py + create mode 100644 tools/grit/grit/node/node_io_unittest.py + create mode 100644 tools/grit/grit/node/structure.py + create mode 100644 tools/grit/grit/node/structure_unittest.py + create mode 100644 tools/grit/grit/node/variant.py + create mode 100644 tools/grit/grit/pseudo.py + create mode 100644 tools/grit/grit/pseudo_rtl.py + create mode 100644 tools/grit/grit/pseudo_unittest.py + create mode 100644 tools/grit/grit/shortcuts.py + create mode 100644 tools/grit/grit/shortcuts_unittest.py + create mode 100644 tools/grit/grit/tclib.py + create mode 100644 tools/grit/grit/tclib_unittest.py + create mode 100644 tools/grit/grit/test_suite_all.py + create mode 100644 tools/grit/grit/testdata/GoogleDesktop.adm + create mode 100644 tools/grit/grit/testdata/README.txt + create mode 100644 tools/grit/grit/testdata/about.html + create mode 100644 tools/grit/grit/testdata/android.xml + create mode 100644 tools/grit/grit/testdata/bad_browser.html + create mode 100644 tools/grit/grit/testdata/browser.html + create mode 100644 tools/grit/grit/testdata/buildinfo.grd + create mode 100644 tools/grit/grit/testdata/cache_prefix.html + create mode 100644 tools/grit/grit/testdata/cache_prefix_file.html + create mode 100644 tools/grit/grit/testdata/chat_result.html + create mode 100644 tools/grit/grit/testdata/chrome/app/generated_resources.grd + create mode 100644 tools/grit/grit/testdata/chrome_html.html + create mode 100644 tools/grit/grit/testdata/default_100_percent/a.png + create mode 100644 tools/grit/grit/testdata/default_100_percent/b.png + create mode 100644 tools/grit/grit/testdata/del_footer.html + create mode 100644 tools/grit/grit/testdata/del_header.html + create mode 100644 tools/grit/grit/testdata/deleted.html + create mode 100644 tools/grit/grit/testdata/depfile.grd + create mode 100644 tools/grit/grit/testdata/details.html + create mode 100644 tools/grit/grit/testdata/duplicate-name-input.xml + create mode 100644 tools/grit/grit/testdata/email_result.html + create mode 100644 tools/grit/grit/testdata/email_thread.html + create mode 100644 tools/grit/grit/testdata/error.html + create mode 100644 tools/grit/grit/testdata/explicit_web.html + create mode 100644 tools/grit/grit/testdata/footer.html + create mode 100644 tools/grit/grit/testdata/generated_resources_fr.xtb + create mode 100644 tools/grit/grit/testdata/generated_resources_iw.xtb + create mode 100644 tools/grit/grit/testdata/generated_resources_no.xtb + create mode 100644 tools/grit/grit/testdata/grit_part.grdp + create mode 100644 tools/grit/grit/testdata/header.html + create mode 100644 tools/grit/grit/testdata/homepage.html + create mode 100644 tools/grit/grit/testdata/hover.html + create mode 100644 tools/grit/grit/testdata/include_test.html + create mode 100644 tools/grit/grit/testdata/included_sample.html + create mode 100644 tools/grit/grit/testdata/indexing_speed.html + create mode 100644 tools/grit/grit/testdata/install_prefs.html + create mode 100644 tools/grit/grit/testdata/install_prefs2.html + create mode 100644 tools/grit/grit/testdata/klonk-alternate-skeleton.rc + create mode 100644 tools/grit/grit/testdata/klonk.ico + create mode 100644 tools/grit/grit/testdata/klonk.rc + create mode 100644 tools/grit/grit/testdata/ko_oem_enable_bug.html + create mode 100644 tools/grit/grit/testdata/ko_oem_non_admin_bug.html + create mode 100644 tools/grit/grit/testdata/mini.html + create mode 100644 tools/grit/grit/testdata/oem_enable.html + create mode 100644 tools/grit/grit/testdata/oem_non_admin.html + create mode 100644 tools/grit/grit/testdata/onebox.html + create mode 100644 tools/grit/grit/testdata/oneclick.html + create mode 100644 tools/grit/grit/testdata/password.html + create mode 100644 tools/grit/grit/testdata/preferences.html + create mode 100644 tools/grit/grit/testdata/preprocess_test.html + create mode 100644 tools/grit/grit/testdata/privacy.html + create mode 100644 tools/grit/grit/testdata/quit_apps.html + create mode 100644 tools/grit/grit/testdata/recrawl.html + create mode 100644 tools/grit/grit/testdata/resource_ids + create mode 100644 tools/grit/grit/testdata/script.html + create mode 100644 tools/grit/grit/testdata/searchbox.html + create mode 100644 tools/grit/grit/testdata/sidebar_h.html + create mode 100644 tools/grit/grit/testdata/sidebar_v.html + create mode 100644 tools/grit/grit/testdata/simple-input.xml + create mode 100644 tools/grit/grit/testdata/simple.html + create mode 100644 tools/grit/grit/testdata/source.rc + create mode 100644 tools/grit/grit/testdata/special_100_percent/a.png + create mode 100644 tools/grit/grit/testdata/status.html + create mode 100644 tools/grit/grit/testdata/structure_variables.html + create mode 100644 tools/grit/grit/testdata/substitute.grd + create mode 100644 tools/grit/grit/testdata/substitute.xmb + create mode 100644 tools/grit/grit/testdata/substitute_no_ids.grd + create mode 100644 tools/grit/grit/testdata/substitute_tmpl.grd + create mode 100644 tools/grit/grit/testdata/test_css.css + create mode 100644 tools/grit/grit/testdata/test_html.html + create mode 100644 tools/grit/grit/testdata/test_js.js + create mode 100644 tools/grit/grit/testdata/test_svg.svg + create mode 100644 tools/grit/grit/testdata/test_text.txt + create mode 100644 tools/grit/grit/testdata/time_related.html + create mode 100644 tools/grit/grit/testdata/toolbar_about.html + create mode 100644 tools/grit/grit/testdata/tools/grit/resource_ids + create mode 100644 tools/grit/grit/testdata/transl.rc + create mode 100644 tools/grit/grit/testdata/versions.html + create mode 100644 tools/grit/grit/testdata/whitelist.txt + create mode 100644 tools/grit/grit/testdata/whitelist_resources.grd + create mode 100644 tools/grit/grit/testdata/whitelist_strings.grd + create mode 100644 tools/grit/grit/tool/__init__.py + create mode 100644 tools/grit/grit/tool/android2grd.py + create mode 100644 tools/grit/grit/tool/android2grd_unittest.py + create mode 100644 tools/grit/grit/tool/build.py + create mode 100644 tools/grit/grit/tool/build_unittest.py + create mode 100644 tools/grit/grit/tool/buildinfo.py + create mode 100644 tools/grit/grit/tool/buildinfo_unittest.py + create mode 100644 tools/grit/grit/tool/count.py + create mode 100644 tools/grit/grit/tool/diff_structures.py + create mode 100644 tools/grit/grit/tool/diff_structures_unittest.py + create mode 100644 tools/grit/grit/tool/interface.py + create mode 100644 tools/grit/grit/tool/menu_from_parts.py + create mode 100644 tools/grit/grit/tool/newgrd.py + create mode 100644 tools/grit/grit/tool/newgrd_unittest.py + create mode 100644 tools/grit/grit/tool/postprocess_interface.py + create mode 100644 tools/grit/grit/tool/postprocess_unittest.py + create mode 100644 tools/grit/grit/tool/preprocess_interface.py + create mode 100644 tools/grit/grit/tool/preprocess_unittest.py + create mode 100644 tools/grit/grit/tool/rc2grd.py + create mode 100644 tools/grit/grit/tool/rc2grd_unittest.py + create mode 100644 tools/grit/grit/tool/resize.py + create mode 100644 tools/grit/grit/tool/test.py + create mode 100644 tools/grit/grit/tool/transl2tc.py + create mode 100644 tools/grit/grit/tool/transl2tc_unittest.py + create mode 100644 tools/grit/grit/tool/unit.py + create mode 100644 tools/grit/grit/tool/update_resource_ids/__init__.py + create mode 100644 tools/grit/grit/tool/update_resource_ids/assigner.py + create mode 100644 tools/grit/grit/tool/update_resource_ids/assigner_unittest.py + create mode 100644 tools/grit/grit/tool/update_resource_ids/common.py + create mode 100644 tools/grit/grit/tool/update_resource_ids/parser.py + create mode 100644 tools/grit/grit/tool/update_resource_ids/reader.py + create mode 100644 tools/grit/grit/tool/xmb.py + create mode 100644 tools/grit/grit/tool/xmb_unittest.py + create mode 100644 tools/grit/grit/util.py + create mode 100644 tools/grit/grit/util_unittest.py + create mode 100644 tools/grit/grit/xtb_reader.py + create mode 100644 tools/grit/grit/xtb_reader_unittest.py + create mode 100644 tools/grit/grit_info.py + create mode 100644 tools/grit/grit_rule.gni + create mode 100644 tools/grit/minify_with_uglify.py + create mode 100644 tools/grit/minimize_css.py + create mode 100644 tools/grit/minimize_css_unittest.py + create mode 100644 tools/grit/pak_util.py + create mode 100644 tools/grit/repack.gni + create mode 100644 tools/grit/setup.py + create mode 100644 tools/grit/stamp_grit_sources.py + create mode 100644 tools/grit/third_party/six/LICENSE + create mode 100644 tools/grit/third_party/six/README + create mode 100644 tools/grit/third_party/six/README.chromium + create mode 100644 tools/grit/third_party/six/__init__.py -diff --git a/tools/clang/OWNERS b/tools/clang/OWNERS +diff --git a/tools/grit/.gitignore b/tools/grit/.gitignore new file mode 100644 -index 0000000000..d86ef9424a +index 0000000000..0d20b6487c --- /dev/null -+++ b/tools/clang/OWNERS -@@ -0,0 +1,2 @@ -+hans@chromium.org -+thakis@chromium.org -diff --git a/tools/clang/plugins/ChromeClassTester.cpp b/tools/clang/plugins/ChromeClassTester.cpp ++++ b/tools/grit/.gitignore +@@ -0,0 +1 @@ ++*.pyc +diff --git a/tools/grit/BUILD.gn b/tools/grit/BUILD.gn new file mode 100644 -index 0000000000..055866c5c5 +index 0000000000..1cd3c75b55 --- /dev/null -+++ b/tools/clang/plugins/ChromeClassTester.cpp -@@ -0,0 +1,294 @@ -+// Copyright (c) 2012 The Chromium Authors. All rights reserved. -+// Use of this source code is governed by a BSD-style license that can be -+// found in the LICENSE file. -+ -+// A general interface for filtering and only acting on classes in Chromium C++ -+// code. ++++ b/tools/grit/BUILD.gn +@@ -0,0 +1,48 @@ ++# Copyright 2014 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+#include "ChromeClassTester.h" ++# This target creates a stamp file that depends on all the sources in the grit ++# directory. By depending on this, a target can force itself to be rebuilt if ++# grit itself changes. + -+#include <sys/param.h> ++import("//build/config/sanitizers/sanitizers.gni") + -+#include "clang/AST/AST.h" -+#include "clang/Basic/FileManager.h" -+#include "clang/Basic/SourceManager.h" ++action("grit_sources") { ++ depfile = "$target_out_dir/grit_sources.d" ++ script = "stamp_grit_sources.py" + -+using namespace clang; ++ inputs = [ "grit.py" ] + -+namespace { ++ # Note that we can't call this "grit_sources.stamp" because that file is ++ # implicitly created by GN for script actions. ++ outputs = [ "$target_out_dir/grit_sources.script.stamp" ] + -+bool starts_with(const std::string& one, const std::string& two) { -+ return one.compare(0, two.size(), two) == 0; ++ args = [ ++ rebase_path("//tools/grit", root_build_dir), ++ rebase_path(outputs[0], root_build_dir), ++ rebase_path(depfile, root_build_dir), ++ ] +} + -+std::string lstrip(const std::string& one, const std::string& two) { -+ if (starts_with(one, two)) -+ return one.substr(two.size()); -+ return one; ++group("grit_python_unittests") { ++ testonly = true ++ ++ data = [ ++ "//testing/scripts/common.py", ++ "//testing/scripts/run_isolated_script_test.py", ++ "//testing/xvfb.py", ++ "//tools/grit/", ++ "//third_party/catapult/third_party/typ/", ++ ] +} + -+bool ends_with(const std::string& one, const std::string& two) { -+ if (two.size() > one.size()) -+ return false; ++# See https://crbug.com/983200 ++if (is_mac && is_asan) { ++ create_bundle("brotli_mac_asan_workaround") { ++ bundle_root_dir = "$target_out_dir/$target_name" ++ bundle_executable_dir = bundle_root_dir + -+ return one.compare(one.size() - two.size(), two.size(), two) == 0; ++ public_deps = [ "//third_party/brotli:brotli($host_toolchain)" ] ++ } +} +diff --git a/tools/grit/MANIFEST.in b/tools/grit/MANIFEST.in +new file mode 100644 +index 0000000000..1cbff42400 +--- /dev/null ++++ b/tools/grit/MANIFEST.in +@@ -0,0 +1,3 @@ ++exclude grit/test_suite_all.py ++exclude grit/tool/test.py ++global-exclude *_unittest.py +diff --git a/tools/grit/OWNERS b/tools/grit/OWNERS +new file mode 100644 +index 0000000000..6a8f447b82 +--- /dev/null ++++ b/tools/grit/OWNERS +@@ -0,0 +1,8 @@ ++agrieve@chromium.org ++flackr@chromium.org ++thakis@chromium.org ++thestig@chromium.org + -+} // namespace ++# Admin policy related grit tools. ++per-file *policy*=file://components/policy/tools/OWNERS ++per-file *admin_template*=file://components/policy/tools/OWNERS +diff --git a/tools/grit/PRESUBMIT.py b/tools/grit/PRESUBMIT.py +new file mode 100644 +index 0000000000..03b7188551 +--- /dev/null ++++ b/tools/grit/PRESUBMIT.py +@@ -0,0 +1,22 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+ChromeClassTester::ChromeClassTester(CompilerInstance& instance) -+ : instance_(instance), -+ diagnostic_(instance.getDiagnostics()) { -+ BuildBannedLists(); -+} ++"""grit unittests presubmit script. + -+ChromeClassTester::~ChromeClassTester() {} ++See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for ++details on the presubmit API built into gcl. ++""" + -+void ChromeClassTester::HandleTagDeclDefinition(TagDecl* tag) { -+ pending_class_decls_.push_back(tag); -+} + -+bool ChromeClassTester::HandleTopLevelDecl(DeclGroupRef group_ref) { -+ for (size_t i = 0; i < pending_class_decls_.size(); ++i) -+ CheckTag(pending_class_decls_[i]); -+ pending_class_decls_.clear(); ++def RunUnittests(input_api, output_api): ++ return input_api.canned_checks.RunUnitTests(input_api, output_api, ++ [input_api.os_path.join('grit', 'test_suite_all.py')]) + -+ return true; // true means continue parsing. -+} + -+void ChromeClassTester::CheckTag(TagDecl* tag) { -+ // We handle class types here where we have semantic information. We can only -+ // check structs/classes/enums here, but we get a bunch of nice semantic -+ // information instead of just parsing information. ++def CheckChangeOnUpload(input_api, output_api): ++ return RunUnittests(input_api, output_api) + -+ if (CXXRecordDecl* record = dyn_cast<CXXRecordDecl>(tag)) { -+ // If this is a POD or a class template or a type dependent on a -+ // templated class, assume there's no ctor/dtor/virtual method -+ // optimization that we can do. -+ if (record->isPOD() || -+ record->getDescribedClassTemplate() || -+ record->getTemplateSpecializationKind() || -+ record->isDependentType()) -+ return; + -+ if (InBannedNamespace(record)) -+ return; ++def CheckChangeOnCommit(input_api, output_api): ++ return RunUnittests(input_api, output_api) +diff --git a/tools/grit/README.md b/tools/grit/README.md +new file mode 100644 +index 0000000000..b5c3f4b51b +--- /dev/null ++++ b/tools/grit/README.md +@@ -0,0 +1,19 @@ ++# GRIT (Google Resource and Internationalization Tool) + -+ SourceLocation record_location = record->getInnerLocStart(); -+ if (InBannedDirectory(record_location)) -+ return; ++This is a tool for projects to manage resources and simplify the localization ++workflow. + -+ // We sadly need to maintain a blacklist of types that violate these -+ // rules, but do so for good reason or due to limitations of this -+ // checker (i.e., we don't handle extern templates very well). -+ std::string base_name = record->getNameAsString(); -+ if (IsIgnoredType(base_name)) -+ return; ++See the user guide for more details on using this project: ++https://dev.chromium.org/developers/tools-we-use-in-chromium/grit/grit-users-guide + -+ // We ignore all classes that end with "Matcher" because they're probably -+ // GMock artifacts. -+ if (ends_with(base_name, "Matcher")) -+ return; ++## History + -+ CheckChromeClass(record_location, record); -+ } -+} ++This code previously used to live at ++https://code.google.com/p/grit-i18n/source/checkout which still contains the ++project's history. https://chromium.googlesource.com/external/grit-i18n/ is ++a git mirror of the SVN repository that's identical except for the last two ++commits. The project is now developed in the Chromium project directly. + -+void ChromeClassTester::emitWarning(SourceLocation loc, -+ const char* raw_error) { -+ FullSourceLoc full(loc, instance().getSourceManager()); -+ std::string err; -+ err = "[chromium-style] "; -+ err += raw_error; -+ DiagnosticsEngine::Level level = -+ diagnostic().getWarningsAsErrors() ? -+ DiagnosticsEngine::Error : -+ DiagnosticsEngine::Warning; -+ unsigned id = diagnostic().getCustomDiagID(level, err); -+ DiagnosticBuilder builder = diagnostic().Report(full, id); -+} -+ -+bool ChromeClassTester::InBannedNamespace(const Decl* record) { -+ std::string n = GetNamespace(record); -+ if (!n.empty()) { -+ return std::find(banned_namespaces_.begin(), banned_namespaces_.end(), n) -+ != banned_namespaces_.end(); -+ } ++There is a read-only mirror of just this directory at ++https://chromium.googlesource.com/chromium/src/tools/grit/ if you don't want to ++check out all of Chromium. +diff --git a/tools/grit/grit.py b/tools/grit/grit.py +new file mode 100644 +index 0000000000..abd1ab6449 +--- /dev/null ++++ b/tools/grit/grit.py +@@ -0,0 +1,31 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+ return false; -+} ++'''Bootstrapping for GRIT. ++''' ++ ++from __future__ import print_function ++ ++import os ++import sys ++ ++import grit.grit_runner ++ ++sys.path.append( ++ os.path.join( ++ os.path.dirname(os.path.dirname(os.path.abspath(__file__))), ++ 'diagnosis')) ++try: ++ import crbug_1001171 ++except ImportError: ++ crbug_1001171 = None ++ ++ ++if __name__ == '__main__': ++ if crbug_1001171: ++ with crbug_1001171.DumpStateOnLookupError(): ++ sys.exit(grit.grit_runner.Main(sys.argv[1:])) ++ else: ++ sys.exit(grit.grit_runner.Main(sys.argv[1:])) +diff --git a/tools/grit/grit/__init__.py b/tools/grit/grit/__init__.py +new file mode 100644 +index 0000000000..91ac9ee896 +--- /dev/null ++++ b/tools/grit/grit/__init__.py +@@ -0,0 +1,19 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Package 'grit' ++''' ++ ++from __future__ import print_function ++ ++import os ++import sys ++ ++ ++_CUR_DIR = os.path.abspath(os.path.dirname(__file__)) ++_GRIT_DIR = os.path.dirname(_CUR_DIR) ++_THIRD_PARTY_DIR = os.path.join(_GRIT_DIR, 'third_party') ++ ++if _THIRD_PARTY_DIR not in sys.path: ++ sys.path.insert(0, _THIRD_PARTY_DIR) +diff --git a/tools/grit/grit/clique.py b/tools/grit/grit/clique.py +new file mode 100644 +index 0000000000..e7be3ec164 +--- /dev/null ++++ b/tools/grit/grit/clique.py +@@ -0,0 +1,491 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Collections of messages and their translations, called cliques. Also ++collections of cliques (uber-cliques). ++''' ++ ++from __future__ import print_function ++ ++import re ++ ++import six ++ ++from grit import constants ++from grit import exception ++from grit import lazy_re ++from grit import pseudo ++from grit import pseudo_rtl ++from grit import tclib ++ ++ ++class UberClique(object): ++ '''A factory (NOT a singleton factory) for making cliques. It has several ++ methods for working with the cliques created using the factory. ++ ''' ++ ++ def __init__(self): ++ # A map from message ID to list of cliques whose source messages have ++ # that ID. This will contain all cliques created using this factory. ++ # Different messages can have the same ID because they have the ++ # same translateable portion and placeholder names, but occur in different ++ # places in the resource tree. ++ # ++ # Each list of cliques is kept sorted by description, to achieve ++ # stable results from the BestClique method, see below. ++ self.cliques_ = {} ++ ++ # A map of clique IDs to list of languages to indicate translations where we ++ # fell back to English. ++ self.fallback_translations_ = {} ++ ++ # A map of clique IDs to list of languages to indicate missing translations. ++ self.missing_translations_ = {} ++ ++ def _AddMissingTranslation(self, lang, clique, is_error): ++ tl = self.fallback_translations_ ++ if is_error: ++ tl = self.missing_translations_ ++ id = clique.GetId() ++ if id not in tl: ++ tl[id] = {} ++ if lang not in tl[id]: ++ tl[id][lang] = 1 ++ ++ def HasMissingTranslations(self): ++ return len(self.missing_translations_) > 0 ++ ++ def MissingTranslationsReport(self): ++ '''Returns a string suitable for printing to report missing ++ and fallback translations to the user. ++ ''' ++ def ReportTranslation(clique, langs): ++ text = clique.GetMessage().GetPresentableContent() ++ # The text 'error' (usually 'Error:' but we are conservative) ++ # can trigger some build environments (Visual Studio, we're ++ # looking at you) to consider invocation of grit to have failed, ++ # so we make sure never to output that word. ++ extract = re.sub(r'(?i)error', 'REDACTED', text[0:40])[0:40] ++ ellipsis = '' ++ if len(text) > 40: ++ ellipsis = '...' ++ langs_extract = langs[0:6] ++ describe_langs = ','.join(langs_extract) ++ if len(langs) > 6: ++ describe_langs += " and %d more" % (len(langs) - 6) ++ return " %s \"%s%s\" %s" % (clique.GetId(), extract, ellipsis, ++ describe_langs) ++ lines = [] ++ if len(self.fallback_translations_): ++ lines.append( ++ "WARNING: Fell back to English for the following translations:") ++ for (id, langs) in self.fallback_translations_.items(): ++ lines.append( ++ ReportTranslation(self.cliques_[id][0], list(langs.keys()))) ++ if len(self.missing_translations_): ++ lines.append("ERROR: The following translations are MISSING:") ++ for (id, langs) in self.missing_translations_.items(): ++ lines.append( ++ ReportTranslation(self.cliques_[id][0], list(langs.keys()))) ++ return '\n'.join(lines) ++ ++ def MakeClique(self, message, translateable=True): ++ '''Create a new clique initialized with a message. ++ ++ Args: ++ message: tclib.Message() ++ translateable: True | False ++ ''' ++ clique = MessageClique(self, message, translateable) ++ ++ # Enable others to find this clique by its message ID ++ if message.GetId() in self.cliques_: ++ presentable_text = clique.GetMessage().GetPresentableContent() ++ if not message.HasAssignedId(): ++ for c in self.cliques_[message.GetId()]: ++ assert c.GetMessage().GetPresentableContent() == presentable_text ++ self.cliques_[message.GetId()].append(clique) ++ # We need to keep each list of cliques sorted by description, to ++ # achieve stable results from the BestClique method, see below. ++ self.cliques_[message.GetId()].sort( ++ key=lambda c:c.GetMessage().GetDescription()) ++ else: ++ self.cliques_[message.GetId()] = [clique] ++ ++ return clique ++ ++ def FindCliqueAndAddTranslation(self, translation, language): ++ '''Adds the specified translation to the clique with the source message ++ it is a translation of. ++ ++ Args: ++ translation: tclib.Translation() ++ language: 'en' | 'fr' ... ++ ++ Return: ++ True if the source message was found, otherwise false. ++ ''' ++ if translation.GetId() in self.cliques_: ++ for clique in self.cliques_[translation.GetId()]: ++ clique.AddTranslation(translation, language) ++ return True ++ else: ++ return False ++ ++ def BestClique(self, id): ++ '''Returns the "best" clique from a list of cliques. All the cliques ++ must have the same ID. The "best" clique is chosen in the following ++ order of preference: ++ - The first clique that has a non-ID-based description. ++ - If no such clique found, the first clique with an ID-based description. ++ - Otherwise the first clique. ++ ++ This method is stable in terms of always returning a clique with ++ an identical description (on different runs of GRIT on the same ++ data) because self.cliques_ is sorted by description. ++ ''' ++ clique_list = self.cliques_[id] ++ clique_with_id = None ++ clique_default = None ++ for clique in clique_list: ++ if not clique_default: ++ clique_default = clique ++ ++ description = clique.GetMessage().GetDescription() ++ if description and len(description) > 0: ++ if not description.startswith('ID:'): ++ # this is the preferred case so we exit right away ++ return clique ++ elif not clique_with_id: ++ clique_with_id = clique ++ if clique_with_id: ++ return clique_with_id ++ else: ++ return clique_default ++ ++ def BestCliquePerId(self): ++ '''Iterates over the list of all cliques and returns the best clique for ++ each ID. This will be the first clique with a source message that has a ++ non-empty description, or an arbitrary clique if none of them has a ++ description. ++ ''' ++ for id in self.cliques_: ++ yield self.BestClique(id) ++ ++ def BestCliqueByOriginalText(self, text, meaning): ++ '''Finds the "best" (as in BestClique()) clique that has original text ++ 'text' and meaning 'meaning'. Returns None if there is no such clique. ++ ''' ++ # If needed, this can be optimized by maintaining a map of ++ # fingerprints of original text+meaning to cliques. ++ for c in self.BestCliquePerId(): ++ msg = c.GetMessage() ++ if msg.GetRealContent() == text and msg.GetMeaning() == meaning: ++ return msg ++ return None ++ ++ def AllMessageIds(self): ++ '''Returns a list of all defined message IDs. ++ ''' ++ return list(self.cliques_.keys()) ++ ++ def AllCliques(self): ++ '''Iterates over all cliques. Note that this can return multiple cliques ++ with the same ID. ++ ''' ++ for cliques in self.cliques_.values(): ++ for c in cliques: ++ yield c ++ ++ def GenerateXtbParserCallback(self, lang, debug=False): ++ '''Creates a callback function as required by grit.xtb_reader.Parse(). ++ This callback will create Translation objects for each message from ++ the XTB that exists in this uberclique, and add them as translations for ++ the relevant cliques. The callback will add translations to the language ++ specified by 'lang' ++ ++ Args: ++ lang: 'fr' ++ debug: True | False ++ ''' ++ def Callback(id, structure): ++ if id not in self.cliques_: ++ if debug: ++ print("Ignoring translation #%s" % id) ++ return ++ ++ if debug: ++ print("Adding translation #%s" % id) ++ ++ # We fetch placeholder information from the original message (the XTB file ++ # only contains placeholder names). ++ original_msg = self.BestClique(id).GetMessage() ++ ++ translation = tclib.Translation(id=id) ++ for is_ph,text in structure: ++ if not is_ph: ++ translation.AppendText(text) ++ else: ++ found_placeholder = False ++ for ph in original_msg.GetPlaceholders(): ++ if ph.GetPresentation() == text: ++ translation.AppendPlaceholder(tclib.Placeholder( ++ ph.GetPresentation(), ph.GetOriginal(), ph.GetExample())) ++ found_placeholder = True ++ break ++ if not found_placeholder: ++ raise exception.MismatchingPlaceholders( ++ 'Translation for message ID %s had <ph name="%s"/>, no match\n' ++ 'in original message' % (id, text)) ++ self.FindCliqueAndAddTranslation(translation, lang) ++ return Callback ++ ++ ++class CustomType(object): ++ '''A base class you should implement if you wish to specify a custom type ++ for a message clique (i.e. custom validation and optional modification of ++ translations).''' ++ ++ def Validate(self, message): ++ '''Returns true if the message (a tclib.Message object) is valid, ++ otherwise false. ++ ''' ++ raise NotImplementedError() ++ ++ def ValidateAndModify(self, lang, translation): ++ '''Returns true if the translation (a tclib.Translation object) is valid, ++ otherwise false. The language is also passed in. This method may modify ++ the translation that is passed in, if it so wishes. ++ ''' ++ raise NotImplementedError() ++ ++ def ModifyTextPart(self, lang, text): ++ '''If you call ModifyEachTextPart, it will turn around and call this method ++ for each text part of the translation. You should return the modified ++ version of the text, or just the original text to not change anything. ++ ''' ++ raise NotImplementedError() ++ ++ def ModifyEachTextPart(self, lang, translation): ++ '''Call this to easily modify one or more of the textual parts of a ++ translation. It will call ModifyTextPart for each part of the ++ translation. ++ ''' ++ contents = translation.GetContent() ++ for ix in range(len(contents)): ++ if (isinstance(contents[ix], six.string_types)): ++ contents[ix] = self.ModifyTextPart(lang, contents[ix]) ++ ++ ++class OneOffCustomType(CustomType): ++ '''A very simple custom type that performs the validation expressed by ++ the input expression on all languages including the source language. ++ The expression can access the variables 'lang', 'msg' and 'text()' where ++ 'lang' is the language of 'msg', 'msg' is the message or translation being ++ validated and 'text()' returns the real contents of 'msg' (for shorthand). ++ ''' ++ def __init__(self, expression): ++ self.expr = expression ++ def Validate(self, message): ++ return self.ValidateAndModify(MessageClique.source_language, message) ++ def ValidateAndModify(self, lang, msg): ++ def text(): ++ return msg.GetRealContent() ++ return eval(self.expr, {}, ++ {'lang' : lang, ++ 'text' : text, ++ 'msg' : msg, ++ }) ++ ++ ++class MessageClique(object): ++ '''A message along with all of its translations. Also code to bring ++ translations together with their original message.''' ++ ++ # change this to the language code of Messages you add to cliques_. ++ # TODO(joi) Actually change this based on the <grit> node's source language ++ source_language = 'en' ++ ++ # A constant translation we use when asked for a translation into the ++ # special language constants.CONSTANT_LANGUAGE. ++ CONSTANT_TRANSLATION = tclib.Translation(text='TTTTTT') ++ ++ # A pattern to match messages that are empty or whitespace only. ++ WHITESPACE_MESSAGE = lazy_re.compile(r'^\s*$') ++ ++ def __init__(self, uber_clique, message, translateable=True, ++ custom_type=None): ++ '''Create a new clique initialized with just a message. ++ ++ Note that messages with a body comprised only of whitespace will implicitly ++ be marked non-translatable. ++ ++ Args: ++ uber_clique: Our uber-clique (collection of cliques) ++ message: tclib.Message() ++ translateable: True | False ++ custom_type: instance of clique.CustomType interface ++ ''' ++ # Our parent ++ self.uber_clique = uber_clique ++ # If not translateable, we only store the original message. ++ self.translateable = translateable ++ ++ # We implicitly mark messages that have a whitespace-only body as ++ # non-translateable. ++ if MessageClique.WHITESPACE_MESSAGE.match(message.GetRealContent()): ++ self.translateable = False ++ ++ # A mapping of language identifiers to tclib.BaseMessage and its ++ # subclasses (i.e. tclib.Message and tclib.Translation). ++ self.clique = { MessageClique.source_language : message } ++ # A list of the "shortcut groups" this clique is ++ # part of. Within any given shortcut group, no shortcut key (e.g. &J) ++ # must appear more than once in each language for all cliques that ++ # belong to the group. ++ self.shortcut_groups = [] ++ # An instance of the CustomType interface, or None. If this is set, it will ++ # be used to validate the original message and translations thereof, and ++ # will also get a chance to modify translations of the message. ++ self.SetCustomType(custom_type) ++ ++ def GetMessage(self): ++ '''Retrieves the tclib.Message that is the source for this clique.''' ++ return self.clique[MessageClique.source_language] ++ ++ def GetId(self): ++ '''Retrieves the message ID of the messages in this clique.''' ++ return self.GetMessage().GetId() ++ ++ def IsTranslateable(self): ++ return self.translateable ++ ++ def AddToShortcutGroup(self, group): ++ self.shortcut_groups.append(group) ++ ++ def SetCustomType(self, custom_type): ++ '''Makes this clique use custom_type for validating messages and ++ translations, and optionally modifying translations. ++ ''' ++ self.custom_type = custom_type ++ if custom_type and not custom_type.Validate(self.GetMessage()): ++ raise exception.InvalidMessage(self.GetMessage().GetRealContent()) ++ ++ def MessageForLanguage(self, lang, pseudo_if_no_match=True, ++ fallback_to_english=False): ++ '''Returns the message/translation for the specified language, providing ++ a pseudotranslation if there is no available translation and a pseudo- ++ translation is requested. ++ ++ The translation of any message whatsoever in the special language ++ 'x_constant' is the message "TTTTTT". ++ ++ Args: ++ lang: 'en' ++ pseudo_if_no_match: True ++ fallback_to_english: False ++ ++ Return: ++ tclib.BaseMessage ++ ''' ++ if not self.translateable: ++ return self.GetMessage() ++ ++ if lang == constants.CONSTANT_LANGUAGE: ++ return self.CONSTANT_TRANSLATION ++ ++ for msglang in self.clique: ++ if lang == msglang: ++ return self.clique[msglang] ++ ++ if lang == constants.FAKE_BIDI: ++ return pseudo_rtl.PseudoRTLMessage(self.GetMessage()) ++ ++ if fallback_to_english: ++ self.uber_clique._AddMissingTranslation(lang, self, is_error=False) ++ return self.GetMessage() ++ ++ # If we're not supposed to generate pseudotranslations, we add an error ++ # report to a list of errors, then fail at a higher level, so that we ++ # get a list of all messages that are missing translations. ++ if not pseudo_if_no_match: ++ self.uber_clique._AddMissingTranslation(lang, self, is_error=True) ++ ++ return pseudo.PseudoMessage(self.GetMessage()) ++ ++ def AllMessagesThatMatch(self, lang_re, include_pseudo = True): ++ '''Returns a map of all messages that match 'lang', including the pseudo ++ translation if requested. ++ ++ Args: ++ lang_re: re.compile(r'fr|en') ++ include_pseudo: True ++ ++ Return: ++ { 'en' : tclib.Message, ++ 'fr' : tclib.Translation, ++ pseudo.PSEUDO_LANG : tclib.Translation } ++ ''' ++ if not self.translateable: ++ return [self.GetMessage()] ++ ++ matches = {} ++ for msglang in self.clique: ++ if lang_re.match(msglang): ++ matches[msglang] = self.clique[msglang] ++ ++ if include_pseudo: ++ matches[pseudo.PSEUDO_LANG] = pseudo.PseudoMessage(self.GetMessage()) ++ ++ return matches ++ ++ def AddTranslation(self, translation, language): ++ '''Add a translation to this clique. The translation must have the same ++ ID as the message that is the source for this clique. ++ ++ If this clique is not translateable, the function just returns. ++ ++ Args: ++ translation: tclib.Translation() ++ language: 'en' ++ ++ Throws: ++ grit.exception.InvalidTranslation if the translation you're trying to add ++ doesn't have the same message ID as the source message of this clique. ++ ''' ++ if not self.translateable: ++ return ++ if translation.GetId() != self.GetId(): ++ raise exception.InvalidTranslation( ++ 'Msg ID %s, transl ID %s' % (self.GetId(), translation.GetId())) ++ ++ assert not language in self.clique ++ ++ # Because two messages can differ in the original content of their ++ # placeholders yet share the same ID (because they are otherwise the ++ # same), the translation we are getting may have different original ++ # content for placeholders than our message, yet it is still the right ++ # translation for our message (because it is for the same ID). We must ++ # therefore fetch the original content of placeholders from our original ++ # English message. ++ # ++ # See grit.clique_unittest.MessageCliqueUnittest.testSemiIdenticalCliques ++ # for a concrete explanation of why this is necessary. ++ ++ original = self.MessageForLanguage(self.source_language, False) ++ if len(original.GetPlaceholders()) != len(translation.GetPlaceholders()): ++ print("ERROR: '%s' translation of message id %s does not match" % ++ (language, translation.GetId())) ++ assert False ++ ++ transl_msg = tclib.Translation(id=self.GetId(), ++ text=translation.GetPresentableContent(), ++ placeholders=original.GetPlaceholders()) ++ ++ if (self.custom_type and ++ not self.custom_type.ValidateAndModify(language, transl_msg)): ++ print("WARNING: %s translation failed validation: %s" % ++ (language, transl_msg.GetId())) ++ ++ self.clique[language] = transl_msg +diff --git a/tools/grit/grit/clique_unittest.py b/tools/grit/grit/clique_unittest.py +new file mode 100644 +index 0000000000..7d2d7318ba +--- /dev/null ++++ b/tools/grit/grit/clique_unittest.py +@@ -0,0 +1,265 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for grit.clique''' ++ ++from __future__ import print_function ++ ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '..')) ++ ++import re ++import unittest ++ ++from six import StringIO ++ ++from grit import clique ++from grit import exception ++from grit import pseudo ++from grit import tclib ++from grit import grd_reader ++from grit import util ++ ++class MessageCliqueUnittest(unittest.TestCase): ++ def testClique(self): ++ factory = clique.UberClique() ++ msg = tclib.Message(text='Hello USERNAME, how are you?', ++ placeholders=[ ++ tclib.Placeholder('USERNAME', '%s', 'Joi')]) ++ c = factory.MakeClique(msg) ++ ++ self.failUnless(c.GetMessage() == msg) ++ self.failUnless(c.GetId() == msg.GetId()) ++ ++ msg_fr = tclib.Translation(text='Bonjour USERNAME, comment ca va?', ++ id=msg.GetId(), placeholders=[ ++ tclib.Placeholder('USERNAME', '%s', 'Joi')]) ++ msg_de = tclib.Translation(text='Guten tag USERNAME, wie geht es dir?', ++ id=msg.GetId(), placeholders=[ ++ tclib.Placeholder('USERNAME', '%s', 'Joi')]) ++ ++ c.AddTranslation(msg_fr, 'fr') ++ factory.FindCliqueAndAddTranslation(msg_de, 'de') ++ ++ # sort() sorts lists in-place and does not return them ++ for lang in ('en', 'fr', 'de'): ++ self.failUnless(lang in c.clique) ++ ++ self.failUnless(c.MessageForLanguage('fr').GetRealContent() == ++ msg_fr.GetRealContent()) ++ ++ try: ++ c.MessageForLanguage('zh-CN', False) ++ self.fail('Should have gotten exception') ++ except: ++ pass ++ ++ self.failUnless(c.MessageForLanguage('zh-CN', True) != None) ++ ++ rex = re.compile('fr|de|bingo') ++ self.failUnless(len(c.AllMessagesThatMatch(rex, False)) == 2) ++ self.failUnless( ++ c.AllMessagesThatMatch(rex, True)[pseudo.PSEUDO_LANG] is not None) ++ ++ def testBestClique(self): ++ factory = clique.UberClique() ++ factory.MakeClique(tclib.Message(text='Alfur', description='alfaholl')) ++ factory.MakeClique(tclib.Message(text='Alfur', description='')) ++ factory.MakeClique(tclib.Message(text='Vaettur', description='')) ++ factory.MakeClique(tclib.Message(text='Vaettur', description='')) ++ factory.MakeClique(tclib.Message(text='Troll', description='')) ++ factory.MakeClique(tclib.Message(text='Gryla', description='ID: IDS_GRYLA')) ++ factory.MakeClique(tclib.Message(text='Gryla', description='vondakerling')) ++ factory.MakeClique(tclib.Message(text='Leppaludi', description='ID: IDS_LL')) ++ factory.MakeClique(tclib.Message(text='Leppaludi', description='')) ++ ++ count_best_cliques = 0 ++ for c in factory.BestCliquePerId(): ++ count_best_cliques += 1 ++ msg = c.GetMessage() ++ text = msg.GetRealContent() ++ description = msg.GetDescription() ++ if text == 'Alfur': ++ self.failUnless(description == 'alfaholl') ++ elif text == 'Gryla': ++ self.failUnless(description == 'vondakerling') ++ elif text == 'Leppaludi': ++ self.failUnless(description == 'ID: IDS_LL') ++ self.failUnless(count_best_cliques == 5) ++ ++ def testAllInUberClique(self): ++ resources = grd_reader.Parse( ++ StringIO(u'''<?xml version="1.0" encoding="UTF-8"?> ++<grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <release seq="3"> ++ <messages> ++ <message name="IDS_GREETING" desc="Printed to greet the currently logged in user"> ++ Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today? ++ </message> ++ </messages> ++ <structures> ++ <structure type="dialog" name="IDD_ABOUTBOX" encoding="utf-16" file="grit/testdata/klonk.rc" /> ++ <structure type="tr_html" name="ID_HTML" file="grit/testdata/simple.html" /> ++ </structures> ++ </release> ++</grit>'''), util.PathFromRoot('.')) ++ resources.SetOutputLanguage('en') ++ resources.RunGatherers() ++ content_list = [] ++ for clique_list in resources.UberClique().cliques_.values(): ++ for clique in clique_list: ++ content_list.append(clique.GetMessage().GetRealContent()) ++ self.failUnless('Hello %s, how are you doing today?' in content_list) ++ self.failUnless('Jack "Black" Daniels' in content_list) ++ self.failUnless('Hello!' in content_list) ++ ++ def testCorrectExceptionIfWrongEncodingOnResourceFile(self): ++ '''This doesn't really belong in this unittest file, but what the heck.''' ++ resources = grd_reader.Parse( ++ StringIO(u'''<?xml version="1.0" encoding="UTF-8"?> ++<grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <release seq="3"> ++ <structures> ++ <structure type="dialog" name="IDD_ABOUTBOX" file="grit/testdata/klonk.rc" /> ++ </structures> ++ </release> ++</grit>'''), util.PathFromRoot('.')) ++ self.assertRaises(exception.SectionNotFound, resources.RunGatherers) ++ ++ def testSemiIdenticalCliques(self): ++ messages = [ ++ tclib.Message(text='Hello USERNAME', ++ placeholders=[tclib.Placeholder('USERNAME', '$1', 'Joi')]), ++ tclib.Message(text='Hello USERNAME', ++ placeholders=[tclib.Placeholder('USERNAME', '%s', 'Joi')]), ++ ] ++ self.failUnless(messages[0].GetId() == messages[1].GetId()) ++ ++ # Both of the above would share a translation. ++ translation = tclib.Translation(id=messages[0].GetId(), ++ text='Bonjour USERNAME', ++ placeholders=[tclib.Placeholder( ++ 'USERNAME', '$1', 'Joi')]) ++ ++ factory = clique.UberClique() ++ cliques = [factory.MakeClique(msg) for msg in messages] ++ ++ for clq in cliques: ++ clq.AddTranslation(translation, 'fr') ++ ++ self.failUnless(cliques[0].MessageForLanguage('fr').GetRealContent() == ++ 'Bonjour $1') ++ self.failUnless(cliques[1].MessageForLanguage('fr').GetRealContent() == ++ 'Bonjour %s') ++ ++ def testMissingTranslations(self): ++ messages = [ tclib.Message(text='Hello'), tclib.Message(text='Goodbye') ] ++ factory = clique.UberClique() ++ cliques = [factory.MakeClique(msg) for msg in messages] ++ ++ cliques[1].MessageForLanguage('fr', False, True) ++ ++ self.failUnless(not factory.HasMissingTranslations()) ++ ++ cliques[0].MessageForLanguage('de', False, False) ++ ++ self.failUnless(factory.HasMissingTranslations()) ++ ++ report = factory.MissingTranslationsReport() ++ self.failUnless(report.count('WARNING') == 1) ++ self.failUnless(report.count('8053599568341804890 "Goodbye" fr') == 1) ++ self.failUnless(report.count('ERROR') == 1) ++ self.failUnless(report.count('800120468867715734 "Hello" de') == 1) ++ ++ def testCustomTypes(self): ++ factory = clique.UberClique() ++ message = tclib.Message(text='Bingo bongo') ++ c = factory.MakeClique(message) ++ try: ++ c.SetCustomType(DummyCustomType()) ++ self.fail() ++ except: ++ pass # expected case - 'Bingo bongo' does not start with 'jjj' ++ ++ message = tclib.Message(text='jjjBingo bongo') ++ c = factory.MakeClique(message) ++ c.SetCustomType(util.NewClassInstance( ++ 'grit.clique_unittest.DummyCustomType', clique.CustomType)) ++ translation = tclib.Translation(id=message.GetId(), text='Bilingo bolongo') ++ c.AddTranslation(translation, 'fr') ++ self.failUnless(c.MessageForLanguage('fr').GetRealContent().startswith('jjj')) ++ ++ def testWhitespaceMessagesAreNontranslateable(self): ++ factory = clique.UberClique() ++ ++ message = tclib.Message(text=' \t') ++ c = factory.MakeClique(message, translateable=True) ++ self.failIf(c.IsTranslateable()) ++ ++ message = tclib.Message(text='\n \n ') ++ c = factory.MakeClique(message, translateable=True) ++ self.failIf(c.IsTranslateable()) ++ ++ message = tclib.Message(text='\n hello') ++ c = factory.MakeClique(message, translateable=True) ++ self.failUnless(c.IsTranslateable()) ++ ++ def testEachCliqueKeptSorted(self): ++ factory = clique.UberClique() ++ msg_a = tclib.Message(text='hello', description='a') ++ msg_b = tclib.Message(text='hello', description='b') ++ msg_c = tclib.Message(text='hello', description='c') ++ # Insert out of order ++ clique_b = factory.MakeClique(msg_b, translateable=True) ++ clique_a = factory.MakeClique(msg_a, translateable=True) ++ clique_c = factory.MakeClique(msg_c, translateable=True) ++ clique_list = factory.cliques_[clique_a.GetId()] ++ self.failUnless(len(clique_list) == 3) ++ self.failUnless(clique_list[0] == clique_a) ++ self.failUnless(clique_list[1] == clique_b) ++ self.failUnless(clique_list[2] == clique_c) ++ ++ def testBestCliqueSortIsStable(self): ++ factory = clique.UberClique() ++ text = 'hello' ++ msg_no_description = tclib.Message(text=text) ++ msg_id_description_a = tclib.Message(text=text, description='ID: a') ++ msg_id_description_b = tclib.Message(text=text, description='ID: b') ++ msg_description_x = tclib.Message(text=text, description='x') ++ msg_description_y = tclib.Message(text=text, description='y') ++ clique_id = msg_no_description.GetId() ++ ++ # Insert in an order that tests all outcomes. ++ clique_no_description = factory.MakeClique(msg_no_description, ++ translateable=True) ++ self.failUnless(factory.BestClique(clique_id) == clique_no_description) ++ clique_id_description_b = factory.MakeClique(msg_id_description_b, ++ translateable=True) ++ self.failUnless(factory.BestClique(clique_id) == clique_id_description_b) ++ clique_id_description_a = factory.MakeClique(msg_id_description_a, ++ translateable=True) ++ self.failUnless(factory.BestClique(clique_id) == clique_id_description_a) ++ clique_description_y = factory.MakeClique(msg_description_y, ++ translateable=True) ++ self.failUnless(factory.BestClique(clique_id) == clique_description_y) ++ clique_description_x = factory.MakeClique(msg_description_x, ++ translateable=True) ++ self.failUnless(factory.BestClique(clique_id) == clique_description_x) ++ ++ ++class DummyCustomType(clique.CustomType): ++ def Validate(self, message): ++ return message.GetRealContent().startswith('jjj') ++ def ValidateAndModify(self, lang, translation): ++ is_ok = self.Validate(translation) ++ self.ModifyEachTextPart(lang, translation) ++ def ModifyTextPart(self, lang, text): ++ return 'jjj%s' % text ++ ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/constants.py b/tools/grit/grit/constants.py +new file mode 100644 +index 0000000000..8229c94b09 +--- /dev/null ++++ b/tools/grit/grit/constants.py +@@ -0,0 +1,23 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Constant definitions for GRIT. ++''' ++ ++from __future__ import print_function ++ ++# This is the Icelandic noun meaning "grit" and is used to check that our ++# input files are in the correct encoding. The middle character gets encoded ++# as two bytes in UTF-8, so this is sufficient to detect incorrect encoding. ++ENCODING_CHECK = u'm\u00f6l' ++ ++# A special language, translations into which are always "TTTTTT". ++CONSTANT_LANGUAGE = 'x_constant' ++ ++FAKE_BIDI = 'fake-bidi' ++ ++# Magic number added to the header of resources brotli compressed by grit. Used ++# to easily identify resources as being brotli compressed. See ++# ui/base/resource/resource_bundle.h for decompression usage. ++BROTLI_CONST = b'\x1e\x9b' +diff --git a/tools/grit/grit/exception.py b/tools/grit/grit/exception.py +new file mode 100644 +index 0000000000..2a363fb077 +--- /dev/null ++++ b/tools/grit/grit/exception.py +@@ -0,0 +1,139 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Exception types for GRIT. ++''' ++ ++from __future__ import print_function ++ ++class Base(Exception): ++ '''A base exception that uses the class's docstring in addition to any ++ user-provided message as the body of the Base. ++ ''' ++ def __init__(self, msg=''): ++ if len(msg): ++ if self.__doc__: ++ msg = self.__doc__ + ': ' + msg ++ else: ++ msg = self.__doc__ ++ super(Base, self).__init__(msg) ++ ++ ++class Parsing(Base): ++ '''An error occurred parsing a GRD or XTB file.''' ++ pass ++ ++ ++class UnknownElement(Parsing): ++ '''An unknown node type was encountered.''' ++ pass ++ ++ ++class MissingElement(Parsing): ++ '''An expected element was missing.''' ++ pass ++ ++ ++class UnexpectedChild(Parsing): ++ '''An unexpected child element was encountered (on a leaf node).''' ++ pass ++ ++ ++class UnexpectedAttribute(Parsing): ++ '''The attribute was not expected''' ++ pass ++ ++ ++class UnexpectedContent(Parsing): ++ '''This element should not have content''' ++ pass ++ ++class MissingMandatoryAttribute(Parsing): ++ '''This element is missing a mandatory attribute''' ++ pass ++ ++ ++class MutuallyExclusiveMandatoryAttribute(Parsing): ++ '''This element has 2 mutually exclusive mandatory attributes''' ++ pass ++ ++ ++class DuplicateKey(Parsing): ++ '''A duplicate key attribute was found.''' ++ pass ++ ++ ++class TooManyExamples(Parsing): ++ '''Only one <ex> element is allowed for each <ph> element.''' ++ pass ++ ++ ++class FileNotFound(Parsing): ++ '''The resource file was not found.''' ++ pass ++ ++ ++class InvalidMessage(Base): ++ '''The specified message failed validation.''' ++ pass ++ ++ ++class InvalidTranslation(Base): ++ '''Attempt to add an invalid translation to a clique.''' ++ pass ++ ++ ++class NoSuchTranslation(Base): ++ '''Requested translation not available''' ++ pass ++ ++ ++class NotReady(Base): ++ '''Attempt to use an object before it is ready, or attempt to translate \ ++an empty document.''' ++ pass ++ ++ ++class MismatchingPlaceholders(Base): ++ '''Placeholders do not match.''' ++ pass ++ ++ ++class InvalidPlaceholderName(Base): ++ '''Placeholder name can only contain A-Z, a-z, 0-9 and underscore.''' ++ pass ++ ++ ++class BlockTagInTranslateableChunk(Base): ++ '''A block tag was encountered where it wasn't expected.''' ++ pass ++ ++ ++class SectionNotFound(Base): ++ '''The section you requested was not found in the RC file. Make \ ++sure the section ID is correct (matches the section's ID in the RC file). \ ++Also note that you may need to specify the RC file's encoding (using the \ ++encoding="" attribute) if it is not in the default Windows-1252 encoding. \ ++''' ++ pass ++ ++ ++class IdRangeOverlap(Base): ++ '''ID range overlap.''' ++ pass ++ ++ ++class ReservedHeaderCollision(Base): ++ '''Resource included with first 3 bytes matching reserved header.''' ++ pass ++ ++ ++class PlaceholderNotInsidePhNode(Base): ++ '''Placeholder formatters should be inside <ph> element.''' ++ pass ++ ++ ++class InvalidCharactersInsidePhNode(Base): ++ '''Invalid characters found inside <ph> element.''' ++ pass +diff --git a/tools/grit/grit/extern/BogoFP.py b/tools/grit/grit/extern/BogoFP.py +new file mode 100644 +index 0000000000..fc90145833 +--- /dev/null ++++ b/tools/grit/grit/extern/BogoFP.py +@@ -0,0 +1,22 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++"""Bogus fingerprint implementation, do not use for production, ++provided only as an example. ++ ++Usage: ++ grit.py -h grit.extern.BogoFP xmb /tmp/foo ++""" ++ ++from __future__ import print_function ++ ++import grit.extern.FP ++ ++ ++def UnsignedFingerPrint(str, encoding='utf-8'): ++ """Generate a fingerprint not intended for production from str (it ++ reduces the precision of the production fingerprint by one bit). ++ """ ++ return (0xFFFFF7FFFFFFFFFF & ++ grit.extern.FP._UnsignedFingerPrintImpl(str, encoding)) +diff --git a/tools/grit/grit/extern/FP.py b/tools/grit/grit/extern/FP.py +new file mode 100644 +index 0000000000..f4ec4d943f +--- /dev/null ++++ b/tools/grit/grit/extern/FP.py +@@ -0,0 +1,72 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++from __future__ import print_function ++ ++try: ++ import hashlib ++ _new_md5 = hashlib.md5 ++except ImportError: ++ import md5 ++ _new_md5 = md5.new ++ ++ ++"""64-bit fingerprint support for strings. ++ ++Usage: ++ from extern import FP ++ print('Fingerprint is %ld' % FP.FingerPrint('Hello world!')) ++""" ++ ++ ++def _UnsignedFingerPrintImpl(str, encoding='utf-8'): ++ """Generate a 64-bit fingerprint by taking the first half of the md5 ++ of the string. ++ """ ++ hex128 = _new_md5(str.encode(encoding)).hexdigest() ++ int64 = int(hex128[:16], 16) ++ return int64 ++ ++ ++def UnsignedFingerPrint(str, encoding='utf-8'): ++ """Generate a 64-bit fingerprint. ++ ++ The default implementation uses _UnsignedFingerPrintImpl, which ++ takes the first half of the md5 of the string, but the ++ implementation may be switched using SetUnsignedFingerPrintImpl. ++ """ ++ return _UnsignedFingerPrintImpl(str, encoding) ++ ++ ++def FingerPrint(str, encoding='utf-8'): ++ fp = UnsignedFingerPrint(str, encoding=encoding) ++ # interpret fingerprint as signed longs ++ if fp & 0x8000000000000000: ++ fp = -((~fp & 0xFFFFFFFFFFFFFFFF) + 1) ++ return fp ++ ++ ++def UseUnsignedFingerPrintFromModule(module_name): ++ """Imports module_name and replaces UnsignedFingerPrint in the ++ current module with the function of the same name from the imported ++ module. ++ ++ Returns the function object previously known as ++ grit.extern.FP.UnsignedFingerPrint. ++ """ ++ hash_module = __import__(module_name, fromlist=[module_name]) ++ return SetUnsignedFingerPrint(hash_module.UnsignedFingerPrint) ++ ++ ++def SetUnsignedFingerPrint(function_object): ++ """Sets grit.extern.FP.UnsignedFingerPrint to point to ++ function_object. + -+std::string ChromeClassTester::GetNamespace(const Decl* record) { -+ return GetNamespaceImpl(record->getDeclContext(), ""); ++ Returns the function object previously known as ++ grit.extern.FP.UnsignedFingerPrint. ++ """ ++ global UnsignedFingerPrint ++ original_function_object = UnsignedFingerPrint ++ UnsignedFingerPrint = function_object ++ return original_function_object +diff --git a/tools/grit/grit/extern/__init__.py b/tools/grit/grit/extern/__init__.py +new file mode 100644 +index 0000000000..e69de29bb2 +diff --git a/tools/grit/grit/extern/tclib.py b/tools/grit/grit/extern/tclib.py +new file mode 100644 +index 0000000000..9952a87c11 +--- /dev/null ++++ b/tools/grit/grit/extern/tclib.py +@@ -0,0 +1,503 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++# The tclib module contains tools for aggregating, verifying, and storing ++# messages destined for the Translation Console, as well as for reading ++# translations back and outputting them in some desired format. ++# ++# This has been stripped down to include only the functionality needed by grit ++# for creating Windows .rc and .h files. These are the only parts needed by ++# the Chrome build process. ++ ++from __future__ import print_function ++ ++from grit.extern import FP ++ ++# This module assumes that within a bundle no two messages can have the ++# same id unless they're identical. ++ ++# The basic classes defined here for external use are Message and Translation, ++# where the former is used for English messages and the latter for ++# translations. These classes have a lot of common functionality, as expressed ++# by the common parent class BaseMessage. Perhaps the most important ++# distinction is that translated text is stored in UTF-8, whereas original text ++# is stored in whatever encoding the client uses (presumably Latin-1). ++ ++# -------------------- ++# The public interface ++# -------------------- ++ ++# Generate message id from message text and meaning string (optional), ++# both in utf-8 encoding ++# ++def GenerateMessageId(message, meaning=''): ++ fp = FP.FingerPrint(message) ++ if meaning: ++ # combine the fingerprints of message and meaning ++ fp2 = FP.FingerPrint(meaning) ++ if fp < 0: ++ fp = fp2 + (fp << 1) + 1 ++ else: ++ fp = fp2 + (fp << 1) ++ # To avoid negative ids we strip the high-order bit ++ return str(fp & 0x7fffffffffffffff) ++ ++# ------------------------------------------------------------------------- ++# The MessageTranslationError class is used to signal tclib-specific errors. ++ ++ ++class MessageTranslationError(Exception): ++ ++ def __init__(self, args = ''): ++ self.args = args ++ ++ ++# ----------------------------------------------------------- ++# The Placeholder class represents a placeholder in a message. ++ ++class Placeholder(object): ++ # String representation ++ def __str__(self): ++ return '%s, "%s", "%s"' % \ ++ (self.__presentation, self.__original, self.__example) ++ ++ # Getters ++ def GetOriginal(self): ++ return self.__original ++ ++ def GetPresentation(self): ++ return self.__presentation ++ ++ def GetExample(self): ++ return self.__example ++ ++ def __eq__(self, other): ++ return self.EqualTo(other, strict=1, ignore_trailing_spaces=0) ++ ++ # Equality test ++ # ++ # ignore_trailing_spaces: TC is using varchar to store the ++ # phrwr fields, as a result of that, the trailing spaces ++ # are removed by MySQL when the strings are stored into TC:-( ++ # ignore_trailing_spaces parameter is used to ignore ++ # trailing spaces during equivalence comparison. ++ # ++ def EqualTo(self, other, strict = 1, ignore_trailing_spaces = 1): ++ if type(other) is not Placeholder: ++ return 0 ++ if StringEquals(self.__presentation, other.__presentation, ++ ignore_trailing_spaces): ++ if not strict or (StringEquals(self.__original, other.__original, ++ ignore_trailing_spaces) and ++ StringEquals(self.__example, other.__example, ++ ignore_trailing_spaces)): ++ return 1 ++ return 0 ++ ++ ++# ----------------------------------------------------------------- ++# BaseMessage is the common parent class of Message and Translation. ++# It is not meant for direct use. ++ ++class BaseMessage(object): ++ # Three types of message construction is supported. If the message text is a ++ # simple string with no dynamic content, you can pass it to the constructor ++ # as the "text" parameter. Otherwise, you can omit "text" and assemble the ++ # message step by step using AppendText() and AppendPlaceholder(). Or, as an ++ # alternative, you can give the constructor the "presentable" version of the ++ # message and a list of placeholders; it will then parse the presentation and ++ # build the message accordingly. For example: ++ # Message(text = "There are NUM_BUGS bugs in your code", ++ # placeholders = [Placeholder("NUM_BUGS", "%d", "33")], ++ # description = "Bla bla bla") ++ def __eq__(self, other): ++ # "source encoding" is nonsense, so ignore it ++ return _ObjectEquals(self, other, ['_BaseMessage__source_encoding']) ++ ++ def GetName(self): ++ return self.__name ++ ++ def GetSourceEncoding(self): ++ return self.__source_encoding ++ ++ # Append a placeholder to the message ++ def AppendPlaceholder(self, placeholder): ++ if not isinstance(placeholder, Placeholder): ++ raise MessageTranslationError("Invalid message placeholder %s in " ++ "message %s" % (placeholder, self.GetId())) ++ # Are there other placeholders with the same presentation? ++ # If so, they need to be the same. ++ for other in self.GetPlaceholders(): ++ if placeholder.GetPresentation() == other.GetPresentation(): ++ if not placeholder.EqualTo(other): ++ raise MessageTranslationError( ++ "Conflicting declarations of %s within message" % ++ placeholder.GetPresentation()) ++ # update placeholder list ++ dup = 0 ++ for item in self.__content: ++ if isinstance(item, Placeholder) and placeholder.EqualTo(item): ++ dup = 1 ++ break ++ if not dup: ++ self.__placeholders.append(placeholder) ++ ++ # update content ++ self.__content.append(placeholder) ++ ++ # Strips leading and trailing whitespace, and returns a tuple ++ # containing the leading and trailing space that was removed. ++ def Strip(self): ++ leading = trailing = '' ++ if len(self.__content) > 0: ++ s0 = self.__content[0] ++ if not isinstance(s0, Placeholder): ++ s = s0.lstrip() ++ leading = s0[:-len(s)] ++ self.__content[0] = s ++ ++ s0 = self.__content[-1] ++ if not isinstance(s0, Placeholder): ++ s = s0.rstrip() ++ trailing = s0[len(s):] ++ self.__content[-1] = s ++ return leading, trailing ++ ++ # Return the id of this message ++ def GetId(self): ++ if self.__id is None: ++ return self.GenerateId() ++ return self.__id ++ ++ # Set the id of this message ++ def SetId(self, id): ++ if id is None: ++ self.__id = None ++ else: ++ self.__id = str(id) # Treat numerical ids as strings ++ ++ # Return content of this message as a list (internal use only) ++ def GetContent(self): ++ return self.__content ++ ++ # Return a human-readable version of this message ++ def GetPresentableContent(self): ++ presentable_content = "" ++ for item in self.__content: ++ if isinstance(item, Placeholder): ++ presentable_content += item.GetPresentation() ++ else: ++ presentable_content += item ++ ++ return presentable_content ++ ++ # Return a fragment of a message in escaped format ++ def EscapeFragment(self, fragment): ++ return fragment.replace('%', '%%') ++ ++ # Return the "original" version of this message, doing %-escaping ++ # properly. If source_msg is specified, the placeholder original ++ # information inside source_msg will be used instead. ++ def GetOriginalContent(self, source_msg = None): ++ original_content = "" ++ for item in self.__content: ++ if isinstance(item, Placeholder): ++ if source_msg: ++ ph = source_msg.GetPlaceholder(item.GetPresentation()) ++ if not ph: ++ raise MessageTranslationError( ++ "Placeholder %s doesn't exist in message: %s" % ++ (item.GetPresentation(), source_msg)) ++ original_content += ph.GetOriginal() ++ else: ++ original_content += item.GetOriginal() ++ else: ++ original_content += self.EscapeFragment(item) ++ return original_content ++ ++ # Return the example of this message ++ def GetExampleContent(self): ++ example_content = "" ++ for item in self.__content: ++ if isinstance(item, Placeholder): ++ example_content += item.GetExample() ++ else: ++ example_content += item ++ return example_content ++ ++ # Return a list of all unique placeholders in this message ++ def GetPlaceholders(self): ++ return self.__placeholders ++ ++ # Return a placeholder in this message ++ def GetPlaceholder(self, presentation): ++ for item in self.__content: ++ if (isinstance(item, Placeholder) and ++ item.GetPresentation() == presentation): ++ return item ++ return None ++ ++ # Return this message's description ++ def GetDescription(self): ++ return self.__description ++ ++ # Add a message source ++ def AddSource(self, source): ++ self.__sources.append(source) ++ ++ # Return this message's sources as a list ++ def GetSources(self): ++ return self.__sources ++ ++ # Return this message's sources as a string ++ def GetSourcesAsText(self, delimiter = "; "): ++ return delimiter.join(self.__sources) ++ ++ # Set the obsolete flag for a message (internal use only) ++ def SetObsolete(self): ++ self.__obsolete = 1 ++ ++ # Get the obsolete flag for a message (internal use only) ++ def IsObsolete(self): ++ return self.__obsolete ++ ++ # Get the sequence number (0 by default) ++ def GetSequenceNumber(self): ++ return self.__sequence_number ++ ++ # Set the sequence number ++ def SetSequenceNumber(self, number): ++ self.__sequence_number = number ++ ++ # Increment instance counter ++ def AddInstance(self): ++ self.__num_instances += 1 ++ ++ # Return instance count ++ def GetNumInstances(self): ++ return self.__num_instances ++ ++ def GetErrors(self, from_tc=0): ++ """ ++ Returns a description of the problem if the message is not ++ syntactically valid, or None if everything is fine. ++ ++ Args: ++ from_tc: indicates whether this message came from the TC. We let ++ the TC get away with some things we normally wouldn't allow for ++ historical reasons. ++ """ ++ # check that placeholders are unambiguous ++ pos = 0 ++ phs = {} ++ for item in self.__content: ++ if isinstance(item, Placeholder): ++ phs[pos] = item ++ pos += len(item.GetPresentation()) ++ else: ++ pos += len(item) ++ presentation = self.GetPresentableContent() ++ for ph in self.GetPlaceholders(): ++ for pos in FindOverlapping(presentation, ph.GetPresentation()): ++ # message contains the same text as a placeholder presentation ++ other_ph = phs.get(pos) ++ if ((not other_ph ++ and not IsSubstringInPlaceholder(pos, len(ph.GetPresentation()), phs)) ++ or ++ (other_ph and len(other_ph.GetPresentation()) < len(ph.GetPresentation()))): ++ return "message contains placeholder name '%s':\n%s" % ( ++ ph.GetPresentation(), presentation) ++ return None ++ ++ ++ def __CopyTo(self, other): ++ """ ++ Returns a copy of this BaseMessage. ++ """ ++ assert isinstance(other, self.__class__) or isinstance(self, other.__class__) ++ other.__source_encoding = self.__source_encoding ++ other.__content = self.__content[:] ++ other.__description = self.__description ++ other.__id = self.__id ++ other.__num_instances = self.__num_instances ++ other.__obsolete = self.__obsolete ++ other.__name = self.__name ++ other.__placeholders = self.__placeholders[:] ++ other.__sequence_number = self.__sequence_number ++ other.__sources = self.__sources[:] ++ ++ return other ++ ++ def HasText(self): ++ """Returns true iff this message has anything other than placeholders.""" ++ for item in self.__content: ++ if not isinstance(item, Placeholder): ++ return True ++ return False ++ ++# -------------------------------------------------------- ++# The Message class represents original (English) messages ++ ++class Message(BaseMessage): ++ # See BaseMessage constructor ++ def __init__(self, source_encoding, text=None, id=None, ++ description=None, meaning="", placeholders=None, ++ source=None, sequence_number=0, clone_from=None, ++ time_created=0, name=None, is_hidden = 0): ++ ++ if clone_from is not None: ++ BaseMessage.__init__(self, None, clone_from=clone_from) ++ self.__meaning = clone_from.__meaning ++ self.__time_created = clone_from.__time_created ++ self.__is_hidden = clone_from.__is_hidden ++ return ++ ++ BaseMessage.__init__(self, source_encoding, text, id, description, ++ placeholders, source, sequence_number, ++ name=name) ++ self.__meaning = meaning ++ self.__time_created = time_created ++ self.SetIsHidden(is_hidden) ++ ++ # String representation ++ def __str__(self): ++ s = 'source: %s, id: %s, content: "%s", meaning: "%s", ' \ ++ 'description: "%s"' % \ ++ (self.GetSourcesAsText(), self.GetId(), self.GetPresentableContent(), ++ self.__meaning, self.GetDescription()) ++ if self.GetName() is not None: ++ s += ', name: "%s"' % self.GetName() ++ placeholders = self.GetPlaceholders() ++ for i in range(len(placeholders)): ++ s += ", placeholder[%d]: %s" % (i, placeholders[i]) ++ return s ++ ++ # Strips leading and trailing whitespace, and returns a tuple ++ # containing the leading and trailing space that was removed. ++ def Strip(self): ++ leading = trailing = '' ++ content = self.GetContent() ++ if len(content) > 0: ++ s0 = content[0] ++ if not isinstance(s0, Placeholder): ++ s = s0.lstrip() ++ leading = s0[:-len(s)] ++ content[0] = s ++ ++ s0 = content[-1] ++ if not isinstance(s0, Placeholder): ++ s = s0.rstrip() ++ trailing = s0[len(s):] ++ content[-1] = s ++ return leading, trailing ++ ++ # Generate an id by hashing message content ++ def GenerateId(self): ++ self.SetId(GenerateMessageId(self.GetPresentableContent(), ++ self.__meaning)) ++ return self.GetId() ++ ++ def GetMeaning(self): ++ return self.__meaning ++ ++ def GetTimeCreated(self): ++ return self.__time_created ++ ++ # Equality operator ++ def EqualTo(self, other, strict = 1): ++ # Check id, meaning, content ++ if self.GetId() != other.GetId(): ++ return 0 ++ if self.__meaning != other.__meaning: ++ return 0 ++ if self.GetPresentableContent() != other.GetPresentableContent(): ++ return 0 ++ # Check descriptions if comparison is strict ++ if (strict and ++ self.GetDescription() is not None and ++ other.GetDescription() is not None and ++ self.GetDescription() != other.GetDescription()): ++ return 0 ++ # Check placeholders ++ ph1 = self.GetPlaceholders() ++ ph2 = other.GetPlaceholders() ++ if len(ph1) != len(ph2): ++ return 0 ++ for i in range(len(ph1)): ++ if not ph1[i].EqualTo(ph2[i], strict): ++ return 0 ++ ++ return 1 ++ ++ def Copy(self): ++ """ ++ Returns a copy of this Message. ++ """ ++ assert isinstance(self, Message) ++ return Message(None, clone_from=self) ++ ++ def SetIsHidden(self, is_hidden): ++ """Sets whether this message should be hidden. ++ ++ Args: ++ is_hidden : 0 or 1 - if the message should be hidden, 0 otherwise ++ """ ++ if is_hidden not in [0, 1]: ++ raise MessageTranslationError("is_hidden must be 0 or 1, got %s") ++ self.__is_hidden = is_hidden ++ ++ def IsHidden(self): ++ """Returns 1 if this message is hidden, and 0 otherwise.""" ++ return self.__is_hidden ++ ++# ---------------------------------------------------- ++# The Translation class represents translated messages ++ ++class Translation(BaseMessage): ++ # See BaseMessage constructor ++ def __init__(self, source_encoding, text=None, id=None, ++ description=None, placeholders=None, source=None, ++ sequence_number=0, clone_from=None, ignore_ph_errors=0, ++ name=None): ++ if clone_from is not None: ++ BaseMessage.__init__(self, None, clone_from=clone_from) ++ return ++ ++ BaseMessage.__init__(self, source_encoding, text, id, description, ++ placeholders, source, sequence_number, ++ ignore_ph_errors=ignore_ph_errors, name=name) ++ ++ # String representation ++ def __str__(self): ++ s = 'source: %s, id: %s, content: "%s", description: "%s"' % \ ++ (self.GetSourcesAsText(), self.GetId(), self.GetPresentableContent(), ++ self.GetDescription()); ++ placeholders = self.GetPlaceholders() ++ for i in range(len(placeholders)): ++ s += ", placeholder[%d]: %s" % (i, placeholders[i]) ++ return s ++ ++ # Equality operator ++ def EqualTo(self, other, strict=1): ++ # Check id and content ++ if self.GetId() != other.GetId(): ++ return 0 ++ if self.GetPresentableContent() != other.GetPresentableContent(): ++ return 0 ++ # Check placeholders ++ ph1 = self.GetPlaceholders() ++ ph2 = other.GetPlaceholders() ++ if len(ph1) != len(ph2): ++ return 0 ++ for i in range(len(ph1)): ++ if not ph1[i].EqualTo(ph2[i], strict): ++ return 0 ++ ++ return 1 ++ ++ def Copy(self): ++ """ ++ Returns a copy of this Translation. ++ """ ++ return Translation(None, clone_from=self) +diff --git a/tools/grit/grit/format/__init__.py b/tools/grit/grit/format/__init__.py +new file mode 100644 +index 0000000000..55d56b8cfd +--- /dev/null ++++ b/tools/grit/grit/format/__init__.py +@@ -0,0 +1,8 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Module grit.format ++''' ++ ++pass +diff --git a/tools/grit/grit/format/android_xml.py b/tools/grit/grit/format/android_xml.py +new file mode 100644 +index 0000000000..7eb288891f +--- /dev/null ++++ b/tools/grit/grit/format/android_xml.py +@@ -0,0 +1,212 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++"""Produces localized strings.xml files for Android. ++ ++In cases where an "android" type output file is requested in a grd, the classes ++in android_xml will process the messages and translations to produce a valid ++strings.xml that is properly localized with the specified language. ++ ++For example if the following output tag were to be included in a grd file ++ <outputs> ++ ... ++ <output filename="values-es/strings.xml" type="android" lang="es" /> ++ ... ++ </outputs> ++ ++for a grd file with the following messages: ++ ++ <message name="IDS_HELLO" desc="Simple greeting">Hello</message> ++ <message name="IDS_WORLD" desc="The world">world</message> ++ ++and there existed an appropriate xtb file containing the Spanish translations, ++then the output would be: ++ ++ <?xml version="1.0" encoding="utf-8"?> ++ <resources xmlns:android="http://schemas.android.com/apk/res/android"> ++ <string name="hello">"Hola"</string> ++ <string name="world">"mundo"</string> ++ </resources> ++ ++which would be written to values-es/strings.xml and usable by the Android ++resource framework. ++ ++Advanced usage ++-------------- ++ ++To process only certain messages in a grd file, tag each desired message by ++adding "android_java" to formatter_data. Then set the environmental variable ++ANDROID_JAVA_TAGGED_ONLY to "true" when building the grd file. For example: ++ ++ <message name="IDS_HELLO" formatter_data="android_java">Hello</message> ++ ++To generate Android plurals (aka "quantity strings"), use the ICU plural syntax ++in the grd file. This will automatically be transformed into a <purals> element ++in the output xml file. For example: ++ ++ <message name="IDS_CATS"> ++ {NUM_CATS, plural, ++ =1 {1 cat} ++ other {# cats}} ++ </message> ++ ++ will produce ++ ++ <plurals name="cats"> ++ <item quantity="one">1 Katze</item> ++ <item quantity="other">%d Katzen</item> ++ </plurals> ++""" ++ ++from __future__ import print_function ++ ++import os ++import re ++import xml.sax.saxutils ++ ++from grit import lazy_re ++from grit.node import message ++ ++ ++# When this environmental variable has value "true", only tagged messages will ++# be outputted. ++_TAGGED_ONLY_ENV_VAR = 'ANDROID_JAVA_TAGGED_ONLY' ++_TAGGED_ONLY_DEFAULT = False ++ ++# In tagged-only mode, only messages with this tag will be ouputted. ++_EMIT_TAG = 'android_java' ++ ++_NAME_PATTERN = lazy_re.compile(r'IDS_(?P<name>[A-Z0-9_]+)\Z') ++ ++# Most strings are output as a <string> element. Note the double quotes ++# around the value to preserve whitespace. ++_STRING_TEMPLATE = u'<string name="%s">"%s"</string>\n' ++ ++# Some strings are output as a <plurals> element. ++_PLURALS_TEMPLATE = '<plurals name="%s">\n%s</plurals>\n' ++_PLURALS_ITEM_TEMPLATE = ' <item quantity="%s">%s</item>\n' ++ ++# Matches e.g. "{HELLO, plural, HOW ARE YOU DOING}", while capturing ++# "HOW ARE YOU DOING" in <items>. ++_PLURALS_PATTERN = lazy_re.compile(r'\{[A-Z_]+,\s*plural,(?P<items>.*)\}$', ++ flags=re.S) ++ ++# Repeatedly matched against the <items> capture in _PLURALS_PATTERN, ++# to match "<quantity>{<value>}". ++_PLURALS_ITEM_PATTERN = lazy_re.compile(r'(?P<quantity>\S+?)\s*' ++ r'\{(?P<value>.*?)\}') ++_PLURALS_QUANTITY_MAP = { ++ '=0': 'zero', ++ 'zero': 'zero', ++ '=1': 'one', ++ 'one': 'one', ++ '=2': 'two', ++ 'two': 'two', ++ 'few': 'few', ++ 'many': 'many', ++ 'other': 'other', +} + -+bool ChromeClassTester::InImplementationFile(SourceLocation record_location) { -+ std::string filename; -+ if (!GetFilename(record_location, &filename)) -+ return false; + -+ if (ends_with(filename, ".cc") || ends_with(filename, ".cpp") || -+ ends_with(filename, ".mm")) { -+ return true; ++def Format(root, lang='en', output_dir='.'): ++ yield ('<?xml version="1.0" encoding="utf-8"?>\n' ++ '<resources ' ++ 'xmlns:android="http://schemas.android.com/apk/res/android">\n') ++ ++ tagged_only = _TAGGED_ONLY_DEFAULT ++ if _TAGGED_ONLY_ENV_VAR in os.environ: ++ tagged_only = os.environ[_TAGGED_ONLY_ENV_VAR].lower() ++ if tagged_only == 'true': ++ tagged_only = True ++ elif tagged_only == 'false': ++ tagged_only = False ++ else: ++ raise Exception('env variable ANDROID_JAVA_TAGGED_ONLY must have value ' ++ 'true or false. Invalid value: %s' % tagged_only) ++ ++ for item in root.ActiveDescendants(): ++ with item: ++ if ShouldOutputNode(item, tagged_only): ++ yield _FormatMessage(item, lang) ++ ++ yield '</resources>\n' ++ ++ ++def ShouldOutputNode(node, tagged_only): ++ """Returns true if node should be outputted. ++ ++ Args: ++ node: a Node from the grd dom ++ tagged_only: true, if only tagged messages should be outputted ++ """ ++ return (isinstance(node, message.MessageNode) and ++ (not tagged_only or _EMIT_TAG in node.formatter_data)) ++ ++ ++def _FormatPluralMessage(message): ++ """Compiles ICU plural syntax to the body of an Android <plurals> element. ++ ++ 1. In a .grd file, we can write a plural string like this: ++ ++ <message name="IDS_THINGS"> ++ {NUM_THINGS, plural, ++ =1 {1 thing} ++ other {# things}} ++ </message> ++ ++ 2. The Android equivalent looks like this: ++ ++ <plurals name="things"> ++ <item quantity="one">1 thing</item> ++ <item quantity="other">%d things</item> ++ </plurals> ++ ++ This method takes the body of (1) and converts it to the body of (2). ++ ++ If the message is *not* a plural string, this function returns `None`. ++ If the message includes quantities without an equivalent format in Android, ++ it raises an exception. ++ """ ++ ret = {} ++ plural_match = _PLURALS_PATTERN.match(message) ++ if not plural_match: ++ return None ++ body_in = plural_match.group('items').strip() ++ lines = [] ++ quantities_so_far = set() ++ for item_match in _PLURALS_ITEM_PATTERN.finditer(body_in): ++ quantity_in = item_match.group('quantity') ++ quantity_out = _PLURALS_QUANTITY_MAP.get(quantity_in) ++ value_in = item_match.group('value') ++ value_out = '"' + value_in.replace('#', '%d') + '"' ++ if quantity_out: ++ # only one line per quantity out (https://crbug.com/787488) ++ if quantity_out not in quantities_so_far: ++ quantities_so_far.add(quantity_out) ++ lines.append(_PLURALS_ITEM_TEMPLATE % (quantity_out, value_out)) ++ else: ++ raise Exception('Unsupported plural quantity for android ' ++ 'strings.xml: %s' % quantity_in) ++ return ''.join(lines) ++ ++ ++def _FormatMessage(item, lang): ++ """Writes out a single string as a <resource/> element.""" ++ ++ mangled_name = item.GetTextualIds()[0] ++ match = _NAME_PATTERN.match(mangled_name) ++ if not match: ++ raise Exception('Unexpected resource name: %s' % mangled_name) ++ name = match.group('name').lower() ++ ++ value = item.ws_at_start + item.Translate(lang) + item.ws_at_end ++ # Replace < > & with < > & to ensure we generate valid XML and ++ # replace ' " with \' \" to conform to Android's string formatting rules. ++ value = xml.sax.saxutils.escape(value, {"'": "\\'", '"': '\\"'}) ++ ++ plurals = _FormatPluralMessage(value) ++ if plurals: ++ return _PLURALS_TEMPLATE % (name, plurals) ++ else: ++ return _STRING_TEMPLATE % (name, value) +diff --git a/tools/grit/grit/format/android_xml_unittest.py b/tools/grit/grit/format/android_xml_unittest.py +new file mode 100644 +index 0000000000..d9f476fddf +--- /dev/null ++++ b/tools/grit/grit/format/android_xml_unittest.py +@@ -0,0 +1,149 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++"""Unittest for android_xml.py.""" ++ ++from __future__ import print_function ++ ++import os ++import sys ++import unittest ++ ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++from six import StringIO ++ ++from grit import util ++from grit.format import android_xml ++from grit.node import message ++from grit.tool import build ++ ++ ++class AndroidXmlUnittest(unittest.TestCase): ++ ++ def testMessages(self): ++ root = util.ParseGrdForUnittest(r""" ++ <messages> ++ <message name="IDS_SIMPLE" desc="A vanilla string"> ++ Martha ++ </message> ++ <message name="IDS_ONE_LINE" desc="On one line">sat and wondered</message> ++ <message name="IDS_QUOTES" desc="A string with quotation marks"> ++ out loud, "Why don't I build a flying car?" ++ </message> ++ <message name="IDS_MULTILINE" desc="A string split over several lines"> ++ She gathered ++wood, charcoal, and ++a sledge hammer. ++ </message> ++ <message name="IDS_WHITESPACE" desc="A string with extra whitespace."> ++ ''' How old fashioned -- she thought. ''' ++ </message> ++ <message name="IDS_PLACEHOLDERS" desc="A string with placeholders"> ++ I'll buy a <ph name="WAVELENGTH">%d<ex>200</ex></ph> nm laser at <ph name="STORE_NAME">%s<ex>the grocery store</ex></ph>. ++ </message> ++ <message name="IDS_PLURALS" desc="A string using the ICU plural format"> ++ {NUM_THINGS, plural, ++ =1 {Maybe I'll get one laser.} ++ other {Maybe I'll get # lasers.}} ++ </message> ++ <message name="IDS_PLURALS_NO_SPACE" desc="A string using the ICU plural format with no space"> ++ {NUM_MISSISSIPPIS, plural, ++ =1{OneMississippi}other{ManyMississippis}} ++ </message> ++ </messages> ++ """) ++ ++ buf = StringIO() ++ build.RcBuilder.ProcessNode(root, DummyOutput('android', 'en'), buf) ++ output = buf.getvalue() ++ expected = r""" ++<?xml version="1.0" encoding="utf-8"?> ++<resources xmlns:android="http://schemas.android.com/apk/res/android"> ++<string name="simple">"Martha"</string> ++<string name="one_line">"sat and wondered"</string> ++<string name="quotes">"out loud, \"Why don\'t I build a flying car?\""</string> ++<string name="multiline">"She gathered ++wood, charcoal, and ++a sledge hammer."</string> ++<string name="whitespace">" How old fashioned -- she thought. "</string> ++<string name="placeholders">"I\'ll buy a %d nm laser at %s."</string> ++<plurals name="plurals"> ++ <item quantity="one">"Maybe I\'ll get one laser."</item> ++ <item quantity="other">"Maybe I\'ll get %d lasers."</item> ++</plurals> ++<plurals name="plurals_no_space"> ++ <item quantity="one">"OneMississippi"</item> ++ <item quantity="other">"ManyMississippis"</item> ++</plurals> ++</resources> ++""" ++ self.assertEqual(output.strip(), expected.strip()) ++ ++ ++ def testConflictingPlurals(self): ++ root = util.ParseGrdForUnittest(r""" ++ <messages> ++ <message name="IDS_PLURALS" desc="A string using the ICU plural format"> ++ {NUM_THINGS, plural, ++ =1 {Maybe I'll get one laser.} ++ one {Maybe I'll get one laser.} ++ other {Maybe I'll get # lasers.}} ++ </message> ++ </messages> ++ """) ++ ++ buf = StringIO() ++ build.RcBuilder.ProcessNode(root, DummyOutput('android', 'en'), buf) ++ output = buf.getvalue() ++ expected = r""" ++<?xml version="1.0" encoding="utf-8"?> ++<resources xmlns:android="http://schemas.android.com/apk/res/android"> ++<plurals name="plurals"> ++ <item quantity="one">"Maybe I\'ll get one laser."</item> ++ <item quantity="other">"Maybe I\'ll get %d lasers."</item> ++</plurals> ++</resources> ++""" ++ self.assertEqual(output.strip(), expected.strip()) ++ ++ ++ def testTaggedOnly(self): ++ root = util.ParseGrdForUnittest(r""" ++ <messages> ++ <message name="IDS_HELLO" desc="" formatter_data="android_java"> ++ Hello ++ </message> ++ <message name="IDS_WORLD" desc=""> ++ world ++ </message> ++ </messages> ++ """) ++ ++ msg_hello, msg_world = root.GetChildrenOfType(message.MessageNode) ++ self.assertTrue(android_xml.ShouldOutputNode(msg_hello, tagged_only=True)) ++ self.assertFalse(android_xml.ShouldOutputNode(msg_world, tagged_only=True)) ++ self.assertTrue(android_xml.ShouldOutputNode(msg_hello, tagged_only=False)) ++ self.assertTrue(android_xml.ShouldOutputNode(msg_world, tagged_only=False)) ++ ++ ++class DummyOutput(object): ++ ++ def __init__(self, type, language): ++ self.type = type ++ self.language = language ++ ++ def GetType(self): ++ return self.type ++ ++ def GetLanguage(self): ++ return self.language ++ ++ def GetOutputFilename(self): ++ return 'hello.gif' ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/format/c_format.py b/tools/grit/grit/format/c_format.py +new file mode 100644 +index 0000000000..16809a9f70 +--- /dev/null ++++ b/tools/grit/grit/format/c_format.py +@@ -0,0 +1,95 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++"""Formats as a .C file for compilation. ++""" ++ ++from __future__ import print_function ++ ++import codecs ++import os ++import re ++ ++import six ++ ++from grit import util ++ ++ ++def _FormatHeader(root, output_dir): ++ """Returns the required preamble for C files.""" ++ # Find the location of the resource header file, so that we can include ++ # it. ++ resource_header = 'resource.h' # fall back to this ++ for output in root.GetOutputFiles(): ++ if output.attrs['type'] == 'rc_header': ++ resource_header = os.path.abspath(output.GetOutputFilename()) ++ resource_header = util.MakeRelativePath(output_dir, resource_header) ++ return """// This file is automatically generated by GRIT. Do not edit. ++ ++#include "%s" ++ ++// All strings are UTF-8 ++""" % (resource_header) ++# end _FormatHeader() function ++ ++ ++def Format(root, lang='en', output_dir='.'): ++ """Outputs a C switch statement representing the string table.""" ++ from grit.node import message ++ assert isinstance(lang, six.string_types) ++ ++ yield _FormatHeader(root, output_dir) ++ ++ yield 'const char* GetString(int id) {\n switch (id) {' ++ ++ for item in root.ActiveDescendants(): ++ with item: ++ if isinstance(item, message.MessageNode): ++ yield _FormatMessage(item, lang) ++ ++ yield '\n default:\n return 0;\n }\n}\n' ++ ++ ++def _HexToOct(match): ++ "Return the octal form of the hex numbers" ++ hex = match.group("hex") ++ result = "" ++ while len(hex): ++ next_num = int(hex[2:4], 16) ++ result += "\\" + '%03o' % next_num ++ hex = hex[4:] ++ return match.group("escaped_backslashes") + result ++ ++ ++def _FormatMessage(item, lang): ++ """Format a single <message> element.""" ++ ++ message = item.ws_at_start + item.Translate(lang) + item.ws_at_end ++ # Output message with non-ascii chars escaped as octal numbers C's grammar ++ # allows escaped hexadecimal numbers to be infinite, but octal is always of ++ # the form \OOO. Python 3 doesn't support string-escape, so we have to jump ++ # through some hoops here via codecs.escape_encode. ++ # This basically does: ++ # - message - the starting string ++ # - message.encode(...) - convert to bytes ++ # - codecs.escape_encode(...) - convert non-ASCII bytes to \x## escapes ++ # - (...).decode() - convert bytes back to a string ++ message = codecs.escape_encode(message.encode('utf-8'))[0].decode('utf-8') ++ # an escaped char is (\xHH)+ but only if the initial ++ # backslash is not escaped. ++ not_a_backslash = r"(^|[^\\])" # beginning of line or a non-backslash char ++ escaped_backslashes = not_a_backslash + r"(\\\\)*" ++ hex_digits = r"((\\x)[0-9a-f]{2})+" ++ two_digit_hex_num = re.compile( ++ r"(?P<escaped_backslashes>%s)(?P<hex>%s)" ++ % (escaped_backslashes, hex_digits)) ++ message = two_digit_hex_num.sub(_HexToOct, message) ++ # unescape \ (convert \\ back to \) ++ message = message.replace('\\\\', '\\') ++ message = message.replace('"', '\\"') ++ message = util.LINEBREAKS.sub(r'\\n', message) ++ ++ name_attr = item.GetTextualIds()[0] ++ ++ return '\n case %s:\n return "%s";' % (name_attr, message) +diff --git a/tools/grit/grit/format/c_format_unittest.py b/tools/grit/grit/format/c_format_unittest.py +new file mode 100644 +index 0000000000..380120c42f +--- /dev/null ++++ b/tools/grit/grit/format/c_format_unittest.py +@@ -0,0 +1,81 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++"""Unittest for c_format.py. ++""" ++ ++from __future__ import print_function ++ ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++import unittest ++ ++from six import StringIO ++ ++from grit import util ++from grit.tool import build ++ ++ ++class CFormatUnittest(unittest.TestCase): ++ ++ def testMessages(self): ++ root = util.ParseGrdForUnittest(u""" ++ <messages> ++ <message name="IDS_QUESTIONS">Do you want to play questions?</message> ++ <message name="IDS_QUOTES"> ++ "What's in a name, <ph name="NAME">%s<ex>Brandon</ex></ph>?" ++ </message> ++ <message name="IDS_LINE_BREAKS"> ++ Was that rhetoric? ++No. ++Statement. Two all. Game point. ++</message> ++ <message name="IDS_NON_ASCII"> ++ \u00f5\\xc2\\xa4\\\u00a4\\\\xc3\\xb5\u4924 ++ </message> ++ </messages> ++ """) ++ ++ buf = StringIO() ++ build.RcBuilder.ProcessNode(root, DummyOutput('c_format', 'en'), buf) ++ output = util.StripBlankLinesAndComments(buf.getvalue()) ++ self.assertEqual(u"""\ ++#include "resource.h" ++const char* GetString(int id) { ++ switch (id) { ++ case IDS_QUESTIONS: ++ return "Do you want to play questions?"; ++ case IDS_QUOTES: ++ return "\\"What\\'s in a name, %s?\\""; ++ case IDS_LINE_BREAKS: ++ return "Was that rhetoric?\\nNo.\\nStatement. Two all. Game point."; ++ case IDS_NON_ASCII: ++ return "\\303\\265\\xc2\\xa4\\\\302\\244\\\\xc3\\xb5\\344\\244\\244"; ++ default: ++ return 0; + } ++}""", output) + -+ return false; -+} + -+void ChromeClassTester::BuildBannedLists() { -+ banned_namespaces_.push_back("std"); -+ banned_namespaces_.push_back("__gnu_cxx"); -+ banned_namespaces_.push_back("WebKit"); -+ -+ banned_directories_.push_back("third_party/"); -+ banned_directories_.push_back("native_client/"); -+ banned_directories_.push_back("breakpad/"); -+ banned_directories_.push_back("courgette/"); -+ banned_directories_.push_back("pdf/"); -+ banned_directories_.push_back("ppapi/"); -+ banned_directories_.push_back("usr/"); -+ banned_directories_.push_back("testing/"); -+ banned_directories_.push_back("googleurl/"); -+ banned_directories_.push_back("v8/"); -+ banned_directories_.push_back("dart/"); -+ banned_directories_.push_back("sdch/"); -+ banned_directories_.push_back("icu4c/"); -+ banned_directories_.push_back("frameworks/"); -+ -+ // Don't check autogenerated headers. -+ // Make puts them below $(builddir_name)/.../gen and geni. -+ // Ninja puts them below OUTPUT_DIR/.../gen -+ // Xcode has a fixed output directory for everything. -+ banned_directories_.push_back("gen/"); -+ banned_directories_.push_back("geni/"); -+ banned_directories_.push_back("xcodebuild/"); -+ -+ // You are standing in a mazy of twisty dependencies, all resolved by -+ // putting everything in the header. -+ banned_directories_.push_back("automation/"); -+ -+ // Don't check system headers. -+ banned_directories_.push_back("/Developer/"); -+ -+ // Used in really low level threading code that probably shouldn't be out of -+ // lined. -+ ignored_record_names_.insert("ThreadLocalBoolean"); -+ -+ // A complicated pickle derived struct that is all packed integers. -+ ignored_record_names_.insert("Header"); -+ -+ // Part of the GPU system that uses multiple included header -+ // weirdness. Never getting this right. -+ ignored_record_names_.insert("Validators"); -+ -+ // Has a UNIT_TEST only constructor. Isn't *terribly* complex... -+ ignored_record_names_.insert("AutocompleteController"); -+ ignored_record_names_.insert("HistoryURLProvider"); -+ -+ // Because of chrome frame -+ ignored_record_names_.insert("ReliabilityTestSuite"); -+ -+ // Used over in the net unittests. A large enough bundle of integers with 1 -+ // non-pod class member. Probably harmless. -+ ignored_record_names_.insert("MockTransaction"); -+ -+ // Used heavily in ui_unittests and once in views_unittests. Fixing this -+ // isn't worth the overhead of an additional library. -+ ignored_record_names_.insert("TestAnimationDelegate"); -+ -+ // Part of our public interface that nacl and friends use. (Arguably, this -+ // should mean that this is a higher priority but fixing this looks hard.) -+ ignored_record_names_.insert("PluginVersionInfo"); -+} -+ -+std::string ChromeClassTester::GetNamespaceImpl(const DeclContext* context, -+ const std::string& candidate) { -+ switch (context->getDeclKind()) { -+ case Decl::TranslationUnit: { -+ return candidate; -+ } -+ case Decl::Namespace: { -+ const NamespaceDecl* decl = dyn_cast<NamespaceDecl>(context); -+ std::string name_str; -+ llvm::raw_string_ostream OS(name_str); -+ if (decl->isAnonymousNamespace()) -+ OS << "<anonymous namespace>"; -+ else -+ OS << *decl; -+ return GetNamespaceImpl(context->getParent(), -+ OS.str()); -+ } -+ default: { -+ return GetNamespaceImpl(context->getParent(), candidate); ++class DummyOutput(object): ++ ++ def __init__(self, type, language): ++ self.type = type ++ self.language = language ++ ++ def GetType(self): ++ return self.type ++ ++ def GetLanguage(self): ++ return self.language ++ ++ def GetOutputFilename(self): ++ return 'hello.gif' ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/format/chrome_messages_json.py b/tools/grit/grit/format/chrome_messages_json.py +new file mode 100644 +index 0000000000..88ec1d914b +--- /dev/null ++++ b/tools/grit/grit/format/chrome_messages_json.py +@@ -0,0 +1,59 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++"""Formats as a .json file that can be used to localize Google Chrome ++extensions.""" ++ ++from __future__ import print_function ++ ++from json import JSONEncoder ++ ++from grit import constants ++from grit.node import message ++ ++def Format(root, lang='en', output_dir='.'): ++ """Format the messages as JSON.""" ++ yield '{' ++ ++ encoder = JSONEncoder(ensure_ascii=False) ++ format = '"%s":{"message":%s%s}' ++ placeholder_format = '"%i":{"content":"$%i"}' ++ first = True ++ for child in root.ActiveDescendants(): ++ if isinstance(child, message.MessageNode): ++ id = child.attrs['name'] ++ if id.startswith('IDR_') or id.startswith('IDS_'): ++ id = id[4:] ++ ++ translation_missing = child.GetCliques()[0].clique.get(lang) is None; ++ if (child.ShouldFallbackToEnglish() and translation_missing and ++ lang != constants.FAKE_BIDI): ++ # Skip the string if it's not translated. Chrome will fallback ++ # to English automatically. ++ continue ++ ++ loc_message = encoder.encode(child.ws_at_start + child.Translate(lang) + ++ child.ws_at_end) ++ ++ # Replace $n place-holders with $n$ and add an appropriate "placeholders" ++ # entry. Note that chrome.i18n.getMessage only supports 9 placeholders: ++ # https://developer.chrome.com/extensions/i18n#method-getMessage ++ placeholders = '' ++ for i in range(1, 10): ++ if loc_message.find('$%d' % i) == -1: ++ break ++ loc_message = loc_message.replace('$%d' % i, '$%d$' % i) ++ if placeholders: ++ placeholders += ',' ++ placeholders += placeholder_format % (i, i) ++ ++ if not first: ++ yield ',' ++ first = False ++ ++ if placeholders: ++ placeholders = ',"placeholders":{%s}' % placeholders ++ yield format % (id, loc_message, placeholders) ++ ++ yield '}' +diff --git a/tools/grit/grit/format/chrome_messages_json_unittest.py b/tools/grit/grit/format/chrome_messages_json_unittest.py +new file mode 100644 +index 0000000000..a54e6bdc1c +--- /dev/null ++++ b/tools/grit/grit/format/chrome_messages_json_unittest.py +@@ -0,0 +1,190 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++"""Unittest for chrome_messages_json.py. ++""" ++ ++from __future__ import print_function ++ ++import json ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++import unittest ++ ++from six import StringIO ++ ++from grit import grd_reader ++from grit import util ++from grit.tool import build ++ ++class ChromeMessagesJsonFormatUnittest(unittest.TestCase): ++ ++ # The default unittest diff limit is too low for our unittests. ++ # Allow the framework to show the full diff output all the time. ++ maxDiff = None ++ ++ def testMessages(self): ++ root = util.ParseGrdForUnittest(u""" ++ <messages> ++ <message name="IDS_SIMPLE_MESSAGE"> ++ Simple message. ++ </message> ++ <message name="IDS_QUOTES"> ++ element\u2019s \u201c<ph name="NAME">%s<ex>name</ex></ph>\u201d attribute ++ </message> ++ <message name="IDS_PLACEHOLDERS"> ++ <ph name="ERROR_COUNT">%1$d<ex>1</ex></ph> error, <ph name="WARNING_COUNT">%2$d<ex>1</ex></ph> warning ++ </message> ++ <message name="IDS_PLACEHOLDERS_SUBSTITUTED_BY_GETMESSAGE"> ++ <ph name="BEGIN">$1<ex>a</ex></ph>test<ph name="END">$2<ex>b</ex></ph> ++ </message> ++ <message name="IDS_STARTS_WITH_SPACE"> ++ ''' (<ph name="COUNT">%d<ex>2</ex></ph>) ++ </message> ++ <message name="IDS_ENDS_WITH_SPACE"> ++ (<ph name="COUNT">%d<ex>2</ex></ph>) ''' ++ </message> ++ <message name="IDS_SPACE_AT_BOTH_ENDS"> ++ ''' (<ph name="COUNT">%d<ex>2</ex></ph>) ''' ++ </message> ++ <message name="IDS_DOUBLE_QUOTES"> ++ A "double quoted" message. ++ </message> ++ <message name="IDS_BACKSLASH"> ++ \\ ++ </message> ++ </messages> ++ """) ++ ++ buf = StringIO() ++ build.RcBuilder.ProcessNode(root, DummyOutput('chrome_messages_json', 'en'), ++ buf) ++ output = buf.getvalue() ++ test = u""" ++{ ++ "SIMPLE_MESSAGE": { ++ "message": "Simple message." ++ }, ++ "QUOTES": { ++ "message": "element\u2019s \u201c%s\u201d attribute" ++ }, ++ "PLACEHOLDERS": { ++ "message": "%1$d error, %2$d warning" ++ }, ++ "PLACEHOLDERS_SUBSTITUTED_BY_GETMESSAGE": { ++ "message": "$1$test$2$", ++ "placeholders": { ++ "1": { ++ "content": "$1" ++ }, ++ "2": { ++ "content": "$2" ++ } + } ++ }, ++ "STARTS_WITH_SPACE": { ++ "message": " (%d)" ++ }, ++ "ENDS_WITH_SPACE": { ++ "message": "(%d) " ++ }, ++ "SPACE_AT_BOTH_ENDS": { ++ "message": " (%d) " ++ }, ++ "DOUBLE_QUOTES": { ++ "message": "A \\"double quoted\\" message." ++ }, ++ "BACKSLASH": { ++ "message": "\\\\" + } +} -+ -+bool ChromeClassTester::InBannedDirectory(SourceLocation loc) { -+ std::string filename; -+ if (!GetFilename(loc, &filename)) { -+ // If the filename cannot be determined, simply treat this as a banned -+ // location, instead of going through the full lookup process. -+ return true; ++""" ++ self.assertEqual(json.loads(test), json.loads(output)) ++ ++ def testTranslations(self): ++ root = util.ParseGrdForUnittest(""" ++ <messages> ++ <message name="ID_HELLO">Hello!</message> ++ <message name="ID_HELLO_USER">Hello <ph name="USERNAME">%s<ex> ++ Joi</ex></ph></message> ++ </messages> ++ """) ++ ++ buf = StringIO() ++ build.RcBuilder.ProcessNode(root, DummyOutput('chrome_messages_json', 'fr'), ++ buf) ++ output = buf.getvalue() ++ test = u""" ++{ ++ "ID_HELLO": { ++ "message": "H\u00e9P\u00e9ll\u00f4P\u00f4!" ++ }, ++ "ID_HELLO_USER": { ++ "message": "H\u00e9P\u00e9ll\u00f4P\u00f4 %s" + } ++} ++""" ++ self.assertEqual(json.loads(test), json.loads(output)) ++ ++ def testSkipMissingTranslations(self): ++ grd = """<?xml version="1.0" encoding="UTF-8"?> ++<grit latest_public_release="2" current_release="3" source_lang_id="en" ++ base_dir="%s"> ++ <outputs> ++ </outputs> ++ <release seq="3" allow_pseudo="False"> ++ <messages fallback_to_english="true"> ++ <message name="ID_HELLO_NO_TRANSLATION">Hello not translated</message> ++ </messages> ++ </release> ++</grit>""" ++ root = grd_reader.Parse(StringIO(grd), dir=".") ++ ++ buf = StringIO() ++ build.RcBuilder.ProcessNode(root, DummyOutput('chrome_messages_json', 'fr'), ++ buf) ++ output = buf.getvalue() ++ test = u'{}' ++ self.assertEqual(test, output) ++ ++ def testVerifyMinification(self): ++ root = util.ParseGrdForUnittest(u""" ++ <messages> ++ <message name="IDS"> ++ <ph name="BEGIN">$1<ex>a</ex></ph>test<ph name="END">$2<ex>b</ex></ph> ++ </message> ++ </messages> ++ """) ++ ++ buf = StringIO() ++ build.RcBuilder.ProcessNode(root, DummyOutput('chrome_messages_json', 'en'), ++ buf) ++ output = buf.getvalue() ++ test = (u'{"IDS":{"message":"$1$test$2$","placeholders":' ++ u'{"1":{"content":"$1"},"2":{"content":"$2"}}}}') ++ self.assertEqual(test, output) ++ ++ ++class DummyOutput(object): ++ ++ def __init__(self, type, language): ++ self.type = type ++ self.language = language ++ ++ def GetType(self): ++ return self.type ++ ++ def GetLanguage(self): ++ return self.language ++ ++ def GetOutputFilename(self): ++ return 'hello.gif' + -+ // We need to special case scratch space; which is where clang does its -+ // macro expansion. We explicitly want to allow people to do otherwise bad -+ // things through macros that were defined due to third party libraries. -+ if (filename == "<scratch space>") -+ return true; + -+ // Don't complain about autogenerated protobuf files. -+ if (ends_with(filename, ".pb.h")) { -+ return true; -+ } ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/format/data_pack.py b/tools/grit/grit/format/data_pack.py +new file mode 100644 +index 0000000000..f7128a4725 +--- /dev/null ++++ b/tools/grit/grit/format/data_pack.py +@@ -0,0 +1,321 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+ // We need to munge the paths so that they are relative to the repository -+ // srcroot. We first resolve the symlinktastic relative path and then -+ // remove our known srcroot from it if needed. -+ char resolvedPath[MAXPATHLEN]; -+ if (realpath(filename.c_str(), resolvedPath)) { -+ filename = resolvedPath; -+ } ++"""Support for formatting a data pack file used for platform agnostic resource ++files. ++""" ++ ++from __future__ import print_function ++ ++import collections ++import os ++import struct ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) + -+ // On linux, chrome is often checked out to /usr/local/google. Due to the -+ // "usr" rule in banned_directories_, all diagnostics would be suppressed -+ // in that case. As a workaround, strip that prefix. -+ filename = lstrip(filename, "/usr/local/google"); -+ -+ for (std::vector<std::string>::const_iterator it = -+ banned_directories_.begin(); -+ it != banned_directories_.end(); ++it) { -+ // If we can find any of the banned path components in this path, then -+ // this file is rejected. -+ size_t index = filename.find(*it); -+ if (index != std::string::npos) { -+ bool matches_full_dir_name = index == 0 || filename[index - 1] == '/'; -+ if ((*it)[0] == '/') -+ matches_full_dir_name = true; -+ if (matches_full_dir_name) -+ return true; ++import six ++ ++from grit import util ++from grit.node import include ++from grit.node import message ++from grit.node import structure ++ ++ ++PACK_FILE_VERSION = 5 ++BINARY, UTF8, UTF16 = range(3) ++ ++ ++GrdInfoItem = collections.namedtuple('GrdInfoItem', ++ ['textual_id', 'id', 'path']) ++ ++ ++class WrongFileVersion(Exception): ++ pass ++ ++ ++class CorruptDataPack(Exception): ++ pass ++ ++ ++class DataPackSizes(object): ++ def __init__(self, header, id_table, alias_table, data): ++ self.header = header ++ self.id_table = id_table ++ self.alias_table = alias_table ++ self.data = data ++ ++ @property ++ def total(self): ++ return sum(v for v in self.__dict__.values()) ++ ++ def __iter__(self): ++ yield ('header', self.header) ++ yield ('id_table', self.id_table) ++ yield ('alias_table', self.alias_table) ++ yield ('data', self.data) ++ ++ def __eq__(self, other): ++ return self.__dict__ == other.__dict__ ++ ++ def __repr__(self): ++ return self.__class__.__name__ + repr(self.__dict__) ++ ++ ++class DataPackContents(object): ++ def __init__(self, resources, encoding, version, aliases, sizes): ++ # Map of resource_id -> str. ++ self.resources = resources ++ # Encoding (int). ++ self.encoding = encoding ++ # Version (int). ++ self.version = version ++ # Map of resource_id->canonical_resource_id ++ self.aliases = aliases ++ # DataPackSizes instance. ++ self.sizes = sizes ++ ++ ++def Format(root, lang='en', output_dir='.'): ++ """Writes out the data pack file format (platform agnostic resource file).""" ++ id_map = root.GetIdMap() ++ data = {} ++ root.info = [] ++ for node in root.ActiveDescendants(): ++ with node: ++ if isinstance(node, (include.IncludeNode, message.MessageNode, ++ structure.StructureNode)): ++ value = node.GetDataPackValue(lang, util.BINARY) ++ if value is not None: ++ resource_id = id_map[node.GetTextualIds()[0]] ++ data[resource_id] = value ++ root.info.append('{},{},{}'.format( ++ node.attrs.get('name'), resource_id, node.source)) ++ return WriteDataPackToString(data, UTF8) ++ ++ ++def ReadDataPack(input_file): ++ return ReadDataPackFromString(util.ReadFile(input_file, util.BINARY)) ++ ++ ++def ReadDataPackFromString(data): ++ """Reads a data pack file and returns a dictionary.""" ++ # Read the header. ++ version = struct.unpack('<I', data[:4])[0] ++ if version == 4: ++ resource_count, encoding = struct.unpack('<IB', data[4:9]) ++ alias_count = 0 ++ header_size = 9 ++ elif version == 5: ++ encoding, resource_count, alias_count = struct.unpack('<BxxxHH', data[4:12]) ++ header_size = 12 ++ else: ++ raise WrongFileVersion('Found version: ' + str(version)) ++ ++ resources = {} ++ kIndexEntrySize = 2 + 4 # Each entry is a uint16 and a uint32. ++ def entry_at_index(idx): ++ offset = header_size + idx * kIndexEntrySize ++ return struct.unpack('<HI', data[offset:offset + kIndexEntrySize]) ++ ++ prev_resource_id, prev_offset = entry_at_index(0) ++ for i in range(1, resource_count + 1): ++ resource_id, offset = entry_at_index(i) ++ resources[prev_resource_id] = data[prev_offset:offset] ++ prev_resource_id, prev_offset = resource_id, offset ++ ++ id_table_size = (resource_count + 1) * kIndexEntrySize ++ # Read the alias table. ++ kAliasEntrySize = 2 + 2 # uint16, uint16 ++ def alias_at_index(idx): ++ offset = header_size + id_table_size + idx * kAliasEntrySize ++ return struct.unpack('<HH', data[offset:offset + kAliasEntrySize]) ++ ++ aliases = {} ++ for i in range(alias_count): ++ resource_id, index = alias_at_index(i) ++ aliased_id = entry_at_index(index)[0] ++ aliases[resource_id] = aliased_id ++ resources[resource_id] = resources[aliased_id] ++ ++ alias_table_size = kAliasEntrySize * alias_count ++ sizes = DataPackSizes( ++ header_size, id_table_size, alias_table_size, ++ len(data) - header_size - id_table_size - alias_table_size) ++ assert sizes.total == len(data), 'original={} computed={}'.format( ++ len(data), sizes.total) ++ return DataPackContents(resources, encoding, version, aliases, sizes) ++ ++ ++def WriteDataPackToString(resources, encoding): ++ """Returns bytes with a map of id=>data in the data pack format.""" ++ ret = [] ++ ++ # Compute alias map. ++ resource_ids = sorted(resources) ++ # Use reversed() so that for duplicates lower IDs clobber higher ones. ++ id_by_data = {resources[k]: k for k in reversed(resource_ids)} ++ # Map of resource_id -> resource_id, where value < key. ++ alias_map = {k: id_by_data[v] for k, v in resources.items() ++ if id_by_data[v] != k} ++ ++ # Write file header. ++ resource_count = len(resources) - len(alias_map) ++ # Padding bytes added for alignment. ++ ret.append(struct.pack('<IBxxxHH', PACK_FILE_VERSION, encoding, ++ resource_count, len(alias_map))) ++ HEADER_LENGTH = 4 + 4 + 2 + 2 ++ ++ # Each main table entry is: uint16 + uint32 (and an extra entry at the end). ++ # Each alias table entry is: uint16 + uint16. ++ data_offset = HEADER_LENGTH + (resource_count + 1) * 6 + len(alias_map) * 4 ++ ++ # Write main table. ++ index_by_id = {} ++ deduped_data = [] ++ index = 0 ++ for resource_id in resource_ids: ++ if resource_id in alias_map: ++ continue ++ data = resources[resource_id] ++ if isinstance(data, six.text_type): ++ data = data.encode('utf-8') ++ index_by_id[resource_id] = index ++ ret.append(struct.pack('<HI', resource_id, data_offset)) ++ data_offset += len(data) ++ deduped_data.append(data) ++ index += 1 ++ ++ assert index == resource_count ++ # Add an extra entry at the end. ++ ret.append(struct.pack('<HI', 0, data_offset)) ++ ++ # Write alias table. ++ for resource_id in sorted(alias_map): ++ index = index_by_id[alias_map[resource_id]] ++ ret.append(struct.pack('<HH', resource_id, index)) ++ ++ # Write data. ++ ret.extend(deduped_data) ++ return b''.join(ret) ++ ++ ++def WriteDataPack(resources, output_file, encoding): ++ """Writes a map of id=>data into output_file as a data pack.""" ++ content = WriteDataPackToString(resources, encoding) ++ with open(output_file, 'wb') as file: ++ file.write(content) ++ ++ ++def ReadGrdInfo(grd_file): ++ info_dict = {} ++ with open(grd_file + '.info', 'rt') as f: ++ for line in f: ++ item = GrdInfoItem._make(line.strip().split(',')) ++ info_dict[int(item.id)] = item ++ return info_dict ++ ++ ++def RePack(output_file, input_files, whitelist_file=None, ++ suppress_removed_key_output=False, ++ output_info_filepath=None): ++ """Write a new data pack file by combining input pack files. ++ ++ Args: ++ output_file: path to the new data pack file. ++ input_files: a list of paths to the data pack files to combine. ++ whitelist_file: path to the file that contains the list of resource IDs ++ that should be kept in the output file or None to include ++ all resources. ++ suppress_removed_key_output: allows the caller to suppress the output from ++ RePackFromDataPackStrings. ++ output_info_file: If not None, specify the output .info filepath. ++ ++ Raises: ++ KeyError: if there are duplicate keys or resource encoding is ++ inconsistent. ++ """ ++ input_data_packs = [ReadDataPack(filename) for filename in input_files] ++ input_info_files = [filename + '.info' for filename in input_files] ++ whitelist = None ++ if whitelist_file: ++ lines = util.ReadFile(whitelist_file, 'utf-8').strip().splitlines() ++ if not lines: ++ raise Exception('Whitelist file should not be empty') ++ whitelist = set(int(x) for x in lines) ++ inputs = [(p.resources, p.encoding) for p in input_data_packs] ++ resources, encoding = RePackFromDataPackStrings( ++ inputs, whitelist, suppress_removed_key_output) ++ WriteDataPack(resources, output_file, encoding) ++ if output_info_filepath is None: ++ output_info_filepath = output_file + '.info' ++ with open(output_info_filepath, 'w') as output_info_file: ++ for filename in input_info_files: ++ with open(filename, 'r') as info_file: ++ output_info_file.writelines(info_file.readlines()) ++ ++ ++def RePackFromDataPackStrings(inputs, whitelist, ++ suppress_removed_key_output=False): ++ """Combines all inputs into one. ++ ++ Args: ++ inputs: a list of (resources_by_id, encoding) tuples to be combined. ++ whitelist: a list of resource IDs that should be kept in the output string ++ or None to include all resources. ++ suppress_removed_key_output: Do not print removed keys. ++ ++ Returns: ++ Returns (resources_by_id, encoding). ++ ++ Raises: ++ KeyError: if there are duplicate keys or resource encoding is ++ inconsistent. ++ """ ++ resources = {} ++ encoding = None ++ for input_resources, input_encoding in inputs: ++ # Make sure we have no dups. ++ duplicate_keys = set(input_resources.keys()) & set(resources.keys()) ++ if duplicate_keys: ++ raise KeyError('Duplicate keys: ' + str(list(duplicate_keys))) ++ ++ # Make sure encoding is consistent. ++ if encoding in (None, BINARY): ++ encoding = input_encoding ++ elif input_encoding not in (BINARY, encoding): ++ raise KeyError('Inconsistent encodings: ' + str(encoding) + ++ ' vs ' + str(input_encoding)) ++ ++ if whitelist: ++ whitelisted_resources = dict([(key, input_resources[key]) ++ for key in input_resources.keys() ++ if key in whitelist]) ++ resources.update(whitelisted_resources) ++ removed_keys = [key for key in input_resources.keys() ++ if key not in whitelist] ++ if not suppress_removed_key_output: ++ for key in removed_keys: ++ print('RePackFromDataPackStrings Removed Key:', key) ++ else: ++ resources.update(input_resources) ++ ++ # Encoding is 0 for BINARY, 1 for UTF8 and 2 for UTF16 ++ if encoding is None: ++ encoding = BINARY ++ return resources, encoding ++ ++ ++def main(): ++ # Write a simple file. ++ data = {1: '', 4: 'this is id 4', 6: 'this is id 6', 10: ''} ++ WriteDataPack(data, 'datapack1.pak', UTF8) ++ data2 = {1000: 'test', 5: 'five'} ++ WriteDataPack(data2, 'datapack2.pak', UTF8) ++ print('wrote datapack1 and datapack2 to current directory.') ++ ++ ++if __name__ == '__main__': ++ main() +diff --git a/tools/grit/grit/format/data_pack_unittest.py b/tools/grit/grit/format/data_pack_unittest.py +new file mode 100644 +index 0000000000..fcd7035473 +--- /dev/null ++++ b/tools/grit/grit/format/data_pack_unittest.py +@@ -0,0 +1,102 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for grit.format.data_pack''' ++ ++from __future__ import print_function ++ ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++import unittest ++ ++from grit.format import data_pack ++ ++ ++class FormatDataPackUnittest(unittest.TestCase): ++ def testReadDataPackV4(self): ++ expected_data = ( ++ b'\x04\x00\x00\x00' # header(version ++ b'\x04\x00\x00\x00' # no. entries, ++ b'\x01' # encoding) ++ b'\x01\x00\x27\x00\x00\x00' # index entry 1 ++ b'\x04\x00\x27\x00\x00\x00' # index entry 4 ++ b'\x06\x00\x33\x00\x00\x00' # index entry 6 ++ b'\x0a\x00\x3f\x00\x00\x00' # index entry 10 ++ b'\x00\x00\x3f\x00\x00\x00' # extra entry for the size of last ++ b'this is id 4this is id 6') # data ++ expected_data_pack = data_pack.DataPackContents( ++ { ++ 1: b'', ++ 4: b'this is id 4', ++ 6: b'this is id 6', ++ 10: b'', ++ }, data_pack.UTF8, 4, {}, data_pack.DataPackSizes(9, 30, 0, 24)) ++ loaded = data_pack.ReadDataPackFromString(expected_data) ++ self.assertDictEqual(expected_data_pack.__dict__, loaded.__dict__) ++ ++ def testReadWriteDataPackV5(self): ++ expected_data = ( ++ b'\x05\x00\x00\x00' # version ++ b'\x01\x00\x00\x00' # encoding & padding ++ b'\x03\x00' # resource_count ++ b'\x01\x00' # alias_count ++ b'\x01\x00\x28\x00\x00\x00' # index entry 1 ++ b'\x04\x00\x28\x00\x00\x00' # index entry 4 ++ b'\x06\x00\x34\x00\x00\x00' # index entry 6 ++ b'\x00\x00\x40\x00\x00\x00' # extra entry for the size of last ++ b'\x0a\x00\x01\x00' # alias table ++ b'this is id 4this is id 6') # data ++ input_resources = { ++ 1: b'', ++ 4: b'this is id 4', ++ 6: b'this is id 6', ++ 10: b'this is id 4', + } -+ } ++ data = data_pack.WriteDataPackToString(input_resources, data_pack.UTF8) ++ self.assertEquals(data, expected_data) ++ ++ expected_data_pack = data_pack.DataPackContents({ ++ 1: b'', ++ 4: input_resources[4], ++ 6: input_resources[6], ++ 10: input_resources[4], ++ }, data_pack.UTF8, 5, {10: 4}, data_pack.DataPackSizes(12, 24, 4, 24)) ++ loaded = data_pack.ReadDataPackFromString(expected_data) ++ self.assertDictEqual(expected_data_pack.__dict__, loaded.__dict__) ++ ++ def testRePackUnittest(self): ++ expected_with_whitelist = { ++ 1: 'Never gonna', 10: 'give you up', 20: 'Never gonna let', ++ 30: 'you down', 40: 'Never', 50: 'gonna run around and', ++ 60: 'desert you'} ++ expected_without_whitelist = { ++ 1: 'Never gonna', 10: 'give you up', 20: 'Never gonna let', 65: 'Close', ++ 30: 'you down', 40: 'Never', 50: 'gonna run around and', 4: 'click', ++ 60: 'desert you', 6: 'chirr', 32: 'oops, try again', 70: 'Awww, snap!'} ++ inputs = [{1: 'Never gonna', 4: 'click', 6: 'chirr', 10: 'give you up'}, ++ {20: 'Never gonna let', 30: 'you down', 32: 'oops, try again'}, ++ {40: 'Never', 50: 'gonna run around and', 60: 'desert you'}, ++ {65: 'Close', 70: 'Awww, snap!'}] ++ whitelist = [1, 10, 20, 30, 40, 50, 60] ++ inputs = [(i, data_pack.UTF8) for i in inputs] ++ ++ # RePack using whitelist ++ output, _ = data_pack.RePackFromDataPackStrings( ++ inputs, whitelist, suppress_removed_key_output=True) ++ self.assertDictEqual(expected_with_whitelist, output, ++ 'Incorrect resource output') ++ ++ # RePack a None whitelist ++ output, _ = data_pack.RePackFromDataPackStrings( ++ inputs, None, suppress_removed_key_output=True) ++ self.assertDictEqual(expected_without_whitelist, output, ++ 'Incorrect resource output') + -+ return false; -+} + -+bool ChromeClassTester::IsIgnoredType(const std::string& base_name) { -+ return ignored_record_names_.find(base_name) != ignored_record_names_.end(); -+} ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/format/gen_predetermined_ids.py b/tools/grit/grit/format/gen_predetermined_ids.py +new file mode 100644 +index 0000000000..9b2aa7b1a5 +--- /dev/null ++++ b/tools/grit/grit/format/gen_predetermined_ids.py +@@ -0,0 +1,144 @@ ++#!/usr/bin/env python ++# Copyright 2017 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+bool ChromeClassTester::GetFilename(SourceLocation loc, -+ std::string* filename) { -+ const SourceManager& source_manager = instance_.getSourceManager(); -+ SourceLocation spelling_location = source_manager.getSpellingLoc(loc); -+ PresumedLoc ploc = source_manager.getPresumedLoc(spelling_location); -+ if (ploc.isInvalid()) { -+ // If we're in an invalid location, we're looking at things that aren't -+ // actually stated in the source. -+ return false; -+ } ++""" ++A tool to generate a predetermined resource ids file that can be used as an ++input to grit via the -p option. This is meant to be run manually every once in ++a while and its output checked in. See tools/gritsettings/README.md for details. ++""" + -+ *filename = ploc.getFilename(); -+ return true; -+} -diff --git a/tools/clang/plugins/ChromeClassTester.h b/tools/clang/plugins/ChromeClassTester.h ++from __future__ import print_function ++ ++import os ++import re ++import sys ++ ++# Regular expression for parsing the #define macro format. Matches both the ++# version of the macro with whitelist support and the one without. For example, ++# Without generate whitelist flag: ++# #define IDS_FOO_MESSAGE 1234 ++# With generate whitelist flag: ++# #define IDS_FOO_MESSAGE (::ui::WhitelistedResource<1234>(), 1234) ++RESOURCE_EXTRACT_REGEX = re.compile(r'^#define (\S*).* (\d+)\)?$', re.MULTILINE) ++ ++ORDERED_RESOURCE_IDS_REGEX = re.compile(r'^Resource=(\d*)$', re.MULTILINE) ++ ++ ++def _GetResourceNameIdPairsIter(string_to_scan): ++ """Gets an iterator of the resource name and id pairs of the given string. ++ ++ Scans the input string for lines of the form "#define NAME ID" and returns ++ an iterator over all matching (NAME, ID) pairs. ++ ++ Args: ++ string_to_scan: The input string to scan. ++ ++ Yields: ++ A tuple of name and id. ++ """ ++ for match in RESOURCE_EXTRACT_REGEX.finditer(string_to_scan): ++ yield match.group(1, 2) ++ ++ ++def _ReadOrderedResourceIds(path): ++ """Reads ordered resource ids from the given file. ++ ++ The resources are expected to be of the format produced by running Chrome ++ with --print-resource-ids command line. ++ ++ Args: ++ path: File path to read resource ids from. ++ ++ Returns: ++ An array of ordered resource ids. ++ """ ++ ordered_resource_ids = [] ++ with open(path, "r") as f: ++ for match in ORDERED_RESOURCE_IDS_REGEX.finditer(f.read()): ++ ordered_resource_ids.append(int(match.group(1))) ++ return ordered_resource_ids ++ ++ ++def GenerateResourceMapping(original_resources, ordered_resource_ids): ++ """Generates a resource mapping from the ordered ids and the original mapping. ++ ++ The returned dict will assign new ids to ordered_resource_ids numerically ++ increasing from 101. ++ ++ Args: ++ original_resources: A dict of original resource ids to resource names. ++ ordered_resource_ids: An array of ordered resource ids. ++ ++ Returns: ++ A dict of resource ids to resource names. ++ """ ++ output_resource_map = {} ++ # 101 is used as the starting value since other parts of GRIT require it to be ++ # the minimum (e.g. rc_header.py) based on Windows resource numbering. ++ next_id = 101 ++ for original_id in ordered_resource_ids: ++ resource_name = original_resources[original_id] ++ output_resource_map[next_id] = resource_name ++ next_id += 1 ++ return output_resource_map ++ ++ ++def ReadResourceIdsFromFile(file, original_resources): ++ """Reads resource ids from a GRIT-produced header file. ++ ++ Args: ++ file: File to a GRIT-produced header file to read from. ++ original_resources: Dict of resource ids to resource names to add to. ++ """ ++ for resource_name, resource_id in _GetResourceNameIdPairsIter(file.read()): ++ original_resources[int(resource_id)] = resource_name ++ ++ ++def _ReadOriginalResourceIds(out_dir): ++ """Reads resource ids from GRIT header files in the specified directory. ++ ++ Args: ++ out_dir: A Chrome build output directory (e.g. out/gn) to scan. ++ ++ Returns: ++ A dict of resource ids to resource names. ++ """ ++ original_resources = {} ++ for root, dirnames, filenames in os.walk(out_dir + '/gen'): ++ for filename in filenames: ++ if filename.endswith(('_resources.h', '_settings.h', '_strings.h')): ++ with open(os.path.join(root, filename), "r") as f: ++ ReadResourceIdsFromFile(f, original_resources) ++ return original_resources ++ ++ ++def _GeneratePredeterminedIdsFile(ordered_resources_file, out_dir): ++ """Generates a predetermined ids file. ++ ++ Args: ++ ordered_resources_file: File path to read ordered resource ids from. ++ out_dir: A Chrome build output directory (e.g. out/gn) to scan. ++ ++ Returns: ++ A dict of resource ids to resource names. ++ """ ++ original_resources = _ReadOriginalResourceIds(out_dir) ++ ordered_resource_ids = _ReadOrderedResourceIds(ordered_resources_file) ++ output_resource_map = GenerateResourceMapping(original_resources, ++ ordered_resource_ids) ++ for res_id in sorted(output_resource_map.keys()): ++ print(output_resource_map[res_id], res_id) ++ ++ ++def main(argv): ++ if len(argv) != 2: ++ print("usage: gen_predetermined_ids.py <ordered_resources_file> <out_dir>") ++ sys.exit(1) ++ ordered_resources_file, out_dir = argv[0], argv[1] ++ _GeneratePredeterminedIdsFile(ordered_resources_file, out_dir) ++ ++ ++if '__main__' == __name__: ++ main(sys.argv[1:]) +diff --git a/tools/grit/grit/format/gen_predetermined_ids_unittest.py b/tools/grit/grit/format/gen_predetermined_ids_unittest.py +new file mode 100644 +index 0000000000..bd0331adb4 +--- /dev/null ++++ b/tools/grit/grit/format/gen_predetermined_ids_unittest.py +@@ -0,0 +1,46 @@ ++#!/usr/bin/env python ++# Copyright 2017 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for the gen_predetermined_ids module.''' ++ ++from __future__ import print_function ++ ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++import unittest ++ ++from six import StringIO ++ ++from grit.format import gen_predetermined_ids ++ ++class GenPredeterminedIdsUnittest(unittest.TestCase): ++ def testGenerateResourceMapping(self): ++ original_resources = {200: 'A', 201: 'B', 300: 'C', 350: 'D', 370: 'E'} ++ ordered_resource_ids = [300, 201, 370] ++ mapping = gen_predetermined_ids.GenerateResourceMapping( ++ original_resources, ordered_resource_ids) ++ self.assertEqual({101: 'C', 102: 'B', 103: 'E'}, mapping) ++ ++ def testReadResourceIdsFromFile(self): ++ f = StringIO(''' ++// This file is automatically generated by GRIT. Do not edit. ++ ++#pragma once ++ ++#define IDS_BOOKMARKS_NO_ITEMS 12500 ++#define IDS_BOOKMARK_BAR_IMPORT_LINK (::ui::WhitelistedResource<12501>(), 12501) ++#define IDS_BOOKMARK_X (::ui::WhitelistedResource<12502>(), 12502) ++''') ++ resources = {} ++ gen_predetermined_ids.ReadResourceIdsFromFile(f, resources) ++ self.assertEqual({12500: 'IDS_BOOKMARKS_OPEN_ALL', ++ 12501: 'IDS_BOOKMARKS_OPEN_ALL_INCOGNITO', ++ 12502: 'IDS_BOOKMARK_X'}, resources) ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/format/gzip_string.py b/tools/grit/grit/format/gzip_string.py new file mode 100644 -index 0000000000..588ae9cae5 +index 0000000000..3cd17185c9 --- /dev/null -+++ b/tools/clang/plugins/ChromeClassTester.h -@@ -0,0 +1,84 @@ -+// Copyright (c) 2012 The Chromium Authors. All rights reserved. -+// Use of this source code is governed by a BSD-style license that can be -+// found in the LICENSE file. ++++ b/tools/grit/grit/format/gzip_string.py +@@ -0,0 +1,46 @@ ++# Copyright (c) 2016 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++"""Provides gzip utilities for strings. ++""" + -+#ifndef TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_ -+#define TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_ ++from __future__ import print_function + -+#include <set> -+#include <vector> ++import gzip ++import io ++import subprocess + -+#include "clang/AST/ASTConsumer.h" -+#include "clang/AST/TypeLoc.h" -+#include "clang/Frontend/CompilerInstance.h" + -+// A class on top of ASTConsumer that forwards classes defined in Chromium -+// headers to subclasses which implement CheckChromeClass(). -+class ChromeClassTester : public clang::ASTConsumer { -+ public: -+ explicit ChromeClassTester(clang::CompilerInstance& instance); -+ virtual ~ChromeClassTester(); ++def GzipStringRsyncable(data): ++ # Make call to host system's gzip to get access to --rsyncable option. This ++ # option makes updates much smaller - if one line is changed in the resource, ++ # it won't have to push the entire compressed resource with the update. ++ # Instead, --rsyncable breaks the file into small chunks, so that one doesn't ++ # affect the other in compression, and then only that chunk will have to be ++ # updated. ++ gzip_proc = subprocess.Popen(['gzip', '--stdout', '--rsyncable', ++ '--best', '--no-name'], ++ stdin=subprocess.PIPE, ++ stdout=subprocess.PIPE, ++ stderr=subprocess.PIPE) ++ data, stderr = gzip_proc.communicate(data) ++ if gzip_proc.returncode != 0: ++ raise subprocess.CalledProcessError(gzip_proc.returncode, 'gzip', ++ stderr) ++ return data ++ ++ ++def GzipString(data): ++ # Gzipping using Python's built in gzip: Windows doesn't ship with gzip, and ++ # OSX's gzip does not have an --rsyncable option built in. Although this is ++ # not preferable to --rsyncable, it is an option for the systems that do ++ # not have --rsyncable. If used over GzipStringRsyncable, the primary ++ # difference of this function's compression will be larger updates every time ++ # a compressed resource is changed. ++ gzip_output = io.BytesIO() ++ with gzip.GzipFile(mode='wb', compresslevel=9, fileobj=gzip_output, ++ mtime=0) as gzip_file: ++ gzip_file.write(data) ++ data = gzip_output.getvalue() ++ gzip_output.close() ++ return data +diff --git a/tools/grit/grit/format/gzip_string_unittest.py b/tools/grit/grit/format/gzip_string_unittest.py +new file mode 100644 +index 0000000000..c0cfbe1837 +--- /dev/null ++++ b/tools/grit/grit/format/gzip_string_unittest.py +@@ -0,0 +1,65 @@ ++#!/usr/bin/env python ++# Copyright (c) 2016 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+ // clang::ASTConsumer: -+ virtual void HandleTagDeclDefinition(clang::TagDecl* tag); -+ virtual bool HandleTopLevelDecl(clang::DeclGroupRef group_ref); ++'''Unit tests for grit.format.gzip_string''' + -+ protected: -+ clang::CompilerInstance& instance() { return instance_; } -+ clang::DiagnosticsEngine& diagnostic() { return diagnostic_; } ++from __future__ import print_function + -+ // Emits a simple warning; this shouldn't be used if you require printf-style -+ // printing. -+ void emitWarning(clang::SourceLocation loc, const char* error); ++import gzip ++import io ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) + -+ // Utility method for subclasses to check if this class is in a banned -+ // namespace. -+ bool InBannedNamespace(const clang::Decl* record); ++import unittest + -+ // Utility method for subclasses to determine the namespace of the -+ // specified record, if any. Unnamed namespaces will be identified as -+ // "<anonymous namespace>". -+ std::string GetNamespace(const clang::Decl* record); ++from grit.format import gzip_string + -+ // Utility method for subclasses to check if this class is within an -+ // implementation (.cc, .cpp, .mm) file. -+ bool InImplementationFile(clang::SourceLocation location); + -+ private: -+ void BuildBannedLists(); ++class FormatGzipStringUnittest(unittest.TestCase): + -+ void CheckTag(clang::TagDecl*); ++ def testGzipStringRsyncable(self): ++ # Can only test the rsyncable version on platforms which support rsyncable, ++ # which at the moment is Linux. ++ if sys.platform == 'linux2': ++ header_begin = (b'\x1f\x8b') # gzip first two bytes ++ input = (b'TEST STRING STARTING NOW' ++ b'continuing' ++ b'<even more>' ++ b'<finished NOW>') + -+ // Filtered versions of tags that are only called with things defined in -+ // chrome header files. -+ virtual void CheckChromeClass(clang::SourceLocation record_location, -+ clang::CXXRecordDecl* record) = 0; ++ compressed = gzip_string.GzipStringRsyncable(input) ++ self.failUnless(header_begin == compressed[:2]) + -+ // Utility methods used for filtering out non-chrome classes (and ones we -+ // deliberately ignore) in HandleTagDeclDefinition(). -+ std::string GetNamespaceImpl(const clang::DeclContext* context, -+ const std::string& candidate); -+ bool InBannedDirectory(clang::SourceLocation loc); -+ bool IsIgnoredType(const std::string& base_name); ++ compressed_file = io.BytesIO() ++ compressed_file.write(compressed) ++ compressed_file.seek(0) + -+ // Attempts to determine the filename for the given SourceLocation. -+ // Returns false if the filename could not be determined. -+ bool GetFilename(clang::SourceLocation loc, std::string* filename); ++ with gzip.GzipFile(mode='rb', fileobj=compressed_file) as f: ++ output = f.read() ++ self.failUnless(output == input) + -+ clang::CompilerInstance& instance_; -+ clang::DiagnosticsEngine& diagnostic_; ++ def testGzipString(self): ++ header_begin = b'\x1f\x8b' # gzip first two bytes ++ input = (b'TEST STRING STARTING NOW' ++ b'continuing' ++ b'<even more>' ++ b'<finished NOW>') + -+ // List of banned namespaces. -+ std::vector<std::string> banned_namespaces_; ++ compressed = gzip_string.GzipString(input) ++ self.failUnless(header_begin == compressed[:2]) + -+ // List of banned directories. -+ std::vector<std::string> banned_directories_; ++ compressed_file = io.BytesIO() ++ compressed_file.write(compressed) ++ compressed_file.seek(0) + -+ // List of types that we don't check. -+ std::set<std::string> ignored_record_names_; ++ with gzip.GzipFile(mode='rb', fileobj=compressed_file) as f: ++ output = f.read() ++ self.failUnless(output == input) + -+ // List of decls to check once the current top-level decl is parsed. -+ std::vector<clang::TagDecl*> pending_class_decls_; -+}; + -+#endif // TOOLS_CLANG_PLUGINS_CHROMECLASSTESTER_H_ -diff --git a/tools/clang/plugins/FindBadConstructs.cpp b/tools/clang/plugins/FindBadConstructs.cpp ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/format/html_inline.py b/tools/grit/grit/format/html_inline.py new file mode 100644 -index 0000000000..b79a64dbd1 +index 0000000000..da55216ea4 --- /dev/null -+++ b/tools/clang/plugins/FindBadConstructs.cpp -@@ -0,0 +1,435 @@ -+// Copyright (c) 2012 The Chromium Authors. All rights reserved. -+// Use of this source code is governed by a BSD-style license that can be -+// found in the LICENSE file. ++++ b/tools/grit/grit/format/html_inline.py +@@ -0,0 +1,602 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+// This file defines a bunch of recurring problems in the Chromium C++ code. -+// -+// Checks that are implemented: -+// - Constructors/Destructors should not be inlined if they are of a complex -+// class type. -+// - Missing "virtual" keywords on methods that should be virtual. -+// - Non-annotated overriding virtual methods. -+// - Virtual methods with nonempty implementations in their headers. -+// - Classes that derive from base::RefCounted / base::RefCountedThreadSafe -+// should have protected or private destructors. ++"""Flattens a HTML file by inlining its external resources. + -+#include "clang/Frontend/FrontendPluginRegistry.h" -+#include "clang/AST/ASTConsumer.h" -+#include "clang/AST/AST.h" -+#include "clang/AST/CXXInheritance.h" -+#include "clang/AST/TypeLoc.h" -+#include "clang/Basic/SourceManager.h" -+#include "clang/Frontend/CompilerInstance.h" -+#include "llvm/Support/raw_ostream.h" ++This is a small script that takes a HTML file, looks for src attributes ++and inlines the specified file, producing one HTML file with no external ++dependencies. It recursively inlines the included files. ++""" + -+#include "ChromeClassTester.h" ++from __future__ import print_function + -+using namespace clang; ++import os ++import re ++import sys ++import base64 ++import mimetypes ++ ++from grit import lazy_re ++from grit import util ++from grit.format import minifier ++ ++# There is a python bug that makes mimetypes crash if the Windows ++# registry contains non-Latin keys ( http://bugs.python.org/issue9291 ++# ). Initing manually and blocking external mime-type databases will ++# prevent that bug and if we add svg manually, it will still give us ++# the data we need. ++mimetypes.init([]) ++mimetypes.add_type('image/svg+xml', '.svg') ++ ++# webm video type is not always available if mimetype package is outdated. ++mimetypes.add_type('video/webm', '.webm') ++ ++DIST_DEFAULT = 'chromium' ++DIST_ENV_VAR = 'CHROMIUM_BUILD' ++DIST_SUBSTR = '%DISTRIBUTION%' ++ ++# Matches beginning of an "if" block. ++_BEGIN_IF_BLOCK = lazy_re.compile( ++ r'<if [^>]*?expr=("(?P<expr1>[^">]*)"|\'(?P<expr2>[^\'>]*)\')[^>]*?>') ++ ++# Matches ending of an "if" block. ++_END_IF_BLOCK = lazy_re.compile(r'</if>') ++ ++# Used by DoInline to replace various links with inline content. ++_STYLESHEET_RE = lazy_re.compile( ++ r'<link rel="stylesheet"[^>]+?href="(?P<filename>[^"]*)".*?>(\s*</link>)?', ++ re.DOTALL) ++_INCLUDE_RE = lazy_re.compile( ++ r'(?P<comment>\/\/ )?<include[^>]+?' ++ r'src=("(?P<file1>[^">]*)"|\'(?P<file2>[^\'>]*)\').*?>(\s*</include>)?', ++ re.DOTALL) ++_SRC_RE = lazy_re.compile( ++ r'<(?!script)(?:[^>]+?\s)src="(?!\[\[|{{)(?P<filename>[^"\']*)"', ++ re.MULTILINE) ++# This re matches '<img srcset="..."' or '<source srcset="..."' ++_SRCSET_RE = lazy_re.compile( ++ r'<(img|source)\b(?:[^>]*?\s)srcset="(?!\[\[|{{|\$i18n{)' ++ r'(?P<srcset>[^"\']*)"', ++ re.MULTILINE) ++# This re is for splitting srcset value string into "image candidate strings". ++# Notes: ++# - HTML 5.2 states that URL cannot start or end with comma. ++# - the "descriptor" is either "width descriptor" or "pixel density descriptor". ++# The first one consists of "valid non-negative integer + letter 'x'", ++# the second one is formed of "positive valid floating-point number + ++# letter 'w'". As a reasonable compromise, we match a list of characters ++# that form both of them. ++# Matches for example "img2.png 2x" or "img9.png 11E-2w". ++_SRCSET_ENTRY_RE = lazy_re.compile( ++ r'\s*(?P<url>[^,\s]\S+[^,\s])' ++ r'(?:\s+(?P<descriptor>[\deE.-]+[wx]))?\s*' ++ r'(?P<separator>,|$)', ++ re.MULTILINE) ++_ICON_RE = lazy_re.compile( ++ r'<link rel="icon"\s(?:[^>]+?\s)?' ++ r'href=(?P<quote>")(?P<filename>[^"\']*)\1', ++ re.MULTILINE) ++ ++ ++def GetDistribution(): ++ """Helper function that gets the distribution we are building. ++ ++ Returns: ++ string ++ """ ++ distribution = DIST_DEFAULT ++ if DIST_ENV_VAR in os.environ: ++ distribution = os.environ[DIST_ENV_VAR] ++ if len(distribution) > 1 and distribution[0] == '_': ++ distribution = distribution[1:].lower() ++ return distribution ++ ++def ConvertFileToDataURL(filename, base_path, distribution, inlined_files, ++ names_only): ++ """Convert filename to inlined data URI. ++ ++ Takes a filename from ether "src" or "srcset", and attempts to read the file ++ at 'filename'. Returns data URI as string with given file inlined. ++ If it finds DIST_SUBSTR string in file name, replaces it with distribution. ++ If filename contains ':', it is considered URL and not translated. ++ ++ Args: ++ filename: filename string from ether src or srcset attributes. ++ base_path: path that to look for files in ++ distribution: string that should replace DIST_SUBSTR ++ inlined_files: The name of the opened file is appended to this list. ++ names_only: If true, the function will not read the file but just return "". ++ It will still add the filename to |inlined_files|. ++ ++ Returns: ++ string ++ """ ++ if filename.find(':') != -1: ++ # filename is probably a URL, which we don't want to bother inlining ++ return filename ++ ++ filename = filename.replace(DIST_SUBSTR , distribution) ++ filepath = os.path.normpath(os.path.join(base_path, filename)) ++ inlined_files.add(filepath) ++ ++ if names_only: ++ return "" ++ ++ mimetype = mimetypes.guess_type(filename)[0] ++ if mimetype is None: ++ raise Exception('%s is of an an unknown type and ' ++ 'cannot be stored in a data url.' % filename) ++ inline_data = base64.standard_b64encode(util.ReadFile(filepath, util.BINARY)) ++ return 'data:%s;base64,%s' % (mimetype, inline_data.decode('utf-8')) ++ ++ ++def SrcInlineAsDataURL( ++ src_match, base_path, distribution, inlined_files, names_only=False, ++ filename_expansion_function=None): ++ """regex replace function. ++ ++ Takes a regex match for src="filename", attempts to read the file ++ at 'filename' and returns the src attribute with the file inlined ++ as a data URI. If it finds DIST_SUBSTR string in file name, replaces ++ it with distribution. ++ ++ Args: ++ src_match: regex match object with 'filename' named capturing group ++ base_path: path that to look for files in ++ distribution: string that should replace DIST_SUBSTR ++ inlined_files: The name of the opened file is appended to this list. ++ names_only: If true, the function will not read the file but just return "". ++ It will still add the filename to |inlined_files|. ++ ++ Returns: ++ string ++ """ ++ filename = src_match.group('filename') ++ if filename_expansion_function: ++ filename = filename_expansion_function(filename) ++ ++ data_url = ConvertFileToDataURL(filename, base_path, distribution, ++ inlined_files, names_only) ++ ++ if not data_url: ++ return data_url ++ ++ prefix = src_match.string[src_match.start():src_match.start('filename')] ++ suffix = src_match.string[src_match.end('filename'):src_match.end()] ++ return prefix + data_url + suffix ++ ++def SrcsetInlineAsDataURL( ++ srcset_match, base_path, distribution, inlined_files, names_only=False, ++ filename_expansion_function=None): ++ """regex replace function to inline files in srcset="..." attributes ++ ++ Takes a regex match for srcset="filename 1x, filename 2x, ...", attempts to ++ read the files referenced by filenames and returns the srcset attribute with ++ the files inlined as a data URI. If it finds DIST_SUBSTR string in file name, ++ replaces it with distribution. ++ ++ Args: ++ srcset_match: regex match object with 'srcset' named capturing group ++ base_path: path that to look for files in ++ distribution: string that should replace DIST_SUBSTR ++ inlined_files: The name of the opened file is appended to this list. ++ names_only: If true, the function will not read the file but just return "". ++ It will still add the filename to |inlined_files|. ++ ++ Returns: ++ string ++ """ ++ srcset = srcset_match.group('srcset') ++ ++ if not srcset: ++ return srcset_match.group(0) ++ ++ # HTML 5.2 defines srcset as a list of "image candidate strings". ++ # Each of them consists of URL and descriptor. ++ # _SRCSET_ENTRY_RE splits srcset into a list of URLs, descriptors and ++ # commas. ++ # The descriptor part will be None if that optional regex didn't match ++ parts = _SRCSET_ENTRY_RE.split(srcset) ++ ++ if not parts: ++ return srcset_match.group(0) ++ ++ # List of image candidate strings that will form new srcset="..." ++ new_candidates = [] ++ ++ # When iterating over split srcset we fill this parts of a single image ++ # candidate string: [url, descriptor] ++ candidate = []; ++ ++ # Each entry should consist of some text before the entry, the url, ++ # the descriptor or None if the entry has no descriptor, a comma separator or ++ # the end of the line, and finally some text after the entry (which is the ++ # same as the text before the next entry). ++ for i in range(0, len(parts) - 1, 4): ++ before, url, descriptor, separator, after = parts[i:i+5] ++ ++ # There must be a comma-separated next entry or this must be the last entry. ++ assert separator == "," or (separator == "" and i == len(parts) - 5), ( ++ "Bad srcset format in {}".format(srcset_match.group(0))) ++ # Both before and after the entry must be empty ++ assert before == after == "", ( ++ "Bad srcset format in {}".format(srcset_match.group(0))) ++ ++ if filename_expansion_function: ++ filename = filename_expansion_function(url) ++ else: ++ filename = url ++ ++ data_url = ConvertFileToDataURL(filename, base_path, distribution, ++ inlined_files, names_only) ++ ++ # This is not "names_only" mode ++ if data_url: ++ candidate = [data_url] ++ if descriptor: ++ candidate.append(descriptor) ++ ++ new_candidates.append(" ".join(candidate)) ++ ++ prefix = srcset_match.string[srcset_match.start(): ++ srcset_match.start('srcset')] ++ suffix = srcset_match.string[srcset_match.end('srcset'):srcset_match.end()] ++ return prefix + ','.join(new_candidates) + suffix ++ ++class InlinedData: ++ """Helper class holding the results from DoInline(). ++ ++ Holds the inlined data and the set of filenames of all the inlined ++ files. ++ """ ++ def __init__(self, inlined_data, inlined_files): ++ self.inlined_data = inlined_data ++ self.inlined_files = inlined_files ++ ++def DoInline( ++ input_filename, grd_node, allow_external_script=False, ++ preprocess_only=False, names_only=False, strip_whitespace=False, ++ rewrite_function=None, filename_expansion_function=None): ++ """Helper function that inlines the resources in a specified file. ++ ++ Reads input_filename, finds all the src attributes and attempts to ++ inline the files they are referring to, then returns the result and ++ the set of inlined files. ++ ++ Args: ++ input_filename: name of file to read in ++ grd_node: html node from the grd file for this include tag ++ preprocess_only: Skip all HTML processing, only handle <if> and <include>. ++ names_only: |nil| will be returned for the inlined contents (faster). ++ strip_whitespace: remove whitespace and comments in the input files. ++ rewrite_function: function(filepath, text, distribution) which will be ++ called to rewrite html content before inlining images. ++ filename_expansion_function: function(filename) which will be called to ++ rewrite filenames before attempting to read them. ++ Returns: ++ a tuple of the inlined data as a string and the set of filenames ++ of all the inlined files ++ """ ++ if filename_expansion_function: ++ input_filename = filename_expansion_function(input_filename) ++ input_filepath = os.path.dirname(input_filename) ++ distribution = GetDistribution() ++ ++ # Keep track of all the files we inline. ++ inlined_files = set() ++ ++ def SrcReplace(src_match, filepath=input_filepath, ++ inlined_files=inlined_files): ++ """Helper function to provide SrcInlineAsDataURL with the base file path""" ++ return SrcInlineAsDataURL( ++ src_match, filepath, distribution, inlined_files, names_only=names_only, ++ filename_expansion_function=filename_expansion_function) ++ ++ def SrcsetReplace(srcset_match, filepath=input_filepath, ++ inlined_files=inlined_files): ++ """Helper function to provide SrcsetInlineAsDataURL with the base file ++ path. ++ """ ++ return SrcsetInlineAsDataURL( ++ srcset_match, filepath, distribution, inlined_files, ++ names_only=names_only, ++ filename_expansion_function=filename_expansion_function) ++ ++ def GetFilepath(src_match, base_path = input_filepath): ++ filename = [v for k, v in src_match.groupdict().items() ++ if k.startswith('file') and v][0] ++ ++ if filename.find(':') != -1: ++ # filename is probably a URL, which we don't want to bother inlining ++ return None ++ ++ filename = filename.replace('%DISTRIBUTION%', distribution) ++ if filename_expansion_function: ++ filename = filename_expansion_function(filename) ++ return os.path.normpath(os.path.join(base_path, filename)) ++ ++ def IsConditionSatisfied(src_match): ++ expr1 = src_match.group('expr1') or '' ++ expr2 = src_match.group('expr2') or '' ++ return grd_node is None or grd_node.EvaluateCondition(expr1 + expr2) ++ ++ def CheckConditionalElements(str): ++ """Helper function to conditionally inline inner elements""" ++ while True: ++ begin_if = _BEGIN_IF_BLOCK.search(str) ++ if begin_if is None: ++ if _END_IF_BLOCK.search(str) is not None: ++ raise Exception('Unmatched </if>') ++ return str ++ ++ condition_satisfied = IsConditionSatisfied(begin_if) ++ leading = str[0:begin_if.start()] ++ content_start = begin_if.end() ++ ++ # Find matching "if" block end. ++ count = 1 ++ pos = begin_if.end() ++ while True: ++ end_if = _END_IF_BLOCK.search(str, pos) ++ if end_if is None: ++ raise Exception('Unmatched <if>') ++ ++ next_if = _BEGIN_IF_BLOCK.search(str, pos) ++ if next_if is None or next_if.start() >= end_if.end(): ++ count = count - 1 ++ if count == 0: ++ break ++ pos = end_if.end() ++ else: ++ count = count + 1 ++ pos = next_if.end() ++ ++ content = str[content_start:end_if.start()] ++ trailing = str[end_if.end():] ++ ++ if condition_satisfied: ++ str = leading + CheckConditionalElements(content) + trailing ++ else: ++ str = leading + trailing ++ ++ def InlineFileContents(src_match, ++ pattern, ++ inlined_files=inlined_files, ++ strip_whitespace=False): ++ """Helper function to inline external files of various types""" ++ filepath = GetFilepath(src_match) ++ if filepath is None: ++ return src_match.group(0) ++ inlined_files.add(filepath) ++ ++ if names_only: ++ inlined_files.update(GetResourceFilenames( ++ filepath, ++ grd_node, ++ allow_external_script, ++ rewrite_function, ++ filename_expansion_function=filename_expansion_function)) ++ return "" ++ # To recursively save inlined files, we need InlinedData instance returned ++ # by DoInline. ++ inlined_data_inst=DoInline(filepath, grd_node, ++ allow_external_script=allow_external_script, ++ preprocess_only=preprocess_only, ++ strip_whitespace=strip_whitespace, ++ filename_expansion_function=filename_expansion_function) ++ ++ inlined_files.update(inlined_data_inst.inlined_files) ++ ++ return pattern % inlined_data_inst.inlined_data; ++ ++ ++ def InlineIncludeFiles(src_match): ++ """Helper function to directly inline generic external files (without ++ wrapping them with any kind of tags). ++ """ ++ return InlineFileContents(src_match, '%s') ++ ++ def InlineScript(match): ++ """Helper function to inline external script files""" ++ attrs = (match.group('attrs1') + match.group('attrs2')).strip() ++ if attrs: ++ attrs = ' ' + attrs ++ return InlineFileContents(match, '<script' + attrs + '>%s</script>', ++ strip_whitespace=True) ++ ++ def InlineCSSText(text, css_filepath): ++ """Helper function that inlines external resources in CSS text""" ++ filepath = os.path.dirname(css_filepath) ++ # Allow custom modifications before inlining images. ++ if rewrite_function: ++ text = rewrite_function(filepath, text, distribution) ++ text = InlineCSSImages(text, filepath) ++ return InlineCSSImports(text, filepath) ++ ++ def InlineCSSFile(src_match, pattern, base_path=input_filepath): ++ """Helper function to inline external CSS files. ++ ++ Args: ++ src_match: A regular expression match with a named group named "filename". ++ pattern: The pattern to replace with the contents of the CSS file. ++ base_path: The base path to use for resolving the CSS file. ++ ++ Returns: ++ The text that should replace the reference to the CSS file. ++ """ ++ filepath = GetFilepath(src_match, base_path) ++ if filepath is None: ++ return src_match.group(0) ++ ++ # Even if names_only is set, the CSS file needs to be opened, because it ++ # can link to images that need to be added to the file set. ++ inlined_files.add(filepath) ++ ++ # Inline stylesheets included in this css file. ++ text = _INCLUDE_RE.sub(InlineIncludeFiles, util.ReadFile(filepath, 'utf-8')) ++ # When resolving CSS files we need to pass in the path so that relative URLs ++ # can be resolved. ++ ++ return pattern % InlineCSSText(text, filepath) ++ ++ def GetUrlRegexString(postfix=''): ++ """Helper function that returns a string for a regex that matches url('') ++ but not url([[ ]]) or url({{ }}). Appends |postfix| to group names. ++ """ ++ url_re = (r'url\((?!\[\[|{{)(?P<q%s>"|\'|)(?P<filename%s>[^"\'()]*)' ++ r'(?P=q%s)\)') ++ return url_re % (postfix, postfix, postfix) ++ ++ def InlineCSSImages(text, filepath=input_filepath): ++ """Helper function that inlines external images in CSS backgrounds.""" ++ # Replace contents of url() for css attributes: content, background, ++ # or *-image. ++ property_re = r'(content|background|[\w-]*-image):[^;]*' ++ # Replace group names to prevent duplicates when forming value_re. ++ image_set_value_re = (r'image-set\(([ ]*' + GetUrlRegexString('2') + ++ r'[ ]*[0-9.]*x[ ]*(,[ ]*)?)+\)') ++ value_re = '(%s|%s)' % (GetUrlRegexString(), image_set_value_re) ++ css_re = property_re + value_re ++ return re.sub(css_re, lambda m: InlineCSSUrls(m, filepath), text) ++ ++ def InlineCSSUrls(src_match, filepath=input_filepath): ++ """Helper function that inlines each url on a CSS image rule match.""" ++ # Replace contents of url() references in matches. ++ return re.sub(GetUrlRegexString(), ++ lambda m: SrcReplace(m, filepath), ++ src_match.group(0)) ++ ++ def InlineCSSImports(text, filepath=input_filepath): ++ """Helper function that inlines CSS files included via the @import ++ directive. ++ """ ++ return re.sub(r'@import\s+' + GetUrlRegexString() + r';', ++ lambda m: InlineCSSFile(m, '%s', filepath), ++ text) ++ ++ ++ flat_text = util.ReadFile(input_filename, 'utf-8') ++ ++ # Check conditional elements, remove unsatisfied ones from the file. We do ++ # this twice. The first pass is so that we don't even bother calling ++ # InlineScript, InlineCSSFile and InlineIncludeFiles on text we're eventually ++ # going to throw out anyway. ++ flat_text = CheckConditionalElements(flat_text) ++ ++ flat_text = _INCLUDE_RE.sub(InlineIncludeFiles, flat_text) ++ ++ if not preprocess_only: ++ if strip_whitespace: ++ flat_text = minifier.Minify(flat_text.encode('utf-8'), ++ input_filename).decode('utf-8') ++ ++ if not allow_external_script: ++ # We need to inline css and js before we inline images so that image ++ # references gets inlined in the css and js ++ flat_text = re.sub(r'<script (?P<attrs1>.*?)src="(?P<filename>[^"\']*)"' ++ r'(?P<attrs2>.*?)></script>', ++ InlineScript, ++ flat_text) ++ ++ flat_text = _STYLESHEET_RE.sub( ++ lambda m: InlineCSSFile(m, '<style>%s</style>'), ++ flat_text) ++ ++ # Check conditional elements, second pass. This catches conditionals in any ++ # of the text we just inlined. ++ flat_text = CheckConditionalElements(flat_text) ++ ++ # Allow custom modifications before inlining images. ++ if rewrite_function: ++ flat_text = rewrite_function(input_filepath, flat_text, distribution) ++ ++ if not preprocess_only: ++ flat_text = _SRC_RE.sub(SrcReplace, flat_text) ++ flat_text = _SRCSET_RE.sub(SrcsetReplace, flat_text) ++ ++ # TODO(arv): Only do this inside <style> tags. ++ flat_text = InlineCSSImages(flat_text) ++ ++ flat_text = _ICON_RE.sub(SrcReplace, flat_text) ++ ++ if names_only: ++ flat_text = None # Will contains garbage if the flag is set anyway. ++ return InlinedData(flat_text, inlined_files) ++ ++ ++def InlineToString(input_filename, grd_node, preprocess_only = False, ++ allow_external_script=False, strip_whitespace=False, ++ rewrite_function=None, filename_expansion_function=None): ++ """Inlines the resources in a specified file and returns it as a string. ++ ++ Args: ++ input_filename: name of file to read in ++ grd_node: html node from the grd file for this include tag ++ Returns: ++ the inlined data as a string ++ """ ++ try: ++ return DoInline( ++ input_filename, ++ grd_node, ++ preprocess_only=preprocess_only, ++ allow_external_script=allow_external_script, ++ strip_whitespace=strip_whitespace, ++ rewrite_function=rewrite_function, ++ filename_expansion_function=filename_expansion_function).inlined_data ++ except IOError as e: ++ raise Exception("Failed to open %s while trying to flatten %s. (%s)" % ++ (e.filename, input_filename, e.strerror)) ++ ++ ++def InlineToFile(input_filename, output_filename, grd_node): ++ """Inlines the resources in a specified file and writes it. ++ ++ Reads input_filename, finds all the src attributes and attempts to ++ inline the files they are referring to, then writes the result ++ to output_filename. ++ ++ Args: ++ input_filename: name of file to read in ++ output_filename: name of file to be written to ++ grd_node: html node from the grd file for this include tag ++ Returns: ++ a set of filenames of all the inlined files ++ """ ++ inlined_data = InlineToString(input_filename, grd_node) ++ with open(output_filename, 'wb') as out_file: ++ out_file.write(inlined_data) ++ ++ ++def GetResourceFilenames(filename, ++ grd_node, ++ allow_external_script=False, ++ rewrite_function=None, ++ filename_expansion_function=None): ++ """For a grd file, returns a set of all the files that would be inline.""" ++ try: ++ return DoInline( ++ filename, ++ grd_node, ++ names_only=True, ++ preprocess_only=False, ++ allow_external_script=allow_external_script, ++ strip_whitespace=False, ++ rewrite_function=rewrite_function, ++ filename_expansion_function=filename_expansion_function).inlined_files ++ except IOError as e: ++ raise Exception("Failed to open %s while trying to flatten %s. (%s)" % ++ (e.filename, filename, e.strerror)) + -+namespace { + -+bool TypeHasNonTrivialDtor(const Type* type) { -+ if (const CXXRecordDecl* cxx_r = type->getCXXRecordDeclForPointerType()) -+ return cxx_r->hasTrivialDestructor(); ++def main(): ++ if len(sys.argv) <= 2: ++ print("Flattens a HTML file by inlining its external resources.\n") ++ print("html_inline.py inputfile outputfile") ++ else: ++ InlineToFile(sys.argv[1], sys.argv[2], None) + -+ return false; -+} ++if __name__ == '__main__': ++ main() +diff --git a/tools/grit/grit/format/html_inline_unittest.py b/tools/grit/grit/format/html_inline_unittest.py +new file mode 100644 +index 0000000000..1b11e9e476 +--- /dev/null ++++ b/tools/grit/grit/format/html_inline_unittest.py +@@ -0,0 +1,927 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+// Returns the underlying Type for |type| by expanding typedefs and removing -+// any namespace qualifiers. -+const Type* UnwrapType(const Type* type) { -+ if (const ElaboratedType* elaborated = dyn_cast<ElaboratedType>(type)) -+ return UnwrapType(elaborated->getNamedType().getTypePtr()); -+ if (const TypedefType* typedefed = dyn_cast<TypedefType>(type)) -+ return UnwrapType(typedefed->desugar().getTypePtr()); -+ return type; -+} -+ -+// Searches for constructs that we know we don't want in the Chromium code base. -+class FindBadConstructsConsumer : public ChromeClassTester { -+ public: -+ FindBadConstructsConsumer(CompilerInstance& instance, -+ bool check_refcounted_dtors, -+ bool check_virtuals_in_implementations) -+ : ChromeClassTester(instance), -+ check_refcounted_dtors_(check_refcounted_dtors), -+ check_virtuals_in_implementations_(check_virtuals_in_implementations) { -+ } ++'''Unit tests for grit.format.html_inline''' + -+ virtual void CheckChromeClass(SourceLocation record_location, -+ CXXRecordDecl* record) { -+ bool implementation_file = InImplementationFile(record_location); ++from __future__ import print_function + -+ if (!implementation_file) { -+ // Only check for "heavy" constructors/destructors in header files; -+ // within implementation files, there is no performance cost. -+ CheckCtorDtorWeight(record_location, record); -+ } ++import os ++import re ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++import unittest ++ ++from grit import util ++from grit.format import html_inline ++ ++ ++class HtmlInlineUnittest(unittest.TestCase): ++ '''Unit tests for HtmlInline.''' ++ ++ def testGetResourceFilenames(self): ++ '''Tests that all included files are returned by GetResourceFilenames.''' ++ ++ files = { ++ 'index.html': ''' ++ <!DOCTYPE HTML> ++ <html> ++ <head> ++ <link rel="stylesheet" href="test.css"> ++ <link rel="stylesheet" ++ href="really-long-long-long-long-long-test.css"> ++ </head> ++ <body> ++ <include src='test.html'> ++ <include ++ src="really-long-long-long-long-long-test-file-omg-so-long.html"> ++ </body> ++ </html> ++ ''', ++ ++ 'test.html': ''' ++ <include src="test2.html"> ++ ''', ++ ++ 'really-long-long-long-long-long-test-file-omg-so-long.html': ''' ++ <!-- This really long named resource should be included. --> ++ ''', ++ ++ 'test2.html': ''' ++ <!-- This second level resource should also be included. --> ++ ''', ++ ++ 'test.css': ''' ++ .image { ++ background: url('test.png'); ++ } ++ ''', ++ ++ 'really-long-long-long-long-long-test.css': ''' ++ a:hover { ++ font-weight: bold; /* Awesome effect is awesome! */ ++ } ++ ''', + -+ if (!implementation_file || check_virtuals_in_implementations_) { -+ bool warn_on_inline_bodies = !implementation_file; ++ 'test.png': 'PNG DATA', ++ } + -+ // Check that all virtual methods are marked accordingly with both -+ // virtual and OVERRIDE. -+ CheckVirtualMethods(record_location, record, warn_on_inline_bodies); ++ source_resources = set() ++ tmp_dir = util.TempDir(files) ++ for filename in files: ++ source_resources.add(tmp_dir.GetPath(filename)) ++ ++ resources = html_inline.GetResourceFilenames(tmp_dir.GetPath('index.html'), ++ None) ++ resources.add(tmp_dir.GetPath('index.html')) ++ self.failUnlessEqual(resources, source_resources) ++ tmp_dir.CleanUp() ++ ++ def testUnmatchedEndIfBlock(self): ++ '''Tests that an unmatched </if> raises an exception.''' ++ ++ files = { ++ 'index.html': ''' ++ <!DOCTYPE HTML> ++ <html> ++ <if expr="lang == 'fr'"> ++ bonjour ++ </if> ++ <if expr='lang == "de"'> ++ hallo ++ </if> ++ </if> ++ </html> ++ ''', + } + -+ if (check_refcounted_dtors_) -+ CheckRefCountedDtors(record_location, record); -+ } ++ tmp_dir = util.TempDir(files) ++ ++ with self.assertRaises(Exception) as cm: ++ html_inline.GetResourceFilenames(tmp_dir.GetPath('index.html'), None) ++ self.failUnlessEqual(str(cm.exception), 'Unmatched </if>') ++ tmp_dir.CleanUp() ++ ++ def testCompressedJavaScript(self): ++ '''Tests that ".src=" doesn't treat as a tag.''' + -+ private: -+ bool check_refcounted_dtors_; -+ bool check_virtuals_in_implementations_; -+ -+ // Returns true if |base| specifies one of the Chromium reference counted -+ // classes (base::RefCounted / base::RefCountedThreadSafe). |user_data| is -+ // ignored. -+ static bool IsRefCountedCallback(const CXXBaseSpecifier* base, -+ CXXBasePath& path, -+ void* user_data) { -+ FindBadConstructsConsumer* self = -+ static_cast<FindBadConstructsConsumer*>(user_data); -+ -+ const TemplateSpecializationType* base_type = -+ dyn_cast<TemplateSpecializationType>( -+ UnwrapType(base->getType().getTypePtr())); -+ if (!base_type) { -+ // Base-most definition is not a template, so this cannot derive from -+ // base::RefCounted. However, it may still be possible to use with a -+ // scoped_refptr<> and support ref-counting, so this is not a perfect -+ // guarantee of safety. -+ return false; ++ files = { ++ 'index.js': ''' ++ if(i<j)a.src="hoge.png"; ++ ''', + } + -+ TemplateName name = base_type->getTemplateName(); -+ if (TemplateDecl* decl = name.getAsTemplateDecl()) { -+ std::string base_name = decl->getNameAsString(); ++ source_resources = set() ++ tmp_dir = util.TempDir(files) ++ for filename in files: ++ source_resources.add(tmp_dir.GetPath(filename)) ++ ++ resources = html_inline.GetResourceFilenames(tmp_dir.GetPath('index.js'), ++ None) ++ resources.add(tmp_dir.GetPath('index.js')) ++ self.failUnlessEqual(resources, source_resources) ++ tmp_dir.CleanUp() ++ ++ def testInlineCSSImports(self): ++ '''Tests that @import directives in inlined CSS files are inlined too. ++ ''' ++ ++ files = { ++ 'index.html': ''' ++ <html> ++ <head> ++ <link rel="stylesheet" href="css/test.css"> ++ </head> ++ </html> ++ ''', ++ ++ 'css/test.css': ''' ++ @import url('test2.css'); ++ blink { ++ display: none; ++ } ++ ''', + -+ // Check for both base::RefCounted and base::RefCountedThreadSafe. -+ if (base_name.compare(0, 10, "RefCounted") == 0 && -+ self->GetNamespace(decl) == "base") { -+ return true; ++ 'css/test2.css': ''' ++ .image { ++ background: url('../images/test.png'); + } -+ } -+ return false; -+ } ++ '''.strip(), + -+ // Prints errors if the destructor of a RefCounted class is public. -+ void CheckRefCountedDtors(SourceLocation record_location, -+ CXXRecordDecl* record) { -+ // Skip anonymous structs. -+ if (record->getIdentifier() == NULL) -+ return; -+ -+ CXXBasePaths paths; -+ if (!record->lookupInBases( -+ &FindBadConstructsConsumer::IsRefCountedCallback, this, paths)) { -+ return; // Class does not derive from a ref-counted base class. ++ 'images/test.png': 'PNG DATA' + } + -+ if (!record->hasUserDeclaredDestructor()) { -+ emitWarning( -+ record_location, -+ "Classes that are ref-counted should have explicit " -+ "destructors that are protected or private."); -+ } else if (CXXDestructorDecl* dtor = record->getDestructor()) { -+ if (dtor->getAccess() == AS_public) { -+ emitWarning( -+ dtor->getInnerLocStart(), -+ "Classes that are ref-counted should not have " -+ "public destructors."); ++ expected_inlined = ''' ++ <html> ++ <head> ++ <style> ++ .image { ++ background: url('data:image/png;base64,UE5HIERBVEE='); ++ } ++ blink { ++ display: none; ++ } ++ </style> ++ </head> ++ </html> ++ ''' ++ ++ source_resources = set() ++ tmp_dir = util.TempDir(files) ++ for filename in files: ++ source_resources.add(tmp_dir.GetPath(util.normpath(filename))) ++ ++ result = html_inline.DoInline(tmp_dir.GetPath('index.html'), None) ++ resources = result.inlined_files ++ resources.add(tmp_dir.GetPath('index.html')) ++ self.failUnlessEqual(resources, source_resources) ++ self.failUnlessEqual(expected_inlined, ++ util.FixLineEnd(result.inlined_data, '\n')) ++ ++ tmp_dir.CleanUp() ++ ++ def testInlineIgnoresPolymerBindings(self): ++ '''Tests that polymer bindings are ignored when inlining. ++ ''' ++ ++ files = { ++ 'index.html': ''' ++ <html> ++ <head> ++ <link rel="stylesheet" href="test.css"> ++ </head> ++ <body> ++ <iron-icon src="[[icon]]"></iron-icon><!-- Should be ignored. --> ++ <iron-icon src="{{src}}"></iron-icon><!-- Also ignored. --> ++ <!-- [[image]] should be ignored. --> ++ <div style="background: url([[image]]), ++ url('test.png');"> ++ </div> ++ <div style="background: url('test.png'), ++ url([[image]]);"> ++ </div> ++ </body> ++ </html> ++ ''', ++ ++ 'test.css': ''' ++ .image { ++ background: url('test.png'); ++ background-image: url([[ignoreMe]]); ++ background-image: image-set(url({{alsoMe}}), 1x); ++ background-image: image-set( ++ url({{ignore}}) 1x, ++ url('test.png') 2x); + } ++ ''', ++ ++ 'test.png': 'PNG DATA' + } -+ } + -+ // Prints errors if the constructor/destructor weight is too heavy. -+ void CheckCtorDtorWeight(SourceLocation record_location, -+ CXXRecordDecl* record) { -+ // We don't handle anonymous structs. If this record doesn't have a -+ // name, it's of the form: -+ // -+ // struct { -+ // ... -+ // } name_; -+ if (record->getIdentifier() == NULL) -+ return; -+ -+ // Count the number of templated base classes as a feature of whether the -+ // destructor can be inlined. -+ int templated_base_classes = 0; -+ for (CXXRecordDecl::base_class_const_iterator it = record->bases_begin(); -+ it != record->bases_end(); ++it) { -+ if (it->getTypeSourceInfo()->getTypeLoc().getTypeLocClass() == -+ TypeLoc::TemplateSpecialization) { -+ ++templated_base_classes; ++ expected_inlined = ''' ++ <html> ++ <head> ++ <style> ++ .image { ++ background: url('data:image/png;base64,UE5HIERBVEE='); ++ background-image: url([[ignoreMe]]); ++ background-image: image-set(url({{alsoMe}}), 1x); ++ background-image: image-set( ++ url({{ignore}}) 1x, ++ url('data:image/png;base64,UE5HIERBVEE=') 2x); ++ } ++ </style> ++ </head> ++ <body> ++ <iron-icon src="[[icon]]"></iron-icon><!-- Should be ignored. --> ++ <iron-icon src="{{src}}"></iron-icon><!-- Also ignored. --> ++ <!-- [[image]] should be ignored. --> ++ <div style="background: url([[image]]), ++ url('data:image/png;base64,UE5HIERBVEE=');"> ++ </div> ++ <div style="background: url('data:image/png;base64,UE5HIERBVEE='), ++ url([[image]]);"> ++ </div> ++ </body> ++ </html> ++ ''' ++ ++ source_resources = set() ++ tmp_dir = util.TempDir(files) ++ for filename in files: ++ source_resources.add(tmp_dir.GetPath(util.normpath(filename))) ++ ++ result = html_inline.DoInline(tmp_dir.GetPath('index.html'), None) ++ resources = result.inlined_files ++ resources.add(tmp_dir.GetPath('index.html')) ++ self.failUnlessEqual(resources, source_resources) ++ self.failUnlessEqual(expected_inlined, ++ util.FixLineEnd(result.inlined_data, '\n')) ++ ++ tmp_dir.CleanUp() ++ ++ def testInlineCSSWithIncludeDirective(self): ++ '''Tests that include directive in external css files also inlined''' ++ ++ files = { ++ 'index.html': ''' ++ <html> ++ <head> ++ <link rel="stylesheet" href="foo.css"> ++ </head> ++ </html> ++ ''', ++ ++ 'foo.css': '''<include src="style.css">''', ++ ++ 'style.css': ''' ++ <include src="style2.css"> ++ blink { ++ display: none; + } ++ ''', ++ 'style2.css': '''h1 {}''', + } + -+ // Count the number of trivial and non-trivial member variables. -+ int trivial_member = 0; -+ int non_trivial_member = 0; -+ int templated_non_trivial_member = 0; -+ for (RecordDecl::field_iterator it = record->field_begin(); -+ it != record->field_end(); ++it) { -+ CountType(it->getType().getTypePtr(), -+ &trivial_member, -+ &non_trivial_member, -+ &templated_non_trivial_member); ++ expected_inlined = ''' ++ <html> ++ <head> ++ <style> ++ h1 {} ++ blink { ++ display: none; ++ } ++ </style> ++ </head> ++ </html> ++ ''' ++ ++ source_resources = set() ++ tmp_dir = util.TempDir(files) ++ for filename in files: ++ source_resources.add(tmp_dir.GetPath(filename)) ++ ++ result = html_inline.DoInline(tmp_dir.GetPath('index.html'), None) ++ resources = result.inlined_files ++ resources.add(tmp_dir.GetPath('index.html')) ++ self.failUnlessEqual(resources, source_resources) ++ self.failUnlessEqual(expected_inlined, ++ util.FixLineEnd(result.inlined_data, '\n')) ++ tmp_dir.CleanUp() ++ ++ def testCssIncludedFileNames(self): ++ '''Tests that all included files from css are returned''' ++ ++ files = { ++ 'index.html': ''' ++ <!DOCTYPE HTML> ++ <html> ++ <head> ++ <link rel="stylesheet" href="test.css"> ++ </head> ++ <body> ++ </body> ++ </html> ++ ''', ++ ++ 'test.css': ''' ++ <include src="test2.css"> ++ ''', ++ ++ 'test2.css': ''' ++ <include src="test3.css"> ++ .image { ++ background: url('test.png'); ++ } ++ ''', ++ ++ 'test3.css': '''h1 {}''', ++ ++ 'test.png': 'PNG DATA' + } + -+ // Check to see if we need to ban inlined/synthesized constructors. Note -+ // that the cutoffs here are kind of arbitrary. Scores over 10 break. -+ int dtor_score = 0; -+ // Deriving from a templated base class shouldn't be enough to trigger -+ // the ctor warning, but if you do *anything* else, it should. -+ // -+ // TODO(erg): This is motivated by templated base classes that don't have -+ // any data members. Somehow detect when templated base classes have data -+ // members and treat them differently. -+ dtor_score += templated_base_classes * 9; -+ // Instantiating a template is an insta-hit. -+ dtor_score += templated_non_trivial_member * 10; -+ // The fourth normal class member should trigger the warning. -+ dtor_score += non_trivial_member * 3; -+ -+ int ctor_score = dtor_score; -+ // You should be able to have 9 ints before we warn you. -+ ctor_score += trivial_member; -+ -+ if (ctor_score >= 10) { -+ if (!record->hasUserDeclaredConstructor()) { -+ emitWarning(record_location, -+ "Complex class/struct needs an explicit out-of-line " -+ "constructor."); -+ } else { -+ // Iterate across all the constructors in this file and yell if we -+ // find one that tries to be inline. -+ for (CXXRecordDecl::ctor_iterator it = record->ctor_begin(); -+ it != record->ctor_end(); ++it) { -+ if (it->hasInlineBody()) { -+ if (it->isCopyConstructor() && -+ !record->hasUserDeclaredCopyConstructor()) { -+ emitWarning(record_location, -+ "Complex class/struct needs an explicit out-of-line " -+ "copy constructor."); -+ } else { -+ emitWarning(it->getInnerLocStart(), -+ "Complex constructor has an inlined body."); -+ } -+ } -+ } ++ source_resources = set() ++ tmp_dir = util.TempDir(files) ++ for filename in files: ++ source_resources.add(tmp_dir.GetPath(filename)) ++ ++ resources = html_inline.GetResourceFilenames(tmp_dir.GetPath('index.html'), ++ None) ++ resources.add(tmp_dir.GetPath('index.html')) ++ self.failUnlessEqual(resources, source_resources) ++ tmp_dir.CleanUp() ++ ++ def testInlineCSSLinks(self): ++ '''Tests that only CSS files referenced via relative URLs are inlined.''' ++ ++ files = { ++ 'index.html': ''' ++ <html> ++ <head> ++ <link rel="stylesheet" href="foo.css"> ++ <link rel="stylesheet" href="chrome://resources/bar.css"> ++ </head> ++ </html> ++ ''', ++ ++ 'foo.css': ''' ++ @import url(chrome://resources/blurp.css); ++ blink { ++ display: none; + } ++ ''', + } + -+ // The destructor side is equivalent except that we don't check for -+ // trivial members; 20 ints don't need a destructor. -+ if (dtor_score >= 10 && !record->hasTrivialDestructor()) { -+ if (!record->hasUserDeclaredDestructor()) { -+ emitWarning( -+ record_location, -+ "Complex class/struct needs an explicit out-of-line " -+ "destructor."); -+ } else if (CXXDestructorDecl* dtor = record->getDestructor()) { -+ if (dtor->hasInlineBody()) { -+ emitWarning(dtor->getInnerLocStart(), -+ "Complex destructor has an inline body."); -+ } ++ expected_inlined = ''' ++ <html> ++ <head> ++ <style> ++ @import url(chrome://resources/blurp.css); ++ blink { ++ display: none; + } ++ </style> ++ <link rel="stylesheet" href="chrome://resources/bar.css"> ++ </head> ++ </html> ++ ''' ++ ++ source_resources = set() ++ tmp_dir = util.TempDir(files) ++ for filename in files: ++ source_resources.add(tmp_dir.GetPath(filename)) ++ ++ result = html_inline.DoInline(tmp_dir.GetPath('index.html'), None) ++ resources = result.inlined_files ++ resources.add(tmp_dir.GetPath('index.html')) ++ self.failUnlessEqual(resources, source_resources) ++ self.failUnlessEqual(expected_inlined, ++ util.FixLineEnd(result.inlined_data, '\n')) ++ tmp_dir.CleanUp() ++ ++ def testFilenameVariableExpansion(self): ++ '''Tests that variables are expanded in filenames before inlining.''' ++ ++ files = { ++ 'index.html': ''' ++ <html> ++ <head> ++ <link rel="stylesheet" href="style[WHICH].css"> ++ <script src="script[WHICH].js"></script> ++ </head> ++ <include src="tmpl[WHICH].html"> ++ <img src="img[WHICH].png"> ++ </html> ++ ''', ++ 'style1.css': '''h1 {}''', ++ 'tmpl1.html': '''<h1></h1>''', ++ 'script1.js': '''console.log('hello');''', ++ 'img1.png': '''abc''', + } -+ } + -+ void CheckVirtualMethod(const CXXMethodDecl* method, -+ bool warn_on_inline_bodies) { -+ if (!method->isVirtual()) -+ return; ++ expected_inlined = ''' ++ <html> ++ <head> ++ <style>h1 {}</style> ++ <script>console.log('hello');</script> ++ </head> ++ <h1></h1> ++ <img src="data:image/png;base64,YWJj"> ++ </html> ++ ''' ++ ++ source_resources = set() ++ tmp_dir = util.TempDir(files) ++ for filename in files: ++ source_resources.add(tmp_dir.GetPath(filename)) ++ ++ def replacer(var, repl): ++ return lambda filename: filename.replace('[%s]' % var, repl) ++ ++ # Test normal inlining. ++ result = html_inline.DoInline( ++ tmp_dir.GetPath('index.html'), ++ None, ++ filename_expansion_function=replacer('WHICH', '1')) ++ resources = result.inlined_files ++ resources.add(tmp_dir.GetPath('index.html')) ++ self.failUnlessEqual(resources, source_resources) ++ self.failUnlessEqual(expected_inlined, ++ util.FixLineEnd(result.inlined_data, '\n')) ++ ++ # Test names-only inlining. ++ result = html_inline.DoInline( ++ tmp_dir.GetPath('index.html'), ++ None, ++ names_only=True, ++ filename_expansion_function=replacer('WHICH', '1')) ++ resources = result.inlined_files ++ resources.add(tmp_dir.GetPath('index.html')) ++ self.failUnlessEqual(resources, source_resources) ++ tmp_dir.CleanUp() ++ ++ def testWithCloseTags(self): ++ '''Tests that close tags are removed.''' ++ ++ files = { ++ 'index.html': ''' ++ <html> ++ <head> ++ <link rel="stylesheet" href="style1.css"></link> ++ <link rel="stylesheet" href="style2.css"> ++ </link> ++ <link rel="stylesheet" href="style2.css" ++ > ++ </link> ++ <script src="script1.js"></script> ++ </head> ++ <include src="tmpl1.html"></include> ++ <include src="tmpl2.html"> ++ </include> ++ <include src="tmpl2.html" ++ > ++ </include> ++ <img src="img1.png"> ++ <include src='single-double-quotes.html"></include> ++ <include src="double-single-quotes.html'></include> ++ </html> ++ ''', ++ 'style1.css': '''h1 {}''', ++ 'style2.css': '''h2 {}''', ++ 'tmpl1.html': '''<h1></h1>''', ++ 'tmpl2.html': '''<h2></h2>''', ++ 'script1.js': '''console.log('hello');''', ++ 'img1.png': '''abc''', ++ } + -+ if (!method->isVirtualAsWritten()) { -+ SourceLocation loc = method->getTypeSpecStartLoc(); -+ if (isa<CXXDestructorDecl>(method)) -+ loc = method->getInnerLocStart(); -+ emitWarning(loc, "Overriding method must have \"virtual\" keyword."); ++ expected_inlined = ''' ++ <html> ++ <head> ++ <style>h1 {}</style> ++ <style>h2 {}</style> ++ <style>h2 {}</style> ++ <script>console.log('hello');</script> ++ </head> ++ <h1></h1> ++ <h2></h2> ++ <h2></h2> ++ <img src="data:image/png;base64,YWJj"> ++ <include src='single-double-quotes.html"></include> ++ <include src="double-single-quotes.html'></include> ++ </html> ++ ''' ++ ++ source_resources = set() ++ tmp_dir = util.TempDir(files) ++ for filename in files: ++ source_resources.add(tmp_dir.GetPath(filename)) ++ ++ # Test normal inlining. ++ result = html_inline.DoInline( ++ tmp_dir.GetPath('index.html'), ++ None) ++ resources = result.inlined_files ++ resources.add(tmp_dir.GetPath('index.html')) ++ self.failUnlessEqual(resources, source_resources) ++ self.failUnlessEqual(expected_inlined, ++ util.FixLineEnd(result.inlined_data, '\n')) ++ tmp_dir.CleanUp() ++ ++ def testCommentedJsInclude(self): ++ '''Tests that <include> works inside a comment.''' ++ ++ files = { ++ 'include.js': '// <include src="other.js">', ++ 'other.js': '// Copyright somebody\nalert(1);', + } + -+ // Virtual methods should not have inline definitions beyond "{}". This -+ // only matters for header files. -+ if (warn_on_inline_bodies && method->hasBody() && -+ method->hasInlineBody()) { -+ if (CompoundStmt* cs = dyn_cast<CompoundStmt>(method->getBody())) { -+ if (cs->size()) { -+ emitWarning( -+ cs->getLBracLoc(), -+ "virtual methods with non-empty bodies shouldn't be " -+ "declared inline."); -+ } -+ } ++ expected_inlined = '// Copyright somebody\nalert(1);' ++ ++ source_resources = set() ++ tmp_dir = util.TempDir(files) ++ for filename in files: ++ source_resources.add(tmp_dir.GetPath(filename)) ++ ++ result = html_inline.DoInline(tmp_dir.GetPath('include.js'), None) ++ resources = result.inlined_files ++ resources.add(tmp_dir.GetPath('include.js')) ++ self.failUnlessEqual(resources, source_resources) ++ self.failUnlessEqual(expected_inlined, ++ util.FixLineEnd(result.inlined_data, '\n')) ++ tmp_dir.CleanUp() ++ ++ def testCommentedJsIf(self): ++ '''Tests that <if> works inside a comment.''' ++ ++ files = { ++ 'if.js': ''' ++ // <if expr="True"> ++ yep(); ++ // </if> ++ ++ // <if expr="False"> ++ nope(); ++ // </if> ++ ''', + } -+ } + -+ bool InTestingNamespace(const Decl* record) { -+ return GetNamespace(record).find("testing") != std::string::npos; -+ } ++ expected_inlined = ''' ++ // ++ yep(); ++ // ++ ++ // ++ ''' ++ ++ source_resources = set() ++ tmp_dir = util.TempDir(files) ++ for filename in files: ++ source_resources.add(tmp_dir.GetPath(filename)) ++ ++ class FakeGrdNode(object): ++ def EvaluateCondition(self, cond): ++ return eval(cond) ++ ++ result = html_inline.DoInline(tmp_dir.GetPath('if.js'), FakeGrdNode()) ++ resources = result.inlined_files ++ ++ resources.add(tmp_dir.GetPath('if.js')) ++ self.failUnlessEqual(resources, source_resources) ++ self.failUnlessEqual(expected_inlined, ++ util.FixLineEnd(result.inlined_data, '\n')) ++ tmp_dir.CleanUp() ++ ++ def testImgSrcset(self): ++ '''Tests that img srcset="" attributes are converted.''' ++ ++ # Note that there is no space before "img10.png" and that ++ # "img11.png" has no descriptor. ++ files = { ++ 'index.html': ''' ++ <html> ++ <img src="img1.png" srcset="img2.png 1x, img3.png 2x"> ++ <img src="img4.png" srcset=" img5.png 1x , img6.png 2x "> ++ <img src="chrome://theme/img11.png" srcset="img7.png 1x, '''\ ++ '''chrome://theme/img13.png 2x"> ++ <img srcset="img8.png 300w, img9.png 11E-2w,img10.png -1e2w"> ++ <img srcset="img11.png"> ++ <img srcset="img11.png, img2.png 1x"> ++ <img srcset="img2.png 1x, img11.png"> ++ </html> ++ ''', ++ 'img1.png': '''a1''', ++ 'img2.png': '''a2''', ++ 'img3.png': '''a3''', ++ 'img4.png': '''a4''', ++ 'img5.png': '''a5''', ++ 'img6.png': '''a6''', ++ 'img7.png': '''a7''', ++ 'img8.png': '''a8''', ++ 'img9.png': '''a9''', ++ 'img10.png': '''a10''', ++ 'img11.png': '''a11''', ++ } + -+ bool IsMethodInBannedNamespace(const CXXMethodDecl* method) { -+ if (InBannedNamespace(method)) -+ return true; -+ for (CXXMethodDecl::method_iterator i = method->begin_overridden_methods(); -+ i != method->end_overridden_methods(); -+ ++i) { -+ const CXXMethodDecl* overridden = *i; -+ if (IsMethodInBannedNamespace(overridden)) -+ return true; ++ expected_inlined = ''' ++ <html> ++ <img src="data:image/png;base64,YTE=" srcset="data:image/png;base64,'''\ ++ '''YTI= 1x,data:image/png;base64,YTM= 2x"> ++ <img src="data:image/png;base64,YTQ=" srcset="data:image/png;base64,'''\ ++ '''YTU= 1x,data:image/png;base64,YTY= 2x"> ++ <img src="chrome://theme/img11.png" srcset="data:image/png;base64,'''\ ++ '''YTc= 1x,chrome://theme/img13.png 2x"> ++ <img srcset="data:image/png;base64,YTg= 300w,data:image/png;base64,'''\ ++ '''YTk= 11E-2w,data:image/png;base64,YTEw -1e2w"> ++ <img srcset="data:image/png;base64,YTEx"> ++ <img srcset="data:image/png;base64,YTEx,data:image/png;base64,YTI= 1x"> ++ <img srcset="data:image/png;base64,YTI= 1x,data:image/png;base64,YTEx"> ++ </html> ++ ''' ++ ++ source_resources = set() ++ tmp_dir = util.TempDir(files) ++ for filename in files: ++ source_resources.add(tmp_dir.GetPath(filename)) ++ ++ # Test normal inlining. ++ result = html_inline.DoInline( ++ tmp_dir.GetPath('index.html'), ++ None) ++ resources = result.inlined_files ++ resources.add(tmp_dir.GetPath('index.html')) ++ self.failUnlessEqual(resources, source_resources) ++ self.failUnlessEqual(expected_inlined, ++ util.FixLineEnd(result.inlined_data, '\n')) ++ tmp_dir.CleanUp() ++ ++ def testImgSrcsetIgnoresI18n(self): ++ '''Tests that $i18n{...} strings are ignored when inlining. ++ ''' ++ ++ src_html = ''' ++ <html> ++ <head></head> ++ <body> ++ <img srcset="$i18n{foo}"> ++ </body> ++ </html> ++ ''' ++ ++ files = { ++ 'index.html': src_html, + } + -+ return false; -+ } ++ expected_inlined = src_html ++ ++ source_resources = set() ++ tmp_dir = util.TempDir(files) ++ for filename in files: ++ source_resources.add(tmp_dir.GetPath(util.normpath(filename))) ++ ++ result = html_inline.DoInline(tmp_dir.GetPath('index.html'), None) ++ resources = result.inlined_files ++ resources.add(tmp_dir.GetPath('index.html')) ++ self.failUnlessEqual(resources, source_resources) ++ self.failUnlessEqual(expected_inlined, ++ util.FixLineEnd(result.inlined_data, '\n')) ++ tmp_dir.CleanUp() ++ ++ def testSourceSrcset(self): ++ '''Tests that source srcset="" attributes are converted.''' ++ ++ # Note that there is no space before "img10.png" and that ++ # "img11.png" has no descriptor. ++ files = { ++ 'index.html': ''' ++ <html> ++ <source src="img1.png" srcset="img2.png 1x, img3.png 2x"> ++ <source src="img4.png" srcset=" img5.png 1x , img6.png 2x "> ++ <source src="chrome://theme/img11.png" srcset="img7.png 1x, '''\ ++ '''chrome://theme/img13.png 2x"> ++ <source srcset="img8.png 300w, img9.png 11E-2w,img10.png -1e2w"> ++ <source srcset="img11.png"> ++ </html> ++ ''', ++ 'img1.png': '''a1''', ++ 'img2.png': '''a2''', ++ 'img3.png': '''a3''', ++ 'img4.png': '''a4''', ++ 'img5.png': '''a5''', ++ 'img6.png': '''a6''', ++ 'img7.png': '''a7''', ++ 'img8.png': '''a8''', ++ 'img9.png': '''a9''', ++ 'img10.png': '''a10''', ++ 'img11.png': '''a11''', ++ } ++ ++ expected_inlined = ''' ++ <html> ++ <source src="data:image/png;base64,YTE=" srcset="data:image/png;'''\ ++ '''base64,YTI= 1x,data:image/png;base64,YTM= 2x"> ++ <source src="data:image/png;base64,YTQ=" srcset="data:image/png;'''\ ++ '''base64,YTU= 1x,data:image/png;base64,YTY= 2x"> ++ <source src="chrome://theme/img11.png" srcset="data:image/png;'''\ ++ '''base64,YTc= 1x,chrome://theme/img13.png 2x"> ++ <source srcset="data:image/png;base64,YTg= 300w,data:image/png;'''\ ++ '''base64,YTk= 11E-2w,data:image/png;base64,YTEw -1e2w"> ++ <source srcset="data:image/png;base64,YTEx"> ++ </html> ++ ''' ++ ++ source_resources = set() ++ tmp_dir = util.TempDir(files) ++ for filename in files: ++ source_resources.add(tmp_dir.GetPath(filename)) ++ ++ # Test normal inlining. ++ result = html_inline.DoInline(tmp_dir.GetPath('index.html'), None) ++ resources = result.inlined_files ++ resources.add(tmp_dir.GetPath('index.html')) ++ self.failUnlessEqual(resources, source_resources) ++ self.failUnlessEqual(expected_inlined, ++ util.FixLineEnd(result.inlined_data, '\n')) ++ tmp_dir.CleanUp() ++ ++ def testConditionalInclude(self): ++ '''Tests that output and dependency generation includes only files not'''\ ++ ''' blocked by <if> macros.''' ++ ++ files = { ++ 'index.html': ''' ++ <html> ++ <if expr="True"> ++ <img src="img1.png" srcset="img2.png 1x, img3.png 2x"> ++ </if> ++ <if expr="False"> ++ <img src="img4.png" srcset=" img5.png 1x, img6.png 2x "> ++ </if> ++ <if expr="True"> ++ <img src="chrome://theme/img11.png" srcset="img7.png 1x, '''\ ++ '''chrome://theme/img13.png 2x"> ++ </if> ++ <img srcset="img8.png 300w, img9.png 11E-2w,img10.png -1e2w"> ++ </html> ++ ''', ++ 'img1.png': '''a1''', ++ 'img2.png': '''a2''', ++ 'img3.png': '''a3''', ++ 'img4.png': '''a4''', ++ 'img5.png': '''a5''', ++ 'img6.png': '''a6''', ++ 'img7.png': '''a7''', ++ 'img8.png': '''a8''', ++ 'img9.png': '''a9''', ++ 'img10.png': '''a10''', ++ } + -+ void CheckOverriddenMethod(const CXXMethodDecl* method) { -+ if (!method->size_overridden_methods() || method->getAttr<OverrideAttr>()) -+ return; ++ expected_inlined = ''' ++ <html> ++ <img src="data:image/png;base64,YTE=" srcset="data:image/png;base64,'''\ ++ '''YTI= 1x,data:image/png;base64,YTM= 2x"> ++ <img src="chrome://theme/img11.png" srcset="data:image/png;base64,'''\ ++ '''YTc= 1x,chrome://theme/img13.png 2x"> ++ <img srcset="data:image/png;base64,YTg= 300w,data:image/png;base64,'''\ ++ '''YTk= 11E-2w,data:image/png;base64,YTEw -1e2w"> ++ </html> ++ ''' ++ ++ expected_files = [ ++ 'index.html', ++ 'img1.png', ++ 'img2.png', ++ 'img3.png', ++ 'img7.png', ++ 'img8.png', ++ 'img9.png', ++ 'img10.png' ++ ] ++ ++ source_resources = set() ++ tmp_dir = util.TempDir(files) ++ for filename in expected_files: ++ source_resources.add(tmp_dir.GetPath(filename)) ++ ++ class FakeGrdNode(object): ++ def EvaluateCondition(self, cond): ++ return eval(cond) ++ ++ # Test normal inlining. ++ result = html_inline.DoInline( ++ tmp_dir.GetPath('index.html'), ++ FakeGrdNode()) ++ resources = result.inlined_files ++ resources.add(tmp_dir.GetPath('index.html')) ++ self.failUnlessEqual(resources, source_resources) ++ ++ # ignore whitespace ++ expected_inlined = re.sub(r'\s+', ' ', expected_inlined) ++ actually_inlined = re.sub(r'\s+', ' ', ++ util.FixLineEnd(result.inlined_data, '\n')) ++ self.failUnlessEqual(expected_inlined, actually_inlined); ++ tmp_dir.CleanUp() ++ ++ def testPreprocessOnlyEvaluatesIncludeAndIf(self): ++ '''Tests that preprocess_only=true evaluates <include> and <if> only. ''' ++ ++ files = { ++ 'index.html': ''' ++ <html> ++ <head> ++ <link rel="stylesheet" href="not_inlined.css"> ++ <script src="also_not_inlined.js"> ++ </head> ++ <body> ++ <include src="inline_this.html"> ++ <if expr="True"> ++ <p>'if' should be evaluated.</p> ++ </if> ++ </body> ++ </html> ++ ''', ++ 'not_inlined.css': ''' /* <link> should not be inlined. */ ''', ++ 'also_not_inlined.js': ''' // <script> should not be inlined. ''', ++ 'inline_this.html': ''' <p>'include' should be inlined.</p> ''' ++ } ++ ++ expected_inlined = ''' ++ <html> ++ <head> ++ <link rel="stylesheet" href="not_inlined.css"> ++ <script src="also_not_inlined.js"> ++ </head> ++ <body> ++ <p>'include' should be inlined.</p> ++ <p>'if' should be evaluated.</p> ++ </body> ++ </html> ++ ''' ++ ++ source_resources = set() ++ tmp_dir = util.TempDir(files) ++ source_resources.add(tmp_dir.GetPath('index.html')) ++ source_resources.add(tmp_dir.GetPath('inline_this.html')) ++ ++ result = html_inline.DoInline(tmp_dir.GetPath('index.html'), None, ++ preprocess_only=True) ++ resources = result.inlined_files ++ resources.add(tmp_dir.GetPath('index.html')) ++ self.failUnlessEqual(resources, source_resources) ++ ++ # Ignore whitespace ++ expected_inlined = re.sub(r'\s+', ' ', expected_inlined) ++ actually_inlined = re.sub(r'\s+', ' ', ++ util.FixLineEnd(result.inlined_data, '\n')) ++ self.failUnlessEqual(expected_inlined, actually_inlined) ++ ++ tmp_dir.CleanUp() ++ ++ def testPreprocessOnlyAppliesRecursively(self): ++ '''Tests that preprocess_only=true propagates to included files. ''' ++ ++ files = { ++ 'index.html': ''' ++ <html> ++ <include src="outer_include.html"> ++ </html> ++ ''', ++ 'outer_include.html': ''' ++ <include src="inner_include.html"> ++ <link rel="stylesheet" href="not_inlined.css"> ++ ''', ++ 'inner_include.html': ''' <p>This should be inlined in index.html</p> ''', ++ 'not_inlined.css': ''' /* This should not be inlined. */ ''' ++ } + -+ if (isa<CXXDestructorDecl>(method) || method->isPure()) -+ return; ++ expected_inlined = ''' ++ <html> ++ <p>This should be inlined in index.html</p> ++ <link rel="stylesheet" href="not_inlined.css"> ++ </html> ++ ''' ++ ++ source_resources = set() ++ tmp_dir = util.TempDir(files) ++ source_resources.add(tmp_dir.GetPath('index.html')) ++ source_resources.add(tmp_dir.GetPath('outer_include.html')) ++ source_resources.add(tmp_dir.GetPath('inner_include.html')) ++ ++ result = html_inline.DoInline(tmp_dir.GetPath('index.html'), None, ++ preprocess_only=True) ++ resources = result.inlined_files ++ resources.add(tmp_dir.GetPath('index.html')) ++ self.failUnlessEqual(resources, source_resources) ++ ++ # Ignore whitespace ++ expected_inlined = re.sub(r'\s+', ' ', expected_inlined) ++ actually_inlined = re.sub(r'\s+', ' ', ++ util.FixLineEnd(result.inlined_data, '\n')) ++ self.failUnlessEqual(expected_inlined, actually_inlined) ++ ++ tmp_dir.CleanUp() + -+ if (IsMethodInBannedNamespace(method)) -+ return; ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/format/minifier.py b/tools/grit/grit/format/minifier.py +new file mode 100644 +index 0000000000..1a0ea34e49 +--- /dev/null ++++ b/tools/grit/grit/format/minifier.py +@@ -0,0 +1,45 @@ ++# Copyright 2016 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++"""Framework for stripping whitespace and comments from resource files""" + -+ SourceLocation loc = method->getTypeSpecStartLoc(); -+ emitWarning(loc, "Overriding method must be marked with OVERRIDE."); ++from __future__ import print_function ++ ++from os import path ++import subprocess ++import sys ++ ++import six ++ ++__js_minifier = None ++__css_minifier = None ++ ++def SetJsMinifier(minifier): ++ global __js_minifier ++ __js_minifier = minifier.split() ++ ++def SetCssMinifier(minifier): ++ global __css_minifier ++ __css_minifier = minifier.split() ++ ++def Minify(source, filename): ++ """Minify |source| (bytes) from |filename| and return bytes.""" ++ file_type = path.splitext(filename)[1] ++ minifier = None ++ if file_type == '.js': ++ minifier = __js_minifier ++ elif file_type == '.css': ++ minifier = __css_minifier ++ if not minifier: ++ return source ++ p = subprocess.Popen( ++ minifier, ++ stdin=subprocess.PIPE, ++ stdout=subprocess.PIPE, ++ stderr=subprocess.PIPE) ++ (stdout, stderr) = p.communicate(source) ++ if p.returncode != 0: ++ print('Minification failed for %s' % filename) ++ print(stderr) ++ sys.exit(p.returncode) ++ return stdout +diff --git a/tools/grit/grit/format/policy_templates_json.py b/tools/grit/grit/format/policy_templates_json.py +new file mode 100644 +index 0000000000..2f9330bb9a +--- /dev/null ++++ b/tools/grit/grit/format/policy_templates_json.py +@@ -0,0 +1,26 @@ ++# Copyright 2017 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++"""Translates policy_templates.json files. ++""" ++ ++from __future__ import print_function ++ ++from grit.node import structure ++ ++ ++def Format(root, lang='en', output_dir='.'): ++ policy_json = None ++ for item in root.ActiveDescendants(): ++ with item: ++ if (isinstance(item, structure.StructureNode) and ++ item.attrs['type'] == 'policy_template_metafile'): ++ json_text = item.gatherer.Translate( ++ lang, ++ pseudo_if_not_available=item.PseudoIsAllowed(), ++ fallback_to_english=item.ShouldFallbackToEnglish()) ++ # We're only expecting one node of this kind. ++ assert not policy_json ++ policy_json = json_text ++ return policy_json +diff --git a/tools/grit/grit/format/policy_templates_json_unittest.py b/tools/grit/grit/format/policy_templates_json_unittest.py +new file mode 100644 +index 0000000000..e252c94e2c +--- /dev/null ++++ b/tools/grit/grit/format/policy_templates_json_unittest.py +@@ -0,0 +1,207 @@ ++#!/usr/bin/env python ++# coding: utf-8 ++# Copyright 2017 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++"""Unittest for policy_templates_json.py. ++""" ++ ++from __future__ import print_function ++ ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++import grit.extern.tclib ++import tempfile ++import unittest ++ ++from six import StringIO ++ ++from grit import grd_reader ++from grit.tool import build ++ ++ ++class PolicyTemplatesJsonUnittest(unittest.TestCase): ++ ++ def testPolicyTranslation(self): ++ # Create test policy_templates.json data. ++ caption = "The main policy" ++ caption_translation = "Die Hauptrichtlinie" ++ ++ message = \ ++ "Red cabbage stays red cabbage and wedding dress stays wedding dress" ++ message_translation = \ ++ "Blaukraut bleibt Blaukraut und Brautkleid bleibt Brautkleid" ++ ++ schema_key_description = "Number of users" ++ schema_key_description_translation = "Anzahl der Nutzer" ++ ++ policy_json = """ ++ { ++ "policy_definitions": [ ++ { ++ 'name': 'MainPolicy', ++ 'type': 'main', ++ 'owners': ['foo@bar.com'], ++ 'schema': { ++ 'properties': { ++ 'default_launch_container': { ++ 'enum': [ ++ 'tab', ++ 'window', ++ ], ++ 'type': 'string', ++ }, ++ 'users_number': { ++ 'description': '''%s''', ++ 'type': 'integer', ++ }, ++ }, ++ 'type': 'object', ++ }, ++ 'supported_on': ['chrome_os:29-'], ++ 'features': { ++ 'can_be_recommended': True, ++ 'dynamic_refresh': True, ++ }, ++ 'example_value': True, ++ 'caption': '''%s''', ++ 'tags': [], ++ 'desc': '''This policy does stuff.''' ++ }, ++ ], ++ "policy_atomic_group_definitions": [], ++ "placeholders": [], ++ "messages": { ++ 'message_string_id': { ++ 'desc': '''The description is removed from the grit output''', ++ 'text': '''%s''' ++ } ++ } ++ }""" % (schema_key_description, caption, message) ++ ++ # Create translations. The translation IDs are hashed from the English text. ++ caption_id = grit.extern.tclib.GenerateMessageId(caption); ++ message_id = grit.extern.tclib.GenerateMessageId(message); ++ schema_key_description_id = grit.extern.tclib.GenerateMessageId( ++ schema_key_description) ++ policy_xtb = """ ++<?xml version="1.0" ?> ++<!DOCTYPE translationbundle> ++<translationbundle lang="de"> ++<translation id="%s">%s</translation> ++<translation id="%s">%s</translation> ++<translation id="%s">%s</translation> ++</translationbundle>""" % (caption_id, caption_translation, ++ message_id, message_translation, ++ schema_key_description_id, ++ schema_key_description_translation) ++ ++ # Write both to a temp file. ++ tmp_dir_name = tempfile.gettempdir() ++ ++ json_file_path = os.path.join(tmp_dir_name, 'test.json') ++ with open(json_file_path, 'w') as f: ++ f.write(policy_json.strip()) ++ ++ xtb_file_path = os.path.join(tmp_dir_name, 'test.xtb') ++ with open(xtb_file_path, 'w') as f: ++ f.write(policy_xtb.strip()) ++ ++ # Assemble a test grit tree, similar to policy_templates.grd. ++ grd_text = ''' ++ <grit base_dir="." latest_public_release="0" current_release="1" source_lang_id="en"> ++ <translations> ++ <file path="%s" lang="de" /> ++ </translations> ++ <release seq="1"> ++ <structures> ++ <structure name="IDD_POLICY_SOURCE_FILE" file="%s" type="policy_template_metafile" /> ++ </structures> ++ </release> ++ </grit>''' % (xtb_file_path, json_file_path) ++ grd_string_io = StringIO(grd_text) ++ ++ # Parse the grit tree and load the policies' JSON with a gatherer. ++ grd = grd_reader.Parse(grd_string_io, dir=tmp_dir_name, defines={'_google_chrome': True}) ++ grd.SetOutputLanguage('en') ++ grd.RunGatherers() ++ ++ # Remove the temp files. ++ os.unlink(xtb_file_path) ++ os.unlink(json_file_path) ++ ++ # Run grit with en->de translation. ++ env_lang = 'en' ++ out_lang = 'de' ++ env_defs = {'_google_chrome': '1'} ++ ++ grd.SetOutputLanguage(env_lang) ++ grd.SetDefines(env_defs) ++ buf = StringIO() ++ build.RcBuilder.ProcessNode(grd, DummyOutput('policy_templates', out_lang), buf) ++ output = buf.getvalue() ++ ++ # Caption and message texts get taken from xtb. ++ # desc is 'translated' to some pseudo-English ++ # 'ThïPïs pôPôlïPïcýPý dôéPôés stüPüff'. ++ expected = u"""{ ++ "policy_definitions": [ ++ { ++ "caption": "%s", ++ "desc": "Th\xefP\xefs p\xf4P\xf4l\xefP\xefc\xfdP\xfd d\xf4\xe9P\xf4\xe9s st\xfcP\xfcff.", ++ "example_value": true, ++ "features": {"can_be_recommended": true, "dynamic_refresh": true}, ++ "name": "MainPolicy", ++ "owners": ["foo@bar.com"], ++ "schema": { ++ "properties": { ++ "default_launch_container": { ++ "enum": [ ++ "tab", ++ "window" ++ ], ++ "type": "string" ++ }, ++ "users_number": { ++ "description": "%s", ++ "type": "integer" ++ } ++ }, ++ "type": "object" ++ }, ++ "supported_on": ["chrome_os:29-"], ++ "tags": [], ++ "type": "main" ++ } ++ ], ++ "policy_atomic_group_definitions": [ ++ ], ++ "messages": { ++ "message_string_id": { ++ "text": "%s" ++ } + } + -+ // Makes sure there is a "virtual" keyword on virtual methods. -+ // -+ // Gmock objects trigger these for each MOCK_BLAH() macro used. So we have a -+ // trick to get around that. If a class has member variables whose types are -+ // in the "testing" namespace (which is how gmock works behind the scenes), -+ // there's a really high chance we won't care about these errors -+ void CheckVirtualMethods(SourceLocation record_location, -+ CXXRecordDecl* record, -+ bool warn_on_inline_bodies) { -+ for (CXXRecordDecl::field_iterator it = record->field_begin(); -+ it != record->field_end(); ++it) { -+ CXXRecordDecl* record_type = -+ it->getTypeSourceInfo()->getTypeLoc().getTypePtr()-> -+ getAsCXXRecordDecl(); -+ if (record_type) { -+ if (InTestingNamespace(record_type)) { -+ return; -+ } ++}""" % (caption_translation, schema_key_description_translation, ++ message_translation) ++ self.assertEqual(expected, output) ++ ++ ++class DummyOutput(object): ++ ++ def __init__(self, type, language): ++ self.type = type ++ self.language = language ++ ++ def GetType(self): ++ return self.type ++ ++ def GetLanguage(self): ++ return self.language ++ ++ def GetOutputFilename(self): ++ return 'hello.gif' +diff --git a/tools/grit/grit/format/rc.py b/tools/grit/grit/format/rc.py +new file mode 100644 +index 0000000000..ed32bb809e +--- /dev/null ++++ b/tools/grit/grit/format/rc.py +@@ -0,0 +1,474 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Support for formatting an RC file for compilation. ++''' ++ ++from __future__ import print_function ++ ++import os ++import re ++from functools import partial ++ ++import six ++ ++from grit import util ++from grit.node import misc ++ ++ ++def Format(root, lang='en', output_dir='.'): ++ from grit.node import empty, include, message, structure ++ ++ yield _FormatHeader(root, lang, output_dir) ++ ++ for item in root.ActiveDescendants(): ++ if isinstance(item, empty.MessagesNode): ++ # Write one STRINGTABLE per <messages> container. ++ # This is hacky: it iterates over the children twice. ++ yield 'STRINGTABLE\nBEGIN\n' ++ for subitem in item.ActiveDescendants(): ++ if isinstance(subitem, message.MessageNode): ++ with subitem: ++ yield FormatMessage(subitem, lang) ++ yield 'END\n\n' ++ elif isinstance(item, include.IncludeNode): ++ with item: ++ yield FormatInclude(item, lang, output_dir) ++ elif isinstance(item, structure.StructureNode): ++ with item: ++ yield FormatStructure(item, lang, output_dir) ++ ++ ++''' ++This dictionary defines the language charset pair lookup table, which is used ++for replacing the GRIT expand variables for language info in Product Version ++resource. The key is the language ISO country code, and the value ++is the language and character-set pair, which is a hexadecimal string ++consisting of the concatenation of the language and character-set identifiers. ++The first 4 digit of the value is the hex value of LCID, the remaining ++4 digits is the hex value of character-set id(code page)of the language. ++ ++LCID resource: http://msdn.microsoft.com/en-us/library/ms776294.aspx ++Codepage resource: http://www.science.co.il/language/locale-codes.asp ++ ++We have defined three GRIT expand_variables to be used in the version resource ++file to set the language info. Here is an example how they should be used in ++the VS_VERSION_INFO section of the resource file to allow GRIT to localize ++the language info correctly according to product locale. ++ ++VS_VERSION_INFO VERSIONINFO ++... ++BEGIN ++ BLOCK "StringFileInfo" ++ BEGIN ++ BLOCK "[GRITVERLANGCHARSETHEX]" ++ BEGIN ++ ... ++ END ++ END ++ BLOCK "VarFileInfo" ++ BEGIN ++ VALUE "Translation", [GRITVERLANGID], [GRITVERCHARSETID] ++ END ++END ++ ++''' ++ ++_LANGUAGE_CHARSET_PAIR = { ++ # Language neutral LCID, unicode(1200) code page. ++ 'neutral' : '000004b0', ++ # LANG_USER_DEFAULT LCID, unicode(1200) code page. ++ 'userdefault' : '040004b0', ++ 'ar' : '040104e8', ++ 'fi' : '040b04e4', ++ 'ko' : '041203b5', ++ 'es' : '0c0a04e4', ++ 'bg' : '040204e3', ++ # No codepage for filipino, use unicode(1200). ++ 'fil' : '046404e4', ++ 'fr' : '040c04e4', ++ 'lv' : '042604e9', ++ 'sv' : '041d04e4', ++ 'ca' : '040304e4', ++ 'de' : '040704e4', ++ 'lt' : '042704e9', ++ # Do not use! This is only around for backwards ++ # compatibility and will be removed - use fil instead ++ 'tl' : '0c0004b0', ++ 'zh-CN' : '080403a8', ++ 'zh-TW' : '040403b6', ++ 'zh-HK' : '0c0403b6', ++ 'el' : '040804e5', ++ 'no' : '001404e4', ++ 'nb' : '041404e4', ++ 'nn' : '081404e4', ++ 'th' : '041e036a', ++ 'he' : '040d04e7', ++ 'iw' : '040d04e7', ++ 'pl' : '041504e2', ++ 'tr' : '041f04e6', ++ 'hr' : '041a04e4', ++ # No codepage for Hindi, use unicode(1200). ++ 'hi' : '043904b0', ++ 'pt-PT' : '081604e4', ++ 'pt-BR' : '041604e4', ++ 'uk' : '042204e3', ++ 'cs' : '040504e2', ++ 'hu' : '040e04e2', ++ 'ro' : '041804e2', ++ # No codepage for Urdu, use unicode(1200). ++ 'ur' : '042004b0', ++ 'da' : '040604e4', ++ 'is' : '040f04e4', ++ 'ru' : '041904e3', ++ 'vi' : '042a04ea', ++ 'nl' : '041304e4', ++ 'id' : '042104e4', ++ 'sr' : '081a04e2', ++ 'en-GB' : '0809040e', ++ 'it' : '041004e4', ++ 'sk' : '041b04e2', ++ 'et' : '042504e9', ++ 'ja' : '041103a4', ++ 'sl' : '042404e2', ++ 'en' : '040904b0', ++ # LCID for Mexico; Windows does not support L.A. LCID. ++ 'es-419' : '080a04e4', ++ # No codepage for Bengali, use unicode(1200). ++ 'bn' : '044504b0', ++ 'fa' : '042904e8', ++ # No codepage for Gujarati, use unicode(1200). ++ 'gu' : '044704b0', ++ # No codepage for Kannada, use unicode(1200). ++ 'kn' : '044b04b0', ++ # Malay (Malaysia) [ms-MY] ++ 'ms' : '043e04e4', ++ # No codepage for Malayalam, use unicode(1200). ++ 'ml' : '044c04b0', ++ # No codepage for Marathi, use unicode(1200). ++ 'mr' : '044e04b0', ++ # No codepage for Oriya , use unicode(1200). ++ 'or' : '044804b0', ++ # No codepage for Tamil, use unicode(1200). ++ 'ta' : '044904b0', ++ # No codepage for Telugu, use unicode(1200). ++ 'te' : '044a04b0', ++ # No codepage for Amharic, use unicode(1200). >= Vista. ++ 'am' : '045e04b0', ++ 'sw' : '044104e4', ++ 'af' : '043604e4', ++ 'eu' : '042d04e4', ++ 'fr-CA' : '0c0c04e4', ++ 'gl' : '045604e4', ++ # No codepage for Zulu, use unicode(1200). ++ 'zu' : '043504b0', ++ 'fake-bidi' : '040d04e7', ++} ++ ++# Language ID resource: http://msdn.microsoft.com/en-us/library/ms776294.aspx ++# ++# There is no appropriate sublang for Spanish (Latin America) [es-419], so we ++# use Mexico. SUBLANG_DEFAULT would incorrectly map to Spain. Unlike other ++# Latin American countries, Mexican Spanish is supported by VERSIONINFO: ++# http://msdn.microsoft.com/en-us/library/aa381058.aspx ++ ++_LANGUAGE_DIRECTIVE_PAIR = { ++ 'neutral' : 'LANG_NEUTRAL, SUBLANG_NEUTRAL', ++ 'userdefault' : 'LANG_NEUTRAL, SUBLANG_DEFAULT', ++ 'ar' : 'LANG_ARABIC, SUBLANG_DEFAULT', ++ 'fi' : 'LANG_FINNISH, SUBLANG_DEFAULT', ++ 'ko' : 'LANG_KOREAN, SUBLANG_KOREAN', ++ 'es' : 'LANG_SPANISH, SUBLANG_SPANISH_MODERN', ++ 'bg' : 'LANG_BULGARIAN, SUBLANG_DEFAULT', ++ # LANG_FILIPINO (100) not in VC 7 winnt.h. ++ 'fil' : '100, SUBLANG_DEFAULT', ++ 'fr' : 'LANG_FRENCH, SUBLANG_FRENCH', ++ 'lv' : 'LANG_LATVIAN, SUBLANG_DEFAULT', ++ 'sv' : 'LANG_SWEDISH, SUBLANG_SWEDISH', ++ 'ca' : 'LANG_CATALAN, SUBLANG_DEFAULT', ++ 'de' : 'LANG_GERMAN, SUBLANG_GERMAN', ++ 'lt' : 'LANG_LITHUANIAN, SUBLANG_LITHUANIAN', ++ # Do not use! See above. ++ 'tl' : 'LANG_NEUTRAL, SUBLANG_DEFAULT', ++ 'zh-CN' : 'LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED', ++ 'zh-TW' : 'LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL', ++ 'zh-HK' : 'LANG_CHINESE, SUBLANG_CHINESE_HONGKONG', ++ 'el' : 'LANG_GREEK, SUBLANG_DEFAULT', ++ 'no' : 'LANG_NORWEGIAN, SUBLANG_DEFAULT', ++ 'nb' : 'LANG_NORWEGIAN, SUBLANG_NORWEGIAN_BOKMAL', ++ 'nn' : 'LANG_NORWEGIAN, SUBLANG_NORWEGIAN_NYNORSK', ++ 'th' : 'LANG_THAI, SUBLANG_DEFAULT', ++ 'he' : 'LANG_HEBREW, SUBLANG_DEFAULT', ++ 'iw' : 'LANG_HEBREW, SUBLANG_DEFAULT', ++ 'pl' : 'LANG_POLISH, SUBLANG_DEFAULT', ++ 'tr' : 'LANG_TURKISH, SUBLANG_DEFAULT', ++ 'hr' : 'LANG_CROATIAN, SUBLANG_DEFAULT', ++ 'hi' : 'LANG_HINDI, SUBLANG_DEFAULT', ++ 'pt-PT' : 'LANG_PORTUGUESE, SUBLANG_PORTUGUESE', ++ 'pt-BR' : 'LANG_PORTUGUESE, SUBLANG_DEFAULT', ++ 'uk' : 'LANG_UKRAINIAN, SUBLANG_DEFAULT', ++ 'cs' : 'LANG_CZECH, SUBLANG_DEFAULT', ++ 'hu' : 'LANG_HUNGARIAN, SUBLANG_DEFAULT', ++ 'ro' : 'LANG_ROMANIAN, SUBLANG_DEFAULT', ++ 'ur' : 'LANG_URDU, SUBLANG_DEFAULT', ++ 'da' : 'LANG_DANISH, SUBLANG_DEFAULT', ++ 'is' : 'LANG_ICELANDIC, SUBLANG_DEFAULT', ++ 'ru' : 'LANG_RUSSIAN, SUBLANG_DEFAULT', ++ 'vi' : 'LANG_VIETNAMESE, SUBLANG_DEFAULT', ++ 'nl' : 'LANG_DUTCH, SUBLANG_DEFAULT', ++ 'id' : 'LANG_INDONESIAN, SUBLANG_DEFAULT', ++ 'sr' : 'LANG_SERBIAN, SUBLANG_SERBIAN_LATIN', ++ 'en-GB' : 'LANG_ENGLISH, SUBLANG_ENGLISH_UK', ++ 'it' : 'LANG_ITALIAN, SUBLANG_DEFAULT', ++ 'sk' : 'LANG_SLOVAK, SUBLANG_DEFAULT', ++ 'et' : 'LANG_ESTONIAN, SUBLANG_DEFAULT', ++ 'ja' : 'LANG_JAPANESE, SUBLANG_DEFAULT', ++ 'sl' : 'LANG_SLOVENIAN, SUBLANG_DEFAULT', ++ 'en' : 'LANG_ENGLISH, SUBLANG_ENGLISH_US', ++ # No L.A. sublang exists. ++ 'es-419' : 'LANG_SPANISH, SUBLANG_SPANISH_MEXICAN', ++ 'bn' : 'LANG_BENGALI, SUBLANG_DEFAULT', ++ 'fa' : 'LANG_PERSIAN, SUBLANG_DEFAULT', ++ 'gu' : 'LANG_GUJARATI, SUBLANG_DEFAULT', ++ 'kn' : 'LANG_KANNADA, SUBLANG_DEFAULT', ++ 'ms' : 'LANG_MALAY, SUBLANG_DEFAULT', ++ 'ml' : 'LANG_MALAYALAM, SUBLANG_DEFAULT', ++ 'mr' : 'LANG_MARATHI, SUBLANG_DEFAULT', ++ 'or' : 'LANG_ORIYA, SUBLANG_DEFAULT', ++ 'ta' : 'LANG_TAMIL, SUBLANG_DEFAULT', ++ 'te' : 'LANG_TELUGU, SUBLANG_DEFAULT', ++ 'am' : 'LANG_AMHARIC, SUBLANG_DEFAULT', ++ 'sw' : 'LANG_SWAHILI, SUBLANG_DEFAULT', ++ 'af' : 'LANG_AFRIKAANS, SUBLANG_DEFAULT', ++ 'eu' : 'LANG_BASQUE, SUBLANG_DEFAULT', ++ 'fr-CA' : 'LANG_FRENCH, SUBLANG_FRENCH_CANADIAN', ++ 'gl' : 'LANG_GALICIAN, SUBLANG_DEFAULT', ++ 'zu' : 'LANG_ZULU, SUBLANG_DEFAULT', ++ 'pa' : 'LANG_PUNJABI, SUBLANG_PUNJABI_INDIA', ++ 'sa' : 'LANG_SANSKRIT, SUBLANG_SANSKRIT_INDIA', ++ 'si' : 'LANG_SINHALESE, SUBLANG_SINHALESE_SRI_LANKA', ++ 'ne' : 'LANG_NEPALI, SUBLANG_NEPALI_NEPAL', ++ 'ti' : 'LANG_TIGRIGNA, SUBLANG_TIGRIGNA_ERITREA', ++ 'fake-bidi' : 'LANG_HEBREW, SUBLANG_DEFAULT', ++} ++ ++# A note on 'no-specific-language' in the following few functions: ++# Some build systems may wish to call GRIT to scan for dependencies in ++# a language-agnostic way, and can then specify this fake language as ++# the output context. It should never be used when output is actually ++# being generated. ++ ++def GetLangCharsetPair(language): ++ if language in _LANGUAGE_CHARSET_PAIR: ++ return _LANGUAGE_CHARSET_PAIR[language] ++ if language != 'no-specific-language': ++ print('Warning:GetLangCharsetPair() found undefined language %s' % language) ++ return '' ++ ++def GetLangDirectivePair(language): ++ if language in _LANGUAGE_DIRECTIVE_PAIR: ++ return _LANGUAGE_DIRECTIVE_PAIR[language] ++ ++ # We don't check for 'no-specific-language' here because this ++ # function should only get called when output is being formatted, ++ # and at that point we would not want to get ++ # 'no-specific-language' passed as the language. ++ print('Warning:GetLangDirectivePair() found undefined language %s' % language) ++ return 'unknown language: see tools/grit/format/rc.py' ++ ++def GetLangIdHex(language): ++ if language in _LANGUAGE_CHARSET_PAIR: ++ langcharset = _LANGUAGE_CHARSET_PAIR[language] ++ lang_id = '0x' + langcharset[0:4] ++ return lang_id ++ if language != 'no-specific-language': ++ print('Warning:GetLangIdHex() found undefined language %s' % language) ++ return '' ++ ++ ++def GetCharsetIdDecimal(language): ++ if language in _LANGUAGE_CHARSET_PAIR: ++ langcharset = _LANGUAGE_CHARSET_PAIR[language] ++ charset_decimal = int(langcharset[4:], 16) ++ return str(charset_decimal) ++ if language != 'no-specific-language': ++ print('Warning:GetCharsetIdDecimal() found undefined language %s' % language) ++ return '' ++ ++ ++def GetUnifiedLangCode(language) : ++ r = re.compile('([a-z]{1,2})_([a-z]{1,2})') ++ if r.match(language) : ++ underscore = language.find('_') ++ return language[0:underscore] + '-' + language[underscore + 1:].upper() ++ return language ++ ++ ++def RcSubstitutions(substituter, lang): ++ '''Add language-based substitutions for Rc files to the substitutor.''' ++ unified_lang_code = GetUnifiedLangCode(lang) ++ substituter.AddSubstitutions({ ++ 'GRITVERLANGCHARSETHEX': GetLangCharsetPair(unified_lang_code), ++ 'GRITVERLANGID': GetLangIdHex(unified_lang_code), ++ 'GRITVERCHARSETID': GetCharsetIdDecimal(unified_lang_code)}) ++ ++ ++def _FormatHeader(root, lang, output_dir): ++ '''Returns the required preamble for RC files.''' ++ assert isinstance(lang, six.string_types) ++ assert isinstance(root, misc.GritNode) ++ # Find the location of the resource header file, so that we can include ++ # it. ++ resource_header = 'resource.h' # fall back to this ++ language_directive = '' ++ for output in root.GetOutputFiles(): ++ if output.attrs['type'] == 'rc_header': ++ resource_header = os.path.abspath(output.GetOutputFilename()) ++ resource_header = util.MakeRelativePath(output_dir, resource_header) ++ if output.attrs['lang'] != lang: ++ continue ++ if output.attrs['language_section'] == '': ++ # If no language_section is requested, no directive is added ++ # (Used when the generated rc will be included from another rc ++ # file that will have the appropriate language directive) ++ language_directive = '' ++ elif output.attrs['language_section'] == 'neutral': ++ # If a neutral language section is requested (default), add a ++ # neutral language directive ++ language_directive = 'LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL' ++ elif output.attrs['language_section'] == 'lang': ++ language_directive = 'LANGUAGE %s' % GetLangDirectivePair(lang) ++ resource_header = resource_header.replace('\\', '\\\\') ++ return '''// This file is automatically generated by GRIT. Do not edit. ++ ++#include "%s" ++#include <winresrc.h> ++#ifdef IDC_STATIC ++#undef IDC_STATIC ++#endif ++#define IDC_STATIC (-1) ++ ++%s ++ ++ ++''' % (resource_header, language_directive) ++# end _FormatHeader() function ++ ++ ++def FormatMessage(item, lang): ++ '''Returns a single message of a string table.''' ++ message = item.ws_at_start + item.Translate(lang) + item.ws_at_end ++ # Escape quotation marks (RC format uses doubling-up ++ message = message.replace('"', '""') ++ # Replace linebreaks with a \n escape ++ message = util.LINEBREAKS.sub(r'\\n', message) ++ if hasattr(item.GetRoot(), 'GetSubstituter'): ++ substituter = item.GetRoot().GetSubstituter() ++ message = substituter.Substitute(message) ++ ++ name_attr = item.GetTextualIds()[0] ++ ++ return ' %-15s "%s"\n' % (name_attr, message) ++ ++ ++def _FormatSection(item, lang, output_dir): ++ '''Writes out an .rc file section.''' ++ assert isinstance(lang, six.string_types) ++ from grit.node import structure ++ assert isinstance(item, structure.StructureNode) ++ ++ if item.IsExcludedFromRc(): ++ return '' ++ ++ text = item.gatherer.Translate( ++ lang, skeleton_gatherer=item.GetSkeletonGatherer(), ++ pseudo_if_not_available=item.PseudoIsAllowed(), ++ fallback_to_english=item.ShouldFallbackToEnglish()) + '\n\n' ++ ++ # Replace the language expand_variables in version rc info. ++ if item.ExpandVariables() and hasattr(item.GetRoot(), 'GetSubstituter'): ++ substituter = item.GetRoot().GetSubstituter() ++ text = substituter.Substitute(text) ++ return text ++ ++ ++def FormatInclude(item, lang, output_dir, type=None, process_html=False): ++ '''Formats an item that is included in an .rc file (e.g. an ICON). ++ ++ Args: ++ item: an IncludeNode or StructureNode ++ lang, output_dir: standard formatter parameters ++ type: .rc file resource type, e.g. 'ICON' (ignored unless item is a ++ StructureNode) ++ process_html: False/True (ignored unless item is a StructureNode) ++ ''' ++ assert isinstance(lang, six.string_types) ++ from grit.node import structure ++ from grit.node import include ++ assert isinstance(item, (structure.StructureNode, include.IncludeNode)) ++ ++ if isinstance(item, include.IncludeNode): ++ type = item.attrs['type'].upper() ++ process_html = item.attrs['flattenhtml'] == 'true' ++ filename_only = item.attrs['filenameonly'] == 'true' ++ relative_path = item.attrs['relativepath'] == 'true' ++ else: ++ assert (isinstance(item, structure.StructureNode) and item.attrs['type'] in ++ ['admin_template', 'chrome_html', 'chrome_scaled_image', ++ 'tr_html', 'txt']) ++ filename_only = False ++ relative_path = False ++ ++ # By default, we use relative pathnames to included resources so that ++ # sharing the resulting .rc files is possible. ++ # ++ # The FileForLanguage() Function has the side effect of generating the file ++ # if needed (e.g. if it is an HTML file include). ++ file_for_lang = item.FileForLanguage(lang, output_dir) ++ if file_for_lang is None: ++ return '' ++ ++ filename = os.path.abspath(file_for_lang) ++ if process_html: ++ filename = item.Process(output_dir) ++ elif filename_only: ++ filename = os.path.basename(filename) ++ elif relative_path: ++ filename = util.MakeRelativePath(output_dir, filename) ++ ++ filename = filename.replace('\\', '\\\\') # escape for the RC format ++ ++ if isinstance(item, structure.StructureNode) and item.IsExcludedFromRc(): ++ return '' ++ ++ name = item.attrs['name'] ++ item_id = item.GetRoot().GetIdMap()[name] ++ return '// ID: %d\n%-18s %-18s "%s"\n' % (item_id, name, type, filename) ++ ++ ++def _DoNotFormat(item, lang, output_dir): ++ return '' ++ ++ ++# Formatter instance to use for each type attribute ++# when formatting Structure nodes. ++_STRUCTURE_FORMATTERS = { ++ 'accelerators' : _FormatSection, ++ 'dialog' : _FormatSection, ++ 'menu' : _FormatSection, ++ 'rcdata' : _FormatSection, ++ 'version' : _FormatSection, ++ 'admin_template' : partial(FormatInclude, type='ADM'), ++ 'chrome_html' : partial(FormatInclude, type='BINDATA', ++ process_html=True), ++ 'chrome_scaled_image' : partial(FormatInclude, type='BINDATA'), ++ 'tr_html' : partial(FormatInclude, type='HTML'), ++ 'txt' : partial(FormatInclude, type='TXT'), ++ 'policy_template_metafile': _DoNotFormat, ++} ++ ++ ++def FormatStructure(item, lang, output_dir): ++ formatter = _STRUCTURE_FORMATTERS[item.attrs['type']] ++ return formatter(item, lang, output_dir) +diff --git a/tools/grit/grit/format/rc_header.py b/tools/grit/grit/format/rc_header.py +new file mode 100644 +index 0000000000..ea2c217f53 +--- /dev/null ++++ b/tools/grit/grit/format/rc_header.py +@@ -0,0 +1,48 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Item formatters for RC headers. ++''' ++ ++from __future__ import print_function ++ ++ ++def Format(root, lang='en', output_dir='.'): ++ yield '''\ ++// This file is automatically generated by GRIT. Do not edit. ++ ++#pragma once ++''' ++ # Check for emit nodes under the rc_header. If any emit node ++ # is present, we assume it means the GRD file wants to override ++ # the default header, with no includes. ++ default_includes = ['#include <atlres.h>', ''] ++ emit_lines = [] ++ for output_node in root.GetOutputFiles(): ++ if output_node.GetType() == 'rc_header': ++ for child in output_node.children: ++ if child.name == 'emit' and child.attrs['emit_type'] == 'prepend': ++ emit_lines.append(child.GetCdata()) ++ for line in emit_lines or default_includes: ++ yield line + '\n' ++ if root.IsWhitelistSupportEnabled(): ++ yield '#include "ui/base/resource/whitelist.h"\n' ++ for line in FormatDefines(root): ++ yield line ++ ++ ++def FormatDefines(root): ++ '''Yields #define SYMBOL 1234 lines. ++ ++ Args: ++ root: A GritNode. ++ ''' ++ tids = root.GetIdMap() ++ rc_header_format = '#define {0} {1}\n' ++ if root.IsWhitelistSupportEnabled(): ++ rc_header_format = '#define {0} (::ui::WhitelistedResource<{1}>(), {1})\n' ++ for item in root.ActiveDescendants(): ++ with item: ++ for tid in item.GetTextualIds(): ++ yield rc_header_format.format(tid, tids[tid]) +diff --git a/tools/grit/grit/format/rc_header_unittest.py b/tools/grit/grit/format/rc_header_unittest.py +new file mode 100644 +index 0000000000..eed4d70a99 +--- /dev/null ++++ b/tools/grit/grit/format/rc_header_unittest.py +@@ -0,0 +1,138 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for the rc_header formatter''' ++ ++# GRD samples exceed the 80 character limit. ++# pylint: disable-msg=C6310 ++ ++from __future__ import print_function ++ ++import os ++import sys ++import unittest ++ ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++from grit import util ++from grit.format import rc_header ++ ++ ++class RcHeaderFormatterUnittest(unittest.TestCase): ++ def FormatAll(self, grd): ++ output = rc_header.FormatDefines(grd) ++ return ''.join(output).replace(' ', '') ++ ++ def testFormatter(self): ++ grd = util.ParseGrdForUnittest(''' ++ <includes first_id="300" comment="bingo"> ++ <include type="gif" name="ID_LOGO" file="images/logo.gif" /> ++ </includes> ++ <messages first_id="10000"> ++ <message name="IDS_GREETING" desc="Printed to greet the currently logged in user"> ++ Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today? ++ </message> ++ <message name="IDS_BONGO"> ++ Bongo! ++ </message> ++ </messages> ++ <structures> ++ <structure type="dialog" name="IDD_NARROW_DIALOG" file="rc_files/dialogs.rc" /> ++ <structure type="version" name="VS_VERSION_INFO" file="rc_files/version.rc" /> ++ </structures>''') ++ output = self.FormatAll(grd) ++ self.failUnless(output.count('IDS_GREETING10000')) ++ self.failUnless(output.count('ID_LOGO300')) ++ ++ def testOnlyDefineResourcesThatSatisfyOutputCondition(self): ++ grd = util.ParseGrdForUnittest(''' ++ <includes first_id="300" comment="bingo"> ++ <include type="gif" name="ID_LOGO" file="images/logo.gif" /> ++ </includes> ++ <messages first_id="10000"> ++ <message name="IDS_FIRSTPRESENTSTRING" desc="Present in .rc file."> ++ I will appear in the .rc file. ++ </message> ++ <if expr="False"> <!--Do not include in the .rc files until used.--> ++ <message name="IDS_MISSINGSTRING" desc="Not present in .rc file."> ++ I will not appear in the .rc file. ++ </message> ++ </if> ++ <if expr="lang != 'es'"> ++ <message name="IDS_LANGUAGESPECIFICSTRING" desc="Present in .rc file."> ++ Hello. ++ </message> ++ </if> ++ <if expr="lang == 'es'"> ++ <message name="IDS_LANGUAGESPECIFICSTRING" desc="Present in .rc file."> ++ Hola. ++ </message> ++ </if> ++ <message name="IDS_THIRDPRESENTSTRING" desc="Present in .rc file."> ++ I will also appear in the .rc file. ++ </message> ++ </messages>''') ++ output = self.FormatAll(grd) ++ self.failUnless(output.count('IDS_FIRSTPRESENTSTRING10000')) ++ self.failIf(output.count('IDS_MISSINGSTRING')) ++ self.failUnless(output.count('IDS_LANGUAGESPECIFICSTRING10002')) ++ self.failUnless(output.count('IDS_THIRDPRESENTSTRING10003')) ++ ++ def testEmit(self): ++ grd = util.ParseGrdForUnittest(''' ++ <outputs> ++ <output type="rc_all" filename="dummy"> ++ <emit emit_type="prepend">Wrong</emit> ++ </output> ++ <if expr="False"> ++ <output type="rc_header" filename="dummy"> ++ <emit emit_type="prepend">No</emit> ++ </output> ++ </if> ++ <output type="rc_header" filename="dummy"> ++ <emit emit_type="append">Error</emit> ++ </output> ++ <output type="rc_header" filename="dummy"> ++ <emit emit_type="prepend">Bingo</emit> ++ </output> ++ </outputs>''') ++ output = ''.join(rc_header.Format(grd, 'en', '.')) ++ output = util.StripBlankLinesAndComments(output) ++ self.assertEqual('#pragma once\nBingo', output) ++ ++ def testRcHeaderFormat(self): ++ grd = util.ParseGrdForUnittest(''' ++ <includes first_id="300" comment="bingo"> ++ <include type="gif" name="IDR_LOGO" file="images/logo.gif" /> ++ </includes> ++ <messages first_id="10000"> ++ <message name="IDS_GREETING" desc="Printed to greet the currently logged in user"> ++ Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today? ++ </message> ++ <message name="IDS_BONGO"> ++ Bongo! ++ </message> ++ </messages>''') ++ ++ # Using the default settings. ++ output = rc_header.FormatDefines(grd) ++ self.assertEqual(('#define IDR_LOGO 300\n' ++ '#define IDS_GREETING 10000\n' ++ '#define IDS_BONGO 10001\n'), ''.join(output)) ++ ++ # Using resource whitelist support. ++ grd.SetWhitelistSupportEnabled(True) ++ output = rc_header.FormatDefines(grd) ++ self.assertEqual(('#define IDR_LOGO ' ++ '(::ui::WhitelistedResource<300>(), 300)\n' ++ '#define IDS_GREETING ' ++ '(::ui::WhitelistedResource<10000>(), 10000)\n' ++ '#define IDS_BONGO ' ++ '(::ui::WhitelistedResource<10001>(), 10001)\n'), ++ ''.join(output)) ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/format/rc_unittest.py b/tools/grit/grit/format/rc_unittest.py +new file mode 100644 +index 0000000000..d23f063596 +--- /dev/null ++++ b/tools/grit/grit/format/rc_unittest.py +@@ -0,0 +1,415 @@ ++#!/usr/bin/env python ++# Copyright (c) 2011 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for grit.format.rc''' ++ ++from __future__ import print_function ++ ++import os ++import re ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++import tempfile ++import unittest ++ ++from six import StringIO ++ ++from grit import grd_reader ++from grit import util ++from grit.node import structure ++from grit.tool import build ++ ++ ++_PREAMBLE = '''\ ++#include "resource.h" ++#include <winresrc.h> ++#ifdef IDC_STATIC ++#undef IDC_STATIC ++#endif ++#define IDC_STATIC (-1) ++''' ++ ++ ++class DummyOutput(object): ++ def __init__(self, type, language, file = 'hello.gif'): ++ self.type = type ++ self.language = language ++ self.file = file ++ ++ def GetType(self): ++ return self.type ++ ++ def GetLanguage(self): ++ return self.language ++ ++ def GetOutputFilename(self): ++ return self.file ++ ++ ++class FormatRcUnittest(unittest.TestCase): ++ def testMessages(self): ++ root = util.ParseGrdForUnittest(""" ++ <messages> ++ <message name="IDS_BTN_GO" desc="Button text" meaning="verb">Go!</message> ++ <message name="IDS_GREETING" desc="Printed to greet the currently logged in user"> ++ Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today? ++ </message> ++ <message name="BONGO" desc="Flippo nippo"> ++ Howdie "Mr. Elephant", how are you doing? ''' ++ </message> ++ <message name="IDS_WITH_LINEBREAKS"> ++Good day sir, ++I am a bee ++Sting sting ++ </message> ++ </messages> ++ """) ++ ++ buf = StringIO() ++ build.RcBuilder.ProcessNode(root, DummyOutput('rc_all', 'en'), buf) ++ output = util.StripBlankLinesAndComments(buf.getvalue()) ++ self.assertEqual(_PREAMBLE + u'''\ ++STRINGTABLE ++BEGIN ++ IDS_BTN_GO "Go!" ++ IDS_GREETING "Hello %s, how are you doing today?" ++ BONGO "Howdie ""Mr. Elephant"", how are you doing? " ++ IDS_WITH_LINEBREAKS "Good day sir,\\nI am a bee\\nSting sting" ++END''', output) ++ ++ def testRcSection(self): ++ root = util.ParseGrdForUnittest(r''' ++ <structures> ++ <structure type="menu" name="IDC_KLONKMENU" file="grit\testdata\klonk.rc" encoding="utf-16" /> ++ <structure type="dialog" name="IDD_ABOUTBOX" file="grit\testdata\klonk.rc" encoding="utf-16" /> ++ <structure type="version" name="VS_VERSION_INFO" file="grit\testdata\klonk.rc" encoding="utf-16" /> ++ </structures>''') ++ root.SetOutputLanguage('en') ++ root.RunGatherers() ++ ++ buf = StringIO() ++ build.RcBuilder.ProcessNode(root, DummyOutput('rc_all', 'en'), buf) ++ output = util.StripBlankLinesAndComments(buf.getvalue()) ++ expected = _PREAMBLE + u'''\ ++IDC_KLONKMENU MENU ++BEGIN ++ POPUP "&File" ++ BEGIN ++ MENUITEM "E&xit", IDM_EXIT ++ MENUITEM "This be ""Klonk"" me like", ID_FILE_THISBE ++ POPUP "gonk" ++ BEGIN ++ MENUITEM "Klonk && is [good]", ID_GONK_KLONKIS ++ END ++ END ++ POPUP "&Help" ++ BEGIN ++ MENUITEM "&About ...", IDM_ABOUT ++ END ++END ++ ++IDD_ABOUTBOX DIALOGEX 22, 17, 230, 75 ++STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU ++CAPTION "About" ++FONT 8, "System", 0, 0, 0x0 ++BEGIN ++ ICON IDI_KLONK,IDC_MYICON,14,9,20,20 ++ LTEXT "klonk Version ""yibbee"" 1.0",IDC_STATIC,49,10,119,8, ++ SS_NOPREFIX ++ LTEXT "Copyright (C) 2005",IDC_STATIC,49,20,119,8 ++ DEFPUSHBUTTON "OK",IDOK,195,6,30,11,WS_GROUP ++ CONTROL "Jack ""Black"" Daniels",IDC_RADIO1,"Button", ++ BS_AUTORADIOBUTTON,46,51,84,10 ++END ++ ++VS_VERSION_INFO VERSIONINFO ++ FILEVERSION 1,0,0,1 ++ PRODUCTVERSION 1,0,0,1 ++ FILEFLAGSMASK 0x17L ++#ifdef _DEBUG ++ FILEFLAGS 0x1L ++#else ++ FILEFLAGS 0x0L ++#endif ++ FILEOS 0x4L ++ FILETYPE 0x1L ++ FILESUBTYPE 0x0L ++BEGIN ++ BLOCK "StringFileInfo" ++ BEGIN ++ BLOCK "040904b0" ++ BEGIN ++ VALUE "FileDescription", "klonk Application" ++ VALUE "FileVersion", "1, 0, 0, 1" ++ VALUE "InternalName", "klonk" ++ VALUE "LegalCopyright", "Copyright (C) 2005" ++ VALUE "OriginalFilename", "klonk.exe" ++ VALUE "ProductName", " klonk Application" ++ VALUE "ProductVersion", "1, 0, 0, 1" ++ END ++ END ++ BLOCK "VarFileInfo" ++ BEGIN ++ VALUE "Translation", 0x409, 1200 ++ END ++END'''.strip() ++ for expected_line, output_line in zip(expected.split(), output.split()): ++ self.assertEqual(expected_line, output_line) ++ ++ def testRcIncludeStructure(self): ++ root = util.ParseGrdForUnittest(''' ++ <structures> ++ <structure type="tr_html" name="IDR_HTML" file="bingo.html"/> ++ <structure type="tr_html" name="IDR_HTML2" file="bingo2.html"/> ++ </structures>''', base_dir = '/temp') ++ # We do not run gatherers as it is not needed and wouldn't find the file ++ ++ buf = StringIO() ++ build.RcBuilder.ProcessNode(root, DummyOutput('rc_all', 'en'), buf) ++ output = util.StripBlankLinesAndComments(buf.getvalue()) ++ expected = (_PREAMBLE + ++ u'IDR_HTML HTML "%s"\n' ++ u'IDR_HTML2 HTML "%s"' ++ % (util.normpath('/temp/bingo.html').replace('\\', '\\\\'), ++ util.normpath('/temp/bingo2.html').replace('\\', '\\\\'))) ++ # hackety hack to work on win32&lin ++ output = re.sub(r'"[c-zC-Z]:', '"', output) ++ self.assertEqual(expected, output) ++ ++ def testRcIncludeFile(self): ++ root = util.ParseGrdForUnittest(''' ++ <includes> ++ <include type="TXT" name="TEXT_ONE" file="bingo.txt"/> ++ <include type="TXT" name="TEXT_TWO" file="bingo2.txt" filenameonly="true" /> ++ </includes>''', base_dir = '/temp') ++ ++ buf = StringIO() ++ build.RcBuilder.ProcessNode(root, DummyOutput('rc_all', 'en'), buf) ++ output = util.StripBlankLinesAndComments(buf.getvalue()) ++ expected = (_PREAMBLE + ++ u'TEXT_ONE TXT "%s"\n' ++ u'TEXT_TWO TXT "%s"' ++ % (util.normpath('/temp/bingo.txt').replace('\\', '\\\\'), ++ 'bingo2.txt')) ++ # hackety hack to work on win32&lin ++ output = re.sub(r'"[c-zC-Z]:', '"', output) ++ self.assertEqual(expected, output) ++ ++ def testRcIncludeFlattenedHtmlFile(self): ++ input_file = util.PathFromRoot('grit/testdata/include_test.html') ++ output_file = '%s/HTML_FILE1_include_test.html' % tempfile.gettempdir() ++ root = util.ParseGrdForUnittest(''' ++ <includes> ++ <include name="HTML_FILE1" flattenhtml="true" file="%s" type="BINDATA" /> ++ </includes>''' % input_file) ++ ++ buf = StringIO() ++ build.RcBuilder.ProcessNode(root, DummyOutput('rc_all', 'en', output_file), ++ buf) ++ output = util.StripBlankLinesAndComments(buf.getvalue()) ++ ++ expected = (_PREAMBLE + ++ u'HTML_FILE1 BINDATA "HTML_FILE1_include_test.html"') ++ # hackety hack to work on win32&lin ++ output = re.sub(r'"[c-zC-Z]:', '"', output) ++ self.assertEqual(expected, output) ++ ++ file_contents = util.ReadFile(output_file, 'utf-8') ++ ++ # Check for the content added by the <include> tag. ++ self.failUnless(file_contents.find('Hello Include!') != -1) ++ # Check for the content that was removed by if tag. ++ self.failUnless(file_contents.find('should be removed') == -1) ++ # Check for the content that was kept in place by if. ++ self.failUnless(file_contents.find('should be kept') != -1) ++ self.failUnless(file_contents.find('in the middle...') != -1) ++ self.failUnless(file_contents.find('at the end...') != -1) ++ # Check for nested content that was kept ++ self.failUnless(file_contents.find('nested true should be kept') != -1) ++ self.failUnless(file_contents.find('silbing true should be kept') != -1) ++ # Check for removed "<if>" and "</if>" tags. ++ self.failUnless(file_contents.find('<if expr=') == -1) ++ self.failUnless(file_contents.find('</if>') == -1) ++ os.remove(output_file) ++ ++ def testStructureNodeOutputfile(self): ++ input_file = util.PathFromRoot('grit/testdata/simple.html') ++ root = util.ParseGrdForUnittest(''' ++ <structures> ++ <structure type="tr_html" name="IDR_HTML" file="%s" /> ++ </structures>''' % input_file) ++ struct, = root.GetChildrenOfType(structure.StructureNode) ++ # We must run the gatherer since we'll be wanting the translation of the ++ # file. The file exists in the location pointed to. ++ root.SetOutputLanguage('en') ++ root.RunGatherers() ++ ++ output_dir = tempfile.gettempdir() ++ en_file = struct.FileForLanguage('en', output_dir) ++ self.failUnless(en_file == input_file) ++ fr_file = struct.FileForLanguage('fr', output_dir) ++ self.failUnless(fr_file == os.path.join(output_dir, 'fr_simple.html')) ++ ++ contents = util.ReadFile(fr_file, 'utf-8') ++ ++ self.failUnless(contents.find('<p>') != -1) # should contain the markup ++ self.failUnless(contents.find('Hello!') == -1) # should be translated ++ os.remove(fr_file) ++ ++ def testChromeHtmlNodeOutputfile(self): ++ input_file = util.PathFromRoot('grit/testdata/chrome_html.html') ++ output_file = '%s/HTML_FILE1_chrome_html.html' % tempfile.gettempdir() ++ root = util.ParseGrdForUnittest(''' ++ <structures> ++ <structure type="chrome_html" name="HTML_FILE1" file="%s" flattenhtml="true" /> ++ </structures>''' % input_file) ++ struct, = root.GetChildrenOfType(structure.StructureNode) ++ struct.gatherer.SetDefines({'scale_factors': '2x'}) ++ # We must run the gatherers since we'll be wanting the chrome_html output. ++ # The file exists in the location pointed to. ++ root.SetOutputLanguage('en') ++ root.RunGatherers() ++ ++ buf = StringIO() ++ build.RcBuilder.ProcessNode(root, DummyOutput('rc_all', 'en', output_file), ++ buf) ++ output = util.StripBlankLinesAndComments(buf.getvalue()) ++ expected = (_PREAMBLE + ++ u'HTML_FILE1 BINDATA "HTML_FILE1_chrome_html.html"') ++ # hackety hack to work on win32&lin ++ output = re.sub(r'"[c-zC-Z]:', '"', output) ++ self.assertEqual(expected, output) ++ ++ file_contents = util.ReadFile(output_file, 'utf-8') ++ ++ # Check for the content added by the <include> tag. ++ self.failUnless(file_contents.find('Hello Include!') != -1) ++ # Check for inserted -webkit-image-set. ++ self.failUnless(file_contents.find('content: -webkit-image-set') != -1) ++ os.remove(output_file) ++ ++ def testSubstitutionHtml(self): ++ input_file = util.PathFromRoot('grit/testdata/toolbar_about.html') ++ root = grd_reader.Parse(StringIO('''<?xml version="1.0" encoding="UTF-8"?> ++ <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <release seq="1" allow_pseudo="False"> ++ <structures fallback_to_english="True"> ++ <structure type="tr_html" name="IDR_HTML" file="%s" expand_variables="true"/> ++ </structures> ++ </release> ++ </grit> ++ ''' % input_file), util.PathFromRoot('.')) ++ root.SetOutputLanguage('ar') ++ # We must run the gatherers since we'll be wanting the translation of the ++ # file. The file exists in the location pointed to. ++ root.RunGatherers() ++ ++ output_dir = tempfile.gettempdir() ++ struct, = root.GetChildrenOfType(structure.StructureNode) ++ ar_file = struct.FileForLanguage('ar', output_dir) ++ self.failUnless(ar_file == os.path.join(output_dir, ++ 'ar_toolbar_about.html')) ++ ++ contents = util.ReadFile(ar_file, 'utf-8') ++ ++ self.failUnless(contents.find('dir="RTL"') != -1) ++ os.remove(ar_file) ++ ++ def testFallbackToEnglish(self): ++ root = util.ParseGrdForUnittest(r''' ++ <structures fallback_to_english="True"> ++ <structure type="dialog" name="IDD_ABOUTBOX" file="grit\testdata\klonk.rc" encoding="utf-16" /> ++ </structures>''', base_dir=util.PathFromRoot('.')) ++ root.SetOutputLanguage('en') ++ root.RunGatherers() ++ ++ buf = StringIO() ++ formatter = build.RcBuilder.ProcessNode( ++ root, DummyOutput('rc_all', 'bingobongo'), buf) ++ output = util.StripBlankLinesAndComments(buf.getvalue()) ++ self.assertEqual(_PREAMBLE + '''\ ++IDD_ABOUTBOX DIALOGEX 22, 17, 230, 75 ++STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU ++CAPTION "About" ++FONT 8, "System", 0, 0, 0x0 ++BEGIN ++ ICON IDI_KLONK,IDC_MYICON,14,9,20,20 ++ LTEXT "klonk Version ""yibbee"" 1.0",IDC_STATIC,49,10,119,8, ++ SS_NOPREFIX ++ LTEXT "Copyright (C) 2005",IDC_STATIC,49,20,119,8 ++ DEFPUSHBUTTON "OK",IDOK,195,6,30,11,WS_GROUP ++ CONTROL "Jack ""Black"" Daniels",IDC_RADIO1,"Button", ++ BS_AUTORADIOBUTTON,46,51,84,10 ++END''', output) ++ ++ ++ def testSubstitutionRc(self): ++ root = grd_reader.Parse(StringIO(r'''<?xml version="1.0" encoding="UTF-8"?> ++ <grit latest_public_release="2" source_lang_id="en-US" current_release="3" ++ base_dir="."> ++ <outputs> ++ <output lang="en" type="rc_all" filename="grit\testdata\klonk_resources.rc"/> ++ </outputs> ++ <release seq="1" allow_pseudo="False"> ++ <structures> ++ <structure type="menu" name="IDC_KLONKMENU" ++ file="grit\testdata\klonk.rc" encoding="utf-16" ++ expand_variables="true" /> ++ </structures> ++ <messages> ++ <message name="good" sub_variable="true"> ++ excellent ++ </message> ++ </messages> ++ </release> ++ </grit> ++ '''), util.PathFromRoot('.')) ++ root.SetOutputLanguage('en') ++ root.RunGatherers() ++ ++ buf = StringIO() ++ build.RcBuilder.ProcessNode(root, DummyOutput('rc_all', 'en'), buf) ++ output = buf.getvalue() ++ self.assertEqual(''' ++// This file is automatically generated by GRIT. Do not edit. ++ ++#include "resource.h" ++#include <winresrc.h> ++#ifdef IDC_STATIC ++#undef IDC_STATIC ++#endif ++#define IDC_STATIC (-1) ++ ++LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL ++ ++ ++IDC_KLONKMENU MENU ++BEGIN ++ POPUP "&File" ++ BEGIN ++ MENUITEM "E&xit", IDM_EXIT ++ MENUITEM "This be ""Klonk"" me like", ID_FILE_THISBE ++ POPUP "gonk" ++ BEGIN ++ MENUITEM "Klonk && is excellent", ID_GONK_KLONKIS ++ END ++ END ++ POPUP "&Help" ++ BEGIN ++ MENUITEM "&About ...", IDM_ABOUT ++ END ++END ++ ++STRINGTABLE ++BEGIN ++ good "excellent" ++END ++'''.strip(), output.strip()) ++ ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/format/resource_map.py b/tools/grit/grit/format/resource_map.py +new file mode 100644 +index 0000000000..95a8b83160 +--- /dev/null ++++ b/tools/grit/grit/format/resource_map.py +@@ -0,0 +1,159 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''This file contains item formatters for resource_map_header and ++resource_map_source files. A resource map is a mapping between resource names ++(string) and the internal resource ID.''' ++ ++from __future__ import print_function ++ ++import os ++from functools import partial ++ ++from grit import util ++ ++ ++def GetFormatter(type): ++ if type == 'resource_map_header': ++ return _FormatHeader ++ if type == 'resource_file_map_source': ++ return partial(_FormatSource, _GetItemPath) ++ if type == 'resource_map_source': ++ return partial(_FormatSource, _GetItemName) ++ ++ ++def GetMapName(root): ++ '''Get the name of the resource map based on the header file name. E.g., ++ if our header filename is theme_resources.h, we name our resource map ++ kThemeResourcesMap. ++ ++ |root| is the grd file root.''' ++ outputs = root.GetOutputFiles() ++ rc_header_file = None ++ for output in outputs: ++ if 'rc_header' == output.GetType(): ++ rc_header_file = output.GetFilename() ++ if not rc_header_file: ++ raise Exception('unable to find resource header filename') ++ filename = os.path.splitext(os.path.split(rc_header_file)[1])[0] ++ filename = filename[0].upper() + filename[1:] ++ while True: ++ pos = filename.find('_') ++ if pos == -1 or pos >= len(filename): ++ break ++ filename = filename[:pos] + filename[pos + 1].upper() + filename[pos + 2:] ++ return 'k' + filename ++ ++ ++def _FormatHeader(root, lang='en', output_dir='.'): ++ '''Create the header file for the resource mapping. This file just declares ++ an array of name/value pairs.''' ++ return '''\ ++// This file is automatically generated by GRIT. Do not edit. ++ ++#include <stddef.h> ++ ++#ifndef GRIT_RESOURCE_MAP_STRUCT_ ++#define GRIT_RESOURCE_MAP_STRUCT_ ++struct GritResourceMap { ++ const char* const name; ++ int value; ++}; ++#endif // GRIT_RESOURCE_MAP_STRUCT_ ++ ++extern const GritResourceMap %(map_name)s[]; ++extern const size_t %(map_name)sSize; ++''' % { 'map_name': GetMapName(root) } ++ ++ ++def _FormatSourceHeader(root, output_dir): ++ '''Create the header of the C++ source file for the resource mapping.''' ++ rc_header_file = None ++ map_header_file = None ++ for output in root.GetOutputFiles(): ++ type = output.GetType() ++ if 'rc_header' == type: ++ rc_header_file = util.MakeRelativePath(output_dir, ++ output.GetOutputFilename()) ++ elif 'resource_map_header' == type: ++ map_header_file = util.MakeRelativePath(output_dir, ++ output.GetOutputFilename()) ++ if not rc_header_file or not map_header_file: ++ raise Exception('resource_map_source output type requires ' ++ 'a resource_map_header and rc_header outputs') ++ return '''\ ++// This file is automatically generated by GRIT. Do not edit. ++ ++#include "%(map_header_file)s" ++ ++#include <stddef.h> ++ ++#include "base/stl_util.h" ++ ++#include "%(rc_header_file)s" ++ ++const GritResourceMap %(map_name)s[] = { ++''' % { 'map_header_file': map_header_file, ++ 'rc_header_file': rc_header_file, ++ 'map_name': GetMapName(root), + } -+ } + -+ for (CXXRecordDecl::method_iterator it = record->method_begin(); -+ it != record->method_end(); ++it) { -+ if (it->isCopyAssignmentOperator() || isa<CXXConstructorDecl>(*it)) { -+ // Ignore constructors and assignment operators. -+ } else if (isa<CXXDestructorDecl>(*it) && -+ !record->hasUserDeclaredDestructor()) { -+ // Ignore non-user-declared destructors. -+ } else { -+ CheckVirtualMethod(*it, warn_on_inline_bodies); -+ CheckOverriddenMethod(*it); ++ ++def _FormatSourceFooter(root): ++ # Return the footer text. ++ return '''\ ++}; ++ ++const size_t %(map_name)sSize = base::size(%(map_name)s); ++''' % { 'map_name': GetMapName(root) } ++ ++ ++def _FormatSource(get_key, root, lang, output_dir): ++ from grit.node import include, structure, message ++ id_map = root.GetIdMap() ++ yield _FormatSourceHeader(root, output_dir) ++ seen = set() ++ for item in root.ActiveDescendants(): ++ if not item.IsResourceMapSource(): ++ continue ++ key = get_key(item) ++ tid = item.attrs['name'] ++ if tid not in id_map or key in seen: ++ continue ++ seen.add(key) ++ yield ' {"%s", %s},\n' % (key, tid) ++ yield _FormatSourceFooter(root) ++ ++ ++def _GetItemName(item): ++ return item.attrs['name'] ++ ++# Check if |path2| is a subpath of |path1|. ++def _IsSubpath(path1, path2): ++ path1_abs = os.path.abspath(path1) ++ path2_abs = os.path.abspath(path2) ++ common = os.path.commonprefix([path1_abs, path2_abs]) ++ return path1_abs == common ++ ++def _GetItemPath(item): ++ path = item.GetInputPath().replace("\\", "/") ++ ++ # Handle the case where the file resides within the output folder, ++ # by expanding any variables as well as replacing the output folder name with ++ # a fixed string such that the key added to the map does not depend on a given ++ # developer's setup. ++ # ++ # For example this will convert the following path: ++ # ../../out/gchrome/${root_gen_dir}/ui/webui/resources/js/foo.js ++ # to: ++ # @out_folder@/gen/ui/webui/resources/js/foo.js ++ ++ real_path = item.ToRealPath(item.GetInputPath()) ++ if (item.attrs.get('use_base_dir', 'true') != 'true' and ++ _IsSubpath(os.path.curdir, real_path)): ++ path = os.path.join( ++ '@out_folder@', os.path.relpath(real_path)).replace("\\", "/") ++ ++ assert '$' not in path, 'all variables should have been expanded' ++ return path +diff --git a/tools/grit/grit/format/resource_map_unittest.py b/tools/grit/grit/format/resource_map_unittest.py +new file mode 100644 +index 0000000000..3499b321ef +--- /dev/null ++++ b/tools/grit/grit/format/resource_map_unittest.py +@@ -0,0 +1,345 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for grit.format.resource_map''' ++ ++from __future__ import print_function ++ ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++import unittest ++ ++from grit import util ++from grit.format import resource_map ++ ++ ++class FormatResourceMapUnittest(unittest.TestCase): ++ def testFormatResourceMap(self): ++ grd = util.ParseGrdForUnittest(''' ++ <outputs> ++ <output type="rc_header" filename="the_rc_header.h" /> ++ <output type="resource_map_header" ++ filename="the_resource_map_header.h" /> ++ </outputs> ++ <release seq="3"> ++ <structures first_id="300"> ++ <structure type="menu" name="IDC_KLONKMENU" ++ file="grit\\testdata\\klonk.rc" encoding="utf-16" /> ++ </structures> ++ <includes first_id="10000"> ++ <include type="foo" file="abc" name="IDS_FIRSTPRESENT" /> ++ <if expr="False"> ++ <include type="foo" file="def" name="IDS_MISSING" /> ++ </if> ++ <if expr="lang != 'es'"> ++ <include type="foo" file="ghi" name="IDS_LANGUAGESPECIFIC" /> ++ </if> ++ <if expr="lang == 'es'"> ++ <include type="foo" file="jkl" name="IDS_LANGUAGESPECIFIC" /> ++ </if> ++ <include type="foo" file="mno" name="IDS_THIRDPRESENT" /> ++ <include type="foo" file="opq" name="IDS_FOURTHPRESENT" ++ skip_in_resource_map="true" /> ++ </includes> ++ </release>''', run_gatherers=True) ++ output = util.StripBlankLinesAndComments(''.join( ++ resource_map.GetFormatter('resource_map_header')(grd, 'en', '.'))) ++ self.assertEqual('''\ ++#include <stddef.h> ++#ifndef GRIT_RESOURCE_MAP_STRUCT_ ++#define GRIT_RESOURCE_MAP_STRUCT_ ++struct GritResourceMap { ++ const char* const name; ++ int value; ++}; ++#endif // GRIT_RESOURCE_MAP_STRUCT_ ++extern const GritResourceMap kTheRcHeader[]; ++extern const size_t kTheRcHeaderSize;''', output) ++ output = util.StripBlankLinesAndComments(''.join( ++ resource_map.GetFormatter('resource_map_source')(grd, 'en', '.'))) ++ self.assertEqual('''\ ++#include "the_resource_map_header.h" ++#include <stddef.h> ++#include "base/stl_util.h" ++#include "the_rc_header.h" ++const GritResourceMap kTheRcHeader[] = { ++ {"IDC_KLONKMENU", IDC_KLONKMENU}, ++ {"IDS_FIRSTPRESENT", IDS_FIRSTPRESENT}, ++ {"IDS_LANGUAGESPECIFIC", IDS_LANGUAGESPECIFIC}, ++ {"IDS_THIRDPRESENT", IDS_THIRDPRESENT}, ++}; ++const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''', output) ++ output = util.StripBlankLinesAndComments(''.join( ++ resource_map.GetFormatter('resource_file_map_source')(grd, 'en', '.'))) ++ self.assertEqual('''\ ++#include "the_resource_map_header.h" ++#include <stddef.h> ++#include "base/stl_util.h" ++#include "the_rc_header.h" ++const GritResourceMap kTheRcHeader[] = { ++ {"grit/testdata/klonk.rc", IDC_KLONKMENU}, ++ {"abc", IDS_FIRSTPRESENT}, ++ {"ghi", IDS_LANGUAGESPECIFIC}, ++ {"mno", IDS_THIRDPRESENT}, ++}; ++const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''', output) ++ ++ def testFormatResourceMapWithGeneratedFile(self): ++ os.environ["root_gen_dir"] = "gen" ++ ++ grd = util.ParseGrdForUnittest('''\ ++ <outputs> ++ <output type="rc_header" filename="the_rc_header.h" /> ++ <output type="resource_map_header" ++ filename="resource_map_header.h" /> ++ </outputs> ++ <release seq="3"> ++ <includes first_id="10000"> ++ <include type="BINDATA" ++ file="${root_gen_dir}/foo/bar/baz.js" ++ name="IDR_FOO_BAR_BAZ_JS" ++ use_base_dir="false" ++ compress="gzip" /> ++ </includes> ++ </release>''', run_gatherers=True) ++ ++ formatter = resource_map.GetFormatter('resource_file_map_source') ++ output = util.StripBlankLinesAndComments(''.join(formatter(grd, 'en', '.'))) ++ expected = '''\ ++#include "resource_map_header.h" ++#include <stddef.h> ++#include "base/stl_util.h" ++#include "the_rc_header.h" ++const GritResourceMap kTheRcHeader[] = { ++ {"@out_folder@/gen/foo/bar/baz.js", IDR_FOO_BAR_BAZ_JS}, ++}; ++const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''' ++ self.assertEqual(expected, output) ++ ++ def testFormatResourceMapWithOutputAllEqualsFalseForStructures(self): ++ grd = util.ParseGrdForUnittest(''' ++ <outputs> ++ <output type="rc_header" filename="the_rc_header.h" /> ++ <output type="resource_map_header" ++ filename="the_resource_map_header.h" /> ++ <output type="resource_map_source" ++ filename="the_resource_map_header.cc" /> ++ </outputs> ++ <release seq="3"> ++ <structures first_id="300"> ++ <structure type="chrome_scaled_image" name="IDR_KLONKMENU" ++ file="foo.png" /> ++ <if expr="False"> ++ <structure type="chrome_scaled_image" name="IDR_MISSING" ++ file="bar.png" /> ++ </if> ++ <if expr="True"> ++ <structure type="chrome_scaled_image" name="IDR_BLOB" ++ file="blob.png" /> ++ </if> ++ <if expr="True"> ++ <then> ++ <structure type="chrome_scaled_image" name="IDR_METEOR" ++ file="meteor.png" /> ++ </then> ++ <else> ++ <structure type="chrome_scaled_image" name="IDR_METEOR" ++ file="roetem.png" /> ++ </else> ++ </if> ++ <if expr="False"> ++ <structure type="chrome_scaled_image" name="IDR_LAST" ++ file="zyx.png" /> ++ </if> ++ <if expr="True"> ++ <structure type="chrome_scaled_image" name="IDR_LAST" ++ file="xyz.png" /> ++ </if> ++ </structures> ++ </release>''', run_gatherers=True) ++ output = util.StripBlankLinesAndComments(''.join( ++ resource_map.GetFormatter('resource_map_header')(grd, 'en', '.'))) ++ self.assertEqual('''\ ++#include <stddef.h> ++#ifndef GRIT_RESOURCE_MAP_STRUCT_ ++#define GRIT_RESOURCE_MAP_STRUCT_ ++struct GritResourceMap { ++ const char* const name; ++ int value; ++}; ++#endif // GRIT_RESOURCE_MAP_STRUCT_ ++extern const GritResourceMap kTheRcHeader[]; ++extern const size_t kTheRcHeaderSize;''', output) ++ output = util.StripBlankLinesAndComments(''.join( ++ resource_map.GetFormatter('resource_map_source')(grd, 'en', '.'))) ++ self.assertEqual('''\ ++#include "the_resource_map_header.h" ++#include <stddef.h> ++#include "base/stl_util.h" ++#include "the_rc_header.h" ++const GritResourceMap kTheRcHeader[] = { ++ {"IDR_KLONKMENU", IDR_KLONKMENU}, ++ {"IDR_BLOB", IDR_BLOB}, ++ {"IDR_METEOR", IDR_METEOR}, ++ {"IDR_LAST", IDR_LAST}, ++}; ++const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''', output) ++ output = util.StripBlankLinesAndComments(''.join( ++ resource_map.GetFormatter('resource_map_source')(grd, 'en', '.'))) ++ self.assertEqual('''\ ++#include "the_resource_map_header.h" ++#include <stddef.h> ++#include "base/stl_util.h" ++#include "the_rc_header.h" ++const GritResourceMap kTheRcHeader[] = { ++ {"IDR_KLONKMENU", IDR_KLONKMENU}, ++ {"IDR_BLOB", IDR_BLOB}, ++ {"IDR_METEOR", IDR_METEOR}, ++ {"IDR_LAST", IDR_LAST}, ++}; ++const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''', output) ++ ++ def testFormatResourceMapWithOutputAllEqualsFalseForIncludes(self): ++ grd = util.ParseGrdForUnittest(''' ++ <outputs> ++ <output type="rc_header" filename="the_rc_header.h" /> ++ <output type="resource_map_header" ++ filename="the_resource_map_header.h" /> ++ </outputs> ++ <release seq="3"> ++ <structures first_id="300"> ++ <structure type="menu" name="IDC_KLONKMENU" ++ file="grit\\testdata\\klonk.rc" encoding="utf-16" /> ++ </structures> ++ <includes first_id="10000"> ++ <include type="foo" file="abc" name="IDS_FIRSTPRESENT" /> ++ <if expr="False"> ++ <include type="foo" file="def" name="IDS_MISSING" /> ++ </if> ++ <include type="foo" file="mno" name="IDS_THIRDPRESENT" /> ++ <if expr="True"> ++ <include type="foo" file="blob" name="IDS_BLOB" /> ++ </if> ++ <if expr="True"> ++ <then> ++ <include type="foo" file="meteor" name="IDS_METEOR" /> ++ </then> ++ <else> ++ <include type="foo" file="roetem" name="IDS_METEOR" /> ++ </else> ++ </if> ++ <if expr="False"> ++ <include type="foo" file="zyx" name="IDS_LAST" /> ++ </if> ++ <if expr="True"> ++ <include type="foo" file="xyz" name="IDS_LAST" /> ++ </if> ++ </includes> ++ </release>''', run_gatherers=True) ++ output = util.StripBlankLinesAndComments(''.join( ++ resource_map.GetFormatter('resource_map_header')(grd, 'en', '.'))) ++ self.assertEqual('''\ ++#include <stddef.h> ++#ifndef GRIT_RESOURCE_MAP_STRUCT_ ++#define GRIT_RESOURCE_MAP_STRUCT_ ++struct GritResourceMap { ++ const char* const name; ++ int value; ++}; ++#endif // GRIT_RESOURCE_MAP_STRUCT_ ++extern const GritResourceMap kTheRcHeader[]; ++extern const size_t kTheRcHeaderSize;''', output) ++ output = util.StripBlankLinesAndComments(''.join( ++ resource_map.GetFormatter('resource_map_source')(grd, 'en', '.'))) ++ self.assertEqual('''\ ++#include "the_resource_map_header.h" ++#include <stddef.h> ++#include "base/stl_util.h" ++#include "the_rc_header.h" ++const GritResourceMap kTheRcHeader[] = { ++ {"IDC_KLONKMENU", IDC_KLONKMENU}, ++ {"IDS_FIRSTPRESENT", IDS_FIRSTPRESENT}, ++ {"IDS_THIRDPRESENT", IDS_THIRDPRESENT}, ++ {"IDS_BLOB", IDS_BLOB}, ++ {"IDS_METEOR", IDS_METEOR}, ++ {"IDS_LAST", IDS_LAST}, ++}; ++const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''', output) ++ output = util.StripBlankLinesAndComments(''.join( ++ resource_map.GetFormatter('resource_file_map_source')(grd, 'en', '.'))) ++ self.assertEqual('''\ ++#include "the_resource_map_header.h" ++#include <stddef.h> ++#include "base/stl_util.h" ++#include "the_rc_header.h" ++const GritResourceMap kTheRcHeader[] = { ++ {"grit/testdata/klonk.rc", IDC_KLONKMENU}, ++ {"abc", IDS_FIRSTPRESENT}, ++ {"mno", IDS_THIRDPRESENT}, ++ {"blob", IDS_BLOB}, ++ {"meteor", IDS_METEOR}, ++ {"xyz", IDS_LAST}, ++}; ++const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''', output) ++ ++ def testFormatStringResourceMap(self): ++ grd = util.ParseGrdForUnittest(''' ++ <outputs> ++ <output type="rc_header" filename="the_rc_header.h" /> ++ <output type="resource_map_header" filename="the_rc_map_header.h" /> ++ <output type="resource_map_source" filename="the_rc_map_source.cc" /> ++ </outputs> ++ <release seq="1" allow_pseudo="false"> ++ <messages fallback_to_english="true"> ++ <message name="IDS_PRODUCT_NAME" desc="The application name"> ++ Application ++ </message> ++ <if expr="True"> ++ <message name="IDS_DEFAULT_TAB_TITLE_TITLE_CASE" ++ desc="In Title Case: The default title in a tab."> ++ New Tab ++ </message> ++ </if> ++ <if expr="False"> ++ <message name="IDS_DEFAULT_TAB_TITLE" ++ desc="The default title in a tab."> ++ New tab ++ </message> ++ </if> ++ </messages> ++ </release>''', run_gatherers=True) ++ grd.InitializeIds() ++ output = util.StripBlankLinesAndComments(''.join( ++ resource_map.GetFormatter('resource_map_header')(grd, 'en', '.'))) ++ self.assertEqual('''\ ++#include <stddef.h> ++#ifndef GRIT_RESOURCE_MAP_STRUCT_ ++#define GRIT_RESOURCE_MAP_STRUCT_ ++struct GritResourceMap { ++ const char* const name; ++ int value; ++}; ++#endif // GRIT_RESOURCE_MAP_STRUCT_ ++extern const GritResourceMap kTheRcHeader[]; ++extern const size_t kTheRcHeaderSize;''', output) ++ output = util.StripBlankLinesAndComments(''.join( ++ resource_map.GetFormatter('resource_map_source')(grd, 'en', '.'))) ++ self.assertEqual('''\ ++#include "the_rc_map_header.h" ++#include <stddef.h> ++#include "base/stl_util.h" ++#include "the_rc_header.h" ++const GritResourceMap kTheRcHeader[] = { ++ {"IDS_PRODUCT_NAME", IDS_PRODUCT_NAME}, ++ {"IDS_DEFAULT_TAB_TITLE_TITLE_CASE", IDS_DEFAULT_TAB_TITLE_TITLE_CASE}, ++}; ++const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''', output) ++ ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/gather/__init__.py b/tools/grit/grit/gather/__init__.py +new file mode 100644 +index 0000000000..2d578f5643 +--- /dev/null ++++ b/tools/grit/grit/gather/__init__.py +@@ -0,0 +1,8 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Module grit.gather ++''' ++ ++pass +diff --git a/tools/grit/grit/gather/admin_template.py b/tools/grit/grit/gather/admin_template.py +new file mode 100644 +index 0000000000..c26b6a88d7 +--- /dev/null ++++ b/tools/grit/grit/gather/admin_template.py +@@ -0,0 +1,62 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Gatherer for administrative template files. ++''' ++ ++from __future__ import print_function ++ ++import re ++ ++from grit.gather import regexp ++from grit import exception ++from grit import lazy_re ++ ++ ++class MalformedAdminTemplateException(exception.Base): ++ '''This file doesn't look like a .adm file to me.''' ++ pass ++ ++ ++class AdmGatherer(regexp.RegexpGatherer): ++ '''Gatherer for the translateable portions of an admin template. ++ ++ This gatherer currently makes the following assumptions: ++ - there is only one [strings] section and it is always the last section ++ of the file ++ - translateable strings do not need to be escaped. ++ ''' ++ ++ # Finds the strings section as the group named 'strings' ++ _STRINGS_SECTION = lazy_re.compile( ++ r'(?P<first_part>.+^\[strings\])(?P<strings>.+)\Z', ++ re.MULTILINE | re.DOTALL) ++ ++ # Finds the translateable sections from within the [strings] section. ++ _TRANSLATEABLES = lazy_re.compile( ++ r'^\s*[A-Za-z0-9_]+\s*=\s*"(?P<text>.+)"\s*$', ++ re.MULTILINE) ++ ++ def Escape(self, text): ++ return text.replace('\n', '\\n') ++ ++ def UnEscape(self, text): ++ return text.replace('\\n', '\n') ++ ++ def Parse(self): ++ if self.have_parsed_: ++ return ++ self.have_parsed_ = True ++ ++ self.text_ = self._LoadInputFile().strip() ++ m = self._STRINGS_SECTION.match(self.text_) ++ if not m: ++ raise MalformedAdminTemplateException() ++ # Add the first part, which is all nontranslateable, to the skeleton ++ self._AddNontranslateableChunk(m.group('first_part')) ++ # Then parse the rest using the _TRANSLATEABLES regexp. ++ self._RegExpParse(self._TRANSLATEABLES, m.group('strings')) ++ ++ def GetTextualIds(self): ++ return [self.extkey] +diff --git a/tools/grit/grit/gather/admin_template_unittest.py b/tools/grit/grit/gather/admin_template_unittest.py +new file mode 100644 +index 0000000000..c637af3a75 +--- /dev/null ++++ b/tools/grit/grit/gather/admin_template_unittest.py +@@ -0,0 +1,115 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for the admin template gatherer.''' ++ ++from __future__ import print_function ++ ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++import unittest ++ ++from six import StringIO ++ ++from grit.gather import admin_template ++from grit import util ++from grit import grd_reader ++from grit import grit_runner ++from grit.tool import build ++ ++ ++class AdmGathererUnittest(unittest.TestCase): ++ def testParsingAndTranslating(self): ++ pseudofile = StringIO( ++ 'bingo bongo\n' ++ 'ding dong\n' ++ '[strings] \n' ++ 'whatcha="bingo bongo"\n' ++ 'gotcha = "bingolabongola "the wise" fingulafongula" \n') ++ gatherer = admin_template.AdmGatherer(pseudofile) ++ gatherer.Parse() ++ self.failUnless(len(gatherer.GetCliques()) == 2) ++ self.failUnless(gatherer.GetCliques()[1].GetMessage().GetRealContent() == ++ 'bingolabongola "the wise" fingulafongula') ++ ++ translation = gatherer.Translate('en') ++ self.failUnless(translation == gatherer.GetText().strip()) ++ ++ def testErrorHandling(self): ++ pseudofile = StringIO( ++ 'bingo bongo\n' ++ 'ding dong\n' ++ 'whatcha="bingo bongo"\n' ++ 'gotcha = "bingolabongola "the wise" fingulafongula" \n') ++ gatherer = admin_template.AdmGatherer(pseudofile) ++ self.assertRaises(admin_template.MalformedAdminTemplateException, ++ gatherer.Parse) ++ ++ _TRANSLATABLES_FROM_FILE = ( ++ 'Google', 'Google Desktop', 'Preferences', ++ 'Controls Google Desktop preferences', ++ 'Indexing and Capture Control', ++ 'Controls what files, web pages, and other content will be indexed by Google Desktop.', ++ 'Prevent indexing of email', ++ # there are lots more but we don't check any further ++ ) ++ ++ def VerifyCliquesFromAdmFile(self, cliques): ++ self.failUnless(len(cliques) > 20) ++ for clique, expected in zip(cliques, self._TRANSLATABLES_FROM_FILE): ++ text = clique.GetMessage().GetRealContent() ++ self.failUnless(text == expected) ++ ++ def testFromFile(self): ++ fname = util.PathFromRoot('grit/testdata/GoogleDesktop.adm') ++ gatherer = admin_template.AdmGatherer(fname) ++ gatherer.Parse() ++ cliques = gatherer.GetCliques() ++ self.VerifyCliquesFromAdmFile(cliques) ++ ++ def MakeGrd(self): ++ grd = grd_reader.Parse(StringIO('''<?xml version="1.0" encoding="UTF-8"?> ++ <grit latest_public_release="2" source_lang_id="en-US" current_release="3"> ++ <release seq="3"> ++ <structures> ++ <structure type="admin_template" name="IDAT_GOOGLE_DESKTOP_SEARCH" ++ file="GoogleDesktop.adm" exclude_from_rc="true" /> ++ <structure type="txt" name="BINGOBONGO" ++ file="README.txt" exclude_from_rc="true" /> ++ </structures> ++ </release> ++ <outputs> ++ <output filename="de_res.rc" type="rc_all" lang="de" /> ++ </outputs> ++ </grit>'''), util.PathFromRoot('grit/testdata')) ++ grd.SetOutputLanguage('en') ++ grd.RunGatherers() ++ return grd ++ ++ def testInGrd(self): ++ grd = self.MakeGrd() ++ cliques = grd.children[0].children[0].children[0].GetCliques() ++ self.VerifyCliquesFromAdmFile(cliques) ++ ++ def testFileIsOutput(self): ++ grd = self.MakeGrd() ++ dirname = util.TempDir({}) ++ try: ++ tool = build.RcBuilder() ++ tool.o = grit_runner.Options() ++ tool.output_directory = dirname.GetPath() ++ tool.res = grd ++ tool.Process() ++ ++ self.failUnless(os.path.isfile(dirname.GetPath('de_GoogleDesktop.adm'))) ++ self.failUnless(os.path.isfile(dirname.GetPath('de_README.txt'))) ++ finally: ++ dirname.CleanUp() ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/gather/chrome_html.py b/tools/grit/grit/gather/chrome_html.py +new file mode 100644 +index 0000000000..71c1332d66 +--- /dev/null ++++ b/tools/grit/grit/gather/chrome_html.py +@@ -0,0 +1,377 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++"""Prepares a Chrome HTML file by inlining resources and adding references to ++high DPI resources and removing references to unsupported scale factors. ++ ++This is a small gatherer that takes a HTML file, looks for src attributes ++and inlines the specified file, producing one HTML file with no external ++dependencies. It recursively inlines the included files. When inlining CSS ++image files this script also checks for the existence of high DPI versions ++of the inlined file including those on relevant platforms. Unsupported scale ++factors are also removed from existing image sets to support explicitly ++referencing all available images. ++""" ++ ++from __future__ import print_function ++ ++import os ++import re ++ ++from grit import lazy_re ++from grit import util ++from grit.format import html_inline ++from grit.gather import interface ++ ++ ++# Distribution string to replace with distribution. ++DIST_SUBSTR = '%DISTRIBUTION%' ++ ++ ++# Matches a chrome theme source URL. ++_THEME_SOURCE = lazy_re.compile( ++ r'(?P<baseurl>chrome://theme/IDR_[A-Z0-9_]*)(?P<query>\?.*)?') ++# Pattern for matching CSS url() function. ++_CSS_URL_PATTERN = r'url\((?P<quote>"|\'|)(?P<filename>[^"\'()]*)(?P=quote)\)' ++# Matches CSS url() functions with the capture group 'filename'. ++_CSS_URL = lazy_re.compile(_CSS_URL_PATTERN) ++# Matches one or more CSS image urls used in given properties. ++_CSS_IMAGE_URLS = lazy_re.compile( ++ r'(?P<attribute>content|background|[\w-]*-image):\s*' ++ r'(?P<urls>(' + _CSS_URL_PATTERN + r'\s*,?\s*)+)') ++# Matches CSS image sets. ++_CSS_IMAGE_SETS = lazy_re.compile( ++ r'(?P<attribute>content|background|[\w-]*-image):[ ]*' ++ r'-webkit-image-set\((?P<images>' ++ r'(\s*,?\s*url\((?P<quote>"|\'|)[^"\'()]*(?P=quote)\)[ ]*[0-9.]*x)*)\)', ++ re.MULTILINE) ++# Matches a single image in a CSS image set with the capture group scale. ++_CSS_IMAGE_SET_IMAGE = lazy_re.compile(r'\s*,?\s*' ++ r'url\((?P<quote>"|\'|)[^"\'()]*(?P=quote)\)[ ]*(?P<scale>[0-9.]*x)', ++ re.MULTILINE) ++_HTML_IMAGE_SRC = lazy_re.compile( ++ r'<img[^>]+src=\"(?P<filename>[^">]*)\"[^>]*>') ++ ++def GetImageList( ++ base_path, filename, scale_factors, distribution, ++ filename_expansion_function=None): ++ """Generate the list of images which match the provided scale factors. ++ ++ Takes an image filename and checks for files of the same name in folders ++ corresponding to the supported scale factors. If the file is from a ++ chrome://theme/ source, inserts supported @Nx scale factors as high DPI ++ versions. ++ ++ Args: ++ base_path: path to look for relative file paths in ++ filename: name of the base image file ++ scale_factors: a list of the supported scale factors (i.e. ['2x']) ++ distribution: string that should replace %DISTRIBUTION% ++ ++ Returns: ++ array of tuples containing scale factor and image (i.e. ++ [('1x', 'image.png'), ('2x', '2x/image.png')]). ++ """ ++ # Any matches for which a chrome URL handler will serve all scale factors ++ # can simply request all scale factors. ++ theme_match = _THEME_SOURCE.match(filename) ++ if theme_match: ++ images = [('1x', filename)] ++ for scale_factor in scale_factors: ++ scale_filename = "%s@%s" % (theme_match.group('baseurl'), scale_factor) ++ if theme_match.group('query'): ++ scale_filename += theme_match.group('query') ++ images.append((scale_factor, scale_filename)) ++ return images ++ ++ if filename.find(':') != -1: ++ # filename is probably a URL, only return filename itself. ++ return [('1x', filename)] ++ ++ filename = filename.replace(DIST_SUBSTR, distribution) ++ if filename_expansion_function: ++ filename = filename_expansion_function(filename) ++ filepath = os.path.join(base_path, filename) ++ images = [('1x', filename)] ++ ++ for scale_factor in scale_factors: ++ # Check for existence of file and add to image set. ++ scale_path = os.path.split(os.path.join(base_path, filename)) ++ scale_image_path = os.path.join(scale_path[0], scale_factor, scale_path[1]) ++ if os.path.isfile(scale_image_path): ++ # HTML/CSS always uses forward slashed paths. ++ parts = filename.rsplit('/', 1) ++ if len(parts) == 1: ++ path = '' ++ else: ++ path = parts[0] + '/' ++ scale_image_name = path + scale_factor + '/' + parts[-1] ++ images.append((scale_factor, scale_image_name)) ++ return images ++ ++ ++def GenerateImageSet(images, quote): ++ """Generates a -webkit-image-set for the provided list of images. ++ ++ Args: ++ images: an array of tuples giving scale factor and file path ++ (i.e. [('1x', 'image.png'), ('2x', '2x/image.png')]). ++ quote: a string giving the quotation character to use (i.e. "'") ++ ++ Returns: ++ string giving a -webkit-image-set rule referencing the provided images. ++ (i.e. '-webkit-image-set(url('image.png') 1x, url('2x/image.png') 2x)') ++ """ ++ imageset = [] ++ for (scale_factor, filename) in images: ++ imageset.append("url(%s%s%s) %s" % (quote, filename, quote, scale_factor)) ++ return "-webkit-image-set(%s)" % (', '.join(imageset)) ++ ++ ++def UrlToImageSet( ++ src_match, base_path, scale_factors, distribution, ++ filename_expansion_function=None): ++ """Regex replace function which replaces url() with -webkit-image-set. ++ ++ Takes a regex match for url('path'). If the file is local, checks for ++ files of the same name in folders corresponding to the supported scale ++ factors. If the file is from a chrome://theme/ source, inserts the ++ supported @Nx scale factor request. In either case inserts a ++ -webkit-image-set rule to fetch the appropriate image for the current ++ scale factor. ++ ++ Args: ++ src_match: regex match object from _CSS_URLS ++ base_path: path to look for relative file paths in ++ scale_factors: a list of the supported scale factors (i.e. ['2x']) ++ distribution: string that should replace %DISTRIBUTION%. ++ ++ Returns: ++ string ++ """ ++ quote = src_match.group('quote') ++ filename = src_match.group('filename') ++ image_list = GetImageList( ++ base_path, filename, scale_factors, distribution, ++ filename_expansion_function=filename_expansion_function) ++ ++ # Don't modify the source if there is only one image. ++ if len(image_list) == 1: ++ return src_match.group(0) ++ ++ return GenerateImageSet(image_list, quote) ++ ++ ++def InsertImageSet( ++ src_match, base_path, scale_factors, distribution, ++ filename_expansion_function=None): ++ """Regex replace function which inserts -webkit-image-set rules. ++ ++ Takes a regex match for `property: url('path')[, url('path')]+`. ++ Replaces one or more occurances of the match with image set rules. ++ ++ Args: ++ src_match: regex match object from _CSS_IMAGE_URLS ++ base_path: path to look for relative file paths in ++ scale_factors: a list of the supported scale factors (i.e. ['2x']) ++ distribution: string that should replace %DISTRIBUTION%. ++ ++ Returns: ++ string ++ """ ++ attr = src_match.group('attribute') ++ urls = _CSS_URL.sub( ++ lambda m: UrlToImageSet(m, base_path, scale_factors, distribution, ++ filename_expansion_function), ++ src_match.group('urls')) ++ ++ return "%s: %s" % (attr, urls) ++ ++ ++def InsertImageStyle( ++ src_match, base_path, scale_factors, distribution, ++ filename_expansion_function=None): ++ """Regex replace function which adds a content style to an <img>. ++ ++ Takes a regex match from _HTML_IMAGE_SRC and replaces the attribute with a CSS ++ style which defines the image set. ++ """ ++ filename = src_match.group('filename') ++ image_list = GetImageList( ++ base_path, filename, scale_factors, distribution, ++ filename_expansion_function=filename_expansion_function) ++ ++ # Don't modify the source if there is only one image or image already defines ++ # a style. ++ if src_match.group(0).find(" style=\"") != -1 or len(image_list) == 1: ++ return src_match.group(0) ++ ++ return "%s style=\"content: %s;\">" % (src_match.group(0)[:-1], ++ GenerateImageSet(image_list, "'")) ++ ++ ++def InsertImageSets( ++ filepath, text, scale_factors, distribution, ++ filename_expansion_function=None): ++ """Helper function that adds references to external images available in any of ++ scale_factors in CSS backgrounds. ++ """ ++ # Add high DPI urls for css attributes: content, background, ++ # or *-image or <img src="foo">. ++ return _CSS_IMAGE_URLS.sub( ++ lambda m: InsertImageSet( ++ m, filepath, scale_factors, distribution, ++ filename_expansion_function=filename_expansion_function), ++ _HTML_IMAGE_SRC.sub( ++ lambda m: InsertImageStyle( ++ m, filepath, scale_factors, distribution, ++ filename_expansion_function=filename_expansion_function), ++ text)) ++ ++ ++def RemoveImagesNotIn(scale_factors, src_match): ++ """Regex replace function which removes images for scale factors not in ++ scale_factors. ++ ++ Takes a regex match for _CSS_IMAGE_SETS. For each image in the group images, ++ checks if this scale factor is in scale_factors and if not, removes it. ++ ++ Args: ++ scale_factors: a list of the supported scale factors (i.e. ['1x', '2x']) ++ src_match: regex match object from _CSS_IMAGE_SETS ++ ++ Returns: ++ string ++ """ ++ attr = src_match.group('attribute') ++ images = _CSS_IMAGE_SET_IMAGE.sub( ++ lambda m: m.group(0) if m.group('scale') in scale_factors else '', ++ src_match.group('images')) ++ return "%s: -webkit-image-set(%s)" % (attr, images) ++ ++ ++def RemoveImageSetImages(text, scale_factors): ++ """Helper function which removes images in image sets not in the list of ++ supported scale_factors. ++ """ ++ return _CSS_IMAGE_SETS.sub( ++ lambda m: RemoveImagesNotIn(scale_factors, m), text) ++ ++ ++def ProcessImageSets( ++ filepath, text, scale_factors, distribution, ++ filename_expansion_function=None): ++ """Helper function that adds references to external images available in other ++ scale_factors and removes images from image-sets in unsupported scale_factors. ++ """ ++ # Explicitly add 1x to supported scale factors so that it is not removed. ++ supported_scale_factors = ['1x'] ++ supported_scale_factors.extend(scale_factors) ++ return InsertImageSets( ++ filepath, ++ RemoveImageSetImages(text, supported_scale_factors), ++ scale_factors, ++ distribution, ++ filename_expansion_function=filename_expansion_function) ++ ++ ++class ChromeHtml(interface.GathererBase): ++ """Represents an HTML document processed for Chrome WebUI. ++ ++ HTML documents used in Chrome WebUI have local resources inlined and ++ automatically insert references to high DPI assets used in CSS properties ++ with the use of the -webkit-image-set value. References to unsupported scale ++ factors in image sets are also removed. This does not generate any ++ translateable messages and instead generates a single DataPack resource. ++ """ ++ ++ def __init__(self, *args, **kwargs): ++ super(ChromeHtml, self).__init__(*args, **kwargs) ++ self.allow_external_script_ = False ++ self.flatten_html_ = False ++ self.preprocess_only_ = False ++ # 1x resources are implicitly already in the source and do not need to be ++ # added. ++ self.scale_factors_ = [] ++ self.filename_expansion_function = None ++ ++ def SetAttributes(self, attrs): ++ self.allow_external_script_ = ('allowexternalscript' in attrs and ++ attrs['allowexternalscript'] == 'true') ++ self.preprocess_only_ = ('preprocess' in attrs and ++ attrs['preprocess'] == 'true') ++ self.flatten_html_ = (self.preprocess_only_ or ('flattenhtml' in attrs and ++ attrs['flattenhtml'] == 'true')) ++ ++ def SetDefines(self, defines): ++ if 'scale_factors' in defines: ++ self.scale_factors_ = defines['scale_factors'].split(',') ++ ++ def GetText(self): ++ """Returns inlined text of the HTML document.""" ++ return self.inlined_text_ ++ ++ def GetTextualIds(self): ++ return [self.extkey] ++ ++ def GetData(self, lang, encoding): ++ """Returns inlined text of the HTML document.""" ++ ret = self.inlined_text_ ++ if encoding == util.BINARY: ++ ret = ret.encode('utf-8') ++ return ret ++ ++ def GetHtmlResourceFilenames(self): ++ """Returns a set of all filenames inlined by this file.""" ++ if self.flatten_html_: ++ return html_inline.GetResourceFilenames( ++ self.grd_node.ToRealPath(self.GetInputPath()), ++ self.grd_node, ++ allow_external_script=self.allow_external_script_, ++ rewrite_function=lambda fp, t, d: ProcessImageSets( ++ fp, t, self.scale_factors_, d, ++ filename_expansion_function=self.filename_expansion_function), ++ filename_expansion_function=self.filename_expansion_function) ++ return [] ++ ++ def Translate(self, lang, pseudo_if_not_available=True, ++ skeleton_gatherer=None, fallback_to_english=False): ++ """Returns this document translated.""" ++ return self.inlined_text_ ++ ++ def SetFilenameExpansionFunction(self, fn): ++ self.filename_expansion_function = fn ++ ++ def Parse(self): ++ """Parses and inlines the represented file.""" ++ ++ filename = self.GetInputPath() ++ # If there is a grd_node, prefer its GetInputPath(), as that may do more ++ # processing to make the call to ToRealPath() below work correctly. ++ if self.grd_node: ++ filename = self.grd_node.GetInputPath() ++ if self.filename_expansion_function: ++ filename = self.filename_expansion_function(filename) ++ # Hack: some unit tests supply an absolute path and no root node. ++ if not os.path.isabs(filename): ++ filename = self.grd_node.ToRealPath(filename) ++ if self.flatten_html_: ++ self.inlined_text_ = html_inline.InlineToString( ++ filename, ++ self.grd_node, ++ allow_external_script = self.allow_external_script_, ++ strip_whitespace=True, ++ preprocess_only = self.preprocess_only_, ++ rewrite_function=lambda fp, t, d: ProcessImageSets( ++ fp, t, self.scale_factors_, d, ++ filename_expansion_function=self.filename_expansion_function), ++ filename_expansion_function=self.filename_expansion_function) ++ else: ++ distribution = html_inline.GetDistribution() ++ self.inlined_text_ = ProcessImageSets( ++ os.path.dirname(filename), ++ util.ReadFile(filename, 'utf-8'), ++ self.scale_factors_, ++ distribution, ++ filename_expansion_function=self.filename_expansion_function) +diff --git a/tools/grit/grit/gather/chrome_html_unittest.py b/tools/grit/grit/gather/chrome_html_unittest.py +new file mode 100644 +index 0000000000..8c75ee5bf4 +--- /dev/null ++++ b/tools/grit/grit/gather/chrome_html_unittest.py +@@ -0,0 +1,610 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for grit.gather.chrome_html''' ++ ++from __future__ import print_function ++ ++import os ++import re ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++import unittest ++ ++from grit import lazy_re ++from grit import util ++from grit.gather import chrome_html ++ ++ ++_NEW_LINE = lazy_re.compile('(\r\n|\r|\n)', re.MULTILINE) ++ ++ ++def StandardizeHtml(text): ++ '''Standardizes the newline format and png mime type in Html text.''' ++ return _NEW_LINE.sub('\n', text).replace('data:image/x-png;', ++ 'data:image/png;') ++ ++ ++class ChromeHtmlUnittest(unittest.TestCase): ++ '''Unit tests for ChromeHtml.''' ++ ++ def testFileResources(self): ++ '''Tests inlined image file resources with available high DPI assets.''' ++ ++ tmp_dir = util.TempDir({ ++ 'index.html': ''' ++ <!DOCTYPE HTML> ++ <html> ++ <head> ++ <link rel="stylesheet" href="test.css"> ++ </head> ++ <body> ++ <!-- Don't need a body. --> ++ </body> ++ </html> ++ ''', ++ ++ 'test.css': ''' ++ .image { ++ background: url('test.png'); + } -+ } -+ } ++ ''', ++ ++ 'test.png': 'PNG DATA', ++ ++ '1.4x/test.png': '1.4x PNG DATA', ++ ++ '1.8x/test.png': '1.8x PNG DATA', ++ }) ++ ++ html = chrome_html.ChromeHtml(tmp_dir.GetPath('index.html')) ++ html.SetDefines({'scale_factors': '1.4x,1.8x'}) ++ html.SetAttributes({'flattenhtml': 'true'}) ++ html.Parse() ++ self.failUnlessEqual(StandardizeHtml(html.GetData('en', 'utf-8')), ++ StandardizeHtml(''' ++ <!DOCTYPE HTML> ++ <html> ++ <head> ++ <style> ++ .image { ++ background: -webkit-image-set(url('data:image/png;base64,UE5HIERBVEE=') 1x, url('data:image/png;base64,MS40eCBQTkcgREFUQQ==') 1.4x, url('data:image/png;base64,MS44eCBQTkcgREFUQQ==') 1.8x); ++ } ++ </style> ++ </head> ++ <body> ++ <!-- Don't need a body. --> ++ </body> ++ </html> ++ ''')) ++ tmp_dir.CleanUp() ++ ++ def testFileResourcesImageTag(self): ++ '''Tests inlined image file resources with available high DPI assets on ++ an image tag.''' ++ ++ tmp_dir = util.TempDir({ ++ 'index.html': ''' ++ <!DOCTYPE HTML> ++ <html> ++ <body> ++ <img id="foo" src="test.png"> ++ </body> ++ </html> ++ ''', ++ ++ 'test.png': 'PNG DATA', ++ ++ '2x/test.png': '2x PNG DATA', ++ }) ++ ++ html = chrome_html.ChromeHtml(tmp_dir.GetPath('index.html')) ++ html.SetDefines({'scale_factors': '2x'}) ++ html.SetAttributes({'flattenhtml': 'true'}) ++ html.Parse() ++ self.failUnlessEqual(StandardizeHtml(html.GetData('en', 'utf-8')), ++ StandardizeHtml(''' ++ <!DOCTYPE HTML> ++ <html> ++ <body> ++ <img id="foo" src="data:image/png;base64,UE5HIERBVEE=" style="content: -webkit-image-set(url('data:image/png;base64,UE5HIERBVEE=') 1x, url('data:image/png;base64,MnggUE5HIERBVEE=') 2x);"> ++ </body> ++ </html> ++ ''')) ++ tmp_dir.CleanUp() ++ ++ def testFileResourcesNoFlatten(self): ++ '''Tests non-inlined image file resources with available high DPI assets.''' ++ ++ tmp_dir = util.TempDir({ ++ 'test.css': ''' ++ .image { ++ background: url('test.png'); ++ } ++ ''', ++ ++ 'test.png': 'PNG DATA', ++ ++ '1.4x/test.png': '1.4x PNG DATA', + -+ void CountType(const Type* type, -+ int* trivial_member, -+ int* non_trivial_member, -+ int* templated_non_trivial_member) { -+ switch (type->getTypeClass()) { -+ case Type::Record: { -+ // Simplifying; the whole class isn't trivial if the dtor is, but -+ // we use this as a signal about complexity. -+ if (TypeHasNonTrivialDtor(type)) -+ (*trivial_member)++; -+ else -+ (*non_trivial_member)++; -+ break; ++ '1.8x/test.png': '1.8x PNG DATA', ++ }) ++ ++ html = chrome_html.ChromeHtml(tmp_dir.GetPath('test.css')) ++ html.SetDefines({'scale_factors': '1.4x,1.8x'}) ++ html.SetAttributes({'flattenhtml': 'false'}) ++ html.Parse() ++ self.failUnlessEqual(StandardizeHtml(html.GetData('en', 'utf-8')), ++ StandardizeHtml(''' ++ .image { ++ background: -webkit-image-set(url('test.png') 1x, url('1.4x/test.png') 1.4x, url('1.8x/test.png') 1.8x); + } -+ case Type::TemplateSpecialization: { -+ TemplateName name = -+ dyn_cast<TemplateSpecializationType>(type)->getTemplateName(); -+ bool whitelisted_template = false; -+ -+ // HACK: I'm at a loss about how to get the syntax checker to get -+ // whether a template is exterened or not. For the first pass here, -+ // just do retarded string comparisons. -+ if (TemplateDecl* decl = name.getAsTemplateDecl()) { -+ std::string base_name = decl->getNameAsString(); -+ if (base_name == "basic_string") -+ whitelisted_template = true; -+ } ++ ''')) ++ tmp_dir.CleanUp() + -+ if (whitelisted_template) -+ (*non_trivial_member)++; -+ else -+ (*templated_non_trivial_member)++; -+ break; ++ def testFileResourcesNoFlattenSubdir(self): ++ '''Tests non-inlined image file resources w/high DPI assets in subdirs.''' ++ ++ tmp_dir = util.TempDir({ ++ 'test.css': ''' ++ .image { ++ background: url('sub/test.png'); + } -+ case Type::Elaborated: { -+ CountType( -+ dyn_cast<ElaboratedType>(type)->getNamedType().getTypePtr(), -+ trivial_member, non_trivial_member, templated_non_trivial_member); -+ break; ++ ''', ++ ++ 'sub/test.png': 'PNG DATA', ++ ++ 'sub/1.4x/test.png': '1.4x PNG DATA', ++ ++ 'sub/1.8x/test.png': '1.8x PNG DATA', ++ }) ++ ++ html = chrome_html.ChromeHtml(tmp_dir.GetPath('test.css')) ++ html.SetDefines({'scale_factors': '1.4x,1.8x'}) ++ html.SetAttributes({'flattenhtml': 'false'}) ++ html.Parse() ++ self.failUnlessEqual(StandardizeHtml(html.GetData('en', 'utf-8')), ++ StandardizeHtml(''' ++ .image { ++ background: -webkit-image-set(url('sub/test.png') 1x, url('sub/1.4x/test.png') 1.4x, url('sub/1.8x/test.png') 1.8x); + } -+ case Type::Typedef: { -+ while (const TypedefType* TT = dyn_cast<TypedefType>(type)) { -+ type = TT->getDecl()->getUnderlyingType().getTypePtr(); -+ } -+ CountType(type, trivial_member, non_trivial_member, -+ templated_non_trivial_member); -+ break; ++ ''')) ++ tmp_dir.CleanUp() ++ ++ def testFileResourcesPreprocess(self): ++ '''Tests preprocessed image file resources with available high DPI ++ assets.''' ++ ++ tmp_dir = util.TempDir({ ++ 'test.css': ''' ++ .image { ++ background: url('test.png'); + } -+ default: { -+ // Stupid assumption: anything we see that isn't the above is one of -+ // the 20 integer types. -+ (*trivial_member)++; -+ break; ++ ''', ++ ++ 'test.png': 'PNG DATA', ++ ++ '1.4x/test.png': '1.4x PNG DATA', ++ ++ '1.8x/test.png': '1.8x PNG DATA', ++ }) ++ ++ html = chrome_html.ChromeHtml(tmp_dir.GetPath('test.css')) ++ html.SetDefines({'scale_factors': '1.4x,1.8x'}) ++ html.SetAttributes({'flattenhtml': 'false', 'preprocess': 'true'}) ++ html.Parse() ++ self.failUnlessEqual(StandardizeHtml(html.GetData('en', 'utf-8')), ++ StandardizeHtml(''' ++ .image { ++ background: -webkit-image-set(url('test.png') 1x, url('1.4x/test.png') 1.4x, url('1.8x/test.png') 1.8x); + } -+ } -+ } -+}; ++ ''')) ++ tmp_dir.CleanUp() + -+class FindBadConstructsAction : public PluginASTAction { -+ public: -+ FindBadConstructsAction() -+ : check_refcounted_dtors_(true), -+ check_virtuals_in_implementations_(true) { -+ } ++ def testFileResourcesDoubleQuotes(self): ++ '''Tests inlined image file resources if url() filename is double quoted.''' ++ ++ tmp_dir = util.TempDir({ ++ 'test.css': ''' ++ .image { ++ background: url("test.png"); ++ } ++ ''', ++ ++ 'test.png': 'PNG DATA', ++ ++ '2x/test.png': '2x PNG DATA', ++ }) ++ ++ html = chrome_html.ChromeHtml(tmp_dir.GetPath('test.css')) ++ html.SetDefines({'scale_factors': '2x'}) ++ html.SetAttributes({'flattenhtml': 'true'}) ++ html.Parse() ++ self.failUnlessEqual(StandardizeHtml(html.GetData('en', 'utf-8')), ++ StandardizeHtml(''' ++ .image { ++ background: -webkit-image-set(url("data:image/png;base64,UE5HIERBVEE=") 1x, url("data:image/png;base64,MnggUE5HIERBVEE=") 2x); ++ } ++ ''')) ++ tmp_dir.CleanUp() ++ ++ def testFileResourcesNoQuotes(self): ++ '''Tests inlined image file resources when url() filename is unquoted.''' ++ ++ tmp_dir = util.TempDir({ ++ 'test.css': ''' ++ .image { ++ background: url(test.png); ++ } ++ ''', ++ ++ 'test.png': 'PNG DATA', + -+ protected: -+ // Overridden from PluginASTAction: -+ virtual ASTConsumer* CreateASTConsumer(CompilerInstance& instance, -+ llvm::StringRef ref) { -+ return new FindBadConstructsConsumer( -+ instance, check_refcounted_dtors_, check_virtuals_in_implementations_); ++ '2x/test.png': '2x PNG DATA', ++ }) ++ ++ html = chrome_html.ChromeHtml(tmp_dir.GetPath('test.css')) ++ html.SetDefines({'scale_factors': '2x'}) ++ html.SetAttributes({'flattenhtml': 'true'}) ++ html.Parse() ++ self.failUnlessEqual(StandardizeHtml(html.GetData('en', 'utf-8')), ++ StandardizeHtml(''' ++ .image { ++ background: -webkit-image-set(url(data:image/png;base64,UE5HIERBVEE=) 1x, url(data:image/png;base64,MnggUE5HIERBVEE=) 2x); ++ } ++ ''')) ++ tmp_dir.CleanUp() ++ ++ def testFileResourcesSubdirs(self): ++ '''Tests inlined image file resources if url() filename is in a subdir.''' ++ ++ tmp_dir = util.TempDir({ ++ 'test.css': ''' ++ .image { ++ background: url('some/sub/path/test.png'); ++ } ++ ''', ++ ++ 'some/sub/path/test.png': 'PNG DATA', ++ ++ 'some/sub/path/2x/test.png': '2x PNG DATA', ++ }) ++ ++ html = chrome_html.ChromeHtml(tmp_dir.GetPath('test.css')) ++ html.SetDefines({'scale_factors': '2x'}) ++ html.SetAttributes({'flattenhtml': 'true'}) ++ html.Parse() ++ self.failUnlessEqual(StandardizeHtml(html.GetData('en', 'utf-8')), ++ StandardizeHtml(''' ++ .image { ++ background: -webkit-image-set(url('data:image/png;base64,UE5HIERBVEE=') 1x, url('data:image/png;base64,MnggUE5HIERBVEE=') 2x); ++ } ++ ''')) ++ tmp_dir.CleanUp() ++ ++ def testFileResourcesNoFile(self): ++ '''Tests inlined image file resources without available high DPI assets.''' ++ ++ tmp_dir = util.TempDir({ ++ 'index.html': ''' ++ <!DOCTYPE HTML> ++ <html> ++ <head> ++ <link rel="stylesheet" href="test.css"> ++ </head> ++ <body> ++ <!-- Don't need a body. --> ++ </body> ++ </html> ++ ''', ++ ++ 'test.css': ''' ++ .image { ++ background: url('test.png'); ++ } ++ ''', ++ ++ 'test.png': 'PNG DATA', ++ }) ++ ++ html = chrome_html.ChromeHtml(tmp_dir.GetPath('index.html')) ++ html.SetDefines({'scale_factors': '2x'}) ++ html.SetAttributes({'flattenhtml': 'true'}) ++ html.Parse() ++ self.failUnlessEqual(StandardizeHtml(html.GetData('en', 'utf-8')), ++ StandardizeHtml(''' ++ <!DOCTYPE HTML> ++ <html> ++ <head> ++ <style> ++ .image { ++ background: url('data:image/png;base64,UE5HIERBVEE='); ++ } ++ </style> ++ </head> ++ <body> ++ <!-- Don't need a body. --> ++ </body> ++ </html> ++ ''')) ++ tmp_dir.CleanUp() ++ ++ def testFileResourcesMultipleBackgrounds(self): ++ '''Tests inlined image file resources with two url()s.''' ++ ++ tmp_dir = util.TempDir({ ++ 'test.css': ''' ++ .image { ++ background: url(test.png), url(test.png); ++ } ++ ''', ++ ++ 'test.png': 'PNG DATA', ++ ++ '2x/test.png': '2x PNG DATA', ++ }) ++ ++ html = chrome_html.ChromeHtml(tmp_dir.GetPath('test.css')) ++ html.SetDefines({'scale_factors': '2x'}) ++ html.SetAttributes({'flattenhtml': 'true'}) ++ html.Parse() ++ self.failUnlessEqual(StandardizeHtml(html.GetData('en', 'utf-8')), ++ StandardizeHtml(''' ++ .image { ++ background: -webkit-image-set(url(data:image/png;base64,UE5HIERBVEE=) 1x, url(data:image/png;base64,MnggUE5HIERBVEE=) 2x), -webkit-image-set(url(data:image/png;base64,UE5HIERBVEE=) 1x, url(data:image/png;base64,MnggUE5HIERBVEE=) 2x); ++ } ++ ''')) ++ tmp_dir.CleanUp() ++ ++ def testFileResourcesMultipleBackgroundsWithNewline1(self): ++ '''Tests inlined image file resources with line break after first url().''' ++ ++ tmp_dir = util.TempDir({ ++ 'test.css': ''' ++ .image { ++ background: url(test.png), ++ url(test.png); ++ } ++ ''', ++ ++ 'test.png': 'PNG DATA', ++ ++ '2x/test.png': '2x PNG DATA', ++ }) ++ ++ html = chrome_html.ChromeHtml(tmp_dir.GetPath('test.css')) ++ html.SetDefines({'scale_factors': '2x'}) ++ html.SetAttributes({'flattenhtml': 'true'}) ++ html.Parse() ++ self.failUnlessEqual(StandardizeHtml(html.GetData('en', 'utf-8')), ++ StandardizeHtml(''' ++ .image { ++ background: -webkit-image-set(url(data:image/png;base64,UE5HIERBVEE=) 1x, url(data:image/png;base64,MnggUE5HIERBVEE=) 2x), ++ -webkit-image-set(url(data:image/png;base64,UE5HIERBVEE=) 1x, url(data:image/png;base64,MnggUE5HIERBVEE=) 2x); ++ } ++ ''')) ++ tmp_dir.CleanUp() ++ ++ def testFileResourcesMultipleBackgroundsWithNewline2(self): ++ '''Tests inlined image file resources with line break before first url() ++ and before second url().''' ++ ++ tmp_dir = util.TempDir({ ++ 'test.css': ''' ++ .image { ++ background: ++ url(test.png), ++ url(test.png); ++ } ++ ''', ++ ++ 'test.png': 'PNG DATA', ++ ++ '2x/test.png': '2x PNG DATA', ++ }) ++ ++ html = chrome_html.ChromeHtml(tmp_dir.GetPath('test.css')) ++ html.SetDefines({'scale_factors': '2x'}) ++ html.SetAttributes({'flattenhtml': 'true'}) ++ html.Parse() ++ self.failUnlessEqual(StandardizeHtml(html.GetData('en', 'utf-8')), ++ StandardizeHtml(''' ++ .image { ++ background: -webkit-image-set(url(data:image/png;base64,UE5HIERBVEE=) 1x, url(data:image/png;base64,MnggUE5HIERBVEE=) 2x), ++ -webkit-image-set(url(data:image/png;base64,UE5HIERBVEE=) 1x, url(data:image/png;base64,MnggUE5HIERBVEE=) 2x); ++ } ++ ''')) ++ tmp_dir.CleanUp() ++ ++ def testFileResourcesCRLF(self): ++ '''Tests inlined image file resource when url() is preceded by a Windows ++ style line break.''' ++ ++ tmp_dir = util.TempDir({ ++ 'test.css': ''' ++ .image { ++ background:\r\nurl(test.png); ++ } ++ ''', ++ ++ 'test.png': 'PNG DATA', ++ ++ '2x/test.png': '2x PNG DATA', ++ }) ++ ++ html = chrome_html.ChromeHtml(tmp_dir.GetPath('test.css')) ++ html.SetDefines({'scale_factors': '2x'}) ++ html.SetAttributes({'flattenhtml': 'true'}) ++ html.Parse() ++ self.failUnlessEqual(StandardizeHtml(html.GetData('en', 'utf-8')), ++ StandardizeHtml(''' ++ .image { ++ background: -webkit-image-set(url(data:image/png;base64,UE5HIERBVEE=) 1x, url(data:image/png;base64,MnggUE5HIERBVEE=) 2x); ++ } ++ ''')) ++ tmp_dir.CleanUp() ++ ++ def testThemeResources(self): ++ '''Tests inserting high DPI chrome://theme references.''' ++ ++ tmp_dir = util.TempDir({ ++ 'index.html': ''' ++ <!DOCTYPE HTML> ++ <html> ++ <head> ++ <link rel="stylesheet" href="test.css"> ++ </head> ++ <body> ++ <!-- Don't need a body. --> ++ </body> ++ </html> ++ ''', ++ ++ 'test.css': ''' ++ .image { ++ background: url('chrome://theme/IDR_RESOURCE_NAME'); ++ content: url('chrome://theme/IDR_RESOURCE_NAME_WITH_Q?$1'); ++ } ++ ''', ++ }) ++ ++ html = chrome_html.ChromeHtml(tmp_dir.GetPath('index.html')) ++ html.SetDefines({'scale_factors': '2x'}) ++ html.SetAttributes({'flattenhtml': 'true'}) ++ html.Parse() ++ self.failUnlessEqual(StandardizeHtml(html.GetData('en', 'utf-8')), ++ StandardizeHtml(''' ++ <!DOCTYPE HTML> ++ <html> ++ <head> ++ <style> ++ .image { ++ background: -webkit-image-set(url('chrome://theme/IDR_RESOURCE_NAME') 1x, url('chrome://theme/IDR_RESOURCE_NAME@2x') 2x); ++ content: -webkit-image-set(url('chrome://theme/IDR_RESOURCE_NAME_WITH_Q?$1') 1x, url('chrome://theme/IDR_RESOURCE_NAME_WITH_Q@2x?$1') 2x); ++ } ++ </style> ++ </head> ++ <body> ++ <!-- Don't need a body. --> ++ </body> ++ </html> ++ ''')) ++ tmp_dir.CleanUp() ++ ++ def testRemoveUnsupportedScale(self): ++ '''Tests removing an unsupported scale factor from an explicit image-set.''' ++ ++ tmp_dir = util.TempDir({ ++ 'index.html': ''' ++ <!DOCTYPE HTML> ++ <html> ++ <head> ++ <link rel="stylesheet" href="test.css"> ++ </head> ++ <body> ++ <!-- Don't need a body. --> ++ </body> ++ </html> ++ ''', ++ ++ 'test.css': ''' ++ .image { ++ background: -webkit-image-set(url('test.png') 1x, ++ url('test1.4.png') 1.4x, ++ url('test1.8.png') 1.8x); ++ } ++ ''', ++ ++ 'test.png': 'PNG DATA', ++ ++ 'test1.4.png': '1.4x PNG DATA', ++ ++ 'test1.8.png': '1.8x PNG DATA', ++ }) ++ ++ html = chrome_html.ChromeHtml(tmp_dir.GetPath('index.html')) ++ html.SetDefines({'scale_factors': '1.8x'}) ++ html.SetAttributes({'flattenhtml': 'true'}) ++ html.Parse() ++ self.failUnlessEqual(StandardizeHtml(html.GetData('en', 'utf-8')), ++ StandardizeHtml(''' ++ <!DOCTYPE HTML> ++ <html> ++ <head> ++ <style> ++ .image { ++ background: -webkit-image-set(url('data:image/png;base64,UE5HIERBVEE=') 1x, ++ url('data:image/png;base64,MS44eCBQTkcgREFUQQ==') 1.8x); ++ } ++ </style> ++ </head> ++ <body> ++ <!-- Don't need a body. --> ++ </body> ++ </html> ++ ''')) ++ tmp_dir.CleanUp() ++ ++ def testExpandVariablesInFilename(self): ++ ''' ++ Tests variable substitution in filenames while flattening images ++ with multiple scale factors. ++ ''' ++ ++ tmp_dir = util.TempDir({ ++ 'index.html': ''' ++ <!DOCTYPE HTML> ++ <html> ++ <head> ++ <link rel="stylesheet" href="test.css"> ++ </head> ++ <body> ++ <!-- Don't need a body. --> ++ </body> ++ </html> ++ ''', ++ ++ 'test.css': ''' ++ .image { ++ background: url('test[WHICH].png'); ++ } ++ ''', ++ ++ 'test1.png': 'PNG DATA', ++ '1.4x/test1.png': '1.4x PNG DATA', ++ '1.8x/test1.png': '1.8x PNG DATA', ++ }) ++ ++ def replacer(var, repl): ++ return lambda filename: filename.replace('[%s]' % var, repl) ++ ++ html = chrome_html.ChromeHtml(tmp_dir.GetPath('index.html')) ++ html.SetDefines({'scale_factors': '1.4x,1.8x'}) ++ html.SetAttributes({'flattenhtml': 'true'}) ++ html.SetFilenameExpansionFunction(replacer('WHICH', '1')); ++ html.Parse() ++ self.failUnlessEqual(StandardizeHtml(html.GetData('en', 'utf-8')), ++ StandardizeHtml(''' ++ <!DOCTYPE HTML> ++ <html> ++ <head> ++ <style> ++ .image { ++ background: -webkit-image-set(url('data:image/png;base64,UE5HIERBVEE=') 1x, url('data:image/png;base64,MS40eCBQTkcgREFUQQ==') 1.4x, url('data:image/png;base64,MS44eCBQTkcgREFUQQ==') 1.8x); ++ } ++ </style> ++ </head> ++ <body> ++ <!-- Don't need a body. --> ++ </body> ++ </html> ++ ''')) ++ tmp_dir.CleanUp() ++ ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/gather/chrome_scaled_image.py b/tools/grit/grit/gather/chrome_scaled_image.py +new file mode 100644 +index 0000000000..44f98cbcf0 +--- /dev/null ++++ b/tools/grit/grit/gather/chrome_scaled_image.py +@@ -0,0 +1,157 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Gatherer for <structure type="chrome_scaled_image">. ++''' ++ ++from __future__ import print_function ++ ++import os ++import struct ++ ++from grit import exception ++from grit import lazy_re ++from grit import util ++from grit.gather import interface ++ ++ ++_PNG_SCALE_CHUNK = b'\0\0\0\0csCl\xc1\x30\x60\x4d' ++ ++ ++def _RescaleImage(data, from_scale, to_scale): ++ if from_scale != to_scale: ++ assert from_scale == 100 ++ # Rather than rescaling the image we add a custom chunk directing Chrome to ++ # rescale it on load. Just append it to the PNG data since ++ # _MoveSpecialChunksToFront will move it later anyway. ++ data += _PNG_SCALE_CHUNK ++ return data ++ ++ ++_PNG_MAGIC = b'\x89PNG\r\n\x1a\n' ++ ++'''Mandatory first chunk in order for the png to be valid.''' ++_FIRST_CHUNK = b'IHDR' ++ ++'''Special chunks to move immediately after the IHDR chunk. (so that the PNG ++remains valid.) ++''' ++_SPECIAL_CHUNKS = frozenset(b'csCl npTc'.split()) ++ ++'''Any ancillary chunk not in this list is deleted from the PNG.''' ++_ANCILLARY_CHUNKS_TO_LEAVE = frozenset( ++ b'bKGD cHRM gAMA iCCP pHYs sBIT sRGB tRNS acTL fcTL fdAT'.split()) ++ ++ ++def _MoveSpecialChunksToFront(data): ++ '''Move special chunks immediately after the IHDR chunk (so that the PNG ++ remains valid). Also delete ancillary chunks that are not on our whitelist. ++ ''' ++ first = [_PNG_MAGIC] ++ special_chunks = [] ++ rest = [] ++ for chunk in _ChunkifyPNG(data): ++ type = chunk[4:8] ++ critical = type < b'a' ++ if type == _FIRST_CHUNK: ++ first.append(chunk) ++ elif type in _SPECIAL_CHUNKS: ++ special_chunks.append(chunk) ++ elif critical or type in _ANCILLARY_CHUNKS_TO_LEAVE: ++ rest.append(chunk) ++ return b''.join(first + special_chunks + rest) ++ ++ ++def _ChunkifyPNG(data): ++ '''Given a PNG image, yield its chunks in order.''' ++ assert data.startswith(_PNG_MAGIC) ++ pos = 8 ++ while pos != len(data): ++ length = 12 + struct.unpack_from('>I', data, pos)[0] ++ assert 12 <= length <= len(data) - pos ++ yield data[pos:pos+length] ++ pos += length ++ ++ ++def _MakeBraceGlob(strings): ++ '''Given ['foo', 'bar'], return '{foo,bar}', for error reporting. ++ ''' ++ if len(strings) == 1: ++ return strings[0] ++ else: ++ return '{' + ','.join(strings) + '}' ++ ++ ++class ChromeScaledImage(interface.GathererBase): ++ '''Represents an image that exists in multiple layout variants ++ (e.g. "default", "touch") and multiple scale variants ++ (e.g. "100_percent", "200_percent"). ++ ''' ++ ++ split_context_re_ = lazy_re.compile(r'(.+)_(\d+)_percent\Z') ++ ++ def _FindInputFile(self): ++ output_context = self.grd_node.GetRoot().output_context ++ match = self.split_context_re_.match(output_context) ++ if not match: ++ raise exception.MissingMandatoryAttribute( ++ 'All <output> nodes must have an appropriate context attribute' ++ ' (e.g. context="touch_200_percent")') ++ req_layout, req_scale = match.group(1), int(match.group(2)) ++ ++ layouts = [req_layout] ++ try_default_layout = self.grd_node.GetRoot().fallback_to_default_layout ++ if try_default_layout and 'default' not in layouts: ++ layouts.append('default') ++ ++ scales = [req_scale] ++ try_low_res = self.grd_node.FindBooleanAttribute( ++ 'fallback_to_low_resolution', default=False, skip_self=False) ++ if try_low_res and 100 not in scales: ++ scales.append(100) ++ ++ for layout in layouts: ++ for scale in scales: ++ dir = '%s_%s_percent' % (layout, scale) ++ path = os.path.join(dir, self.rc_file) ++ if os.path.exists(self.grd_node.ToRealPath(path)): ++ return path, scale, req_scale ++ ++ if not try_default_layout: ++ # The file was not found in the specified output context and it was ++ # explicitly indicated that the default context should not be searched ++ # as a fallback, so return an empty path. ++ return None, 100, req_scale ++ ++ # The file was found in neither the specified context nor the default ++ # context, so raise an exception. ++ dir = "%s_%s_percent" % (_MakeBraceGlob(layouts), ++ _MakeBraceGlob([str(x) for x in scales])) ++ raise exception.FileNotFound( ++ 'Tried ' + self.grd_node.ToRealPath(os.path.join(dir, self.rc_file))) ++ ++ def GetInputPath(self): ++ path, scale, req_scale = self._FindInputFile() ++ return path ++ ++ def Parse(self): ++ pass ++ ++ def GetTextualIds(self): ++ return [self.extkey] ++ ++ def GetData(self, lang, encoding): ++ assert encoding == util.BINARY ++ ++ path, scale, req_scale = self._FindInputFile() ++ if path is None: ++ return None ++ ++ data = util.ReadFile(self.grd_node.ToRealPath(path), util.BINARY) ++ data = _RescaleImage(data, scale, req_scale) ++ data = _MoveSpecialChunksToFront(data) ++ return data ++ ++ def Translate(self, *args, **kwargs): ++ return self.GetData() +diff --git a/tools/grit/grit/gather/chrome_scaled_image_unittest.py b/tools/grit/grit/gather/chrome_scaled_image_unittest.py +new file mode 100644 +index 0000000000..1cebfc6de2 +--- /dev/null ++++ b/tools/grit/grit/gather/chrome_scaled_image_unittest.py +@@ -0,0 +1,209 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for ChromeScaledImage.''' ++ ++from __future__ import print_function ++ ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ++ '../..'))) ++ ++import re ++import struct ++import unittest ++import zlib ++ ++from grit import exception ++from grit import util ++from grit.format import data_pack ++from grit.tool import build ++ ++ ++_OUTFILETYPES = [ ++ ('.h', 'rc_header'), ++ ('_map.cc', 'resource_map_source'), ++ ('_map.h', 'resource_map_header'), ++ ('.pak', 'data_package'), ++ ('.rc', 'rc_all'), ++] ++ ++ ++_PNG_HEADER = ( ++ b'\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52' ++ b'\x00\x00\x00\x01\x00\x00\x00\x01\x08\x02\x00\x00\x00\x90\x77\x53' ++ b'\xde') ++_PNG_FOOTER = ( ++ b'\x00\x00\x00\x0c\x49\x44\x41\x54\x18\x57\x63\xf8\xff\xff\x3f\x00' ++ b'\x05\xfe\x02\xfe\xa7\x35\x81\x84\x00\x00\x00\x00\x49\x45\x4e\x44' ++ b'\xae\x42\x60\x82') ++ ++ ++def _MakePNG(chunks): ++ # Python 3 changed the return value of zlib.crc32 to an unsigned int. ++ format = 'i' if sys.version_info.major < 3 else 'I' ++ pack_int32 = struct.Struct('>' + format).pack ++ chunks = [pack_int32(len(payload)) + type + payload + ++ pack_int32(zlib.crc32(type + payload)) ++ for type, payload in chunks] ++ return _PNG_HEADER + b''.join(chunks) + _PNG_FOOTER ++ ++ ++def _GetFilesInPak(pakname): ++ '''Get a set of the files that were actually included in the .pak output. ++ ''' ++ return set(data_pack.ReadDataPack(pakname).resources.values()) ++ ++ ++def _GetFilesInRc(rcname, tmp_dir, contents): ++ '''Get a set of the files that were actually included in the .rc output. ++ ''' ++ data = util.ReadFile(rcname, util.BINARY).decode('utf-16') ++ contents = dict((tmp_dir.GetPath(k), v) for k, v in contents.items()) ++ return set(contents[os.path.normpath(m.group(1))] ++ for m in re.finditer(r'(?m)^\w+\s+BINDATA\s+"([^"]+)"$', data)) ++ ++ ++def _MakeFallbackAttr(fallback): ++ if fallback is None: ++ return '' ++ else: ++ return ' fallback_to_low_resolution="%s"' % ('false', 'true')[fallback] ++ ++ ++def _Structures(fallback, *body): ++ return '<structures%s>\n%s\n</structures>' % ( ++ _MakeFallbackAttr(fallback), '\n'.join(body)) ++ ++ ++def _Structure(name, file, fallback=None): ++ return '<structure name="%s" file="%s" type="chrome_scaled_image"%s />' % ( ++ name, file, _MakeFallbackAttr(fallback)) ++ ++ ++def _If(expr, *body): ++ return '<if expr="%s">\n%s\n</if>' % (expr, '\n'.join(body)) ++ ++ ++def _RunBuildTest(self, structures, inputs, expected_outputs, skip_rc=False, ++ layout_fallback=''): ++ outputs = '\n'.join('<output filename="out/%s%s" type="%s" context="%s"%s />' ++ % (context, ext, type, context, layout_fallback) ++ for ext, type in _OUTFILETYPES ++ for context in expected_outputs) ++ ++ infiles = { ++ 'in/in.grd': ('''<?xml version="1.0" encoding="UTF-8"?> ++ <grit latest_public_release="0" current_release="1"> ++ <outputs> ++ %s ++ </outputs> ++ <release seq="1"> ++ %s ++ </release> ++ </grit> ++ ''' % (outputs, structures)).encode('utf-8'), + } ++ for pngpath, pngdata in inputs.items(): ++ normpath = os.path.normpath('in/' + pngpath) ++ infiles[normpath] = pngdata ++ class Options(object): ++ pass ++ ++ with util.TempDir(infiles, mode='wb') as tmp_dir: ++ with tmp_dir.AsCurrentDir(): ++ options = Options() ++ options.input = tmp_dir.GetPath('in/in.grd') ++ options.verbose = False ++ options.extra_verbose = False ++ build.RcBuilder().Run(options, []) ++ for context, expected_data in expected_outputs.items(): ++ self.assertEquals(expected_data, ++ _GetFilesInPak(tmp_dir.GetPath('out/%s.pak' % context))) ++ if not skip_rc: ++ self.assertEquals(expected_data, ++ _GetFilesInRc(tmp_dir.GetPath('out/%s.rc' % context), ++ tmp_dir, infiles)) ++ ++ ++class ChromeScaledImageUnittest(unittest.TestCase): ++ def testNormalFallback(self): ++ d123a = _MakePNG([(b'AbCd', b'')]) ++ t123a = _MakePNG([(b'EfGh', b'')]) ++ d123b = _MakePNG([(b'IjKl', b'')]) ++ _RunBuildTest(self, ++ _Structures(None, ++ _Structure('IDR_A', 'a.png'), ++ _Structure('IDR_B', 'b.png'), ++ ), ++ {'default_123_percent/a.png': d123a, ++ 'tactile_123_percent/a.png': t123a, ++ 'default_123_percent/b.png': d123b, ++ }, ++ {'default_123_percent': set([d123a, d123b]), ++ 'tactile_123_percent': set([t123a, d123b]), ++ }) ++ ++ def testNormalFallbackFailure(self): ++ self.assertRaises( ++ exception.FileNotFound, _RunBuildTest, self, ++ _Structures( ++ None, ++ _Structure('IDR_A', 'a.png'), ++ ), { ++ 'default_100_percent/a.png': _MakePNG([(b'AbCd', b'')]), ++ 'tactile_100_percent/a.png': _MakePNG([(b'EfGh', b'')]), ++ }, {'tactile_123_percent': 'should fail before using this'}) ++ ++ def testLowresFallback(self): ++ png = _MakePNG([(b'Abcd', b'')]) ++ png_with_csCl = _MakePNG([(b'csCl', b''), (b'Abcd', b'')]) ++ for outer in (None, False, True): ++ for inner in (None, False, True): ++ args = ( ++ self, ++ _Structures(outer, ++ _Structure('IDR_A', 'a.png', inner), ++ ), ++ {'default_100_percent/a.png': png}, ++ {'tactile_200_percent': set([png_with_csCl])}) ++ if inner or (inner is None and outer): ++ # should fall back to 100% ++ _RunBuildTest(*args, skip_rc=True) ++ else: ++ # shouldn't fall back ++ self.assertRaises(exception.FileNotFound, _RunBuildTest, *args) ++ ++ # Test fallback failure with fallback_to_low_resolution=True ++ self.assertRaises(exception.FileNotFound, ++ _RunBuildTest, self, ++ _Structures(True, ++ _Structure('IDR_A', 'a.png'), ++ ), ++ {}, # no files ++ {'tactile_123_percent': 'should fail before using this'}) ++ ++ def testNoFallbackToDefaultLayout(self): ++ d123a = _MakePNG([(b'AbCd', b'')]) ++ t123a = _MakePNG([(b'EfGh', b'')]) ++ d123b = _MakePNG([(b'IjKl', b'')]) ++ _RunBuildTest(self, ++ _Structures(None, ++ _Structure('IDR_A', 'a.png'), ++ _Structure('IDR_B', 'b.png'), ++ ), ++ {'default_123_percent/a.png': d123a, ++ 'tactile_123_percent/a.png': t123a, ++ 'default_123_percent/b.png': d123b, ++ }, ++ {'default_123_percent': set([d123a, d123b]), ++ 'tactile_123_percent': set([t123a]), ++ }, ++ layout_fallback=' fallback_to_default_layout="false"') + -+ virtual bool ParseArgs(const CompilerInstance& instance, -+ const std::vector<std::string>& args) { -+ bool parsed = true; ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/gather/interface.py b/tools/grit/grit/gather/interface.py +new file mode 100644 +index 0000000000..15d64f9326 +--- /dev/null ++++ b/tools/grit/grit/gather/interface.py +@@ -0,0 +1,172 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+ for (size_t i = 0; i < args.size() && parsed; ++i) { -+ if (args[i] == "skip-refcounted-dtors") { -+ check_refcounted_dtors_ = false; -+ } else if (args[i] == "skip-virtuals-in-implementations") { -+ check_virtuals_in_implementations_ = false; -+ } else { -+ parsed = false; -+ llvm::errs() << "Unknown argument: " << args[i] << "\n"; ++'''Interface for all gatherers. ++''' ++ ++from __future__ import print_function ++ ++import os.path ++ ++import six ++ ++from grit import clique ++from grit import util ++ ++ ++class GathererBase(object): ++ '''Interface for all gatherer implementations. Subclasses must implement ++ all methods that raise NotImplemented.''' ++ ++ def __init__(self, rc_file, extkey=None, encoding='cp1252', is_skeleton=False): ++ '''Initializes the gatherer object's attributes, but does not attempt to ++ read the input file. ++ ++ Args: ++ rc_file: The 'file' attribute of the <structure> node (usually the ++ relative path to the source file). ++ extkey: e.g. 'ID_MY_DIALOG' ++ encoding: e.g. 'utf-8' ++ is_skeleton: Indicates whether this gatherer is a skeleton gatherer, in ++ which case we should not do some types of processing on the ++ translateable bits. ++ ''' ++ self.rc_file = rc_file ++ self.extkey = extkey ++ self.encoding = encoding ++ # A default uberclique that is local to this object. Users can override ++ # this with the uberclique they are using. ++ self.uberclique = clique.UberClique() ++ # Indicates whether this gatherer is a skeleton gatherer, in which case ++ # we should not do some types of processing on the translateable bits. ++ self.is_skeleton = is_skeleton ++ # Stores the grd node on which this gatherer is running. This allows ++ # evaluating expressions. ++ self.grd_node = None ++ ++ def SetAttributes(self, attrs): ++ '''Sets node attributes used by the gatherer. ++ ++ By default, this does nothing. If special handling is desired, it should be ++ overridden by the child gatherer. ++ ++ Args: ++ attrs: The mapping of node attributes. ++ ''' ++ pass ++ ++ def SetDefines(self, defines): ++ '''Sets global defines used by the gatherer. ++ ++ By default, this does nothing. If special handling is desired, it should be ++ overridden by the child gatherer. ++ ++ Args: ++ defines: The mapping of define values. ++ ''' ++ pass ++ ++ def SetGrdNode(self, node): ++ '''Sets the grd node on which this gatherer is running. ++ ''' ++ self.grd_node = node ++ ++ def SetUberClique(self, uberclique): ++ '''Overrides the default uberclique so that cliques created by this object ++ become part of the uberclique supplied by the user. ++ ''' ++ self.uberclique = uberclique ++ ++ def Parse(self): ++ '''Reads and parses the contents of what is being gathered.''' ++ raise NotImplementedError() ++ ++ def GetData(self, lang, encoding): ++ '''Returns the data to be added to the DataPack for this node or None if ++ this node does not add a DataPack entry. ++ ''' ++ return None ++ ++ def GetText(self): ++ '''Returns the text of what is being gathered.''' ++ raise NotImplementedError() ++ ++ def GetTextualIds(self): ++ '''Returns the mnemonic IDs that need to be defined for the resource ++ being gathered to compile correctly.''' ++ return [] ++ ++ def GetCliques(self): ++ '''Returns the MessageClique objects for all translateable portions.''' ++ return [] ++ ++ def GetInputPath(self): ++ return self.rc_file ++ ++ def GetHtmlResourceFilenames(self): ++ """Returns a set of all filenames inlined by this gatherer.""" ++ return [] ++ ++ def Translate(self, lang, pseudo_if_not_available=True, ++ skeleton_gatherer=None, fallback_to_english=False): ++ '''Returns the resource being gathered, with translateable portions filled ++ with the translation for language 'lang'. ++ ++ If pseudo_if_not_available is true, a pseudotranslation will be used for any ++ message that doesn't have a real translation available. ++ ++ If no translation is available and pseudo_if_not_available is false, ++ fallback_to_english controls the behavior. If it is false, throw an error. ++ If it is true, use the English version of the message as its own ++ "translation". ++ ++ If skeleton_gatherer is specified, the translation will use the nontranslateable ++ parts from the gatherer 'skeleton_gatherer', which must be of the same type ++ as 'self'. ++ ++ If fallback_to_english ++ ++ Args: ++ lang: 'en' ++ pseudo_if_not_available: True | False ++ skeleton_gatherer: other_gatherer ++ fallback_to_english: True | False ++ ++ Return: ++ e.g. 'ID_THIS_SECTION TYPE\n...BEGIN\n "Translated message"\n......\nEND' ++ ++ Raises: ++ grit.exception.NotReady() if used before Parse() has been successfully ++ called. ++ grit.exception.NoSuchTranslation() if 'pseudo_if_not_available' and ++ fallback_to_english are both false and there is no translation for the ++ requested language. ++ ''' ++ raise NotImplementedError() ++ ++ def SubstituteMessages(self, substituter): ++ '''Applies substitutions to all messages in the gatherer. ++ ++ Args: ++ substituter: a grit.util.Substituter object. ++ ''' ++ pass ++ ++ def SetFilenameExpansionFunction(self, fn): ++ '''Sets a function for rewriting filenames before gathering.''' ++ pass ++ ++ # TODO(benrg): Move this elsewhere, since it isn't part of the interface. ++ def _LoadInputFile(self): ++ '''A convenience function for subclasses that loads the contents of the ++ input file. ++ ''' ++ if isinstance(self.rc_file, six.string_types): ++ path = self.GetInputPath() ++ # Hack: some unit tests supply an absolute path and no root node. ++ if not os.path.isabs(path): ++ path = self.grd_node.ToRealPath(path) ++ return util.ReadFile(path, self.encoding) ++ else: ++ return self.rc_file.read() +diff --git a/tools/grit/grit/gather/json_loader.py b/tools/grit/grit/gather/json_loader.py +new file mode 100644 +index 0000000000..058e5f17ae +--- /dev/null ++++ b/tools/grit/grit/gather/json_loader.py +@@ -0,0 +1,27 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++from __future__ import print_function ++ ++from grit.gather import interface ++ ++ ++class JsonLoader(interface.GathererBase): ++ '''A simple gatherer that loads and parses a JSON file.''' ++ ++ def Parse(self): ++ '''Reads and parses the text of self._json_text into the data structure in ++ self._data. ++ ''' ++ self._json_text = self._LoadInputFile() ++ self._data = None ++ ++ globs = {} ++ exec('data = ' + self._json_text, globs) ++ self._data = globs['data'] ++ ++ def GetData(self, lang, encoding): ++ '''Returns the parsed JSON data.''' ++ assert encoding == 'utf-8' ++ return self._data +diff --git a/tools/grit/grit/gather/policy_json.py b/tools/grit/grit/gather/policy_json.py +new file mode 100644 +index 0000000000..6621c5f3c4 +--- /dev/null ++++ b/tools/grit/grit/gather/policy_json.py +@@ -0,0 +1,325 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Support for "policy_templates.json" format used by the policy template ++generator as a source for generating ADM,ADMX,etc files.''' ++ ++from __future__ import print_function ++ ++import json ++import sys ++ ++import six ++ ++from grit.gather import skeleton_gatherer ++from grit import util ++from grit import tclib ++from xml.dom import minidom ++from xml.parsers.expat import ExpatError ++ ++ ++class PolicyJson(skeleton_gatherer.SkeletonGatherer): ++ '''Collects and translates the following strings from policy_templates.json: ++ - captions, descriptions, labels and Android app support details of policies ++ - captions of enumeration items ++ - misc strings from the 'messages' section ++ Translatable strings may have untranslateable placeholders with the same ++ format that is used in .grd files. ++ ''' ++ ++ def _AddEndline(self, add_comma): ++ '''Adds an endline to the skeleton tree. If add_comma is true, adds a ++ comma before the endline. ++ ++ Args: ++ add_comma: A boolean to add a comma or not. ++ ''' ++ self._AddNontranslateableChunk(',\n' if add_comma else '\n') ++ ++ def _ParsePlaceholder(self, placeholder, msg): ++ '''Extracts a placeholder from a DOM node and adds it to a tclib Message. ++ ++ Args: ++ placeholder: A DOM node of the form: ++ <ph name="PLACEHOLDER_NAME">Placeholder text<ex>Example value</ex></ph> ++ msg: The placeholder is added to this message. ++ ''' ++ text = [] ++ example_text = [] ++ for node1 in placeholder.childNodes: ++ if (node1.nodeType == minidom.Node.TEXT_NODE): ++ text.append(node1.data) ++ elif (node1.nodeType == minidom.Node.ELEMENT_NODE and ++ node1.tagName == 'ex'): ++ for node2 in node1.childNodes: ++ example_text.append(node2.toxml()) ++ else: ++ raise Exception('Unexpected element inside a placeholder: ' + ++ node2.toxml()) ++ if example_text == []: ++ # In such cases the original text is okay for an example. ++ example_text = text ++ ++ replaced_text = self.Escape(''.join(text).strip()) ++ replaced_text = replaced_text.replace('$1', self._config['app_name']) ++ replaced_text = replaced_text.replace('$2', self._config['os_name']) ++ replaced_text = replaced_text.replace('$3', self._config['frame_name']) ++ ++ msg.AppendPlaceholder(tclib.Placeholder( ++ placeholder.attributes['name'].value, ++ replaced_text, ++ ''.join(example_text).strip())) ++ ++ def _ParseMessage(self, string, desc): ++ '''Parses a given string and adds it to the output as a translatable chunk ++ with a given description. ++ ++ Args: ++ string: The message string to parse. ++ desc: The description of the message (for the translators). ++ ''' ++ msg = tclib.Message(description=desc) ++ xml = '<msg>' + string + '</msg>' ++ try: ++ node = minidom.parseString(xml).childNodes[0] ++ except ExpatError: ++ reason = '''Input isn't valid XML (has < & > been escaped?): ''' + string ++ six.reraise(Exception, reason, sys.exc_info()[2]) ++ ++ for child in node.childNodes: ++ if child.nodeType == minidom.Node.TEXT_NODE: ++ msg.AppendText(child.data) ++ elif child.nodeType == minidom.Node.ELEMENT_NODE: ++ if child.tagName == 'ph': ++ self._ParsePlaceholder(child, msg) ++ else: ++ raise Exception("Not implemented.") ++ else: ++ raise Exception("Not implemented.") ++ self.skeleton_.append(self.uberclique.MakeClique(msg)) ++ ++ def _ParseNode(self, node): ++ '''Traverses the subtree of a DOM node, and register a tclib message for ++ all the <message> nodes. ++ ''' ++ att_text = [] ++ if node.attributes: ++ for key, value in sorted(node.attributes.items()): ++ att_text.append(' %s=\"%s\"' % (key, value)) ++ self._AddNontranslateableChunk("<%s%s>" % ++ (node.tagName, ''.join(att_text))) ++ if node.tagName == 'message': ++ msg = tclib.Message(description=node.attributes['desc']) ++ for child in node.childNodes: ++ if child.nodeType == minidom.Node.TEXT_NODE: ++ if msg == None: ++ self._AddNontranslateableChunk(child.data) ++ else: ++ msg.AppendText(child.data) ++ elif child.nodeType == minidom.Node.ELEMENT_NODE: ++ if child.tagName == 'ph': ++ self._ParsePlaceholder(child, msg) ++ else: ++ assert False ++ self.skeleton_.append(self.uberclique.MakeClique(msg)) ++ else: ++ for child in node.childNodes: ++ if child.nodeType == minidom.Node.TEXT_NODE: ++ self._AddNontranslateableChunk(child.data) ++ elif node.nodeType == minidom.Node.ELEMENT_NODE: ++ self._ParseNode(child) ++ ++ self._AddNontranslateableChunk("</%s>" % node.tagName) ++ ++ def _AddIndentedNontranslateableChunk(self, depth, string): ++ '''Adds a nontranslateable chunk of text to the internally stored output. ++ ++ Args: ++ depth: The number of double spaces to prepend to the next argument string. ++ string: The chunk of text to add. ++ ''' ++ result = [] ++ while depth > 0: ++ result.append(' ') ++ depth = depth - 1 ++ result.append(string) ++ self._AddNontranslateableChunk(''.join(result)) ++ ++ def _GetDescription(self, item, item_type, parent_item, key): ++ '''Creates a description for a translatable message. The description gives ++ some context for the person who will translate this message. ++ ++ Args: ++ item: A policy or an enumeration item. ++ item_type: 'enum_item' | 'policy' ++ parent_item: The owner of item. (A policy of type group or enum.) ++ key: The name of the key to parse. ++ depth: The level of indentation. ++ ''' ++ key_map = { ++ 'desc': 'Description', ++ 'caption': 'Caption', ++ 'label': 'Label', ++ 'arc_support': 'Information about the effect on Android apps' ++ } ++ if item_type == 'policy': ++ return ('%s of the policy named %s [owner(s): %s]' % ++ (key_map[key], item['name'], ++ ','.join(item['owners'] if 'owners' in item else 'unknown'))) ++ if item_type == 'enum_item': ++ return ('%s of the option named %s in policy %s [owner(s): %s]' % ++ (key_map[key], item['name'], parent_item['name'], ++ ','.join(parent_item['owners'] if 'owners' in parent_item else 'unknown'))) ++ raise Exception('Unexpected type %s' % item_type) ++ ++ def _AddSchemaKeys(self, obj, depth): ++ obj_type = type(obj) ++ if obj_type == dict: ++ self._AddNontranslateableChunk('{\n') ++ keys = sorted(obj.keys()) ++ for count, (key) in enumerate(keys, 1): ++ json_key = "%s: " % json.dumps(key) ++ self._AddIndentedNontranslateableChunk(depth + 1, json_key) ++ if key == 'description' and type(obj[key]) == str: ++ self._AddNontranslateableChunk("\"") ++ self._ParseMessage(obj[key], 'Description of schema property') ++ self._AddNontranslateableChunk("\"") ++ elif type(obj[key]) in (bool, int, str): ++ self._AddSchemaKeys(obj[key], 0) ++ else: ++ self._AddSchemaKeys(obj[key], depth + 1) ++ self._AddEndline(count < len(keys)) ++ self._AddIndentedNontranslateableChunk(depth, '}') ++ elif obj_type == list: ++ self._AddNontranslateableChunk('[\n') ++ for count, (item) in enumerate(obj, 1): ++ self._AddSchemaKeys(item, depth + 1) ++ self._AddEndline(count < len(obj)) ++ self._AddIndentedNontranslateableChunk(depth, ']') ++ elif obj_type in (bool, int, str): ++ self._AddIndentedNontranslateableChunk(depth, json.dumps(obj)) ++ else: ++ raise Exception('Invalid schema object: %s' % obj) ++ ++ def _AddPolicyKey(self, item, item_type, parent_item, key, depth): ++ '''Given a policy/enumeration item and a key, adds that key and its value ++ into the output. ++ E.g.: ++ 'example_value': 123 ++ If key indicates that the value is a translatable string, then it is parsed ++ as a translatable string. ++ ++ Args: ++ item: A policy or an enumeration item. ++ item_type: 'enum_item' | 'policy' ++ parent_item: The owner of item. (A policy of type group or enum.) ++ key: The name of the key to parse. ++ depth: The level of indentation. ++ ''' ++ self._AddIndentedNontranslateableChunk(depth, "%s: " % json.dumps(key)) ++ if key in ('desc', 'caption', 'label', 'arc_support'): ++ self._AddNontranslateableChunk("\"") ++ self._ParseMessage( ++ item[key], ++ self._GetDescription(item, item_type, parent_item, key)) ++ self._AddNontranslateableChunk("\"") ++ elif key in ('schema', 'validation_schema', 'description_schema'): ++ self._AddSchemaKeys(item[key], depth) ++ else: ++ self._AddNontranslateableChunk(json.dumps(item[key], ensure_ascii=False)) ++ ++ def _AddItems(self, items, item_type, parent_item, depth): ++ '''Parses and adds a list of items from the JSON file. Items can be policies ++ or parts of an enum policy. ++ ++ Args: ++ items: Either a list of policies or a list of dictionaries. ++ item_type: 'enum_item' | 'policy' ++ parent_item: If items contains a list of policies, then this is the policy ++ group that owns them. If items contains a list of enumeration items, ++ then this is the enum policy that holds them. ++ depth: Indicates the depth of our position in the JSON hierarchy. Used to ++ add nice line-indent to the output. ++ ''' ++ for item_count, (item1) in enumerate(items, 1): ++ self._AddIndentedNontranslateableChunk(depth, "{\n") ++ keys = sorted(item1.keys()) ++ for keys_count, (key) in enumerate(keys, 1): ++ if key == 'items': ++ self._AddIndentedNontranslateableChunk(depth + 1, "\"items\": [\n") ++ self._AddItems(item1['items'], 'enum_item', item1, depth + 2) ++ self._AddIndentedNontranslateableChunk(depth + 1, "]") ++ elif key == 'policies' and all(not isinstance(x, str) ++ for x in item1['policies']): ++ self._AddIndentedNontranslateableChunk(depth + 1, "\"policies\": [\n") ++ self._AddItems(item1['policies'], 'policy', item1, depth + 2) ++ self._AddIndentedNontranslateableChunk(depth + 1, "]") ++ else: ++ self._AddPolicyKey(item1, item_type, parent_item, key, depth + 1) ++ self._AddEndline(keys_count < len(keys)) ++ self._AddIndentedNontranslateableChunk(depth, "}") ++ self._AddEndline(item_count < len(items)) ++ ++ def _AddMessages(self): ++ '''Processed and adds the 'messages' section to the output.''' ++ self._AddNontranslateableChunk(" \"messages\": {\n") ++ messages = self.data['messages'].items() ++ for count, (name, message) in enumerate(messages, 1): ++ self._AddNontranslateableChunk(" %s: {\n" % json.dumps(name)) ++ self._AddNontranslateableChunk(" \"text\": \"") ++ self._ParseMessage(message['text'], message['desc']) ++ self._AddNontranslateableChunk("\"\n") ++ self._AddNontranslateableChunk(" }") ++ self._AddEndline(count < len(self.data['messages'])) ++ self._AddNontranslateableChunk(" }\n") ++ ++ # Although we use the RegexpGatherer base class, we do not use the ++ # _RegExpParse method of that class to implement Parse(). Instead, we ++ # parse using a DOM parser. ++ def Parse(self): ++ if self.have_parsed_: ++ return ++ self.have_parsed_ = True ++ ++ self.text_ = self._LoadInputFile() ++ if util.IsExtraVerbose(): ++ print(self.text_) ++ ++ self.data = eval(self.text_) ++ ++ self._AddNontranslateableChunk('{\n') ++ self._AddNontranslateableChunk(" \"policy_definitions\": [\n") ++ self._AddItems(self.data['policy_definitions'], 'policy', None, 2) ++ self._AddNontranslateableChunk(" ],\n") ++ self._AddNontranslateableChunk(" \"policy_atomic_group_definitions\": [\n") ++ if 'policy_atomic_group_definitions' in self.data: ++ self._AddItems(self.data['policy_atomic_group_definitions'], ++ 'policy', None, 2) ++ self._AddNontranslateableChunk(" ],\n") ++ self._AddMessages() ++ self._AddNontranslateableChunk('\n}') ++ ++ def Escape(self, text): ++ return json.dumps(text, ensure_ascii=False)[1:-1] ++ ++ def SetDefines(self, defines): ++ if not defines: ++ raise Exception('Must pass valid defines') ++ ++ if '_chromium' in defines: ++ self._config = { ++ 'build': 'chromium', ++ 'app_name': 'Chromium', ++ 'frame_name': 'Chromium Frame', ++ 'os_name': 'Chromium OS', + } ++ elif '_google_chrome' in defines: ++ self._config = { ++ 'build': 'chrome', ++ 'app_name': 'Google Chrome', ++ 'frame_name': 'Google Chrome Frame', ++ 'os_name': 'Google Chrome OS', ++ } ++ else: ++ raise Exception('Unknown build') +diff --git a/tools/grit/grit/gather/policy_json_unittest.py b/tools/grit/grit/gather/policy_json_unittest.py +new file mode 100644 +index 0000000000..214cd276aa +--- /dev/null ++++ b/tools/grit/grit/gather/policy_json_unittest.py +@@ -0,0 +1,347 @@ ++#!/usr/bin/env python ++# Copyright (c) 2011 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for grit.gather.policy_json''' ++ ++from __future__ import print_function ++ ++import json ++import os ++import re ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++import unittest ++ ++from six import StringIO ++ ++from grit.gather import policy_json ++ ++class PolicyJsonUnittest(unittest.TestCase): ++ ++ def GetExpectedOutput(self, original): ++ expected = eval(original) ++ for key, message in expected['messages'].items(): ++ del message['desc'] ++ return expected ++ ++ def testEmpty(self): ++ original = """{ ++ 'policy_definitions': [], ++ 'policy_atomic_group_definitions': [], ++ 'messages': {} ++ }""" ++ gatherer = policy_json.PolicyJson(StringIO(original)) ++ gatherer.Parse() ++ self.failUnless(len(gatherer.GetCliques()) == 0) ++ self.failUnless(eval(original) == json.loads(gatherer.Translate('en'))) ++ ++ def testGeneralPolicy(self): ++ original = ( ++ "{" ++ " 'policy_definitions': [" ++ " {" ++ " 'name': 'HomepageLocation'," ++ " 'type': 'string'," ++ " 'owners': ['foo@bar.com']," ++ " 'supported_on': ['chrome.*:8-']," ++ " 'features': {'dynamic_refresh': 1}," ++ " 'example_value': 'http://chromium.org'," ++ " 'caption': 'nothing special 1'," ++ " 'desc': 'nothing special 2'," ++ " 'label': 'nothing special 3'," ++ " }," ++ " ]," ++ " 'policy_atomic_group_definitions': []," ++ " 'messages': {" ++ " 'msg_identifier': {" ++ " 'text': 'nothing special 3'," ++ " 'desc': 'nothing special descr 3'," ++ " }" ++ " }" ++ "}") ++ gatherer = policy_json.PolicyJson(StringIO(original)) ++ gatherer.Parse() ++ self.failUnless(len(gatherer.GetCliques()) == 4) ++ expected = self.GetExpectedOutput(original) ++ self.failUnless(expected == json.loads(gatherer.Translate('en'))) ++ ++ def testEnum(self): ++ original = ( ++ "{" ++ " 'policy_definitions': [" ++ " {" ++ " 'name': 'Policy1'," ++ " 'owners': ['a@b']," ++ " 'items': [" ++ " {" ++ " 'name': 'Item1'," ++ " 'caption': 'nothing special'," ++ " }" ++ " ]" ++ " }," ++ " ]," ++ " 'policy_atomic_group_definitions': []," ++ " 'messages': {}" ++ "}") ++ gatherer = policy_json.PolicyJson(StringIO(original)) ++ gatherer.Parse() ++ self.failUnless(len(gatherer.GetCliques()) == 1) ++ expected = self.GetExpectedOutput(original) ++ self.failUnless(expected == json.loads(gatherer.Translate('en'))) ++ ++ def testSchema(self): ++ original = ("{" ++ " 'policy_definitions': [" ++ " {" ++ " 'name': 'Policy1'," ++ " 'schema': {" ++ " 'type': 'object'," ++ " 'properties': {" ++ " 'outer': {" ++ " 'description': 'outer description'," ++ " 'type': 'object'," ++ " 'inner': {" ++ " 'description': 'inner description'," ++ " 'type': 'integer', 'minimum': 0, 'maximum': 100" ++ " }," ++ " 'inner2': {" ++ " 'description': 'inner2 description'," ++ " 'type': 'integer'," ++ " 'enum': [ 1, 2, 3 ]," ++ " 'sensitiveValue': True" ++ " }," ++ " }," ++ " }," ++ " }," ++ " 'caption': 'nothing special'," ++ " 'owners': ['a@b']" ++ " }," ++ " ]," ++ " 'policy_atomic_group_definitions': []," ++ " 'messages': {}" ++ "}") ++ gatherer = policy_json.PolicyJson(StringIO(original)) ++ gatherer.Parse() ++ self.failUnless(len(gatherer.GetCliques()) == 4) ++ expected = self.GetExpectedOutput(original) ++ self.failUnless(expected == json.loads(gatherer.Translate('en'))) ++ ++ def testValidationSchema(self): ++ original = ("{" ++ " 'policy_definitions': [" ++ " {" ++ " 'name': 'Policy1'," ++ " 'owners': ['a@b']," ++ " 'validation_schema': {" ++ " 'type': 'object'," ++ " 'properties': {" ++ " 'description': 'properties description'," ++ " 'type': 'object'," ++ " }," ++ " }," ++ " }," ++ " ]," ++ " 'policy_atomic_group_definitions': []," ++ " 'messages': {}" ++ "}") ++ gatherer = policy_json.PolicyJson(StringIO(original)) ++ gatherer.Parse() ++ self.failUnless(len(gatherer.GetCliques()) == 1) ++ expected = self.GetExpectedOutput(original) ++ self.failUnless(expected == json.loads(gatherer.Translate('en'))) ++ ++ def testDescriptionSchema(self): ++ original = ("{" ++ " 'policy_definitions': [" ++ " {" ++ " 'name': 'Policy1'," ++ " 'owners': ['a@b']," ++ " 'description_schema': {" ++ " 'type': 'object'," ++ " 'properties': {" ++ " 'description': 'properties description'," ++ " 'type': 'object'," ++ " }," ++ " }," ++ " }," ++ " ]," ++ " 'policy_atomic_group_definitions': []," ++ " 'messages': {}" ++ "}") ++ gatherer = policy_json.PolicyJson(StringIO(original)) ++ gatherer.Parse() ++ self.failUnless(len(gatherer.GetCliques()) == 1) ++ expected = self.GetExpectedOutput(original) ++ self.failUnless(expected == json.loads(gatherer.Translate('en'))) ++ ++ # Keeping for backwards compatibility. ++ def testSubPolicyOldFormat(self): ++ original = ( ++ "{" ++ " 'policy_definitions': [" ++ " {" ++ " 'type': 'group'," ++ " 'policies': [" ++ " {" ++ " 'name': 'Policy1'," ++ " 'caption': 'nothing special'," ++ " 'owners': ['a@b']" ++ " }" ++ " ]" ++ " }" ++ " ]," ++ " 'policy_atomic_group_definitions': []," ++ " 'messages': {}" ++ "}") ++ gatherer = policy_json.PolicyJson(StringIO(original)) ++ gatherer.Parse() ++ self.failUnless(len(gatherer.GetCliques()) == 1) ++ expected = self.GetExpectedOutput(original) ++ self.failUnless(expected == json.loads(gatherer.Translate('en'))) ++ ++ def testSubPolicyNewFormat(self): ++ original = ( ++ "{" ++ " 'policy_definitions': [" ++ " {" ++ " 'type': 'group'," ++ " 'policies': ['Policy1']" ++ " }," ++ " {" ++ " 'name': 'Policy1'," ++ " 'caption': 'nothing special'," ++ " 'owners': ['a@b']" ++ " }" ++ " ]," ++ " 'policy_atomic_group_definitions': []," ++ " 'messages': {}" ++ "}") ++ gatherer = policy_json.PolicyJson(StringIO(original)) ++ gatherer.Parse() ++ self.failUnless(len(gatherer.GetCliques()) == 1) ++ expected = self.GetExpectedOutput(original) ++ self.failUnless(expected == json.loads(gatherer.Translate('en'))) ++ ++ def testEscapingAndLineBreaks(self): ++ original = """{ ++ 'policy_definitions': [], ++ 'policy_atomic_group_definitions': [], ++ 'messages': { ++ 'msg1': { ++ # The following line will contain two backslash characters when it ++ # ends up in eval(). ++ 'text': '''backslashes, Sir? \\\\''', ++ 'desc': '' ++ }, ++ 'msg2': { ++ 'text': '''quotes, Madam? "''', ++ 'desc': '' ++ }, ++ 'msg3': { ++ # The following line will contain two backslash characters when it ++ # ends up in eval(). ++ 'text': 'backslashes, Sir? \\\\', ++ 'desc': '' ++ }, ++ 'msg4': { ++ 'text': "quotes, Madam? '", ++ 'desc': '' ++ }, ++ 'msg5': { ++ 'text': '''what happens ++with a newline?''', ++ 'desc': '' ++ }, ++ 'msg6': { ++ # The following line will contain a backslash+n when it ends up in ++ # eval(). ++ 'text': 'what happens\\nwith a newline? (Episode 1)', ++ 'desc': '' ++ } ++ } ++}""" ++ gatherer = policy_json.PolicyJson(StringIO(original)) ++ gatherer.Parse() ++ self.failUnless(len(gatherer.GetCliques()) == 6) ++ expected = self.GetExpectedOutput(original) ++ self.failUnless(expected == json.loads(gatherer.Translate('en'))) ++ ++ def testPlaceholdersChromium(self): ++ original = """{ ++ "policy_definitions": [ ++ { ++ "name": "Policy1", ++ "caption": "Please install\\n<ph name=\\"PRODUCT_NAME\\">$1<ex>Google Chrome</ex></ph>.", ++ "owners": "a@b" ++ } ++ ], ++ "policy_atomic_group_definitions": [], ++ "messages": {} ++}""" ++ gatherer = policy_json.PolicyJson(StringIO(original)) ++ gatherer.SetDefines({'_chromium': True}) ++ gatherer.Parse() ++ self.failUnless(len(gatherer.GetCliques()) == 1) ++ expected = json.loads(re.sub('<ph.*ph>', 'Chromium', original)) ++ self.failUnless(expected == json.loads(gatherer.Translate('en'))) ++ self.failUnless(gatherer.GetCliques()[0].translateable) ++ msg = gatherer.GetCliques()[0].GetMessage() ++ self.failUnless(len(msg.GetPlaceholders()) == 1) ++ ph = msg.GetPlaceholders()[0] ++ self.failUnless(ph.GetOriginal() == 'Chromium') ++ self.failUnless(ph.GetPresentation() == 'PRODUCT_NAME') ++ self.failUnless(ph.GetExample() == 'Google Chrome') ++ ++ def testPlaceholdersChrome(self): ++ original = """{ ++ "policy_definitions": [ ++ { ++ "name": "Policy1", ++ "caption": "Please install\\n<ph name=\\"PRODUCT_NAME\\">$1<ex>Google Chrome</ex></ph>.", ++ "owners": "a@b" ++ } ++ ], ++ "policy_atomic_group_definitions": [], ++ "messages": {} ++}""" ++ gatherer = policy_json.PolicyJson(StringIO(original)) ++ gatherer.SetDefines({'_google_chrome': True}) ++ gatherer.Parse() ++ self.failUnless(len(gatherer.GetCliques()) == 1) ++ expected = json.loads(re.sub('<ph.*ph>', 'Google Chrome', original)) ++ self.failUnless(expected == json.loads(gatherer.Translate('en'))) ++ self.failUnless(gatherer.GetCliques()[0].translateable) ++ msg = gatherer.GetCliques()[0].GetMessage() ++ self.failUnless(len(msg.GetPlaceholders()) == 1) ++ ph = msg.GetPlaceholders()[0] ++ self.failUnless(ph.GetOriginal() == 'Google Chrome') ++ self.failUnless(ph.GetPresentation() == 'PRODUCT_NAME') ++ self.failUnless(ph.GetExample() == 'Google Chrome') ++ ++ def testGetDescription(self): ++ gatherer = policy_json.PolicyJson({}) ++ gatherer.SetDefines({'_google_chrome': True}) ++ self.assertEquals( ++ gatherer._GetDescription({'name': 'Policy1', 'owners': ['a@b']}, ++ 'policy', None, 'desc'), ++ 'Description of the policy named Policy1 [owner(s): a@b]') ++ self.assertEquals( ++ gatherer._GetDescription({'name': 'Plcy2', 'owners': ['a@b', 'c@d']}, ++ 'policy', None, 'caption'), ++ 'Caption of the policy named Plcy2 [owner(s): a@b,c@d]') ++ self.assertEquals( ++ gatherer._GetDescription({'name': 'Plcy3', 'owners': ['a@b']}, ++ 'policy', None, 'label'), ++ 'Label of the policy named Plcy3 [owner(s): a@b]') ++ self.assertEquals( ++ gatherer._GetDescription({'name': 'Item'}, 'enum_item', ++ {'name': 'Plcy', 'owners': ['a@b']}, 'caption'), ++ 'Caption of the option named Item in policy Plcy [owner(s): a@b]') ++ ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/gather/rc.py b/tools/grit/grit/gather/rc.py +new file mode 100644 +index 0000000000..dd091d1e18 +--- /dev/null ++++ b/tools/grit/grit/gather/rc.py +@@ -0,0 +1,343 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Support for gathering resources from RC files. ++''' ++ ++from __future__ import print_function ++ ++import re ++ ++from grit import exception ++from grit import lazy_re ++from grit import tclib ++ ++from grit.gather import regexp ++ ++ ++# Find portions that need unescaping in resource strings. We need to be ++# careful that a \\n is matched _first_ as a \\ rather than matching as ++# a \ followed by a \n. ++# TODO(joi) Handle ampersands if we decide to change them into <ph> ++# TODO(joi) May need to handle other control characters than \n ++_NEED_UNESCAPE = lazy_re.compile(r'""|\\\\|\\n|\\t') ++ ++# Find portions that need escaping to encode string as a resource string. ++_NEED_ESCAPE = lazy_re.compile(r'"|\n|\t|\\|\ \;') ++ ++# How to escape certain characters ++_ESCAPE_CHARS = { ++ '"' : '""', ++ '\n' : '\\n', ++ '\t' : '\\t', ++ '\\' : '\\\\', ++ ' ' : ' ' ++} ++ ++# How to unescape certain strings ++_UNESCAPE_CHARS = dict([[value, key] for key, value in _ESCAPE_CHARS.items()]) ++ ++ ++ ++class Section(regexp.RegexpGatherer): ++ '''A section from a resource file.''' ++ ++ @staticmethod ++ def Escape(text): ++ '''Returns a version of 'text' with characters escaped that need to be ++ for inclusion in a resource section.''' ++ def Replace(match): ++ return _ESCAPE_CHARS[match.group()] ++ return _NEED_ESCAPE.sub(Replace, text) ++ ++ @staticmethod ++ def UnEscape(text): ++ '''Returns a version of 'text' with escaped characters unescaped.''' ++ def Replace(match): ++ return _UNESCAPE_CHARS[match.group()] ++ return _NEED_UNESCAPE.sub(Replace, text) ++ ++ def _RegExpParse(self, rexp, text_to_parse): ++ '''Overrides _RegExpParse to add shortcut group handling. Otherwise ++ the same. ++ ''' ++ super(Section, self)._RegExpParse(rexp, text_to_parse) ++ ++ if not self.is_skeleton and len(self.GetTextualIds()) > 0: ++ group_name = self.GetTextualIds()[0] ++ for c in self.GetCliques(): ++ c.AddToShortcutGroup(group_name) ++ ++ def ReadSection(self): ++ rc_text = self._LoadInputFile() ++ ++ out = '' ++ begin_count = 0 ++ assert self.extkey ++ first_line_re = re.compile(r'\s*' + self.extkey + r'\b') ++ for line in rc_text.splitlines(True): ++ if out or first_line_re.match(line): ++ out += line ++ ++ # we stop once we reach the END for the outermost block. ++ begin_count_was = begin_count ++ if len(out) > 0 and line.strip() == 'BEGIN': ++ begin_count += 1 ++ elif len(out) > 0 and line.strip() == 'END': ++ begin_count -= 1 ++ if begin_count_was == 1 and begin_count == 0: ++ break ++ ++ if len(out) == 0: ++ raise exception.SectionNotFound('%s in file %s' % (self.extkey, self.rc_file)) ++ ++ self.text_ = out.strip() ++ ++ ++class Dialog(Section): ++ '''A resource section that contains a dialog resource.''' ++ ++ # A typical dialog resource section looks like this: ++ # ++ # IDD_ABOUTBOX DIALOGEX 22, 17, 230, 75 ++ # STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU ++ # CAPTION "About" ++ # FONT 8, "System", 0, 0, 0x0 ++ # BEGIN ++ # ICON IDI_KLONK,IDC_MYICON,14,9,20,20 ++ # LTEXT "klonk Version ""yibbee"" 1.0",IDC_STATIC,49,10,119,8, ++ # SS_NOPREFIX ++ # LTEXT "Copyright (C) 2005",IDC_STATIC,49,20,119,8 ++ # DEFPUSHBUTTON "OK",IDOK,195,6,30,11,WS_GROUP ++ # CONTROL "Jack ""Black"" Daniels",IDC_RADIO1,"Button", ++ # BS_AUTORADIOBUTTON,46,51,84,10 ++ # END ++ ++ # We are using a sorted set of keys, and we assume that the ++ # group name used for descriptions (type) will come after the "text" ++ # group in alphabetical order. We also assume that there cannot be ++ # more than one description per regular expression match. ++ # If that's not the case some descriptions will be clobbered. ++ dialog_re_ = lazy_re.compile(r''' ++ # The dialog's ID in the first line ++ (?P<id1>[A-Z0-9_]+)\s+DIALOG(EX)? ++ | ++ # The caption of the dialog ++ (?P<type1>CAPTION)\s+"(?P<text1>.*?([^"]|""))"\s ++ | ++ # Lines for controls that have text and an ID ++ \s+(?P<type2>[A-Z]+)\s+"(?P<text2>.*?([^"]|"")?)"\s*,\s*(?P<id2>[A-Z0-9_]+)\s*, ++ | ++ # Lines for controls that have text only ++ \s+(?P<type3>[A-Z]+)\s+"(?P<text3>.*?([^"]|"")?)"\s*, ++ | ++ # Lines for controls that reference other resources ++ \s+[A-Z]+\s+[A-Z0-9_]+\s*,\s*(?P<id3>[A-Z0-9_]*[A-Z][A-Z0-9_]*) ++ | ++ # This matches "NOT SOME_STYLE" so that it gets consumed and doesn't get ++ # matched by the next option (controls that have only an ID and then just ++ # numbers) ++ \s+NOT\s+[A-Z][A-Z0-9_]+ ++ | ++ # Lines for controls that have only an ID and then just numbers ++ \s+[A-Z]+\s+(?P<id4>[A-Z0-9_]*[A-Z][A-Z0-9_]*)\s*, ++ ''', re.MULTILINE | re.VERBOSE) ++ ++ def Parse(self): ++ '''Knows how to parse dialog resource sections.''' ++ self.ReadSection() ++ self._RegExpParse(self.dialog_re_, self.text_) ++ ++ ++class Menu(Section): ++ '''A resource section that contains a menu resource.''' ++ ++ # A typical menu resource section looks something like this: ++ # ++ # IDC_KLONK MENU ++ # BEGIN ++ # POPUP "&File" ++ # BEGIN ++ # MENUITEM "E&xit", IDM_EXIT ++ # MENUITEM "This be ""Klonk"" me like", ID_FILE_THISBE ++ # POPUP "gonk" ++ # BEGIN ++ # MENUITEM "Klonk && is ""good""", ID_GONK_KLONKIS ++ # END ++ # END ++ # POPUP "&Help" ++ # BEGIN ++ # MENUITEM "&About ...", IDM_ABOUT ++ # END ++ # END ++ ++ # Description used for the messages generated for menus, to explain to ++ # the translators how to handle them. ++ MENU_MESSAGE_DESCRIPTION = ( ++ 'This message represents a menu. Each of the items appears in sequence ' ++ '(some possibly within sub-menus) in the menu. The XX01XX placeholders ' ++ 'serve to separate items. Each item contains an & (ampersand) character ' ++ 'in front of the keystroke that should be used as a shortcut for that item ' ++ 'in the menu. Please make sure that no two items in the same menu share ' ++ 'the same shortcut.' ++ ) ++ ++ # A dandy regexp to suck all the IDs and translateables out of a menu ++ # resource ++ menu_re_ = lazy_re.compile(r''' ++ # Match the MENU ID on the first line ++ ^(?P<id1>[A-Z0-9_]+)\s+MENU ++ | ++ # Match the translateable caption for a popup menu ++ POPUP\s+"(?P<text1>.*?([^"]|""))"\s ++ | ++ # Match the caption & ID of a MENUITEM ++ MENUITEM\s+"(?P<text2>.*?([^"]|""))"\s*,\s*(?P<id2>[A-Z0-9_]+) ++ ''', re.MULTILINE | re.VERBOSE) ++ ++ def Parse(self): ++ '''Knows how to parse menu resource sections. Because it is important that ++ menu shortcuts are unique within the menu, we return each menu as a single ++ message with placeholders to break up the different menu items, rather than ++ return a single message per menu item. we also add an automatic description ++ with instructions for the translators.''' ++ self.ReadSection() ++ self.single_message_ = tclib.Message(description=self.MENU_MESSAGE_DESCRIPTION) ++ self._RegExpParse(self.menu_re_, self.text_) ++ ++ ++class Version(Section): ++ '''A resource section that contains a VERSIONINFO resource.''' ++ ++ # A typical version info resource can look like this: ++ # ++ # VS_VERSION_INFO VERSIONINFO ++ # FILEVERSION 1,0,0,1 ++ # PRODUCTVERSION 1,0,0,1 ++ # FILEFLAGSMASK 0x3fL ++ # #ifdef _DEBUG ++ # FILEFLAGS 0x1L ++ # #else ++ # FILEFLAGS 0x0L ++ # #endif ++ # FILEOS 0x4L ++ # FILETYPE 0x2L ++ # FILESUBTYPE 0x0L ++ # BEGIN ++ # BLOCK "StringFileInfo" ++ # BEGIN ++ # BLOCK "040904e4" ++ # BEGIN ++ # VALUE "CompanyName", "TODO: <Company name>" ++ # VALUE "FileDescription", "TODO: <File description>" ++ # VALUE "FileVersion", "1.0.0.1" ++ # VALUE "LegalCopyright", "TODO: (c) <Company name>. All rights reserved." ++ # VALUE "InternalName", "res_format_test.dll" ++ # VALUE "OriginalFilename", "res_format_test.dll" ++ # VALUE "ProductName", "TODO: <Product name>" ++ # VALUE "ProductVersion", "1.0.0.1" ++ # END ++ # END ++ # BLOCK "VarFileInfo" ++ # BEGIN ++ # VALUE "Translation", 0x409, 1252 ++ # END ++ # END ++ # ++ # ++ # In addition to the above fields, VALUE fields named "Comments" and ++ # "LegalTrademarks" may also be translateable. ++ ++ version_re_ = lazy_re.compile(r''' ++ # Match the ID on the first line ++ ^(?P<id1>[A-Z0-9_]+)\s+VERSIONINFO ++ | ++ # Match all potentially translateable VALUE sections ++ \s+VALUE\s+" ++ ( ++ CompanyName|FileDescription|LegalCopyright| ++ ProductName|Comments|LegalTrademarks ++ )",\s+"(?P<text1>.*?([^"]|""))"\s ++ ''', re.MULTILINE | re.VERBOSE) ++ ++ def Parse(self): ++ '''Knows how to parse VERSIONINFO resource sections.''' ++ self.ReadSection() ++ self._RegExpParse(self.version_re_, self.text_) ++ ++ # TODO(joi) May need to override the Translate() method to change the ++ # "Translation" VALUE block to indicate the correct language code. ++ ++ ++class RCData(Section): ++ '''A resource section that contains some data .''' ++ ++ # A typical rcdataresource section looks like this: ++ # ++ # IDR_BLAH RCDATA { 1, 2, 3, 4 } ++ ++ dialog_re_ = lazy_re.compile(r''' ++ ^(?P<id1>[A-Z0-9_]+)\s+RCDATA\s+(DISCARDABLE)?\s+\{.*?\} ++ ''', re.MULTILINE | re.VERBOSE | re.DOTALL) ++ ++ def Parse(self): ++ '''Implementation for resource types w/braces (not BEGIN/END) ++ ''' ++ rc_text = self._LoadInputFile() ++ ++ out = '' ++ begin_count = 0 ++ openbrace_count = 0 ++ assert self.extkey ++ first_line_re = re.compile(r'\s*' + self.extkey + r'\b') ++ for line in rc_text.splitlines(True): ++ if out or first_line_re.match(line): ++ out += line ++ ++ # We stop once the braces balance (could happen in one line). ++ begin_count_was = begin_count ++ if len(out) > 0: ++ openbrace_count += line.count('{') ++ begin_count += line.count('{') ++ begin_count -= line.count('}') ++ if ((begin_count_was == 1 and begin_count == 0) or ++ (openbrace_count > 0 and begin_count == 0)): ++ break ++ ++ if len(out) == 0: ++ raise exception.SectionNotFound('%s in file %s' % (self.extkey, self.rc_file)) ++ ++ self.text_ = out ++ ++ self._RegExpParse(self.dialog_re_, out) ++ ++ ++class Accelerators(Section): ++ '''An ACCELERATORS table. ++ ''' ++ ++ # A typical ACCELERATORS section looks like this: ++ # ++ # IDR_ACCELERATOR1 ACCELERATORS ++ # BEGIN ++ # "^C", ID_ACCELERATOR32770, ASCII, NOINVERT ++ # "^V", ID_ACCELERATOR32771, ASCII, NOINVERT ++ # VK_INSERT, ID_ACCELERATOR32772, VIRTKEY, CONTROL, NOINVERT ++ # END ++ ++ accelerators_re_ = lazy_re.compile(r''' ++ # Match the ID on the first line ++ ^(?P<id1>[A-Z0-9_]+)\s+ACCELERATORS\s+ ++ | ++ # Match accelerators specified as VK_XXX ++ \s+VK_[A-Z0-9_]+,\s*(?P<id2>[A-Z0-9_]+)\s*, ++ | ++ # Match accelerators specified as e.g. "^C" ++ \s+"[^"]*",\s+(?P<id3>[A-Z0-9_]+)\s*, ++ ''', re.MULTILINE | re.VERBOSE) ++ ++ def Parse(self): ++ '''Knows how to parse ACCELERATORS resource sections.''' ++ self.ReadSection() ++ self._RegExpParse(self.accelerators_re_, self.text_) +diff --git a/tools/grit/grit/gather/rc_unittest.py b/tools/grit/grit/gather/rc_unittest.py +new file mode 100644 +index 0000000000..3c26a4342a +--- /dev/null ++++ b/tools/grit/grit/gather/rc_unittest.py +@@ -0,0 +1,372 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for grit.gather.rc''' ++ ++from __future__ import print_function ++ ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++import unittest ++ ++from six import StringIO ++ ++from grit.gather import rc ++from grit import util ++ ++ ++class RcUnittest(unittest.TestCase): ++ ++ part_we_want = '''IDC_KLONKACC ACCELERATORS ++BEGIN ++ "?", IDM_ABOUT, ASCII, ALT ++ "/", IDM_ABOUT, ASCII, ALT ++END''' ++ ++ def testSectionFromFile(self): ++ buf = '''IDC_SOMETHINGELSE BINGO ++BEGIN ++ BLA BLA ++ BLA BLA ++END ++%s ++ ++IDC_KLONK BINGOBONGO ++BEGIN ++ HONGO KONGO ++END ++''' % self.part_we_want ++ ++ f = StringIO(buf) ++ ++ out = rc.Section(f, 'IDC_KLONKACC') ++ out.ReadSection() ++ self.failUnless(out.GetText() == self.part_we_want) ++ ++ out = rc.Section(util.PathFromRoot(r'grit/testdata/klonk.rc'), ++ 'IDC_KLONKACC', ++ encoding='utf-16') ++ out.ReadSection() ++ out_text = out.GetText().replace('\t', '') ++ out_text = out_text.replace(' ', '') ++ self.part_we_want = self.part_we_want.replace(' ', '') ++ self.failUnless(out_text.strip() == self.part_we_want.strip()) ++ ++ ++ def testDialog(self): ++ dlg = rc.Dialog(StringIO('''IDD_ABOUTBOX DIALOGEX 22, 17, 230, 75 ++STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU ++CAPTION "About" ++FONT 8, "System", 0, 0, 0x0 ++BEGIN ++ ICON IDI_KLONK,IDC_MYICON,14,9,20,20 ++ LTEXT "klonk Version ""yibbee"" 1.0",IDC_STATIC,49,10,119,8, ++ SS_NOPREFIX ++ LTEXT "Copyright (C) 2005",IDC_STATIC,49,20,119,8 ++ DEFPUSHBUTTON "OK",IDOK,195,6,30,11,WS_GROUP ++ CONTROL "Jack ""Black"" Daniels",IDC_RADIO1,"Button", ++ BS_AUTORADIOBUTTON,46,51,84,10 ++ // try a line where the ID is on the continuation line ++ LTEXT "blablablabla blablabla blablablablablablablabla blablabla", ++ ID_SMURF, whatever... ++END ++'''), 'IDD_ABOUTBOX') ++ dlg.Parse() ++ self.failUnless(len(dlg.GetTextualIds()) == 7) ++ self.failUnless(len(dlg.GetCliques()) == 6) ++ self.failUnless(dlg.GetCliques()[1].GetMessage().GetRealContent() == ++ 'klonk Version "yibbee" 1.0') ++ ++ transl = dlg.Translate('en') ++ self.failUnless(transl.strip() == dlg.GetText().strip()) ++ ++ def testAlternateSkeleton(self): ++ dlg = rc.Dialog(StringIO('''IDD_ABOUTBOX DIALOGEX 22, 17, 230, 75 ++STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU ++CAPTION "About" ++FONT 8, "System", 0, 0, 0x0 ++BEGIN ++ LTEXT "Yipee skippy",IDC_STATIC,49,10,119,8, ++ SS_NOPREFIX ++END ++'''), 'IDD_ABOUTBOX') ++ dlg.Parse() ++ ++ alt_dlg = rc.Dialog(StringIO('''IDD_ABOUTBOX DIALOGEX 040704, 17, 230, 75 ++STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU ++CAPTION "XXXXXXXXX" ++FONT 8, "System", 0, 0, 0x0 ++BEGIN ++ LTEXT "XXXXXXXXXXXXXXXXX",IDC_STATIC,110978,10,119,8, ++ SS_NOPREFIX ++END ++'''), 'IDD_ABOUTBOX') ++ alt_dlg.Parse() ++ ++ transl = dlg.Translate('en', skeleton_gatherer=alt_dlg) ++ self.failUnless(transl.count('040704') and ++ transl.count('110978')) ++ self.failUnless(transl.count('Yipee skippy')) ++ ++ def testMenu(self): ++ menu = rc.Menu(StringIO('''IDC_KLONK MENU ++BEGIN ++ POPUP "&File """ ++ BEGIN ++ MENUITEM "E&xit", IDM_EXIT ++ MENUITEM "This be ""Klonk"" me like", ID_FILE_THISBE ++ POPUP "gonk" ++ BEGIN ++ MENUITEM "Klonk && is ""good""", ID_GONK_KLONKIS ++ END ++ MENUITEM "This is a very long menu caption to try to see if we can make the ID go to a continuation line, blablabla blablabla bla blabla blablabla blablabla blablabla blablabla...", ++ ID_FILE_THISISAVERYLONGMENUCAPTIONTOTRYTOSEEIFWECANMAKETHEIDGOTOACONTINUATIONLINE ++ END ++ POPUP "&Help" ++ BEGIN ++ MENUITEM "&About ...", IDM_ABOUT ++ END ++END'''), 'IDC_KLONK') ++ ++ menu.Parse() ++ self.failUnless(len(menu.GetTextualIds()) == 6) ++ self.failUnless(len(menu.GetCliques()) == 1) ++ self.failUnless(len(menu.GetCliques()[0].GetMessage().GetPlaceholders()) == ++ 9) ++ ++ transl = menu.Translate('en') ++ self.failUnless(transl.strip() == menu.GetText().strip()) ++ ++ def testVersion(self): ++ version = rc.Version(StringIO(''' ++VS_VERSION_INFO VERSIONINFO ++ FILEVERSION 1,0,0,1 ++ PRODUCTVERSION 1,0,0,1 ++ FILEFLAGSMASK 0x3fL ++#ifdef _DEBUG ++ FILEFLAGS 0x1L ++#else ++ FILEFLAGS 0x0L ++#endif ++ FILEOS 0x4L ++ FILETYPE 0x2L ++ FILESUBTYPE 0x0L ++BEGIN ++ BLOCK "StringFileInfo" ++ BEGIN ++ BLOCK "040904e4" ++ BEGIN ++ VALUE "CompanyName", "TODO: <Company name>" ++ VALUE "FileDescription", "TODO: <File description>" ++ VALUE "FileVersion", "1.0.0.1" ++ VALUE "LegalCopyright", "TODO: (c) <Company name>. All rights reserved." ++ VALUE "InternalName", "res_format_test.dll" ++ VALUE "OriginalFilename", "res_format_test.dll" ++ VALUE "ProductName", "TODO: <Product name>" ++ VALUE "ProductVersion", "1.0.0.1" ++ END ++ END ++ BLOCK "VarFileInfo" ++ BEGIN ++ VALUE "Translation", 0x409, 1252 ++ END ++END ++'''.strip()), 'VS_VERSION_INFO') ++ version.Parse() ++ self.failUnless(len(version.GetTextualIds()) == 1) ++ self.failUnless(len(version.GetCliques()) == 4) ++ ++ transl = version.Translate('en') ++ self.failUnless(transl.strip() == version.GetText().strip()) ++ ++ ++ def testRegressionDialogBox(self): ++ dialog = rc.Dialog(StringIO(''' ++IDD_SIDEBAR_WEATHER_PANEL_PROPPAGE DIALOGEX 0, 0, 205, 157 ++STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD ++FONT 8, "MS Shell Dlg", 400, 0, 0x1 ++BEGIN ++ EDITTEXT IDC_SIDEBAR_WEATHER_NEW_CITY,3,27,112,14,ES_AUTOHSCROLL ++ DEFPUSHBUTTON "Add Location",IDC_SIDEBAR_WEATHER_ADD,119,27,50,14 ++ LISTBOX IDC_SIDEBAR_WEATHER_CURR_CITIES,3,48,127,89, ++ LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP ++ PUSHBUTTON "Move Up",IDC_SIDEBAR_WEATHER_MOVE_UP,134,104,50,14 ++ PUSHBUTTON "Move Down",IDC_SIDEBAR_WEATHER_MOVE_DOWN,134,121,50,14 ++ PUSHBUTTON "Remove",IDC_SIDEBAR_WEATHER_DELETE,134,48,50,14 ++ LTEXT "To see current weather conditions and forecasts in the USA, enter the zip code (example: 94043) or city and state (example: Mountain View, CA).", ++ IDC_STATIC,3,0,199,25 ++ CONTROL "Fahrenheit",IDC_SIDEBAR_WEATHER_FAHRENHEIT,"Button", ++ BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,3,144,51,10 ++ CONTROL "Celsius",IDC_SIDEBAR_WEATHER_CELSIUS,"Button", ++ BS_AUTORADIOBUTTON,57,144,38,10 ++END'''.strip()), 'IDD_SIDEBAR_WEATHER_PANEL_PROPPAGE') ++ dialog.Parse() ++ self.failUnless(len(dialog.GetTextualIds()) == 10) ++ ++ ++ def testRegressionDialogBox2(self): ++ dialog = rc.Dialog(StringIO(''' ++IDD_SIDEBAR_EMAIL_PANEL_PROPPAGE DIALOG DISCARDABLE 0, 0, 264, 220 ++STYLE WS_CHILD ++FONT 8, "MS Shell Dlg" ++BEGIN ++ GROUPBOX "Email Filters",IDC_STATIC,7,3,250,190 ++ LTEXT "Click Add Filter to create the email filter.",IDC_STATIC,16,41,130,9 ++ PUSHBUTTON "Add Filter...",IDC_SIDEBAR_EMAIL_ADD_FILTER,196,38,50,14 ++ PUSHBUTTON "Remove",IDC_SIDEBAR_EMAIL_REMOVE,196,174,50,14 ++ PUSHBUTTON "", IDC_SIDEBAR_EMAIL_HIDDEN, 200, 178, 5, 5, NOT WS_VISIBLE ++ LISTBOX IDC_SIDEBAR_EMAIL_LIST,16,60,230,108, ++ LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP ++ LTEXT "You can prevent certain emails from showing up in the sidebar with a filter.", ++ IDC_STATIC,16,18,234,18 ++END'''.strip()), 'IDD_SIDEBAR_EMAIL_PANEL_PROPPAGE') ++ dialog.Parse() ++ self.failUnless('IDC_SIDEBAR_EMAIL_HIDDEN' in dialog.GetTextualIds()) ++ ++ ++ def testRegressionMenuId(self): ++ menu = rc.Menu(StringIO(''' ++IDR_HYPERMENU_FOLDER MENU ++BEGIN ++ POPUP "HyperFolder" ++ BEGIN ++ MENUITEM "Open Containing Folder", IDM_OPENFOLDER ++ END ++END'''.strip()), 'IDR_HYPERMENU_FOLDER') ++ menu.Parse() ++ self.failUnless(len(menu.GetTextualIds()) == 2) ++ ++ def testRegressionNewlines(self): ++ menu = rc.Menu(StringIO(''' ++IDR_HYPERMENU_FOLDER MENU ++BEGIN ++ POPUP "Hyper\\nFolder" ++ BEGIN ++ MENUITEM "Open Containing Folder", IDM_OPENFOLDER ++ END ++END'''.strip()), 'IDR_HYPERMENU_FOLDER') ++ menu.Parse() ++ transl = menu.Translate('en') ++ # Shouldn't find \\n (the \n shouldn't be changed to \\n) ++ self.failUnless(transl.find('\\\\n') == -1) ++ ++ def testRegressionTabs(self): ++ menu = rc.Menu(StringIO(''' ++IDR_HYPERMENU_FOLDER MENU ++BEGIN ++ POPUP "Hyper\\tFolder" ++ BEGIN ++ MENUITEM "Open Containing Folder", IDM_OPENFOLDER ++ END ++END'''.strip()), 'IDR_HYPERMENU_FOLDER') ++ menu.Parse() ++ transl = menu.Translate('en') ++ # Shouldn't find \\t (the \t shouldn't be changed to \\t) ++ self.failUnless(transl.find('\\\\t') == -1) ++ ++ def testEscapeUnescape(self): ++ original = 'Hello "bingo"\n How\\are\\you\\n?' ++ escaped = rc.Section.Escape(original) ++ self.failUnless(escaped == 'Hello ""bingo""\\n How\\\\are\\\\you\\\\n?') ++ unescaped = rc.Section.UnEscape(escaped) ++ self.failUnless(unescaped == original) ++ ++ def testRegressionPathsWithSlashN(self): ++ original = '..\\\\..\\\\trs\\\\res\\\\nav_first.gif' ++ unescaped = rc.Section.UnEscape(original) ++ self.failUnless(unescaped == '..\\..\\trs\\res\\nav_first.gif') ++ ++ def testRegressionDialogItemsTextOnly(self): ++ dialog = rc.Dialog(StringIO('''IDD_OPTIONS_SEARCH DIALOGEX 0, 0, 280, 292 ++STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | ++ WS_DISABLED | WS_CAPTION | WS_SYSMENU ++CAPTION "Search" ++FONT 8, "MS Shell Dlg", 400, 0, 0x1 ++BEGIN ++ GROUPBOX "Select search buttons and options",-1,7,5,266,262 ++ CONTROL "",IDC_OPTIONS,"SysTreeView32",TVS_DISABLEDRAGDROP | ++ WS_BORDER | WS_TABSTOP | 0x800,16,19,248,218 ++ LTEXT "Use Google site:",-1,26,248,52,8 ++ COMBOBOX IDC_GOOGLE_HOME,87,245,177,256,CBS_DROPDOWNLIST | ++ WS_VSCROLL | WS_TABSTOP ++ PUSHBUTTON "Restore Defaults...",IDC_RESET,187,272,86,14 ++END'''), 'IDD_OPTIONS_SEARCH') ++ dialog.Parse() ++ translateables = [c.GetMessage().GetRealContent() ++ for c in dialog.GetCliques()] ++ self.failUnless('Select search buttons and options' in translateables) ++ self.failUnless('Use Google site:' in translateables) ++ ++ def testAccelerators(self): ++ acc = rc.Accelerators(StringIO('''\ ++IDR_ACCELERATOR1 ACCELERATORS ++BEGIN ++ "^C", ID_ACCELERATOR32770, ASCII, NOINVERT ++ "^V", ID_ACCELERATOR32771, ASCII, NOINVERT ++ VK_INSERT, ID_ACCELERATOR32772, VIRTKEY, CONTROL, NOINVERT ++END ++'''), 'IDR_ACCELERATOR1') ++ acc.Parse() ++ self.failUnless(len(acc.GetTextualIds()) == 4) ++ self.failUnless(len(acc.GetCliques()) == 0) ++ ++ transl = acc.Translate('en') ++ self.failUnless(transl.strip() == acc.GetText().strip()) ++ ++ ++ def testRegressionEmptyString(self): ++ dlg = rc.Dialog(StringIO('''\ ++IDD_CONFIRM_QUIT_GD_DLG DIALOGEX 0, 0, 267, 108 ++STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | ++ WS_CAPTION ++EXSTYLE WS_EX_TOPMOST ++CAPTION "Google Desktop" ++FONT 8, "MS Shell Dlg", 400, 0, 0x1 ++BEGIN ++ DEFPUSHBUTTON "&Yes",IDYES,82,87,50,14 ++ PUSHBUTTON "&No",IDNO,136,87,50,14 ++ ICON 32514,IDC_STATIC,7,9,21,20 ++ EDITTEXT IDC_TEXTBOX,34,7,231,60,ES_MULTILINE | ES_READONLY | NOT WS_BORDER ++ CONTROL "", ++ IDC_ENABLE_GD_AUTOSTART,"Button",BS_AUTOCHECKBOX | ++ WS_TABSTOP,33,70,231,10 ++END'''), 'IDD_CONFIRM_QUIT_GD_DLG') ++ dlg.Parse() ++ ++ def Check(): ++ self.failUnless(transl.count('IDC_ENABLE_GD_AUTOSTART')) ++ self.failUnless(transl.count('END')) ++ ++ transl = dlg.Translate('de', pseudo_if_not_available=True, ++ fallback_to_english=True) ++ Check() ++ transl = dlg.Translate('de', pseudo_if_not_available=True, ++ fallback_to_english=False) ++ Check() ++ transl = dlg.Translate('de', pseudo_if_not_available=False, ++ fallback_to_english=True) ++ Check() ++ transl = dlg.Translate('de', pseudo_if_not_available=False, ++ fallback_to_english=False) ++ Check() ++ transl = dlg.Translate('en', pseudo_if_not_available=True, ++ fallback_to_english=True) ++ Check() ++ transl = dlg.Translate('en', pseudo_if_not_available=True, ++ fallback_to_english=False) ++ Check() ++ transl = dlg.Translate('en', pseudo_if_not_available=False, ++ fallback_to_english=True) ++ Check() ++ transl = dlg.Translate('en', pseudo_if_not_available=False, ++ fallback_to_english=False) ++ Check() ++ ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/gather/regexp.py b/tools/grit/grit/gather/regexp.py +new file mode 100644 +index 0000000000..97ce2cfbf7 +--- /dev/null ++++ b/tools/grit/grit/gather/regexp.py +@@ -0,0 +1,82 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''A baseclass for simple gatherers based on regular expressions. ++''' ++ ++from __future__ import print_function ++ ++from grit.gather import skeleton_gatherer ++ ++ ++class RegexpGatherer(skeleton_gatherer.SkeletonGatherer): ++ '''Common functionality of gatherers based on parsing using a single ++ regular expression. ++ ''' ++ ++ DescriptionMapping_ = { ++ 'CAPTION' : 'This is a caption for a dialog', ++ 'CHECKBOX' : 'This is a label for a checkbox', ++ 'CONTROL': 'This is the text on a control', ++ 'CTEXT': 'This is a label for a control', ++ 'DEFPUSHBUTTON': 'This is a button definition', ++ 'GROUPBOX': 'This is a label for a grouping', ++ 'ICON': 'This is a label for an icon', ++ 'LTEXT': 'This is the text for a label', ++ 'PUSHBUTTON': 'This is the text for a button', + } + -+ return parsed; -+ } ++ # Contextualization elements. Used for adding additional information ++ # to the message bundle description string from RC files. ++ def AddDescriptionElement(self, string): ++ if string in self.DescriptionMapping_: ++ description = self.DescriptionMapping_[string] ++ else: ++ description = string ++ if self.single_message_: ++ self.single_message_.SetDescription(description) ++ else: ++ if (self.translatable_chunk_): ++ message = self.skeleton_[len(self.skeleton_) - 1].GetMessage() ++ message.SetDescription(description) ++ ++ def _RegExpParse(self, regexp, text_to_parse): ++ '''An implementation of Parse() that can be used for resource sections that ++ can be parsed using a single multi-line regular expression. ++ ++ All translateables must be in named groups that have names starting with ++ 'text'. All textual IDs must be in named groups that have names starting ++ with 'id'. All type definitions that can be included in the description ++ field for contextualization purposes should have a name that starts with ++ 'type'. ++ ++ Args: ++ regexp: re.compile('...', re.MULTILINE) ++ text_to_parse: ++ ''' ++ chunk_start = 0 ++ for match in regexp.finditer(text_to_parse): ++ groups = match.groupdict() ++ keys = sorted(groups.keys()) ++ self.translatable_chunk_ = False ++ for group in keys: ++ if group.startswith('id') and groups[group]: ++ self._AddTextualId(groups[group]) ++ elif group.startswith('text') and groups[group]: ++ self._AddNontranslateableChunk( ++ text_to_parse[chunk_start : match.start(group)]) ++ chunk_start = match.end(group) # Next chunk will start after the match ++ self._AddTranslateableChunk(groups[group]) ++ elif group.startswith('type') and groups[group]: ++ # Add the description to the skeleton_ list. This works because ++ # we are using a sort set of keys, and because we assume that the ++ # group name used for descriptions (type) will come after the "text" ++ # group in alphabetical order. We also assume that there cannot be ++ # more than one description per regular expression match. ++ self.AddDescriptionElement(groups[group]) ++ ++ self._AddNontranslateableChunk(text_to_parse[chunk_start:]) ++ ++ if self.single_message_: ++ self.skeleton_.append(self.uberclique.MakeClique(self.single_message_)) +diff --git a/tools/grit/grit/gather/skeleton_gatherer.py b/tools/grit/grit/gather/skeleton_gatherer.py +new file mode 100644 +index 0000000000..b11862b314 +--- /dev/null ++++ b/tools/grit/grit/gather/skeleton_gatherer.py +@@ -0,0 +1,149 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+ private: -+ bool check_refcounted_dtors_; -+ bool check_virtuals_in_implementations_; -+}; ++'''A baseclass for simple gatherers that store their gathered resource in a ++list. ++''' ++ ++from __future__ import print_function ++ ++import six ++ ++from grit.gather import interface ++from grit import clique ++from grit import exception ++from grit import tclib ++ ++ ++class SkeletonGatherer(interface.GathererBase): ++ '''Common functionality of gatherers that parse their input as a skeleton of ++ translatable and nontranslatable chunks. ++ ''' ++ ++ def __init__(self, *args, **kwargs): ++ super(SkeletonGatherer, self).__init__(*args, **kwargs) ++ # List of parts of the document. Translateable parts are ++ # clique.MessageClique objects, nontranslateable parts are plain strings. ++ # Translated messages are inserted back into the skeleton using the quoting ++ # rules defined by self.Escape() ++ self.skeleton_ = [] ++ # A list of the names of IDs that need to be defined for this resource ++ # section to compile correctly. ++ self.ids_ = [] ++ # True if Parse() has already been called. ++ self.have_parsed_ = False ++ # True if a translatable chunk has been added ++ self.translatable_chunk_ = False ++ # If not None, all parts of the document will be put into this single ++ # message; otherwise the normal skeleton approach is used. ++ self.single_message_ = None ++ # Number to use for the next placeholder name. Used only if single_message ++ # is not None ++ self.ph_counter_ = 1 ++ ++ def GetText(self): ++ '''Returns the original text of the section''' ++ return self.text_ ++ ++ def Escape(self, text): ++ '''Subclasses can override. Base impl is identity. ++ ''' ++ return text ++ ++ def UnEscape(self, text): ++ '''Subclasses can override. Base impl is identity. ++ ''' ++ return text ++ ++ def GetTextualIds(self): ++ '''Returns the list of textual IDs that need to be defined for this ++ resource section to compile correctly.''' ++ return self.ids_ ++ ++ def _AddTextualId(self, id): ++ self.ids_.append(id) ++ ++ def GetCliques(self): ++ '''Returns the message cliques for each translateable message in the ++ resource section.''' ++ return [x for x in self.skeleton_ if isinstance(x, clique.MessageClique)] ++ ++ def Translate(self, lang, pseudo_if_not_available=True, ++ skeleton_gatherer=None, fallback_to_english=False): ++ if len(self.skeleton_) == 0: ++ raise exception.NotReady() ++ if skeleton_gatherer: ++ assert len(skeleton_gatherer.skeleton_) == len(self.skeleton_) ++ ++ out = [] ++ for ix in range(len(self.skeleton_)): ++ if isinstance(self.skeleton_[ix], six.string_types): ++ if skeleton_gatherer: ++ # Make sure the skeleton is like the original ++ assert(isinstance(skeleton_gatherer.skeleton_[ix], six.string_types)) ++ out.append(skeleton_gatherer.skeleton_[ix]) ++ else: ++ out.append(self.skeleton_[ix]) ++ else: ++ if skeleton_gatherer: # Make sure the skeleton is like the original ++ assert(not isinstance(skeleton_gatherer.skeleton_[ix], ++ six.string_types)) ++ msg = self.skeleton_[ix].MessageForLanguage(lang, ++ pseudo_if_not_available, ++ fallback_to_english) ++ ++ def MyEscape(text): ++ return self.Escape(text) ++ text = msg.GetRealContent(escaping_function=MyEscape) ++ out.append(text) ++ return ''.join(out) ++ ++ def Parse(self): ++ '''Parses the section. Implemented by subclasses. Idempotent.''' ++ raise NotImplementedError() ++ ++ def _AddNontranslateableChunk(self, chunk): ++ '''Adds a nontranslateable chunk.''' ++ if self.single_message_: ++ ph = tclib.Placeholder('XX%02dXX' % self.ph_counter_, chunk, chunk) ++ self.ph_counter_ += 1 ++ self.single_message_.AppendPlaceholder(ph) ++ else: ++ self.skeleton_.append(chunk) ++ ++ def _AddTranslateableChunk(self, chunk): ++ '''Adds a translateable chunk. It will be unescaped before being added.''' ++ # We don't want empty messages since they are redundant and the TC ++ # doesn't allow them. ++ if chunk == '': ++ return ++ ++ unescaped_text = self.UnEscape(chunk) ++ if self.single_message_: ++ self.single_message_.AppendText(unescaped_text) ++ else: ++ self.skeleton_.append(self.uberclique.MakeClique( ++ tclib.Message(text=unescaped_text))) ++ self.translatable_chunk_ = True ++ ++ def SubstituteMessages(self, substituter): ++ '''Applies substitutions to all messages in the tree. ++ ++ Goes through the skeleton and finds all MessageCliques. ++ ++ Args: ++ substituter: a grit.util.Substituter object. ++ ''' ++ if self.single_message_: ++ self.single_message_ = substituter.SubstituteMessage(self.single_message_) ++ new_skel = [] ++ for chunk in self.skeleton_: ++ if isinstance(chunk, clique.MessageClique): ++ old_message = chunk.GetMessage() ++ new_message = substituter.SubstituteMessage(old_message) ++ if new_message is not old_message: ++ new_skel.append(self.uberclique.MakeClique(new_message)) ++ continue ++ new_skel.append(chunk) ++ self.skeleton_ = new_skel +diff --git a/tools/grit/grit/gather/tr_html.py b/tools/grit/grit/gather/tr_html.py +new file mode 100644 +index 0000000000..60a9bfaf4e +--- /dev/null ++++ b/tools/grit/grit/gather/tr_html.py +@@ -0,0 +1,743 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''A gatherer for the TotalRecall brand of HTML templates with replaceable ++portions. We wanted to reuse extern.tclib.api.handlers.html.TCHTMLParser ++but this proved impossible due to the fact that the TotalRecall HTML templates ++are in general quite far from parseable HTML and the TCHTMLParser derives ++ ++from HTMLParser.HTMLParser which requires relatively well-formed HTML. Some ++examples of "HTML" from the TotalRecall HTML templates that wouldn't be ++parseable include things like: ++ ++ <a [PARAMS]>blabla</a> (not parseable because attributes are invalid) ++ ++ <table><tr><td>[LOTSOFSTUFF]</tr></table> (not parseable because closing ++ </td> is in the HTML [LOTSOFSTUFF] ++ is replaced by) ++ ++The other problem with using general parsers (such as TCHTMLParser) is that ++we want to make sure we output the TotalRecall template with as little changes ++as possible in terms of whitespace characters, layout etc. With any parser ++that generates a parse tree, and generates output by dumping the parse tree, ++we would always have little inconsistencies which could cause bugs (the ++TotalRecall template stuff is quite brittle and can break if e.g. a tab ++character is replaced with spaces). ++ ++The solution, which may be applicable to some other HTML-like template ++languages floating around Google, is to create a parser with a simple state ++machine that keeps track of what kind of tag it's inside, and whether it's in ++a translateable section or not. Translateable sections are: ++ ++a) text (including [BINGO] replaceables) inside of tags that ++ can contain translateable text (which is all tags except ++ for a few) ++ ++b) text inside of an 'alt' attribute in an <image> element, or ++ the 'value' attribute of a <submit>, <button> or <text> ++ element. ++ ++The parser does not build up a parse tree but rather a "skeleton" which ++is a list of nontranslateable strings intermingled with grit.clique.MessageClique ++objects. This simplifies the parser considerably compared to a regular HTML ++parser. To output a translated document, each item in the skeleton is ++printed out, with the relevant Translation from each MessageCliques being used ++for the requested language. ++ ++This implementation borrows some code, constants and ideas from ++extern.tclib.api.handlers.html.TCHTMLParser. ++''' ++ ++from __future__ import print_function ++ ++import re ++ ++import six ++ ++from grit import clique ++from grit import exception ++from grit import lazy_re ++from grit import util ++from grit import tclib ++ ++from grit.gather import interface ++ ++ ++# HTML tags which break (separate) chunks. ++_BLOCK_TAGS = ['script', 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'br', ++ 'body', 'style', 'head', 'title', 'table', 'tr', 'td', 'th', ++ 'ul', 'ol', 'dl', 'nl', 'li', 'div', 'object', 'center', ++ 'html', 'link', 'form', 'select', 'textarea', ++ 'button', 'option', 'map', 'area', 'blockquote', 'pre', ++ 'meta', 'xmp', 'noscript', 'label', 'tbody', 'thead', ++ 'script', 'style', 'pre', 'iframe', 'img', 'input', 'nowrap', ++ 'fieldset', 'legend'] ++ ++# HTML tags which may appear within a chunk. ++_INLINE_TAGS = ['b', 'i', 'u', 'tt', 'code', 'font', 'a', 'span', 'small', ++ 'key', 'nobr', 'url', 'em', 's', 'sup', 'strike', ++ 'strong'] ++ ++# HTML tags within which linebreaks are significant. ++_PREFORMATTED_TAGS = ['textarea', 'xmp', 'pre'] ++ ++# An array mapping some of the inline HTML tags to more meaningful ++# names for those tags. This will be used when generating placeholders ++# representing these tags. ++_HTML_PLACEHOLDER_NAMES = { 'a' : 'link', 'br' : 'break', 'b' : 'bold', ++ 'i' : 'italic', 'li' : 'item', 'ol' : 'ordered_list', 'p' : 'paragraph', ++ 'ul' : 'unordered_list', 'img' : 'image', 'em' : 'emphasis' } ++ ++# We append each of these characters in sequence to distinguish between ++# different placeholders with basically the same name (e.g. BOLD1, BOLD2). ++# Keep in mind that a placeholder name must not be a substring of any other ++# placeholder name in the same message, so we can't simply count (BOLD_1 ++# would be a substring of BOLD_10). ++_SUFFIXES = '123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ++ ++# Matches whitespace in an HTML document. Also matches HTML comments, which are ++# treated as whitespace. ++_WHITESPACE = lazy_re.compile(r'(\s| |\\n|\\r|<!--\s*desc\s*=.*?-->)+', ++ re.DOTALL) ++ ++# Matches whitespace sequences which can be folded into a single whitespace ++# character. This matches single characters so that non-spaces are replaced ++# with spaces. ++_FOLD_WHITESPACE = lazy_re.compile(r'\s+') ++ ++# Finds a non-whitespace character ++_NON_WHITESPACE = lazy_re.compile(r'\S') ++ ++# Matches two or more in a row (a single   is not changed into ++# placeholders because different languages require different numbers of spaces ++# and placeholders must match exactly; more than one is probably a "special" ++# whitespace sequence and should be turned into a placeholder). ++_NBSP = lazy_re.compile(r' ( )+') ++ ++# Matches nontranslateable chunks of the document ++_NONTRANSLATEABLES = lazy_re.compile(r''' ++ <\s*script.+?<\s*/\s*script\s*> ++ | ++ <\s*style.+?<\s*/\s*style\s*> ++ | ++ <!--.+?--> ++ | ++ <\?IMPORT\s.+?> # import tag ++ | ++ <\s*[a-zA-Z_]+:.+?> # custom tag (open) ++ | ++ <\s*/\s*[a-zA-Z_]+:.+?> # custom tag (close) ++ | ++ <!\s*[A-Z]+\s*([^>]+|"[^"]+"|'[^']+')*?> ++ ''', re.MULTILINE | re.DOTALL | re.VERBOSE | re.IGNORECASE) ++ ++# Matches a tag and its attributes ++_ELEMENT = lazy_re.compile(r''' ++ # Optional closing /, element name ++ <\s*(?P<closing>/)?\s*(?P<element>[a-zA-Z0-9]+)\s* ++ # Attributes and/or replaceables inside the tag, if any ++ (?P<atts>( ++ \s*([a-zA-Z_][-:.a-zA-Z_0-9]*) # Attribute name ++ (\s*=\s*(\'[^\']*\'|"[^"]*"|[-a-zA-Z0-9./,:;+*%?!&$\(\)_#=~\'"@]*))? ++ | ++ \s*\[(\$?\~)?([A-Z0-9-_]+?)(\~\$?)?\] ++ )*) ++ \s*(?P<empty>/)?\s*> # Optional empty-tag closing /, and tag close ++ ''', ++ re.MULTILINE | re.DOTALL | re.VERBOSE) ++ ++# Matches elements that may have translateable attributes. The value of these ++# special attributes is given by group 'value1' or 'value2'. Note that this ++# regexp demands that the attribute value be quoted; this is necessary because ++# the non-tree-building nature of the parser means we don't know when we're ++# writing out attributes, so we wouldn't know to escape spaces. ++_SPECIAL_ELEMENT = lazy_re.compile(r''' ++ <\s*( ++ input[^>]+?value\s*=\s*(\'(?P<value3>[^\']*)\'|"(?P<value4>[^"]*)") ++ [^>]+type\s*=\s*"?'?(button|reset|text|submit)'?"? ++ | ++ ( ++ table[^>]+?title\s*= ++ | ++ img[^>]+?alt\s*= ++ | ++ input[^>]+?type\s*=\s*"?'?(button|reset|text|submit)'?"?[^>]+?value\s*= ++ ) ++ \s*(\'(?P<value1>[^\']*)\'|"(?P<value2>[^"]*)") ++ )[^>]*?> ++ ''', re.MULTILINE | re.DOTALL | re.VERBOSE | re.IGNORECASE) ++ ++# Matches stuff that is translateable if it occurs in the right context ++# (between tags). This includes all characters and character entities. ++# Note that this also matches which needs to be handled as whitespace ++# before this regexp is applied. ++_CHARACTERS = lazy_re.compile(r''' ++ ( ++ \w ++ | ++ [\!\@\#\$\%\^\*\(\)\-\=\_\+\[\]\{\}\\\|\;\:\'\"\,\.\/\?\`\~] ++ | ++ &(\#[0-9]+|\#x[0-9a-fA-F]+|[A-Za-z0-9]+); ++ )+ ++ ''', re.MULTILINE | re.DOTALL | re.VERBOSE) ++ ++# Matches Total Recall's "replaceable" tags, which are just any text ++# in capitals enclosed by delimiters like [] or [~~] or [$~~$] (e.g. [HELLO], ++# [~HELLO~] and [$~HELLO~$]). ++_REPLACEABLE = lazy_re.compile(r'\[(\$?\~)?(?P<name>[A-Z0-9-_]+?)(\~\$?)?\]', ++ re.MULTILINE) ++ ++ ++# Matches the silly [!]-prefixed "header" that is used in some TotalRecall ++# templates. ++_SILLY_HEADER = lazy_re.compile(r'\[!\]\ntitle\t(?P<title>[^\n]+?)\n.+?\n\n', ++ re.MULTILINE | re.DOTALL) ++ ++ ++# Matches a comment that provides a description for the message it occurs in. ++_DESCRIPTION_COMMENT = lazy_re.compile( ++ r'<!--\s*desc\s*=\s*(?P<description>.+?)\s*-->', re.DOTALL) ++ ++# Matches a comment which is used to break apart multiple messages. ++_MESSAGE_BREAK_COMMENT = lazy_re.compile(r'<!--\s*message-break\s*-->', ++ re.DOTALL) ++ ++# Matches a comment which is used to prevent block tags from splitting a message ++_MESSAGE_NO_BREAK_COMMENT = re.compile(r'<!--\s*message-no-break\s*-->', ++ re.DOTALL) ++ ++ ++_DEBUG = 0 ++def _DebugPrint(text): ++ if _DEBUG: ++ print(text.encode('utf-8')) ++ ++ ++class HtmlChunks(object): ++ '''A parser that knows how to break an HTML-like document into a list of ++ chunks, where each chunk is either translateable or non-translateable. ++ The chunks are unmodified sections of the original document, so concatenating ++ the text of all chunks would result in the original document.''' ++ ++ def InTranslateable(self): ++ return self.last_translateable != -1 ++ ++ def Rest(self): ++ return self.text_[self.current:] ++ ++ def StartTranslateable(self): ++ assert not self.InTranslateable() ++ if self.current != 0: ++ # Append a nontranslateable chunk ++ chunk_text = self.text_[self.chunk_start : self.last_nontranslateable + 1] ++ # Needed in the case where document starts with a translateable. ++ if len(chunk_text) > 0: ++ self.AddChunk(False, chunk_text) ++ self.chunk_start = self.last_nontranslateable + 1 ++ self.last_translateable = self.current ++ self.last_nontranslateable = -1 ++ ++ def EndTranslateable(self): ++ assert self.InTranslateable() ++ # Append a translateable chunk ++ self.AddChunk(True, ++ self.text_[self.chunk_start : self.last_translateable + 1]) ++ self.chunk_start = self.last_translateable + 1 ++ self.last_translateable = -1 ++ self.last_nontranslateable = self.current ++ ++ def AdvancePast(self, match): ++ self.current += match.end() ++ ++ def AddChunk(self, translateable, text): ++ '''Adds a chunk to self, removing linebreaks and duplicate whitespace ++ if appropriate. ++ ''' ++ m = _DESCRIPTION_COMMENT.search(text) ++ if m: ++ self.last_description = m.group('description') ++ # Remove the description from the output text ++ text = _DESCRIPTION_COMMENT.sub('', text) ++ ++ m = _MESSAGE_BREAK_COMMENT.search(text) ++ if m: ++ # Remove the coment from the output text. It should already effectively ++ # break apart messages. ++ text = _MESSAGE_BREAK_COMMENT.sub('', text) ++ ++ if translateable and not self.last_element_ in _PREFORMATTED_TAGS: ++ if self.fold_whitespace_: ++ # Fold whitespace sequences if appropriate. This is optional because it ++ # alters the output strings. ++ text = _FOLD_WHITESPACE.sub(' ', text) ++ else: ++ text = text.replace('\n', ' ') ++ text = text.replace('\r', ' ') ++ # This whitespace folding doesn't work in all cases, thus the ++ # fold_whitespace flag to support backwards compatibility. ++ text = text.replace(' ', ' ') ++ text = text.replace(' ', ' ') ++ ++ if translateable: ++ description = self.last_description ++ self.last_description = '' ++ else: ++ description = '' ++ ++ if text != '': ++ self.chunks_.append((translateable, text, description)) ++ ++ def Parse(self, text, fold_whitespace): ++ '''Parses self.text_ into an intermediate format stored in self.chunks_ ++ which is translateable and nontranslateable chunks. Also returns ++ self.chunks_ ++ ++ Args: ++ text: The HTML for parsing. ++ fold_whitespace: Whether whitespace sequences should be folded into a ++ single space. ++ ++ Return: ++ [chunk1, chunk2, chunk3, ...] (instances of class Chunk) ++ ''' ++ # ++ # Chunker state ++ # ++ ++ self.text_ = text ++ self.fold_whitespace_ = fold_whitespace ++ ++ # A list of tuples (is_translateable, text) which represents the document ++ # after chunking. ++ self.chunks_ = [] ++ ++ # Start index of the last chunk, whether translateable or not ++ self.chunk_start = 0 ++ ++ # Index of the last for-sure translateable character if we are parsing ++ # a translateable chunk, -1 to indicate we are not in a translateable chunk. ++ # This is needed so that we don't include trailing whitespace in the ++ # translateable chunk (whitespace is neutral). ++ self.last_translateable = -1 ++ ++ # Index of the last for-sure nontranslateable character if we are parsing ++ # a nontranslateable chunk, -1 if we are not in a nontranslateable chunk. ++ # This is needed to make sure we can group e.g. "<b>Hello</b> there" ++ # together instead of just "Hello</b> there" which would be much worse ++ # for translation. ++ self.last_nontranslateable = -1 ++ ++ # Index of the character we're currently looking at. ++ self.current = 0 ++ ++ # The name of the last block element parsed. ++ self.last_element_ = '' ++ ++ # The last explicit description we found. ++ self.last_description = '' ++ ++ # Whether no-break was the last chunk seen ++ self.last_nobreak = False ++ ++ while self.current < len(self.text_): ++ _DebugPrint('REST: %s' % self.text_[self.current:self.current+60]) ++ ++ m = _MESSAGE_NO_BREAK_COMMENT.match(self.Rest()) ++ if m: ++ self.AdvancePast(m) ++ self.last_nobreak = True ++ continue ++ ++ # Try to match whitespace ++ m = _WHITESPACE.match(self.Rest()) ++ if m: ++ # Whitespace is neutral, it just advances 'current' and does not switch ++ # between translateable/nontranslateable. If we are in a ++ # nontranslateable section that extends to the current point, we extend ++ # it to include the whitespace. If we are in a translateable section, ++ # we do not extend it until we find ++ # more translateable parts, because we never want a translateable chunk ++ # to end with whitespace. ++ if (not self.InTranslateable() and ++ self.last_nontranslateable == self.current - 1): ++ self.last_nontranslateable = self.current + m.end() - 1 ++ self.AdvancePast(m) ++ continue ++ ++ # Then we try to match nontranslateables ++ m = _NONTRANSLATEABLES.match(self.Rest()) ++ if m: ++ if self.InTranslateable(): ++ self.EndTranslateable() ++ self.last_nontranslateable = self.current + m.end() - 1 ++ self.AdvancePast(m) ++ continue ++ ++ # Now match all other HTML element tags (opening, closing, or empty, we ++ # don't care). ++ m = _ELEMENT.match(self.Rest()) ++ if m: ++ element_name = m.group('element').lower() ++ if element_name in _BLOCK_TAGS: ++ self.last_element_ = element_name ++ if self.InTranslateable(): ++ if self.last_nobreak: ++ self.last_nobreak = False ++ else: ++ self.EndTranslateable() ++ ++ # Check for "special" elements, i.e. ones that have a translateable ++ # attribute, and handle them correctly. Note that all of the ++ # "special" elements are block tags, so no need to check for this ++ # if the tag is not a block tag. ++ sm = _SPECIAL_ELEMENT.match(self.Rest()) ++ if sm: ++ # Get the appropriate group name ++ for group in sm.groupdict(): ++ if sm.groupdict()[group]: ++ break ++ ++ # First make a nontranslateable chunk up to and including the ++ # quote before the translateable attribute value ++ self.AddChunk(False, self.text_[ ++ self.chunk_start : self.current + sm.start(group)]) ++ # Then a translateable for the translateable bit ++ self.AddChunk(True, self.Rest()[sm.start(group) : sm.end(group)]) ++ # Finally correct the data invariant for the parser ++ self.chunk_start = self.current + sm.end(group) ++ ++ self.last_nontranslateable = self.current + m.end() - 1 ++ elif self.InTranslateable(): ++ # We're in a translateable and the tag is an inline tag, so we ++ # need to include it in the translateable. ++ self.last_translateable = self.current + m.end() - 1 ++ self.AdvancePast(m) ++ continue ++ ++ # Anything else we find must be translateable, so we advance one character ++ # at a time until one of the above matches. ++ if not self.InTranslateable(): ++ self.StartTranslateable() ++ else: ++ self.last_translateable = self.current ++ self.current += 1 ++ ++ # Close the final chunk ++ if self.InTranslateable(): ++ self.AddChunk(True, self.text_[self.chunk_start : ]) ++ else: ++ self.AddChunk(False, self.text_[self.chunk_start : ]) ++ ++ return self.chunks_ ++ ++ ++def HtmlToMessage(html, include_block_tags=False, description=''): ++ '''Takes a bit of HTML, which must contain only "inline" HTML elements, ++ and changes it into a tclib.Message. This involves escaping any entities and ++ replacing any HTML code with placeholders. ++ ++ If include_block_tags is true, no error will be given if block tags (e.g. ++ <p> or <br>) are included in the HTML. ++ ++ Args: ++ html: 'Hello <b>[USERNAME]</b>, how <i>are</i> you?' ++ include_block_tags: False ++ ++ Return: ++ tclib.Message('Hello START_BOLD1USERNAMEEND_BOLD, ' ++ 'howNBSPSTART_ITALICareEND_ITALIC you?', ++ [ Placeholder('START_BOLD', '<b>', ''), ++ Placeholder('USERNAME', '[USERNAME]', ''), ++ Placeholder('END_BOLD', '</b>', ''), ++ Placeholder('START_ITALIC', '<i>', ''), ++ Placeholder('END_ITALIC', '</i>', ''), ]) ++ ''' ++ # Approach is: ++ # - first placeholderize, finding <elements>, [REPLACEABLES] and ++ # - then escape all character entities in text in-between placeholders ++ ++ parts = [] # List of strings (for text chunks) and tuples (ID, original) ++ # for placeholders ++ ++ count_names = {} # Map of base names to number of times used ++ end_names = {} # Map of base names to stack of end tags (for correct nesting) ++ ++ def MakeNameClosure(base, type = ''): ++ '''Returns a closure that can be called once all names have been allocated ++ to return the final name of the placeholder. This allows us to minimally ++ number placeholders for non-overlap. ++ ++ Also ensures that END_XXX_Y placeholders have the same Y as the ++ corresponding BEGIN_XXX_Y placeholder when we have nested tags of the same ++ type. ++ ++ Args: ++ base: 'phname' ++ type: '' | 'begin' | 'end' ++ ++ Return: ++ Closure() ++ ''' ++ name = base.upper() ++ if type != '': ++ name = ('%s_%s' % (type, base)).upper() ++ ++ count_names.setdefault(name, 0) ++ count_names[name] += 1 ++ ++ def MakeFinalName(name_ = name, index = count_names[name] - 1): ++ if type.lower() == 'end' and end_names.get(base): ++ return end_names[base].pop(-1) # For correct nesting ++ if count_names[name_] != 1: ++ name_ = '%s_%s' % (name_, _SUFFIXES[index]) ++ # We need to use a stack to ensure that the end-tag suffixes match ++ # the begin-tag suffixes. Only needed when more than one tag of the ++ # same type. ++ if type == 'begin': ++ end_name = ('END_%s_%s' % (base, _SUFFIXES[index])).upper() ++ if base in end_names: ++ end_names[base].append(end_name) ++ else: ++ end_names[base] = [end_name] ++ ++ return name_ ++ ++ return MakeFinalName ++ ++ current = 0 ++ last_nobreak = False ++ ++ while current < len(html): ++ m = _MESSAGE_NO_BREAK_COMMENT.match(html[current:]) ++ if m: ++ last_nobreak = True ++ current += m.end() ++ continue ++ ++ m = _NBSP.match(html[current:]) ++ if m: ++ parts.append((MakeNameClosure('SPACE'), m.group())) ++ current += m.end() ++ continue ++ ++ m = _REPLACEABLE.match(html[current:]) ++ if m: ++ # Replaceables allow - but placeholders don't, so replace - with _ ++ ph_name = MakeNameClosure('X_%s_X' % m.group('name').replace('-', '_')) ++ parts.append((ph_name, m.group())) ++ current += m.end() ++ continue ++ ++ m = _SPECIAL_ELEMENT.match(html[current:]) ++ if m: ++ if not include_block_tags: ++ if last_nobreak: ++ last_nobreak = False ++ else: ++ raise exception.BlockTagInTranslateableChunk(html) ++ element_name = 'block' # for simplification ++ # Get the appropriate group name ++ for group in m.groupdict(): ++ if m.groupdict()[group]: ++ break ++ parts.append((MakeNameClosure(element_name, 'begin'), ++ html[current : current + m.start(group)])) ++ parts.append(m.group(group)) ++ parts.append((MakeNameClosure(element_name, 'end'), ++ html[current + m.end(group) : current + m.end()])) ++ current += m.end() ++ continue ++ ++ m = _ELEMENT.match(html[current:]) ++ if m: ++ element_name = m.group('element').lower() ++ if not include_block_tags and not element_name in _INLINE_TAGS: ++ if last_nobreak: ++ last_nobreak = False ++ else: ++ raise exception.BlockTagInTranslateableChunk(html[current:]) ++ if element_name in _HTML_PLACEHOLDER_NAMES: # use meaningful names ++ element_name = _HTML_PLACEHOLDER_NAMES[element_name] ++ ++ # Make a name for the placeholder ++ type = '' ++ if not m.group('empty'): ++ if m.group('closing'): ++ type = 'end' ++ else: ++ type = 'begin' ++ parts.append((MakeNameClosure(element_name, type), m.group())) ++ current += m.end() ++ continue ++ ++ if len(parts) and isinstance(parts[-1], six.string_types): ++ parts[-1] += html[current] ++ else: ++ parts.append(html[current]) ++ current += 1 ++ ++ msg_text = '' ++ placeholders = [] ++ for part in parts: ++ if isinstance(part, tuple): ++ final_name = part[0]() ++ original = part[1] ++ msg_text += final_name ++ placeholders.append(tclib.Placeholder(final_name, original, '(HTML code)')) ++ else: ++ msg_text += part ++ ++ msg = tclib.Message(text=msg_text, placeholders=placeholders, ++ description=description) ++ content = msg.GetContent() ++ for ix in range(len(content)): ++ if isinstance(content[ix], six.string_types): ++ content[ix] = util.UnescapeHtml(content[ix], replace_nbsp=False) ++ ++ return msg ++ ++ ++class TrHtml(interface.GathererBase): ++ '''Represents a document or message in the template format used by ++ Total Recall for HTML documents.''' ++ ++ def __init__(self, *args, **kwargs): ++ super(TrHtml, self).__init__(*args, **kwargs) ++ self.have_parsed_ = False ++ self.skeleton_ = [] # list of strings and MessageClique objects ++ self.fold_whitespace_ = False ++ ++ def SetAttributes(self, attrs): ++ '''Sets node attributes used by the gatherer. ++ ++ This checks the fold_whitespace attribute. ++ ++ Args: ++ attrs: The mapping of node attributes. ++ ''' ++ self.fold_whitespace_ = ('fold_whitespace' in attrs and ++ attrs['fold_whitespace'] == 'true') ++ ++ def GetText(self): ++ '''Returns the original text of the HTML document''' ++ return self.text_ ++ ++ def GetTextualIds(self): ++ return [self.extkey] ++ ++ def GetCliques(self): ++ '''Returns the message cliques for each translateable message in the ++ document.''' ++ return [x for x in self.skeleton_ if isinstance(x, clique.MessageClique)] ++ ++ def Translate(self, lang, pseudo_if_not_available=True, ++ skeleton_gatherer=None, fallback_to_english=False): ++ '''Returns this document with translateable messages filled with ++ the translation for language 'lang'. ++ ++ Args: ++ lang: 'en' ++ pseudo_if_not_available: True ++ ++ Return: ++ 'ID_THIS_SECTION TYPE\n...BEGIN\n "Translated message"\n......\nEND ++ ++ Raises: ++ grit.exception.NotReady() if used before Parse() has been successfully ++ called. ++ grit.exception.NoSuchTranslation() if 'pseudo_if_not_available' is false ++ and there is no translation for the requested language. ++ ''' ++ if len(self.skeleton_) == 0: ++ raise exception.NotReady() ++ ++ # TODO(joi) Implement support for skeleton gatherers here. ++ ++ out = [] ++ for item in self.skeleton_: ++ if isinstance(item, six.string_types): ++ out.append(item) ++ else: ++ msg = item.MessageForLanguage(lang, ++ pseudo_if_not_available, ++ fallback_to_english) ++ for content in msg.GetContent(): ++ if isinstance(content, tclib.Placeholder): ++ out.append(content.GetOriginal()) ++ else: ++ # We escape " characters to increase the chance that attributes ++ # will be properly escaped. ++ out.append(util.EscapeHtml(content, True)) ++ ++ return ''.join(out) ++ ++ def Parse(self): ++ if self.have_parsed_: ++ return ++ self.have_parsed_ = True ++ ++ text = self._LoadInputFile() ++ ++ # Ignore the BOM character if the document starts with one. ++ if text.startswith(u'\ufeff'): ++ text = text[1:] ++ ++ self.text_ = text ++ ++ # Parsing is done in two phases: First, we break the document into ++ # translateable and nontranslateable chunks. Second, we run through each ++ # translateable chunk and insert placeholders for any HTML elements, ++ # unescape escaped characters, etc. ++ ++ # First handle the silly little [!]-prefixed header because it's not ++ # handled by our HTML parsers. ++ m = _SILLY_HEADER.match(text) ++ if m: ++ self.skeleton_.append(text[:m.start('title')]) ++ self.skeleton_.append(self.uberclique.MakeClique( ++ tclib.Message(text=text[m.start('title'):m.end('title')]))) ++ self.skeleton_.append(text[m.end('title') : m.end()]) ++ text = text[m.end():] ++ ++ chunks = HtmlChunks().Parse(text, self.fold_whitespace_) ++ ++ for chunk in chunks: ++ if chunk[0]: # Chunk is translateable ++ self.skeleton_.append(self.uberclique.MakeClique( ++ HtmlToMessage(chunk[1], description=chunk[2]))) ++ else: ++ self.skeleton_.append(chunk[1]) ++ ++ # Go through the skeleton and change any messages that consist solely of ++ # placeholders and whitespace into nontranslateable strings. ++ for ix in range(len(self.skeleton_)): ++ got_text = False ++ if isinstance(self.skeleton_[ix], clique.MessageClique): ++ msg = self.skeleton_[ix].GetMessage() ++ for item in msg.GetContent(): ++ if (isinstance(item, six.string_types) ++ and _NON_WHITESPACE.search(item) and item != ' '): ++ got_text = True ++ break ++ if not got_text: ++ self.skeleton_[ix] = msg.GetRealContent() ++ ++ def SubstituteMessages(self, substituter): ++ '''Applies substitutions to all messages in the tree. ++ ++ Goes through the skeleton and finds all MessageCliques. ++ ++ Args: ++ substituter: a grit.util.Substituter object. ++ ''' ++ new_skel = [] ++ for chunk in self.skeleton_: ++ if isinstance(chunk, clique.MessageClique): ++ old_message = chunk.GetMessage() ++ new_message = substituter.SubstituteMessage(old_message) ++ if new_message is not old_message: ++ new_skel.append(self.uberclique.MakeClique(new_message)) ++ continue ++ new_skel.append(chunk) ++ self.skeleton_ = new_skel +diff --git a/tools/grit/grit/gather/tr_html_unittest.py b/tools/grit/grit/gather/tr_html_unittest.py +new file mode 100644 +index 0000000000..1194853d9a +--- /dev/null ++++ b/tools/grit/grit/gather/tr_html_unittest.py +@@ -0,0 +1,524 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+} // namespace ++'''Unit tests for grit.gather.tr_html''' + -+static FrontendPluginRegistry::Add<FindBadConstructsAction> -+X("find-bad-constructs", "Finds bad C++ constructs"); -diff --git a/tools/clang/plugins/Makefile b/tools/clang/plugins/Makefile ++from __future__ import print_function ++ ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++import unittest ++ ++import six ++from six import StringIO ++ ++from grit.gather import tr_html ++from grit import clique ++from grit import util ++ ++ ++class ParserUnittest(unittest.TestCase): ++ def testChunkingWithoutFoldWhitespace(self): ++ self.VerifyChunking(False) ++ ++ def testChunkingWithFoldWhitespace(self): ++ self.VerifyChunking(True) ++ ++ def VerifyChunking(self, fold_whitespace): ++ """Use a single function to run all chunking testing. ++ ++ This makes it easier to run chunking with fold_whitespace both on and off, ++ to make sure the outputs are the same. ++ ++ Args: ++ fold_whitespace: Whether whitespace sequences should be folded into a ++ single space. ++ """ ++ self.VerifyChunkingBasic(fold_whitespace) ++ self.VerifyChunkingDescriptions(fold_whitespace) ++ self.VerifyChunkingReplaceables(fold_whitespace) ++ self.VerifyChunkingLineBreaks(fold_whitespace) ++ self.VerifyChunkingMessageBreak(fold_whitespace) ++ self.VerifyChunkingMessageNoBreak(fold_whitespace) ++ ++ def VerifyChunkingBasic(self, fold_whitespace): ++ p = tr_html.HtmlChunks() ++ chunks = p.Parse('<p>Hello <b>dear</b> how <i>are</i>you?<p>Fine!', ++ fold_whitespace) ++ self.failUnlessEqual(chunks, [ ++ (False, '<p>', ''), (True, 'Hello <b>dear</b> how <i>are</i>you?', ''), ++ (False, '<p>', ''), (True, 'Fine!', '')]) ++ ++ chunks = p.Parse('<p> Hello <b>dear</b> how <i>are</i>you? <p>Fine!', ++ fold_whitespace) ++ self.failUnlessEqual(chunks, [ ++ (False, '<p> ', ''), (True, 'Hello <b>dear</b> how <i>are</i>you?', ''), ++ (False, ' <p>', ''), (True, 'Fine!', '')]) ++ ++ chunks = p.Parse('<p> Hello <b>dear how <i>are you? <p> Fine!', ++ fold_whitespace) ++ self.failUnlessEqual(chunks, [ ++ (False, '<p> ', ''), (True, 'Hello <b>dear how <i>are you?', ''), ++ (False, ' <p> ', ''), (True, 'Fine!', '')]) ++ ++ # Ensure translateable sections that start with inline tags contain ++ # the starting inline tag. ++ chunks = p.Parse('<b>Hello!</b> how are you?<p><i>I am fine.</i>', ++ fold_whitespace) ++ self.failUnlessEqual(chunks, [ ++ (True, '<b>Hello!</b> how are you?', ''), (False, '<p>', ''), ++ (True, '<i>I am fine.</i>', '')]) ++ ++ # Ensure translateable sections that end with inline tags contain ++ # the ending inline tag. ++ chunks = p.Parse("Hello! How are <b>you?</b><p><i>I'm fine!</i>", ++ fold_whitespace) ++ self.failUnlessEqual(chunks, [ ++ (True, 'Hello! How are <b>you?</b>', ''), (False, '<p>', ''), ++ (True, "<i>I'm fine!</i>", '')]) ++ ++ def VerifyChunkingDescriptions(self, fold_whitespace): ++ p = tr_html.HtmlChunks() ++ # Check capitals and explicit descriptions ++ chunks = p.Parse('<!-- desc=bingo! --><B>Hello!</B> how are you?<P>' ++ '<I>I am fine.</I>', fold_whitespace) ++ self.failUnlessEqual(chunks, [ ++ (True, '<B>Hello!</B> how are you?', 'bingo!'), (False, '<P>', ''), ++ (True, '<I>I am fine.</I>', '')]) ++ chunks = p.Parse('<B><!-- desc=bingo! -->Hello!</B> how are you?<P>' ++ '<I>I am fine.</I>', fold_whitespace) ++ self.failUnlessEqual(chunks, [ ++ (True, '<B>Hello!</B> how are you?', 'bingo!'), (False, '<P>', ''), ++ (True, '<I>I am fine.</I>', '')]) ++ # Linebreaks get handled by the tclib message. ++ chunks = p.Parse('<B>Hello!</B> <!-- desc=bi\nngo\n! -->how are you?<P>' ++ '<I>I am fine.</I>', fold_whitespace) ++ self.failUnlessEqual(chunks, [ ++ (True, '<B>Hello!</B> how are you?', 'bi\nngo\n!'), (False, '<P>', ''), ++ (True, '<I>I am fine.</I>', '')]) ++ ++ # In this case, because the explicit description appears after the first ++ # translateable, it will actually apply to the second translateable. ++ chunks = p.Parse('<B>Hello!</B> how are you?<!-- desc=bingo! --><P>' ++ '<I>I am fine.</I>', fold_whitespace) ++ self.failUnlessEqual(chunks, [ ++ (True, '<B>Hello!</B> how are you?', ''), (False, '<P>', ''), ++ (True, '<I>I am fine.</I>', 'bingo!')]) ++ ++ def VerifyChunkingReplaceables(self, fold_whitespace): ++ # Check that replaceables within block tags (where attributes would go) are ++ # handled correctly. ++ p = tr_html.HtmlChunks() ++ chunks = p.Parse('<b>Hello!</b> how are you?<p [BINGO] [$~BONGO~$]>' ++ '<i>I am fine.</i>', fold_whitespace) ++ self.failUnlessEqual(chunks, [ ++ (True, '<b>Hello!</b> how are you?', ''), ++ (False, '<p [BINGO] [$~BONGO~$]>', ''), ++ (True, '<i>I am fine.</i>', '')]) ++ ++ def VerifyChunkingLineBreaks(self, fold_whitespace): ++ # Check that the contents of preformatted tags preserve line breaks. ++ p = tr_html.HtmlChunks() ++ chunks = p.Parse('<textarea>Hello\nthere\nhow\nare\nyou?</textarea>', ++ fold_whitespace) ++ self.failUnlessEqual(chunks, [(False, '<textarea>', ''), ++ (True, 'Hello\nthere\nhow\nare\nyou?', ''), (False, '</textarea>', '')]) ++ ++ # ...and that other tags' line breaks are converted to spaces ++ chunks = p.Parse('<p>Hello\nthere\nhow\nare\nyou?</p>', fold_whitespace) ++ self.failUnlessEqual(chunks, [(False, '<p>', ''), ++ (True, 'Hello there how are you?', ''), (False, '</p>', '')]) ++ ++ def VerifyChunkingMessageBreak(self, fold_whitespace): ++ p = tr_html.HtmlChunks() ++ # Make sure that message-break comments work properly. ++ chunks = p.Parse('Break<!-- message-break --> apart ' ++ '<!--message-break-->messages', fold_whitespace) ++ self.failUnlessEqual(chunks, [(True, 'Break', ''), ++ (False, ' ', ''), ++ (True, 'apart', ''), ++ (False, ' ', ''), ++ (True, 'messages', '')]) ++ ++ # Make sure message-break comments work in an inline tag. ++ chunks = p.Parse('<a href=\'google.com\'><!-- message-break -->Google' ++ '<!--message-break--></a>', fold_whitespace) ++ self.failUnlessEqual(chunks, [(False, '<a href=\'google.com\'>', ''), ++ (True, 'Google', ''), ++ (False, '</a>', '')]) ++ ++ def VerifyChunkingMessageNoBreak(self, fold_whitespace): ++ p = tr_html.HtmlChunks() ++ # Make sure that message-no-break comments work properly. ++ chunks = p.Parse('Please <!-- message-no-break --> <br />don\'t break', ++ fold_whitespace) ++ self.failUnlessEqual(chunks, [(True, 'Please <!-- message-no-break --> ' ++ '<br />don\'t break', '')]) ++ ++ chunks = p.Parse('Please <br /> break. <!-- message-no-break --> <br /> ' ++ 'But not this time.', fold_whitespace) ++ self.failUnlessEqual(chunks, [(True, 'Please', ''), ++ (False, ' <br /> ', ''), ++ (True, 'break. <!-- message-no-break --> ' ++ '<br /> But not this time.', '')]) ++ ++ def testTranslateableAttributes(self): ++ p = tr_html.HtmlChunks() ++ ++ # Check that the translateable attributes in <img>, <submit>, <button> and ++ # <text> elements buttons are handled correctly. ++ chunks = p.Parse('<img src=bingo.jpg alt="hello there">' ++ '<input type=submit value="hello">' ++ '<input type="button" value="hello">' ++ '<input type=\'text\' value=\'Howdie\'>', False) ++ self.failUnlessEqual(chunks, [ ++ (False, '<img src=bingo.jpg alt="', ''), (True, 'hello there', ''), ++ (False, '"><input type=submit value="', ''), (True, 'hello', ''), ++ (False, '"><input type="button" value="', ''), (True, 'hello', ''), ++ (False, '"><input type=\'text\' value=\'', ''), (True, 'Howdie', ''), ++ (False, '\'>', '')]) ++ ++ ++ def testTranslateableHtmlToMessage(self): ++ msg = tr_html.HtmlToMessage( ++ 'Hello <b>[USERNAME]</b>, <how> <i>are</i> you?') ++ pres = msg.GetPresentableContent() ++ self.failUnless(pres == ++ 'Hello BEGIN_BOLDX_USERNAME_XEND_BOLD, ' ++ '<how> BEGIN_ITALICareEND_ITALIC you?') ++ ++ msg = tr_html.HtmlToMessage('<b>Hello</b><I>Hello</I><b>Hello</b>') ++ pres = msg.GetPresentableContent() ++ self.failUnless(pres == ++ 'BEGIN_BOLD_1HelloEND_BOLD_1BEGIN_ITALICHelloEND_ITALIC' ++ 'BEGIN_BOLD_2HelloEND_BOLD_2') ++ ++ # Check that nesting (of the <font> tags) is handled correctly - i.e. that ++ # the closing placeholder numbers match the opening placeholders. ++ msg = tr_html.HtmlToMessage( ++ '''<font size=-1><font color=#FF0000>Update!</font> ''' ++ '''<a href='http://desktop.google.com/whatsnew.html?hl=[$~LANG~$]'>''' ++ '''New Features</a>: Now search PDFs, MP3s, Firefox web history, and ''' ++ '''more</font>''') ++ pres = msg.GetPresentableContent() ++ self.failUnless(pres == ++ 'BEGIN_FONT_1BEGIN_FONT_2Update!END_FONT_2 BEGIN_LINK' ++ 'New FeaturesEND_LINK: Now search PDFs, MP3s, Firefox ' ++ 'web history, and moreEND_FONT_1') ++ ++ msg = tr_html.HtmlToMessage('''<a href='[$~URL~$]'><b>[NUM][CAT]</b></a>''') ++ pres = msg.GetPresentableContent() ++ self.failUnless(pres == 'BEGIN_LINKBEGIN_BOLDX_NUM_XX_CAT_XEND_BOLDEND_LINK') ++ ++ msg = tr_html.HtmlToMessage( ++ '''<font size=-1><a class=q onClick='return window.qs?qs(this):1' ''' ++ '''href='http://[WEBSERVER][SEARCH_URI]'>Desktop</a></font> ''' ++ ''' ''') ++ pres = msg.GetPresentableContent() ++ self.failUnless(pres == ++ '''BEGIN_FONTBEGIN_LINKDesktopEND_LINKEND_FONTSPACE''') ++ ++ msg = tr_html.HtmlToMessage( ++ '''<br><br><center><font size=-2>©2005 Google </font></center>''', 1) ++ pres = msg.GetPresentableContent() ++ self.failUnless(pres == ++ u'BEGIN_BREAK_1BEGIN_BREAK_2BEGIN_CENTERBEGIN_FONT\xa92005' ++ u' Google END_FONTEND_CENTER') ++ ++ msg = tr_html.HtmlToMessage( ++ ''' - <a class=c href=[$~CACHE~$]>Cached</a>''') ++ pres = msg.GetPresentableContent() ++ self.failUnless(pres == ++ ' - BEGIN_LINKCachedEND_LINK') ++ ++ # Check that upper-case tags are handled correctly. ++ msg = tr_html.HtmlToMessage( ++ '''You can read the <A HREF='http://desktop.google.com/privacypolicy.''' ++ '''html?hl=[LANG_CODE]'>Privacy Policy</A> and <A HREF='http://desktop''' ++ '''.google.com/privacyfaq.html?hl=[LANG_CODE]'>Privacy FAQ</A> online.''') ++ pres = msg.GetPresentableContent() ++ self.failUnless(pres == ++ 'You can read the BEGIN_LINK_1Privacy PolicyEND_LINK_1 and ' ++ 'BEGIN_LINK_2Privacy FAQEND_LINK_2 online.') ++ ++ # Check that tags with linebreaks immediately preceding them are handled ++ # correctly. ++ msg = tr_html.HtmlToMessage( ++ '''You can read the ++<A HREF='http://desktop.google.com/privacypolicy.html?hl=[LANG_CODE]'>Privacy Policy</A> ++and <A HREF='http://desktop.google.com/privacyfaq.html?hl=[LANG_CODE]'>Privacy FAQ</A> online.''') ++ pres = msg.GetPresentableContent() ++ self.failUnless(pres == '''You can read the ++BEGIN_LINK_1Privacy PolicyEND_LINK_1 ++and BEGIN_LINK_2Privacy FAQEND_LINK_2 online.''') ++ ++ # Check that message-no-break comments are handled correctly. ++ msg = tr_html.HtmlToMessage('''Please <!-- message-no-break --><br /> don't break''') ++ pres = msg.GetPresentableContent() ++ self.failUnlessEqual(pres, '''Please BREAK don't break''') ++ ++class TrHtmlUnittest(unittest.TestCase): ++ def testSetAttributes(self): ++ html = tr_html.TrHtml(StringIO('')) ++ self.failUnlessEqual(html.fold_whitespace_, False) ++ html.SetAttributes({}) ++ self.failUnlessEqual(html.fold_whitespace_, False) ++ html.SetAttributes({'fold_whitespace': 'false'}) ++ self.failUnlessEqual(html.fold_whitespace_, False) ++ html.SetAttributes({'fold_whitespace': 'true'}) ++ self.failUnlessEqual(html.fold_whitespace_, True) ++ ++ def testFoldWhitespace(self): ++ text = '<td> Test Message </td>' ++ ++ html = tr_html.TrHtml(StringIO(text)) ++ html.Parse() ++ self.failUnlessEqual(html.skeleton_[1].GetMessage().GetPresentableContent(), ++ 'Test Message') ++ ++ html = tr_html.TrHtml(StringIO(text)) ++ html.fold_whitespace_ = True ++ html.Parse() ++ self.failUnlessEqual(html.skeleton_[1].GetMessage().GetPresentableContent(), ++ 'Test Message') ++ ++ def testTable(self): ++ html = tr_html.TrHtml(StringIO('''<table class="shaded-header"><tr> ++<td class="header-element b expand">Preferences</td> ++<td class="header-element s"> ++<a href="http://desktop.google.com/preferences.html">Preferences Help</a> ++</td> ++</tr></table>''')) ++ html.Parse() ++ self.failUnless(html.skeleton_[3].GetMessage().GetPresentableContent() == ++ 'BEGIN_LINKPreferences HelpEND_LINK') ++ ++ def testSubmitAttribute(self): ++ html = tr_html.TrHtml(StringIO('''</td> ++<td class="header-element"><input type=submit value="Save Preferences" ++name=submit2></td> ++</tr></table>''')) ++ html.Parse() ++ self.failUnless(html.skeleton_[1].GetMessage().GetPresentableContent() == ++ 'Save Preferences') ++ ++ def testWhitespaceAfterInlineTag(self): ++ '''Test that even if there is whitespace after an inline tag at the start ++ of a translateable section the inline tag will be included. ++ ''' ++ html = tr_html.TrHtml( ++ StringIO('''<label for=DISPLAYNONE><font size=-1> Hello</font>''')) ++ html.Parse() ++ self.failUnless(html.skeleton_[1].GetMessage().GetRealContent() == ++ '<font size=-1> Hello</font>') ++ ++ def testSillyHeader(self): ++ html = tr_html.TrHtml(StringIO('''[!] ++title\tHello ++bingo ++bongo ++bla ++ ++<p>Other stuff</p>''')) ++ html.Parse() ++ content = html.skeleton_[1].GetMessage().GetRealContent() ++ self.failUnless(content == 'Hello') ++ self.failUnless(html.skeleton_[-1] == '</p>') ++ # Right after the translateable the nontranslateable should start with ++ # a linebreak (this catches a bug we had). ++ self.failUnless(html.skeleton_[2][0] == '\n') ++ ++ ++ def testExplicitDescriptions(self): ++ html = tr_html.TrHtml( ++ StringIO('Hello [USER]<br/><!-- desc=explicit -->' ++ '<input type="button">Go!</input>')) ++ html.Parse() ++ msg = html.GetCliques()[1].GetMessage() ++ self.failUnlessEqual(msg.GetDescription(), 'explicit') ++ self.failUnlessEqual(msg.GetRealContent(), 'Go!') ++ ++ html = tr_html.TrHtml( ++ StringIO('Hello [USER]<br/><!-- desc=explicit\nmultiline -->' ++ '<input type="button">Go!</input>')) ++ html.Parse() ++ msg = html.GetCliques()[1].GetMessage() ++ self.failUnlessEqual(msg.GetDescription(), 'explicit multiline') ++ self.failUnlessEqual(msg.GetRealContent(), 'Go!') ++ ++ ++ def testRegressionInToolbarAbout(self): ++ html = tr_html.TrHtml(util.PathFromRoot(r'grit/testdata/toolbar_about.html')) ++ html.Parse() ++ cliques = html.GetCliques() ++ for cl in cliques: ++ content = cl.GetMessage().GetRealContent() ++ if content.count('De parvis grandis acervus erit'): ++ self.failIf(content.count('$/translate')) ++ ++ ++ def HtmlFromFileWithManualCheck(self, f): ++ html = tr_html.TrHtml(f) ++ html.Parse() ++ ++ # For manual results inspection only... ++ list = [] ++ for item in html.skeleton_: ++ if isinstance(item, six.string_types): ++ list.append(item) ++ else: ++ list.append(item.GetMessage().GetPresentableContent()) ++ ++ return html ++ ++ ++ def testPrivacyHtml(self): ++ html = self.HtmlFromFileWithManualCheck( ++ util.PathFromRoot(r'grit/testdata/privacy.html')) ++ ++ self.failUnless(html.skeleton_[1].GetMessage().GetRealContent() == ++ 'Privacy and Google Desktop Search') ++ self.failUnless(html.skeleton_[3].startswith('<')) ++ self.failUnless(len(html.skeleton_) > 10) ++ ++ ++ def testPreferencesHtml(self): ++ html = self.HtmlFromFileWithManualCheck( ++ util.PathFromRoot(r'grit/testdata/preferences.html')) ++ ++ # Verify that we don't get '[STATUS-MESSAGE]' as the original content of ++ # one of the MessageClique objects (it would be a placeholder-only message ++ # and we're supposed to have stripped those). ++ ++ for item in [x for x in html.skeleton_ ++ if isinstance(x, clique.MessageClique)]: ++ if (item.GetMessage().GetRealContent() == '[STATUS-MESSAGE]' or ++ item.GetMessage().GetRealContent() == '[ADDIN-DO] [ADDIN-OPTIONS]'): ++ self.fail() ++ ++ self.failUnless(len(html.skeleton_) > 100) ++ ++ def AssertNumberOfTranslateables(self, files, num): ++ '''Fails if any of the files in files don't have exactly ++ num translateable sections. ++ ++ Args: ++ files: ['file1', 'file2'] ++ num: 3 ++ ''' ++ for f in files: ++ f = util.PathFromRoot(r'grit/testdata/%s' % f) ++ html = self.HtmlFromFileWithManualCheck(f) ++ self.failUnless(len(html.GetCliques()) == num) ++ ++ def testFewTranslateables(self): ++ self.AssertNumberOfTranslateables(['browser.html', 'email_thread.html', ++ 'header.html', 'mini.html', ++ 'oneclick.html', 'script.html', ++ 'time_related.html', 'versions.html'], 0) ++ self.AssertNumberOfTranslateables(['footer.html', 'hover.html'], 1) ++ ++ def testOtherHtmlFilesForManualInspection(self): ++ files = [ ++ 'about.html', 'bad_browser.html', 'cache_prefix.html', ++ 'cache_prefix_file.html', 'chat_result.html', 'del_footer.html', ++ 'del_header.html', 'deleted.html', 'details.html', 'email_result.html', ++ 'error.html', 'explicit_web.html', 'footer.html', ++ 'homepage.html', 'indexing_speed.html', ++ 'install_prefs.html', 'install_prefs2.html', ++ 'oem_enable.html', 'oem_non_admin.html', 'onebox.html', ++ 'password.html', 'quit_apps.html', 'recrawl.html', ++ 'searchbox.html', 'sidebar_h.html', 'sidebar_v.html', 'status.html', ++ ] ++ for f in files: ++ self.HtmlFromFileWithManualCheck( ++ util.PathFromRoot(r'grit/testdata/%s' % f)) ++ ++ def testTranslate(self): ++ # Note that the English translation of documents that use character ++ # literals (e.g. ©) will not be the same as the original document ++ # because the character literal will be transformed into the Unicode ++ # character itself. So for this test we choose some relatively complex ++ # HTML without character entities (but with because that's handled ++ # specially). ++ html = tr_html.TrHtml(StringIO(''' <script> ++ <!-- ++ function checkOffice() { var w = document.getElementById("h7"); ++ var e = document.getElementById("h8"); var o = document.getElementById("h10"); ++ if (!(w.checked || e.checked)) { o.checked=0;o.disabled=1;} else {o.disabled=0;} } ++ // --> ++ </script> ++ <input type=checkbox [CHECK-DOC] name=DOC id=h7 onclick='checkOffice()'> ++ <label for=h7> Word</label><br> ++ <input type=checkbox [CHECK-XLS] name=XLS id=h8 onclick='checkOffice()'> ++ <label for=h8> Excel</label><br> ++ <input type=checkbox [CHECK-PPT] name=PPT id=h9> ++ <label for=h9> PowerPoint</label><br> ++ </span></td><td nowrap valign=top><span class="s"> ++ <input type=checkbox [CHECK-PDF] name=PDF id=hpdf> ++ <label for=hpdf> PDF</label><br> ++ <input type=checkbox [CHECK-TXT] name=TXT id=h6> ++ <label for=h6> Text, media, and other files</label><br> ++ </tr> ++ <tr><td nowrap valign=top colspan=3><span class="s"><br /> ++ <input type=checkbox [CHECK-SECUREOFFICE] name=SECUREOFFICE id=h10> ++ <label for=h10> Password-protected Office documents (Word, Excel)</label><br /> ++ <input type=checkbox [DISABLED-HTTPS] [CHECK-HTTPS] name=HTTPS id=h12><label ++ for=h12> Secure pages (HTTPS) in web history</label></span></td></tr> ++ </table>''')) ++ html.Parse() ++ trans = html.Translate('en') ++ if (html.GetText() != trans): ++ self.fail() ++ ++ ++ def testHtmlToMessageWithBlockTags(self): ++ msg = tr_html.HtmlToMessage( ++ 'Hello<p>Howdie<img alt="bingo" src="image.gif">', True) ++ result = msg.GetPresentableContent() ++ self.failUnless( ++ result == 'HelloBEGIN_PARAGRAPHHowdieBEGIN_BLOCKbingoEND_BLOCK') ++ ++ msg = tr_html.HtmlToMessage( ++ 'Hello<p>Howdie<input type="button" value="bingo">', True) ++ result = msg.GetPresentableContent() ++ self.failUnless( ++ result == 'HelloBEGIN_PARAGRAPHHowdieBEGIN_BLOCKbingoEND_BLOCK') ++ ++ ++ def testHtmlToMessageRegressions(self): ++ msg = tr_html.HtmlToMessage(' - ', True) ++ result = msg.GetPresentableContent() ++ self.failUnless(result == ' - ') ++ ++ ++ def testEscapeUnescaped(self): ++ text = '© & "<hello>"' ++ unescaped = util.UnescapeHtml(text) ++ self.failUnless(unescaped == u'\u00a9\u00a0 & "<hello>"') ++ escaped_unescaped = util.EscapeHtml(unescaped, True) ++ self.failUnless(escaped_unescaped == ++ u'\u00a9\u00a0 & "<hello>"') ++ ++ def testRegressionCjkHtmlFile(self): ++ # TODO(joi) Fix this problem where unquoted attributes that ++ # have a value that is CJK characters causes the regular expression ++ # match never to return. (culprit is the _ELEMENT regexp( ++ if False: ++ html = self.HtmlFromFileWithManualCheck(util.PathFromRoot( ++ r'grit/testdata/ko_oem_enable_bug.html')) ++ self.failUnless(True) ++ ++ def testRegressionCpuHang(self): ++ # If this regression occurs, the unit test will never return ++ html = tr_html.TrHtml(StringIO( ++ '''<input type=text size=12 id=advFileTypeEntry [~SHOW-FILETYPE-BOX~] value="[EXT]" name=ext>''')) ++ html.Parse() ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/gather/txt.py b/tools/grit/grit/gather/txt.py new file mode 100644 -index 0000000000..0cfec71159 +index 0000000000..e5c10abc28 --- /dev/null -+++ b/tools/clang/plugins/Makefile -@@ -0,0 +1,19 @@ -+# This file requires the clang build system, at least for now. So to use this -+# Makefile, you should execute the following commands to copy this directory -+# into a clang checkout: -+# -+# cp -R <this directory> third_party/llvm/tools/clang/tools/chrome-plugin -+# cd third_party/llvm/tools/clang/tools/chrome-plugin -+# make ++++ b/tools/grit/grit/gather/txt.py +@@ -0,0 +1,38 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+CLANG_LEVEL := ../.. -+LIBRARYNAME = FindBadConstructs ++'''Supports making amessage from a text file. ++''' + -+LINK_LIBS_IN_SHARED = 0 -+SHARED_LIBRARY = 1 ++from __future__ import print_function + -+include $(CLANG_LEVEL)/Makefile ++from grit.gather import interface ++from grit import tclib + -+ifeq ($(OS),Darwin) -+ LDFLAGS=-Wl,-undefined,dynamic_lookup -+endif -diff --git a/tools/clang/plugins/OWNERS b/tools/clang/plugins/OWNERS ++ ++class TxtFile(interface.GathererBase): ++ '''A text file gatherer. Very simple, all text from the file becomes a ++ single clique. ++ ''' ++ ++ def Parse(self): ++ self.text_ = self._LoadInputFile() ++ self.clique_ = self.uberclique.MakeClique(tclib.Message(text=self.text_)) ++ ++ def GetText(self): ++ '''Returns the text of what is being gathered.''' ++ return self.text_ ++ ++ def GetTextualIds(self): ++ return [self.extkey] ++ ++ def GetCliques(self): ++ '''Returns the MessageClique objects for all translateable portions.''' ++ return [self.clique_] ++ ++ def Translate(self, lang, pseudo_if_not_available=True, ++ skeleton_gatherer=None, fallback_to_english=False): ++ return self.clique_.MessageForLanguage(lang, ++ pseudo_if_not_available, ++ fallback_to_english).GetRealContent() +diff --git a/tools/grit/grit/gather/txt_unittest.py b/tools/grit/grit/gather/txt_unittest.py new file mode 100644 -index 0000000000..4733a4f06b +index 0000000000..abb9ed98d7 --- /dev/null -+++ b/tools/clang/plugins/OWNERS -@@ -0,0 +1 @@ -+erg@chromium.org -diff --git a/tools/clang/plugins/README.chromium b/tools/clang/plugins/README.chromium ++++ b/tools/grit/grit/gather/txt_unittest.py +@@ -0,0 +1,35 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for TxtFile gatherer''' ++ ++from __future__ import print_function ++ ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++ ++import unittest ++ ++from six import StringIO ++ ++from grit.gather import txt ++ ++ ++class TxtUnittest(unittest.TestCase): ++ def testGather(self): ++ input = StringIO('Hello there\nHow are you?') ++ gatherer = txt.TxtFile(input) ++ gatherer.Parse() ++ self.failUnless(gatherer.GetText() == input.getvalue()) ++ self.failUnless(len(gatherer.GetCliques()) == 1) ++ self.failUnless(gatherer.GetCliques()[0].GetMessage().GetRealContent() == ++ input.getvalue()) ++ ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/grd_reader.py b/tools/grit/grit/grd_reader.py new file mode 100644 -index 0000000000..a2ce0ff557 +index 0000000000..b7bb782977 --- /dev/null -+++ b/tools/clang/plugins/README.chromium -@@ -0,0 +1,4 @@ -+Documentation for this code is: ++++ b/tools/grit/grit/grd_reader.py +@@ -0,0 +1,238 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Class for reading GRD files into memory, without processing them. ++''' ++ ++from __future__ import print_function ++ ++import os.path ++import sys ++import xml.sax ++import xml.sax.handler ++ ++import six ++ ++from grit import exception ++from grit import util ++from grit.node import mapping ++from grit.node import misc ++ ++ ++class StopParsingException(Exception): ++ '''An exception used to stop parsing.''' ++ pass ++ ++ ++class GrdContentHandler(xml.sax.handler.ContentHandler): ++ def __init__(self, stop_after, debug, dir, defines, tags_to_ignore, ++ target_platform, source): ++ # Invariant of data: ++ # 'root' is the root of the parse tree being created, or None if we haven't ++ # parsed out any elements. ++ # 'stack' is the a stack of elements that we push new nodes onto and ++ # pop from when they finish parsing, or [] if we are not currently parsing. ++ # 'stack[-1]' is the top of the stack. ++ self.root = None ++ self.stack = [] ++ self.stop_after = stop_after ++ self.debug = debug ++ self.dir = dir ++ self.defines = defines ++ self.tags_to_ignore = tags_to_ignore or set() ++ self.ignore_depth = 0 ++ self.target_platform = target_platform ++ self.source = source ++ ++ def startElement(self, name, attrs): ++ if self.ignore_depth or name in self.tags_to_ignore: ++ if self.debug and self.ignore_depth == 0: ++ print("Ignoring element %s and its children" % name) ++ self.ignore_depth += 1 ++ return ++ ++ if self.debug: ++ attr_list = ' '.join('%s="%s"' % kv for kv in attrs.items()) ++ print("Starting parsing of element %s with attributes %r" % ++ (name, attr_list or '(none)')) ++ ++ typeattr = attrs.get('type') ++ node = mapping.ElementToClass(name, typeattr)() ++ node.source = self.source ++ ++ if self.stack: ++ self.stack[-1].AddChild(node) ++ node.StartParsing(name, self.stack[-1]) ++ else: ++ assert self.root is None ++ self.root = node ++ if isinstance(self.root, misc.GritNode): ++ if self.target_platform: ++ self.root.SetTargetPlatform(self.target_platform) ++ node.StartParsing(name, None) ++ if self.defines: ++ node.SetDefines(self.defines) ++ self.stack.append(node) ++ ++ for attr, attrval in attrs.items(): ++ node.HandleAttribute(attr, attrval) ++ ++ def endElement(self, name): ++ if self.ignore_depth: ++ self.ignore_depth -= 1 ++ return ++ ++ if name == 'part': ++ partnode = self.stack[-1] ++ partnode.started_inclusion = True ++ # Add the contents of the sub-grd file as children of the <part> node. ++ partname = os.path.join(self.dir, partnode.GetInputPath()) ++ # Check the GRDP file exists. ++ if not os.path.exists(partname): ++ raise exception.FileNotFound(partname) ++ # Exceptions propagate to the handler in grd_reader.Parse(). ++ oldsource = self.source ++ try: ++ self.source = partname ++ xml.sax.parse(partname, GrdPartContentHandler(self)) ++ finally: ++ self.source = oldsource ++ ++ if self.debug: ++ print("End parsing of element %s" % name) ++ self.stack.pop().EndParsing() ++ ++ if name == self.stop_after: ++ raise StopParsingException() ++ ++ def characters(self, content): ++ if self.ignore_depth == 0: ++ if self.stack[-1]: ++ self.stack[-1].AppendContent(content) ++ ++ def ignorableWhitespace(self, whitespace): ++ # TODO(joi): This is not supported by expat. Should use a different XML ++ # parser? ++ pass ++ ++ ++class GrdPartContentHandler(xml.sax.handler.ContentHandler): ++ def __init__(self, parent): ++ self.parent = parent ++ self.depth = 0 ++ ++ def startElement(self, name, attrs): ++ if self.depth: ++ self.parent.startElement(name, attrs) ++ else: ++ if name != 'grit-part': ++ raise exception.MissingElement("root tag must be <grit-part>") ++ if attrs: ++ raise exception.UnexpectedAttribute( ++ "<grit-part> tag must not have attributes") ++ self.depth += 1 ++ ++ def endElement(self, name): ++ self.depth -= 1 ++ if self.depth: ++ self.parent.endElement(name) ++ ++ def characters(self, content): ++ self.parent.characters(content) ++ ++ def ignorableWhitespace(self, whitespace): ++ self.parent.ignorableWhitespace(whitespace) ++ ++ ++def Parse(filename_or_stream, dir=None, stop_after=None, first_ids_file=None, ++ debug=False, defines=None, tags_to_ignore=None, target_platform=None, ++ predetermined_ids_file=None): ++ '''Parses a GRD file into a tree of nodes (from grit.node). ++ ++ If filename_or_stream is a stream, 'dir' should point to the directory ++ notionally containing the stream (this feature is only used in unit tests). ++ ++ If 'stop_after' is provided, the parsing will stop once the first node ++ with this name has been fully parsed (including all its contents). ++ ++ If 'debug' is true, lots of information about the parsing events will be ++ printed out during parsing of the file. ++ ++ If 'first_ids_file' is non-empty, it is used to override the setting for the ++ first_ids_file attribute of the <grit> root node. Note that the first_ids_file ++ parameter should be relative to the cwd, even though the first_ids_file ++ attribute of the <grit> node is relative to the grd file. ++ ++ If 'target_platform' is set, this is used to determine the target ++ platform of builds, instead of using |sys.platform|. ++ ++ Args: ++ filename_or_stream: './bla.xml' ++ dir: None (if filename_or_stream is a filename) or '.' ++ stop_after: 'inputs' ++ first_ids_file: 'GRIT_DIR/../gritsettings/resource_ids' ++ debug: False ++ defines: dictionary of defines, like {'chromeos': '1'} ++ target_platform: None or the value that would be returned by sys.platform ++ on your target platform. ++ predetermined_ids_file: File path to a file containing a pre-determined ++ mapping from resource names to resource ids which will be used to assign ++ resource ids to those resources. ++ ++ Return: ++ Subclass of grit.node.base.Node ++ ++ Throws: ++ grit.exception.Parsing ++ ''' ++ ++ if isinstance(filename_or_stream, six.string_types): ++ source = filename_or_stream ++ if dir is None: ++ dir = util.dirname(filename_or_stream) ++ else: ++ source = None ++ ++ handler = GrdContentHandler(stop_after=stop_after, debug=debug, dir=dir, ++ defines=defines, tags_to_ignore=tags_to_ignore, ++ target_platform=target_platform, source=source) ++ try: ++ xml.sax.parse(filename_or_stream, handler) ++ except StopParsingException: ++ assert stop_after ++ pass ++ except: ++ if not debug: ++ print("parse exception: run GRIT with the -x flag to debug .grd problems") ++ raise ++ ++ if handler.root.name != 'grit': ++ raise exception.MissingElement("root tag must be <grit>") ++ ++ if hasattr(handler.root, 'SetOwnDir'): ++ # Fix up the base_dir so it is relative to the input file. ++ assert dir is not None ++ handler.root.SetOwnDir(dir) ++ ++ if isinstance(handler.root, misc.GritNode): ++ handler.root.SetPredeterminedIdsFile(predetermined_ids_file) ++ if first_ids_file: ++ # Make the path to the first_ids_file relative to the grd file, ++ # unless it begins with GRIT_DIR. ++ GRIT_DIR_PREFIX = 'GRIT_DIR' ++ if not (first_ids_file.startswith(GRIT_DIR_PREFIX) ++ and first_ids_file[len(GRIT_DIR_PREFIX)] in ['/', '\\']): ++ rel_dir = os.path.relpath(os.getcwd(), dir) ++ first_ids_file = util.normpath(os.path.join(rel_dir, first_ids_file)) ++ handler.root.attrs['first_ids_file'] = first_ids_file ++ # Assign first ids to the nodes that don't have them. ++ handler.root.AssignFirstIds(filename_or_stream, defines) ++ ++ return handler.root + -+- http://code.google.com/p/chromium/wiki/Clang -+- http://code.google.com/p/chromium/wiki/WritingClangPlugins -diff --git a/tools/clang/plugins/tests/base_refcounted.cpp b/tools/clang/plugins/tests/base_refcounted.cpp ++ ++if __name__ == '__main__': ++ util.ChangeStdoutEncoding() ++ print(six.text_type(Parse(sys.argv[1]))) +diff --git a/tools/grit/grit/grd_reader_unittest.py b/tools/grit/grit/grd_reader_unittest.py new file mode 100644 -index 0000000000..364a3e888c +index 0000000000..920a92f9c0 --- /dev/null -+++ b/tools/clang/plugins/tests/base_refcounted.cpp -@@ -0,0 +1,72 @@ -+// Copyright (c) 2012 The Chromium Authors. All rights reserved. -+// Use of this source code is governed by a BSD-style license that can be -+// found in the LICENSE file. ++++ b/tools/grit/grit/grd_reader_unittest.py +@@ -0,0 +1,346 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+#include "base_refcounted.h" ++'''Unit tests for grd_reader package''' + -+#include <cstddef> ++from __future__ import print_function + -+namespace { ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '..')) ++ ++import unittest ++ ++import six ++from six import StringIO ++ ++from grit import exception ++from grit import grd_reader ++from grit import util ++from grit.node import empty ++from grit.node import message ++ ++ ++class GrdReaderUnittest(unittest.TestCase): ++ def testParsingAndXmlOutput(self): ++ input = u'''<?xml version="1.0" encoding="UTF-8"?> ++<grit base_dir="." current_release="3" latest_public_release="2" source_lang_id="en-US"> ++ <release seq="3"> ++ <includes> ++ <include file="images/logo.gif" name="ID_LOGO" type="gif" /> ++ </includes> ++ <messages> ++ <if expr="True"> ++ <message desc="Printed to greet the currently logged in user" name="IDS_GREETING"> ++ Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today? ++ </message> ++ </if> ++ </messages> ++ <structures> ++ <structure file="rc_files/dialogs.rc" name="IDD_NARROW_DIALOG" type="dialog"> ++ <skeleton expr="lang == 'fr-FR'" file="bla.rc" variant_of_revision="3" /> ++ </structure> ++ <structure file="rc_files/version.rc" name="VS_VERSION_INFO" type="version" /> ++ </structures> ++ </release> ++ <translations> ++ <file lang="nl" path="nl_translations.xtb" /> ++ </translations> ++ <outputs> ++ <output filename="resource.h" type="rc_header" /> ++ <output filename="resource.rc" lang="en-US" type="rc_all" /> ++ </outputs> ++</grit>''' ++ pseudo_file = StringIO(input) ++ tree = grd_reader.Parse(pseudo_file, '.') ++ output = six.text_type(tree) ++ expected_output = input.replace(u' base_dir="."', u'') ++ self.assertEqual(expected_output, output) ++ self.failUnless(tree.GetNodeById('IDS_GREETING')) ++ ++ ++ def testStopAfter(self): ++ input = u'''<?xml version="1.0" encoding="UTF-8"?> ++<grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <outputs> ++ <output filename="resource.h" type="rc_header" /> ++ <output filename="resource.rc" lang="en-US" type="rc_all" /> ++ </outputs> ++ <release seq="3"> ++ <includes> ++ <include type="gif" name="ID_LOGO" file="images/logo.gif"/> ++ </includes> ++ </release> ++</grit>''' ++ pseudo_file = StringIO(input) ++ tree = grd_reader.Parse(pseudo_file, '.', stop_after='outputs') ++ # only an <outputs> child ++ self.failUnless(len(tree.children) == 1) ++ self.failUnless(tree.children[0].name == 'outputs') ++ ++ def testLongLinesWithComments(self): ++ input = u'''<?xml version="1.0" encoding="UTF-8"?> ++<grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <release seq="3"> ++ <messages> ++ <message name="IDS_GREETING" desc="Printed to greet the currently logged in user"> ++ This is a very long line with no linebreaks yes yes it stretches on <!-- ++ -->and on <!-- ++ -->and on! ++ </message> ++ </messages> ++ </release> ++</grit>''' ++ pseudo_file = StringIO(input) ++ tree = grd_reader.Parse(pseudo_file, '.') ++ ++ greeting = tree.GetNodeById('IDS_GREETING') ++ self.failUnless(greeting.GetCliques()[0].GetMessage().GetRealContent() == ++ 'This is a very long line with no linebreaks yes yes it ' ++ 'stretches on and on and on!') ++ ++ def doTestAssignFirstIds(self, first_ids_path): ++ input = u'''<?xml version="1.0" encoding="UTF-8"?> ++<grit latest_public_release="2" source_lang_id="en-US" current_release="3" ++ base_dir="." first_ids_file="%s"> ++ <release seq="3"> ++ <messages> ++ <message name="IDS_TEST" desc="test"> ++ test ++ </message> ++ </messages> ++ </release> ++</grit>''' % first_ids_path ++ pseudo_file = StringIO(input) ++ grit_root_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), ++ '..') ++ fake_input_path = os.path.join( ++ grit_root_dir, "grit/testdata/chrome/app/generated_resources.grd") ++ root = grd_reader.Parse(pseudo_file, os.path.split(fake_input_path)[0]) ++ root.AssignFirstIds(fake_input_path, {}) ++ messages_node = root.children[0].children[0] ++ self.failUnless(isinstance(messages_node, empty.MessagesNode)) ++ self.failUnless(messages_node.attrs["first_id"] != ++ empty.MessagesNode().DefaultAttributes()["first_id"]) ++ ++ def testAssignFirstIds(self): ++ self.doTestAssignFirstIds("../../tools/grit/resource_ids") ++ ++ def testAssignFirstIdsUseGritDir(self): ++ self.doTestAssignFirstIds("GRIT_DIR/grit/testdata/tools/grit/resource_ids") ++ ++ def testAssignFirstIdsMultipleMessages(self): ++ """If there are multiple messages sections, the resource_ids file ++ needs to list multiple first_id values.""" ++ input = u'''<?xml version="1.0" encoding="UTF-8"?> ++<grit latest_public_release="2" source_lang_id="en-US" current_release="3" ++ base_dir="." first_ids_file="resource_ids"> ++ <release seq="3"> ++ <messages> ++ <message name="IDS_TEST" desc="test"> ++ test ++ </message> ++ </messages> ++ <messages> ++ <message name="IDS_TEST2" desc="test"> ++ test2 ++ </message> ++ </messages> ++ </release> ++</grit>''' ++ pseudo_file = StringIO(input) ++ grit_root_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), ++ '..') ++ fake_input_path = os.path.join(grit_root_dir, "grit/testdata/test.grd") ++ ++ root = grd_reader.Parse(pseudo_file, os.path.split(fake_input_path)[0]) ++ root.AssignFirstIds(fake_input_path, {}) ++ messages_node = root.children[0].children[0] ++ self.assertTrue(isinstance(messages_node, empty.MessagesNode)) ++ self.assertEqual('100', messages_node.attrs["first_id"]) ++ messages_node = root.children[0].children[1] ++ self.assertTrue(isinstance(messages_node, empty.MessagesNode)) ++ self.assertEqual('10000', messages_node.attrs["first_id"]) ++ ++ def testUseNameForIdAndPpIfdef(self): ++ input = u'''<?xml version="1.0" encoding="UTF-8"?> ++<grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <release seq="3"> ++ <messages> ++ <if expr="pp_ifdef('hello')"> ++ <message name="IDS_HELLO" use_name_for_id="true"> ++ Hello! ++ </message> ++ </if> ++ </messages> ++ </release> ++</grit>''' ++ pseudo_file = StringIO(input) ++ root = grd_reader.Parse(pseudo_file, '.', defines={'hello': '1'}) ++ ++ # Check if the ID is set to the name. In the past, there was a bug ++ # that caused the ID to be a generated number. ++ hello = root.GetNodeById('IDS_HELLO') ++ self.failUnless(hello.GetCliques()[0].GetId() == 'IDS_HELLO') ++ ++ def testUseNameForIdWithIfElse(self): ++ input = u'''<?xml version="1.0" encoding="UTF-8"?> ++<grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <release seq="3"> ++ <messages> ++ <if expr="pp_ifdef('hello')"> ++ <then> ++ <message name="IDS_HELLO" use_name_for_id="true"> ++ Hello! ++ </message> ++ </then> ++ <else> ++ <message name="IDS_HELLO" use_name_for_id="true"> ++ Yellow! ++ </message> ++ </else> ++ </if> ++ </messages> ++ </release> ++</grit>''' ++ pseudo_file = StringIO(input) ++ root = grd_reader.Parse(pseudo_file, '.', defines={'hello': '1'}) ++ ++ # Check if the ID is set to the name. In the past, there was a bug ++ # that caused the ID to be a generated number. ++ hello = root.GetNodeById('IDS_HELLO') ++ self.failUnless(hello.GetCliques()[0].GetId() == 'IDS_HELLO') ++ ++ def testPartInclusionAndCorrectSource(self): ++ arbitrary_path_grd = u'''\ ++ <grit-part> ++ <message name="IDS_TEST5" desc="test5">test5</message> ++ </grit-part>''' ++ tmp_dir = util.TempDir({'arbitrary_path.grp': arbitrary_path_grd}) ++ arbitrary_path_grd_file = tmp_dir.GetPath('arbitrary_path.grp') ++ top_grd = u'''\ ++ <grit latest_public_release="2" current_release="3"> ++ <release seq="3"> ++ <messages> ++ <message name="IDS_TEST" desc="test"> ++ test ++ </message> ++ <part file="sub.grp" /> ++ <part file="%s" /> ++ </messages> ++ </release> ++ </grit>''' % arbitrary_path_grd_file ++ sub_grd = u'''\ ++ <grit-part> ++ <message name="IDS_TEST2" desc="test2">test2</message> ++ <part file="subsub.grp" /> ++ <message name="IDS_TEST3" desc="test3">test3</message> ++ </grit-part>''' ++ subsub_grd = u'''\ ++ <grit-part> ++ <message name="IDS_TEST4" desc="test4">test4</message> ++ </grit-part>''' ++ expected_output = u'''\ ++ <grit current_release="3" latest_public_release="2"> ++ <release seq="3"> ++ <messages> ++ <message desc="test" name="IDS_TEST"> ++ test ++ </message> ++ <part file="sub.grp"> ++ <message desc="test2" name="IDS_TEST2"> ++ test2 ++ </message> ++ <part file="subsub.grp"> ++ <message desc="test4" name="IDS_TEST4"> ++ test4 ++ </message> ++ </part> ++ <message desc="test3" name="IDS_TEST3"> ++ test3 ++ </message> ++ </part> ++ <part file="%s"> ++ <message desc="test5" name="IDS_TEST5"> ++ test5 ++ </message> ++ </part> ++ </messages> ++ </release> ++ </grit>''' % arbitrary_path_grd_file ++ ++ with util.TempDir({'sub.grp': sub_grd, ++ 'subsub.grp': subsub_grd}) as tmp_sub_dir: ++ output = grd_reader.Parse(StringIO(top_grd), ++ tmp_sub_dir.GetPath()) ++ correct_sources = { ++ 'IDS_TEST': None, ++ 'IDS_TEST2': tmp_sub_dir.GetPath('sub.grp'), ++ 'IDS_TEST3': tmp_sub_dir.GetPath('sub.grp'), ++ 'IDS_TEST4': tmp_sub_dir.GetPath('subsub.grp'), ++ 'IDS_TEST5': arbitrary_path_grd_file, ++ } + -+// Unsafe; should error. -+class AnonymousDerivedProtectedToPublicInImpl -+ : public ProtectedRefCountedDtorInHeader { -+ public: -+ AnonymousDerivedProtectedToPublicInImpl() {} -+ ~AnonymousDerivedProtectedToPublicInImpl() {} -+}; ++ for node in output.ActiveDescendants(): ++ with node: ++ if isinstance(node, message.MessageNode): ++ self.assertEqual(correct_sources[node.attrs.get('name')], node.source) ++ self.assertEqual(expected_output.split(), output.FormatXml().split()) ++ tmp_dir.CleanUp() ++ ++ def testPartInclusionFailure(self): ++ template = u''' ++ <grit latest_public_release="2" current_release="3"> ++ <outputs> ++ %s ++ </outputs> ++ </grit>''' ++ ++ part_failures = [ ++ (exception.UnexpectedContent, u'<part file="x">fnord</part>'), ++ (exception.UnexpectedChild, ++ u'<part file="x"><output filename="x" type="y" /></part>'), ++ (exception.FileNotFound, u'<part file="yet_created_x" />'), ++ ] ++ for raises, data in part_failures: ++ data = StringIO(template % data) ++ self.assertRaises(raises, grd_reader.Parse, data, '.') ++ ++ gritpart_failures = [ ++ (exception.UnexpectedAttribute, u'<grit-part file="xyz"></grit-part>'), ++ (exception.MissingElement, u'<output filename="x" type="y" />'), ++ ] ++ for raises, data in gritpart_failures: ++ top_grd = StringIO(template % u'<part file="bad.grp" />') ++ with util.TempDir({'bad.grp': data}) as temp_dir: ++ self.assertRaises(raises, grd_reader.Parse, top_grd, temp_dir.GetPath()) ++ ++ def testEarlyEnoughPlatformSpecification(self): ++ # This is a regression test for issue ++ # https://code.google.com/p/grit-i18n/issues/detail?id=23 ++ grd_text = u'''<?xml version="1.0" encoding="UTF-8"?> ++ <grit latest_public_release="1" current_release="1"> ++ <release seq="1"> ++ <messages> ++ <if expr="not pp_ifdef('use_titlecase')"> ++ <message name="IDS_XYZ">foo</message> ++ </if> ++ <!-- The assumption is that use_titlecase is never true for ++ this platform. When the platform isn't set to 'android' ++ early enough, we get a duplicate message name. --> ++ <if expr="os == '%s'"> ++ <message name="IDS_XYZ">boo</message> ++ </if> ++ </messages> ++ </release> ++ </grit>''' % sys.platform ++ with util.TempDir({}) as temp_dir: ++ grd_reader.Parse(StringIO(grd_text), temp_dir.GetPath(), ++ target_platform='android') + -+} // namespace + -+// Unsafe; should error. -+class PublicRefCountedDtorInImpl -+ : public base::RefCounted<PublicRefCountedDtorInImpl> { -+ public: -+ PublicRefCountedDtorInImpl() {} -+ ~PublicRefCountedDtorInImpl() {} ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/grit-todo.xml b/tools/grit/grit/grit-todo.xml +new file mode 100644 +index 0000000000..b8c20fdfad +--- /dev/null ++++ b/tools/grit/grit/grit-todo.xml +@@ -0,0 +1,62 @@ ++<?xml version="1.0" encoding="windows-1252"?> ++<TODOLIST FILEFORMAT="6" PROJECTNAME="GRIT" NEXTUNIQUEID="56" FILEVERSION="69" LASTMODIFIED="2005-08-19"> ++ <TASK STARTDATESTRING="2005-04-08" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38453.49975694" TITLE="check 'name' attribute is unique" TIMEESTUNITS="H" ID="2" PERCENTDONE="100" STARTDATE="38450.00000000" DONEDATESTRING="2005-04-11" POS="22" DONEDATE="38453.00000000"/> ++ <TASK STARTDATESTRING="2005-04-08" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38488.48189815" TITLE="import id-calculating code" TIMEESTUNITS="H" ID="3" PERCENTDONE="100" STARTDATE="38450.00000000" DONEDATESTRING="2005-05-16" POS="13" DONEDATE="38488.00000000"/> ++ <TASK STARTDATESTRING="2005-05-16" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38488.48209491" TITLE="Import tool for existing translations" TIMEESTUNITS="H" ID="6" PERCENTDONE="100" STARTDATE="38488.00000000" DONEDATESTRING="2005-06-16" POS="12" DONEDATE="38519.00000000"/> ++ <TASK STARTDATESTRING="2005-05-16" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38511.00805556" TITLE="Export XMBs" TIMEESTUNITS="H" ID="8" PERCENTDONE="100" STARTDATE="38488.00000000" DONEDATESTRING="2005-06-08" POS="20" DONEDATE="38511.00000000"/> ++ <TASK STARTDATESTRING="2005-05-16" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38511.00924769" TITLE="Initial Integration" TIMEESTUNITS="H" ID="10" PERCENTDONE="100" STARTDATE="38488.00000000" DONEDATESTRING="2005-06-08" POS="10" DONEDATE="38511.00000000"> ++ <TASK STARTDATESTRING="2005-05-16" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38496.54048611" TITLE="parser for %s strings" TIMEESTUNITS="H" ID="4" PERCENTDONE="100" STARTDATE="38488.00000000" DONEDATESTRING="2005-05-24" POS="2" DONEDATE="38496.00000000"/> ++ <TASK STARTDATESTRING="2005-05-16" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38497.00261574" TITLE="import tool for existing RC files" TIMEESTUNITS="H" ID="5" PERCENTDONE="100" STARTDATE="38488.00000000" DONEDATESTRING="2005-05-25" POS="4" DONEDATE="38497.00000000"> ++ <TASK STARTDATESTRING="2005-05-24" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38496.92990741" TITLE="handle button value= and img alt= in message HTML text" TIMEESTUNITS="H" ID="22" PERCENTDONE="100" STARTDATE="38496.00000000" DONEDATESTRING="2005-05-24" POS="1" DONEDATE="38496.00000000"/> ++ <TASK STARTDATESTRING="2005-05-24" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38497.00258102" TITLE="&nbsp; bug" TIMEESTUNITS="H" ID="23" PERCENTDONE="100" STARTDATE="38496.00000000" DONEDATESTRING="2005-05-25" POS="2" DONEDATE="38497.00000000"/> ++ </TASK> ++ <TASK STARTDATESTRING="2005-05-16" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38490.61171296" TITLE="grit build" TIMEESTUNITS="H" ID="7" PERCENTDONE="100" STARTDATE="38488.00000000" DONEDATESTRING="2005-05-18" POS="6" DONEDATE="38490.00000000"> ++ <TASK STARTDATESTRING="2005-05-16" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38490.61168981" TITLE="use IDs gathered from gatherers for .h file" TIMEESTUNITS="H" ID="20" PERCENTDONE="100" STARTDATE="38488.00000000" DONEDATESTRING="2005-05-18" POS="1" DONEDATE="38490.00000000"/> ++ </TASK> ++ <TASK STARTDATESTRING="2005-05-16" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38504.55199074" TITLE="SCons Integration" TIMEESTUNITS="H" ID="9" PERCENTDONE="100" STARTDATE="38488.00000000" DONEDATESTRING="2005-06-01" POS="1" DONEDATE="38504.00000000"/> ++ <TASK STARTDATESTRING="2005-05-16" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38490.61181713" TITLE="handle includes" TIMEESTUNITS="H" ID="12" PERCENTDONE="100" STARTDATE="38488.00000000" DONEDATESTRING="2005-05-18" POS="5" DONEDATE="38490.00000000"/> ++ <TASK STARTDATESTRING="2005-05-24" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38507.98567130" TITLE="output translated HTML templates" TIMEESTUNITS="H" ID="25" PERCENTDONE="100" STARTDATE="38496.00000000" DONEDATESTRING="2005-06-04" POS="3" DONEDATE="38507.00000000"/> ++ <TASK STARTDATESTRING="2005-05-31" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38507.99394676" TITLE="bug: re-escape too much in RC dialogs etc." TIMEESTUNITS="H" ID="38" PERCENTDONE="100" STARTDATE="38503.00000000" DONEDATESTRING="2005-06-04" POS="7" DONEDATE="38507.00000000"/> ++ </TASK> ++ <TASK STARTDATESTRING="2005-05-16" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38489.46444444" TITLE="handle structure variants" TIMEESTUNITS="H" ID="11" PERCENTDONE="100" STARTDATE="38488.00000000" DONEDATESTRING="2005-06-16" POS="15" DONEDATE="38519.00000000"/> ++ <TASK STARTDATESTRING="2005-05-16" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38489.46456019" TITLE="handle include variants" TIMEESTUNITS="H" ID="13" PERCENTDONE="100" STARTDATE="38488.00000000" DONEDATESTRING="2005-06-16" POS="17" DONEDATE="38519.00000000"/> ++ <TASK STARTDATESTRING="2005-05-16" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38489.46537037" TITLE="handle translateable text for includes (e.g. image text)" TIMEESTUNITS="H" ID="14" PERCENTDONE="100" STARTDATE="38488.00000000" DONEDATESTRING="2005-06-16" POS="14" DONEDATE="38519.00000000"/> ++ <TASK STARTDATESTRING="2005-05-16" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38489.46712963" TITLE="ddoc" TIMEESTUNITS="H" ID="15" STARTDATE="38488.00000000" POS="4"> ++ <TASK STARTDATESTRING="2005-05-16" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38489.46718750" TITLE="review comments miket" TIMEESTUNITS="H" ID="16" STARTDATE="38488.00000000" POS="2"/> ++ <TASK STARTDATESTRING="2005-05-16" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38489.46722222" TITLE="review comments pdoyle" TIMEESTUNITS="H" ID="17" STARTDATE="38488.00000000" POS="1"/> ++ <TASK STARTDATESTRING="2005-05-16" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38489.46732639" TITLE="remove 'extkey' from structure" TIMEESTUNITS="H" ID="18" STARTDATE="38488.00000000" POS="3"/> ++ <TASK STARTDATESTRING="2005-05-16" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38489.53537037" TITLE="add 'encoding' to structure" TIMEESTUNITS="H" ID="19" STARTDATE="38488.00000000" POS="6"/> ++ <TASK STARTDATESTRING="2005-05-31" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38503.55304398" TITLE="document limitation: emitter doesn't emit the translated HTML templates" TIMEESTUNITS="H" ID="30" STARTDATE="38503.00000000" POS="4"/> ++ <TASK STARTDATESTRING="2005-05-31" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38504.58541667" TITLE="add 'internal_comment' to <message>" TIMEESTUNITS="H" ID="32" STARTDATE="38503.00000000" POS="5"/> ++ <TASK STARTDATESTRING="2005-05-31" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38505.73391204" TITLE="<outputs> can not have paths (because of SCons integration - goes to build dir)" TIMEESTUNITS="H" ID="36" STARTDATE="38503.00000000" POS="9"/> ++ <TASK STARTDATESTRING="2005-05-31" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38506.64265046" TITLE="<identifers> and <identifier> nodes" TIMEESTUNITS="H" ID="37" STARTDATE="38503.00000000" POS="10"/> ++ <TASK STARTDATESTRING="2005-06-23" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38526.62344907" TITLE="<structure> can have 'exclude_from_rc' attribute (default false)" TIMEESTUNITS="H" ID="47" STARTDATE="38526.00000000" POS="8"/> ++ <TASK STARTDATESTRING="2005-06-23" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38531.94135417" TITLE="add 'enc_check' to <grit>" TIMEESTUNITS="H" ID="48" STARTDATE="38526.00000000" POS="7"/> ++ </TASK> ++ <TASK STARTDATESTRING="2005-05-18" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38492.51549769" TITLE="handle nontranslateable messages (in MessageClique?)" TIMEESTUNITS="H" ID="21" PERCENTDONE="100" STARTDATE="38490.00000000" DONEDATESTRING="2005-06-16" POS="16" DONEDATE="38519.00000000"/> ++ <TASK STARTDATESTRING="2005-05-24" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38505.70454861" TITLE="ask cprince about SCons builder in new mk system" TIMEESTUNITS="H" ID="24" PERCENTDONE="100" STARTDATE="38496.00000000" DONEDATESTRING="2005-06-02" POS="25" DONEDATE="38505.00000000"/> ++ <TASK STARTDATESTRING="2005-05-24" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38504.57436343" TITLE="fix AOL resource in trunk ("???????")" TIMEESTUNITS="H" ID="26" PERCENTDONE="100" STARTDATE="38496.00000000" DONEDATESTRING="2005-06-01" POS="19" DONEDATE="38504.00000000"/> ++ <TASK STARTDATESTRING="2005-05-24" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38498.53893519" TITLE="rc_all vs. rc_translateable vs. rc_nontranslateable" TIMEESTUNITS="H" ID="27" PERCENTDONE="100" STARTDATE="38496.00000000" DONEDATESTRING="2005-06-16" POS="6" DONEDATE="38519.00000000"/> ++ <TASK STARTDATESTRING="2005-05-31" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38509.45532407" TITLE="make separate .grb "outputs" file (and change SCons integ) (??)" TIMEESTUNITS="H" ID="28" PERCENTDONE="100" STARTDATE="38503.00000000" DONEDATESTRING="2005-06-06" POS="8" DONEDATE="38509.00000000"/> ++ <TASK STARTDATESTRING="2005-05-31" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38511.00939815" TITLE="fix unit tests so they run from any directory" TIMEESTUNITS="H" ID="33" PERCENTDONE="100" STARTDATE="38503.00000000" DONEDATESTRING="2005-06-08" POS="18" DONEDATE="38511.00000000"/> ++ <TASK STARTDATESTRING="2005-05-31" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38508.96640046" TITLE="Change R4 tool to CC correct team(s) on GRIT changes" TIMEESTUNITS="H" ID="39" PERCENTDONE="100" STARTDATE="38503.00000000" DONEDATESTRING="2005-06-05" POS="23" DONEDATE="38508.00000000"/> ++ <TASK STARTDATESTRING="2005-06-07" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38511.00881944" TITLE="Document why wrapper.rc" TIMEESTUNITS="H" ID="40" PERCENTDONE="100" STARTDATE="38510.00000000" DONEDATESTRING="2005-06-08" POS="21" DONEDATE="38511.00000000"/> ++ <TASK STARTDATESTRING="2005-06-08" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38511.00804398" TITLE="import XTBs" TIMEESTUNITS="H" ID="41" PERCENTDONE="100" STARTDATE="38511.00000000" DONEDATESTRING="2005-06-16" POS="11" DONEDATE="38519.00000000"/> ++ <TASK STARTDATESTRING="2005-06-08" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38511.00875000" TITLE="Nightly build integration" TIMEESTUNITS="H" ID="42" STARTDATE="38511.00000000" POS="3"/> ++ <TASK STARTDATESTRING="2005-06-08" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38511.00891204" TITLE="BUGS" TIMEESTUNITS="H" ID="43" STARTDATE="38511.00000000" POS="24"> ++ <TASK STARTDATESTRING="2005-06-08" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38513.03375000" TITLE="Should report error if RC-section structure refers to does not exist" TIMEESTUNITS="H" ID="44" PERCENTDONE="100" STARTDATE="38511.00000000" DONEDATESTRING="2005-06-10" POS="1" DONEDATE="38513.00000000"/> ++ </TASK> ++ <TASK STARTDATESTRING="2005-06-08" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38511.00981481" TITLE="NEW FEATURES" TIMEESTUNITS="H" ID="45" PERCENTDONE="100" STARTDATE="38511.00000000" DONEDATESTRING="2005-06-16" POS="7" DONEDATE="38519.00000000"> ++ <TASK STARTDATESTRING="2005-05-31" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38505.70077546" TITLE="Implement line-continuation feature (\ at end of line?)" TIMEESTUNITS="H" ID="34" PERCENTDONE="100" STARTDATE="38503.00000000" DONEDATESTRING="2005-06-16" POS="1" DONEDATE="38519.00000000"/> ++ <TASK STARTDATESTRING="2005-05-31" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38505.70262731" TITLE="Implement conditional inclusion & reflect the conditionals from R3 RC file" TIMEESTUNITS="H" ID="35" PERCENTDONE="100" STARTDATE="38503.00000000" DONEDATESTRING="2005-06-16" POS="2" DONEDATE="38519.00000000"/> ++ </TASK> ++ <TASK STARTDATESTRING="2005-06-08" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38511.01046296" TITLE="TC integration (one-way TO the TC)" TIMEESTUNITS="H" ID="46" PERCENTDONE="100" STARTDATE="38511.00000000" DONEDATESTRING="2005-06-16" POS="5" DONEDATE="38519.00000000"/> ++ <TASK STARTDATESTRING="2005-06-30" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38533.59072917" TITLE="bazaar20 ad for GRIT help" TIMEESTUNITS="H" ID="49" STARTDATE="38533.00000000" POS="2"> ++ <TASK STARTDATESTRING="2005-08-19" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38583.72346065" TITLE="bazaar20 ideas" TIMEESTUNITS="H" ID="51" STARTDATE="38583.00000000" POS="1"> ++ <TASK STARTDATESTRING="2005-08-19" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38583.72354167" TITLE="GUI for adding/editing messages" TIMEESTUNITS="H" ID="52" STARTDATE="38583.00000000" POS="2"/> ++ <TASK STARTDATESTRING="2005-08-19" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38583.72365741" TITLE="XLIFF import/export" TIMEESTUNITS="H" ID="54" STARTDATE="38583.00000000" POS="1"/> ++ </TASK> ++ </TASK> ++ <TASK STARTDATESTRING="2005-06-30" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38583.73721065" TITLE="internal_comment for all resource nodes (not just <message>)" TIMEESTUNITS="H" ID="50" PERCENTDONE="100" STARTDATE="38533.00000000" DONEDATESTRING="2005-08-19" POS="9" DONEDATE="38583.73721065"/> ++ <TASK STARTDATESTRING="2005-08-19" PRIORITY="5" TIMEESPENTUNITS="H" LASTMOD="38583.73743056" TITLE="Preserve XML comments - this gives us line continuation and more" TIMEESTUNITS="H" ID="55" STARTDATE="38583.72326389" POS="1"/> ++</TODOLIST> +diff --git a/tools/grit/grit/grit_runner.py b/tools/grit/grit/grit_runner.py +new file mode 100644 +index 0000000000..26aa0d58c4 +--- /dev/null ++++ b/tools/grit/grit/grit_runner.py +@@ -0,0 +1,334 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+ private: -+ friend class base::RefCounted<PublicRefCountedDtorInImpl>; -+}; ++"""Command processor for GRIT. This is the script you invoke to run the various ++GRIT tools. ++""" + -+class Foo { -+ public: -+ class BarInterface { -+ protected: -+ virtual ~BarInterface() {} -+ }; ++from __future__ import print_function + -+ typedef base::RefCounted<BarInterface> RefCountedBar; -+ typedef RefCountedBar AnotherTypedef; -+}; ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '..')) ++ ++import getopt ++ ++from grit import util ++ ++import grit.extern.FP ++ ++# Tool info factories; these import only within each factory to avoid ++# importing most of the GRIT code until required. ++def ToolFactoryBuild(): ++ import grit.tool.build ++ return grit.tool.build.RcBuilder() ++ ++def ToolFactoryBuildInfo(): ++ import grit.tool.buildinfo ++ return grit.tool.buildinfo.DetermineBuildInfo() ++ ++def ToolFactoryCount(): ++ import grit.tool.count ++ return grit.tool.count.CountMessage() ++ ++def ToolFactoryDiffStructures(): ++ import grit.tool.diff_structures ++ return grit.tool.diff_structures.DiffStructures() ++ ++def ToolFactoryMenuTranslationsFromParts(): ++ import grit.tool.menu_from_parts ++ return grit.tool.menu_from_parts.MenuTranslationsFromParts() ++ ++def ToolFactoryNewGrd(): ++ import grit.tool.newgrd ++ return grit.tool.newgrd.NewGrd() ++ ++def ToolFactoryResizeDialog(): ++ import grit.tool.resize ++ return grit.tool.resize.ResizeDialog() ++ ++def ToolFactoryRc2Grd(): ++ import grit.tool.rc2grd ++ return grit.tool.rc2grd.Rc2Grd() ++ ++def ToolFactoryTest(): ++ import grit.tool.test ++ return grit.tool.test.TestTool() ++ ++def ToolFactoryTranslationToTc(): ++ import grit.tool.transl2tc ++ return grit.tool.transl2tc.TranslationToTc() ++ ++def ToolFactoryUnit(): ++ import grit.tool.unit ++ return grit.tool.unit.UnitTestTool() ++ ++ ++def ToolFactoryUpdateResourceIds(): ++ import grit.tool.update_resource_ids ++ return grit.tool.update_resource_ids.UpdateResourceIds() ++ ++ ++def ToolFactoryXmb(): ++ import grit.tool.xmb ++ return grit.tool.xmb.OutputXmb() ++ ++def ToolAndroid2Grd(): ++ import grit.tool.android2grd ++ return grit.tool.android2grd.Android2Grd() ++ ++# Keys for the following map ++_FACTORY = 1 ++_REQUIRES_INPUT = 2 ++_HIDDEN = 3 # optional key - presence indicates tool is hidden ++ ++# Maps tool names to the tool's module. Done as a list of (key, value) tuples ++# instead of a map to preserve ordering. ++_TOOLS = [ ++ ['android2grd', { ++ _FACTORY: ToolAndroid2Grd, ++ _REQUIRES_INPUT: False ++ }], ++ ['build', { ++ _FACTORY: ToolFactoryBuild, ++ _REQUIRES_INPUT: True ++ }], ++ ['buildinfo', { ++ _FACTORY: ToolFactoryBuildInfo, ++ _REQUIRES_INPUT: True ++ }], ++ ['count', { ++ _FACTORY: ToolFactoryCount, ++ _REQUIRES_INPUT: True ++ }], ++ [ ++ 'menufromparts', ++ { ++ _FACTORY: ToolFactoryMenuTranslationsFromParts, ++ _REQUIRES_INPUT: True, ++ _HIDDEN: True ++ } ++ ], ++ ['newgrd', { ++ _FACTORY: ToolFactoryNewGrd, ++ _REQUIRES_INPUT: False ++ }], ++ ['rc2grd', { ++ _FACTORY: ToolFactoryRc2Grd, ++ _REQUIRES_INPUT: False ++ }], ++ ['resize', { ++ _FACTORY: ToolFactoryResizeDialog, ++ _REQUIRES_INPUT: True ++ }], ++ ['sdiff', { ++ _FACTORY: ToolFactoryDiffStructures, ++ _REQUIRES_INPUT: False ++ }], ++ ['test', { ++ _FACTORY: ToolFactoryTest, ++ _REQUIRES_INPUT: True, ++ _HIDDEN: True ++ }], ++ [ ++ 'transl2tc', ++ { ++ _FACTORY: ToolFactoryTranslationToTc, ++ _REQUIRES_INPUT: False ++ } ++ ], ++ ['unit', { ++ _FACTORY: ToolFactoryUnit, ++ _REQUIRES_INPUT: False ++ }], ++ [ ++ 'update_resource_ids', ++ { ++ _FACTORY: ToolFactoryUpdateResourceIds, ++ _REQUIRES_INPUT: False ++ } ++ ], ++ ['xmb', { ++ _FACTORY: ToolFactoryXmb, ++ _REQUIRES_INPUT: True ++ }], ++] ++ ++ ++def PrintUsage(): ++ tool_list = '' ++ for (tool, info) in _TOOLS: ++ if not _HIDDEN in info: ++ tool_list += ' %-12s %s\n' % ( ++ tool, info[_FACTORY]().ShortDescription()) ++ ++ print("""GRIT - the Google Resource and Internationalization Tool ++ ++Usage: grit [GLOBALOPTIONS] TOOL [args to tool] ++ ++Global options: ++ ++ -i INPUT Specifies the INPUT file to use (a .grd file). If this is not ++ specified, GRIT will look for the environment variable GRIT_INPUT. ++ If it is not present either, GRIT will try to find an input file ++ named 'resource.grd' in the current working directory. ++ ++ -h MODULE Causes GRIT to use MODULE.UnsignedFingerPrint instead of ++ grit.extern.FP.UnsignedFingerprint. MODULE must be ++ available somewhere in the PYTHONPATH search path. ++ ++ -v Print more verbose runtime information. ++ ++ -x Print extremely verbose runtime information. Implies -v ++ ++ -p FNAME Specifies that GRIT should profile its execution and output the ++ results to the file FNAME. ++ ++Tools: ++ ++ TOOL can be one of the following: ++%s ++ For more information on how to use a particular tool, and the specific ++ arguments you can send to that tool, execute 'grit help TOOL' ++""" % (tool_list)) ++ ++ ++class Options(object): ++ """Option storage and parsing.""" ++ ++ def __init__(self): ++ self.hash = None ++ self.input = None ++ self.verbose = False ++ self.extra_verbose = False ++ self.output_stream = sys.stdout ++ self.profile_dest = None ++ ++ def ReadOptions(self, args): ++ """Reads options from the start of args and returns the remainder.""" ++ (opts, args) = getopt.getopt(args, 'vxi:p:h:', ('help',)) ++ for (key, val) in opts: ++ if key == '-h': self.hash = val ++ elif key == '-i': self.input = val ++ elif key == '-v': ++ self.verbose = True ++ util.verbose = True ++ elif key == '-x': ++ self.verbose = True ++ util.verbose = True ++ self.extra_verbose = True ++ util.extra_verbose = True ++ elif key == '-p': self.profile_dest = val ++ elif key == '--help': ++ PrintUsage() ++ sys.exit(0) ++ ++ if not self.input: ++ if 'GRIT_INPUT' in os.environ: ++ self.input = os.environ['GRIT_INPUT'] ++ else: ++ self.input = 'resource.grd' ++ ++ return args ++ ++ def __repr__(self): ++ return '(verbose: %d, input: %s)' % ( ++ self.verbose, self.input) ++ ++ ++def _GetToolInfo(tool): ++ """Returns the info map for the tool named 'tool' or None if there is no ++ such tool.""" ++ matches = [t for t in _TOOLS if t[0] == tool] ++ if not matches: ++ return None ++ else: ++ return matches[0][1] ++ ++ ++def Main(args=None): ++ """Parses arguments and does the appropriate thing.""" ++ util.ChangeStdoutEncoding() ++ ++ # Support for setuptools console wrappers. ++ if args is None: ++ args = sys.argv[1:] ++ ++ options = Options() ++ try: ++ args = options.ReadOptions(args) # args may be shorter after this ++ except getopt.GetoptError as e: ++ print("grit:", str(e)) ++ print("Try running 'grit help' for valid options.") ++ return 1 ++ if not args: ++ print("No tool provided. Try running 'grit help' for a list of tools.") ++ return 2 ++ ++ tool = args[0] ++ if tool == 'help': ++ if len(args) == 1: ++ PrintUsage() ++ return 0 ++ else: ++ tool = args[1] ++ if not _GetToolInfo(tool): ++ print("No such tool. Try running 'grit help' for a list of tools.") ++ return 2 ++ ++ print("Help for 'grit %s' (for general help, run 'grit help'):\n" % ++ (tool,)) ++ _GetToolInfo(tool)[_FACTORY]().ShowUsage() ++ return 0 ++ if not _GetToolInfo(tool): ++ print("No such tool. Try running 'grit help' for a list of tools.") ++ return 2 ++ ++ try: ++ if _GetToolInfo(tool)[_REQUIRES_INPUT]: ++ os.stat(options.input) ++ except OSError: ++ print('Input file %s not found.\n' ++ 'To specify a different input file:\n' ++ ' 1. Use the GRIT_INPUT environment variable.\n' ++ ' 2. Use the -i command-line option. This overrides ' ++ 'GRIT_INPUT.\n' ++ ' 3. Specify neither GRIT_INPUT or -i and GRIT will try to load ' ++ "'resource.grd'\n" ++ ' from the current directory.' % options.input) ++ return 2 ++ ++ if options.hash: ++ grit.extern.FP.UseUnsignedFingerPrintFromModule(options.hash) ++ ++ try: ++ toolobject = _GetToolInfo(tool)[_FACTORY]() ++ if options.profile_dest: ++ import hotshot ++ prof = hotshot.Profile(options.profile_dest) ++ return prof.runcall(toolobject.Run, options, args[1:]) ++ else: ++ return toolobject.Run(options, args[1:]) ++ except getopt.GetoptError as e: ++ print("grit: %s: %s" % (tool, str(e))) ++ print("Try running 'grit help %s' for valid options." % (tool,)) ++ return 1 + -+class Baz { -+ public: -+ typedef typename Foo::AnotherTypedef MyLocalTypedef; -+}; + -+// Unsafe; should error. -+class UnsafeTypedefChainInImpl : public Baz::MyLocalTypedef { -+ public: -+ UnsafeTypedefChainInImpl() {} -+ ~UnsafeTypedefChainInImpl() {} -+}; ++if __name__ == '__main__': ++ sys.path.append( ++ os.path.join( ++ os.path.dirname( ++ os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), ++ 'diagnosis')) ++ try: ++ import crbug_1001171 ++ with crbug_1001171.DumpStateOnLookupError(): ++ sys.exit(Main(sys.argv[1:])) ++ except ImportError: ++ pass ++ ++ sys.exit(Main(sys.argv[1:])) +diff --git a/tools/grit/grit/grit_runner_unittest.py b/tools/grit/grit/grit_runner_unittest.py +new file mode 100644 +index 0000000000..1487001d81 +--- /dev/null ++++ b/tools/grit/grit/grit_runner_unittest.py +@@ -0,0 +1,42 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for grit.py''' ++ ++from __future__ import print_function + -+int main() { -+ PublicRefCountedDtorInHeader bad; -+ PublicRefCountedDtorInImpl also_bad; ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '..')) + -+ ProtectedRefCountedDtorInHeader* protected_ok = NULL; -+ PrivateRefCountedDtorInHeader* private_ok = NULL; ++import unittest + -+ DerivedProtectedToPublicInHeader still_bad; -+ PublicRefCountedThreadSafeDtorInHeader another_bad_variation; -+ AnonymousDerivedProtectedToPublicInImpl and_this_is_bad_too; -+ ImplicitDerivedProtectedToPublicInHeader bad_yet_again; -+ UnsafeTypedefChainInImpl and_again_this_is_bad; ++from six import StringIO + -+ WebKitPublicDtorInHeader ignored; -+ WebKitDerivedPublicDtorInHeader still_ignored; ++from grit import util ++import grit.grit_runner + -+ return 0; -+} -diff --git a/tools/clang/plugins/tests/base_refcounted.h b/tools/clang/plugins/tests/base_refcounted.h ++class OptionArgsUnittest(unittest.TestCase): ++ def setUp(self): ++ self.buf = StringIO() ++ self.old_stdout = sys.stdout ++ sys.stdout = self.buf ++ ++ def tearDown(self): ++ sys.stdout = self.old_stdout ++ ++ def testSimple(self): ++ grit.grit_runner.Main(['-i', ++ util.PathFromRoot('grit/testdata/simple-input.xml'), ++ 'test', 'bla', 'voff', 'ga']) ++ output = self.buf.getvalue() ++ self.failUnless(output.count("'test'") == 0) # tool name doesn't occur ++ self.failUnless(output.count('bla')) ++ self.failUnless(output.count('simple-input.xml')) ++ ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/lazy_re.py b/tools/grit/grit/lazy_re.py new file mode 100644 -index 0000000000..1e53215997 +index 0000000000..5c461e87e7 --- /dev/null -+++ b/tools/clang/plugins/tests/base_refcounted.h -@@ -0,0 +1,121 @@ -+// Copyright (c) 2012 The Chromium Authors. All rights reserved. -+// Use of this source code is governed by a BSD-style license that can be -+// found in the LICENSE file. ++++ b/tools/grit/grit/lazy_re.py +@@ -0,0 +1,46 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+#ifndef BASE_REFCOUNTED_H_ -+#define BASE_REFCOUNTED_H_ ++'''In GRIT, we used to compile a lot of regular expressions at parse ++time. Since many of them never get used, we use lazy_re to compile ++them on demand the first time they are used, thus speeding up startup ++time in some cases. ++''' ++ ++from __future__ import print_function ++ ++import re ++ ++ ++class LazyRegexObject(object): ++ '''This object creates a RegexObject with the arguments passed in ++ its constructor, the first time any attribute except the several on ++ the class itself is accessed. This accomplishes lazy compilation of ++ the regular expression while maintaining a nearly-identical ++ interface. ++ ''' ++ ++ def __init__(self, *args, **kwargs): ++ self._stash_args = args ++ self._stash_kwargs = kwargs ++ self._lazy_re = None ++ ++ def _LazyInit(self): ++ if not self._lazy_re: ++ self._lazy_re = re.compile(*self._stash_args, **self._stash_kwargs) ++ ++ def __getattribute__(self, name): ++ if name in ('_LazyInit', '_lazy_re', '_stash_args', '_stash_kwargs'): ++ return object.__getattribute__(self, name) ++ else: ++ self._LazyInit() ++ return getattr(self._lazy_re, name) ++ ++ ++def compile(*args, **kwargs): ++ '''Creates a LazyRegexObject that, when invoked on, will compile a ++ re.RegexObject (via re.compile) with the same arguments passed to ++ this function, and delegate almost all of its methods to it. ++ ''' ++ return LazyRegexObject(*args, **kwargs) +diff --git a/tools/grit/grit/lazy_re_unittest.py b/tools/grit/grit/lazy_re_unittest.py +new file mode 100644 +index 0000000000..8488b454ee +--- /dev/null ++++ b/tools/grit/grit/lazy_re_unittest.py +@@ -0,0 +1,40 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+namespace base { ++'''Unit test for lazy_re. ++''' + -+template <typename T> -+class RefCounted { -+ public: -+ RefCounted() {} -+ ~RefCounted() {} -+}; ++from __future__ import print_function + -+template <typename T> -+class RefCountedThreadSafe { -+ public: -+ RefCountedThreadSafe() {} -+ ~RefCountedThreadSafe() {} -+}; ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '..')) + -+} // namespace base ++import re ++import unittest + -+// Ignore classes whose inheritance tree ends in WebKit's RefCounted base -+// class. Though prone to error, this pattern is very prevalent in WebKit -+// code, so do not issue any warnings. -+namespace WebKit { ++from grit import lazy_re + -+template <typename T> -+class RefCounted { -+ public: -+ RefCounted() {} -+ ~RefCounted() {} -+}; + -+} // namespace WebKit ++class LazyReUnittest(unittest.TestCase): + -+// Unsafe; should error. -+class PublicRefCountedDtorInHeader -+ : public base::RefCounted<PublicRefCountedDtorInHeader> { -+ public: -+ PublicRefCountedDtorInHeader() {} -+ ~PublicRefCountedDtorInHeader() {} ++ def testCreatedOnlyOnDemand(self): ++ rex = lazy_re.compile('bingo') ++ self.assertEqual(None, rex._lazy_re) ++ self.assertTrue(rex.match('bingo')) ++ self.assertNotEqual(None, rex._lazy_re) + -+ private: -+ friend class base::RefCounted<PublicRefCountedDtorInHeader>; -+}; ++ def testJustKwargsWork(self): ++ rex = lazy_re.compile(flags=re.I, pattern='BiNgO') ++ self.assertTrue(rex.match('bingo')) ++ ++ def testPositionalAndKwargsWork(self): ++ rex = lazy_re.compile('BiNgO', flags=re.I) ++ self.assertTrue(rex.match('bingo')) + -+// Unsafe; should error. -+class PublicRefCountedThreadSafeDtorInHeader -+ : public base::RefCountedThreadSafe< -+ PublicRefCountedThreadSafeDtorInHeader> { -+ public: -+ PublicRefCountedThreadSafeDtorInHeader() {} -+ ~PublicRefCountedThreadSafeDtorInHeader() {} -+ -+ private: -+ friend class base::RefCountedThreadSafe< -+ PublicRefCountedThreadSafeDtorInHeader>; -+}; + -+// Safe; should not have errors. -+class ProtectedRefCountedDtorInHeader -+ : public base::RefCounted<ProtectedRefCountedDtorInHeader> { -+ public: -+ ProtectedRefCountedDtorInHeader() {} ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/node/__init__.py b/tools/grit/grit/node/__init__.py +new file mode 100644 +index 0000000000..2fc0d3360c +--- /dev/null ++++ b/tools/grit/grit/node/__init__.py +@@ -0,0 +1,8 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+ protected: -+ ~ProtectedRefCountedDtorInHeader() {} ++'''Package 'grit.node' ++''' + -+ private: -+ friend class base::RefCounted<ProtectedRefCountedDtorInHeader>; -+}; ++pass +diff --git a/tools/grit/grit/node/base.py b/tools/grit/grit/node/base.py +new file mode 100644 +index 0000000000..40859d301d +--- /dev/null ++++ b/tools/grit/grit/node/base.py +@@ -0,0 +1,670 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+// Safe; should not have errors. -+class PrivateRefCountedDtorInHeader -+ : public base::RefCounted<PrivateRefCountedDtorInHeader> { -+ public: -+ PrivateRefCountedDtorInHeader() {} ++'''Base types for nodes in a GRIT resource tree. ++''' + -+ private: -+ ~PrivateRefCountedDtorInHeader() {} -+ friend class base::RefCounted<PrivateRefCountedDtorInHeader>; -+}; ++from __future__ import print_function + -+// Unsafe; A grandchild class ends up exposing their parent and grandparent's -+// destructors. -+class DerivedProtectedToPublicInHeader -+ : public ProtectedRefCountedDtorInHeader { -+ public: -+ DerivedProtectedToPublicInHeader() {} -+ ~DerivedProtectedToPublicInHeader() {} -+}; ++import ast ++import os ++import struct ++import sys ++from xml.sax import saxutils ++ ++import six ++ ++from grit import constants ++from grit import clique ++from grit import exception ++from grit import util ++from grit.node import brotli_util ++import grit.format.gzip_string ++ ++ ++class Node(object): ++ '''An item in the tree that has children.''' ++ ++ # Valid content types that can be returned by _ContentType() ++ _CONTENT_TYPE_NONE = 0 # No CDATA content but may have children ++ _CONTENT_TYPE_CDATA = 1 # Only CDATA, no children. ++ _CONTENT_TYPE_MIXED = 2 # CDATA and children, possibly intermingled ++ ++ # Types of files to be compressed by default. ++ _COMPRESS_BY_DEFAULT_EXTENSIONS = ('.js', '.html', '.css', '.svg') ++ ++ # Default nodes to not whitelist skipped ++ _whitelist_marked_as_skip = False ++ ++ # A class-static cache to speed up EvaluateExpression(). ++ # Keys are expressions (e.g. 'is_ios and lang == "fr"'). Values are tuples ++ # (code, variables_in_expr) where code is the compiled expression and can be ++ # directly eval'd, and variables_in_expr is the list of variable and method ++ # names used in the expression (e.g. ['is_ios', 'lang']). ++ eval_expr_cache = {} ++ ++ def __init__(self): ++ self.children = [] # A list of child elements ++ self.mixed_content = [] # A list of u'' and/or child elements (this ++ # duplicates 'children' but ++ # is needed to preserve markup-type content). ++ self.name = u'' # The name of this element ++ self.attrs = {} # The set of attributes (keys to values) ++ self.parent = None # Our parent unless we are the root element. ++ self.uberclique = None # Allows overriding uberclique for parts of tree ++ self.source = None # File that this node was parsed from ++ ++ # This context handler allows you to write "with node:" and get a ++ # line identifying the offending node if an exception escapes from the body ++ # of the with statement. ++ def __enter__(self): ++ return self ++ ++ def __exit__(self, exc_type, exc_value, traceback): ++ if exc_type is not None: ++ print(u'Error processing node %s: %s' % (six.text_type(self), exc_value)) ++ ++ def __iter__(self): ++ '''A preorder iteration through the tree that this node is the root of.''' ++ return self.Preorder() ++ ++ def Preorder(self): ++ '''Generator that generates first this node, then the same generator for ++ any child nodes.''' ++ yield self ++ for child in self.children: ++ for iterchild in child.Preorder(): ++ yield iterchild ++ ++ def ActiveChildren(self): ++ '''Returns the children of this node that should be included in the current ++ configuration. Overridden by <if>.''' ++ return [node for node in self.children if not node.WhitelistMarkedAsSkip()] ++ ++ def ActiveDescendants(self): ++ '''Yields the current node and all descendants that should be included in ++ the current configuration, in preorder.''' ++ yield self ++ for child in self.ActiveChildren(): ++ for descendant in child.ActiveDescendants(): ++ yield descendant ++ ++ def GetRoot(self): ++ '''Returns the root Node in the tree this Node belongs to.''' ++ curr = self ++ while curr.parent: ++ curr = curr.parent ++ return curr ++ ++ # TODO(joi) Use this (currently untested) optimization?: ++ #if hasattr(self, '_root'): ++ # return self._root ++ #curr = self ++ #while curr.parent and not hasattr(curr, '_root'): ++ # curr = curr.parent ++ #if curr.parent: ++ # self._root = curr._root ++ #else: ++ # self._root = curr ++ #return self._root ++ ++ def StartParsing(self, name, parent): ++ '''Called at the start of parsing. ++ ++ Args: ++ name: u'elementname' ++ parent: grit.node.base.Node or subclass or None ++ ''' ++ assert isinstance(name, six.string_types) ++ assert not parent or isinstance(parent, Node) ++ self.name = name ++ self.parent = parent ++ ++ def AddChild(self, child): ++ '''Adds a child to the list of children of this node, if it is a valid ++ child for the node.''' ++ assert isinstance(child, Node) ++ if (not self._IsValidChild(child) or ++ self._ContentType() == self._CONTENT_TYPE_CDATA): ++ explanation = 'invalid child %s for parent %s' % (str(child), self.name) ++ raise exception.UnexpectedChild(explanation) ++ self.children.append(child) ++ self.mixed_content.append(child) ++ ++ def RemoveChild(self, child_id): ++ '''Removes the first node that has a "name" attribute which ++ matches "child_id" in the list of immediate children of ++ this node. ++ ++ Args: ++ child_id: String identifying the child to be removed ++ ''' ++ index = 0 ++ # Safe not to copy since we only remove the first element found ++ for child in self.children: ++ name_attr = child.attrs['name'] ++ if name_attr == child_id: ++ self.children.pop(index) ++ self.mixed_content.pop(index) ++ break ++ index += 1 ++ ++ def AppendContent(self, content): ++ '''Appends a chunk of text as content of this node. ++ ++ Args: ++ content: u'hello' ++ ++ Return: ++ None ++ ''' ++ assert isinstance(content, six.string_types) ++ if self._ContentType() != self._CONTENT_TYPE_NONE: ++ self.mixed_content.append(content) ++ elif content.strip() != '': ++ raise exception.UnexpectedContent() ++ ++ def HandleAttribute(self, attrib, value): ++ '''Informs the node of an attribute that was parsed out of the GRD file ++ for it. ++ ++ Args: ++ attrib: 'name' ++ value: 'fooblat' ++ ++ Return: ++ None ++ ''' ++ assert isinstance(attrib, six.string_types) ++ assert isinstance(value, six.string_types) ++ if self._IsValidAttribute(attrib, value): ++ self.attrs[attrib] = value ++ else: ++ raise exception.UnexpectedAttribute(attrib) ++ ++ def EndParsing(self): ++ '''Called at the end of parsing.''' ++ ++ # TODO(joi) Rewrite this, it's extremely ugly! ++ if len(self.mixed_content): ++ if isinstance(self.mixed_content[0], six.string_types): ++ # Remove leading and trailing chunks of pure whitespace. ++ while (len(self.mixed_content) and ++ isinstance(self.mixed_content[0], six.string_types) and ++ self.mixed_content[0].strip() == ''): ++ self.mixed_content = self.mixed_content[1:] ++ # Strip leading and trailing whitespace from mixed content chunks ++ # at front and back. ++ if (len(self.mixed_content) and ++ isinstance(self.mixed_content[0], six.string_types)): ++ self.mixed_content[0] = self.mixed_content[0].lstrip() ++ # Remove leading and trailing ''' (used to demarcate whitespace) ++ if (len(self.mixed_content) and ++ isinstance(self.mixed_content[0], six.string_types)): ++ if self.mixed_content[0].startswith("'''"): ++ self.mixed_content[0] = self.mixed_content[0][3:] ++ if len(self.mixed_content): ++ if isinstance(self.mixed_content[-1], six.string_types): ++ # Same stuff all over again for the tail end. ++ while (len(self.mixed_content) and ++ isinstance(self.mixed_content[-1], six.string_types) and ++ self.mixed_content[-1].strip() == ''): ++ self.mixed_content = self.mixed_content[:-1] ++ if (len(self.mixed_content) and ++ isinstance(self.mixed_content[-1], six.string_types)): ++ self.mixed_content[-1] = self.mixed_content[-1].rstrip() ++ if (len(self.mixed_content) and ++ isinstance(self.mixed_content[-1], six.string_types)): ++ if self.mixed_content[-1].endswith("'''"): ++ self.mixed_content[-1] = self.mixed_content[-1][:-3] ++ ++ # Check that all mandatory attributes are there. ++ for node_mandatt in self.MandatoryAttributes(): ++ mandatt_list = [] ++ if node_mandatt.find('|') >= 0: ++ mandatt_list = node_mandatt.split('|') ++ else: ++ mandatt_list.append(node_mandatt) ++ ++ mandatt_option_found = False ++ for mandatt in mandatt_list: ++ assert mandatt not in self.DefaultAttributes() ++ if mandatt in self.attrs: ++ if not mandatt_option_found: ++ mandatt_option_found = True ++ else: ++ raise exception.MutuallyExclusiveMandatoryAttribute(mandatt) ++ ++ if not mandatt_option_found: ++ raise exception.MissingMandatoryAttribute(mandatt) ++ ++ # Add default attributes if not specified in input file. ++ for defattr in self.DefaultAttributes(): ++ if not defattr in self.attrs: ++ self.attrs[defattr] = self.DefaultAttributes()[defattr] ++ ++ def GetCdata(self): ++ '''Returns all CDATA of this element, concatenated into a single ++ string. Note that this ignores any elements embedded in CDATA.''' ++ return ''.join([c for c in self.mixed_content ++ if isinstance(c, six.string_types)]) ++ ++ def __str__(self): ++ '''Returns this node and all nodes below it as an XML document in a Unicode ++ string.''' ++ header = u'<?xml version="1.0" encoding="UTF-8"?>\n' ++ return header + self.FormatXml() ++ ++ # Some Python 2 glue. ++ __unicode__ = __str__ ++ ++ def FormatXml(self, indent = u'', one_line = False): ++ '''Returns this node and all nodes below it as an XML ++ element in a Unicode string. This differs from __unicode__ in that it does ++ not include the <?xml> stuff at the top of the string. If one_line is true, ++ children and CDATA are layed out in a way that preserves internal ++ whitespace. ++ ''' ++ assert isinstance(indent, six.string_types) ++ ++ content_one_line = (one_line or ++ self._ContentType() == self._CONTENT_TYPE_MIXED) ++ inside_content = self.ContentsAsXml(indent, content_one_line) ++ ++ # Then the attributes for this node. ++ attribs = u'' ++ default_attribs = self.DefaultAttributes() ++ for attrib, value in sorted(self.attrs.items()): ++ # Only print an attribute if it is other than the default value. ++ if attrib not in default_attribs or value != default_attribs[attrib]: ++ attribs += u' %s=%s' % (attrib, saxutils.quoteattr(value)) ++ ++ # Finally build the XML for our node and return it ++ if len(inside_content) > 0: ++ if one_line: ++ return u'<%s%s>%s</%s>' % (self.name, attribs, inside_content, ++ self.name) ++ elif content_one_line: ++ return u'%s<%s%s>\n%s %s\n%s</%s>' % ( ++ indent, self.name, attribs, ++ indent, inside_content, ++ indent, self.name) ++ else: ++ return u'%s<%s%s>\n%s\n%s</%s>' % ( ++ indent, self.name, attribs, ++ inside_content, ++ indent, self.name) ++ else: ++ return u'%s<%s%s />' % (indent, self.name, attribs) ++ ++ def ContentsAsXml(self, indent, one_line): ++ '''Returns the contents of this node (CDATA and child elements) in XML ++ format. If 'one_line' is true, the content will be laid out on one line.''' ++ assert isinstance(indent, six.string_types) ++ ++ # Build the contents of the element. ++ inside_parts = [] ++ last_item = None ++ for mixed_item in self.mixed_content: ++ if isinstance(mixed_item, Node): ++ inside_parts.append(mixed_item.FormatXml(indent + u' ', one_line)) ++ if not one_line: ++ inside_parts.append(u'\n') ++ else: ++ message = mixed_item ++ # If this is the first item and it starts with whitespace, we add ++ # the ''' delimiter. ++ if not last_item and message.lstrip() != message: ++ message = u"'''" + message ++ inside_parts.append(util.EncodeCdata(message)) ++ last_item = mixed_item ++ ++ # If there are only child nodes and no cdata, there will be a spurious ++ # trailing \n ++ if len(inside_parts) and inside_parts[-1] == '\n': ++ inside_parts = inside_parts[:-1] ++ ++ # If the last item is a string (not a node) and ends with whitespace, ++ # we need to add the ''' delimiter. ++ if (isinstance(last_item, six.string_types) and ++ last_item.rstrip() != last_item): ++ inside_parts[-1] = inside_parts[-1] + u"'''" ++ ++ return u''.join(inside_parts) ++ ++ def SubstituteMessages(self, substituter): ++ '''Applies substitutions to all messages in the tree. ++ ++ Called as a final step of RunGatherers. ++ ++ Args: ++ substituter: a grit.util.Substituter object. ++ ''' ++ for child in self.children: ++ child.SubstituteMessages(substituter) ++ ++ def _IsValidChild(self, child): ++ '''Returns true if 'child' is a valid child of this node. ++ Overridden by subclasses.''' ++ return False ++ ++ def _IsValidAttribute(self, name, value): ++ '''Returns true if 'name' is the name of a valid attribute of this element ++ and 'value' is a valid value for that attribute. Overriden by ++ subclasses unless they have only mandatory attributes.''' ++ return (name in self.MandatoryAttributes() or ++ name in self.DefaultAttributes()) ++ ++ def _ContentType(self): ++ '''Returns the type of content this element can have. Overridden by ++ subclasses. The content type can be one of the _CONTENT_TYPE_XXX constants ++ above.''' ++ return self._CONTENT_TYPE_NONE ++ ++ def MandatoryAttributes(self): ++ '''Returns a list of attribute names that are mandatory (non-optional) ++ on the current element. One can specify a list of ++ "mutually exclusive mandatory" attributes by specifying them as one ++ element in the list, separated by a "|" character. ++ ''' ++ return [] ++ ++ def DefaultAttributes(self): ++ '''Returns a dictionary of attribute names that have defaults, mapped to ++ the default value. Overridden by subclasses.''' ++ return {} ++ ++ def GetCliques(self): ++ '''Returns all MessageClique objects belonging to this node. Overridden ++ by subclasses. ++ ++ Return: ++ [clique1, clique2] or [] ++ ''' ++ return [] ++ ++ def ToRealPath(self, path_from_basedir): ++ '''Returns a real path (which can be absolute or relative to the current ++ working directory), given a path that is relative to the base directory ++ set for the GRIT input file. ++ ++ Args: ++ path_from_basedir: '..' ++ ++ Return: ++ 'resource' ++ ''' ++ return util.normpath(os.path.join(self.GetRoot().GetBaseDir(), ++ os.path.expandvars(path_from_basedir))) ++ ++ def GetInputPath(self): ++ '''Returns a path, relative to the base directory set for the grd file, ++ that points to the file the node refers to. ++ ''' ++ # This implementation works for most nodes that have an input file. ++ return self.attrs['file'] ++ ++ def UberClique(self): ++ '''Returns the uberclique that should be used for messages originating in ++ a given node. If the node itself has its uberclique set, that is what we ++ use, otherwise we search upwards until we find one. If we do not find one ++ even at the root node, we set the root node's uberclique to a new ++ uberclique instance. ++ ''' ++ node = self ++ while not node.uberclique and node.parent: ++ node = node.parent ++ if not node.uberclique: ++ node.uberclique = clique.UberClique() ++ return node.uberclique ++ ++ def IsTranslateable(self): ++ '''Returns false if the node has contents that should not be translated, ++ otherwise returns false (even if the node has no contents). ++ ''' ++ if not 'translateable' in self.attrs: ++ return True ++ else: ++ return self.attrs['translateable'] == 'true' ++ ++ def IsAccessibilityWithNoUI(self): ++ '''Returns true if the node is marked as an accessibility label and the ++ message isn't shown in the UI. Otherwise returns false. This label is ++ used to determine if the text requires screenshots.''' ++ if not 'is_accessibility_with_no_ui' in self.attrs: ++ return False ++ else: ++ return self.attrs['is_accessibility_with_no_ui'] == 'true' ++ ++ def GetNodeById(self, id): ++ '''Returns the node in the subtree parented by this node that has a 'name' ++ attribute matching 'id'. Returns None if no such node is found. ++ ''' ++ for node in self: ++ if 'name' in node.attrs and node.attrs['name'] == id: ++ return node ++ return None ++ ++ def GetChildrenOfType(self, type): ++ '''Returns a list of all subnodes (recursing to all leaves) of this node ++ that are of the indicated type (or tuple of types). ++ ++ Args: ++ type: A type you could use with isinstance(). ++ ++ Return: ++ A list, possibly empty. ++ ''' ++ return [child for child in self if isinstance(child, type)] ++ ++ def GetTextualIds(self): ++ '''Returns a list of the textual ids of this node. ++ ''' ++ if 'name' in self.attrs: ++ return [self.attrs['name']] ++ return [] ++ ++ @classmethod ++ def EvaluateExpression(cls, expr, defs, target_platform, extra_variables={}): ++ '''Worker for EvaluateCondition (below) and conditions in XTB files.''' ++ if expr in cls.eval_expr_cache: ++ code, variables_in_expr = cls.eval_expr_cache[expr] ++ else: ++ # Get a list of all variable and method names used in the expression. ++ syntax_tree = ast.parse(expr, mode='eval') ++ variables_in_expr = [node.id for node in ast.walk(syntax_tree) if ++ isinstance(node, ast.Name) and node.id not in ('True', 'False')] ++ code = compile(syntax_tree, filename='<string>', mode='eval') ++ cls.eval_expr_cache[expr] = code, variables_in_expr ++ ++ # Set values only for variables that are needed to eval the expression. ++ variable_map = {} ++ for name in variables_in_expr: ++ if name == 'os': ++ value = target_platform ++ elif name == 'defs': ++ value = defs ++ ++ elif name == 'is_linux': ++ value = target_platform.startswith('linux') ++ elif name == 'is_macosx': ++ value = target_platform == 'darwin' ++ elif name == 'is_win': ++ value = target_platform in ('cygwin', 'win32') ++ elif name == 'is_android': ++ value = target_platform == 'android' ++ elif name == 'is_ios': ++ value = target_platform == 'ios' ++ elif name == 'is_bsd': ++ value = 'bsd' in target_platform ++ elif name == 'is_posix': ++ value = (target_platform in ('darwin', 'linux2', 'linux3', 'sunos5', ++ 'android', 'ios') ++ or 'bsd' in target_platform) ++ ++ elif name == 'pp_ifdef': ++ def pp_ifdef(symbol): ++ return symbol in defs ++ value = pp_ifdef ++ elif name == 'pp_if': ++ def pp_if(symbol): ++ return defs.get(symbol, False) ++ value = pp_if ++ ++ elif name in defs: ++ value = defs[name] ++ elif name in extra_variables: ++ value = extra_variables[name] ++ else: ++ # Undefined variables default to False. ++ value = False ++ ++ variable_map[name] = value ++ ++ eval_result = eval(code, {}, variable_map) ++ assert isinstance(eval_result, bool) ++ return eval_result ++ ++ def EvaluateCondition(self, expr): ++ '''Returns true if and only if the Python expression 'expr' evaluates ++ to true. ++ ++ The expression is given a few local variables: ++ - 'lang' is the language currently being output ++ (the 'lang' attribute of the <output> element). ++ - 'context' is the current output context ++ (the 'context' attribute of the <output> element). ++ - 'defs' is a map of C preprocessor-style symbol names to their values. ++ - 'os' is the current platform (likely 'linux2', 'win32' or 'darwin'). ++ - 'pp_ifdef(symbol)' is a shorthand for "symbol in defs". ++ - 'pp_if(symbol)' is a shorthand for "symbol in defs and defs[symbol]". ++ - 'is_linux', 'is_macosx', 'is_win', 'is_posix' are true if 'os' ++ matches the given platform. ++ ''' ++ root = self.GetRoot() ++ lang = getattr(root, 'output_language', '') ++ context = getattr(root, 'output_context', '') ++ defs = getattr(root, 'defines', {}) ++ target_platform = getattr(root, 'target_platform', '') ++ extra_variables = { ++ 'lang': lang, ++ 'context': context, ++ } ++ return Node.EvaluateExpression( ++ expr, defs, target_platform, extra_variables) ++ ++ def OnlyTheseTranslations(self, languages): ++ '''Turns off loading of translations for languages not in the provided list. ++ ++ Attrs: ++ languages: ['fr', 'zh_cn'] ++ ''' ++ for node in self: ++ if (hasattr(node, 'IsTranslation') and ++ node.IsTranslation() and ++ node.GetLang() not in languages): ++ node.DisableLoading() ++ ++ def FindBooleanAttribute(self, attr, default, skip_self): ++ '''Searches all ancestors of the current node for the nearest enclosing ++ definition of the given boolean attribute. ++ ++ Args: ++ attr: 'fallback_to_english' ++ default: What to return if no node defines the attribute. ++ skip_self: Don't check the current node, only its parents. ++ ''' ++ p = self.parent if skip_self else self ++ while p: ++ value = p.attrs.get(attr, 'default').lower() ++ if value != 'default': ++ return (value == 'true') ++ p = p.parent ++ return default ++ ++ def PseudoIsAllowed(self): ++ '''Returns true if this node is allowed to use pseudo-translations. This ++ is true by default, unless this node is within a <release> node that has ++ the allow_pseudo attribute set to false. ++ ''' ++ return self.FindBooleanAttribute('allow_pseudo', ++ default=True, skip_self=True) ++ ++ def ShouldFallbackToEnglish(self): ++ '''Returns true iff this node should fall back to English when ++ pseudotranslations are disabled and no translation is available for a ++ given message. ++ ''' ++ return self.FindBooleanAttribute('fallback_to_english', ++ default=False, skip_self=True) ++ ++ def WhitelistMarkedAsSkip(self): ++ '''Returns true if the node is marked to be skipped in the output by a ++ whitelist. ++ ''' ++ return self._whitelist_marked_as_skip ++ ++ def SetWhitelistMarkedAsSkip(self, mark_skipped): ++ '''Sets WhitelistMarkedAsSkip. ++ ''' ++ self._whitelist_marked_as_skip = mark_skipped ++ ++ def ExpandVariables(self): ++ '''Whether we need to expand variables on a given node.''' ++ return False ++ ++ def IsResourceMapSource(self): ++ '''Whether this node is a resource map source.''' ++ return False ++ ++ def CompressDataIfNeeded(self, data): ++ '''Compress data using the format specified in the compress attribute. ++ ++ Args: ++ data: The data to compressed. ++ Returns: ++ The data in gzipped or brotli compressed format. If the format is ++ unspecified then this returns the data uncompressed. ++ ''' ++ ++ compress = self.attrs.get('compress') ++ ++ # Compress JS, HTML, CSS and SVG files by default (gzip), unless |compress| ++ # is explicitly specified. ++ compress_by_default = (compress == 'default' ++ and self.attrs.get('file').endswith( ++ self._COMPRESS_BY_DEFAULT_EXTENSIONS)) ++ ++ if compress == 'gzip' or compress_by_default: ++ # We only use rsyncable compression on Linux. ++ # We exclude ChromeOS since ChromeOS bots are Linux based but do not have ++ # the --rsyncable option built in for gzip. See crbug.com/617950. ++ if sys.platform == 'linux2' and 'chromeos' not in self.GetRoot().defines: ++ return grit.format.gzip_string.GzipStringRsyncable(data) ++ return grit.format.gzip_string.GzipString(data) ++ ++ if compress == 'brotli': ++ # The length of the uncompressed data as 8 bytes little-endian. ++ size_bytes = struct.pack("<q", len(data)) ++ data = brotli_util.BrotliCompress(data) ++ # BROTLI_CONST is prepended to brotli decompressed data in order to ++ # easily check if a resource has been brotli compressed. ++ # The length of the uncompressed data is also appended to the start, ++ # truncated to 6 bytes, little-endian. size_bytes is 8 bytes, ++ # need to truncate further to 6. ++ formatter = b'%ds %dx %ds' % (6, 2, len(size_bytes) - 8) ++ return (constants.BROTLI_CONST + ++ b''.join(struct.unpack(formatter, size_bytes)) + ++ data) ++ ++ if compress == 'false' or compress == 'default': ++ return data ++ ++ raise Exception('Invalid value for compression') ++ ++ ++class ContentNode(Node): ++ '''Convenience baseclass for nodes that can have content.''' ++ def _ContentType(self): ++ return self._CONTENT_TYPE_MIXED +diff --git a/tools/grit/grit/node/base_unittest.py b/tools/grit/grit/node/base_unittest.py +new file mode 100644 +index 0000000000..32a5a0ca59 +--- /dev/null ++++ b/tools/grit/grit/node/base_unittest.py +@@ -0,0 +1,259 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+// Unsafe; A grandchild ends up implicitly exposing their parent and -+// grantparent's destructors. -+class ImplicitDerivedProtectedToPublicInHeader -+ : public ProtectedRefCountedDtorInHeader { -+ public: -+ ImplicitDerivedProtectedToPublicInHeader() {} -+}; ++'''Unit tests for base.Node functionality (as used in various subclasses)''' + -+// Unsafe-but-ignored; should not have errors. -+class WebKitPublicDtorInHeader -+ : public WebKit::RefCounted<WebKitPublicDtorInHeader> { -+ public: -+ WebKitPublicDtorInHeader() {} -+ ~WebKitPublicDtorInHeader() {} -+}; ++from __future__ import print_function + -+// Unsafe-but-ignored; should not have errors. -+class WebKitDerivedPublicDtorInHeader -+ : public WebKitPublicDtorInHeader { -+ public: -+ WebKitDerivedPublicDtorInHeader() {} -+ ~WebKitDerivedPublicDtorInHeader() {} -+}; ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++import unittest ++ ++from six import StringIO ++ ++from grit import grd_reader ++from grit import util ++from grit.node import base ++from grit.node import message ++ ++ ++def MakePlaceholder(phname='BINGO'): ++ ph = message.PhNode() ++ ph.StartParsing(u'ph', None) ++ ph.HandleAttribute(u'name', phname) ++ ph.AppendContent(u'bongo') ++ ph.EndParsing() ++ return ph ++ ++ ++class NodeUnittest(unittest.TestCase): ++ def testWhitespaceHandling(self): ++ # We test using the Message node type. ++ node = message.MessageNode() ++ node.StartParsing(u'hello', None) ++ node.HandleAttribute(u'name', u'bla') ++ node.AppendContent(u" ''' two spaces ") ++ node.EndParsing() ++ self.failUnless(node.GetCdata() == u' two spaces') ++ ++ node = message.MessageNode() ++ node.StartParsing(u'message', None) ++ node.HandleAttribute(u'name', u'bla') ++ node.AppendContent(u" two spaces ''' ") ++ node.EndParsing() ++ self.failUnless(node.GetCdata() == u'two spaces ') ++ ++ def testWhitespaceHandlingWithChildren(self): ++ # We test using the Message node type. ++ node = message.MessageNode() ++ node.StartParsing(u'message', None) ++ node.HandleAttribute(u'name', u'bla') ++ node.AppendContent(u" ''' two spaces ") ++ node.AddChild(MakePlaceholder()) ++ node.AppendContent(u' space before and after ') ++ node.AddChild(MakePlaceholder('BONGO')) ++ node.AppendContent(u" space before two after '''") ++ node.EndParsing() ++ self.failUnless(node.mixed_content[0] == u' two spaces ') ++ self.failUnless(node.mixed_content[2] == u' space before and after ') ++ self.failUnless(node.mixed_content[-1] == u' space before two after ') ++ ++ def testXmlFormatMixedContent(self): ++ # Again test using the Message node type, because it is the only mixed ++ # content node. ++ node = message.MessageNode() ++ node.StartParsing(u'message', None) ++ node.HandleAttribute(u'name', u'name') ++ node.AppendContent(u'Hello <young> ') ++ ++ ph = message.PhNode() ++ ph.StartParsing(u'ph', None) ++ ph.HandleAttribute(u'name', u'USERNAME') ++ ph.AppendContent(u'$1') ++ ex = message.ExNode() ++ ex.StartParsing(u'ex', None) ++ ex.AppendContent(u'Joi') ++ ex.EndParsing() ++ ph.AddChild(ex) ++ ph.EndParsing() ++ ++ node.AddChild(ph) ++ node.EndParsing() ++ ++ non_indented_xml = node.FormatXml() ++ self.failUnless(non_indented_xml == u'<message name="name">\n Hello ' ++ u'<young> <ph name="USERNAME">$1<ex>Joi</ex></ph>' ++ u'\n</message>') ++ ++ indented_xml = node.FormatXml(u' ') ++ self.failUnless(indented_xml == u' <message name="name">\n Hello ' ++ u'<young> <ph name="USERNAME">$1<ex>Joi</ex></ph>' ++ u'\n </message>') ++ ++ def testXmlFormatMixedContentWithLeadingWhitespace(self): ++ # Again test using the Message node type, because it is the only mixed ++ # content node. ++ node = message.MessageNode() ++ node.StartParsing(u'message', None) ++ node.HandleAttribute(u'name', u'name') ++ node.AppendContent(u"''' Hello <young> ") ++ ++ ph = message.PhNode() ++ ph.StartParsing(u'ph', None) ++ ph.HandleAttribute(u'name', u'USERNAME') ++ ph.AppendContent(u'$1') ++ ex = message.ExNode() ++ ex.StartParsing(u'ex', None) ++ ex.AppendContent(u'Joi') ++ ex.EndParsing() ++ ph.AddChild(ex) ++ ph.EndParsing() ++ ++ node.AddChild(ph) ++ node.AppendContent(u" yessiree '''") ++ node.EndParsing() ++ ++ non_indented_xml = node.FormatXml() ++ self.failUnless(non_indented_xml == ++ u"<message name=\"name\">\n ''' Hello" ++ u' <young> <ph name="USERNAME">$1<ex>Joi</ex></ph>' ++ u" yessiree '''\n</message>") ++ ++ indented_xml = node.FormatXml(u' ') ++ self.failUnless(indented_xml == ++ u" <message name=\"name\">\n ''' Hello" ++ u' <young> <ph name="USERNAME">$1<ex>Joi</ex></ph>' ++ u" yessiree '''\n </message>") ++ ++ self.failUnless(node.GetNodeById('name')) ++ ++ def testXmlFormatContentWithEntities(self): ++ '''Tests a bug where would not be escaped correctly.''' ++ from grit import tclib ++ msg_node = message.MessageNode.Construct(None, tclib.Message( ++ text = 'BEGIN_BOLDHelloWHITESPACEthere!END_BOLD Bingo!', ++ placeholders = [ ++ tclib.Placeholder('BEGIN_BOLD', '<b>', 'bla'), ++ tclib.Placeholder('WHITESPACE', ' ', 'bla'), ++ tclib.Placeholder('END_BOLD', '</b>', 'bla')]), ++ 'BINGOBONGO') ++ xml = msg_node.FormatXml() ++ self.failUnless(xml.find(' ') == -1, 'should have no entities') ++ ++ def testIter(self): ++ # First build a little tree of message and ph nodes. ++ node = message.MessageNode() ++ node.StartParsing(u'message', None) ++ node.HandleAttribute(u'name', u'bla') ++ node.AppendContent(u" ''' two spaces ") ++ node.AppendContent(u' space before and after ') ++ ph = message.PhNode() ++ ph.StartParsing(u'ph', None) ++ ph.AddChild(message.ExNode()) ++ ph.HandleAttribute(u'name', u'BINGO') ++ ph.AppendContent(u'bongo') ++ node.AddChild(ph) ++ node.AddChild(message.PhNode()) ++ node.AppendContent(u" space before two after '''") ++ ++ order = [message.MessageNode, message.PhNode, message.ExNode, message.PhNode] ++ for n in node: ++ self.failUnless(type(n) == order[0]) ++ order = order[1:] ++ self.failUnless(len(order) == 0) ++ ++ def testGetChildrenOfType(self): ++ xml = '''<?xml version="1.0" encoding="UTF-8"?> ++ <grit latest_public_release="2" source_lang_id="en-US" ++ current_release="3" base_dir="."> ++ <outputs> ++ <output filename="resource.h" type="rc_header" /> ++ <output filename="en/generated_resources.rc" type="rc_all" ++ lang="en" /> ++ <if expr="pp_if('NOT_TRUE')"> ++ <output filename="de/generated_resources.rc" type="rc_all" ++ lang="de" /> ++ </if> ++ </outputs> ++ <release seq="3"> ++ <messages> ++ <message name="ID_HELLO">Hello!</message> ++ </messages> ++ </release> ++ </grit>''' ++ grd = grd_reader.Parse(StringIO(xml), ++ util.PathFromRoot('grit/test/data')) ++ from grit.node import node_io ++ output_nodes = grd.GetChildrenOfType(node_io.OutputNode) ++ self.failUnlessEqual(len(output_nodes), 3) ++ self.failUnlessEqual(output_nodes[2].attrs['filename'], ++ 'de/generated_resources.rc') ++ ++ def testEvaluateExpression(self): ++ def AssertExpr(expected_value, expr, defs, target_platform, ++ extra_variables): ++ self.failUnlessEqual(expected_value, base.Node.EvaluateExpression( ++ expr, defs, target_platform, extra_variables)) ++ ++ AssertExpr(True, "True", {}, 'linux', {}) ++ AssertExpr(False, "False", {}, 'linux', {}) ++ AssertExpr(True, "True or False", {}, 'linux', {}) ++ AssertExpr(False, "True and False", {}, 'linux', {}) ++ AssertExpr(True, "os == 'linux'", {}, 'linux', {}) ++ AssertExpr(False, "os == 'linux'", {}, 'ios', {}) ++ AssertExpr(True, "'foo' in defs", {'foo': 'bar'}, 'ios', {}) ++ AssertExpr(False, "'foo' in defs", {'baz': 'bar'}, 'ios', {}) ++ AssertExpr(False, "'foo' in defs", {}, 'ios', {}) ++ AssertExpr(True, "is_linux", {}, 'linux2', {}) ++ AssertExpr(False, "is_linux", {}, 'win32', {}) ++ AssertExpr(True, "is_macosx", {}, 'darwin', {}) ++ AssertExpr(False, "is_macosx", {}, 'ios', {}) ++ AssertExpr(True, "is_win", {}, 'win32', {}) ++ AssertExpr(False, "is_win", {}, 'darwin', {}) ++ AssertExpr(True, "is_android", {}, 'android', {}) ++ AssertExpr(False, "is_android", {}, 'linux3', {}) ++ AssertExpr(True, "is_ios", {}, 'ios', {}) ++ AssertExpr(False, "is_ios", {}, 'darwin', {}) ++ AssertExpr(True, "is_posix", {}, 'linux2', {}) ++ AssertExpr(True, "is_posix", {}, 'darwin', {}) ++ AssertExpr(True, "is_posix", {}, 'android', {}) ++ AssertExpr(True, "is_posix", {}, 'ios', {}) ++ AssertExpr(True, "is_posix", {}, 'freebsd7', {}) ++ AssertExpr(False, "is_posix", {}, 'win32', {}) ++ AssertExpr(True, "pp_ifdef('foo')", {'foo': True}, 'win32', {}) ++ AssertExpr(True, "pp_ifdef('foo')", {'foo': False}, 'win32', {}) ++ AssertExpr(False, "pp_ifdef('foo')", {'bar': True}, 'win32', {}) ++ AssertExpr(True, "pp_if('foo')", {'foo': True}, 'win32', {}) ++ AssertExpr(False, "pp_if('foo')", {'foo': False}, 'win32', {}) ++ AssertExpr(False, "pp_if('foo')", {'bar': True}, 'win32', {}) ++ AssertExpr(True, "foo", {'foo': True}, 'win32', {}) ++ AssertExpr(False, "foo", {'foo': False}, 'win32', {}) ++ AssertExpr(False, "foo", {'bar': True}, 'win32', {}) ++ AssertExpr(True, "foo == 'baz'", {'foo': 'baz'}, 'win32', {}) ++ AssertExpr(False, "foo == 'baz'", {'foo': True}, 'win32', {}) ++ AssertExpr(False, "foo == 'baz'", {}, 'win32', {}) ++ AssertExpr(True, "lang == 'de'", {}, 'win32', {'lang': 'de'}) ++ AssertExpr(False, "lang == 'de'", {}, 'win32', {'lang': 'fr'}) ++ AssertExpr(False, "lang == 'de'", {}, 'win32', {}) ++ ++ # Test a couple more complex expressions for good measure. ++ AssertExpr(True, "is_ios and (lang in ['de', 'fr'] or foo)", ++ {'foo': 'bar'}, 'ios', {'lang': 'fr', 'context': 'today'}) ++ AssertExpr(False, "is_ios and (lang in ['de', 'fr'] or foo)", ++ {'foo': False}, 'linux2', {'lang': 'fr', 'context': 'today'}) ++ AssertExpr(False, "is_ios and (lang in ['de', 'fr'] or foo)", ++ {'baz': 'bar'}, 'ios', {'lang': 'he', 'context': 'today'}) ++ AssertExpr(True, "foo == 'bar' or not baz", ++ {'foo': 'bar', 'fun': True}, 'ios', {'lang': 'en'}) ++ AssertExpr(True, "foo == 'bar' or not baz", ++ {}, 'ios', {'lang': 'en', 'context': 'java'}) ++ AssertExpr(False, "foo == 'bar' or not baz", ++ {'foo': 'ruz', 'baz': True}, 'ios', {'lang': 'en'}) + -+#endif // BASE_REFCOUNTED_H_ -diff --git a/tools/clang/plugins/tests/base_refcounted.txt b/tools/clang/plugins/tests/base_refcounted.txt ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/node/brotli_util.py b/tools/grit/grit/node/brotli_util.py new file mode 100644 -index 0000000000..4626424177 +index 0000000000..77f70e49d5 --- /dev/null -+++ b/tools/clang/plugins/tests/base_refcounted.txt -@@ -0,0 +1,23 @@ -+In file included from base_refcounted.cpp:5: -+./base_refcounted.h:45:3: warning: [chromium-style] Classes that are ref-counted should not have public destructors. -+ ~PublicRefCountedDtorInHeader() {} -+ ^ -+./base_refcounted.h:57:3: warning: [chromium-style] Classes that are ref-counted should not have public destructors. -+ ~PublicRefCountedThreadSafeDtorInHeader() {} -+ ^ -+./base_refcounted.h:94:3: warning: [chromium-style] Classes that are ref-counted should not have public destructors. -+ ~DerivedProtectedToPublicInHeader() {} -+ ^ -+./base_refcounted.h:99:1: warning: [chromium-style] Classes that are ref-counted should have explicit destructors that are protected or private. -+class ImplicitDerivedProtectedToPublicInHeader -+^ -+base_refcounted.cpp:16:3: warning: [chromium-style] Classes that are ref-counted should not have public destructors. -+ ~AnonymousDerivedProtectedToPublicInImpl() {} -+ ^ -+base_refcounted.cpp:26:3: warning: [chromium-style] Classes that are ref-counted should not have public destructors. -+ ~PublicRefCountedDtorInImpl() {} -+ ^ -+base_refcounted.cpp:52:3: warning: [chromium-style] Classes that are ref-counted should not have public destructors. -+ ~UnsafeTypedefChainInImpl() {} -+ ^ -+7 warnings generated. -diff --git a/tools/clang/plugins/tests/inline_copy_ctor.cpp b/tools/clang/plugins/tests/inline_copy_ctor.cpp -new file mode 100644 -index 0000000000..dcd90020c5 ---- /dev/null -+++ b/tools/clang/plugins/tests/inline_copy_ctor.cpp -@@ -0,0 +1,5 @@ -+// Copyright (c) 2012 The Chromium Authors. All rights reserved. -+// Use of this source code is governed by a BSD-style license that can be -+// found in the LICENSE file. ++++ b/tools/grit/grit/node/brotli_util.py +@@ -0,0 +1,29 @@ ++# Copyright 2019 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++"""Framework for compressing resources using Brotli.""" ++ ++import subprocess ++ ++__brotli_executable = None + -+#include "inline_copy_ctor.h" -diff --git a/tools/clang/plugins/tests/inline_copy_ctor.h b/tools/clang/plugins/tests/inline_copy_ctor.h ++ ++def SetBrotliCommand(brotli): ++ # brotli is a list. In production it contains the path to the Brotli executable. ++ # During testing it contains [python, mock_brotli.py] for testing on Windows. ++ global __brotli_executable ++ __brotli_executable = brotli ++ ++ ++def BrotliCompress(data): ++ if not __brotli_executable: ++ raise Exception('Add "use_brotli = true" to you GN grit(...) target ' + ++ 'if you want to use brotli.') ++ compress = subprocess.Popen(__brotli_executable + ['-', '-f'], ++ stdin=subprocess.PIPE, stdout=subprocess.PIPE) ++ return compress.communicate(data)[0] ++ ++def IsInitialized(): ++ global __brotli_executable ++ return __brotli_executable is not None +diff --git a/tools/grit/grit/node/custom/__init__.py b/tools/grit/grit/node/custom/__init__.py new file mode 100644 -index 0000000000..619a18392b +index 0000000000..e179cf7730 --- /dev/null -+++ b/tools/clang/plugins/tests/inline_copy_ctor.h -@@ -0,0 +1,12 @@ -+// Copyright (c) 2012 The Chromium Authors. All rights reserved. -+// Use of this source code is governed by a BSD-style license that can be -+// found in the LICENSE file. ++++ b/tools/grit/grit/node/custom/__init__.py +@@ -0,0 +1,8 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+struct C { -+ C(); -+ ~C(); ++'''Package 'grit.node.custom' ++''' + -+ static C foo() { return C(); } ++pass +diff --git a/tools/grit/grit/node/custom/filename.py b/tools/grit/grit/node/custom/filename.py +new file mode 100644 +index 0000000000..55a27e58c1 +--- /dev/null ++++ b/tools/grit/grit/node/custom/filename.py +@@ -0,0 +1,29 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+ int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p , q, r, s, t, u, v, w, x; -+}; -diff --git a/tools/clang/plugins/tests/inline_copy_ctor.txt b/tools/clang/plugins/tests/inline_copy_ctor.txt ++'''A CustomType for filenames.''' ++ ++from __future__ import print_function ++ ++from grit import clique ++from grit import lazy_re ++ ++ ++class WindowsFilename(clique.CustomType): ++ '''Validates that messages can be used as Windows filenames, and strips ++ illegal characters out of translations. ++ ''' ++ ++ BANNED = lazy_re.compile(r'\+|:|\/|\\\\|\*|\?|\"|\<|\>|\|') ++ ++ def Validate(self, message): ++ return not self.BANNED.search(message.GetPresentableContent()) ++ ++ def ValidateAndModify(self, lang, translation): ++ is_ok = self.Validate(translation) ++ self.ModifyEachTextPart(lang, translation) ++ return is_ok ++ ++ def ModifyTextPart(self, lang, text): ++ return self.BANNED.sub(' ', text) +diff --git a/tools/grit/grit/node/custom/filename_unittest.py b/tools/grit/grit/node/custom/filename_unittest.py new file mode 100644 -index 0000000000..bc4bd8911e +index 0000000000..8e2a6dd64a --- /dev/null -+++ b/tools/clang/plugins/tests/inline_copy_ctor.txt -@@ -0,0 +1,5 @@ -+In file included from inline_copy_ctor.cpp:5: -+./inline_copy_ctor.h:5:1: warning: [chromium-style] Complex class/struct needs an explicit out-of-line copy constructor. -+struct C { -+^ -+1 warning generated. -diff --git a/tools/clang/plugins/tests/inline_ctor.cpp b/tools/clang/plugins/tests/inline_ctor.cpp ++++ b/tools/grit/grit/node/custom/filename_unittest.py +@@ -0,0 +1,34 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for grit.node.custom.filename''' ++ ++from __future__ import print_function ++ ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../../..')) ++ ++import unittest ++from grit.node.custom import filename ++from grit import clique ++from grit import tclib ++ ++ ++class WindowsFilenameUnittest(unittest.TestCase): ++ ++ def testValidate(self): ++ factory = clique.UberClique() ++ msg = tclib.Message(text='Bingo bongo') ++ c = factory.MakeClique(msg) ++ c.SetCustomType(filename.WindowsFilename()) ++ translation = tclib.Translation(id=msg.GetId(), text='Bilingo bolongo:') ++ c.AddTranslation(translation, 'fr') ++ self.failUnless(c.MessageForLanguage('fr').GetRealContent() == 'Bilingo bolongo ') ++ ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/node/empty.py b/tools/grit/grit/node/empty.py new file mode 100644 -index 0000000000..6a751fb405 +index 0000000000..e19d2c4ddb --- /dev/null -+++ b/tools/clang/plugins/tests/inline_ctor.cpp -@@ -0,0 +1,25 @@ -+// Copyright (c) 2011 The Chromium Authors. All rights reserved. -+// Use of this source code is governed by a BSD-style license that can be -+// found in the LICENSE file. ++++ b/tools/grit/grit/node/empty.py +@@ -0,0 +1,64 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+#include "inline_ctor.h" ++'''Container nodes that don't have any logic. ++''' + -+#include <string> -+#include <vector> ++from __future__ import print_function + -+// We don't warn on classes that are in CPP files. -+class InlineInCPPOK { -+ public: -+ InlineInCPPOK() {} -+ ~InlineInCPPOK() {} ++from grit.node import base ++from grit.node import include ++from grit.node import message ++from grit.node import misc ++from grit.node import node_io ++from grit.node import structure + -+ private: -+ std::vector<int> one_; -+ std::vector<std::string> two_; -+}; + -+int main() { -+ InlineInCPPOK one; -+ InlineCtorsArentOKInHeader two; -+ return 0; ++class GroupingNode(base.Node): ++ '''Base class for all the grouping elements (<structures>, <includes>, ++ <messages> and <identifiers>).''' ++ def DefaultAttributes(self): ++ return { ++ 'first_id' : '', ++ 'comment' : '', ++ 'fallback_to_english' : 'false', ++ 'fallback_to_low_resolution' : 'false', ++ } ++ ++ ++class IncludesNode(GroupingNode): ++ '''The <includes> element.''' ++ def _IsValidChild(self, child): ++ return isinstance(child, (include.IncludeNode, misc.IfNode, misc.PartNode)) ++ ++ ++class MessagesNode(GroupingNode): ++ '''The <messages> element.''' ++ def _IsValidChild(self, child): ++ return isinstance(child, (message.MessageNode, misc.IfNode, misc.PartNode)) ++ ++ ++class StructuresNode(GroupingNode): ++ '''The <structures> element.''' ++ def _IsValidChild(self, child): ++ return isinstance(child, (structure.StructureNode, ++ misc.IfNode, misc.PartNode)) ++ ++ ++class TranslationsNode(base.Node): ++ '''The <translations> element.''' ++ def _IsValidChild(self, child): ++ return isinstance(child, (node_io.FileNode, misc.IfNode, misc.PartNode)) ++ ++ ++class OutputsNode(base.Node): ++ '''The <outputs> element.''' ++ def _IsValidChild(self, child): ++ return isinstance(child, (node_io.OutputNode, misc.IfNode, misc.PartNode)) ++ ++ ++class IdentifiersNode(GroupingNode): ++ '''The <identifiers> element.''' ++ def _IsValidChild(self, child): ++ return isinstance(child, misc.IdentifierNode) +diff --git a/tools/grit/grit/node/include.py b/tools/grit/grit/node/include.py +new file mode 100644 +index 0000000000..b06b9889bb +--- /dev/null ++++ b/tools/grit/grit/node/include.py +@@ -0,0 +1,170 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++"""Handling of the <include> element. ++""" ++ ++from __future__ import print_function ++ ++import os ++ ++from grit import util ++import grit.format.html_inline ++import grit.format.rc ++from grit.format import minifier ++from grit.node import base ++ ++class IncludeNode(base.Node): ++ """An <include> element.""" ++ ++ def __init__(self): ++ super(IncludeNode, self).__init__() ++ ++ # Cache flattened data so that we don't flatten the same file ++ # multiple times. ++ self._flattened_data = None ++ # Also keep track of the last filename we flattened to, so we can ++ # avoid doing it more than once. ++ self._last_flat_filename = None ++ ++ def _IsValidChild(self, child): ++ return False ++ ++ def _GetFlattenedData( ++ self, allow_external_script=False, preprocess_only=False): ++ if not self._flattened_data: ++ filename = self.ToRealPath(self.GetInputPath()) ++ self._flattened_data = ( ++ grit.format.html_inline.InlineToString(filename, self, ++ preprocess_only=preprocess_only, ++ allow_external_script=allow_external_script)) ++ return self._flattened_data.encode('utf-8') ++ ++ def MandatoryAttributes(self): ++ return ['name', 'type', 'file'] ++ ++ def DefaultAttributes(self): ++ """Attributes: ++ translateable: False if the node has contents that should not be ++ translated. ++ preprocess: Takes the same code path as flattenhtml, but it ++ disables any processing/inlining outside of <if> ++ and <include>. ++ compress: The format to compress the data with, e.g. 'gzip' ++ or 'false' if data should not be compressed. ++ skip_minify: If true, skips minifying the node's contents. ++ skip_in_resource_map: If true, do not add to the resource map. ++ """ ++ return { ++ 'translateable': 'true', ++ 'generateid': 'true', ++ 'filenameonly': 'false', ++ 'mkoutput': 'false', ++ 'preprocess': 'false', ++ 'flattenhtml': 'false', ++ 'compress': 'default', ++ 'allowexternalscript': 'false', ++ 'relativepath': 'false', ++ 'use_base_dir': 'true', ++ 'skip_minify': 'false', ++ 'skip_in_resource_map': 'false', ++ } ++ ++ def GetInputPath(self): ++ # Do not mess with absolute paths, that would make them invalid. ++ if os.path.isabs(os.path.expandvars(self.attrs['file'])): ++ return self.attrs['file'] ++ ++ # We have no control over code that calls ToRealPath later, so convert ++ # the path to be relative against our basedir. ++ if self.attrs.get('use_base_dir', 'true') != 'true': ++ # Normalize the directory path to use the appropriate OS separator. ++ # GetBaseDir() may return paths\like\this or paths/like/this, since it is ++ # read from the base_dir attribute in the grd file. ++ norm_base_dir = util.normpath(self.GetRoot().GetBaseDir()) ++ return os.path.relpath(self.attrs['file'], norm_base_dir) ++ ++ return self.attrs['file'] ++ ++ def FileForLanguage(self, lang, output_dir): ++ """Returns the file for the specified language. This allows us to return ++ different files for different language variants of the include file. ++ """ ++ input_path = self.GetInputPath() ++ if input_path is None: ++ return None ++ ++ return self.ToRealPath(input_path) ++ ++ def GetDataPackValue(self, lang, encoding): ++ '''Returns bytes or a str represenation for a data_pack entry.''' ++ filename = self.ToRealPath(self.GetInputPath()) ++ if self.attrs['flattenhtml'] == 'true': ++ allow_external_script = self.attrs['allowexternalscript'] == 'true' ++ data = self._GetFlattenedData(allow_external_script=allow_external_script) ++ elif self.attrs['preprocess'] == 'true': ++ data = self._GetFlattenedData(preprocess_only=True) ++ else: ++ data = util.ReadFile(filename, util.BINARY) ++ ++ if self.attrs['skip_minify'] != 'true': ++ # Note that the minifier will only do anything if a minifier command ++ # has been set in the command line. ++ data = minifier.Minify(data, filename) ++ ++ # Include does not care about the encoding, because it only returns binary ++ # data. ++ return self.CompressDataIfNeeded(data) ++ ++ def Process(self, output_dir): ++ """Rewrite file references to be base64 encoded data URLs. The new file ++ will be written to output_dir and the name of the new file is returned.""" ++ filename = self.ToRealPath(self.GetInputPath()) ++ flat_filename = os.path.join(output_dir, ++ self.attrs['name'] + '_' + os.path.basename(filename)) ++ ++ if self._last_flat_filename == flat_filename: ++ return ++ ++ with open(flat_filename, 'wb') as outfile: ++ outfile.write(self._GetFlattenedData()) ++ ++ self._last_flat_filename = flat_filename ++ return os.path.basename(flat_filename) ++ ++ def GetHtmlResourceFilenames(self): ++ """Returns a set of all filenames inlined by this file.""" ++ allow_external_script = self.attrs['allowexternalscript'] == 'true' ++ return grit.format.html_inline.GetResourceFilenames( ++ self.ToRealPath(self.GetInputPath()), ++ self, ++ allow_external_script=allow_external_script) ++ ++ def IsResourceMapSource(self): ++ skip = self.attrs.get('skip_in_resource_map', 'false') == 'true' ++ return not skip ++ ++ @staticmethod ++ def Construct(parent, name, type, file, translateable=True, ++ filenameonly=False, mkoutput=False, relativepath=False): ++ """Creates a new node which is a child of 'parent', with attributes set ++ by parameters of the same name. ++ """ ++ # Convert types to appropriate strings ++ translateable = util.BoolToString(translateable) ++ filenameonly = util.BoolToString(filenameonly) ++ mkoutput = util.BoolToString(mkoutput) ++ relativepath = util.BoolToString(relativepath) ++ ++ node = IncludeNode() ++ node.StartParsing('include', parent) ++ node.HandleAttribute('name', name) ++ node.HandleAttribute('type', type) ++ node.HandleAttribute('file', file) ++ node.HandleAttribute('translateable', translateable) ++ node.HandleAttribute('filenameonly', filenameonly) ++ node.HandleAttribute('mkoutput', mkoutput) ++ node.HandleAttribute('relativepath', relativepath) ++ node.EndParsing() ++ return node +diff --git a/tools/grit/grit/node/include_unittest.py b/tools/grit/grit/node/include_unittest.py +new file mode 100644 +index 0000000000..4c658f1ffe +--- /dev/null ++++ b/tools/grit/grit/node/include_unittest.py +@@ -0,0 +1,134 @@ ++#!/usr/bin/env python ++# Copyright (c) 2013 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for include.IncludeNode''' ++ ++from __future__ import print_function ++ ++import os ++import sys ++import unittest ++import zlib ++ ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++from grit.node import misc ++from grit.node import include ++from grit.node import empty ++from grit import util ++ ++ ++def checkIsGzipped(filename, compress_attr): ++ test_data_root = util.PathFromRoot('grit/testdata') ++ root = util.ParseGrdForUnittest( ++ ''' ++ <includes> ++ <include name="TEST_TXT" file="%s" %s type="BINDATA"/> ++ </includes>''' % (filename, compress_attr), ++ base_dir=test_data_root) ++ node, = root.GetChildrenOfType(include.IncludeNode) ++ compressed = node.GetDataPackValue(lang='en', encoding=util.BINARY) ++ ++ decompressed_data = zlib.decompress(compressed, 16 + zlib.MAX_WBITS) ++ expected = util.ReadFile(os.path.join(test_data_root, filename), util.BINARY) ++ return expected == decompressed_data ++ ++ ++class IncludeNodeUnittest(unittest.TestCase): ++ def testGetPath(self): ++ root = misc.GritNode() ++ root.StartParsing(u'grit', None) ++ root.HandleAttribute(u'latest_public_release', u'0') ++ root.HandleAttribute(u'current_release', u'1') ++ root.HandleAttribute(u'base_dir', r'..\resource') ++ release = misc.ReleaseNode() ++ release.StartParsing(u'release', root) ++ release.HandleAttribute(u'seq', u'1') ++ root.AddChild(release) ++ includes = empty.IncludesNode() ++ includes.StartParsing(u'includes', release) ++ release.AddChild(includes) ++ include_node = include.IncludeNode() ++ include_node.StartParsing(u'include', includes) ++ include_node.HandleAttribute(u'file', r'flugel\kugel.pdf') ++ includes.AddChild(include_node) ++ root.EndParsing() ++ ++ self.assertEqual(root.ToRealPath(include_node.GetInputPath()), ++ util.normpath( ++ os.path.join(r'../resource', r'flugel/kugel.pdf'))) ++ ++ def testGetPathNoBasedir(self): ++ root = misc.GritNode() ++ root.StartParsing(u'grit', None) ++ root.HandleAttribute(u'latest_public_release', u'0') ++ root.HandleAttribute(u'current_release', u'1') ++ root.HandleAttribute(u'base_dir', r'..\resource') ++ release = misc.ReleaseNode() ++ release.StartParsing(u'release', root) ++ release.HandleAttribute(u'seq', u'1') ++ root.AddChild(release) ++ includes = empty.IncludesNode() ++ includes.StartParsing(u'includes', release) ++ release.AddChild(includes) ++ include_node = include.IncludeNode() ++ include_node.StartParsing(u'include', includes) ++ include_node.HandleAttribute(u'file', r'flugel\kugel.pdf') ++ include_node.HandleAttribute(u'use_base_dir', u'false') ++ includes.AddChild(include_node) ++ root.EndParsing() ++ ++ last_dir = os.path.basename(os.getcwd()) ++ expected_path = util.normpath(os.path.join( ++ u'..', last_dir, u'flugel/kugel.pdf')) ++ self.assertEqual(root.ToRealPath(include_node.GetInputPath()), ++ expected_path) ++ ++ def testCompressGzip(self): ++ self.assertTrue(checkIsGzipped('test_text.txt', 'compress="gzip"')) ++ ++ def testCompressGzipByDefault(self): ++ self.assertTrue(checkIsGzipped('test_html.html', '')) ++ self.assertTrue(checkIsGzipped('test_js.js', '')) ++ self.assertTrue(checkIsGzipped('test_css.css', '')) ++ self.assertTrue(checkIsGzipped('test_svg.svg', '')) ++ ++ self.assertTrue(checkIsGzipped('test_html.html', 'compress="default"')) ++ self.assertTrue(checkIsGzipped('test_js.js', 'compress="default"')) ++ self.assertTrue(checkIsGzipped('test_css.css', 'compress="default"')) ++ self.assertTrue(checkIsGzipped('test_svg.svg', 'compress="default"')) ++ ++ def testSkipInResourceMap(self): ++ root = util.ParseGrdForUnittest(''' ++ <includes> ++ <include name="TEST1_TXT" file="test1_text.txt" type="BINDATA"/> ++ <include name="TEST2_TXT" file="test1_text.txt" type="BINDATA" ++ skip_in_resource_map="true"/> ++ <include name="TEST3_TXT" file="test1_text.txt" type="BINDATA" ++ skip_in_resource_map="false"/> ++ </includes>''', base_dir = util.PathFromRoot('grit/testdata')) ++ inc = root.GetChildrenOfType(include.IncludeNode) ++ self.assertTrue(inc[0].IsResourceMapSource()) ++ self.assertFalse(inc[1].IsResourceMapSource()) ++ self.assertTrue(inc[2].IsResourceMapSource()) ++ ++ def testAcceptsPreprocess(self): ++ root = util.ParseGrdForUnittest( ++ ''' ++ <includes> ++ <include name="PREPROCESS_TEST" file="preprocess_test.html" ++ preprocess="true" compress="false" type="chrome_html"/> ++ </includes>''', ++ base_dir=util.PathFromRoot('grit/testdata')) ++ inc, = root.GetChildrenOfType(include.IncludeNode) ++ result = inc.GetDataPackValue(lang='en', encoding=util.BINARY) ++ self.assertIn(b'should be kept', result) ++ self.assertIn(b'in the middle...', result) ++ self.assertNotIn(b'should be removed', result) ++ ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/node/mapping.py b/tools/grit/grit/node/mapping.py +new file mode 100644 +index 0000000000..6297f0b666 +--- /dev/null ++++ b/tools/grit/grit/node/mapping.py +@@ -0,0 +1,60 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Maps each node type to an implementation class. ++When adding a new node type, you add to this mapping. ++''' ++ ++from __future__ import print_function ++ ++from grit import exception ++ ++from grit.node import empty ++from grit.node import include ++from grit.node import message ++from grit.node import misc ++from grit.node import node_io ++from grit.node import structure ++from grit.node import variant ++ ++ ++_ELEMENT_TO_CLASS = { ++ 'identifiers' : empty.IdentifiersNode, ++ 'includes' : empty.IncludesNode, ++ 'messages' : empty.MessagesNode, ++ 'outputs' : empty.OutputsNode, ++ 'structures' : empty.StructuresNode, ++ 'translations' : empty.TranslationsNode, ++ 'include' : include.IncludeNode, ++ 'emit' : node_io.EmitNode, ++ 'file' : node_io.FileNode, ++ 'output' : node_io.OutputNode, ++ 'ex' : message.ExNode, ++ 'message' : message.MessageNode, ++ 'ph' : message.PhNode, ++ 'else' : misc.ElseNode, ++ 'grit' : misc.GritNode, ++ 'identifier' : misc.IdentifierNode, ++ 'if' : misc.IfNode, ++ 'part' : misc.PartNode, ++ 'release' : misc.ReleaseNode, ++ 'then' : misc.ThenNode, ++ 'structure' : structure.StructureNode, ++ 'skeleton' : variant.SkeletonNode, +} -diff --git a/tools/clang/plugins/tests/inline_ctor.h b/tools/clang/plugins/tests/inline_ctor.h ++ ++ ++def ElementToClass(name, typeattr): ++ '''Maps an element to a class that handles the element. ++ ++ Args: ++ name: 'element' (the name of the element) ++ typeattr: 'type' (the value of the type attribute, if present, else None) ++ ++ Return: ++ type ++ ''' ++ if name not in _ELEMENT_TO_CLASS: ++ raise exception.UnknownElement() ++ return _ELEMENT_TO_CLASS[name] +diff --git a/tools/grit/grit/node/message.py b/tools/grit/grit/node/message.py new file mode 100644 -index 0000000000..d053b2f57d +index 0000000000..4fa83cf26b --- /dev/null -+++ b/tools/clang/plugins/tests/inline_ctor.h -@@ -0,0 +1,21 @@ -+// Copyright (c) 2012 The Chromium Authors. All rights reserved. -+// Use of this source code is governed by a BSD-style license that can be -+// found in the LICENSE file. ++++ b/tools/grit/grit/node/message.py +@@ -0,0 +1,362 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+#ifndef INLINE_CTOR_H_ -+#define INLINE_CTOR_H_ ++'''Handling of the <message> element. ++''' ++ ++from __future__ import print_function ++ ++import re ++ ++import six ++ ++from grit.node import base ++ ++from grit import clique ++from grit import exception ++from grit import lazy_re ++from grit import tclib ++from grit import util ++ ++ ++# Matches exactly three dots ending a line or followed by whitespace. ++_ELLIPSIS_PATTERN = lazy_re.compile(r'(?<!\.)\.\.\.(?=$|\s)') ++_ELLIPSIS_SYMBOL = u'\u2026' # Ellipsis ++ ++# Finds whitespace at the start and end of a string which can be multiline. ++_WHITESPACE = lazy_re.compile(r'(?P<start>\s*)(?P<body>.+?)(?P<end>\s*)\Z', ++ re.DOTALL | re.MULTILINE) ++ ++# <ph> placeholder elements should contain the special character formatters ++# used to format <ph> element content. ++# Android format. ++_ANDROID_FORMAT = (r'%[1-9]+\$' ++ r'([-#+ 0,(]*)([0-9]+)?(\.[0-9]+)?' ++ r'([bBhHsScCdoxXeEfgGaAtT%n])') ++# Chrome l10n format. ++_CHROME_FORMAT = r'\$+\d' ++# Windows EWT numeric and GRIT %s %d formats. ++_OTHER_FORMAT = r'%[0-9sd]' ++ ++# Finds formatters that must be in a placeholder (<ph>) element. ++_FORMATTERS = lazy_re.compile( ++ '(%s)|(%s)|(%s)' % (_ANDROID_FORMAT, _CHROME_FORMAT, _OTHER_FORMAT)) ++_BAD_PLACEHOLDER_MSG = ('ERROR: Placeholder formatter found outside of <ph> ' ++ 'tag in message "%s" in %s.') ++_INVALID_PH_CHAR_MSG = ('ERROR: Invalid format characters found in message ' ++ '"%s" <ph> tag in %s.') ++ ++# Finds HTML tag tokens. ++_HTMLTOKEN = lazy_re.compile(r'<[/]?[a-z][a-z0-9]*[^>]*>', re.I) ++ ++# Finds HTML entities. ++_HTMLENTITY = lazy_re.compile(r'&[^\s]*;') ++ ++ ++class MessageNode(base.ContentNode): ++ '''A <message> element.''' ++ ++ # For splitting a list of things that can be separated by commas or ++ # whitespace ++ _SPLIT_RE = lazy_re.compile(r'\s*,\s*|\s+') ++ ++ def __init__(self): ++ super(MessageNode, self).__init__() ++ # Valid after EndParsing, this is the MessageClique that contains the ++ # source message and any translations of it that have been loaded. ++ self.clique = None ++ ++ # We don't send leading and trailing whitespace into the translation ++ # console, but rather tack it onto the source message and any ++ # translations when formatting them into RC files or what have you. ++ self.ws_at_start = '' # Any whitespace characters at the start of the text ++ self.ws_at_end = '' # --"-- at the end of the text ++ ++ # A list of "shortcut groups" this message is in. We check to make sure ++ # that shortcut keys (e.g. &J) within each shortcut group are unique. ++ self.shortcut_groups_ = [] ++ ++ # Formatter-specific data used to control the output of individual strings. ++ # formatter_data is a space separated list of C preprocessor-style ++ # definitions. Names without values are given the empty string value. ++ # Example: "foo=5 bar baz=100" ++ self.formatter_data = {} ++ ++ # Whether or not to convert ... -> U+2026 within Translate(). ++ self._replace_ellipsis = False ++ ++ def _IsValidChild(self, child): ++ return isinstance(child, (PhNode)) ++ ++ def _IsValidAttribute(self, name, value): ++ if name not in [ ++ 'name', 'offset', 'translateable', 'desc', 'meaning', ++ 'internal_comment', 'shortcut_groups', 'custom_type', 'validation_expr', ++ 'use_name_for_id', 'sub_variable', 'formatter_data', ++ 'is_accessibility_with_no_ui' ++ ]: ++ return False ++ if (name in ('translateable', 'sub_variable') and ++ value not in ['true', 'false']): ++ return False ++ return True ++ ++ def SetReplaceEllipsis(self, value): ++ r'''Sets whether to replace ... with \u2026. ++ ''' ++ self._replace_ellipsis = value ++ ++ def MandatoryAttributes(self): ++ return ['name|offset'] ++ ++ def DefaultAttributes(self): ++ return { ++ 'custom_type': '', ++ 'desc': '', ++ 'formatter_data': '', ++ 'internal_comment': '', ++ 'is_accessibility_with_no_ui': 'false', ++ 'meaning': '', ++ 'shortcut_groups': '', ++ 'sub_variable': 'false', ++ 'translateable': 'true', ++ 'use_name_for_id': 'false', ++ 'validation_expr': '', ++ } + -+#include <string> -+#include <vector> ++ def HandleAttribute(self, attrib, value): ++ base.ContentNode.HandleAttribute(self, attrib, value) ++ if attrib != 'formatter_data': ++ return ++ ++ # Parse value, a space-separated list of defines, into a dict. ++ # Example: "foo=5 bar" -> {'foo':'5', 'bar':''} ++ for item in value.split(): ++ name, _, val = item.partition('=') ++ self.formatter_data[name] = val ++ ++ def GetTextualIds(self): ++ ''' ++ Returns the concatenation of the parent's node first_id and ++ this node's offset if it has one, otherwise just call the ++ superclass' implementation ++ ''' ++ if 'offset' not in self.attrs: ++ return super(MessageNode, self).GetTextualIds() ++ ++ # we search for the first grouping node in the parents' list ++ # to take care of the case where the first parent is an <if> node ++ grouping_parent = self.parent ++ import grit.node.empty ++ while grouping_parent and not isinstance(grouping_parent, ++ grit.node.empty.GroupingNode): ++ grouping_parent = grouping_parent.parent ++ ++ assert 'first_id' in grouping_parent.attrs ++ return [grouping_parent.attrs['first_id'] + '_' + self.attrs['offset']] ++ ++ def IsTranslateable(self): ++ return self.attrs['translateable'] == 'true' ++ ++ def EndParsing(self): ++ super(MessageNode, self).EndParsing() ++ ++ # Make the text (including placeholder references) and list of placeholders, ++ # verify placeholder formats, then strip and store leading and trailing ++ # whitespace and create the tclib.Message() and a clique to contain it. ++ ++ text = '' ++ placeholders = [] ++ ++ for item in self.mixed_content: ++ if isinstance(item, six.string_types): ++ # Not a <ph> element: fail if any <ph> formatters are detected. ++ if _FORMATTERS.search(item): ++ print(_BAD_PLACEHOLDER_MSG % (item, self.source)) ++ raise exception.PlaceholderNotInsidePhNode ++ text += item ++ else: ++ # Extract the <ph> element components. ++ presentation = item.attrs['name'].upper() ++ text += presentation ++ ex = ' ' # <ex> example element cdata if present. ++ if len(item.children): ++ ex = item.children[0].GetCdata() ++ original = item.GetCdata() ++ ++ # Sanity check the <ph> element content. ++ cdata = original ++ # Replace all HTML tag tokens in cdata. ++ match = _HTMLTOKEN.search(cdata) ++ while match: ++ cdata = cdata.replace(match.group(0), '_') ++ match = _HTMLTOKEN.search(cdata) ++ # Replace all HTML entities in cdata. ++ match = _HTMLENTITY.search(cdata) ++ while match: ++ cdata = cdata.replace(match.group(0), '_') ++ match = _HTMLENTITY.search(cdata) ++ # Remove first matching formatter from cdata. ++ match = _FORMATTERS.search(cdata) ++ if match: ++ cdata = cdata.replace(match.group(0), '') ++ # Fail if <ph> special chars remain in cdata. ++ if re.search(r'[%\$]', cdata): ++ message_id = self.attrs['name'] + ' ' + original; ++ print(_INVALID_PH_CHAR_MSG % (message_id, self.source)) ++ raise exception.InvalidCharactersInsidePhNode ++ ++ # Otherwise, accept this <ph> placeholder. ++ placeholders.append(tclib.Placeholder(presentation, original, ex)) ++ ++ m = _WHITESPACE.match(text) ++ if m: ++ self.ws_at_start = m.group('start') ++ self.ws_at_end = m.group('end') ++ text = m.group('body') ++ ++ self.shortcut_groups_ = self._SPLIT_RE.split(self.attrs['shortcut_groups']) ++ self.shortcut_groups_ = [i for i in self.shortcut_groups_ if i != ''] ++ ++ description_or_id = self.attrs['desc'] ++ if description_or_id == '' and 'name' in self.attrs: ++ description_or_id = 'ID: %s' % self.attrs['name'] ++ ++ assigned_id = None ++ if self.attrs['use_name_for_id'] == 'true': ++ assigned_id = self.attrs['name'] ++ message = tclib.Message(text=text, placeholders=placeholders, ++ description=description_or_id, ++ meaning=self.attrs['meaning'], ++ assigned_id=assigned_id) ++ self.InstallMessage(message) ++ ++ def InstallMessage(self, message): ++ '''Sets this node's clique from a tclib.Message instance. ++ ++ Args: ++ message: A tclib.Message. ++ ''' ++ self.clique = self.UberClique().MakeClique(message, self.IsTranslateable()) ++ for group in self.shortcut_groups_: ++ self.clique.AddToShortcutGroup(group) ++ if self.attrs['custom_type'] != '': ++ self.clique.SetCustomType(util.NewClassInstance(self.attrs['custom_type'], ++ clique.CustomType)) ++ elif self.attrs['validation_expr'] != '': ++ self.clique.SetCustomType( ++ clique.OneOffCustomType(self.attrs['validation_expr'])) ++ ++ def SubstituteMessages(self, substituter): ++ '''Applies substitution to this message. ++ ++ Args: ++ substituter: a grit.util.Substituter object. ++ ''' ++ message = substituter.SubstituteMessage(self.clique.GetMessage()) ++ if message is not self.clique.GetMessage(): ++ self.InstallMessage(message) ++ ++ def GetCliques(self): ++ return [self.clique] if self.clique else [] ++ ++ def Translate(self, lang): ++ '''Returns a translated version of this message. ++ ''' ++ assert self.clique ++ msg = self.clique.MessageForLanguage(lang, ++ self.PseudoIsAllowed(), ++ self.ShouldFallbackToEnglish() ++ ).GetRealContent() ++ if self._replace_ellipsis: ++ msg = _ELLIPSIS_PATTERN.sub(_ELLIPSIS_SYMBOL, msg) ++ # Always remove all byte order marks (\uFEFF) https://crbug.com/1033305 ++ msg = msg.replace(u'\uFEFF','') ++ return msg.replace('[GRITLANGCODE]', lang) ++ ++ def NameOrOffset(self): ++ key = 'name' if 'name' in self.attrs else 'offset' ++ return self.attrs[key] ++ ++ def ExpandVariables(self): ++ '''We always expand variables on Messages.''' ++ return True ++ ++ def GetDataPackValue(self, lang, encoding): ++ '''Returns a str represenation for a data_pack entry.''' ++ message = self.ws_at_start + self.Translate(lang) + self.ws_at_end ++ return util.Encode(message, encoding) ++ ++ def IsResourceMapSource(self): ++ return True ++ ++ @staticmethod ++ def Construct(parent, message, name, desc='', meaning='', translateable=True): ++ '''Constructs a new message node that is a child of 'parent', with the ++ name, desc, meaning and translateable attributes set using the same-named ++ parameters and the text of the message and any placeholders taken from ++ 'message', which must be a tclib.Message() object.''' ++ # Convert type to appropriate string ++ translateable = 'true' if translateable else 'false' ++ ++ node = MessageNode() ++ node.StartParsing('message', parent) ++ node.HandleAttribute('name', name) ++ node.HandleAttribute('desc', desc) ++ node.HandleAttribute('meaning', meaning) ++ node.HandleAttribute('translateable', translateable) ++ ++ items = message.GetContent() ++ for ix, item in enumerate(items): ++ if isinstance(item, six.string_types): ++ # Ensure whitespace at front and back of message is correctly handled. ++ if ix == 0: ++ item = "'''" + item ++ if ix == len(items) - 1: ++ item = item + "'''" ++ ++ node.AppendContent(item) ++ else: ++ phnode = PhNode() ++ phnode.StartParsing('ph', node) ++ phnode.HandleAttribute('name', item.GetPresentation()) ++ phnode.AppendContent(item.GetOriginal()) ++ ++ if len(item.GetExample()) and item.GetExample() != ' ': ++ exnode = ExNode() ++ exnode.StartParsing('ex', phnode) ++ exnode.AppendContent(item.GetExample()) ++ exnode.EndParsing() ++ phnode.AddChild(exnode) ++ ++ phnode.EndParsing() ++ node.AddChild(phnode) ++ ++ node.EndParsing() ++ return node ++ ++ ++class PhNode(base.ContentNode): ++ '''A <ph> element.''' ++ ++ def _IsValidChild(self, child): ++ return isinstance(child, ExNode) ++ ++ def MandatoryAttributes(self): ++ return ['name'] ++ ++ def EndParsing(self): ++ super(PhNode, self).EndParsing() ++ # We only allow a single example for each placeholder ++ if len(self.children) > 1: ++ raise exception.TooManyExamples() ++ ++ def GetTextualIds(self): ++ # The 'name' attribute is not an ID. ++ return [] ++ ++ ++class ExNode(base.ContentNode): ++ '''An <ex> element.''' ++ pass +diff --git a/tools/grit/grit/node/message_unittest.py b/tools/grit/grit/node/message_unittest.py +new file mode 100644 +index 0000000000..7a4cbbedc2 +--- /dev/null ++++ b/tools/grit/grit/node/message_unittest.py +@@ -0,0 +1,380 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+class InlineCtorsArentOKInHeader { -+ public: -+ InlineCtorsArentOKInHeader() {} -+ ~InlineCtorsArentOKInHeader() {} ++'''Unit tests for grit.node.message''' + -+ private: -+ std::vector<int> one_; -+ std::vector<std::string> two_; -+}; ++from __future__ import print_function + -+#endif // INLINE_CTOR_H_ -diff --git a/tools/clang/plugins/tests/inline_ctor.txt b/tools/clang/plugins/tests/inline_ctor.txt ++import os ++import sys ++import unittest ++ ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++from grit import exception ++from grit import tclib ++from grit import util ++from grit.node import message ++ ++class MessageUnittest(unittest.TestCase): ++ def testMessage(self): ++ root = util.ParseGrdForUnittest(''' ++ <messages> ++ <message name="IDS_GREETING" ++ desc="Printed to greet the currently logged in user"> ++ Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today? ++ </message> ++ </messages>''') ++ msg, = root.GetChildrenOfType(message.MessageNode) ++ cliques = msg.GetCliques() ++ content = cliques[0].GetMessage().GetPresentableContent() ++ self.failUnless(content == 'Hello USERNAME, how are you doing today?') ++ ++ def testMessageWithWhitespace(self): ++ root = util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_BLA" desc=""> ++ ''' Hello there <ph name="USERNAME">%s</ph> ''' ++ </message> ++ </messages>""") ++ msg, = root.GetChildrenOfType(message.MessageNode) ++ content = msg.GetCliques()[0].GetMessage().GetPresentableContent() ++ self.failUnless(content == 'Hello there USERNAME') ++ self.failUnless(msg.ws_at_start == ' ') ++ self.failUnless(msg.ws_at_end == ' ') ++ ++ def testConstruct(self): ++ msg = tclib.Message(text=" Hello USERNAME, how are you? BINGO\t\t", ++ placeholders=[tclib.Placeholder('USERNAME', '%s', 'Joi'), ++ tclib.Placeholder('BINGO', '%d', '11')]) ++ msg_node = message.MessageNode.Construct(None, msg, 'BINGOBONGO') ++ self.failUnless(msg_node.children[0].name == 'ph') ++ self.failUnless(msg_node.children[0].children[0].name == 'ex') ++ self.failUnless(msg_node.children[0].children[0].GetCdata() == 'Joi') ++ self.failUnless(msg_node.children[1].children[0].GetCdata() == '11') ++ self.failUnless(msg_node.ws_at_start == ' ') ++ self.failUnless(msg_node.ws_at_end == '\t\t') ++ ++ def testUnicodeConstruct(self): ++ text = u'Howdie \u00fe' ++ msg = tclib.Message(text=text) ++ msg_node = message.MessageNode.Construct(None, msg, 'BINGOBONGO') ++ msg_from_node = msg_node.GetCdata() ++ self.failUnless(msg_from_node == text) ++ ++ def testFormatterData(self): ++ root = util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_BLA" desc="" formatter_data=" foo=123 bar qux=low"> ++ Text ++ </message> ++ </messages>""") ++ msg, = root.GetChildrenOfType(message.MessageNode) ++ expected_formatter_data = { ++ 'foo': '123', ++ 'bar': '', ++ 'qux': 'low'} ++ ++ # Can't use assertDictEqual, not available in Python 2.6, so do it ++ # by hand. ++ self.failUnlessEqual(len(expected_formatter_data), ++ len(msg.formatter_data)) ++ for key in expected_formatter_data: ++ self.failUnlessEqual(expected_formatter_data[key], ++ msg.formatter_data[key]) ++ ++ def testReplaceEllipsis(self): ++ root = util.ParseGrdForUnittest(''' ++ <messages> ++ <message name="IDS_GREETING" desc=""> ++ A...B.... <ph name="PH">%s<ex>A</ex></ph>... B... C... ++ </message> ++ </messages>''') ++ msg, = root.GetChildrenOfType(message.MessageNode) ++ msg.SetReplaceEllipsis(True) ++ content = msg.Translate('en') ++ self.failUnlessEqual(u'A...B.... %s\u2026 B\u2026 C\u2026', content) ++ ++ def testRemoveByteOrderMark(self): ++ root = util.ParseGrdForUnittest(u''' ++ <messages> ++ <message name="IDS_HAS_BOM" desc=""> ++ \uFEFFThis\uFEFF i\uFEFFs OK\uFEFF ++ </message> ++ </messages>''') ++ msg, = root.GetChildrenOfType(message.MessageNode) ++ content = msg.Translate('en') ++ self.failUnlessEqual(u'This is OK', content) ++ ++ def testPlaceholderHasTooManyExamples(self): ++ try: ++ util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_FOO" desc="foo"> ++ Hi <ph name="NAME">$1<ex>Joi</ex><ex>Joy</ex></ph> ++ </message> ++ </messages>""") ++ except exception.TooManyExamples: ++ return ++ self.fail('Should have gotten exception') ++ ++ def testPlaceholderHasInvalidName(self): ++ try: ++ util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_FOO" desc="foo"> ++ Hi <ph name="ABC!">$1</ph> ++ </message> ++ </messages>""") ++ except exception.InvalidPlaceholderName: ++ return ++ self.fail('Should have gotten exception') ++ ++ def testChromeLocalizedFormatIsInsidePhNode(self): ++ try: ++ util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_CHROME_L10N" desc="l10n format"> ++ This message is missing the ph node: $1 ++ </message> ++ </messages>""") ++ except exception.PlaceholderNotInsidePhNode: ++ return ++ self.fail('Should have gotten exception') ++ ++ def testAndroidStringFormatIsInsidePhNode(self): ++ try: ++ util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_ANDROID" desc="string format"> ++ This message is missing a ph node: %1$s ++ </message> ++ </messages>""") ++ except exception.PlaceholderNotInsidePhNode: ++ return ++ self.fail('Should have gotten exception') ++ ++ def testAndroidIntegerFormatIsInsidePhNode(self): ++ try: ++ util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_ANDROID" desc="integer format"> ++ This message is missing a ph node: %2$d ++ </message> ++ </messages>""") ++ except exception.PlaceholderNotInsidePhNode: ++ return ++ self.fail('Should have gotten exception') ++ ++ def testAndroidIntegerWidthFormatIsInsidePhNode(self): ++ try: ++ util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_ANDROID" desc="integer width format"> ++ This message is missing a ph node: %2$3d ++ </message> ++ </messages>""") ++ except exception.PlaceholderNotInsidePhNode: ++ return ++ self.fail('Should have gotten exception') ++ ++ def testValidAndroidIntegerWidthFormatInPhNode(self): ++ try: ++ util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_ANDROID_WIDTH"> ++ <ph name="VALID">%2$3d<ex>042</ex></ph> ++ </message> ++ </messages>""") ++ except: ++ self.fail('Should not have gotten exception') ++ ++ def testAndroidFloatFormatIsInsidePhNode(self): ++ try: ++ util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_ANDROID" desc="float number format"> ++ This message is missing a ph node: %3$4.5f ++ </message> ++ </messages>""") ++ except exception.PlaceholderNotInsidePhNode: ++ return ++ self.fail('Should have gotten exception') ++ ++ def testGritStringFormatIsInsidePhNode(self): ++ try: ++ util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_GRIT_STRING" desc="grit string format"> ++ This message is missing the ph node: %s ++ </message> ++ </messages>""") ++ except exception.PlaceholderNotInsidePhNode: ++ return ++ self.fail('Should have gotten exception') ++ ++ def testGritIntegerFormatIsInsidePhNode(self): ++ try: ++ util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_GRIT_INTEGER" desc="grit integer format"> ++ This message is missing the ph node: %d ++ </message> ++ </messages>""") ++ except exception.PlaceholderNotInsidePhNode: ++ return ++ self.fail('Should have gotten exception') ++ ++ def testWindowsETWIntegerFormatIsInsidePhNode(self): ++ try: ++ util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_WINDOWS_ETW" desc="ETW tracing integer"> ++ This message is missing the ph node: %1 ++ </message> ++ </messages>""") ++ except exception.PlaceholderNotInsidePhNode: ++ return ++ self.fail('Should have gotten exception') ++ ++ def testValidMultipleFormattersInsidePhNodes(self): ++ root = util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_MULTIPLE_FORMATTERS"> ++ <ph name="ERROR_COUNT">%1$d<ex>1</ex></ph> error, <ph name="WARNING_COUNT">%2$d<ex>1</ex></ph> warning ++ </message> ++ </messages>""") ++ msg, = root.GetChildrenOfType(message.MessageNode) ++ cliques = msg.GetCliques() ++ content = cliques[0].GetMessage().GetPresentableContent() ++ self.failUnless(content == 'ERROR_COUNT error, WARNING_COUNT warning') ++ ++ def testMultipleFormattersAreInsidePhNodes(self): ++ failed = True ++ try: ++ util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_MULTIPLE_FORMATTERS"> ++ %1$d error, %2$d warning ++ </message> ++ </messages>""") ++ except exception.PlaceholderNotInsidePhNode: ++ failed = False ++ if failed: ++ self.fail('Should have gotten exception') ++ return ++ ++ failed = True ++ try: ++ util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_MULTIPLE_FORMATTERS"> ++ <ph name="ERROR_COUNT">%1$d<ex>1</ex></ph> error, %2$d warning ++ </message> ++ </messages>""") ++ except exception.PlaceholderNotInsidePhNode: ++ failed = False ++ if failed: ++ self.fail('Should have gotten exception') ++ return ++ ++ failed = True ++ try: ++ util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_MULTIPLE_FORMATTERS"> ++ <ph name="INVALID">%1$d %2$d</ph> ++ </message> ++ </messages>""") ++ except exception.InvalidCharactersInsidePhNode: ++ failed = False ++ if failed: ++ self.fail('Should have gotten exception') ++ return ++ ++ def testValidHTMLFormatInsidePhNode(self): ++ try: ++ util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_HTML"> ++ <ph name="VALID"><span>$1</span><ex>1</ex></ph> ++ </message> ++ </messages>""") ++ except: ++ self.fail('Should not have gotten exception') ++ ++ def testValidHTMLWithAttributesFormatInsidePhNode(self): ++ try: ++ util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_HTML_ATTRIBUTE"> ++ <ph name="VALID"><span attribute="js:$this %">$2</span><ex>2</ex></ph> ++ </message> ++ </messages>""") ++ except: ++ self.fail('Should not have gotten exception') ++ ++ def testValidHTMLEntityFormatInsidePhNode(self): ++ try: ++ util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_ENTITY"> ++ <ph name="VALID">>%1$d<<ex>1</ex></ph> ++ </message> ++ </messages>""") ++ except: ++ self.fail('Should not have gotten exception') ++ ++ def testValidMultipleDollarFormatInsidePhNode(self): ++ try: ++ util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_DOLLARS" desc="l10n dollars format"> ++ <ph name="VALID">$$1</ph> ++ </message> ++ </messages>""") ++ except: ++ self.fail('Should not have gotten exception') ++ ++ def testInvalidDollarCharacterInsidePhNode(self): ++ try: ++ util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_BAD_DOLLAR"> ++ <ph name="INVALID">%1$d $</ph> ++ </message> ++ </messages>""") ++ except exception.InvalidCharactersInsidePhNode: ++ return ++ self.fail('Should have gotten exception') ++ ++ def testInvalidPercentCharacterInsidePhNode(self): ++ try: ++ util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_BAD_PERCENT"> ++ <ph name="INVALID">%1$d %</ph> ++ </message> ++ </messages>""") ++ except exception.InvalidCharactersInsidePhNode: ++ return ++ self.fail('Should have gotten exception') ++ ++ def testInvalidMixedFormatCharactersInsidePhNode(self): ++ try: ++ util.ParseGrdForUnittest("""\ ++ <messages> ++ <message name="IDS_MIXED_FORMATS"> ++ <ph name="INVALID">%1$2</ph> ++ </message> ++ </messages>""") ++ except exception.InvalidCharactersInsidePhNode: ++ return ++ self.fail('Should have gotten exception') ++ ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/node/misc.py b/tools/grit/grit/node/misc.py new file mode 100644 -index 0000000000..caa0cb4e3b +index 0000000000..2d8b06d6a5 --- /dev/null -+++ b/tools/clang/plugins/tests/inline_ctor.txt -@@ -0,0 +1,8 @@ -+In file included from inline_ctor.cpp:5: -+./inline_ctor.h:13:3: warning: [chromium-style] Complex constructor has an inlined body. -+ InlineCtorsArentOKInHeader() {} -+ ^ -+./inline_ctor.h:14:3: warning: [chromium-style] Complex destructor has an inline body. -+ ~InlineCtorsArentOKInHeader() {} -+ ^ -+2 warnings generated. -diff --git a/tools/clang/plugins/tests/missing_ctor.cpp b/tools/clang/plugins/tests/missing_ctor.cpp -new file mode 100644 -index 0000000000..8ee2fb2ac8 ---- /dev/null -+++ b/tools/clang/plugins/tests/missing_ctor.cpp -@@ -0,0 +1,23 @@ -+// Copyright (c) 2011 The Chromium Authors. All rights reserved. -+// Use of this source code is governed by a BSD-style license that can be -+// found in the LICENSE file. ++++ b/tools/grit/grit/node/misc.py +@@ -0,0 +1,707 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+#include "missing_ctor.h" ++"""Miscellaneous node types. ++""" + -+#include <string> -+#include <vector> ++from __future__ import print_function + -+// We don't warn on classes that use default ctors in cpp files. -+class MissingInCPPOK { -+ public: ++import os.path ++import re ++import sys + -+ private: -+ std::vector<int> one_; -+ std::vector<std::string> two_; -+}; ++import six ++ ++from grit import constants ++from grit import exception ++from grit import util ++from grit.extern import FP ++from grit.node import base ++from grit.node import message ++from grit.node import node_io ++ ++ ++# Python 3 doesn't have long() as int() works everywhere. But we really do need ++# the long() behavior on Python 2 as our ids are much too large for int(). ++try: ++ long ++except NameError: ++ long = int ++ ++ ++# RTL languages ++# TODO(jennyz): remove this fixed set of RTL language array ++# now that generic expand_variable code exists. ++_RTL_LANGS = ( ++ 'ar', # Arabic ++ 'fa', # Farsi ++ 'iw', # Hebrew ++ 'ks', # Kashmiri ++ 'ku', # Kurdish ++ 'ps', # Pashto ++ 'ur', # Urdu ++ 'yi', # Yiddish ++) ++ ++ ++def _ReadFirstIdsFromFile(filename, defines): ++ """Read the starting resource id values from |filename|. We also ++ expand variables of the form <(FOO) based on defines passed in on ++ the command line. ++ ++ Returns a tuple, the absolute path of SRCDIR followed by the ++ first_ids dictionary. ++ """ ++ first_ids_dict = eval(util.ReadFile(filename, 'utf-8')) ++ src_root_dir = os.path.abspath(os.path.join(os.path.dirname(filename), ++ first_ids_dict['SRCDIR'])) ++ ++ def ReplaceVariable(matchobj): ++ for key, value in defines.items(): ++ if matchobj.group(1) == key: ++ return value ++ return '' ++ ++ renames = [] ++ for grd_filename in first_ids_dict: ++ new_grd_filename = re.sub(r'<\(([A-Za-z_]+)\)', ReplaceVariable, ++ grd_filename) ++ if new_grd_filename != grd_filename: ++ abs_grd_filename = os.path.abspath(new_grd_filename) ++ if abs_grd_filename[:len(src_root_dir)] != src_root_dir: ++ new_grd_filename = os.path.basename(abs_grd_filename) ++ else: ++ new_grd_filename = abs_grd_filename[len(src_root_dir) + 1:] ++ new_grd_filename = new_grd_filename.replace('\\', '/') ++ renames.append((grd_filename, new_grd_filename)) ++ ++ for grd_filename, new_grd_filename in renames: ++ first_ids_dict[new_grd_filename] = first_ids_dict[grd_filename] ++ del(first_ids_dict[grd_filename]) ++ ++ return (src_root_dir, first_ids_dict) ++ ++ ++def _ComputeIds(root, predetermined_tids): ++ """Returns a dict of textual id -> numeric id for all nodes in root. ++ ++ IDs are mostly assigned sequentially, but will vary based on: ++ * first_id node attribute (from first_ids_file) ++ * hash of textual id (if not first_id is defined) ++ * offset node attribute ++ * whether the textual id matches a system id ++ * whether the node generates its own ID via GetId() ++ ++ Args: ++ predetermined_tids: Dict of textual id -> numeric id to use in return dict. ++ """ ++ from grit.node import empty, include, misc, structure ++ ++ ids = {} # Maps numeric id to textual id ++ tids = {} # Maps textual id to numeric id ++ id_reasons = {} # Maps numeric id to text id and a human-readable explanation ++ group = None ++ last_id = None ++ predetermined_ids = {value: key ++ for key, value in predetermined_tids.items()} ++ ++ for item in root: ++ if isinstance(item, empty.GroupingNode): ++ # Note: this won't work if any GroupingNode can be contained inside ++ # another. ++ group = item ++ last_id = None ++ continue ++ ++ assert not item.GetTextualIds() or isinstance(item, ++ (include.IncludeNode, message.MessageNode, ++ misc.IdentifierNode, structure.StructureNode)) ++ ++ # Resources that use the RES protocol don't need ++ # any numerical ids generated, so we skip them altogether. ++ # This is accomplished by setting the flag 'generateid' to false ++ # in the GRD file. ++ if item.attrs.get('generateid', 'true') == 'false': ++ continue ++ ++ for tid in item.GetTextualIds(): ++ if util.SYSTEM_IDENTIFIERS.match(tid): ++ # Don't emit a new ID for predefined IDs ++ continue ++ ++ if tid in tids: ++ continue ++ ++ if predetermined_tids and tid in predetermined_tids: ++ id = predetermined_tids[tid] ++ reason = "from predetermined_tids map" ++ ++ # Some identifier nodes can provide their own id, ++ # and we use that id in the generated header in that case. ++ elif hasattr(item, 'GetId') and item.GetId(): ++ id = long(item.GetId()) ++ reason = 'returned by GetId() method' ++ ++ elif ('offset' in item.attrs and group and ++ group.attrs.get('first_id', '') != ''): ++ offset_text = item.attrs['offset'] ++ parent_text = group.attrs['first_id'] ++ ++ try: ++ offset_id = long(offset_text) ++ except ValueError: ++ offset_id = tids[offset_text] ++ ++ try: ++ parent_id = long(parent_text) ++ except ValueError: ++ parent_id = tids[parent_text] ++ ++ id = parent_id + offset_id ++ reason = 'first_id %d + offset %d' % (parent_id, offset_id) ++ ++ # We try to allocate IDs sequentially for blocks of items that might ++ # be related, for instance strings in a stringtable (as their IDs might be ++ # used e.g. as IDs for some radio buttons, in which case the IDs must ++ # be sequential). ++ # ++ # We do this by having the first item in a section store its computed ID ++ # (computed from a fingerprint) in its parent object. Subsequent children ++ # of the same parent will then try to get IDs that sequentially follow ++ # the currently stored ID (on the parent) and increment it. ++ elif last_id is None: ++ # First check if the starting ID is explicitly specified by the parent. ++ if group and group.attrs.get('first_id', '') != '': ++ id = long(group.attrs['first_id']) ++ reason = "from parent's first_id attribute" ++ else: ++ # Automatically generate the ID based on the first clique from the ++ # first child of the first child node of our parent (i.e. when we ++ # first get to this location in the code). ++ ++ # According to ++ # http://msdn.microsoft.com/en-us/library/t2zechd4(VS.71).aspx ++ # the safe usable range for resource IDs in Windows is from decimal ++ # 101 to 0x7FFF. ++ ++ id = FP.UnsignedFingerPrint(tid) ++ id = id % (0x7FFF - 101) + 101 ++ reason = 'chosen by random fingerprint -- use first_id to override' ++ ++ last_id = id ++ else: ++ id = last_id = last_id + 1 ++ reason = 'sequentially assigned' ++ ++ reason = "%s (%s)" % (tid, reason) ++ # Don't fail when 'offset' is specified, as the base and the 0th ++ # offset will have the same ID. ++ if id in id_reasons and not 'offset' in item.attrs: ++ raise exception.IdRangeOverlap('ID %d was assigned to both %s and %s.' ++ % (id, id_reasons[id], reason)) ++ ++ if id < 101: ++ print('WARNING: Numeric resource IDs should be greater than 100 to\n' ++ 'avoid conflicts with system-defined resource IDs.') ++ ++ if tid not in predetermined_tids and id in predetermined_ids: ++ raise exception.IdRangeOverlap('ID %d overlaps between %s and %s' ++ % (id, tid, predetermined_ids[tid])) ++ ++ ids[id] = tid ++ tids[tid] = id ++ id_reasons[id] = reason ++ ++ return tids ++ ++class SplicingNode(base.Node): ++ """A node whose children should be considered to be at the same level as ++ its siblings for most purposes. This includes <if> and <part> nodes. ++ """ ++ ++ def _IsValidChild(self, child): ++ assert self.parent, '<%s> node should never be root.' % self.name ++ if isinstance(child, SplicingNode): ++ return True # avoid O(n^2) behavior ++ return self.parent._IsValidChild(child) ++ ++ ++class IfNode(SplicingNode): ++ """A node for conditional inclusion of resources. ++ """ ++ ++ def MandatoryAttributes(self): ++ return ['expr'] ++ ++ def _IsValidChild(self, child): ++ return (isinstance(child, (ThenNode, ElseNode)) or ++ super(IfNode, self)._IsValidChild(child)) ++ ++ def EndParsing(self): ++ children = self.children ++ self.if_then_else = False ++ if any(isinstance(node, (ThenNode, ElseNode)) for node in children): ++ if (len(children) != 2 or not isinstance(children[0], ThenNode) or ++ not isinstance(children[1], ElseNode)): ++ raise exception.UnexpectedChild( ++ '<if> element must be <if><then>...</then><else>...</else></if>') ++ self.if_then_else = True ++ ++ def ActiveChildren(self): ++ cond = self.EvaluateCondition(self.attrs['expr']) ++ if self.if_then_else: ++ return self.children[0 if cond else 1].ActiveChildren() ++ else: ++ # Equivalent to having all children inside <then> with an empty <else> ++ return super(IfNode, self).ActiveChildren() if cond else [] ++ ++ ++class ThenNode(SplicingNode): ++ """A <then> node. Can only appear directly inside an <if> node.""" ++ pass ++ ++ ++class ElseNode(SplicingNode): ++ """An <else> node. Can only appear directly inside an <if> node.""" ++ pass ++ ++ ++class PartNode(SplicingNode): ++ """A node for inclusion of sub-grd (*.grp) files. ++ """ ++ ++ def __init__(self): ++ super(PartNode, self).__init__() ++ self.started_inclusion = False ++ ++ def MandatoryAttributes(self): ++ return ['file'] ++ ++ def _IsValidChild(self, child): ++ return self.started_inclusion and super(PartNode, self)._IsValidChild(child) ++ ++ ++class ReleaseNode(base.Node): ++ """The <release> element.""" ++ ++ def _IsValidChild(self, child): ++ from grit.node import empty ++ return isinstance(child, (empty.IncludesNode, empty.MessagesNode, ++ empty.StructuresNode, empty.IdentifiersNode)) ++ ++ def _IsValidAttribute(self, name, value): ++ return ( ++ (name == 'seq' and int(value) <= self.GetRoot().GetCurrentRelease()) or ++ name == 'allow_pseudo' ++ ) ++ ++ def MandatoryAttributes(self): ++ return ['seq'] ++ ++ def DefaultAttributes(self): ++ return { 'allow_pseudo' : 'true' } ++ ++ ++class GritNode(base.Node): ++ """The <grit> root element.""" ++ ++ def __init__(self): ++ super(GritNode, self).__init__() ++ self.output_language = '' ++ self.defines = {} ++ self.substituter = None ++ self.target_platform = sys.platform ++ self.whitelist_support = False ++ self._predetermined_ids_file = None ++ self._id_map = None # Dict of textual_id -> numeric_id. ++ ++ def _IsValidChild(self, child): ++ from grit.node import empty ++ return isinstance(child, (ReleaseNode, empty.TranslationsNode, ++ empty.OutputsNode)) ++ ++ def _IsValidAttribute(self, name, value): ++ if name not in ['base_dir', 'first_ids_file', 'source_lang_id', ++ 'latest_public_release', 'current_release', ++ 'enc_check', 'tc_project', 'grit_version', ++ 'output_all_resource_defines']: ++ return False ++ if name in ['latest_public_release', 'current_release'] and value.strip( ++ '0123456789') != '': ++ return False ++ return True ++ ++ def MandatoryAttributes(self): ++ return ['latest_public_release', 'current_release'] ++ ++ def DefaultAttributes(self): ++ return { ++ 'base_dir' : '.', ++ 'first_ids_file': '', ++ 'grit_version': 1, ++ 'source_lang_id' : 'en', ++ 'enc_check' : constants.ENCODING_CHECK, ++ 'tc_project' : 'NEED_TO_SET_tc_project_ATTRIBUTE', ++ } ++ ++ def EndParsing(self): ++ super(GritNode, self).EndParsing() ++ if (int(self.attrs['latest_public_release']) ++ > int(self.attrs['current_release'])): ++ raise exception.Parsing('latest_public_release cannot have a greater ' ++ 'value than current_release') ++ ++ self.ValidateUniqueIds() ++ ++ # Add the encoding check if it's not present (should ensure that it's always ++ # present in all .grd files generated by GRIT). If it's present, assert if ++ # it's not correct. ++ if 'enc_check' not in self.attrs or self.attrs['enc_check'] == '': ++ self.attrs['enc_check'] = constants.ENCODING_CHECK ++ else: ++ assert self.attrs['enc_check'] == constants.ENCODING_CHECK, ( ++ 'Are you sure your .grd file is in the correct encoding (UTF-8)?') ++ ++ def ValidateUniqueIds(self): ++ """Validate that 'name' attribute is unique in all nodes in this tree ++ except for nodes that are children of <if> nodes. ++ """ ++ unique_names = {} ++ duplicate_names = [] ++ # To avoid false positives from mutually exclusive <if> clauses, check ++ # against whatever the output condition happens to be right now. ++ # TODO(benrg): do something better. ++ for node in self.ActiveDescendants(): ++ if node.attrs.get('generateid', 'true') == 'false': ++ continue # Duplication not relevant in that case ++ ++ for node_id in node.GetTextualIds(): ++ if util.SYSTEM_IDENTIFIERS.match(node_id): ++ continue # predefined IDs are sometimes used more than once ++ ++ if node_id in unique_names and node_id not in duplicate_names: ++ duplicate_names.append(node_id) ++ unique_names[node_id] = 1 ++ ++ if len(duplicate_names): ++ raise exception.DuplicateKey(', '.join(duplicate_names)) ++ ++ ++ def GetCurrentRelease(self): ++ """Returns the current release number.""" ++ return int(self.attrs['current_release']) ++ ++ def GetLatestPublicRelease(self): ++ """Returns the latest public release number.""" ++ return int(self.attrs['latest_public_release']) ++ ++ def GetSourceLanguage(self): ++ """Returns the language code of the source language.""" ++ return self.attrs['source_lang_id'] ++ ++ def GetTcProject(self): ++ """Returns the name of this project in the TranslationConsole, or ++ 'NEED_TO_SET_tc_project_ATTRIBUTE' if it is not defined.""" ++ return self.attrs['tc_project'] ++ ++ def SetOwnDir(self, dir): ++ """Informs the 'grit' element of the directory the file it is in resides. ++ This allows it to calculate relative paths from the input file, which is ++ what we desire (rather than from the current path). ++ ++ Args: ++ dir: r'c:\bla' ++ ++ Return: ++ None ++ """ ++ assert dir ++ self.base_dir = os.path.normpath(os.path.join(dir, self.attrs['base_dir'])) ++ ++ def GetBaseDir(self): ++ """Returns the base directory, relative to the working directory. To get ++ the base directory as set in the .grd file, use GetOriginalBaseDir() ++ """ ++ if hasattr(self, 'base_dir'): ++ return self.base_dir ++ else: ++ return self.GetOriginalBaseDir() ++ ++ def GetOriginalBaseDir(self): ++ """Returns the base directory, as set in the .grd file. ++ """ ++ return self.attrs['base_dir'] ++ ++ def IsWhitelistSupportEnabled(self): ++ return self.whitelist_support ++ ++ def SetWhitelistSupportEnabled(self, whitelist_support): ++ self.whitelist_support = whitelist_support ++ ++ def GetInputFiles(self): ++ """Returns the list of files that are read to produce the output.""" ++ ++ # Importing this here avoids a circular dependency in the imports. ++ # pylint: disable-msg=C6204 ++ from grit.node import include ++ from grit.node import misc ++ from grit.node import structure ++ from grit.node import variant ++ ++ # Check if the input is required for any output configuration. ++ input_files = set() ++ # Collect even inactive PartNodes since they affect ID assignments. ++ for node in self: ++ if isinstance(node, misc.PartNode): ++ input_files.add(self.ToRealPath(node.GetInputPath())) ++ ++ old_output_language = self.output_language ++ for lang, ctx, fallback in self.GetConfigurations(): ++ self.SetOutputLanguage(lang or self.GetSourceLanguage()) ++ self.SetOutputContext(ctx) ++ self.SetFallbackToDefaultLayout(fallback) ++ ++ for node in self.ActiveDescendants(): ++ if isinstance(node, (node_io.FileNode, include.IncludeNode, ++ structure.StructureNode, variant.SkeletonNode)): ++ input_path = node.GetInputPath() ++ if input_path is not None: ++ input_files.add(self.ToRealPath(input_path)) ++ ++ # If it's a flattened node, grab inlined resources too. ++ if ((node.name == 'structure' or node.name == 'include') ++ and node.attrs['flattenhtml'] == 'true'): ++ if node.name == 'structure': ++ node.RunPreSubstitutionGatherer() ++ input_files.update(node.GetHtmlResourceFilenames()) ++ ++ self.SetOutputLanguage(old_output_language) ++ return sorted(input_files) ++ ++ def GetFirstIdsFile(self): ++ """Returns a usable path to the first_ids file, if set, otherwise ++ returns None. ++ ++ The first_ids_file attribute is by default relative to the ++ base_dir of the .grd file, but may be prefixed by GRIT_DIR/, ++ which makes it relative to the directory of grit.py ++ (e.g. GRIT_DIR/../gritsettings/resource_ids). ++ """ ++ if not self.attrs['first_ids_file']: ++ return None ++ ++ path = self.attrs['first_ids_file'] ++ GRIT_DIR_PREFIX = 'GRIT_DIR' ++ if (path.startswith(GRIT_DIR_PREFIX) ++ and path[len(GRIT_DIR_PREFIX)] in ['/', '\\']): ++ return util.PathFromRoot(path[len(GRIT_DIR_PREFIX) + 1:]) ++ else: ++ return self.ToRealPath(path) ++ ++ def GetOutputFiles(self): ++ """Returns the list of <output> nodes that are descendants of this node's ++ <outputs> child and are not enclosed by unsatisfied <if> conditionals. ++ """ ++ for child in self.children: ++ if child.name == 'outputs': ++ return [node for node in child.ActiveDescendants() ++ if node.name == 'output'] ++ raise exception.MissingElement() ++ ++ def GetConfigurations(self): ++ """Returns the distinct (language, context, fallback_to_default_layout) ++ triples from the output nodes. ++ """ ++ return set((n.GetLanguage(), n.GetContext(), n.GetFallbackToDefaultLayout()) ++ for n in self.GetOutputFiles()) ++ ++ def GetSubstitutionMessages(self): ++ """Returns the list of <message sub_variable="true"> nodes.""" ++ return [n for n in self.ActiveDescendants() ++ if isinstance(n, message.MessageNode) ++ and n.attrs['sub_variable'] == 'true'] ++ ++ def SetOutputLanguage(self, output_language): ++ """Set the output language. Prepares substitutions. ++ ++ The substitutions are reset every time the language is changed. ++ They include messages designated as variables, and language codes for html ++ and rc files. ++ ++ Args: ++ output_language: a two-letter language code (eg: 'en', 'ar'...) or '' ++ """ ++ if not output_language: ++ # We do not specify the output language for .grh files, ++ # so we get an empty string as the default. ++ # The value should match grit.clique.MessageClique.source_language. ++ output_language = self.GetSourceLanguage() ++ if output_language != self.output_language: ++ self.output_language = output_language ++ self.substituter = None # force recalculate ++ ++ def SetOutputContext(self, output_context): ++ self.output_context = output_context ++ self.substituter = None # force recalculate ++ ++ def SetFallbackToDefaultLayout(self, fallback_to_default_layout): ++ self.fallback_to_default_layout = fallback_to_default_layout ++ self.substituter = None # force recalculate ++ ++ def SetDefines(self, defines): ++ self.defines = defines ++ self.substituter = None # force recalculate ++ ++ def SetTargetPlatform(self, target_platform): ++ self.target_platform = target_platform ++ ++ def GetSubstituter(self): ++ if self.substituter is None: ++ self.substituter = util.Substituter() ++ self.substituter.AddMessages(self.GetSubstitutionMessages(), ++ self.output_language) ++ if self.output_language in _RTL_LANGS: ++ direction = 'dir="RTL"' ++ else: ++ direction = 'dir="LTR"' ++ self.substituter.AddSubstitutions({ ++ 'GRITLANGCODE': self.output_language, ++ 'GRITDIR': direction, ++ }) ++ from grit.format import rc # avoid circular dep ++ rc.RcSubstitutions(self.substituter, self.output_language) ++ return self.substituter ++ ++ def AssignFirstIds(self, filename_or_stream, defines): ++ """Assign first ids to each grouping node based on values from the ++ first_ids file (if specified on the <grit> node). ++ """ ++ assert self._id_map is None, 'AssignFirstIds() after InitializeIds()' ++ # If the input is a stream, then we're probably in a unit test and ++ # should skip this step. ++ if not isinstance(filename_or_stream, six.string_types): ++ return ++ ++ # Nothing to do if the first_ids_filename attribute isn't set. ++ first_ids_filename = self.GetFirstIdsFile() ++ if not first_ids_filename: ++ return ++ ++ src_root_dir, first_ids = _ReadFirstIdsFromFile(first_ids_filename, ++ defines) ++ from grit.node import empty ++ for node in self.Preorder(): ++ if isinstance(node, empty.GroupingNode): ++ abs_filename = os.path.abspath(filename_or_stream) ++ if abs_filename[:len(src_root_dir)] != src_root_dir: ++ filename = os.path.basename(filename_or_stream) ++ else: ++ filename = abs_filename[len(src_root_dir) + 1:] ++ filename = filename.replace('\\', '/') ++ ++ if node.attrs['first_id'] != '': ++ raise Exception( ++ "Don't set the first_id attribute when using the first_ids_file " ++ "attribute on the <grit> node, update %s instead." % ++ first_ids_filename) ++ ++ try: ++ id_list = first_ids[filename][node.name] ++ except KeyError as e: ++ print('-' * 78) ++ print('Resource id not set for %s (%s)!' % (filename, node.name)) ++ print('Please update %s to include an entry for %s. See the ' ++ 'comments in resource_ids for information on why you need to ' ++ 'update that file.' % (first_ids_filename, filename)) ++ print('-' * 78) ++ raise e ++ ++ try: ++ node.attrs['first_id'] = str(id_list.pop(0)) ++ except IndexError as e: ++ raise Exception('Please update %s and add a first id for %s (%s).' ++ % (first_ids_filename, filename, node.name)) ++ ++ def GetIdMap(self): ++ '''Return a dictionary mapping textual ids to numeric ids.''' ++ return self._id_map ++ ++ def SetPredeterminedIdsFile(self, predetermined_ids_file): ++ assert self._id_map is None, ( ++ 'SetPredeterminedIdsFile() after InitializeIds()') ++ self._predetermined_ids_file = predetermined_ids_file ++ ++ def InitializeIds(self): ++ '''Initializes the text ID -> numeric ID mapping.''' ++ predetermined_id_map = {} ++ if self._predetermined_ids_file: ++ with open(self._predetermined_ids_file) as f: ++ for line in f: ++ tid, nid = line.split() ++ predetermined_id_map[tid] = int(nid) ++ self._id_map = _ComputeIds(self, predetermined_id_map) ++ ++ def RunGatherers(self, debug=False): ++ '''Call RunPreSubstitutionGatherer() on every node of the tree, then apply ++ substitutions, then call RunPostSubstitutionGatherer() on every node. ++ ++ The substitutions step requires that the output language has been set. ++ Locally, get the Substitution messages and add them to the substituter. ++ Also add substitutions for language codes in the Rc. ++ ++ Args: ++ debug: will print information while running gatherers. ++ ''' ++ for node in self.ActiveDescendants(): ++ if hasattr(node, 'RunPreSubstitutionGatherer'): ++ with node: ++ node.RunPreSubstitutionGatherer(debug=debug) ++ ++ assert self.output_language ++ self.SubstituteMessages(self.GetSubstituter()) ++ ++ for node in self.ActiveDescendants(): ++ if hasattr(node, 'RunPostSubstitutionGatherer'): ++ with node: ++ node.RunPostSubstitutionGatherer(debug=debug) ++ ++ ++class IdentifierNode(base.Node): ++ """A node for specifying identifiers that should appear in the resource ++ header file, and be unique amongst all other resource identifiers, but don't ++ have any other attributes or reference any resources. ++ """ ++ ++ def MandatoryAttributes(self): ++ return ['name'] ++ ++ def DefaultAttributes(self): ++ return { 'comment' : '', 'id' : '', 'systemid': 'false' } ++ ++ def GetId(self): ++ """Returns the id of this identifier if it has one, None otherwise ++ """ ++ if 'id' in self.attrs: ++ return self.attrs['id'] ++ return None ++ ++ def EndParsing(self): ++ """Handles system identifiers.""" ++ super(IdentifierNode, self).EndParsing() ++ if self.attrs['systemid'] == 'true': ++ util.SetupSystemIdentifiers((self.attrs['name'],)) ++ ++ @staticmethod ++ def Construct(parent, name, id, comment, systemid='false'): ++ """Creates a new node which is a child of 'parent', with attributes set ++ by parameters of the same name. ++ """ ++ node = IdentifierNode() ++ node.StartParsing('identifier', parent) ++ node.HandleAttribute('name', name) ++ node.HandleAttribute('id', id) ++ node.HandleAttribute('comment', comment) ++ node.HandleAttribute('systemid', systemid) ++ node.EndParsing() ++ return node +diff --git a/tools/grit/grit/node/misc_unittest.py b/tools/grit/grit/node/misc_unittest.py +new file mode 100644 +index 0000000000..c192b096f4 +--- /dev/null ++++ b/tools/grit/grit/node/misc_unittest.py +@@ -0,0 +1,590 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for misc.GritNode''' ++ ++from __future__ import print_function ++ ++import contextlib ++import os ++import sys ++import tempfile ++import unittest ++ ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++from six import StringIO ++ ++from grit import grd_reader ++import grit.exception ++from grit import util ++from grit.format import rc ++from grit.format import rc_header ++from grit.node import misc ++ ++ ++@contextlib.contextmanager ++def _MakeTempPredeterminedIdsFile(content): ++ """Write the |content| string to a temporary file. ++ ++ The temporary file must be deleted by the caller. ++ ++ Example: ++ with _MakeTempPredeterminedIdsFile('foo') as path: ++ ... ++ os.remove(path) ++ ++ Args: ++ content: The string to write. ++ ++ Yields: ++ The name of the temporary file. ++ """ ++ with tempfile.NamedTemporaryFile(mode='w', delete=False) as f: ++ f.write(content) ++ f.flush() ++ f.close() ++ yield f.name ++ ++ ++class GritNodeUnittest(unittest.TestCase): ++ def testUniqueNameAttribute(self): ++ try: ++ restree = grd_reader.Parse( ++ util.PathFromRoot('grit/testdata/duplicate-name-input.xml')) ++ self.fail('Expected parsing exception because of duplicate names.') ++ except grit.exception.Parsing: ++ pass # Expected case ++ ++ def testReadFirstIdsFromFile(self): ++ test_resource_ids = os.path.join(os.path.dirname(__file__), '..', ++ 'testdata', 'resource_ids') ++ base_dir = os.path.dirname(test_resource_ids) ++ ++ src_dir, id_dict = misc._ReadFirstIdsFromFile( ++ test_resource_ids, ++ { ++ 'FOO': os.path.join(base_dir, 'bar'), ++ 'SHARED_INTERMEDIATE_DIR': os.path.join(base_dir, ++ 'out/Release/obj/gen'), ++ }) ++ self.assertEqual({}, id_dict.get('bar/file.grd', None)) ++ self.assertEqual({}, ++ id_dict.get('out/Release/obj/gen/devtools/devtools.grd', None)) ++ ++ src_dir, id_dict = misc._ReadFirstIdsFromFile( ++ test_resource_ids, ++ { ++ 'SHARED_INTERMEDIATE_DIR': '/outside/src_dir', ++ }) ++ self.assertEqual({}, id_dict.get('devtools.grd', None)) ++ ++ # Verifies that GetInputFiles() returns the correct list of files ++ # corresponding to ChromeScaledImage nodes when assets are missing. ++ def testGetInputFilesChromeScaledImage(self): ++ chrome_html_path = util.PathFromRoot('grit/testdata/chrome_html.html') ++ xml = '''<?xml version="1.0" encoding="utf-8"?> ++ <grit latest_public_release="0" current_release="1"> ++ <outputs> ++ <output filename="default.pak" type="data_package" context="default_100_percent" /> ++ <output filename="special.pak" type="data_package" context="special_100_percent" fallback_to_default_layout="false" /> ++ </outputs> ++ <release seq="1"> ++ <structures fallback_to_low_resolution="true"> ++ <structure type="chrome_scaled_image" name="IDR_A" file="a.png" /> ++ <structure type="chrome_scaled_image" name="IDR_B" file="b.png" /> ++ <structure type="chrome_html" name="HTML_FILE1" file="%s" flattenhtml="true" /> ++ </structures> ++ </release> ++ </grit>''' % chrome_html_path ++ ++ grd = grd_reader.Parse(StringIO(xml), ++ util.PathFromRoot('grit/testdata')) ++ expected = ['chrome_html.html', 'default_100_percent/a.png', ++ 'default_100_percent/b.png', 'included_sample.html', ++ 'special_100_percent/a.png'] ++ actual = [os.path.relpath(path, util.PathFromRoot('grit/testdata')) for ++ path in grd.GetInputFiles()] ++ # Convert path separator for Windows paths. ++ actual = [path.replace('\\', '/') for path in actual] ++ self.assertEquals(expected, actual) ++ ++ # Verifies that GetInputFiles() returns the correct list of files ++ # when files include other files. ++ def testGetInputFilesFromIncludes(self): ++ chrome_html_path = util.PathFromRoot('grit/testdata/chrome_html.html') ++ xml = '''<?xml version="1.0" encoding="utf-8"?> ++ <grit latest_public_release="0" current_release="1"> ++ <outputs> ++ <output filename="default.pak" type="data_package" context="default_100_percent" /> ++ <output filename="special.pak" type="data_package" context="special_100_percent" fallback_to_default_layout="false" /> ++ </outputs> ++ <release seq="1"> ++ <includes> ++ <include name="IDR_TESTDATA_CHROME_HTML" file="%s" flattenhtml="true" ++ allowexternalscript="true" type="BINDATA" /> ++ </includes> ++ </release> ++ </grit>''' % chrome_html_path ++ ++ grd = grd_reader.Parse(StringIO(xml), util.PathFromRoot('grit/testdata')) ++ expected = ['chrome_html.html', 'included_sample.html'] ++ actual = [os.path.relpath(path, util.PathFromRoot('grit/testdata')) for ++ path in grd.GetInputFiles()] ++ # Convert path separator for Windows paths. ++ actual = [path.replace('\\', '/') for path in actual] ++ self.assertEquals(expected, actual) ++ ++ def testNonDefaultEntry(self): ++ grd = util.ParseGrdForUnittest(''' ++ <messages> ++ <message name="IDS_A" desc="foo">bar</message> ++ <if expr="lang == 'fr'"> ++ <message name="IDS_B" desc="foo">bar</message> ++ </if> ++ </messages>''') ++ grd.SetOutputLanguage('fr') ++ output = ''.join(rc_header.Format(grd, 'fr', '.')) ++ self.assertIn('#define IDS_A 2378\n#define IDS_B 2379', output) ++ ++ def testExplicitFirstIdOverlaps(self): ++ # second first_id will overlap preexisting range ++ self.assertRaises(grit.exception.IdRangeOverlap, ++ util.ParseGrdForUnittest, ''' ++ <includes first_id="300" comment="bingo"> ++ <include type="gif" name="ID_LOGO" file="images/logo.gif" /> ++ <include type="gif" name="ID_LOGO2" file="images/logo2.gif" /> ++ </includes> ++ <messages first_id="301"> ++ <message name="IDS_GREETING" desc="Printed to greet the currently logged in user"> ++ Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today? ++ </message> ++ <message name="IDS_SMURFGEBURF">Frubegfrums</message> ++ </messages>''') ++ ++ def testImplicitOverlapsPreexisting(self): ++ # second message in <messages> will overlap preexisting range ++ self.assertRaises(grit.exception.IdRangeOverlap, ++ util.ParseGrdForUnittest, ''' ++ <includes first_id="301" comment="bingo"> ++ <include type="gif" name="ID_LOGO" file="images/logo.gif" /> ++ <include type="gif" name="ID_LOGO2" file="images/logo2.gif" /> ++ </includes> ++ <messages first_id="300"> ++ <message name="IDS_GREETING" desc="Printed to greet the currently logged in user"> ++ Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today? ++ </message> ++ <message name="IDS_SMURFGEBURF">Frubegfrums</message> ++ </messages>''') ++ ++ def testPredeterminedIds(self): ++ with _MakeTempPredeterminedIdsFile('IDS_A 101\nIDS_B 102') as ids_file: ++ grd = util.ParseGrdForUnittest(''' ++ <includes first_id="300" comment="bingo"> ++ <include type="gif" name="IDS_B" file="images/logo.gif" /> ++ </includes> ++ <messages first_id="10000"> ++ <message name="IDS_GREETING" desc="Printed to greet the currently logged in user"> ++ Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today? ++ </message> ++ <message name="IDS_A"> ++ Bongo! ++ </message> ++ </messages>''', predetermined_ids_file=ids_file) ++ output = rc_header.FormatDefines(grd) ++ self.assertEqual(('#define IDS_B 102\n' ++ '#define IDS_GREETING 10000\n' ++ '#define IDS_A 101\n'), ''.join(output)) ++ os.remove(ids_file) ++ ++ def testPredeterminedIdsOverlap(self): ++ with _MakeTempPredeterminedIdsFile('ID_LOGO 10000') as ids_file: ++ self.assertRaises(grit.exception.IdRangeOverlap, ++ util.ParseGrdForUnittest, ''' ++ <includes first_id="300" comment="bingo"> ++ <include type="gif" name="ID_LOGO" file="images/logo.gif" /> ++ </includes> ++ <messages first_id="10000"> ++ <message name="IDS_GREETING" desc="Printed to greet the currently logged in user"> ++ Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today? ++ </message> ++ <message name="IDS_BONGO"> ++ Bongo! ++ </message> ++ </messages>''', predetermined_ids_file=ids_file) ++ os.remove(ids_file) ++ ++ ++class IfNodeUnittest(unittest.TestCase): ++ def testIffyness(self): ++ grd = grd_reader.Parse(StringIO(''' ++ <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <release seq="3"> ++ <messages> ++ <if expr="'bingo' in defs"> ++ <message name="IDS_BINGO"> ++ Bingo! ++ </message> ++ </if> ++ <if expr="'hello' in defs"> ++ <message name="IDS_HELLO"> ++ Hello! ++ </message> ++ </if> ++ <if expr="lang == 'fr' or 'FORCE_FRENCH' in defs"> ++ <message name="IDS_HELLO" internal_comment="French version"> ++ Good morning ++ </message> ++ </if> ++ <if expr="is_win"> ++ <message name="IDS_ISWIN">is_win</message> ++ </if> ++ </messages> ++ </release> ++ </grit>'''), dir='.') ++ ++ messages_node = grd.children[0].children[0] ++ bingo_message = messages_node.children[0].children[0] ++ hello_message = messages_node.children[1].children[0] ++ french_message = messages_node.children[2].children[0] ++ is_win_message = messages_node.children[3].children[0] ++ ++ self.assertTrue(bingo_message.name == 'message') ++ self.assertTrue(hello_message.name == 'message') ++ self.assertTrue(french_message.name == 'message') ++ ++ grd.SetOutputLanguage('fr') ++ grd.SetDefines({'hello': '1'}) ++ active = set(grd.ActiveDescendants()) ++ self.failUnless(bingo_message not in active) ++ self.failUnless(hello_message in active) ++ self.failUnless(french_message in active) ++ ++ grd.SetOutputLanguage('en') ++ grd.SetDefines({'bingo': 1}) ++ active = set(grd.ActiveDescendants()) ++ self.failUnless(bingo_message in active) ++ self.failUnless(hello_message not in active) ++ self.failUnless(french_message not in active) ++ ++ grd.SetOutputLanguage('en') ++ grd.SetDefines({'FORCE_FRENCH': '1', 'bingo': '1'}) ++ active = set(grd.ActiveDescendants()) ++ self.failUnless(bingo_message in active) ++ self.failUnless(hello_message not in active) ++ self.failUnless(french_message in active) ++ ++ grd.SetOutputLanguage('en') ++ grd.SetDefines({}) ++ self.failUnless(grd.target_platform == sys.platform) ++ grd.SetTargetPlatform('darwin') ++ active = set(grd.ActiveDescendants()) ++ self.failUnless(is_win_message not in active) ++ grd.SetTargetPlatform('win32') ++ active = set(grd.ActiveDescendants()) ++ self.failUnless(is_win_message in active) ++ ++ def testElsiness(self): ++ grd = util.ParseGrdForUnittest(''' ++ <messages> ++ <if expr="True"> ++ <then> <message name="IDS_YES1"></message> </then> ++ <else> <message name="IDS_NO1"></message> </else> ++ </if> ++ <if expr="True"> ++ <then> <message name="IDS_YES2"></message> </then> ++ <else> </else> ++ </if> ++ <if expr="True"> ++ <then> </then> ++ <else> <message name="IDS_NO2"></message> </else> ++ </if> ++ <if expr="True"> ++ <then> </then> ++ <else> </else> ++ </if> ++ <if expr="False"> ++ <then> <message name="IDS_NO3"></message> </then> ++ <else> <message name="IDS_YES3"></message> </else> ++ </if> ++ <if expr="False"> ++ <then> <message name="IDS_NO4"></message> </then> ++ <else> </else> ++ </if> ++ <if expr="False"> ++ <then> </then> ++ <else> <message name="IDS_YES4"></message> </else> ++ </if> ++ <if expr="False"> ++ <then> </then> ++ <else> </else> ++ </if> ++ </messages>''') ++ included = [msg.attrs['name'] for msg in grd.ActiveDescendants() ++ if msg.name == 'message'] ++ self.assertEqual(['IDS_YES1', 'IDS_YES2', 'IDS_YES3', 'IDS_YES4'], included) ++ ++ def testIffynessWithOutputNodes(self): ++ grd = grd_reader.Parse(StringIO(''' ++ <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <outputs> ++ <output filename="uncond1.rc" type="rc_data" /> ++ <if expr="lang == 'fr' or 'hello' in defs"> ++ <output filename="only_fr.adm" type="adm" /> ++ <output filename="only_fr.plist" type="plist" /> ++ </if> ++ <if expr="lang == 'ru'"> ++ <output filename="doc.html" type="document" /> ++ </if> ++ <output filename="uncond2.adm" type="adm" /> ++ <output filename="iftest.h" type="rc_header"> ++ <emit emit_type='prepend'></emit> ++ </output> ++ </outputs> ++ </grit>'''), dir='.') ++ ++ outputs_node = grd.children[0] ++ uncond1_output = outputs_node.children[0] ++ only_fr_adm_output = outputs_node.children[1].children[0] ++ only_fr_plist_output = outputs_node.children[1].children[1] ++ doc_output = outputs_node.children[2].children[0] ++ uncond2_output = outputs_node.children[0] ++ self.assertTrue(uncond1_output.name == 'output') ++ self.assertTrue(only_fr_adm_output.name == 'output') ++ self.assertTrue(only_fr_plist_output.name == 'output') ++ self.assertTrue(doc_output.name == 'output') ++ self.assertTrue(uncond2_output.name == 'output') ++ ++ grd.SetOutputLanguage('ru') ++ grd.SetDefines({'hello': '1'}) ++ outputs = [output.GetFilename() for output in grd.GetOutputFiles()] ++ self.assertEquals( ++ outputs, ++ ['uncond1.rc', 'only_fr.adm', 'only_fr.plist', 'doc.html', ++ 'uncond2.adm', 'iftest.h']) ++ ++ grd.SetOutputLanguage('ru') ++ grd.SetDefines({'bingo': '2'}) ++ outputs = [output.GetFilename() for output in grd.GetOutputFiles()] ++ self.assertEquals( ++ outputs, ++ ['uncond1.rc', 'doc.html', 'uncond2.adm', 'iftest.h']) ++ ++ grd.SetOutputLanguage('fr') ++ grd.SetDefines({'hello': '1'}) ++ outputs = [output.GetFilename() for output in grd.GetOutputFiles()] ++ self.assertEquals( ++ outputs, ++ ['uncond1.rc', 'only_fr.adm', 'only_fr.plist', 'uncond2.adm', ++ 'iftest.h']) ++ ++ grd.SetOutputLanguage('en') ++ grd.SetDefines({'bingo': '1'}) ++ outputs = [output.GetFilename() for output in grd.GetOutputFiles()] ++ self.assertEquals(outputs, ['uncond1.rc', 'uncond2.adm', 'iftest.h']) ++ ++ grd.SetOutputLanguage('fr') ++ grd.SetDefines({'bingo': '1'}) ++ outputs = [output.GetFilename() for output in grd.GetOutputFiles()] ++ self.assertNotEquals(outputs, ['uncond1.rc', 'uncond2.adm', 'iftest.h']) ++ ++ def testChildrenAccepted(self): ++ grd_reader.Parse(StringIO(r'''<?xml version="1.0"?> ++ <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <release seq="3"> ++ <includes> ++ <if expr="'bingo' in defs"> ++ <include type="gif" name="ID_LOGO2" file="images/logo2.gif" /> ++ </if> ++ <if expr="'bingo' in defs"> ++ <if expr="'hello' in defs"> ++ <include type="gif" name="ID_LOGO2" file="images/logo2.gif" /> ++ </if> ++ </if> ++ </includes> ++ <structures> ++ <if expr="'bingo' in defs"> ++ <structure type="dialog" name="IDD_ABOUTBOX" file="grit\test\data\klonk.rc" encoding="utf-16" /> ++ </if> ++ <if expr="'bingo' in defs"> ++ <if expr="'hello' in defs"> ++ <structure type="dialog" name="IDD_ABOUTBOX" file="grit\test\data\klonk.rc" encoding="utf-16" /> ++ </if> ++ </if> ++ </structures> ++ <messages> ++ <if expr="'bingo' in defs"> ++ <message name="IDS_BINGO">Bingo!</message> ++ </if> ++ <if expr="'bingo' in defs"> ++ <if expr="'hello' in defs"> ++ <message name="IDS_BINGO">Bingo!</message> ++ </if> ++ </if> ++ </messages> ++ </release> ++ <translations> ++ <if expr="'bingo' in defs"> ++ <file lang="nl" path="nl_translations.xtb" /> ++ </if> ++ <if expr="'bingo' in defs"> ++ <if expr="'hello' in defs"> ++ <file lang="nl" path="nl_translations.xtb" /> ++ </if> ++ </if> ++ </translations> ++ </grit>'''), dir='.') ++ ++ def testIfBadChildrenNesting(self): ++ # includes ++ xml = StringIO(r'''<?xml version="1.0"?> ++ <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <release seq="3"> ++ <includes> ++ <if expr="'bingo' in defs"> ++ <structure type="dialog" name="IDD_ABOUTBOX" file="grit\test\data\klonk.rc" encoding="utf-16" /> ++ </if> ++ </includes> ++ </release> ++ </grit>''') ++ self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml) ++ # messages ++ xml = StringIO(r'''<?xml version="1.0"?> ++ <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <release seq="3"> ++ <messages> ++ <if expr="'bingo' in defs"> ++ <structure type="dialog" name="IDD_ABOUTBOX" file="grit\test\data\klonk.rc" encoding="utf-16" /> ++ </if> ++ </messages> ++ </release> ++ </grit>''') ++ self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml) ++ # structures ++ xml = StringIO('''<?xml version="1.0"?> ++ <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <release seq="3"> ++ <structures> ++ <if expr="'bingo' in defs"> ++ <message name="IDS_BINGO">Bingo!</message> ++ </if> ++ </structures> ++ </release> ++ </grit>''') ++ # translations ++ self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml) ++ xml = StringIO('''<?xml version="1.0"?> ++ <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <translations> ++ <if expr="'bingo' in defs"> ++ <message name="IDS_BINGO">Bingo!</message> ++ </if> ++ </translations> ++ </grit>''') ++ self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml) ++ # same with nesting ++ xml = StringIO(r'''<?xml version="1.0"?> ++ <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <release seq="3"> ++ <includes> ++ <if expr="'bingo' in defs"> ++ <if expr="'hello' in defs"> ++ <structure type="dialog" name="IDD_ABOUTBOX" file="grit\test\data\klonk.rc" encoding="utf-16" /> ++ </if> ++ </if> ++ </includes> ++ </release> ++ </grit>''') ++ self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml) ++ xml = StringIO(r'''<?xml version="1.0"?> ++ <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <release seq="3"> ++ <messages> ++ <if expr="'bingo' in defs"> ++ <if expr="'hello' in defs"> ++ <structure type="dialog" name="IDD_ABOUTBOX" file="grit\test\data\klonk.rc" encoding="utf-16" /> ++ </if> ++ </if> ++ </messages> ++ </release> ++ </grit>''') ++ self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml) ++ xml = StringIO('''<?xml version="1.0"?> ++ <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <release seq="3"> ++ <structures> ++ <if expr="'bingo' in defs"> ++ <if expr="'hello' in defs"> ++ <message name="IDS_BINGO">Bingo!</message> ++ </if> ++ </if> ++ </structures> ++ </release> ++ </grit>''') ++ self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml) ++ xml = StringIO('''<?xml version="1.0"?> ++ <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <translations> ++ <if expr="'bingo' in defs"> ++ <if expr="'hello' in defs"> ++ <message name="IDS_BINGO">Bingo!</message> ++ </if> ++ </if> ++ </translations> ++ </grit>''') ++ self.assertRaises(grit.exception.UnexpectedChild, grd_reader.Parse, xml) ++ ++ ++class ReleaseNodeUnittest(unittest.TestCase): ++ def testPseudoControl(self): ++ grd = grd_reader.Parse(StringIO('''<?xml version="1.0" encoding="UTF-8"?> ++ <grit latest_public_release="1" source_lang_id="en-US" current_release="2" base_dir="."> ++ <release seq="1" allow_pseudo="false"> ++ <messages> ++ <message name="IDS_HELLO"> ++ Hello ++ </message> ++ </messages> ++ <structures> ++ <structure type="dialog" name="IDD_ABOUTBOX" encoding="utf-16" file="klonk.rc" /> ++ </structures> ++ </release> ++ <release seq="2"> ++ <messages> ++ <message name="IDS_BINGO"> ++ Bingo ++ </message> ++ </messages> ++ <structures> ++ <structure type="menu" name="IDC_KLONKMENU" encoding="utf-16" file="klonk.rc" /> ++ </structures> ++ </release> ++ </grit>'''), util.PathFromRoot('grit/testdata')) ++ grd.SetOutputLanguage('en') ++ grd.RunGatherers() ++ ++ hello = grd.GetNodeById('IDS_HELLO') ++ aboutbox = grd.GetNodeById('IDD_ABOUTBOX') ++ bingo = grd.GetNodeById('IDS_BINGO') ++ menu = grd.GetNodeById('IDC_KLONKMENU') ++ ++ for node in [hello, aboutbox]: ++ self.failUnless(not node.PseudoIsAllowed()) ++ ++ for node in [bingo, menu]: ++ self.failUnless(node.PseudoIsAllowed()) ++ ++ # TODO(benrg): There was a test here that formatting hello and aboutbox with ++ # a pseudo language should fail, but they do not fail and the test was ++ # broken and failed to catch it. Fix this. ++ ++ # Should not raise an exception since pseudo is allowed ++ rc.FormatMessage(bingo, 'xyz-pseudo') ++ rc.FormatStructure(menu, 'xyz-pseudo', '.') ++ ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/node/mock_brotli.py b/tools/grit/grit/node/mock_brotli.py +new file mode 100644 +index 0000000000..14237aab20 +--- /dev/null ++++ b/tools/grit/grit/node/mock_brotli.py +@@ -0,0 +1,10 @@ ++#!/usr/bin/env python ++# Copyright 2019 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++"""Mock Brotli Executable for testing purposes.""" + -+int main() { -+ MissingInCPPOK one; -+ MissingCtorsArentOKInHeader two; -+ return 0; ++import sys ++ ++sys.stdout.write('This has been mock compressed!') +diff --git a/tools/grit/grit/node/node_io.py b/tools/grit/grit/node/node_io.py +new file mode 100644 +index 0000000000..ccbc2c0647 +--- /dev/null ++++ b/tools/grit/grit/node/node_io.py +@@ -0,0 +1,117 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''The <output> and <file> elements. ++''' ++ ++from __future__ import print_function ++ ++import os ++ ++from grit import xtb_reader ++from grit.node import base ++ ++ ++class FileNode(base.Node): ++ '''A <file> element.''' ++ ++ def __init__(self): ++ super(FileNode, self).__init__() ++ self.re = None ++ self.should_load_ = True ++ ++ def IsTranslation(self): ++ return True ++ ++ def GetLang(self): ++ return self.attrs['lang'] ++ ++ def DisableLoading(self): ++ self.should_load_ = False ++ ++ def MandatoryAttributes(self): ++ return ['path', 'lang'] ++ ++ def RunPostSubstitutionGatherer(self, debug=False): ++ if not self.should_load_: ++ return ++ ++ root = self.GetRoot() ++ defs = getattr(root, 'defines', {}) ++ target_platform = getattr(root, 'target_platform', '') ++ ++ xtb_file = open(self.ToRealPath(self.GetInputPath()), 'rb') ++ try: ++ lang = xtb_reader.Parse(xtb_file, ++ self.UberClique().GenerateXtbParserCallback( ++ self.attrs['lang'], debug=debug), ++ defs=defs, ++ target_platform=target_platform) ++ except: ++ print("Exception during parsing of %s" % self.GetInputPath()) ++ raise ++ # Translation console uses non-standard language codes 'iw' and 'no' for ++ # Hebrew and Norwegian Bokmal instead of 'he' and 'nb' used in Chrome. ++ # Note that some Chrome's .grd still use 'no' instead of 'nb', but 'nb' is ++ # always used for generated .pak files. ++ ALTERNATIVE_LANG_CODE_MAP = { 'he': 'iw', 'nb': 'no' } ++ assert (lang == self.attrs['lang'] or ++ lang == ALTERNATIVE_LANG_CODE_MAP[self.attrs['lang']]), ( ++ 'The XTB file you reference must contain messages in the language ' ++ 'specified\nby the \'lang\' attribute.') ++ ++ def GetInputPath(self): ++ return os.path.expandvars(self.attrs['path']) ++ ++ ++class OutputNode(base.Node): ++ '''An <output> element.''' ++ ++ def MandatoryAttributes(self): ++ return ['filename', 'type'] ++ ++ def DefaultAttributes(self): ++ return { ++ 'lang' : '', # empty lang indicates all languages ++ 'language_section' : 'neutral', # defines a language neutral section ++ 'context' : '', ++ 'fallback_to_default_layout' : 'true', ++ } ++ ++ def GetType(self): ++ return self.attrs['type'] ++ ++ def GetLanguage(self): ++ '''Returns the language ID, default 'en'.''' ++ return self.attrs['lang'] ++ ++ def GetContext(self): ++ return self.attrs['context'] ++ ++ def GetFilename(self): ++ return self.attrs['filename'] ++ ++ def GetOutputFilename(self): ++ path = None ++ if hasattr(self, 'output_filename'): ++ path = self.output_filename ++ else: ++ path = self.attrs['filename'] ++ return os.path.expandvars(path) ++ ++ def GetFallbackToDefaultLayout(self): ++ return self.attrs['fallback_to_default_layout'].lower() == 'true' ++ ++ def _IsValidChild(self, child): ++ return isinstance(child, EmitNode) ++ ++class EmitNode(base.ContentNode): ++ ''' An <emit> element.''' ++ ++ def DefaultAttributes(self): ++ return { 'emit_type' : 'prepend'} ++ ++ def GetEmitType(self): ++ '''Returns the emit_type for this node. Default is 'append'.''' ++ return self.attrs['emit_type'] +diff --git a/tools/grit/grit/node/node_io_unittest.py b/tools/grit/grit/node/node_io_unittest.py +new file mode 100644 +index 0000000000..1f45e51af8 +--- /dev/null ++++ b/tools/grit/grit/node/node_io_unittest.py +@@ -0,0 +1,182 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for node_io.FileNode''' ++ ++from __future__ import print_function ++ ++import os ++import sys ++import unittest ++ ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++from six import StringIO ++ ++from grit.node import misc ++from grit.node import node_io ++from grit.node import empty ++from grit import grd_reader ++from grit import util ++ ++ ++def _GetAllCliques(root_node): ++ """Return all cliques in the |root_node| tree.""" ++ ret = [] ++ for node in root_node: ++ ret.extend(node.GetCliques()) ++ return ret ++ ++ ++class FileNodeUnittest(unittest.TestCase): ++ def testGetPath(self): ++ root = misc.GritNode() ++ root.StartParsing(u'grit', None) ++ root.HandleAttribute(u'latest_public_release', u'0') ++ root.HandleAttribute(u'current_release', u'1') ++ root.HandleAttribute(u'base_dir', r'..\resource') ++ translations = empty.TranslationsNode() ++ translations.StartParsing(u'translations', root) ++ root.AddChild(translations) ++ file_node = node_io.FileNode() ++ file_node.StartParsing(u'file', translations) ++ file_node.HandleAttribute(u'path', r'flugel\kugel.pdf') ++ translations.AddChild(file_node) ++ root.EndParsing() ++ ++ self.failUnless(root.ToRealPath(file_node.GetInputPath()) == ++ util.normpath( ++ os.path.join(r'../resource', r'flugel/kugel.pdf'))) ++ ++ def VerifyCliquesContainEnglishAndFrenchAndNothingElse(self, cliques): ++ self.assertEqual(2, len(cliques)) ++ for clique in cliques: ++ self.assertEqual({'en', 'fr'}, set(clique.clique.keys())) ++ ++ def testLoadTranslations(self): ++ xml = '''<?xml version="1.0" encoding="UTF-8"?> ++ <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <translations> ++ <file path="generated_resources_fr.xtb" lang="fr" /> ++ </translations> ++ <release seq="3"> ++ <messages> ++ <message name="ID_HELLO">Hello!</message> ++ <message name="ID_HELLO_USER">Hello <ph name="USERNAME">%s<ex>Joi</ex></ph></message> ++ </messages> ++ </release> ++ </grit>''' ++ grd = grd_reader.Parse(StringIO(xml), ++ util.PathFromRoot('grit/testdata')) ++ grd.SetOutputLanguage('en') ++ grd.RunGatherers() ++ self.VerifyCliquesContainEnglishAndFrenchAndNothingElse(_GetAllCliques(grd)) ++ ++ def testIffyness(self): ++ grd = grd_reader.Parse(StringIO('''<?xml version="1.0" encoding="UTF-8"?> ++ <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <translations> ++ <if expr="lang == 'fr'"> ++ <file path="generated_resources_fr.xtb" lang="fr" /> ++ </if> ++ </translations> ++ <release seq="3"> ++ <messages> ++ <message name="ID_HELLO">Hello!</message> ++ <message name="ID_HELLO_USER">Hello <ph name="USERNAME">%s<ex>Joi</ex></ph></message> ++ </messages> ++ </release> ++ </grit>'''), util.PathFromRoot('grit/testdata')) ++ grd.SetOutputLanguage('en') ++ grd.RunGatherers() ++ cliques = _GetAllCliques(grd) ++ self.assertEqual(2, len(cliques)) ++ for clique in cliques: ++ self.assertEqual({'en'}, set(clique.clique.keys())) ++ ++ grd.SetOutputLanguage('fr') ++ grd.RunGatherers() ++ self.VerifyCliquesContainEnglishAndFrenchAndNothingElse(_GetAllCliques(grd)) ++ ++ def testConditionalLoadTranslations(self): ++ xml = '''<?xml version="1.0" encoding="UTF-8"?> ++ <grit latest_public_release="2" source_lang_id="en-US" current_release="3" ++ base_dir="."> ++ <translations> ++ <if expr="True"> ++ <file path="generated_resources_fr.xtb" lang="fr" /> ++ </if> ++ <if expr="False"> ++ <file path="no_such_file.xtb" lang="de" /> ++ </if> ++ </translations> ++ <release seq="3"> ++ <messages> ++ <message name="ID_HELLO">Hello!</message> ++ <message name="ID_HELLO_USER">Hello <ph name="USERNAME">%s<ex> ++ Joi</ex></ph></message> ++ </messages> ++ </release> ++ </grit>''' ++ grd = grd_reader.Parse(StringIO(xml), ++ util.PathFromRoot('grit/testdata')) ++ grd.SetOutputLanguage('en') ++ grd.RunGatherers() ++ self.VerifyCliquesContainEnglishAndFrenchAndNothingElse(_GetAllCliques(grd)) ++ ++ def testConditionalOutput(self): ++ xml = '''<?xml version="1.0" encoding="UTF-8"?> ++ <grit latest_public_release="2" source_lang_id="en-US" current_release="3" ++ base_dir="."> ++ <outputs> ++ <output filename="resource.h" type="rc_header" /> ++ <output filename="en/generated_resources.rc" type="rc_all" ++ lang="en" /> ++ <if expr="pp_if('NOT_TRUE')"> ++ <output filename="de/generated_resources.rc" type="rc_all" ++ lang="de" /> ++ </if> ++ </outputs> ++ <release seq="3"> ++ <messages> ++ <message name="ID_HELLO">Hello!</message> ++ </messages> ++ </release> ++ </grit>''' ++ grd = grd_reader.Parse(StringIO(xml), ++ util.PathFromRoot('grit/test/data'), ++ defines={}) ++ grd.SetOutputLanguage('en') ++ grd.RunGatherers() ++ outputs = grd.GetChildrenOfType(node_io.OutputNode) ++ active = set(grd.ActiveDescendants()) ++ self.failUnless(outputs[0] in active) ++ self.failUnless(outputs[0].GetType() == 'rc_header') ++ self.failUnless(outputs[1] in active) ++ self.failUnless(outputs[1].GetType() == 'rc_all') ++ self.failUnless(outputs[2] not in active) ++ self.failUnless(outputs[2].GetType() == 'rc_all') ++ ++ # Verify that 'iw' and 'no' language codes in xtb files are mapped to 'he' and ++ # 'nb'. ++ def testLangCodeMapping(self): ++ grd = grd_reader.Parse(StringIO('''<?xml version="1.0" encoding="UTF-8"?> ++ <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <translations> ++ <file path="generated_resources_no.xtb" lang="nb" /> ++ <file path="generated_resources_iw.xtb" lang="he" /> ++ </translations> ++ <release seq="3"> ++ <messages></messages> ++ </release> ++ </grit>'''), util.PathFromRoot('grit/testdata')) ++ grd.SetOutputLanguage('en') ++ grd.RunGatherers() ++ self.assertEqual([], _GetAllCliques(grd)) ++ ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/node/structure.py b/tools/grit/grit/node/structure.py +new file mode 100644 +index 0000000000..ec170faebb +--- /dev/null ++++ b/tools/grit/grit/node/structure.py +@@ -0,0 +1,375 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''The <structure> element. ++''' ++ ++from __future__ import print_function ++ ++import os ++import platform ++import re ++ ++from grit import exception ++from grit import util ++from grit.node import base ++from grit.node import variant ++ ++import grit.gather.admin_template ++import grit.gather.chrome_html ++import grit.gather.chrome_scaled_image ++import grit.gather.policy_json ++import grit.gather.rc ++import grit.gather.tr_html ++import grit.gather.txt ++ ++import grit.format.rc ++ ++# Type of the gatherer to use for each type attribute ++_GATHERERS = { ++ 'accelerators' : grit.gather.rc.Accelerators, ++ 'admin_template' : grit.gather.admin_template.AdmGatherer, ++ 'chrome_html' : grit.gather.chrome_html.ChromeHtml, ++ 'chrome_scaled_image' : grit.gather.chrome_scaled_image.ChromeScaledImage, ++ 'dialog' : grit.gather.rc.Dialog, ++ 'menu' : grit.gather.rc.Menu, ++ 'rcdata' : grit.gather.rc.RCData, ++ 'tr_html' : grit.gather.tr_html.TrHtml, ++ 'txt' : grit.gather.txt.TxtFile, ++ 'version' : grit.gather.rc.Version, ++ 'policy_template_metafile' : grit.gather.policy_json.PolicyJson, +} -diff --git a/tools/clang/plugins/tests/missing_ctor.h b/tools/clang/plugins/tests/missing_ctor.h ++ ++ ++# TODO(joi) Print a warning if the 'variant_of_revision' attribute indicates ++# that a skeleton variant is older than the original file. ++ ++ ++class StructureNode(base.Node): ++ '''A <structure> element.''' ++ ++ # Regular expression for a local variable definition. Each definition ++ # is of the form NAME=VALUE, where NAME cannot contain '=' or ',' and ++ # VALUE must escape all commas: ',' -> ',,'. Each variable definition ++ # should be separated by a comma with no extra whitespace. ++ # Example: THING1=foo,THING2=bar ++ variable_pattern = re.compile(r'([^,=\s]+)=((?:,,|[^,])*)') ++ ++ def __init__(self): ++ super(StructureNode, self).__init__() ++ ++ # Keep track of the last filename we flattened to, so we can ++ # avoid doing it more than once. ++ self._last_flat_filename = None ++ ++ # See _Substitute; this substituter is used for local variables and ++ # the root substituter is used for global variables. ++ self.substituter = None ++ ++ def _IsValidChild(self, child): ++ return isinstance(child, variant.SkeletonNode) ++ ++ def _ParseVariables(self, variables): ++ '''Parse a variable string into a dictionary.''' ++ matches = StructureNode.variable_pattern.findall(variables) ++ return dict((name, value.replace(',,', ',')) for name, value in matches) ++ ++ def EndParsing(self): ++ super(StructureNode, self).EndParsing() ++ ++ # Now that we have attributes and children, instantiate the gatherers. ++ gathertype = _GATHERERS[self.attrs['type']] ++ ++ self.gatherer = gathertype(self.attrs['file'], ++ self.attrs['name'], ++ self.attrs['encoding']) ++ self.gatherer.SetGrdNode(self) ++ self.gatherer.SetUberClique(self.UberClique()) ++ if hasattr(self.GetRoot(), 'defines'): ++ self.gatherer.SetDefines(self.GetRoot().defines) ++ self.gatherer.SetAttributes(self.attrs) ++ if self.ExpandVariables(): ++ self.gatherer.SetFilenameExpansionFunction(self._Substitute) ++ ++ # Parse local variables and instantiate the substituter. ++ if self.attrs['variables']: ++ variables = self.attrs['variables'] ++ self.substituter = util.Substituter() ++ self.substituter.AddSubstitutions(self._ParseVariables(variables)) ++ ++ self.skeletons = {} # Maps expressions to skeleton gatherers ++ for child in self.children: ++ assert isinstance(child, variant.SkeletonNode) ++ skel = gathertype(child.attrs['file'], ++ self.attrs['name'], ++ child.GetEncodingToUse(), ++ is_skeleton=True) ++ skel.SetGrdNode(self) # TODO(benrg): Or child? Only used for ToRealPath ++ skel.SetUberClique(self.UberClique()) ++ if hasattr(self.GetRoot(), 'defines'): ++ skel.SetDefines(self.GetRoot().defines) ++ if self.ExpandVariables(): ++ skel.SetFilenameExpansionFunction(self._Substitute) ++ self.skeletons[child.attrs['expr']] = skel ++ ++ def MandatoryAttributes(self): ++ return ['type', 'name', 'file'] ++ ++ def DefaultAttributes(self): ++ return { ++ 'encoding': 'cp1252', ++ 'exclude_from_rc': 'false', ++ 'line_end': 'unix', ++ 'output_encoding': 'utf-8', ++ 'generateid': 'true', ++ 'expand_variables': 'false', ++ 'output_filename': '', ++ 'fold_whitespace': 'false', ++ # Run an arbitrary command after translation is complete ++ # so that it doesn't interfere with what's in translation ++ # console. ++ 'run_command': '', ++ # Leave empty to run on all platforms, comma-separated ++ # for one or more specific platforms. Values must match ++ # output of platform.system(). ++ 'run_command_on_platforms': '', ++ 'allowexternalscript': 'false', ++ # preprocess takes the same code path as flattenhtml, but it ++ # disables any processing/inlining outside of <if> and <include>. ++ 'preprocess': 'false', ++ 'flattenhtml': 'false', ++ 'fallback_to_low_resolution': 'default', ++ 'variables': '', ++ 'compress': 'default', ++ 'use_base_dir': 'true', ++ } ++ ++ def IsExcludedFromRc(self): ++ return self.attrs['exclude_from_rc'] == 'true' ++ ++ def Process(self, output_dir): ++ """Writes the processed data to output_dir. In the case of a chrome_html ++ structure this will add references to other scale factors. If flattening ++ this will also write file references to be base64 encoded data URLs. The ++ name of the new file is returned.""" ++ filename = self.ToRealPath(self.GetInputPath()) ++ flat_filename = os.path.join(output_dir, ++ self.attrs['name'] + '_' + os.path.basename(filename)) ++ ++ if self._last_flat_filename == flat_filename: ++ return ++ ++ with open(flat_filename, 'wb') as outfile: ++ if self.ExpandVariables(): ++ text = self.gatherer.GetText() ++ file_contents = self._Substitute(text) ++ else: ++ file_contents = self.gatherer.GetData('', 'utf-8') ++ outfile.write(file_contents.encode('utf-8')) ++ ++ self._last_flat_filename = flat_filename ++ return os.path.basename(flat_filename) ++ ++ def GetLineEnd(self): ++ '''Returns the end-of-line character or characters for files output because ++ of this node ('\r\n', '\n', or '\r' depending on the 'line_end' attribute). ++ ''' ++ if self.attrs['line_end'] == 'unix': ++ return '\n' ++ elif self.attrs['line_end'] == 'windows': ++ return '\r\n' ++ elif self.attrs['line_end'] == 'mac': ++ return '\r' ++ else: ++ raise exception.UnexpectedAttribute( ++ "Attribute 'line_end' must be one of 'unix' (default), 'windows' or " ++ "'mac'") ++ ++ def GetCliques(self): ++ return self.gatherer.GetCliques() ++ ++ def GetDataPackValue(self, lang, encoding): ++ """Returns a bytes representation for a data_pack entry.""" ++ if self.ExpandVariables(): ++ text = self.gatherer.GetText() ++ data = util.Encode(self._Substitute(text), encoding) ++ else: ++ data = self.gatherer.GetData(lang, encoding) ++ if encoding != util.BINARY: ++ data = data.encode(encoding) ++ return self.CompressDataIfNeeded(data) ++ ++ def GetHtmlResourceFilenames(self): ++ """Returns a set of all filenames inlined by this node.""" ++ return self.gatherer.GetHtmlResourceFilenames() ++ ++ def GetInputPath(self): ++ path = self.gatherer.GetInputPath() ++ if path is None: ++ return path ++ ++ # Do not mess with absolute paths, that would make them invalid. ++ if os.path.isabs(os.path.expandvars(path)): ++ return path ++ ++ # We have no control over code that calls ToRealPath later, so convert ++ # the path to be relative against our basedir. ++ if self.attrs.get('use_base_dir', 'true') != 'true': ++ # Normalize the directory path to use the appropriate OS separator. ++ # GetBaseDir() may return paths\like\this or paths/like/this, since it is ++ # read from the base_dir attribute in the grd file. ++ norm_base_dir = util.normpath(self.GetRoot().GetBaseDir()) ++ return os.path.relpath(path, norm_base_dir) ++ ++ return path ++ ++ def GetTextualIds(self): ++ if not hasattr(self, 'gatherer'): ++ # This case is needed because this method is called by ++ # GritNode.ValidateUniqueIds before RunGatherers has been called. ++ # TODO(benrg): Fix this? ++ return [self.attrs['name']] ++ return self.gatherer.GetTextualIds() ++ ++ def RunPreSubstitutionGatherer(self, debug=False): ++ if debug: ++ print('Running gatherer %s for file %s' % ++ (type(self.gatherer), self.GetInputPath())) ++ ++ # Note: Parse() is idempotent, therefore this method is also. ++ self.gatherer.Parse() ++ for skel in self.skeletons.values(): ++ skel.Parse() ++ ++ def GetSkeletonGatherer(self): ++ '''Returns the gatherer for the alternate skeleton that should be used, ++ based on the expressions for selecting skeletons, or None if the skeleton ++ from the English version of the structure should be used. ++ ''' ++ for expr in self.skeletons: ++ if self.EvaluateCondition(expr): ++ return self.skeletons[expr] ++ return None ++ ++ def HasFileForLanguage(self): ++ return self.attrs['type'] in ['tr_html', 'admin_template', 'txt', ++ 'chrome_scaled_image', ++ 'chrome_html'] ++ ++ def ExpandVariables(self): ++ '''Variable expansion on structures is controlled by an XML attribute. ++ ++ However, old files assume that expansion is always on for Rc files. ++ ++ Returns: ++ A boolean. ++ ''' ++ attrs = self.GetRoot().attrs ++ if 'grit_version' in attrs and attrs['grit_version'] > 1: ++ return self.attrs['expand_variables'] == 'true' ++ else: ++ return (self.attrs['expand_variables'] == 'true' or ++ self.attrs['file'].lower().endswith('.rc')) ++ ++ def _Substitute(self, text): ++ '''Perform local and global variable substitution.''' ++ if self.substituter: ++ text = self.substituter.Substitute(text) ++ return self.GetRoot().GetSubstituter().Substitute(text) ++ ++ def RunCommandOnCurrentPlatform(self): ++ if self.attrs['run_command_on_platforms'] == '': ++ return True ++ else: ++ target_platforms = self.attrs['run_command_on_platforms'].split(',') ++ return platform.system() in target_platforms ++ ++ def FileForLanguage(self, lang, output_dir, create_file=True, ++ return_if_not_generated=True): ++ '''Returns the filename of the file associated with this structure, ++ for the specified language. ++ ++ Args: ++ lang: 'fr' ++ output_dir: 'c:\temp' ++ create_file: True ++ ''' ++ assert self.HasFileForLanguage() ++ # If the source language is requested, and no extra changes are requested, ++ # use the existing file. ++ if ((not lang or lang == self.GetRoot().GetSourceLanguage()) and ++ self.attrs['expand_variables'] != 'true' and ++ (not self.attrs['run_command'] or ++ not self.RunCommandOnCurrentPlatform())): ++ if return_if_not_generated: ++ input_path = self.GetInputPath() ++ if input_path is None: ++ return None ++ return self.ToRealPath(input_path) ++ else: ++ return None ++ ++ if self.attrs['output_filename'] != '': ++ filename = self.attrs['output_filename'] ++ else: ++ filename = os.path.basename(self.attrs['file']) ++ assert len(filename) ++ filename = '%s_%s' % (lang, filename) ++ filename = os.path.join(output_dir, filename) ++ ++ # Only create the output if it was requested by the call. ++ if create_file: ++ text = self.gatherer.Translate( ++ lang, ++ pseudo_if_not_available=self.PseudoIsAllowed(), ++ fallback_to_english=self.ShouldFallbackToEnglish(), ++ skeleton_gatherer=self.GetSkeletonGatherer()) ++ ++ file_contents = util.FixLineEnd(text, self.GetLineEnd()) ++ if self.ExpandVariables(): ++ # Note that we reapply substitution a second time here. ++ # This is because a) we need to look inside placeholders ++ # b) the substitution values are language-dependent ++ file_contents = self._Substitute(file_contents) ++ ++ with open(filename, 'wb') as file_object: ++ output_stream = util.WrapOutputStream(file_object, ++ self.attrs['output_encoding']) ++ output_stream.write(file_contents) ++ ++ if self.attrs['run_command'] and self.RunCommandOnCurrentPlatform(): ++ # Run arbitrary commands after translation is complete so that it ++ # doesn't interfere with what's in translation console. ++ command = self.attrs['run_command'] % {'filename': filename} ++ result = os.system(command) ++ assert result == 0, '"%s" failed.' % command ++ ++ return filename ++ ++ def IsResourceMapSource(self): ++ return True ++ ++ @staticmethod ++ def Construct(parent, name, type, file, encoding='cp1252'): ++ '''Creates a new node which is a child of 'parent', with attributes set ++ by parameters of the same name. ++ ''' ++ node = StructureNode() ++ node.StartParsing('structure', parent) ++ node.HandleAttribute('name', name) ++ node.HandleAttribute('type', type) ++ node.HandleAttribute('file', file) ++ node.HandleAttribute('encoding', encoding) ++ node.EndParsing() ++ return node ++ ++ def SubstituteMessages(self, substituter): ++ '''Propagates substitution to gatherer. ++ ++ Args: ++ substituter: a grit.util.Substituter object. ++ ''' ++ assert hasattr(self, 'gatherer') ++ if self.ExpandVariables(): ++ self.gatherer.SubstituteMessages(substituter) +diff --git a/tools/grit/grit/node/structure_unittest.py b/tools/grit/grit/node/structure_unittest.py new file mode 100644 -index 0000000000..1050457a1a +index 0000000000..0e66dce37a --- /dev/null -+++ b/tools/clang/plugins/tests/missing_ctor.h -@@ -0,0 +1,19 @@ -+// Copyright (c) 2011 The Chromium Authors. All rights reserved. -+// Use of this source code is governed by a BSD-style license that can be -+// found in the LICENSE file. ++++ b/tools/grit/grit/node/structure_unittest.py +@@ -0,0 +1,178 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for <structure> nodes. ++''' + -+#ifndef MISSING_CTOR_H_ -+#define MISSING_CTOR_H_ ++from __future__ import print_function + -+#include <string> -+#include <vector> ++import os ++import os.path ++import sys ++import zlib ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++import platform ++import tempfile ++import unittest ++import struct ++ ++from grit import constants ++from grit import util ++from grit.node import brotli_util ++from grit.node import structure ++from grit.format import rc ++ ++ ++def checkIsGzipped(filename, compress_attr): ++ test_data_root = util.PathFromRoot('grit/testdata') ++ root = util.ParseGrdForUnittest( ++ ''' ++ <structures> ++ <structure name="TEST_TXT" file="%s" %s type="chrome_html"/> ++ </structures>''' % (filename, compress_attr), ++ base_dir=test_data_root) ++ node, = root.GetChildrenOfType(structure.StructureNode) ++ node.RunPreSubstitutionGatherer() ++ compressed = node.GetDataPackValue(lang='en', encoding=util.BINARY) ++ ++ decompressed_data = zlib.decompress(compressed, 16 + zlib.MAX_WBITS) ++ expected = util.ReadFile(os.path.join(test_data_root, filename), util.BINARY) ++ return expected == decompressed_data ++ ++ ++class StructureUnittest(unittest.TestCase): ++ def testSkeleton(self): ++ grd = util.ParseGrdForUnittest(''' ++ <structures> ++ <structure type="dialog" name="IDD_ABOUTBOX" file="klonk.rc" encoding="utf-16-le"> ++ <skeleton expr="lang == 'fr'" variant_of_revision="1" file="klonk-alternate-skeleton.rc" /> ++ </structure> ++ </structures>''', base_dir=util.PathFromRoot('grit/testdata')) ++ grd.SetOutputLanguage('fr') ++ grd.RunGatherers() ++ transl = ''.join(rc.Format(grd, 'fr', '.')) ++ self.failUnless(transl.count('040704') and transl.count('110978')) ++ self.failUnless(transl.count('2005",IDC_STATIC')) ++ ++ def testRunCommandOnCurrentPlatform(self): ++ node = structure.StructureNode() ++ node.attrs = node.DefaultAttributes() ++ self.failUnless(node.RunCommandOnCurrentPlatform()) ++ node.attrs['run_command_on_platforms'] = 'Nosuch' ++ self.failIf(node.RunCommandOnCurrentPlatform()) ++ node.attrs['run_command_on_platforms'] = ( ++ 'Nosuch,%s,Othernot' % platform.system()) ++ self.failUnless(node.RunCommandOnCurrentPlatform()) ++ ++ def testVariables(self): ++ grd = util.ParseGrdForUnittest(''' ++ <structures> ++ <structure type="chrome_html" name="hello_tmpl" file="structure_variables.html" expand_variables="true" variables="GREETING=Hello,THINGS=foo,, bar,, baz,EQUATION=2+2==4,filename=simple" flattenhtml="true"></structure> ++ </structures>''', base_dir=util.PathFromRoot('grit/testdata')) ++ grd.SetOutputLanguage('en') ++ grd.RunGatherers() ++ node, = grd.GetChildrenOfType(structure.StructureNode) ++ filename = node.Process(tempfile.gettempdir()) ++ filepath = os.path.join(tempfile.gettempdir(), filename) ++ with open(filepath) as f: ++ result = f.read() ++ self.failUnlessEqual(('<h1>Hello!</h1>\n' ++ 'Some cool things are foo, bar, baz.\n' ++ 'Did you know that 2+2==4?\n' ++ '<p>\n' ++ ' Hello!\n' ++ '</p>\n'), result) ++ os.remove(filepath) ++ ++ def testGetPath(self): ++ base_dir = util.PathFromRoot('grit/testdata') ++ grd = util.ParseGrdForUnittest(''' ++ <structures> ++ <structure type="chrome_html" name="hello_tmpl" file="structure_variables.html" expand_variables="true" variables="GREETING=Hello,THINGS=foo,, bar,, baz,EQUATION=2+2==4,filename=simple" flattenhtml="true" use_base_dir="true"></structure> ++ </structures>''', base_dir) ++ grd.SetOutputLanguage('en') ++ grd.RunGatherers() ++ node, = grd.GetChildrenOfType(structure.StructureNode) ++ self.assertEqual(grd.ToRealPath(node.GetInputPath()), ++ os.path.abspath(os.path.join( ++ base_dir, r'structure_variables.html'))) ++ ++ def testGetPathNoBasedir(self): ++ base_dir = util.PathFromRoot('grit/testdata') ++ abs_path = os.path.join(base_dir, r'structure_variables.html') ++ rel_path = os.path.relpath(abs_path, os.getcwd()) ++ grd = util.ParseGrdForUnittest(''' ++ <structures> ++ <structure type="chrome_html" name="hello_tmpl" file="''' + rel_path + '''" expand_variables="true" variables="GREETING=Hello,THINGS=foo,, bar,, baz,EQUATION=2+2==4,filename=simple" flattenhtml="true" use_base_dir="false"></structure> ++ </structures>''', util.PathFromRoot('grit/testdata')) ++ grd.SetOutputLanguage('en') ++ grd.RunGatherers() ++ node, = grd.GetChildrenOfType(structure.StructureNode) ++ self.assertEqual(grd.ToRealPath(node.GetInputPath()), ++ os.path.abspath(os.path.join( ++ base_dir, r'structure_variables.html'))) ++ ++ def testCompressGzip(self): ++ self.assertTrue(checkIsGzipped('test_text.txt', 'compress="gzip"')) ++ ++ def testCompressGzipByDefault(self): ++ self.assertTrue(checkIsGzipped('test_html.html', '')) ++ self.assertTrue(checkIsGzipped('test_js.js', '')) ++ self.assertTrue(checkIsGzipped('test_css.css', '')) ++ self.assertTrue(checkIsGzipped('test_svg.svg', '')) ++ ++ self.assertTrue(checkIsGzipped('test_html.html', 'compress="default"')) ++ self.assertTrue(checkIsGzipped('test_js.js', 'compress="default"')) ++ self.assertTrue(checkIsGzipped('test_css.css', 'compress="default"')) ++ self.assertTrue(checkIsGzipped('test_svg.svg', 'compress="default"')) ++ ++ def testCompressBrotli(self): ++ test_data_root = util.PathFromRoot('grit/testdata') ++ root = util.ParseGrdForUnittest( ++ ''' ++ <structures> ++ <structure name="TEST_TXT" file="test_text.txt" ++ compress="brotli" type="chrome_html" /> ++ </structures>''', ++ base_dir=test_data_root) ++ node, = root.GetChildrenOfType(structure.StructureNode) ++ node.RunPreSubstitutionGatherer() ++ ++ # Using the mock brotli decompression executable. ++ brotli_util.SetBrotliCommand([sys.executable, ++ os.path.join(os.path.dirname(__file__), ++ 'mock_brotli.py')]) ++ compressed = node.GetDataPackValue(lang='en', encoding=util.BINARY) ++ # Assert that the first two bytes in compressed format is BROTLI_CONST. ++ self.assertEqual(constants.BROTLI_CONST, compressed[0:2]) ++ ++ # Compare the actual size of the uncompressed test data with ++ # the size appended during compression. ++ actual_size = len(util.ReadFile( ++ os.path.join(test_data_root, 'test_text.txt'), util.BINARY)) ++ uncompress_size = struct.unpack('<i', compressed[2:6])[0] ++ uncompress_size += struct.unpack('<h', compressed[6:8])[0] << 4*8 ++ self.assertEqual(actual_size, uncompress_size) ++ ++ self.assertEqual(b'This has been mock compressed!', compressed[8:]) ++ ++ def testNotCompressed(self): ++ test_data_root = util.PathFromRoot('grit/testdata') ++ root = util.ParseGrdForUnittest(''' ++ <structures> ++ <structure name="TEST_TXT" file="test_text.txt" type="chrome_html" /> ++ </structures>''', base_dir=test_data_root) ++ node, = root.GetChildrenOfType(structure.StructureNode) ++ node.RunPreSubstitutionGatherer() ++ data = node.GetDataPackValue(lang='en', encoding=util.BINARY) ++ ++ self.assertEqual(util.ReadFile( ++ os.path.join(test_data_root, 'test_text.txt'), util.BINARY), data) + -+class MissingCtorsArentOKInHeader { -+ public: + -+ private: -+ std::vector<int> one_; -+ std::vector<std::string> two_; -+}; ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/node/variant.py b/tools/grit/grit/node/variant.py +new file mode 100644 +index 0000000000..9f5845f954 +--- /dev/null ++++ b/tools/grit/grit/node/variant.py +@@ -0,0 +1,41 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''The <skeleton> element. ++''' ++ ++from __future__ import print_function ++ ++from grit.node import base ++ ++ ++class SkeletonNode(base.Node): ++ '''A <skeleton> element.''' ++ ++ # TODO(joi) Support inline skeleton variants as CDATA instead of requiring ++ # a 'file' attribute. ++ ++ def MandatoryAttributes(self): ++ return ['expr', 'variant_of_revision', 'file'] ++ ++ def DefaultAttributes(self): ++ '''If not specified, 'encoding' will actually default to the parent node's ++ encoding. ++ ''' ++ return {'encoding' : ''} ++ ++ def _ContentType(self): ++ if 'file' in self.attrs: ++ return self._CONTENT_TYPE_NONE ++ else: ++ return self._CONTENT_TYPE_CDATA ++ ++ def GetEncodingToUse(self): ++ if self.attrs['encoding'] == '': ++ return self.parent.attrs['encoding'] ++ else: ++ return self.attrs['encoding'] ++ ++ def GetInputPath(self): ++ return self.attrs['file'] +diff --git a/tools/grit/grit/pseudo.py b/tools/grit/grit/pseudo.py +new file mode 100644 +index 0000000000..b607bfc6bb +--- /dev/null ++++ b/tools/grit/grit/pseudo.py +@@ -0,0 +1,129 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Pseudotranslation support. Our pseudotranslations are based on the ++P-language, which is a simple vowel-extending language. Examples of P: ++ - "hello" becomes "hepellopo" ++ - "howdie" becomes "hopowdiepie" ++ - "because" becomes "bepecaupause" (but in our implementation we don't ++ handle the silent e at the end so it actually would return "bepecaupausepe" ++ ++The P-language has the excellent quality of increasing the length of text ++by around 30-50% which is great for pseudotranslations, to stress test any ++GUI layouts etc. ++ ++To make the pseudotranslations more obviously "not a translation" and to make ++them exercise any code that deals with encodings, we also transform all English ++vowels into equivalent vowels with diacriticals on them (rings, acutes, ++diaresis, and circumflex), and we write the "p" in the P-language as a Hebrew ++character Qof. It looks sort of like a latin character "p" but it is outside ++the latin-1 character set which will stress character encoding bugs. ++''' ++ ++from __future__ import print_function ++ ++from grit import lazy_re ++from grit import tclib ++ ++ ++# An RFC language code for the P pseudolanguage. ++PSEUDO_LANG = 'x-P-pseudo' ++ ++# Hebrew character Qof. It looks kind of like a 'p' but is outside ++# the latin-1 character set which is good for our purposes. ++# TODO(joi) For now using P instead of Qof, because of some bugs it used. Find ++# a better solution, i.e. one that introduces a non-latin1 character into the ++# pseudotranslation. ++#_QOF = u'\u05e7' ++_QOF = u'P' ++ ++# How we map each vowel. ++_VOWELS = { ++ u'a' : u'\u00e5', # a with ring ++ u'e' : u'\u00e9', # e acute ++ u'i' : u'\u00ef', # i diaresis ++ u'o' : u'\u00f4', # o circumflex ++ u'u' : u'\u00fc', # u diaresis ++ u'y' : u'\u00fd', # y acute ++ u'A' : u'\u00c5', # A with ring ++ u'E' : u'\u00c9', # E acute ++ u'I' : u'\u00cf', # I diaresis ++ u'O' : u'\u00d4', # O circumflex ++ u'U' : u'\u00dc', # U diaresis ++ u'Y' : u'\u00dd', # Y acute ++} ++_VOWELS_KEYS = set(_VOWELS.keys()) ++ ++# Matches vowels and P ++_PSUB_RE = lazy_re.compile("(%s)" % '|'.join(_VOWELS_KEYS | {'P'})) ++ ++ ++# Pseudotranslations previously created. This is important for performance ++# reasons, especially since we routinely pseudotranslate the whole project ++# several or many different times for each build. ++_existing_translations = {} ++ ++ ++def MapVowels(str, also_p = False): ++ '''Returns a copy of 'str' where characters that exist as keys in _VOWELS ++ have been replaced with the corresponding value. If also_p is true, this ++ function will also change capital P characters into a Hebrew character Qof. ++ ''' ++ def Repl(match): ++ if match.group() == 'p': ++ if also_p: ++ return _QOF ++ else: ++ return 'p' ++ else: ++ return _VOWELS[match.group()] ++ return _PSUB_RE.sub(Repl, str) ++ ++ ++def PseudoString(str): ++ '''Returns a pseudotranslation of the provided string, in our enhanced ++ P-language.''' ++ if str in _existing_translations: ++ return _existing_translations[str] ++ ++ outstr = u'' ++ ix = 0 ++ while ix < len(str): ++ if str[ix] not in _VOWELS_KEYS: ++ outstr += str[ix] ++ ix += 1 ++ else: ++ # We want to treat consecutive vowels as one composite vowel. This is not ++ # always accurate e.g. in composite words but good enough. ++ consecutive_vowels = u'' ++ while ix < len(str) and str[ix] in _VOWELS_KEYS: ++ consecutive_vowels += str[ix] ++ ix += 1 ++ changed_vowels = MapVowels(consecutive_vowels) ++ outstr += changed_vowels ++ outstr += _QOF ++ outstr += changed_vowels ++ ++ _existing_translations[str] = outstr ++ return outstr ++ ++ ++def PseudoMessage(message): ++ '''Returns a pseudotranslation of the provided message. ++ ++ Args: ++ message: tclib.Message() ++ ++ Return: ++ tclib.Translation() ++ ''' ++ transl = tclib.Translation() ++ ++ for part in message.GetContent(): ++ if isinstance(part, tclib.Placeholder): ++ transl.AppendPlaceholder(part) ++ else: ++ transl.AppendText(PseudoString(part)) ++ ++ return transl +diff --git a/tools/grit/grit/pseudo_rtl.py b/tools/grit/grit/pseudo_rtl.py +new file mode 100644 +index 0000000000..2240b571de +--- /dev/null ++++ b/tools/grit/grit/pseudo_rtl.py +@@ -0,0 +1,104 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Pseudo RTL, (aka Fake Bidi) support. It simply wraps each word with ++Unicode RTL overrides. ++More info at https://sites.google.com/a/chromium.org/dev/Home/fake-bidi ++''' ++ ++from __future__ import print_function ++ ++import re ++ ++from grit import lazy_re ++from grit import tclib ++ ++ACCENTED_STRINGS = { ++ 'a': u"\u00e5", 'e': u"\u00e9", 'i': u"\u00ee", 'o': u"\u00f6", ++ 'u': u"\u00fb", 'A': u"\u00c5", 'E': u"\u00c9", 'I': u"\u00ce", ++ 'O': u"\u00d6", 'U': u"\u00db", 'c': u"\u00e7", 'd': u"\u00f0", ++ 'n': u"\u00f1", 'p': u"\u00fe", 'y': u"\u00fd", 'C': u"\u00c7", ++ 'D': u"\u00d0", 'N': u"\u00d1", 'P': u"\u00de", 'Y': u"\u00dd", ++ 'f': u"\u0192", 's': u"\u0161", 'S': u"\u0160", 'z': u"\u017e", ++ 'Z': u"\u017d", 'g': u"\u011d", 'G': u"\u011c", 'h': u"\u0125", ++ 'H': u"\u0124", 'j': u"\u0135", 'J': u"\u0134", 'k': u"\u0137", ++ 'K': u"\u0136", 'l': u"\u013c", 'L': u"\u013b", 't': u"\u0163", ++ 'T': u"\u0162", 'w': u"\u0175", 'W': u"\u0174", ++ '$': u"\u20ac", '?': u"\u00bf", 'R': u"\u00ae", r'!': u"\u00a1", ++} ++ ++# a character set containing the keys in ACCENTED_STRINGS ++# We should not accent characters in an escape sequence such as "\n". ++# To be safe, we assume every character following a backslash is an escaped ++# character. We also need to consider the case like "\\n", which means ++# a blackslash and a character "n", we will accent the character "n". ++TO_ACCENT = lazy_re.compile( ++ r'[%s]|\\[a-z\\]' % ''.join(ACCENTED_STRINGS.keys())) ++ ++# Lex text so that we don't interfere with html tokens and entities. ++# This lexing scheme will handle all well formed tags and entities, html or ++# xhtml. It will not handle comments, CDATA sections, or the unescaping tags: ++# script, style, xmp or listing. If any of those appear in messages, ++# something is wrong. ++TOKENS = [ lazy_re.compile( ++ '^%s' % pattern, # match at the beginning of input ++ re.I | re.S # html tokens are case-insensitive ++ ) ++ for pattern in ++ ( ++ # a run of non html special characters ++ r'[^<&]+', ++ # a tag ++ (r'</?[a-z]\w*' # beginning of tag ++ r'(?:\s+\w+(?:\s*=\s*' # attribute start ++ r'(?:[^\s"\'>]+|"[^\"]*"|\'[^\']*\'))?' # attribute value ++ r')*\s*/?>'), ++ # an entity ++ r'&(?:[a-z]\w+|#\d+|#x[\da-f]+);', ++ # an html special character not part of a special sequence ++ r'.' ++ ) ] ++ ++ALPHABETIC_RUN = lazy_re.compile(r'([^\W0-9_]+)') ++ ++RLO = u'\u202e' ++PDF = u'\u202c' ++ ++def PseudoRTLString(text): ++ '''Returns a fake bidirectional version of the source string. This code is ++ based on accentString above, in turn copied from Frank Tang. ++ ''' ++ parts = [] ++ while text: ++ m = None ++ for token in TOKENS: ++ m = token.search(text) ++ if m: ++ part = m.group(0) ++ text = text[len(part):] ++ if part[0] not in ('<', '&'): ++ # not a tag or entity, so accent ++ part = ALPHABETIC_RUN.sub(lambda run: RLO + run.group() + PDF, part) ++ parts.append(part) ++ break ++ return ''.join(parts) ++ ++ ++def PseudoRTLMessage(message): ++ '''Returns a pseudo-RTL (aka Fake-Bidi) translation of the provided message. ++ ++ Args: ++ message: tclib.Message() ++ ++ Return: ++ tclib.Translation() ++ ''' ++ transl = tclib.Translation() ++ for part in message.GetContent(): ++ if isinstance(part, tclib.Placeholder): ++ transl.AppendPlaceholder(part) ++ else: ++ transl.AppendText(PseudoRTLString(part)) ++ ++ return transl +diff --git a/tools/grit/grit/pseudo_unittest.py b/tools/grit/grit/pseudo_unittest.py +new file mode 100644 +index 0000000000..b1d53ff401 +--- /dev/null ++++ b/tools/grit/grit/pseudo_unittest.py +@@ -0,0 +1,55 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for grit.pseudo''' ++ ++from __future__ import print_function ++ ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '..')) ++ ++import unittest ++ ++from grit import pseudo ++from grit import tclib ++ ++ ++class PseudoUnittest(unittest.TestCase): ++ def testVowelMapping(self): ++ self.failUnless(pseudo.MapVowels('abebibobuby') == ++ u'\u00e5b\u00e9b\u00efb\u00f4b\u00fcb\u00fd') ++ self.failUnless(pseudo.MapVowels('ABEBIBOBUBY') == ++ u'\u00c5B\u00c9B\u00cfB\u00d4B\u00dcB\u00dd') ++ ++ def testPseudoString(self): ++ out = pseudo.PseudoString('hello') ++ self.failUnless(out == pseudo.MapVowels(u'hePelloPo', True)) ++ ++ def testConsecutiveVowels(self): ++ out = pseudo.PseudoString("beautiful weather, ain't it?") ++ self.failUnless(out == pseudo.MapVowels( ++ u"beauPeautiPifuPul weaPeathePer, aiPain't iPit?", 1)) ++ ++ def testCapitals(self): ++ out = pseudo.PseudoString("HOWDIE DOODIE, DR. JONES") ++ self.failUnless(out == pseudo.MapVowels( ++ u"HOPOWDIEPIE DOOPOODIEPIE, DR. JOPONEPES", 1)) ++ ++ def testPseudoMessage(self): ++ msg = tclib.Message(text='Hello USERNAME, how are you?', ++ placeholders=[ ++ tclib.Placeholder('USERNAME', '%s', 'Joi')]) ++ trans = pseudo.PseudoMessage(msg) ++ # TODO(joi) It would be nicer if 'you' -> 'youPou' instead of ++ # 'you' -> 'youPyou' and if we handled the silent e in 'are' ++ self.failUnless(trans.GetPresentableContent() == ++ pseudo.MapVowels( ++ u'HePelloPo USERNAME, hoPow aParePe youPyou?', 1)) ++ ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/shortcuts.py b/tools/grit/grit/shortcuts.py +new file mode 100644 +index 0000000000..0db2ce436c +--- /dev/null ++++ b/tools/grit/grit/shortcuts.py +@@ -0,0 +1,93 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Stuff to prevent conflicting shortcuts. ++''' ++ ++from __future__ import print_function ++ ++from grit import lazy_re ++ ++ ++class ShortcutGroup(object): ++ '''Manages a list of cliques that belong together in a single shortcut ++ group. Knows how to detect conflicting shortcut keys. ++ ''' ++ ++ # Matches shortcut keys, e.g. &J ++ SHORTCUT_RE = lazy_re.compile('([^&]|^)(&[A-Za-z])') ++ ++ def __init__(self, name): ++ self.name = name ++ # Map of language codes to shortcut keys used (which is a map of ++ # shortcut keys to counts). ++ self.keys_by_lang = {} ++ # List of cliques in this group ++ self.cliques = [] ++ ++ def AddClique(self, c): ++ for existing_clique in self.cliques: ++ if existing_clique.GetId() == c.GetId(): ++ # This happens e.g. when we have e.g. ++ # <if expr1><structure 1></if> <if expr2><structure 2></if> ++ # where only one will really be included in the output. ++ return ++ ++ self.cliques.append(c) ++ for (lang, msg) in c.clique.items(): ++ if lang not in self.keys_by_lang: ++ self.keys_by_lang[lang] = {} ++ keymap = self.keys_by_lang[lang] ++ ++ content = msg.GetRealContent() ++ keys = [groups[1] for groups in self.SHORTCUT_RE.findall(content)] ++ for key in keys: ++ key = key.upper() ++ if key in keymap: ++ keymap[key] += 1 ++ else: ++ keymap[key] = 1 ++ ++ def GenerateWarnings(self, tc_project): ++ # For any language that has more than one occurrence of any shortcut, ++ # make a list of the conflicting shortcuts. ++ problem_langs = {} ++ for (lang, keys) in self.keys_by_lang.items(): ++ for (key, count) in keys.items(): ++ if count > 1: ++ if lang not in problem_langs: ++ problem_langs[lang] = [] ++ problem_langs[lang].append(key) ++ ++ warnings = [] ++ if len(problem_langs): ++ warnings.append("WARNING - duplicate keys exist in shortcut group %s" % ++ self.name) ++ for (lang,keys) in problem_langs.items(): ++ warnings.append(" %6s duplicates: %s" % (lang, ', '.join(keys))) ++ return warnings ++ ++ ++def GenerateDuplicateShortcutsWarnings(uberclique, tc_project): ++ '''Given an UberClique and a project name, will print out helpful warnings ++ if there are conflicting shortcuts within shortcut groups in the provided ++ UberClique. ++ ++ Args: ++ uberclique: clique.UberClique() ++ tc_project: 'MyProjectNameInTheTranslationConsole' ++ ++ Returns: ++ ['warning line 1', 'warning line 2', ...] ++ ''' ++ warnings = [] ++ groups = {} ++ for c in uberclique.AllCliques(): ++ for group in c.shortcut_groups: ++ if group not in groups: ++ groups[group] = ShortcutGroup(group) ++ groups[group].AddClique(c) ++ for group in groups.values(): ++ warnings += group.GenerateWarnings(tc_project) ++ return warnings +diff --git a/tools/grit/grit/shortcuts_unittest.py b/tools/grit/grit/shortcuts_unittest.py +new file mode 100644 +index 0000000000..30e7c4f758 +--- /dev/null ++++ b/tools/grit/grit/shortcuts_unittest.py +@@ -0,0 +1,79 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for grit.shortcuts ++''' ++ ++from __future__ import print_function ++ ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '..')) ++ ++import unittest ++ ++from six import StringIO ++ ++from grit import shortcuts ++from grit import clique ++from grit import tclib ++from grit.gather import rc ++ ++class ShortcutsUnittest(unittest.TestCase): ++ ++ def setUp(self): ++ self.uq = clique.UberClique() ++ ++ def testFunctionality(self): ++ c = self.uq.MakeClique(tclib.Message(text="Hello &there")) ++ c.AddToShortcutGroup('group_name') ++ c = self.uq.MakeClique(tclib.Message(text="Howdie &there partner")) ++ c.AddToShortcutGroup('group_name') ++ ++ warnings = shortcuts.GenerateDuplicateShortcutsWarnings(self.uq, 'PROJECT') ++ self.failUnless(warnings) ++ ++ def testAmpersandEscaping(self): ++ c = self.uq.MakeClique(tclib.Message(text="Hello &there")) ++ c.AddToShortcutGroup('group_name') ++ c = self.uq.MakeClique(tclib.Message(text="S&&T are the &letters S and T")) ++ c.AddToShortcutGroup('group_name') ++ ++ warnings = shortcuts.GenerateDuplicateShortcutsWarnings(self.uq, 'PROJECT') ++ self.failUnless(len(warnings) == 0) ++ ++ def testDialog(self): ++ dlg = rc.Dialog(StringIO('''\ ++IDD_SIDEBAR_RSS_PANEL_PROPPAGE DIALOGEX 0, 0, 239, 221 ++STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD ++FONT 8, "MS Shell Dlg", 400, 0, 0x1 ++BEGIN ++ PUSHBUTTON "Add &URL",IDC_SIDEBAR_RSS_ADD_URL,182,53,57,14 ++ EDITTEXT IDC_SIDEBAR_RSS_NEW_URL,0,53,178,15,ES_AUTOHSCROLL ++ PUSHBUTTON "&Remove",IDC_SIDEBAR_RSS_REMOVE,183,200,56,14 ++ PUSHBUTTON "&Edit",IDC_SIDEBAR_RSS_EDIT,123,200,56,14 ++ CONTROL "&Automatically add commonly viewed clips", ++ IDC_SIDEBAR_RSS_AUTO_ADD,"Button",BS_AUTOCHECKBOX | ++ BS_MULTILINE | WS_TABSTOP,0,200,120,17 ++ PUSHBUTTON "",IDC_SIDEBAR_RSS_HIDDEN,179,208,6,6,NOT WS_VISIBLE ++ LTEXT "You can display clips from blogs, news sites, and other online sources.", ++ IDC_STATIC,0,0,239,10 ++ LISTBOX IDC_SIDEBAR_DISPLAYED_FEED_LIST,0,69,239,127,LBS_SORT | ++ LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | ++ LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_HSCROLL | ++ WS_TABSTOP ++ LTEXT "Add a clip from a recently viewed website by clicking Add Recent Clips.", ++ IDC_STATIC,0,13,141,19 ++ LTEXT "Or, if you know a site supports RSS or Atom, you can enter the RSS or Atom URL below and add it to your list of Web Clips.", ++ IDC_STATIC,0,33,239,18 ++ PUSHBUTTON "Add Recent &Clips (10)...", ++ IDC_SIDEBAR_RSS_ADD_RECENT_CLIPS,146,14,93,14 ++END'''), 'IDD_SIDEBAR_RSS_PANEL_PROPPAGE') ++ dlg.SetUberClique(self.uq) ++ dlg.Parse() ++ ++ warnings = shortcuts.GenerateDuplicateShortcutsWarnings(self.uq, 'PROJECT') ++ self.failUnless(len(warnings) == 0) ++ +diff --git a/tools/grit/grit/tclib.py b/tools/grit/grit/tclib.py +new file mode 100644 +index 0000000000..27ba366924 +--- /dev/null ++++ b/tools/grit/grit/tclib.py +@@ -0,0 +1,246 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Adaptation of the extern.tclib classes for our needs. ++''' ++ ++from __future__ import print_function ++ ++import functools ++import re ++ ++import six ++ ++from grit import exception ++from grit import lazy_re ++import grit.extern.tclib ++ ++ ++# Matches whitespace sequences which can be folded into a single whitespace ++# character. This matches single characters so that non-spaces are replaced ++# with spaces. ++_FOLD_WHITESPACE = re.compile(r'\s+') ++ ++# Caches compiled regexp used to split tags in BaseMessage.__init__() ++_RE_CACHE = {} ++ ++def Identity(i): ++ return i ++ ++ ++class BaseMessage(object): ++ '''Base class with methods shared by Message and Translation. ++ ''' ++ ++ def __init__(self, text='', placeholders=[], description='', meaning=''): ++ self.parts = [] ++ self.placeholders = [] ++ self.meaning = meaning ++ self.dirty = True # True if self.id is (or might be) wrong ++ self.id = 0 ++ self.SetDescription(description) ++ ++ if text != '': ++ if not placeholders or placeholders == []: ++ self.AppendText(text) ++ else: ++ tag_map = {} ++ for placeholder in placeholders: ++ tag_map[placeholder.GetPresentation()] = [placeholder, 0] ++ # This creates a regexp like '(TAG1|TAG2|TAG3)'. ++ # The tags have to be sorted in order of decreasing length, so that ++ # longer tags are substituted before shorter tags that happen to be ++ # substrings of the longer tag. ++ # E.g. "EXAMPLE_FOO_NAME" must be matched before "EXAMPLE_FOO", ++ # otherwise "EXAMPLE_FOO" splits "EXAMPLE_FOO_NAME" too. ++ tags = sorted(tag_map.keys(), ++ key=functools.cmp_to_key( ++ lambda x, y: len(x) - len(y) or ((x > y) - (x < y))), ++ reverse=True) ++ tag_re = '(' + '|'.join(tags) + ')' ++ ++ # This caching improves the time to build ++ # chrome/app:generated_resources from 21.562s to 17.672s on Linux. ++ compiled_re = _RE_CACHE.get(tag_re, None) ++ if compiled_re is None: ++ compiled_re = re.compile(tag_re) ++ _RE_CACHE[tag_re] = compiled_re ++ ++ chunked_text = compiled_re.split(text) ++ ++ for chunk in chunked_text: ++ if chunk: # ignore empty chunk ++ if chunk in tag_map: ++ self.AppendPlaceholder(tag_map[chunk][0]) ++ tag_map[chunk][1] += 1 # increase placeholder use count ++ else: ++ self.AppendText(chunk) ++ for key in tag_map: ++ assert tag_map[key][1] != 0 ++ ++ def GetRealContent(self, escaping_function=Identity): ++ '''Returns the original content, i.e. what your application and users ++ will see. ++ ++ Specify a function to escape each translateable bit, if you like. ++ ''' ++ bits = [] ++ for item in self.parts: ++ if isinstance(item, six.string_types): ++ bits.append(escaping_function(item)) ++ else: ++ bits.append(item.GetOriginal()) ++ return ''.join(bits) ++ ++ def GetPresentableContent(self): ++ presentable_content = [] ++ for part in self.parts: ++ if isinstance(part, Placeholder): ++ presentable_content.append(part.GetPresentation()) ++ else: ++ presentable_content.append(part) ++ return ''.join(presentable_content) ++ ++ def AppendPlaceholder(self, placeholder): ++ assert isinstance(placeholder, Placeholder) ++ dup = False ++ for other in self.GetPlaceholders(): ++ if other.presentation == placeholder.presentation: ++ assert other.original == placeholder.original ++ dup = True ++ ++ if not dup: ++ self.placeholders.append(placeholder) ++ self.parts.append(placeholder) ++ self.dirty = True ++ ++ def AppendText(self, text): ++ assert isinstance(text, six.string_types) ++ assert text != '' ++ ++ self.parts.append(text) ++ self.dirty = True ++ ++ def GetContent(self): ++ '''Returns the parts of the message. You may modify parts if you wish. ++ Note that you must not call GetId() on this object until you have finished ++ modifying the contents. ++ ''' ++ self.dirty = True # user might modify content ++ return self.parts ++ ++ def GetDescription(self): ++ return self.description ++ ++ def SetDescription(self, description): ++ self.description = _FOLD_WHITESPACE.sub(' ', description) ++ ++ def GetMeaning(self): ++ return self.meaning ++ ++ def GetId(self): ++ if self.dirty: ++ self.id = self.GenerateId() ++ self.dirty = False ++ return self.id ++ ++ def GenerateId(self): ++ return grit.extern.tclib.GenerateMessageId(self.GetPresentableContent(), ++ self.meaning) ++ ++ def GetPlaceholders(self): ++ return self.placeholders ++ ++ def FillTclibBaseMessage(self, msg): ++ msg.SetDescription(self.description.encode('utf-8')) ++ ++ for part in self.parts: ++ if isinstance(part, Placeholder): ++ ph = grit.extern.tclib.Placeholder( ++ part.presentation.encode('utf-8'), ++ part.original.encode('utf-8'), ++ part.example.encode('utf-8')) ++ msg.AppendPlaceholder(ph) ++ else: ++ msg.AppendText(part.encode('utf-8')) ++ ++ ++class Message(BaseMessage): ++ '''A message.''' ++ ++ def __init__(self, text='', placeholders=[], description='', meaning='', ++ assigned_id=None): ++ super(Message, self).__init__(text, placeholders, description, meaning) ++ self.assigned_id = assigned_id ++ ++ def ToTclibMessage(self): ++ msg = grit.extern.tclib.Message('utf-8', meaning=self.meaning) ++ self.FillTclibBaseMessage(msg) ++ return msg ++ ++ def GetId(self): ++ '''Use the assigned id if we have one.''' ++ if self.assigned_id: ++ return self.assigned_id ++ ++ return super(Message, self).GetId() ++ ++ def HasAssignedId(self): ++ '''Returns True if this message has an assigned id.''' ++ return bool(self.assigned_id) ++ ++ ++class Translation(BaseMessage): ++ '''A translation.''' ++ ++ def __init__(self, text='', id='', placeholders=[], description='', meaning=''): ++ super(Translation, self).__init__(text, placeholders, description, meaning) ++ self.id = id ++ ++ def GetId(self): ++ assert id != '', "ID has not been set." ++ return self.id ++ ++ def SetId(self, id): ++ self.id = id ++ ++ def ToTclibMessage(self): ++ msg = grit.extern.tclib.Message( ++ 'utf-8', id=self.id, meaning=self.meaning) ++ self.FillTclibBaseMessage(msg) ++ return msg ++ ++ ++class Placeholder(grit.extern.tclib.Placeholder): ++ '''Modifies constructor to accept a Unicode string ++ ''' ++ ++ # Must match placeholder presentation names ++ _NAME_RE = lazy_re.compile('^[A-Za-z0-9_]+$') ++ ++ def __init__(self, presentation, original, example): ++ '''Creates a new placeholder. ++ ++ Args: ++ presentation: 'USERNAME' ++ original: '%s' ++ example: 'Joi' ++ ''' ++ assert presentation != '' ++ assert original != '' ++ assert example != '' ++ if not self._NAME_RE.match(presentation): ++ raise exception.InvalidPlaceholderName(presentation) ++ self.presentation = presentation ++ self.original = original ++ self.example = example ++ ++ def GetPresentation(self): ++ return self.presentation ++ ++ def GetOriginal(self): ++ return self.original ++ ++ def GetExample(self): ++ return self.example +diff --git a/tools/grit/grit/tclib_unittest.py b/tools/grit/grit/tclib_unittest.py +new file mode 100644 +index 0000000000..7a08654e1b +--- /dev/null ++++ b/tools/grit/grit/tclib_unittest.py +@@ -0,0 +1,180 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for grit.tclib''' ++ ++from __future__ import print_function ++ ++import sys ++import os.path ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '..')) ++ ++import unittest ++ ++import six ++ ++from grit import tclib ++ ++from grit import exception ++import grit.extern.tclib ++ ++ ++class TclibUnittest(unittest.TestCase): ++ def testInit(self): ++ msg = tclib.Message(text=u'Hello Earthlings', ++ description='Greetings\n\t message') ++ self.failUnlessEqual(msg.GetPresentableContent(), 'Hello Earthlings') ++ self.failUnless(isinstance(msg.GetPresentableContent(), six.string_types)) ++ self.failUnlessEqual(msg.GetDescription(), 'Greetings message') ++ ++ def testGetAttr(self): ++ msg = tclib.Message() ++ msg.AppendText(u'Hello') # Tests __getattr__ ++ self.failUnless(msg.GetPresentableContent() == 'Hello') ++ self.failUnless(isinstance(msg.GetPresentableContent(), six.string_types)) ++ ++ def testAll(self): ++ text = u'Howdie USERNAME' ++ phs = [tclib.Placeholder(u'USERNAME', u'%s', 'Joi')] ++ msg = tclib.Message(text=text, placeholders=phs) ++ self.failUnless(msg.GetPresentableContent() == 'Howdie USERNAME') ++ ++ trans = tclib.Translation(text=text, placeholders=phs) ++ self.failUnless(trans.GetPresentableContent() == 'Howdie USERNAME') ++ self.failUnless(isinstance(trans.GetPresentableContent(), six.string_types)) ++ ++ def testUnicodeReturn(self): ++ text = u'\u00fe' ++ msg = tclib.Message(text=text) ++ self.failUnless(msg.GetPresentableContent() == text) ++ from_list = msg.GetContent()[0] ++ self.failUnless(from_list == text) ++ ++ def testRegressionTranslationInherited(self): ++ '''Regression tests a bug that was caused by grit.tclib.Translation ++ inheriting from the translation console's Translation object ++ instead of only owning an instance of it. ++ ''' ++ msg = tclib.Message(text=u"BLA1\r\nFrom: BLA2 \u00fe BLA3", ++ placeholders=[ ++ tclib.Placeholder('BLA1', '%s', '%s'), ++ tclib.Placeholder('BLA2', '%s', '%s'), ++ tclib.Placeholder('BLA3', '%s', '%s')]) ++ transl = tclib.Translation(text=msg.GetPresentableContent(), ++ placeholders=msg.GetPlaceholders()) ++ content = transl.GetContent() ++ self.failUnless(isinstance(content[3], six.string_types)) ++ ++ def testFingerprint(self): ++ # This has Windows line endings. That is on purpose. ++ id = grit.extern.tclib.GenerateMessageId( ++ 'Google Desktop for Enterprise\r\n' ++ 'All Rights Reserved\r\n' ++ '\r\n' ++ '---------\r\n' ++ 'Contents\r\n' ++ '---------\r\n' ++ 'This distribution contains the following files:\r\n' ++ '\r\n' ++ 'GoogleDesktopSetup.msi - Installation and setup program\r\n' ++ 'GoogleDesktop.adm - Group Policy administrative template file\r\n' ++ 'AdminGuide.pdf - Google Desktop for Enterprise administrative guide\r\n' ++ '\r\n' ++ '\r\n' ++ '--------------\r\n' ++ 'Documentation\r\n' ++ '--------------\r\n' ++ 'Full documentation and installation instructions are in the \r\n' ++ 'administrative guide, and also online at \r\n' ++ 'http://desktop.google.com/enterprise/adminguide.html.\r\n' ++ '\r\n' ++ '\r\n' ++ '------------------------\r\n' ++ 'IBM Lotus Notes Plug-In\r\n' ++ '------------------------\r\n' ++ 'The Lotus Notes plug-in is included in the release of Google \r\n' ++ 'Desktop for Enterprise. The IBM Lotus Notes Plug-in for Google \r\n' ++ 'Desktop indexes mail, calendar, task, contact and journal \r\n' ++ 'documents from Notes. Discussion documents including those from \r\n' ++ 'the discussion and team room templates can also be indexed by \r\n' ++ 'selecting an option from the preferences. Once indexed, this data\r\n' ++ 'will be returned in Google Desktop searches. The corresponding\r\n' ++ 'document can be opened in Lotus Notes from the Google Desktop \r\n' ++ 'results page.\r\n' ++ '\r\n' ++ 'Install: The plug-in will install automatically during the Google \r\n' ++ 'Desktop setup process if Lotus Notes is already installed. Lotus \r\n' ++ 'Notes must not be running in order for the install to occur. \r\n' ++ '\r\n' ++ 'Preferences: Preferences and selection of databases to index are\r\n' ++ 'set in the \'Google Desktop for Notes\' dialog reached through the \r\n' ++ '\'Actions\' menu.\r\n' ++ '\r\n' ++ 'Reindexing: Selecting \'Reindex all databases\' will index all the \r\n' ++ 'documents in each database again.\r\n' ++ '\r\n' ++ '\r\n' ++ 'Notes Plug-in Known Issues\r\n' ++ '---------------------------\r\n' ++ '\r\n' ++ 'If the \'Google Desktop for Notes\' item is not available from the \r\n' ++ 'Lotus Notes Actions menu, then installation was not successful. \r\n' ++ 'Installation consists of writing one file, notesgdsplugin.dll, to \r\n' ++ 'the Notes application directory and a setting to the notes.ini \r\n' ++ 'configuration file. The most likely cause of an unsuccessful \r\n' ++ 'installation is that the installer was not able to locate the \r\n' ++ 'notes.ini file. Installation will complete if the user closes Notes\r\n' ++ 'and manually adds the following setting to this file on a new line:\r\n' ++ 'AddinMenus=notegdsplugin.dll\r\n' ++ '\r\n' ++ 'If the notesgdsplugin.dll file is not in the application directory\r\n' ++ r'(e.g., C:\Program Files\Lotus\Notes) after Google Desktop \r\n' ++ 'installation, it is likely that Notes was not installed correctly. \r\n' ++ '\r\n' ++ 'Only local databases can be indexed. If they can be determined, \r\n' ++ 'the user\'s local mail file and address book will be included in the\r\n' ++ 'list automatically. Mail archives and other databases must be \r\n' ++ 'added with the \'Add\' button.\r\n' ++ '\r\n' ++ 'Some users may experience performance issues during the initial \r\n' ++ 'indexing of a database. The \'Perform the initial index of a \r\n' ++ 'database only when I\'m idle\' option will limit the indexing process\r\n' ++ 'to times when the user is not using the machine. If this does not \r\n' ++ 'alleviate the problem or the user would like to continually index \r\n' ++ 'but just do so more slowly or quickly, the GoogleWaitTime notes.ini\r\n' ++ 'value can be set. Increasing the GoogleWaitTime value will slow \r\n' ++ 'down the indexing process, and lowering the value will speed it up.\r\n' ++ 'A value of zero causes the fastest possible indexing. Removing the\r\n' ++ 'ini parameter altogether returns it to the default (20).\r\n' ++ '\r\n' ++ 'Crashes have been known to occur with certain types of history \r\n' ++ 'bookmarks. If the Notes client seems to crash randomly, try \r\n' ++ 'disabling the \'Index note history\' option. If it crashes before,\r\n' ++ 'you can get to the preferences, add the following line to your \r\n' ++ 'notes.ini file:\r\n' ++ 'GDSNoIndexHistory=1\r\n') ++ self.assertEqual(id, '7660964495923572726') ++ ++ def testPlaceholderNameChecking(self): ++ try: ++ ph = tclib.Placeholder('BINGO BONGO', 'bla', 'bla') ++ raise Exception("We shouldn't get here") ++ except exception.InvalidPlaceholderName: ++ pass # Expect exception to be thrown because presentation contained space ++ ++ def testTagsWithCommonSubstring(self): ++ word = 'ABCDEFGHIJ' ++ text = ' '.join([word[:i] for i in range(1, 11)]) ++ phs = [tclib.Placeholder(word[:i], str(i), str(i)) for i in range(1, 11)] ++ try: ++ msg = tclib.Message(text=text, placeholders=phs) ++ self.failUnless(msg.GetRealContent() == '1 2 3 4 5 6 7 8 9 10') ++ except: ++ self.fail('tclib.Message() should handle placeholders that are ' ++ 'substrings of each other') ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/test_suite_all.py b/tools/grit/grit/test_suite_all.py +new file mode 100644 +index 0000000000..3bfe2a79d5 +--- /dev/null ++++ b/tools/grit/grit/test_suite_all.py +@@ -0,0 +1,34 @@ ++#!/usr/bin/env python3 ++# Copyright (c) 2011 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit test suite that collects all test cases for GRIT.''' ++ ++from __future__ import print_function + -+#endif // MISSING_CTOR_H_ -diff --git a/tools/clang/plugins/tests/missing_ctor.txt b/tools/clang/plugins/tests/missing_ctor.txt ++import os ++import sys ++ ++ ++CUR_DIR = os.path.dirname(os.path.realpath(__file__)) ++SRC_DIR = os.path.dirname(os.path.dirname(os.path.dirname(CUR_DIR))) ++TYP_DIR = os.path.join( ++ SRC_DIR, 'third_party', 'catapult', 'third_party', 'typ') ++ ++if TYP_DIR not in sys.path: ++ sys.path.insert(0, TYP_DIR) ++ ++ ++import typ # pylint: disable=import-error,unused-import ++ ++ ++def main(args): ++ return typ.main( ++ top_level_dirs=[os.path.join(CUR_DIR, '..')], ++ skip=['grit.format.gen_predetermined_ids_unittest.*', ++ 'grit.pseudo_unittest.*'] ++ ) ++ ++if __name__ == '__main__': ++ sys.exit(main(sys.argv[1:])) +diff --git a/tools/grit/grit/testdata/GoogleDesktop.adm b/tools/grit/grit/testdata/GoogleDesktop.adm +new file mode 100644 +index 0000000000..082f56bb1a +--- /dev/null ++++ b/tools/grit/grit/testdata/GoogleDesktop.adm +@@ -0,0 +1,945 @@ ++CLASS MACHINE ++ CATEGORY !!Cat_Google ++ CATEGORY !!Cat_GoogleDesktopSearch ++ KEYNAME "Software\Policies\Google\Google Desktop" ++ ++ CATEGORY !!Cat_Preferences ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences" ++ ++ CATEGORY !!Cat_IndexAndCaptureControl ++ POLICY !!Blacklist_Email ++ EXPLAIN !!Explain_Blacklist_Email ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-1" ++ VALUENAME "1" ++ END POLICY ++ ++ POLICY !!Blacklist_Gmail ++ EXPLAIN !!Explain_Blacklist_Gmail ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-pop" ++ VALUENAME "gmail" ++ END POLICY ++ ++ POLICY !!Blacklist_WebHistory ++ EXPLAIN !!Explain_Blacklist_WebHistory ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-1" ++ VALUENAME "2" ++ END POLICY ++ ++ POLICY !!Blacklist_Chat ++ EXPLAIN !!Explain_Blacklist_Chat ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-1" ++ ACTIONLISTON ++ VALUENAME "3" VALUE NUMERIC 1 ++ END ACTIONLISTON ++ END POLICY ++ ++ POLICY !!Blacklist_Text ++ EXPLAIN !!Explain_Blacklist_Text ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-1" ++ ACTIONLISTON ++ VALUENAME "4" VALUE NUMERIC 1 ++ END ACTIONLISTON ++ END POLICY ++ ++ POLICY !!Blacklist_Media ++ EXPLAIN !!Explain_Blacklist_Media ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-1" ++ ACTIONLISTON ++ VALUENAME "5" VALUE NUMERIC 1 ++ END ACTIONLISTON ++ END POLICY ++ ++ POLICY !!Blacklist_Contact ++ EXPLAIN !!Explain_Blacklist_Contact ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-1" ++ ACTIONLISTON ++ VALUENAME "9" VALUE NUMERIC 1 ++ END ACTIONLISTON ++ END POLICY ++ ++ POLICY !!Blacklist_Calendar ++ EXPLAIN !!Explain_Blacklist_Calendar ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-1" ++ ACTIONLISTON ++ VALUENAME "10" VALUE NUMERIC 1 ++ END ACTIONLISTON ++ END POLICY ++ ++ POLICY !!Blacklist_Task ++ EXPLAIN !!Explain_Blacklist_Task ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-1" ++ ACTIONLISTON ++ VALUENAME "11" VALUE NUMERIC 1 ++ END ACTIONLISTON ++ END POLICY ++ ++ POLICY !!Blacklist_Note ++ EXPLAIN !!Explain_Blacklist_Note ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-1" ++ ACTIONLISTON ++ VALUENAME "12" VALUE NUMERIC 1 ++ END ACTIONLISTON ++ END POLICY ++ ++ POLICY !!Blacklist_Journal ++ EXPLAIN !!Explain_Blacklist_Journal ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-1" ++ ACTIONLISTON ++ VALUENAME "13" VALUE NUMERIC 1 ++ END ACTIONLISTON ++ END POLICY ++ ++ POLICY !!Blacklist_Word ++ EXPLAIN !!Explain_Blacklist_Word ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-2" ++ VALUENAME "DOC" ++ END POLICY ++ ++ POLICY !!Blacklist_Excel ++ EXPLAIN !!Explain_Blacklist_Excel ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-2" ++ VALUENAME "XLS" ++ END POLICY ++ ++ POLICY !!Blacklist_Powerpoint ++ EXPLAIN !!Explain_Blacklist_Powerpoint ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-2" ++ VALUENAME "PPT" ++ END POLICY ++ ++ POLICY !!Blacklist_PDF ++ EXPLAIN !!Explain_Blacklist_PDF ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-2" ++ VALUENAME "PDF" ++ END POLICY ++ ++ POLICY !!Blacklist_ZIP ++ EXPLAIN !!Explain_Blacklist_ZIP ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-2" ++ VALUENAME "ZIP" ++ END POLICY ++ ++ POLICY !!Blacklist_HTTPS ++ EXPLAIN !!Explain_Blacklist_HTTPS ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-3" ++ VALUENAME "HTTPS" ++ END POLICY ++ ++ POLICY !!Blacklist_PasswordProtectedOffice ++ EXPLAIN !!Explain_Blacklist_PasswordProtectedOffice ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-13" ++ VALUENAME "SECUREOFFICE" ++ END POLICY ++ ++ POLICY !!Blacklist_URI_Contains ++ EXPLAIN !!Explain_Blacklist_URI_Contains ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-6" ++ PART !!Blacklist_URI_Contains LISTBOX ++ END PART ++ END POLICY ++ ++ POLICY !!Blacklist_Extensions ++ EXPLAIN !!Explain_Blacklist_Extensions ++ PART !!Blacklist_Extensions EDITTEXT ++ VALUENAME "file_extensions_to_skip" ++ END PART ++ END POLICY ++ ++ POLICY !!Pol_Disallow_UserSearchLocations ++ EXPLAIN !!Explain_Disallow_UserSearchLocations ++ VALUENAME user_search_locations ++ VALUEON NUMERIC 1 ++ END POLICY ++ ++ POLICY !!Pol_Search_Location_Whitelist ++ EXPLAIN !!Explain_Search_Location_Whitelist ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\policy_search_location_whitelist" ++ PART !!Search_Locations_Whitelist LISTBOX ++ END PART ++ END POLICY ++ ++ POLICY !!Email_Retention ++ EXPLAIN !!Explain_Email_Retention ++ PART !!Email_Retention_Edit NUMERIC ++ VALUENAME "email_days_to_retain" ++ MIN 1 MAX 65535 DEFAULT 30 SPIN 1 ++ END PART ++ END POLICY ++ ++ POLICY !!Webpage_Retention ++ EXPLAIN !!Explain_Webpage_Retention ++ PART !!Webpage_Retention_Edit NUMERIC ++ VALUENAME "webpage_days_to_retain" ++ MIN 1 MAX 65535 DEFAULT 30 SPIN 1 ++ END PART ++ END POLICY ++ ++ POLICY !!File_Retention ++ EXPLAIN !!Explain_File_Retention ++ PART !!File_Retention_Edit NUMERIC ++ VALUENAME "file_days_to_retain" ++ MIN 1 MAX 65535 DEFAULT 30 SPIN 1 ++ END PART ++ END POLICY ++ ++ POLICY !!IM_Retention ++ EXPLAIN !!Explain_IM_Retention ++ PART !!IM_Retention_Edit NUMERIC ++ VALUENAME "im_days_to_retain" ++ MIN 1 MAX 65535 DEFAULT 30 SPIN 1 ++ END PART ++ END POLICY ++ ++ POLICY !!Pol_Remove_Deleted_Items ++ EXPLAIN !!Explain_Remove_Deleted_Items ++ VALUENAME remove_deleted_items ++ VALUEON NUMERIC 1 ++ END POLICY ++ ++ POLICY !!Pol_Allow_Simultaneous_Indexing ++ EXPLAIN !!Explain_Allow_Simultaneous_Indexing ++ VALUENAME simultaneous_indexing ++ VALUEON NUMERIC 1 ++ END POLICY ++ ++ END CATEGORY ++ ++ POLICY !!Pol_TurnOffAdvancedFeatures ++ EXPLAIN !!Explain_TurnOffAdvancedFeatures ++ VALUENAME error_report_on ++ VALUEON NUMERIC 0 ++ END POLICY ++ ++ POLICY !!Pol_TurnOffImproveGd ++ EXPLAIN !!Explain_TurnOffImproveGd ++ VALUENAME improve_gd ++ VALUEON NUMERIC 0 ++ VALUEOFF NUMERIC 1 ++ END POLICY ++ ++ POLICY !!Pol_NoPersonalizationInfo ++ EXPLAIN !!Explain_NoPersonalizationInfo ++ VALUENAME send_personalization_info ++ VALUEON NUMERIC 0 ++ VALUEOFF NUMERIC 1 ++ END POLICY ++ ++ POLICY !!Pol_OneBoxMode ++ EXPLAIN !!Explain_OneBoxMode ++ VALUENAME onebox_mode ++ VALUEON NUMERIC 0 ++ END POLICY ++ ++ POLICY !!Pol_EncryptIndex ++ EXPLAIN !!Explain_EncryptIndex ++ VALUENAME encrypt_index ++ VALUEON NUMERIC 1 ++ END POLICY ++ ++ POLICY !!Pol_Hyper ++ EXPLAIN !!Explain_Hyper ++ VALUENAME hyper_off ++ VALUEON NUMERIC 1 ++ END POLICY ++ ++ POLICY !!Pol_Display_Mode ++ EXPLAIN !!Explain_Display_Mode ++ PART !!Pol_Display_Mode DROPDOWNLIST ++ VALUENAME display_mode ++ ITEMLIST ++ NAME !!Sidebar VALUE NUMERIC 1 ++ NAME !!Deskbar VALUE NUMERIC 8 ++ NAME !!FloatingDeskbar VALUE NUMERIC 4 ++ NAME !!None VALUE NUMERIC 0 ++ END ITEMLIST ++ END PART ++ END POLICY ++ ++ END CATEGORY ; Preferences ++ ++ CATEGORY !!Cat_Enterprise ++ KEYNAME "Software\Policies\Google\Google Desktop\Enterprise" ++ ++ POLICY !!Pol_Autoupdate ++ EXPLAIN !!Explain_Autoupdate ++ VALUENAME autoupdate_host ++ VALUEON "" ++ END POLICY ++ ++ POLICY !!Pol_AutoupdateAsSystem ++ EXPLAIN !!Explain_AutoupdateAsSystem ++ VALUENAME autoupdate_impersonate_user ++ VALUEON NUMERIC 0 ++ VALUEOFF NUMERIC 1 ++ END POLICY ++ ++ POLICY !!Pol_EnterpriseTab ++ EXPLAIN !!Explain_EnterpriseTab ++ PART !!EnterpriseTabText EDITTEXT ++ VALUENAME enterprise_tab_text ++ END PART ++ PART !!EnterpriseTabHomepage EDITTEXT ++ VALUENAME enterprise_tab_homepage ++ END PART ++ PART !!EnterpriseTabHomepageQuery CHECKBOX ++ VALUENAME enterprise_tab_homepage_query ++ END PART ++ PART !!EnterpriseTabResults EDITTEXT ++ VALUENAME enterprise_tab_results ++ END PART ++ PART !!EnterpriseTabResultsQuery CHECKBOX ++ VALUENAME enterprise_tab_results_query ++ END PART ++ END POLICY ++ ++ POLICY !!Pol_GSAHosts ++ EXPLAIN !!Explain_GSAHosts ++ KEYNAME "Software\Policies\Google\Google Desktop\Enterprise\GSAHosts" ++ PART !!Pol_GSAHosts LISTBOX ++ END PART ++ END POLICY ++ ++ POLICY !!Pol_PolicyUnawareClientProhibitedFlag ++ EXPLAIN !!Explain_PolicyUnawareClientProhibitedFlag ++ KEYNAME "Software\Policies\Google\Google Desktop" ++ VALUENAME PolicyUnawareClientProhibitedFlag ++ END POLICY ++ ++ POLICY !!Pol_MinimumAllowedVersion ++ EXPLAIN !!Explain_MinimumAllowedVersion ++ PART !!Pol_MinimumAllowedVersion EDITTEXT ++ VALUENAME minimum_allowed_version ++ END PART ++ END POLICY ++ ++ POLICY !!Pol_MaximumAllowedVersion ++ EXPLAIN !!Explain_MaximumAllowedVersion ++ PART !!Pol_MaximumAllowedVersion EDITTEXT ++ VALUENAME maximum_allowed_version ++ END PART ++ END POLICY ++ ++ POLICY !!Pol_Disallow_Gadgets ++ EXPLAIN !!Explain_Disallow_Gadgets ++ VALUENAME disallow_gadgets ++ VALUEON NUMERIC 1 ++ PART !!Disallow_Only_Non_Builtin_Gadgets CHECKBOX DEFCHECKED ++ VALUENAME disallow_only_non_builtin_gadgets ++ VALUEON NUMERIC 1 ++ VALUEOFF NUMERIC 0 ++ END PART ++ END POLICY ++ ++ POLICY !!Pol_Gadget_Whitelist ++ EXPLAIN !!Explain_Gadget_Whitelist ++ KEYNAME "Software\Policies\Google\Google Desktop\Enterprise\gadget_whitelist" ++ PART !!Pol_Gadget_Whitelist LISTBOX ++ END PART ++ END POLICY ++ ++ POLICY !!Pol_Gadget_Install_Confirmation_Whitelist ++ EXPLAIN !!Explain_Gadget_Install_Confirmation_Whitelist ++ KEYNAME "Software\Policies\Google\Google Desktop\Enterprise\install_confirmation_whitelist" ++ PART !!Pol_Gadget_Install_Confirmation_Whitelist LISTBOX ++ END PART ++ END POLICY ++ ++ POLICY !!Pol_Alternate_User_Data_Dir ++ EXPLAIN !!Explain_Alternate_User_Data_Dir ++ PART !!Pol_Alternate_User_Data_Dir EDITTEXT ++ VALUENAME alternate_user_data_dir ++ END PART ++ END POLICY ++ ++ POLICY !!Pol_MaxAllowedOutlookConnections ++ EXPLAIN !!Explain_MaxAllowedOutlookConnections ++ PART !!Pol_MaxAllowedOutlookConnections NUMERIC ++ VALUENAME max_allowed_outlook_connections ++ MIN 1 MAX 65535 DEFAULT 400 SPIN 1 ++ END PART ++ END POLICY ++ ++ POLICY !!Pol_DisallowSsdService ++ EXPLAIN !!Explain_DisallowSsdService ++ VALUENAME disallow_ssd_service ++ VALUEON NUMERIC 1 ++ END POLICY ++ ++ POLICY !!Pol_DisallowSsdOutbound ++ EXPLAIN !!Explain_DisallowSsdOutbound ++ VALUENAME disallow_ssd_outbound ++ VALUEON NUMERIC 1 ++ END POLICY ++ ++ POLICY !!Pol_Disallow_Store_Gadget_Service ++ EXPLAIN !!Explain_Disallow_Store_Gadget_Service ++ VALUENAME disallow_store_gadget_service ++ VALUEON NUMERIC 1 ++ END POLICY ++ ++ POLICY !!Pol_MaxExchangeIndexingRate ++ EXPLAIN !!Explain_MaxExchangeIndexingRate ++ PART !!Pol_MaxExchangeIndexingRate NUMERIC ++ VALUENAME max_exchange_indexing_rate ++ MIN 1 MAX 1000 DEFAULT 60 SPIN 1 ++ END PART ++ END POLICY ++ ++ POLICY !!Pol_EnableSafeweb ++ EXPLAIN !!Explain_Safeweb ++ VALUENAME safe_browsing ++ VALUEON NUMERIC 1 ++ VALUEOFF NUMERIC 0 ++ END POLICY ++ ++ END CATEGORY ; Enterprise ++ ++ END CATEGORY ; GoogleDesktopSearch ++ END CATEGORY ; Google ++ ++ ++CLASS USER ++ CATEGORY !!Cat_Google ++ CATEGORY !!Cat_GoogleDesktopSearch ++ KEYNAME "Software\Policies\Google\Google Desktop" ++ ++ CATEGORY !!Cat_Preferences ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences" ++ ++ CATEGORY !!Cat_IndexAndCaptureControl ++ POLICY !!Blacklist_Email ++ EXPLAIN !!Explain_Blacklist_Email ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-1" ++ VALUENAME "1" ++ END POLICY ++ ++ POLICY !!Blacklist_Gmail ++ EXPLAIN !!Explain_Blacklist_Gmail ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-pop" ++ VALUENAME "gmail" ++ END POLICY ++ ++ POLICY !!Blacklist_WebHistory ++ EXPLAIN !!Explain_Blacklist_WebHistory ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-1" ++ VALUENAME "2" ++ END POLICY ++ ++ POLICY !!Blacklist_Chat ++ EXPLAIN !!Explain_Blacklist_Chat ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-1" ++ ACTIONLISTON ++ VALUENAME "3" VALUE NUMERIC 1 ++ END ACTIONLISTON ++ END POLICY ++ ++ POLICY !!Blacklist_Text ++ EXPLAIN !!Explain_Blacklist_Text ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-1" ++ ACTIONLISTON ++ VALUENAME "4" VALUE NUMERIC 1 ++ END ACTIONLISTON ++ END POLICY ++ ++ POLICY !!Blacklist_Media ++ EXPLAIN !!Explain_Blacklist_Media ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-1" ++ ACTIONLISTON ++ VALUENAME "5" VALUE NUMERIC 1 ++ END ACTIONLISTON ++ END POLICY ++ ++ POLICY !!Blacklist_Contact ++ EXPLAIN !!Explain_Blacklist_Contact ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-1" ++ ACTIONLISTON ++ VALUENAME "9" VALUE NUMERIC 1 ++ END ACTIONLISTON ++ END POLICY ++ ++ POLICY !!Blacklist_Calendar ++ EXPLAIN !!Explain_Blacklist_Calendar ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-1" ++ ACTIONLISTON ++ VALUENAME "10" VALUE NUMERIC 1 ++ END ACTIONLISTON ++ END POLICY ++ ++ POLICY !!Blacklist_Task ++ EXPLAIN !!Explain_Blacklist_Task ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-1" ++ ACTIONLISTON ++ VALUENAME "11" VALUE NUMERIC 1 ++ END ACTIONLISTON ++ END POLICY ++ ++ POLICY !!Blacklist_Note ++ EXPLAIN !!Explain_Blacklist_Note ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-1" ++ ACTIONLISTON ++ VALUENAME "12" VALUE NUMERIC 1 ++ END ACTIONLISTON ++ END POLICY ++ ++ POLICY !!Blacklist_Journal ++ EXPLAIN !!Explain_Blacklist_Journal ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-1" ++ ACTIONLISTON ++ VALUENAME "13" VALUE NUMERIC 1 ++ END ACTIONLISTON ++ END POLICY ++ ++ POLICY !!Blacklist_Word ++ EXPLAIN !!Explain_Blacklist_Word ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-2" ++ VALUENAME "DOC" ++ END POLICY ++ ++ POLICY !!Blacklist_Excel ++ EXPLAIN !!Explain_Blacklist_Excel ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-2" ++ VALUENAME "XLS" ++ END POLICY ++ ++ POLICY !!Blacklist_Powerpoint ++ EXPLAIN !!Explain_Blacklist_Powerpoint ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-2" ++ VALUENAME "PPT" ++ END POLICY ++ ++ POLICY !!Blacklist_PDF ++ EXPLAIN !!Explain_Blacklist_PDF ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-2" ++ VALUENAME "PDF" ++ END POLICY ++ ++ POLICY !!Blacklist_ZIP ++ EXPLAIN !!Explain_Blacklist_ZIP ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-2" ++ VALUENAME "ZIP" ++ END POLICY ++ ++ POLICY !!Blacklist_HTTPS ++ EXPLAIN !!Explain_Blacklist_HTTPS ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-3" ++ VALUENAME "HTTPS" ++ END POLICY ++ ++ POLICY !!Blacklist_PasswordProtectedOffice ++ EXPLAIN !!Explain_Blacklist_PasswordProtectedOffice ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-13" ++ VALUENAME "SECUREOFFICE" ++ END POLICY ++ ++ POLICY !!Blacklist_URI_Contains ++ EXPLAIN !!Explain_Blacklist_URI_Contains ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\blacklist-6" ++ PART !!Blacklist_URI_Contains LISTBOX ++ END PART ++ END POLICY ++ ++ POLICY !!Blacklist_Extensions ++ EXPLAIN !!Explain_Blacklist_Extensions ++ PART !!Blacklist_Extensions EDITTEXT ++ VALUENAME "file_extensions_to_skip" ++ END PART ++ END POLICY ++ ++ POLICY !!Pol_Disallow_UserSearchLocations ++ EXPLAIN !!Explain_Disallow_UserSearchLocations ++ VALUENAME user_search_locations ++ VALUEON NUMERIC 1 ++ END POLICY ++ ++ POLICY !!Pol_Search_Location_Whitelist ++ EXPLAIN !!Explain_Search_Location_Whitelist ++ KEYNAME "Software\Policies\Google\Google Desktop\Preferences\policy_search_location_whitelist" ++ PART !!Search_Locations_Whitelist LISTBOX ++ END PART ++ END POLICY ++ ++ POLICY !!Email_Retention ++ EXPLAIN !!Explain_Email_Retention ++ PART !!Email_Retention_Edit NUMERIC ++ VALUENAME "email_days_to_retain" ++ MIN 1 MAX 65535 DEFAULT 30 SPIN 1 ++ END PART ++ END POLICY ++ ++ POLICY !!Webpage_Retention ++ EXPLAIN !!Explain_Webpage_Retention ++ PART !!Webpage_Retention_Edit NUMERIC ++ VALUENAME "webpage_days_to_retain" ++ MIN 1 MAX 65535 DEFAULT 30 SPIN 1 ++ END PART ++ END POLICY ++ ++ POLICY !!File_Retention ++ EXPLAIN !!Explain_File_Retention ++ PART !!File_Retention_Edit NUMERIC ++ VALUENAME "file_days_to_retain" ++ MIN 1 MAX 65535 DEFAULT 30 SPIN 1 ++ END PART ++ END POLICY ++ ++ POLICY !!IM_Retention ++ EXPLAIN !!Explain_IM_Retention ++ PART !!IM_Retention_Edit NUMERIC ++ VALUENAME "im_days_to_retain" ++ MIN 1 MAX 65535 DEFAULT 30 SPIN 1 ++ END PART ++ END POLICY ++ ++ POLICY !!Pol_Remove_Deleted_Items ++ EXPLAIN !!Explain_Remove_Deleted_Items ++ VALUENAME remove_deleted_items ++ VALUEON NUMERIC 1 ++ END POLICY ++ ++ POLICY !!Pol_Allow_Simultaneous_Indexing ++ EXPLAIN !!Explain_Allow_Simultaneous_Indexing ++ VALUENAME simultaneous_indexing ++ VALUEON NUMERIC 1 ++ END POLICY ++ ++ END CATEGORY ++ ++ POLICY !!Pol_TurnOffAdvancedFeatures ++ EXPLAIN !!Explain_TurnOffAdvancedFeatures ++ VALUENAME error_report_on ++ VALUEON NUMERIC 0 ++ END POLICY ++ ++ POLICY !!Pol_TurnOffImproveGd ++ EXPLAIN !!Explain_TurnOffImproveGd ++ VALUENAME improve_gd ++ VALUEON NUMERIC 0 ++ VALUEOFF NUMERIC 1 ++ END POLICY ++ ++ POLICY !!Pol_NoPersonalizationInfo ++ EXPLAIN !!Explain_NoPersonalizationInfo ++ VALUENAME send_personalization_info ++ VALUEON NUMERIC 0 ++ VALUEOFF NUMERIC 1 ++ END POLICY ++ ++ POLICY !!Pol_OneBoxMode ++ EXPLAIN !!Explain_OneBoxMode ++ VALUENAME onebox_mode ++ VALUEON NUMERIC 0 ++ END POLICY ++ ++ POLICY !!Pol_EncryptIndex ++ EXPLAIN !!Explain_EncryptIndex ++ VALUENAME encrypt_index ++ VALUEON NUMERIC 1 ++ END POLICY ++ ++ POLICY !!Pol_Hyper ++ EXPLAIN !!Explain_Hyper ++ VALUENAME hyper_off ++ VALUEON NUMERIC 1 ++ END POLICY ++ ++ POLICY !!Pol_Display_Mode ++ EXPLAIN !!Explain_Display_Mode ++ PART !!Pol_Display_Mode DROPDOWNLIST ++ VALUENAME display_mode ++ ITEMLIST ++ NAME !!Sidebar VALUE NUMERIC 1 ++ NAME !!Deskbar VALUE NUMERIC 8 ++ NAME !!FloatingDeskbar VALUE NUMERIC 4 ++ NAME !!None VALUE NUMERIC 0 ++ END ITEMLIST ++ END PART ++ END POLICY ++ ++ END CATEGORY ; Preferences ++ ++ CATEGORY !!Cat_Enterprise ++ KEYNAME "Software\Policies\Google\Google Desktop\Enterprise" ++ ++ POLICY !!Pol_Autoupdate ++ EXPLAIN !!Explain_Autoupdate ++ VALUENAME autoupdate_host ++ VALUEON "" ++ END POLICY ++ ++ POLICY !!Pol_AutoupdateAsSystem ++ EXPLAIN !!Explain_AutoupdateAsSystem ++ VALUENAME autoupdate_impersonate_user ++ VALUEON NUMERIC 0 ++ VALUEOFF NUMERIC 1 ++ END POLICY ++ ++ POLICY !!Pol_EnterpriseTab ++ EXPLAIN !!Explain_EnterpriseTab ++ PART !!EnterpriseTabText EDITTEXT ++ VALUENAME enterprise_tab_text ++ END PART ++ PART !!EnterpriseTabHomepage EDITTEXT ++ VALUENAME enterprise_tab_homepage ++ END PART ++ PART !!EnterpriseTabHomepageQuery CHECKBOX ++ VALUENAME enterprise_tab_homepage_query ++ END PART ++ PART !!EnterpriseTabResults EDITTEXT ++ VALUENAME enterprise_tab_results ++ END PART ++ PART !!EnterpriseTabResultsQuery CHECKBOX ++ VALUENAME enterprise_tab_results_query ++ END PART ++ END POLICY ++ ++ POLICY !!Pol_GSAHosts ++ EXPLAIN !!Explain_GSAHosts ++ KEYNAME "Software\Policies\Google\Google Desktop\Enterprise\GSAHosts" ++ PART !!Pol_GSAHosts LISTBOX ++ END PART ++ END POLICY ++ ++ POLICY !!Pol_Disallow_Gadgets ++ EXPLAIN !!Explain_Disallow_Gadgets ++ VALUENAME disallow_gadgets ++ VALUEON NUMERIC 1 ++ PART !!Disallow_Only_Non_Builtin_Gadgets CHECKBOX DEFCHECKED ++ VALUENAME disallow_only_non_builtin_gadgets ++ VALUEON NUMERIC 1 ++ VALUEOFF NUMERIC 0 ++ END PART ++ END POLICY ++ ++ POLICY !!Pol_Gadget_Whitelist ++ EXPLAIN !!Explain_Gadget_Whitelist ++ KEYNAME "Software\Policies\Google\Google Desktop\Enterprise\gadget_whitelist" ++ PART !!Pol_Gadget_Whitelist LISTBOX ++ END PART ++ END POLICY ++ ++ POLICY !!Pol_Gadget_Install_Confirmation_Whitelist ++ EXPLAIN !!Explain_Gadget_Install_Confirmation_Whitelist ++ KEYNAME "Software\Policies\Google\Google Desktop\Enterprise\install_confirmation_whitelist" ++ PART !!Pol_Gadget_Install_Confirmation_Whitelist LISTBOX ++ END PART ++ END POLICY ++ ++ POLICY !!Pol_Alternate_User_Data_Dir ++ EXPLAIN !!Explain_Alternate_User_Data_Dir ++ PART !!Pol_Alternate_User_Data_Dir EDITTEXT ++ VALUENAME alternate_user_data_dir ++ END PART ++ END POLICY ++ ++ POLICY !!Pol_MaxAllowedOutlookConnections ++ EXPLAIN !!Explain_MaxAllowedOutlookConnections ++ PART !!Pol_MaxAllowedOutlookConnections NUMERIC ++ VALUENAME max_allowed_outlook_connections ++ MIN 1 MAX 65535 DEFAULT 400 SPIN 1 ++ END PART ++ END POLICY ++ ++ POLICY !!Pol_DisallowSsdService ++ EXPLAIN !!Explain_DisallowSsdService ++ VALUENAME disallow_ssd_service ++ VALUEON NUMERIC 1 ++ END POLICY ++ ++ POLICY !!Pol_DisallowSsdOutbound ++ EXPLAIN !!Explain_DisallowSsdOutbound ++ VALUENAME disallow_ssd_outbound ++ VALUEON NUMERIC 1 ++ END POLICY ++ ++ POLICY !!Pol_Disallow_Store_Gadget_Service ++ EXPLAIN !!Explain_Disallow_Store_Gadget_Service ++ VALUENAME disallow_store_gadget_service ++ VALUEON NUMERIC 1 ++ END POLICY ++ ++ POLICY !!Pol_MaxExchangeIndexingRate ++ EXPLAIN !!Explain_MaxExchangeIndexingRate ++ PART !!Pol_MaxExchangeIndexingRate NUMERIC ++ VALUENAME max_exchange_indexing_rate ++ MIN 1 MAX 1000 DEFAULT 60 SPIN 1 ++ END PART ++ END POLICY ++ ++ POLICY !!Pol_EnableSafeweb ++ EXPLAIN !!Explain_Safeweb ++ VALUENAME safe_browsing ++ VALUEON NUMERIC 1 ++ VALUEOFF NUMERIC 0 ++ END POLICY ++ ++ END CATEGORY ; Enterprise ++ ++ END CATEGORY ; GoogleDesktopSearch ++ END CATEGORY ; Google ++ ++;------------------------------------------------------------------------------ ++ ++[strings] ++Cat_Google="Google" ++Cat_GoogleDesktopSearch="Google Desktop" ++ ++;------------------------------------------------------------------------------ ++; Preferences ++;------------------------------------------------------------------------------ ++Cat_Preferences="Preferences" ++Explain_Preferences="Controls Google Desktop preferences" ++ ++Cat_IndexAndCaptureControl="Indexing and Capture Control" ++Explain_IndexAndCaptureControl="Controls what files, web pages, and other content will be indexed by Google Desktop." ++ ++Blacklist_Email="Prevent indexing of email" ++Explain_Blacklist_Email="Enabling this policy will prevent Google Desktop from indexing emails.\n\nIf this policy is not configured, the user can choose whether or not to index emails." ++Blacklist_Gmail="Prevent indexing of Gmail" ++Explain_Blacklist_Gmail="Enabling this policy prevents Google Desktop from indexing Gmail messages.\n\nThis policy is in effect only when the policy "Prevent indexing of email" is disabled. When that policy is enabled, all email indexing is disabled, including Gmail indexing.\n\nIf both this policy and "Prevent indexing of email" are disabled or not configured, a user can choose whether or not to index Gmail messages." ++Blacklist_WebHistory="Prevent indexing of web pages" ++Explain_Blacklist_WebHistory="Enabling this policy will prevent Google Desktop from indexing web pages.\n\nIf this policy is disabled or not configured, the user can choose whether or not to index web pages." ++Blacklist_Text="Prevent indexing of text files" ++Explain_Blacklist_Text="Enabling this policy will prevent Google Desktop from indexing text files.\n\nIf this policy is disabled or not configured, the user can choose whether or not to index text files." ++Blacklist_Media="Prevent indexing of media files" ++Explain_Blacklist_Media="Enabling this policy will prevent Google Desktop from indexing media files.\n\nIf this policy is disabled or not configured, the user can choose whether or not to index media files." ++Blacklist_Contact="Prevent indexing of contacts" ++Explain_Blacklist_Contact="Enabling this policy will prevent Google Desktop from indexing contacts.\n\nIf this policy is disabled or not configured, the user can choose whether or not to index contacts." ++Blacklist_Calendar="Prevent indexing of calendar entries" ++Explain_Blacklist_Calendar="Enabling this policy will prevent Google Desktop from indexing calendar entries.\n\nIf this policy is disabled or not configured, the user can choose whether or not to index calendar entries." ++Blacklist_Task="Prevent indexing of tasks" ++Explain_Blacklist_Task="Enabling this policy will prevent Google Desktop from indexing tasks.\n\nIf this policy is disabled or not configured, the user can choose whether or not to index tasks." ++Blacklist_Note="Prevent indexing of notes" ++Explain_Blacklist_Note="Enabling this policy will prevent Google Desktop from indexing notes.\n\nIf this policy is disabled or not configured, the user can choose whether or not to index notes." ++Blacklist_Journal="Prevent indexing of journal entries" ++Explain_Blacklist_Journal="Enabling this policy will prevent Google Desktop from indexing journal entries.\n\nIf this policy is disabled or not configured, the user can choose whether or not to index journal entries." ++Blacklist_Word="Prevent indexing of Word documents" ++Explain_Blacklist_Word="Enabling this policy will prevent Google Desktop from indexing Word documents.\n\nIf this policy is disabled or not configured, the user can choose whether or not to index Word documents." ++Blacklist_Excel="Prevent indexing of Excel documents" ++Explain_Blacklist_Excel="Enabling this policy will prevent Google Desktop from indexing Excel documents.\n\nIf this policy is disabled or not configured, the user can choose whether or not to index Excel documents." ++Blacklist_Powerpoint="Prevent indexing of PowerPoint documents" ++Explain_Blacklist_Powerpoint="Enabling this policy will prevent Google Desktop from indexing PowerPoint documents.\n\nIf this policy is disabled or not configured, the user can choose whether or not to index PowerPoint documents." ++Blacklist_PDF="Prevent indexing of PDF documents" ++Explain_Blacklist_PDF="Enabling this policy will prevent Google Desktop from indexing PDF documents.\n\nIf this policy is disabled or not configured, the user can choose whether or not to index PDF documents." ++Blacklist_ZIP="Prevent indexing of ZIP files" ++Explain_Blacklist_ZIP="Enabling this policy will prevent Google Desktop from indexing ZIP files.\n\nIf this policy is disabled or not configured, the user can choose whether or not to index ZIP files." ++Blacklist_HTTPS="Prevent indexing of secure web pages" ++Explain_Blacklist_HTTPS="Enabling this policy will prevent Google Desktop from indexing secure web pages (pages with HTTPS in the URL).\n\nIf this policy is disabled or not configured, the user can choose whether or not to index secure web pages." ++Blacklist_URI_Contains="Prevent indexing of specific web sites and folders" ++Explain_Blacklist_URI_Contains="This policy allows you to prevent Google Desktop from indexing specific websites or folders. If an item's URL or path name contains any of these specified strings, it will not be indexed. These restrictions will be applied in addition to any websites or folders that the user has specified.\n\nThis policy has no effect when disabled or not configured." ++Blacklist_Chat="Prevent indexing of IM chats" ++Explain_Blacklist_Chat="Enabling this policy will prevent Google Desktop from indexing IM chat conversations.\n\nIf this policy is disabled or not configured, the user can choose whether or not to index IM chat conversations." ++Blacklist_PasswordProtectedOffice="Prevent indexing of password-protected Office documents (Word, Excel)" ++Explain_Blacklist_PasswordProtectedOffice="Enabling this policy will prevent Google Desktop from indexing password-protected office documents.\n\nIf this policy is disabled or not configured, the user can choose whether or not to index password-protected office documents." ++Blacklist_Extensions="Prevent indexing of specific file extensions" ++Explain_Blacklist_Extensions="This policy allows you to prevent Google Desktop from indexing files with specific extensions. Enter a list of file extensions, separated by commas, that you wish to exclude from indexing.\n\nThis policy has no effect when disabled or not configured." ++Pol_Disallow_UserSearchLocations="Disallow adding search locations for indexing" ++Explain_Disallow_UserSearchLocations="Enabling this policy will prevent the user from specifying additional drives or networked folders to be indexed by Google Desktop.\n\nIf this policy is disabled or not configured, users may specify additional drives and networked folders to be indexed." ++Pol_Search_Location_Whitelist="Allow indexing of specific folders" ++Explain_Search_Location_Whitelist="This policy allows you to add additional drives and networked folders to index." ++Search_Locations_Whitelist="Search these locations" ++Email_Retention="Only retain emails that are less than x days old" ++Explain_Email_Retention="This policy allows you to configure Google Desktop to only retain emails that are less than the specified number of days old in the index. Enter the number of days to retain emails for\n\nThis policy has no effect when disabled or not configured." ++Email_Retention_Edit="Number of days to retain emails" ++Webpage_Retention="Only retain webpages that are less than x days old" ++Explain_Webpage_Retention="This policy allows you to configure Google Desktop to only retain webpages that are less than the specified number of days old in the index. Enter the number of days to retain webpages for\n\nThis policy has no effect when disabled or not configured." ++Webpage_Retention_Edit="Number of days to retain webpages" ++File_Retention="Only retain files that are less than x days old" ++Explain_File_Retention="This policy allows you to configure Google Desktop to only retain files that are less than the specified number of days old in the index. Enter the number of days to retain files for\n\nThis policy has no effect when disabled or not configured." ++File_Retention_Edit="Number of days to retain files" ++IM_Retention="Only retain IM that are less than x days old" ++Explain_IM_Retention="This policy allows you to configure Google Desktop to only retain IM that are less than the specified number of days old in the index. Enter the number of days to retain IM for\n\nThis policy has no effect when disabled or not configured." ++IM_Retention_Edit="Number of days to retain IM" ++ ++Pol_Remove_Deleted_Items="Remove deleted items from the index." ++Explain_Remove_Deleted_Items="Enabling this policy will remove all deleted items from the index and cache. Any items that are deleted will no longer be searchable." ++ ++Pol_Allow_Simultaneous_Indexing="Allow historical indexing for multiple users simultaneously." ++Explain_Allow_Simultaneous_Indexing="Enabling this policy will allow a computer to generate first-time indexes for multiple users simultaneously. \n\nIf this policy is disabled or not configured, historical indexing will happen only for the logged-in user that was connected last; historical indexing for any other logged-in user will happen the next time that other user connects." ++ ++Pol_TurnOffAdvancedFeatures="Turn off Advanced Features options" ++Explain_TurnOffAdvancedFeatures="Enabling this policy will prevent Google Desktop from sending Advanced Features data to Google (for either improvements or personalization), and users won't be able to change these options. Enabling this policy also prevents older versions of Google Desktop from sending data.\n\nIf this policy is disabled or not configured and the user has a pre-5.5 version of Google Desktop, the user can choose whether or not to enable sending data to Google. If the user has version 5.5 or later, the 'Turn off Improve Google Desktop option' and 'Do not send personalization info' policies will be used instead." ++ ++Pol_TurnOffImproveGd="Turn off Improve Google Desktop option" ++Explain_TurnOffImproveGd="Enabling this policy will prevent Google Desktop from sending improvement data, including crash reports and anonymous usage data, to Google.\n\nIf this policy is disabled, improvement data will be sent to Google and the user won't be able to change the option.\n\nIf this policy is not configured, the user can choose whether or not to enable the Improve Google Desktop option.\n\nNote that this policy applies only to version 5.5 or later and doesn't affect previous versions of Google Desktop.\n\nAlso note that this policy can be overridden by the 'Turn off Advanced Features options' policy." ++ ++Pol_NoPersonalizationInfo="Do not send personalization info" ++Explain_NoPersonalizationInfo="Enabling this policy will prevent Google Desktop from displaying personalized content, such as news that reflects the user's past interest in articles. Personalized content is derived from anonymous usage data sent to Google.\n\nIf this policy is disabled, personalized content will be displayed for all users, and users won't be able to disable this feature.\n\nIf this policy is not configured, users can choose whether or not to enable personalization in each gadget that supports this feature.\n\nNote that this policy applies only to version 5.5 or later and doesn't affect previous versions of Google Desktop.\n\nAlso note that this policy can be overridden by the 'Turn off Advanced Features options' policy." ++ ++Pol_OneBoxMode="Turn off Google Web Search Integration" ++Explain_OneBoxMode="Enabling this policy will prevent Google Desktop from displaying Desktop Search results in queries to google.com.\n\nIf this policy is disabled or not configured, the user can choose whether or not to include Desktop Search results in queries to google.com." ++ ++Pol_EncryptIndex="Encrypt index data" ++Explain_EncryptIndex="Enabling this policy will cause Google Desktop to turn on Windows file encryption for the folder containing the Google Desktop index and related user data the next time it is run.\n\nNote that Windows EFS is only available on NTFS volumes. If the user's data is stored on a FAT volume, this policy will have no effect.\n\nThis policy has no effect when disabled or not configured." ++ ++Pol_Hyper="Turn off Quick Find" ++Explain_Hyper="Enabling this policy will cause Google Desktop to turn off Quick Find feature. Quick Find allows you to see results as you type.\n\nIf this policy is disabled or not configured, the user can choose whether or not to enable it." ++ ++Pol_Display_Mode="Choose display option" ++Explain_Display_Mode="This policy sets the Google Desktop display option: Sidebar, Deskbar, Floating Deskbar or none.\n\nNote that on 64-bit systems, a setting of Deskbar will be interpreted as Floating Deskbar.\n\nIf this policy is disabled or not configured, the user can choose a display option." ++Sidebar="Sidebar" ++Deskbar="Deskbar" ++FloatingDeskbar="Floating Deskbar" ++None="None" ++ ++;------------------------------------------------------------------------------ ++; Enterprise ++;------------------------------------------------------------------------------ ++Cat_Enterprise="Enterprise Integration" ++Explain_Enterprise="Controls features specific to Enterprise installations of Google Desktop" ++ ++Pol_Autoupdate="Block Auto-update" ++Explain_Autoupdate="Enabling this policy prevents Google Desktop from automatically checking for and installing updates from google.com.\n\nIf you enable this policy, you must distribute updates to Google Desktop using Group Policy, SMS, or a similar enterprise software distribution mechanism. You should check http://desktop.google.com/enterprise/ for updates.\n\nIf this policy is disabled or not configured, Google Desktop will periodically check for updates from desktop.google.com." ++ ++Pol_AutoupdateAsSystem="Use system proxy settings when auto-updating" ++Explain_AutoupdateAsSystem="Enabling this policy makes Google Desktop use the machine-wide proxy settings (as specified using e.g. proxycfg.exe) when performing autoupdates (if enabled).\n\nIf this policy is disabled or not configured, Google Desktop will use the logged-on user's Internet Explorer proxy settings when checking for auto-updates (if enabled)." ++ ++Pol_EnterpriseTab="Enterprise search tab" ++Explain_EnterpriseTab="This policy allows you to add a search tab for your Google Search Appliance to Google Desktop and google.com web pages.\n\nYou must provide the name of the tab, such as "Intranet", as well as URLs for the search homepage and for retrieving search results. Use [DISP_QUERY] in place of the query term for the search results URL.\n\nSee the administrator's guide for more details." ++EnterpriseTabText="Tab name" ++EnterpriseTabHomepage="Search homepage URL" ++EnterpriseTabHomepageQuery="Check if search homepage supports '&&q=<query>'" ++EnterpriseTabResults="Search results URL" ++EnterpriseTabResultsQuery="Check if search results page supports '&&q=<query>'" ++ ++Pol_GSAHosts="Google Search Appliances" ++Explain_GSAHosts="This policy allows you to list any Google Search Appliances in your intranet. When properly configured, Google Desktop will insert Google Desktop results into the results of queries on the Google Search Appliance" ++ ++Pol_PolicyUnawareClientProhibitedFlag="Prohibit Policy-Unaware versions" ++Explain_PolicyUnawareClientProhibitedFlag="Prohibits installation and execution of versions of Google Desktop that are unaware of group policy.\n\nEnabling this policy will prevent users from installing or running version 1.0 of Google Desktop.\n\nThis policy has no effect when disabled or not configured." ++ ++Pol_MinimumAllowedVersion="Minimum allowed version" ++Explain_MinimumAllowedVersion="This policy allows you to prevent installation and/or execution of older versions of Google Desktop by specifying the minimum version you wish to allow. When enabling this policy, you should also enable the "Prohibit Policy-Unaware versions" policy to block versions of Google Desktop that did not support group policy.\n\nThis policy has no effect when disabled or not configured." ++ ++Pol_MaximumAllowedVersion="Maximum allowed version" ++Explain_MaximumAllowedVersion="This policy allows you to prevent installation and/or execution of newer versions of Google Desktop by specifying the maximum version you wish to allow.\n\nThis policy has no effect when disabled or not configured." ++ ++Pol_Disallow_Gadgets="Disallow gadgets and indexing plug-ins" ++Explain_Disallow_Gadgets="This policy prevents the use of all Google Desktop gadgets and indexing plug-ins. The policy applies to gadgets that are included in the Google Desktop installation package (built-in gadgets), built-in indexing plug-ins (currently only the Lotus Notes plug-in), and to gadgets or indexing plug-ins that a user might want to add later (non-built-in gadgets and indexing plug-ins).\n\nYou can prohibit use of all non-built-in gadgets and indexing plug-ins, but allow use of built-in gadgets and indexing plug-ins. To do so, enable this policy and then select the option "Disallow only non-built-in gadgets and indexing plug-ins.\n\nYou can supersede this policy to allow specified built-in and non-built-in gadgets and indexing plug-ins. To do so, enable this policy and then specify the gadgets and/or indexing plug-ins you want to allow under "Gadget and Plug-in Whitelist."" ++Disallow_Only_Non_Builtin_Gadgets="Disallow only non-built-in gadgets and indexing plug-ins" ++ ++Pol_Gadget_Whitelist="Gadget and plug-in whitelist" ++Explain_Gadget_Whitelist="This policy specifies a list of Google Desktop gadgets and indexing plug-ins that you want to allow, as exceptions to the "Disallow gadgets and indexing plug-ins" policy. This policy is valid only when the "Disallow gadgets and indexing plug-ins" policy is enabled.\n\nFor each gadget or indexing plug-in you wish to allow, add the CLSID or PROGID of the gadget or indexing plug-in (see the administrator's guide for more details).\n\nThis policy has no effect when disabled or not configured." ++ ++Pol_Gadget_Install_Confirmation_Whitelist="Allow silent installation of gadgets" ++Explain_Gadget_Install_Confirmation_Whitelist="Enabling this policy lets you specify a list of Google Desktop gadgets or indexing plug-ins that can be installed without confirmation from the user.\n\nAdd a gadget or indexing plug-in by placing its class ID (CLSID) or program identifier (PROGID) in the list, surrounded with curly braces ({ }).\n\nThis policy has no effect when disabled or not configured." ++ ++Pol_Alternate_User_Data_Dir="Alternate user data directory" ++Explain_Alternate_User_Data_Dir="This policy allows you to specify a directory to be used to store user data for Google Desktop (such as index data and cached documents).\n\nYou may use [USER_NAME] or [DOMAIN_NAME] in the path to specify the current user's name or domain. If [USER_NAME] is not specified, the user name will be appended at the end of the path.\n\nThis policy has no effect when disabled or not configured." ++ ++Pol_MaxAllowedOutlookConnections="Maximum allowed Outlook connections" ++Explain_MaxAllowedOutlookConnections="This policy specifies the maximum number of open connections that Google Desktop maintains with the Exchange server. Google Desktop opens a connection for each email folder that it indexes. If insufficient connections are allowed, Google Desktop cannot index all the user email folders.\n\nThe default value is 400. Because users rarely have as many as 400 email folders, Google Desktop rarely reaches the limit.\n\nIf you set this policy's value above 400, you must also configure the number of open connections between Outlook and the Exchange server. By default, approximately 400 connections are allowed. If Google Desktop uses too many of these connections, Outlook might be unable to access email.\n\nThis policy has no effect when disabled or not configured." ++ ++Pol_DisallowSsdService="Disallow sharing and receiving of web history and documents across computers" ++Explain_DisallowSsdService="Enabling this policy will prevent Google Desktop from sharing the user's web history and document contents across the user's different Google Desktop installations, and will also prevent it from receiving such shared items from the user's other machines. To allow reception but disallow sharing, use DisallowSsdOutbound.\nThis policy has no effect when disabled or not configured." ++ ++Pol_DisallowSsdOutbound="Disallow sharing of web history and documents to user's other computers." ++Explain_DisallowSsdOutbound="Enabling this policy will prevent Google Desktop from sending the user's web history and document contents from this machine to the user's other machines. It does not prevent reception of items from the user's other machines; to disallow both, use DisallowSsdService.\nThis policy has no effect when disabled or not configured." ++ ++Pol_Disallow_Store_Gadget_Service="Disallow storage of gadget content and settings." ++Explain_Disallow_Store_Gadget_Service="Enabling this policy will prevent users from storing their gadget content and settings with Google. Users will be unable to access their gadget content and settings from other computers and all content and settings will be lost if Google Desktop is uninstalled." ++ ++Pol_MaxExchangeIndexingRate="Maximum allowed Exchange indexing rate" ++Explain_MaxExchangeIndexingRate="This policy allows you to specify the maximum number of emails that are indexed per minute. \n\nThis policy has no effect when disabled or not configured." ++ ++Pol_EnableSafeweb="Enable or disable safe browsing" ++Explain_Safeweb="Google Desktop safe browsing informs the user whenever they visit any site which is a suspected forgery site or may harm their computer. Enabling this policy turns on safe browsing; disabling the policy turns it off. \n\nIf this policy is not configured, the user can select whether to turn on safe browsing." +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/README.txt b/tools/grit/grit/testdata/README.txt +new file mode 100644 +index 0000000000..a683b3b9e3 +--- /dev/null ++++ b/tools/grit/grit/testdata/README.txt +@@ -0,0 +1,87 @@ ++Google Desktop for Enterprise ++Copyright (C) 2007 Google Inc. ++All Rights Reserved ++ ++--------- ++Contents ++--------- ++This distribution contains the following files: ++ ++GoogleDesktopSetup.msi - Installation and setup program ++GoogleDesktop.adm - Group Policy administrative template file ++AdminGuide.pdf - Google Desktop for Enterprise administrative guide ++ ++ ++-------------- ++Documentation ++-------------- ++Full documentation and installation instructions are in the ++administrative guide, and also online at ++http://desktop.google.com/enterprise/adminguide.html. ++ ++ ++------------------------ ++IBM Lotus Notes Plug-In ++------------------------ ++The Lotus Notes plug-in is included in the release of Google ++Desktop for Enterprise. The IBM Lotus Notes Plug-in for Google ++Desktop indexes mail, calendar, task, contact and journal ++documents from Notes. Discussion documents including those from ++the discussion and team room templates can also be indexed by ++selecting an option from the preferences. Once indexed, this data ++will be returned in Google Desktop searches. The corresponding ++document can be opened in Lotus Notes from the Google Desktop ++results page. ++ ++Install: The plug-in will install automatically during the Google ++Desktop setup process if Lotus Notes is already installed. Lotus ++Notes must not be running in order for the install to occur. The ++Class ID for this plug-in is {8F42BDFB-33E8-427B-AFDC-A04E046D3F07}. ++ ++Preferences: Preferences and selection of databases to index are ++set in the 'Google Desktop for Notes' dialog reached through the ++'Actions' menu. ++ ++Reindexing: Selecting 'Reindex all databases' will index all the ++documents in each database again. ++ ++ ++Notes Plug-in Known Issues ++--------------------------- ++ ++If the 'Google Desktop for Notes' item is not available from the ++Lotus Notes Actions menu, then installation was not successful. ++Installation consists of writing one file, notesgdsplugin.dll, to ++the Notes application directory and a setting to the notes.ini ++configuration file. The most likely cause of an unsuccessful ++installation is that the installer was not able to locate the ++notes.ini file. Installation will complete if the user closes Notes ++and manually adds the following setting to this file on a new line: ++AddinMenus=notesgdsplugin.dll ++ ++If the notesgdsplugin.dll file is not in the application directory ++(e.g., C:\Program Files\Lotus\Notes) after Google Desktop ++installation, it is likely that Notes was not installed correctly. ++ ++Only local databases can be indexed. If they can be determined, ++the user's local mail file and address book will be included in the ++list automatically. Mail archives and other databases must be ++added with the 'Add' button. ++ ++Some users may experience performance issues during the initial ++indexing of a database. The 'Perform the initial index of a ++database only when I'm idle' option will limit the indexing process ++to times when the user is not using the machine. If this does not ++alleviate the problem or the user would like to continually index ++but just do so more slowly or quickly, the GoogleWaitTime notes.ini ++value can be set. Increasing the GoogleWaitTime value will slow ++down the indexing process, and lowering the value will speed it up. ++A value of zero causes the fastest possible indexing. Removing the ++ini parameter altogether returns it to the default (20). ++ ++Crashes have been known to occur with certain types of history ++bookmarks. If the Notes client seems to crash randomly, try ++disabling the 'Index note history' option. If it crashes before, ++you can get to the preferences, add the following line to your ++notes.ini file: ++GDSNoIndexHistory=1 +diff --git a/tools/grit/grit/testdata/about.html b/tools/grit/grit/testdata/about.html +new file mode 100644 +index 0000000000..8e5fad7b2b +--- /dev/null ++++ b/tools/grit/grit/testdata/about.html +@@ -0,0 +1,45 @@ ++[HEADER] ++<table cellspacing=0 cellPadding=0 width="100%" border=0><tr bgcolor=#3399cc><td align=middle height=1><img height=1 width=1></td></tr></table> ++<table cellspacing=0 cellPadding=1 width="100%" bgcolor=#e8f4f7 border=0><tr><td height=20><font size=+1 color=#000000> <b>[TITLE]</b></font></td></tr></table> ++<br><center><span style="line-height:16pt"><font color=#335cec><B>Google Desktop Search: Search your own computer.</B></font></span></center><br> ++ ++<table cellspacing=1 cellpadding=0 width=300 align=center border=0> ++<tr><td nowrap><font size=-1><img style="vertical-align:middle" height=16 src="outlook.gif" width=16> Outlook Email</font></td> ++<td nowrap> </td> ++<td nowrap><font size=-1><img style="vertical-align:middle" height=16 src="netscape.gif" width=16> Netscape Mail / Thunderbird</font></td></tr> ++ ++<tr><td nowrap><font size=-1><img style="vertical-align:middle" height=16 src="oe.gif" width=16> Outlook Express</font></td> ++<td nowrap> </td> ++<td nowrap><font size=-1><img style="vertical-align:middle" height=16 src="ff.gif" width=16> Netscape / Firefox / Mozilla</font></td></tr> ++ ++<tr><td nowrap><font size=-1><img style="vertical-align:middle" height=16 src="doc.gif" width=16> Word</font></td> ++<td nowrap> </td> ++<td nowrap><font size=-1><img style="vertical-align:middle" height=16 src="pdf.gif" width=16> PDF</font></td></tr> ++ ++<tr><td nowrap><font size=-1><img style="vertical-align:middle" height=16 src="xls.gif" width=16> Excel</font></td> ++<td nowrap> </td> ++<td nowrap><font size=-1><img style="vertical-align:middle" height=16 src="mus.gif" width=16> Music</font></td></tr> ++ ++<tr><td nowrap><font size=-1><img style="vertical-align:middle" height=16 src="ppt.gif" width=16> PowerPoint</font></td> ++<td nowrap> </td> ++<td nowrap><font size=-1><img style="vertical-align:middle" height=16 src="jpg.gif" width=16> Images</font></td></tr> ++ ++<tr><td nowrap><font size=-1><img style="vertical-align:middle" height=16 src="ie.gif" width=16> Internet Explorer</font></td> ++<td nowrap> </td> ++<td nowrap><font size=-1><img style="vertical-align:middle" height=16 src="mov.gif" width=16> Video</font></td></tr> ++ ++<tr><td nowrap><font size=-1><img style="vertical-align:middle" height=16 src="aim.gif" width=16> AOL Instant Messenger</font></td> ++<td nowrap> </td> ++<td nowrap><font size=-1><img style="vertical-align:middle" height=16 src="other.gif" width=16> Even more with <a href="http://desktop.google.com/plugins.html">these plug-ins</A></font></td></tr> ++ ++<tr><td nowrap><font size=-1><img style="vertical-align:middle" height=16 src="txt.gif" width=16> Text and others</font></td></tr> ++</table> ++<center> ++<p><table cellpadding=1> ++<tr><td><a href="http://desktop.google.com/gettingstarted.html?hl=[LANG_CODE]"><B>Getting Started</B></A> - Learn more about using Google Desktop Search</td></tr> ++<tr><td><a href="http://desktop.google.com/help.html?hl=[LANG_CODE]"><B>Online Help</B></A> - Up-to-date answers to your questions</td></tr> ++<tr><td><a href="[$~PRIVACY~$]"><B>Privacy</B></A> - A few words about privacy and Google Desktop Search</td></tr> ++<tr><td><a href="http://desktop.google.com/uninstall.html?hl=[LANG_CODE]"><B>Uninstall</B></A> - How to uninstall Google Desktop Search</td></tr> ++<tr><td><a href="http://desktop.google.com/feedback.html?hl=[LANG_CODE]"><B>Submit Feedback</B></A> - Send us your comments and ideas</td></tr> ++</table><br><font size=-2>Google Desktop Search [$~BUILDNUMBER~$]</font><br><br> ++[FOOTER] +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/android.xml b/tools/grit/grit/testdata/android.xml +new file mode 100644 +index 0000000000..cc3b141f70 +--- /dev/null ++++ b/tools/grit/grit/testdata/android.xml +@@ -0,0 +1,24 @@ ++<!-- ++ Copyright (c) 2012 The Chromium Authors. All rights reserved. ++ Use of this source code is governed by a BSD-style license that can be ++ found in the LICENSE file. ++--> ++ ++<resources> ++ <!-- A string with placeholder. --> ++ <string xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2" name="placeholders"> ++ Open <xliff:g id="FILENAME" example="internet.html">%s</xliff:g>? ++ </string> ++ ++ <!-- A simple string. --> ++ <string name="simple">A simple string.</string> ++ ++ <!-- A string with a comment. --> ++ <string name="comment">Contains a <!-- ignore this --> comment. </string> ++ ++ <!-- A second simple string. --> ++ <string name="simple2"> Another simple string. </string> ++ ++ <!-- A non-translatable string. --> ++ <string name="constant" translatable="false">Do not translate me.</string> ++</resources> +diff --git a/tools/grit/grit/testdata/bad_browser.html b/tools/grit/grit/testdata/bad_browser.html +new file mode 100644 +index 0000000000..e8cf34664d +--- /dev/null ++++ b/tools/grit/grit/testdata/bad_browser.html +@@ -0,0 +1,16 @@ ++<p><b>We're sorry, but we don't seem to be compatible.</b></p> ++<p><font size="-1">Our software suggests that you're using a browser incompatible with Google Desktop Search. ++ Google Desktop Search currently supports the following:</font></p> ++<ul><font size="-1"> ++ <li>Microsoft IE 5 and newer (<a href="http://www.microsoft.com/windows/ie/downloads/default.asp">Download</a>)</li> ++ <li>Mozilla (<a href="http://www.mozilla.org/products/mozilla1.x/">Download</a>)</li> ++ <li>Mozilla Firefox (<a href="http://www.mozilla.org/products/firefox/">Download</a>)</li> ++ <li>Netscape 7 and newer (<a href="http://channels.netscape.com/ns/browsers/download.jsp">Download</a>)</li> ++</font></ul> ++ ++<p><font size="-1">You may <a href="[REDIR]">click here</a> to use your ++ unsupported browser, though you likely will encounter some areas that don't ++ work as expected. You need to have Javascript enabled, regardless of the ++ browser you use.</font> ++<p><font size="-1">We hope to expand this list in the near future and announce new ++ browsers as they become available. +diff --git a/tools/grit/grit/testdata/browser.html b/tools/grit/grit/testdata/browser.html +new file mode 100644 +index 0000000000..45d364d56f +--- /dev/null ++++ b/tools/grit/grit/testdata/browser.html +@@ -0,0 +1,42 @@ ++<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ++<html><head><title>[$~TITLE~$]</title> ++<style> ++BODY { MARGIN-LEFT: 1em; MARGIN-RIGHT: 1em } ++BODY, TD, DIV, A { FONT-FAMILY: arial,sans-serif} ++DIV, TD { COLOR: #000} ++A:link { COLOR: #00c} ++A:visited { COLOR: #551a8b} ++A:active { COLOR: #f00 } ++</style> ++</head> ++ ++<body bgcolor="#ffffff" text="#000000" link="#0000cc" vlink="#800080" alink="#ff0000" topmargin=2> ++ ++<table cellspacing=2 cellpadding=0 width="99%" border=0> ++<tr> ++ <td width="1%" rowspan=2>[$~IMAGE~$] ++ <td> </td> ++ <td rowspan=2> ++ <table cellspacing=0 cellpadding=0 width="100%" border=0> ++ <tr> ++ <td bgcolor=#3399cc><img height=1 width=1></td> ++ </tr> ++ </table> ++ <table cellspacing=0 cellpadding=0 width="100%" border=0 bgcolor=#efefef> ++ <tr> ++ <td nowrap bgcolor=#E8F4F7><font face=arial,sans-serif color=#000000 size=+1><b> [$~CHROME_TITLE~$]</b></font></td> ++ </tr> ++ </table> ++ </td> ++</tr> ++</table> ++ ++<table cellpadding=3 width="94%" align="center" cellspacing=0 border=0> ++<tr valign="middle"> ++ <td valign="top"> ++ [$~BODY~$] ++ </td> ++ </tr> ++</table> ++[$~FOOTER~$] ++</body></html> +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/buildinfo.grd b/tools/grit/grit/testdata/buildinfo.grd +new file mode 100644 +index 0000000000..80458a8265 +--- /dev/null ++++ b/tools/grit/grit/testdata/buildinfo.grd +@@ -0,0 +1,46 @@ ++<?xml version="1.0" encoding="UTF-8"?> <!-- -*- XML -*- --> ++<grit ++ base_dir="." ++ source_lang_id="en" ++ tc_project="GoogleDesktopWindowsClient" ++ latest_public_release="0" ++ current_release="1" ++ enc_check="möl"> ++ <outputs> ++ <output filename="resource.h" type="rc_header" /> ++ <output filename="en_generated_resources.rc" type="rc_all" lang="en" /> ++ <output filename="sv_generated_resources.rc" type="rc_all" lang="sv" /> ++ </outputs> ++ <translations> ++ <file path="substitute.xmb" lang="sv" /> ++ </translations> ++ <release seq="1" allow_pseudo="false"> ++ <includes> ++ <include type="BITMAP" name="IDB_PR" file="pr.bmp" /> ++ <if expr="lang == 'sv'"> ++ <include type="BITMAP" name="IDB_PR2" file="pr2.bmp" /> ++ </if> ++ </includes> ++ <structures> ++ <structure name="SIDEBAR_LOADING.HTML" encoding="utf-8" file="sidebar_loading.html" type="tr_html" generateid="false" expand_variables="false"/> ++ <structure name="IDS_PLACEHOLDER" file="transl.rc" type="dialog" > ++ <skeleton expr="lang == 'sv'" file="transl1.rc" variant_of_revision="1"/> ++ </structure> ++ <if expr="lang != 'sv'"> ++ <structure name="WELCOME_TOAST.HTML" encoding="utf-8" file="welcome_toast.html" type="tr_html" generateid="false" expand_variables="true"/> ++ </if> ++ </structures> ++ <messages first_id="8192"> ++ <message name="IDS_COPYRIGHT_GOOGLE_LONG" sub_variable="true" desc="Gadget copyright notice. Needs to be updated every year."> ++ Copyright 2008 Google Inc. All Rights Reserved. ++ </message> ++ <message name="IDS_NEWS_PANEL_COPYRIGHT"> ++ Google Desktop News gadget ++[IDS_COPYRIGHT_GOOGLE_LONG] ++View news that is personalized based on the articles you read. ++ ++For example, if you read lots of sports news, you'll see more sports articles. If you read technology news less often, you'll see fewer of those articles. ++ </message> ++ </messages> ++ </release> ++</grit> +diff --git a/tools/grit/grit/testdata/cache_prefix.html b/tools/grit/grit/testdata/cache_prefix.html +new file mode 100644 +index 0000000000..b1f91dd82b +--- /dev/null ++++ b/tools/grit/grit/testdata/cache_prefix.html +@@ -0,0 +1,24 @@ ++<head> ++<meta http-equiv="cache-control" content="no-cache"> ++<meta http-equiv="pragma" content="no-cache"> ++<meta http-equiv="expires" content="-1"> ++</head> ++<body onload="[ONLOAD]"> ++<table width="100%" border=1><tr><td> ++<table cellspacing=0 cellpadding=10 width="100%" bgcolor=#ffffff border=1 color="#ffffff"> ++<tr><td><font face="arial,sans-serif" color=black size=-1>This is one version of <a href="[$~URL~$]"> ++<font color="blue">[URL-DISP]</font></a> from your personal <a href="http://desktop.google.com/webcache.html"><font color=blue>cache</font></a>.<br> ++The page may have changed since that time. Click here for the <a href="[$~URL~$]"><font color="blue">current page</font></a>.<br> ++Since this page is stored on your computer, publicly linking to this page will not work.[$~EXTRA~$]<br><br> ++<font size="-2"><i>Google may not be affiliated with the authors of this page nor responsible for its content. This page may be protected by copyright.</i></font> ++</td> ++</tr></table></td></tr></table> ++<style> ++.hl { color:black; background-color:#ffff88} ++</style> ++<script> ++[$~HIGHLIGHT_SCRIPT~$] ++window.onerror=new Function(';'); ++</script> ++<hr id=gg_1> ++</body> +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/cache_prefix_file.html b/tools/grit/grit/testdata/cache_prefix_file.html +new file mode 100644 +index 0000000000..f3eb8e0f11 +--- /dev/null ++++ b/tools/grit/grit/testdata/cache_prefix_file.html +@@ -0,0 +1,25 @@ ++<head> ++<meta http-equiv="cache-control" content="no-cache"> ++<meta http-equiv="pragma" content="no-cache"> ++<meta http-equiv="expires" content="-1"></head> ++<body onload="[ONLOAD]"> ++<table width="100%" border=1> ++<tr><td> ++<table cellspacing=0 cellpadding=10 width="100%" bgcolor=#ffffff border=1 color="#ffffff"> ++<tr><td><font face=arial,sans-serif color=black size=-1>This is one version of <a href="[$~URL~$]"><font color=blue>[URL-DISP]</font></a> ++from your personal <a href="http://desktop.google.com/filecache.html"><font color=blue>cache</font></a>.<br> ++The file may have changed since that time. Click here for the <a href="[$~URL~$]"><font color=blue>current file</font></a>.<br> ++Since this file is stored on your computer, publicly linking to it will not work.[$~EXTRA~$]<br><br> ++<font size="-2"><i>Google may not be affiliated with the authors of this page nor responsible for its content. This page may be protected by copyright.</i></font> ++</td></tr> ++</table> ++</td></tr></table> ++<style> ++.hl { color:black; background-color:#ffff88} ++</style> ++<script> ++[$~HIGHLIGHT_SCRIPT~$] ++window.onerror=new Function(';'); ++</script> ++<hr id=gg_1> ++</body> +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/chat_result.html b/tools/grit/grit/testdata/chat_result.html +new file mode 100644 +index 0000000000..318078bc3d +--- /dev/null ++++ b/tools/grit/grit/testdata/chat_result.html +@@ -0,0 +1,24 @@ ++[HEADER] ++[CHROME] ++<table border=0 cellpadding=2 cellspacing=2> ++<tr><td>[$~STARTCHAT~$]</td></tr> ++</table> ++<blockquote id=gg_1> ++<table bgcolor=#f0f8ff width=80% cellpadding=5><tr><td> ++<img style="vertical-align:middle;" height=16 src="16x16_chat.gif" width=16> <b>[$~TITLE~$]</b> ++<font size=-1><br><br>Participants: [USERNAME], [BUDDYNAME]<br> ++Date: [TIME]</font></td></tr></table> ++<br id=contents> ++<label>[CONTENTS]</label> ++</blockquote> ++<table border=0 cellpadding=2 cellspacing=2> ++<tr><td>[$~STARTCHAT~$]</td></tr> ++</table> ++<style> ++.hl { color:black; background-color:#ffff88} ++</style> ++<script> ++[$~HIGHLIGHT_SCRIPT~$] ++[ONLOAD] ++</script> ++[FOOTER] +diff --git a/tools/grit/grit/testdata/chrome/app/generated_resources.grd b/tools/grit/grit/testdata/chrome/app/generated_resources.grd +new file mode 100644 +index 0000000000..c2efb77fd8 +--- /dev/null ++++ b/tools/grit/grit/testdata/chrome/app/generated_resources.grd +@@ -0,0 +1,199 @@ ++<?xml version="1.0" encoding="UTF-8"?> ++ ++<!-- ++This file contains definitions of resources that will be translated for each ++locale. The variables is_win, is_macosx, is_linux, and is_posix are available ++for making strings OS specific. Other platform defines such as use_titlecase ++are declared in build/common.gypi. ++--> ++ ++<grit base_dir="." latest_public_release="0" current_release="1" ++ source_lang_id="en" enc_check="möl"> ++ <outputs> ++ <output filename="grit/generated_resources.h" type="rc_header"> ++ <emit emit_type='prepend'></emit> ++ </output> ++ <output filename="generated_resources_am.pak" type="data_package" lang="am" /> ++ <output filename="generated_resources_ar.pak" type="data_package" lang="ar" /> ++ <if expr="pp_ifdef('use_third_party_translations')"> ++ <output filename="generated_resources_ast.pak" type="data_package" lang="ast" /> ++ </if> ++ <output filename="generated_resources_bg.pak" type="data_package" lang="bg" /> ++ <output filename="generated_resources_bn.pak" type="data_package" lang="bn" /> ++ <if expr="pp_ifdef('use_third_party_translations')"> ++ <output filename="generated_resources_bs.pak" type="data_package" lang="bs" /> ++ </if> ++ <output filename="generated_resources_ca.pak" type="data_package" lang="ca" /> ++ <if expr="pp_ifdef('use_third_party_translations')"> ++ <output filename="generated_resources_ca@valencia.pak" type="data_package" lang="ca@valencia" /> ++ </if> ++ <output filename="generated_resources_cs.pak" type="data_package" lang="cs" /> ++ <output filename="generated_resources_da.pak" type="data_package" lang="da" /> ++ <output filename="generated_resources_de.pak" type="data_package" lang="de" /> ++ <output filename="generated_resources_el.pak" type="data_package" lang="el" /> ++ <if expr="pp_ifdef('use_third_party_translations')"> ++ <output filename="generated_resources_en-AU.pak" type="data_package" lang="en-AU" /> ++ </if> ++ <output filename="generated_resources_en-GB.pak" type="data_package" lang="en-GB" /> ++ <output filename="generated_resources_en-US.pak" type="data_package" lang="en" /> ++ <if expr="pp_ifdef('use_third_party_translations')"> ++ <output filename="generated_resources_eo.pak" type="data_package" lang="eo" /> ++ </if> ++ <output filename="generated_resources_es.pak" type="data_package" lang="es" /> ++ <output filename="generated_resources_es-419.pak" type="data_package" lang="es-419" /> ++ <output filename="generated_resources_et.pak" type="data_package" lang="et" /> ++ <if expr="pp_ifdef('use_third_party_translations')"> ++ <output filename="generated_resources_eu.pak" type="data_package" lang="eu" /> ++ </if> ++ <output filename="generated_resources_fa.pak" type="data_package" lang="fa" /> ++ <output filename="generated_resources_fake-bidi.pak" type="data_package" lang="fake-bidi" /> ++ <output filename="generated_resources_fi.pak" type="data_package" lang="fi" /> ++ <output filename="generated_resources_fil.pak" type="data_package" lang="fil" /> ++ <output filename="generated_resources_fr.pak" type="data_package" lang="fr" /> ++ <if expr="pp_ifdef('use_third_party_translations')"> ++ <output filename="generated_resources_gl.pak" type="data_package" lang="gl" /> ++ </if> ++ <output filename="generated_resources_gu.pak" type="data_package" lang="gu" /> ++ <output filename="generated_resources_he.pak" type="data_package" lang="he" /> ++ <output filename="generated_resources_hi.pak" type="data_package" lang="hi" /> ++ <output filename="generated_resources_hr.pak" type="data_package" lang="hr" /> ++ <output filename="generated_resources_hu.pak" type="data_package" lang="hu" /> ++ <if expr="pp_ifdef('use_third_party_translations')"> ++ <output filename="generated_resources_hy.pak" type="data_package" lang="hy" /> ++ <output filename="generated_resources_ia.pak" type="data_package" lang="ia" /> ++ </if> ++ <output filename="generated_resources_id.pak" type="data_package" lang="id" /> ++ <output filename="generated_resources_it.pak" type="data_package" lang="it" /> ++ <output filename="generated_resources_ja.pak" type="data_package" lang="ja" /> ++ <if expr="pp_ifdef('use_third_party_translations')"> ++ <output filename="generated_resources_ka.pak" type="data_package" lang="ka" /> ++ </if> ++ <output filename="generated_resources_kn.pak" type="data_package" lang="kn" /> ++ <output filename="generated_resources_ko.pak" type="data_package" lang="ko" /> ++ <if expr="pp_ifdef('use_third_party_translations')"> ++ <output filename="generated_resources_ku.pak" type="data_package" lang="ku" /> ++ <output filename="generated_resources_kw.pak" type="data_package" lang="kw" /> ++ </if> ++ <output filename="generated_resources_lt.pak" type="data_package" lang="lt" /> ++ <output filename="generated_resources_lv.pak" type="data_package" lang="lv" /> ++ <output filename="generated_resources_ml.pak" type="data_package" lang="ml" /> ++ <output filename="generated_resources_mr.pak" type="data_package" lang="mr" /> ++ <if expr="pp_ifdef('use_third_party_translations')"> ++ <output filename="generated_resources_ms.pak" type="data_package" lang="ms" /> ++ </if> ++ <output filename="generated_resources_nl.pak" type="data_package" lang="nl" /> ++ <!-- The translation console uses 'no' for Norwegian Bokmål. It should ++ be 'nb'. --> ++ <output filename="generated_resources_nb.pak" type="data_package" lang="no" /> ++ <output filename="generated_resources_pl.pak" type="data_package" lang="pl" /> ++ <output filename="generated_resources_pt-BR.pak" type="data_package" lang="pt-BR" /> ++ <output filename="generated_resources_pt-PT.pak" type="data_package" lang="pt-PT" /> ++ <output filename="generated_resources_ro.pak" type="data_package" lang="ro" /> ++ <output filename="generated_resources_ru.pak" type="data_package" lang="ru" /> ++ <output filename="generated_resources_sk.pak" type="data_package" lang="sk" /> ++ <output filename="generated_resources_sl.pak" type="data_package" lang="sl" /> ++ <output filename="generated_resources_sr.pak" type="data_package" lang="sr" /> ++ <output filename="generated_resources_sv.pak" type="data_package" lang="sv" /> ++ <output filename="generated_resources_sw.pak" type="data_package" lang="sw" /> ++ <output filename="generated_resources_ta.pak" type="data_package" lang="ta" /> ++ <output filename="generated_resources_te.pak" type="data_package" lang="te" /> ++ <output filename="generated_resources_th.pak" type="data_package" lang="th" /> ++ <output filename="generated_resources_tr.pak" type="data_package" lang="tr" /> ++ <if expr="pp_ifdef('use_third_party_translations')"> ++ <output filename="generated_resources_ug.pak" type="data_package" lang="ug" /> ++ </if> ++ <output filename="generated_resources_uk.pak" type="data_package" lang="uk" /> ++ <output filename="generated_resources_vi.pak" type="data_package" lang="vi" /> ++ <output filename="generated_resources_zh-CN.pak" type="data_package" lang="zh-CN" /> ++ <output filename="generated_resources_zh-TW.pak" type="data_package" lang="zh-TW" /> ++ </outputs> ++ <translations> ++ <file path="resources/generated_resources_am.xtb" lang="am" /> ++ <file path="resources/generated_resources_ar.xtb" lang="ar" /> ++ <file path="../../third_party/launchpad_translations/generated_resources_ast.xtb" lang="ast" /> ++ <file path="resources/generated_resources_bg.xtb" lang="bg" /> ++ <file path="resources/generated_resources_bn.xtb" lang="bn" /> ++ <file path="../../third_party/launchpad_translations/generated_resources_bs.xtb" lang="bs" /> ++ <file path="resources/generated_resources_ca.xtb" lang="ca" /> ++ <file path="../../third_party/launchpad_translations/generated_resources_ca-valencia.xtb" lang="ca@valencia" /> ++ <file path="resources/generated_resources_cs.xtb" lang="cs" /> ++ <file path="resources/generated_resources_da.xtb" lang="da" /> ++ <file path="resources/generated_resources_de.xtb" lang="de" /> ++ <file path="resources/generated_resources_el.xtb" lang="el" /> ++ <file path="../../third_party/launchpad_translations/generated_resources_en-AU.xtb" lang="en-AU" /> ++ <file path="resources/generated_resources_en-GB.xtb" lang="en-GB" /> ++ <file path="../../third_party/launchpad_translations/generated_resources_eo.xtb" lang="eo" /> ++ <file path="resources/generated_resources_es.xtb" lang="es" /> ++ <file path="resources/generated_resources_es-419.xtb" lang="es-419" /> ++ <file path="resources/generated_resources_et.xtb" lang="et" /> ++ <file path="../../third_party/launchpad_translations/generated_resources_eu.xtb" lang="eu" /> ++ <file path="resources/generated_resources_fa.xtb" lang="fa" /> ++ <file path="resources/generated_resources_fi.xtb" lang="fi" /> ++ <file path="resources/generated_resources_fil.xtb" lang="fil" /> ++ <file path="resources/generated_resources_fr.xtb" lang="fr" /> ++ <file path="../../third_party/launchpad_translations/generated_resources_gl.xtb" lang="gl" /> ++ <file path="resources/generated_resources_gu.xtb" lang="gu" /> ++ <file path="resources/generated_resources_hi.xtb" lang="hi" /> ++ <file path="resources/generated_resources_hr.xtb" lang="hr" /> ++ <file path="resources/generated_resources_hu.xtb" lang="hu" /> ++ <file path="../../third_party/launchpad_translations/generated_resources_hy.xtb" lang="hy" /> ++ <file path="../../third_party/launchpad_translations/generated_resources_ia.xtb" lang="ia" /> ++ <file path="resources/generated_resources_id.xtb" lang="id" /> ++ <file path="resources/generated_resources_it.xtb" lang="it" /> ++ <!-- The translation console uses 'iw' for Hebrew, but we use 'he'. --> ++ <file path="resources/generated_resources_iw.xtb" lang="he" /> ++ <file path="resources/generated_resources_ja.xtb" lang="ja" /> ++ <file path="../../third_party/launchpad_translations/generated_resources_ka.xtb" lang="ka" /> ++ <file path="resources/generated_resources_kn.xtb" lang="kn" /> ++ <file path="resources/generated_resources_ko.xtb" lang="ko" /> ++ <file path="../../third_party/launchpad_translations/generated_resources_ku.xtb" lang="ku" /> ++ <file path="../../third_party/launchpad_translations/generated_resources_kw.xtb" lang="kw" /> ++ <file path="resources/generated_resources_lt.xtb" lang="lt" /> ++ <file path="resources/generated_resources_lv.xtb" lang="lv" /> ++ <file path="resources/generated_resources_ml.xtb" lang="ml" /> ++ <file path="resources/generated_resources_mr.xtb" lang="mr" /> ++ <file path="../../third_party/launchpad_translations/generated_resources_ms.xtb" lang="ms" /> ++ <file path="resources/generated_resources_nl.xtb" lang="nl" /> ++ <file path="resources/generated_resources_no.xtb" lang="no" /> ++ <file path="resources/generated_resources_pl.xtb" lang="pl" /> ++ <file path="resources/generated_resources_pt-BR.xtb" lang="pt-BR" /> ++ <file path="resources/generated_resources_pt-PT.xtb" lang="pt-PT" /> ++ <file path="resources/generated_resources_ro.xtb" lang="ro" /> ++ <file path="resources/generated_resources_ru.xtb" lang="ru" /> ++ <file path="resources/generated_resources_sk.xtb" lang="sk" /> ++ <file path="resources/generated_resources_sl.xtb" lang="sl" /> ++ <file path="resources/generated_resources_sr.xtb" lang="sr" /> ++ <file path="resources/generated_resources_sv.xtb" lang="sv" /> ++ <file path="resources/generated_resources_sw.xtb" lang="sw" /> ++ <file path="resources/generated_resources_ta.xtb" lang="ta" /> ++ <file path="resources/generated_resources_te.xtb" lang="te" /> ++ <file path="resources/generated_resources_th.xtb" lang="th" /> ++ <file path="resources/generated_resources_tr.xtb" lang="tr" /> ++ <file path="../../third_party/launchpad_translations/generated_resources_ug.xtb" lang="ug" /> ++ <file path="resources/generated_resources_uk.xtb" lang="uk" /> ++ <file path="resources/generated_resources_vi.xtb" lang="vi" /> ++ <file path="resources/generated_resources_zh-CN.xtb" lang="zh-CN" /> ++ <file path="resources/generated_resources_zh-TW.xtb" lang="zh-TW" /> ++ </translations> ++ <release seq="1" allow_pseudo="false"> ++ <messages fallback_to_english="true"> ++ <!-- TODO add all of your "string table" messages here. Remember to ++ change nontranslateable parts of the messages into placeholders (using the ++ <ph> element). You can also use the 'grit add' tool to help you identify ++ nontranslateable parts and create placeholders for them. --> ++ <message name="IDS_BACKGROUND_APP_INSTALLED_BALLOON_TITLE" desc="The title of the balloon that is displayed when a background app is installed"> ++ New background app installed ++ </message> ++ <message name="IDS_BACKGROUND_APP_INSTALLED_BALLOON_BODY" desc="The contents of the balloon that is displayed when a background app is installed"> ++ <ph name="APP_NAME">$1<ex>Background App</ex></ph> will launch at system startup and continue to run in the background even once you've closed all other <ph name="PRODUCT_NAME">$2<ex>Google Chrome</ex></ph> windows. ++ </message> ++ </messages> ++ <structures fallback_to_english="true"> ++ <!-- Make sure these stay in sync with the structures in generated_resources.grd. --> ++ <structure name="IDD_CHROME_FRAME_FIND_DIALOG" file="cf_resources.rc" type="dialog" > ++ </structure> ++ <structure name="IDD_CHROME_FRAME_READY_PROMPT" file="cf_resources.rc" type="dialog" > ++ </structure> ++ </structures> ++ </release> ++</grit> +diff --git a/tools/grit/grit/testdata/chrome_html.html b/tools/grit/grit/testdata/chrome_html.html new file mode 100644 -index 0000000000..301449c4ac +index 0000000000..7f7633c5cf --- /dev/null -+++ b/tools/clang/plugins/tests/missing_ctor.txt ++++ b/tools/grit/grit/testdata/chrome_html.html @@ -0,0 +1,6 @@ -+In file included from missing_ctor.cpp:5: -+./missing_ctor.h:11:1: warning: [chromium-style] Complex class/struct needs an explicit out-of-line constructor. -+class MissingCtorsArentOKInHeader { -+^ -+./missing_ctor.h:11:1: warning: [chromium-style] Complex class/struct needs an explicit out-of-line destructor. -+2 warnings generated. -diff --git a/tools/clang/plugins/tests/nested_class_inline_ctor.cpp b/tools/clang/plugins/tests/nested_class_inline_ctor.cpp ++<include src="included_sample.html"> ++<style type="text/css"> ++#image { ++ content: url('chrome://theme/IDR_SOME_FILE'); ++} ++</style> +diff --git a/tools/grit/grit/testdata/default_100_percent/a.png b/tools/grit/grit/testdata/default_100_percent/a.png +new file mode 100644 +index 0000000000000000000000000000000000000000..5d5089038ca71172e95db9e7aae1e1fa5cebd505 +GIT binary patch +literal 159 +zcmeAS@N?(olHy`uVBq!ia0vp^oFL4>0wld=oSO}#(mY)pLnNjq|2Y3)zGGzYPN&L+ +zMSC}CcCfp=Dtxv4%6W%G#Q=|R|L;6pCCLUWO)Z<5eoL%TkDTw=s4X!^d(Qa<2khAN +zZPy!XToBAic1Ss}vcWiD27B3&`Zj^H6CO>7R1{ToQ;=ggdEYbV=IISvfHpFCy85}S +Ib4q9e0O9jEh5!Hn + +literal 0 +HcmV?d00001 + +diff --git a/tools/grit/grit/testdata/default_100_percent/b.png b/tools/grit/grit/testdata/default_100_percent/b.png +new file mode 100644 +index 0000000000..6178079822 +--- /dev/null ++++ b/tools/grit/grit/testdata/default_100_percent/b.png +@@ -0,0 +1 @@ ++b +diff --git a/tools/grit/grit/testdata/del_footer.html b/tools/grit/grit/testdata/del_footer.html +new file mode 100644 +index 0000000000..4e19950bfc +--- /dev/null ++++ b/tools/grit/grit/testdata/del_footer.html +@@ -0,0 +1,8 @@ ++<table cellspacing=0 cellpadding=2 width="100%" border=0> ++<tr bgcolor=#EFEFEF><td><font size=-1> <b>Remove</b> checked results and <b>return to search</b>.</font></td> ++<td align=right><font size=-1><a onClick='checkall(1)' href="#">Check all</a> - <a onClick='checkall(0)' href="#">Uncheck all</a> </font></td> ++<td align=right width=1% nowrap><font size=-1> ++<input onclick=deleting() type=submit value="Remove checked results" name=submit2> ++</font></td></tr></table> ++<center><br><font size=-1>[$~BOTTOMLINE~$] - ©2005 Google </font></center> ++</body></html> +diff --git a/tools/grit/grit/testdata/del_header.html b/tools/grit/grit/testdata/del_header.html +new file mode 100644 +index 0000000000..72bc6756eb +--- /dev/null ++++ b/tools/grit/grit/testdata/del_header.html +@@ -0,0 +1,60 @@ ++<body bgcolor="#ffffff" topmargin="2" marginheight="2"> ++<table cellSpacing="2" cellPadding="0" width="100%" border="0"> ++<form action='[$~DELETE~$]' method="post" name="delform"> ++<input name="redir" type="hidden" value="[REDIR]"> ++<script> ++<!-- ++function deleting() { ++f=document.getElementsByName("del"); ++var num = 0; ++if (f.length) ++ for(i=0;i<f.length; i++) ++ if(f[i].checked) num++; ++ if (num == 1) alert("One checked result has been removed"); ++ else if (num > 1) alert(num + " checked results have been removed"); ++ else alert("No results were checked, so no results have been removed"); ++} ++function checkall(v) { ++ f=document.getElementsByName("del"); ++ if (f.length) ++ for(i=0;i<f.length; i++) ++ f[i].checked=v; ++} ++//--> ++</script> ++<tr> ++<td vAlign="top" width="1%"><A href='[$~HOMEPAGE~$]'> <img alt="Go to Google Desktop Search" width="150" height="55" src="/logo3.gif" border="0" vspace="12"></A></td> ++<td> </td> ++<td noWrap> ++ <table cellSpacing="0" cellPadding="0" width="100%" border="0"> ++ <tr> ++ <td bgColor="#DD0000"><img height="1" alt="" width="1"></td> ++ </tr> ++ </table> ++ <table cellSpacing="0" cellPadding="0" width="100%" border="0"> ++ <tr> ++ <td noWrap bgColor="#efefef"><font size="+1"><b> Remove Specific Items</b></font></td> ++ <td noWrap align="right" bgColor="#efefef"><font size="-1"><a href="http://desktop.google.com/remove.html">Help</a> </font></td> ++ </tr> ++ </table> ++</td> ++</tr> ++</table> ++<table cellSpacing="0" cellPadding="2" width="100%" border="0"> ++<tr bgColor="#EFEFEF"> ++<td><font size="-1"> <B>Remove</B> checked results and <B>return to search</B>.</font></td> ++<td align="right"><font size="-1"><a onClick='checkall(1)' href="#">Check all</a> - <a onClick='checkall(0)' href="#"> ++Uncheck all</a> </font></td> ++<td align="right" width="1%" nowrap><font size="-1"><input onclick="deleting()" type="submit" value="Remove checked results" name="submit2"></font></td> ++</tr> ++</table> ++<br> ++<table cellspacing="0" cellpadding="2" width="100%" border="0"> ++<tr> ++<td colSpan="3" bgcolor="#FFFFFF" style="border:solid; border-width:1px; border-color:#DD0000"><font size="-1"> <b>Remove ++checked items from Google Desktop Search. Other copies of the same items will not be ++affected.<br> ++ If you view the item again, it will be added back to Google Desktop Search.</b></font></td> ++</tr> ++</table> ++<br> +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/deleted.html b/tools/grit/grit/testdata/deleted.html +new file mode 100644 +index 0000000000..5ae5f355fa +--- /dev/null ++++ b/tools/grit/grit/testdata/deleted.html +@@ -0,0 +1,21 @@ ++<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ++<html><head><title>Database Deleted</title> ++<meta http-equiv="content-type" content="text/html; charset=utf-8"> ++<meta http-equiv="cache-control" content="no-cache"> ++<meta http-equiv="pragma" content="no-cache"> ++<meta http-equiv="expires" content="-1"> ++<style> ++BODY,TD,A,P {FONT-FAMILY: arial,sans-serif} ++.q {COLOR: #0000cc} ++</style> ++</head> ++<BODY text=#000000 vLink=#551a8b aLink=#ff0000 link=#0000cc bgColor=#ffffff onload=sf()> ++<center> ++<TABLE cellSpacing=0 cellPadding=0 border=0> ++<tr><td><a href="[$~HOMEPAGE~$]"><IMG border=0 height=110 alt="Google Desktop Search" src="hp_logo.gif" width=276></a> ++</td></tr></table><BR> ++<center>The database has been deleted. Click <a href="[$~HOMEPAGE~$]">here</a> to continue.</center> ++</td></tr> ++</table> ++<br><FONT size=-1>[$~BOTTOMLINE~$]</font></p> ++<p><FONT size=-2>©2005 Google</font></p></center></body></html> +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/depfile.grd b/tools/grit/grit/testdata/depfile.grd +new file mode 100644 +index 0000000000..e2f7191218 +--- /dev/null ++++ b/tools/grit/grit/testdata/depfile.grd +@@ -0,0 +1,18 @@ ++<?xml version="1.0" encoding="UTF-8"?> <!-- -*- XML -*- --> ++<grit ++ base_dir="." ++ latest_public_release="0" ++ current_release="1"> ++ <outputs> ++ <output filename="default_100_percent.pak" lang="en" type="data_package" context="default_100_percent" /> ++ <output filename="special_100_percent.pak" lang="en" type="data_package" context="special_100_percent" /> ++ </outputs> ++ <release seq="1"> ++ <structures fallback_to_low_resolution="true"> ++ <if expr="False"> ++ <part file="grit_part.grdp" /> ++ </if> ++ <structure type="chrome_scaled_image" name="IDR_A" file="a.png" /> ++ </structures> ++ </release> ++</grit> +diff --git a/tools/grit/grit/testdata/details.html b/tools/grit/grit/testdata/details.html +new file mode 100644 +index 0000000000..0ab0e2a90c +--- /dev/null ++++ b/tools/grit/grit/testdata/details.html +@@ -0,0 +1,10 @@ ++[!] ++title Improve Google Desktop Search by Sending Non-Personal Information ++template ++bottomline ++hp_image ++ ++<p><strong>This documentation is not yet available</strong></p> ++<center><br> ++<font size=-1>[$~BOTTOMLINE~$] - ©2005 Google </font> ++</center> +diff --git a/tools/grit/grit/testdata/duplicate-name-input.xml b/tools/grit/grit/testdata/duplicate-name-input.xml +new file mode 100644 +index 0000000000..cc4d1d65c5 +--- /dev/null ++++ b/tools/grit/grit/testdata/duplicate-name-input.xml +@@ -0,0 +1,26 @@ ++<?xml version="1.0" encoding="UTF-8"?> ++<grit base_dir="." latest_public_release="2" current_release="3" source_lang_id="en-US"> ++ <release seq="3"> ++ <messages> ++ <message name="IDS_GREETING" desc="Printed to greet the currently logged in user"> ++ Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today? ++ </message> ++ </messages> ++ <structures> ++ <!-- Duplicate name here --> ++ <structure type="version" name="IDS_GREETING" file="rc_files/bla.rc" /> ++ </structures> ++ </release> ++ <translations> ++ <file path="figs_nl_translations.xml" /> ++ <file path="cjk_translations.xml" /> ++ </translations> ++ <outputs> ++ <output filename="resource.h" type="rc_header" /> ++ <output filename="resource_en.rc" type="rc_all" lang="en-US" /> ++ <output filename="resource_fr.rc" type="rc_all" lang="fr-FR" /> ++ <output filename="resource_it.rc" type="rc_translateable" lang="it-IT" /> ++ <output filename="resource_zh_cn.rc" type="rc_translateable" lang="zh-CN" /> ++ <output filename="nontranslateable.rc" type="rc_nontranslateable" /> ++ </outputs> ++</grit> +diff --git a/tools/grit/grit/testdata/email_result.html b/tools/grit/grit/testdata/email_result.html +new file mode 100644 +index 0000000000..8bb04b988c +--- /dev/null ++++ b/tools/grit/grit/testdata/email_result.html +@@ -0,0 +1,34 @@ ++[HEADER] ++[CHROME] ++<table border=0 cellpadding=2 cellspacing=2 width='100%'> ++<tr><td><font size=-1>[CONV] ++<a href='[$~REPLY_URL~$]'>Reply</a> | <a href='[$~REPLYALL_URL~$]'>Reply to All</a>[$~FORWARD_URL~$] | <a href='mailto:'>Compose</a>[$~OUTLOOKVIEW~$] ++</font></td></tr> ++</table> ++<blockquote id=gg_1> ++<table bgcolor=#f0f8ff width=80% cellpadding=5><tr><td> ++<img style="vertical-align:middle;" height=16 src='/email.gif' width=16> <b>[SUBJECT]</b> ++<p><font size=-1>[FROM-DISP] ++[TO-DISP] ++[CC-DISP] ++[BCC-DISP] ++[REPLYTO-DISP] ++[DATE-DISP] ++[VIEW-DISP] ++[$~ATTACH~$] ++</font></td></tr></table> ++<p class=g><span style="width:500;"><font size=-1><label>[MESSAGE]</label></span></p> ++</font> ++</blockquote> ++<table border=0 cellpadding=2 cellspacing=2 width='100%'> ++<tr><td><font size=-1>[CONV] ++<a href='[$~REPLY_URL~$]'>Reply</a> | <a href='[$~REPLYALL_URL~$]'>Reply to All</a>[$~FORWARD_URL~$] | <a href='mailto:'>Compose</a>[$~OUTLOOKVIEW~$] ++</font></td></tr></table> ++<style> ++.hl { color:black; background-color:#ffff88} ++</style> ++<script> ++[$~HIGHLIGHT_SCRIPT~$] ++[ONLOAD] ++</script> ++[FOOTER] +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/email_thread.html b/tools/grit/grit/testdata/email_thread.html +new file mode 100644 +index 0000000000..3c7279b841 +--- /dev/null ++++ b/tools/grit/grit/testdata/email_thread.html +@@ -0,0 +1,10 @@ ++[HEADER] ++[CHROME] ++<blockquote [MAXWIDTH]> ++<b><img src=email.gif style="vertical-align:middle;" width=16 height=16> [SUBJECT]</b><br><br> ++<TABLE cellSpacing=0 cellPadding=3 border=0> ++[CONTENTS] ++</table> ++</blockquote> ++[NEXT_PREV] ++[FOOTER] +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/error.html b/tools/grit/grit/testdata/error.html +new file mode 100644 +index 0000000000..66875a234c +--- /dev/null ++++ b/tools/grit/grit/testdata/error.html +@@ -0,0 +1,8 @@ ++[HEADER] ++[CHROME] ++<br> ++<blockquote> ++[ERROR]<br><br> ++If you think this is an error, please <a href="http://desktop.google.com/feedback.html?version=[VERSION]">contact us</a>. ++</blockquote> ++[FOOTER] +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/explicit_web.html b/tools/grit/grit/testdata/explicit_web.html +new file mode 100644 +index 0000000000..1424adc617 +--- /dev/null ++++ b/tools/grit/grit/testdata/explicit_web.html +@@ -0,0 +1,11 @@ ++[HEADER] ++<style> ++.image {BORDER: #0000cc 1px solid;} ++.imageh {BORDER: #0000cc 1px solid;} ++</style> ++[WEB_TOP_CHROME] ++[$~STATUS~$] ++[$~MESSAGE~$] ++[WEB_FILES] ++<br>[NEXT_PREV] ++[FOOTER] +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/footer.html b/tools/grit/grit/testdata/footer.html +new file mode 100644 +index 0000000000..3372d6afac +--- /dev/null ++++ b/tools/grit/grit/testdata/footer.html +@@ -0,0 +1,14 @@ ++<center><br clear=all><br> ++<table cellspacing=0 cellpadding=0 width="100%" border=0><tr bgcolor=#3399CC><td align=middle height=1><img height=1 width=1></td></tr></table> ++<table cellspacing=0 cellpadding=0 width="100%" bgcolor=#e8f4f7 border=0> ++<tr bgcolor=#e8f4f7> ++<td><br> ++<table cellpadding=1 align=center border=0 cellspacing=0 bgcolor=#e8f4f7> ++<form action='[$~SEARCHURL~$]' method=get> ++<tr><td noWrap>[$~BOTTOM~$]</td></tr></form> ++</table><br> ++</td></tr></table> ++<table cellspacing=0 cellpadding=0 width="100%" border=0><tr bgcolor=#3399CC><td align=middle height=1><img height=1 width=1></td></tr></table><br> ++<font size=-1>[$~BOTTOMLINE~$] - ©2005 Google </font></center> ++[SCRIPT] ++</body></html> +diff --git a/tools/grit/grit/testdata/generated_resources_fr.xtb b/tools/grit/grit/testdata/generated_resources_fr.xtb +new file mode 100644 +index 0000000000..373c40feea +--- /dev/null ++++ b/tools/grit/grit/testdata/generated_resources_fr.xtb +@@ -0,0 +1,3079 @@ ++<?xml version="1.0" ?> ++<!DOCTYPE translationbundle> ++<translationbundle lang="fr"> ++<translation id="1525924600121678168">Salut!</translation> ++<translation id="5335090254790956485">Salut <ph name="USERNAME"/></translation> ++<translation id="6779164083355903755">Supprime&r</translation> ++<translation id="6879617193011158416">Activer la barre de favoris</translation> ++<translation id="8130276680150879341">Déconnexion du réseau privé</translation> ++<translation id="1058418043520174283"><ph name="INDEX"/> sur <ph name="COUNT"/></translation> ++<translation id="4480627574828695486">Déconnecter ce compte...</translation> ++<translation id="7040807039050164757">&Vérifier l'orthographe dans ce champ</translation> ++<translation id="778579833039460630">Aucune donnée reçue.</translation> ++<translation id="1852799913675865625">Une erreur s'est produite lors de la tentative de lecture du fichier : <ph name="ERROR_TEXT"/>.</translation> ++<translation id="3828924085048779000">Le mot de passe multiterme est obligatoire.</translation> ++<translation id="8265562484034134517">Importer les données d'un autre navigateur...</translation> ++<translation id="2709516037105925701">Saisie automatique</translation> ++<translation id="4857138207355690859">API P2P</translation> ++<translation id="250599269244456932">Exécuter automatiquement (recommandé)</translation> ++<translation id="3581034179710640788">Le certificat de sécurité du site a expiré !</translation> ++<translation id="2825758591930162672">Clé publique de l'objet</translation> ++<translation id="8275038454117074363">Importer</translation> ++<translation id="8418445294933751433">Afficher dan&s un onglet</translation> ++<translation id="6985276906761169321">ID :</translation> ++<translation id="859285277496340001">Le certificat n'indique aucun mécanisme permettant de vérifier s'il a été révoqué.</translation> ++<translation id="2010799328026760191">Touches de modification...</translation> ++<translation id="3300394989536077382">Signé par :</translation> ++<translation id="654233263479157500">Utiliser un service Web pour résoudre les erreurs de navigation</translation> ++<translation id="4940047036413029306">Guillemet</translation> ++<translation id="1526811905352917883">Une nouvelle tentative de connexion avec SSL 3.0 a dû être effectuée. Cette opération indique généralement que le serveur utilise un logiciel très ancien et qu'il est susceptible de présenter d'autres problèmes de sécurité.</translation> ++<translation id="1497897566809397301">Autoriser le stockage des données locales (recommandé)</translation> ++<translation id="3275778913554317645">Ouvrir dans une fenêtre</translation> ++<translation id="4553117311324416101">Google pense qu'un logiciel malveillant pourrait être installé sur votre ordinateur si vous continuez. Nous vous conseillons de ne pas continuer, même si vous avez déjà consulté ce site auparavant ou si vous avez confiance en celui-ci. Il se peut qu'il ait été piraté récemment. Réessayez demain ou utilisez un autre site.</translation> ++<translation id="509988127256758334">&Rechercher :</translation> ++<translation id="1420684932347524586">Échec de génération de clé privée RSA aléatoire</translation> ++<translation id="2501173422421700905">Certificat en attente</translation> ++<translation id="2313634973119803790">Technologie réseau :</translation> ++<translation id="2382901536325590843">Le certificat du serveur ne figure pas dans le DNS.</translation> ++<translation id="2833791489321462313">Demander le mot de passe au retour de veille</translation> ++<translation id="3850258314292525915">Désactiver la synchronisation</translation> ++<translation id="2721561274224027017">Base de données indexée</translation> ++<translation id="8208216423136871611">Ne pas enregistrer</translation> ++<translation id="684587995079587263"><ph name="PRODUCT_NAME"/> synchronise vos données avec votre compte Google en toute sécurité. Synchronisez toutes vos données ou personnalisez les types de données synchronisées et les options de chiffrement.</translation> ++<translation id="4405141258442788789">Le délai imparti à l'opération est dépassé.</translation> ++<translation id="5048179823246820836">Nordique</translation> ++<translation id="1763046204212875858">Créer des raccourcis vers des applications</translation> ++<translation id="2105006017282194539">Pas encore chargé</translation> ++<translation id="524759338601046922">Confirmer le nouveau code PIN :</translation> ++<translation id="688547603556380205">L2TP/IPSec + Certificat utilisateur</translation> ++<translation id="777702478322588152">Préfecture</translation> ++<translation id="6562437808764959486">Extraction de l'image de récupération...</translation> ++<translation id="561349411957324076">Terminé</translation> ++<translation id="4764776831041365478">Il se peut que la page Web à l'adresse <ph name="URL"/> soit temporairement inaccessible ou qu'elle ait été déplacée de façon permanente à une autre adresse Web.</translation> ++<translation id="6156863943908443225">Cache des scripts</translation> ++<translation id="4610656722473172270">Barre d'outils Google</translation> ++<translation id="151501797353681931">Importés depuis Safari</translation> ++<translation id="6706684875496318067">Le plug-in <ph name="PLUGIN_NAME"/> n'est pas autorisé.</translation> ++<translation id="586567932979200359">Vous exécutez <ph name="PRODUCT_NAME"/> à partir de son image disque. Si vous l'installez sur votre ordinateur, vous pourrez l'utiliser sans image disque et bénéficierez de mises à jour automatiques.</translation> ++<translation id="3775432569830822555">Certificat du serveur SSL</translation> ++<translation id="1829192082282182671">Z&oom arrière</translation> ++<translation id="6102827823267795198">Indique si la suggestion du moteur de recherche doit être entrée immédiatement via la saisie semi-automatique lorsque la fonctionnalité Recherche instantanée est activée.</translation> ++<translation id="1467071896935429871">Mise à jour du système : <ph name="PERCENT"/> % téléchargés</translation> ++<translation id="7881267037441701396">Les informations d'identification associées au partage de vos imprimantes via <ph name="CLOUD_PRINT_NAME"/> sont arrivées à expiration. Cliquez ici pour saisir à nouveau votre nom d'utilisateur et votre mot de passe.</translation> ++<translation id="816055135686411707">Erreur de définition du paramètre de confiance du certificat</translation> ++<translation id="4714531393479055912"><ph name="PRODUCT_NAME"/> peut maintenant synchroniser vos mots de passe.</translation> ++<translation id="5704565838965461712">Sélectionnez le certificat à présenter pour l'identification :</translation> ++<translation id="2025632980034333559"><ph name="APP_NAME"/> a planté. Cliquez sur cette info-bulle pour actualiser l'extension.</translation> ++<translation id="4059593000330943833">Compatibilité expérimentale avec des méthodes Wi-Fi Extensible Authentication Protocol supplémentaires, telles que EAP-TLS et LEAP.</translation> ++<translation id="6322279351188361895">Échec de lecture de la clé privée</translation> ++<translation id="3781072658385678636">Les plug-ins suivants ont été bloqués sur cette page :</translation> ++<translation id="4428782877951507641">Configuration de la synchronisation</translation> ++<translation id="3648460724479383440">Case d'option cochée</translation> ++<translation id="4654488276758583406">Très petite</translation> ++<translation id="6647228709620733774">URL de révocation de l'autorité de certification Netscape</translation> ++<translation id="546411240573627095">Style de pavé numérique</translation> ++<translation id="7663002797281767775">Active les feuilles de style CSS 3D et la composition graphique haute performance des pages Web via le processeur graphique.</translation> ++<translation id="2972581237482394796">&Rétablir</translation> ++<translation id="5895138241574237353">Redémarrer</translation> ++<translation id="1858072074757584559">La connexion n'est pas compressée.</translation> ++<translation id="528468243742722775">Fin</translation> ++<translation id="1723824996674794290">&Nouvelle fenêtre</translation> ++<translation id="1313405956111467313">Configuration automatique du proxy</translation> ++<translation id="1589055389569595240">Afficher l'orthographe et la grammaire</translation> ++<translation id="4364779374839574930">Aucune imprimante n'a été trouvée. Veuillez en installer une.</translation> ++<translation id="7017587484910029005">Saisissez les caractères visibles dans l'image ci-dessous.</translation> ++<translation id="9013589315497579992">Certificat d'authentification de client SSL incorrect</translation> ++<translation id="8595062045771121608">Le certificat du serveur ou un certificat AC intermédiaire présenté au navigateur a été signé avec un algorithme de signature faible tel que RSA-MD2. D'après des études récentes menées par des informaticiens, les algorithmes de signature seraient plus faibles qu'on ne le pensait jusqu'alors. Aujourd'hui, ils sont très rarement utilisés par les sites Web jugés dignes de confiance. Ce certificat a peut-être été contrefait. Nous vous déconseillons vivement de continuer.</translation> ++<translation id="8666632926482119393">Rechercher le précédent</translation> ++<translation id="7567293639574541773">I&nspecter l'élément</translation> ++<translation id="8392896330146417149">État d'itinérance :</translation> ++<translation id="6813971406343552491">&Non</translation> ++<translation id="36224234498066874">Effacer les données de navigation...</translation> ++<translation id="3384773155383850738">Nombre maximal de suggestions</translation> ++<translation id="8331498498435985864">L'accessibilité est désactivée.</translation> ++<translation id="8530339740589765688">Sélectionner par domaine</translation> ++<translation id="8677212948402625567">Tout réduire...</translation> ++<translation id="7600965453749440009">Ne jamais traduire les pages rédigées en <ph name="LANGUAGE"/> </translation> ++<translation id="3208703785962634733">Non confirmé</translation> ++<translation id="6523841952727744497">Avant de vous connecter, démarrez une session en tant qu'invité afin d'activer le réseau <ph name="NETWORK_ID"/>.</translation> ++<translation id="7450044767321666434">La gravure de l'image est terminée.</translation> ++<translation id="2653266418988778031">Si vous supprimez le certificat d'une autorité de certification, votre navigateur ne fera plus confiance aux certificats émis par cette autorité de certification.</translation> ++<translation id="298068999958468740">Synchronisez toutes les données de cet ordinateur ou sélectionnez celles que vous souhaitez synchroniser.</translation> ++<translation id="5341849548509163798"><ph name="NUMBER_MANY"/> hours ago</translation> ++<translation id="4422428420715047158">Domaine :</translation> ++<translation id="3602290021589620013">Aperçu</translation> ++<translation id="7516602544578411747">Associe chaque fenêtre du navigateur à un profil et ajoute une option de sélection des profils en haut à droite. Chaque profil possède ses propres favoris, extensions, applications, etc.</translation> ++<translation id="7082055294850503883">Ignorer le verrouillage des majuscules et saisir des minuscules par défaut</translation> ++<translation id="1800124151523561876">Aucune parole détectée</translation> ++<translation id="7814266509351532385">Changer de moteur de recherche par défaut</translation> ++<translation id="5376169624176189338">Cliquer pour revenir en arrière, maintenir pour voir l'historique</translation> ++<translation id="6310545596129886942"><ph name="NUMBER_FEW"/> secondes restantes</translation> ++<translation id="9181716872983600413">Unicode</translation> ++<translation id="1383861834909034572">Ouverture à la fin du téléchargement</translation> ++<translation id="5727728807527375859">Les extensions, les applications et les thèmes peuvent endommager votre ordinateur. Voulez-vous vraiment continuer ?</translation> ++<translation id="3857272004253733895">Schéma du pinyin double</translation> ++<translation id="1636842079139032947">Déconnecter ce compte...</translation> ++<translation id="6721972322305477112">&Fichier</translation> ++<translation id="1076818208934827215">Microsoft Internet Explorer</translation> ++<translation id="9056810968620647706">Aucune correspondance trouvée</translation> ++<translation id="1901494098092085382">État de votre commentaire</translation> ++<translation id="2861301611394761800">Mise à jour terminée. Veuillez redémarrer le système.</translation> ++<translation id="2231238007119540260">Lorsque vous supprimez un certificat de serveur, vous rétablissez les contrôles de sécurité habituels du serveur et un certificat valide lui est demandé.</translation> ++<translation id="5463582782056205887">Essayez d'ajouter ++ <ph name="PRODUCT_NAME"/> ++ aux programmes autorisés dans les paramètres de votre pare-feu ou de votre antivirus. S'il ++ est déjà autorisé, tentez de le supprimer de la liste et de l'ajouter à nouveau à ++ la liste des programmes autorisés.</translation> ++<translation id="7624154074265342755">Réseaux sans fil</translation> ++<translation id="3315158641124845231">Masquer <ph name="PRODUCT_NAME"/></translation> ++<translation id="3496213124478423963">Zoom arrière</translation> ++<translation id="2296019197782308739">Méthode EAP :</translation> ++<translation id="42981349822642051">Développer</translation> ++<translation id="4013794286379809233">Veuillez vous connecter</translation> ++<translation id="7693221960936265065">de n'importe quand</translation> ++<translation id="1763138995382273070">Désactiver la validation des formulaires interactifs HTML5</translation> ++<translation id="4920887663447894854">Le suivi de votre position géographique sur cette page a été bloqué pour les sites suivants :</translation> ++<translation id="7690346658388844119">La gravure de l'image a été interrompue.</translation> ++<translation id="8133676275609324831">&Afficher dans le dossier</translation> ++<translation id="645705751491738698">Continuer à bloquer JavaScript</translation> ++<translation id="4780321648949301421">Enregistrer la page sous...</translation> ++<translation id="9154072353677278078">Le serveur <ph name="DOMAIN"/> à l'adresse <ph name="REALM"/> requiert un nom d'utilisateur et un mot de passe.</translation> ++<translation id="2551191967044410069">Exceptions de géolocalisation</translation> ++<translation id="4092066334306401966">13px</translation> ++<translation id="8178665534778830238">Contenu :</translation> ++<translation id="153384433402665971">Le plug-in <ph name="PLUGIN_NAME"/> a été bloqué, car il n'est plus à jour.</translation> ++<translation id="2610260699262139870">Taille ré&elle</translation> ++<translation id="4535734014498033861">Échec de la connexion au serveur proxy.</translation> ++<translation id="558170650521898289">Vérification de pilote matériel Microsoft Windows</translation> ++<translation id="98515147261107953">Paysage</translation> ++<translation id="8974161578568356045">Détecter automatiquement</translation> ++<translation id="1818606096021558659">Page</translation> ++<translation id="5388588172257446328">Nom d'utilisateur :</translation> ++<translation id="1657406563541664238">Nous aider à améliorer <ph name="PRODUCT_NAME"/> en envoyant automatiquement les statistiques d'utilisation et les rapports d'erreur à Google</translation> ++<translation id="7982789257301363584">Réseau</translation> ++<translation id="8528962588711550376">Connexion en cours</translation> ++<translation id="2336228925368920074">Ajouter tous les onglets aux favoris...</translation> ++<translation id="4985312428111449076">Onglets ou fenêtres</translation> ++<translation id="7481475534986701730">Sites récemment consultés</translation> ++<translation id="4260722247480053581">Ouvrir dans une fenêtre de navigation privée</translation> ++<translation id="8503758797520866434">Préférences de saisie automatique...</translation> ++<translation id="2757031529886297178">Compteur d'images par seconde</translation> ++<translation id="6657585470893396449">Mot de passe</translation> ++<translation id="7881483672146086348">Afficher le compte</translation> ++<translation id="1776883657531386793"><ph name="OID"/> : <ph name="INFO"/></translation> ++<translation id="1510030919967934016">Le suivi de votre position géographique a été bloqué pour cette page.</translation> ++<translation id="4640525840053037973">Connexion à l'aide de votre compte Google</translation> ++<translation id="5255315797444241226">Le mot de passe multiterme entré est incorrect.</translation> ++<translation id="6242054993434749861">télécopie : #<ph name="FAX"/></translation> ++<translation id="762917759028004464">Le navigateur par défaut est actuellement <ph name="BROWSER_NAME"/>.</translation> ++<translation id="9213479837033539041"><ph name="NUMBER_MANY"/> secondes restantes</translation> ++<translation id="300544934591011246">Mot de passe précédent</translation> ++<translation id="5078796286268621944">Code PIN incorrect</translation> ++<translation id="989988560359834682">Modifier l'adresse</translation> ++<translation id="8487678622945914333">Zoom avant</translation> ++<translation id="2972557485845626008">Micrologiciel</translation> ++<translation id="735327918767574393">Une erreur s'est produite lors de l'affichage de cette page Web. Pour continuer, actualisez cette page ou ouvrez-en une autre.</translation> ++<translation id="8028060951694135607">Récupération de clé Microsoft</translation> ++<translation id="9187657844611842955">recto verso</translation> ++<translation id="6391832066170725637">Fichier ou répertoire introuvable</translation> ++<translation id="4694445829210540512">Aucun forfait de données <ph name="NETWORK"/> actif</translation> ++<translation id="5494920125229734069">Tout sélectionner</translation> ++<translation id="2857834222104759979">Le fichier manifeste est incorrect.</translation> ++<translation id="7931071620596053769">Les pages suivantes ne répondent plus. Vous pouvez attendre qu'elles soient de nouveau accessibles ou les supprimer.</translation> ++<translation id="1209866192426315618"><ph name="NUMBER_DEFAULT"/> minutes restantes</translation> ++<translation id="7938958445268990899">Le certificat du serveur n'est pas encore valide.</translation> ++<translation id="4569998400745857585">Menu contenant des extensions masquées</translation> ++<translation id="4081383687659939437">Enregistrer les infos</translation> ++<translation id="5786805320574273267">Configuration de l'accès à distance à cet ordinateur.</translation> ++<translation id="1801827354178857021">Point</translation> ++<translation id="2179052183774520942">Ajouter un moteur de recherche</translation> ++<translation id="5498951625591520696">Impossible d'atteindre le serveur.</translation> ++<translation id="2956948609882871496">Importer mes favoris...</translation> ++<translation id="1621207256975573490">Enregistrer le &cadre sous...</translation> ++<translation id="4681260323810445443">Vous n'êtes pas autorisé à accéder à la page Web <ph name="URL"/>. Votre connexion peut être requise.</translation> ++<translation id="2176444992480806665">Envoyer la capture d'écran du dernier onglet actif</translation> ++<translation id="1165039591588034296">Erreur</translation> ++<translation id="2064942105849061141">Utiliser le thème GTK+</translation> ++<translation id="2278562042389100163">Ouvrir une fenêtre du navigateur</translation> ++<translation id="5246282308050205996"><ph name="APP_NAME"/> a planté. Cliquez sur cette info-bulle pour redémarrer l'application.</translation> ++<translation id="9218430445555521422">Définir comme navigateur par défaut</translation> ++<translation id="5027550639139316293">Certificat de courrier électronique</translation> ++<translation id="938582441709398163">Clavier en superposition</translation> ++<translation id="427208986916971462">La connexion est compressée avec <ph name="COMPRESSION"/>.</translation> ++<translation id="4589279373639964403">Exporter mes favoris...</translation> ++<translation id="8876215549894133151">Format :</translation> ++<translation id="5234764350956374838">Ignorer</translation> ++<translation id="40027638859996362">Déplacer un mot</translation> ++<translation id="5463275305984126951">Index de <ph name="LOCATION"/></translation> ++<translation id="5154917547274118687">Mémoire</translation> ++<translation id="1493492096534259649">Impossible d'utiliser cette langue pour corriger l'orthographe.</translation> ++<translation id="6628463337424475685">Recherche <ph name="ENGINE"/></translation> ++<translation id="2502105862509471425">Ajouter une autre carte de paiement...</translation> ++<translation id="4037618776454394829">Envoyer la dernière capture d'écran enregistrée</translation> ++<translation id="8987670145726065238">Ce fichier contient du code malveillant. Voulez-vous vraiment continuer ?</translation> ++<translation id="182729337634291014">Erreur de synchronisation...</translation> ++<translation id="4465830120256509958">Clavier brésilien</translation> ++<translation id="2459861677908225199">Utiliser TLS 1.0</translation> ++<translation id="4792711294155034829">&Signaler un problème...</translation> ++<translation id="5819484510464120153">Créer des raccourci&s vers des applications...</translation> ++<translation id="6845180713465955339">Le certificat "<ph name="CERTIFICATE_NAME"/>" a été émis par :</translation> ++<translation id="7531238562312180404"><ph name="PRODUCT_NAME"/> ne contrôlant pas la façon dont les extensions gèrent vos données personnelles, toutes les extensions sont désactivées dans les fenêtres de navigation privée. Vous pouvez les réactiver individuellement dans le <ph name="BEGIN_LINK"/>gestionnaire des extensions<ph name="END_LINK"/>.</translation> ++<translation id="5667293444945855280">Logiciels malveillants</translation> ++<translation id="3435845180011337502">Mise en page ou mise en forme de la page</translation> ++<translation id="3838186299160040975">Acheter davantage...</translation> ++<translation id="6831043979455480757">Traduire</translation> ++<translation id="3587482841069643663">Tout</translation> ++<translation id="6698381487523150993">Créé :</translation> ++<translation id="4684748086689879921">Annuler l'importation</translation> ++<translation id="9130015405878219958">Le mode indiqué est incorrect.</translation> ++<translation id="6615807189585243369"><ph name="BURNT_AMOUNT"/> copié(s) sur <ph name="TOTAL_SIZE"/></translation> ++<translation id="8518425453349204360">L'accès à distance à cet ordinateur est activé pour <ph name="USER_EMAIL_ADDRESS"/>.</translation> ++<translation id="4950138595962845479">Options...</translation> ++<translation id="4653235815000740718">Un problème est survenu lors de la création du support de récupération du système d'exploitation. Le périphérique de stockage utilisé est introuvable.</translation> ++<translation id="5516565854418269276">Toujours &afficher la barre de favoris</translation> ++<translation id="6426222199977479699">Erreur SSL</translation> ++<translation id="7104784605502674932">Confirmer les préférences de synchronisation</translation> ++<translation id="1788636309517085411">Utiliser les valeurs par défaut</translation> ++<translation id="1661867754829461514">Code secret manquant</translation> ++<translation id="7406714851119047430">L'accès à distance à cet ordinateur est désactivé.</translation> ++<translation id="8589311641140863898">API des extensions expérimentales</translation> ++<translation id="2804922931795102237">Inclure les informations système</translation> ++<translation id="869891660844655955">Date d'expiration</translation> ++<translation id="2178614541317717477">Autorité de certification compromise</translation> ++<translation id="4449935293120761385">À propos de la saisie automatique</translation> ++<translation id="4194570336751258953">Activer la fonction "Taper pour cliquer"</translation> ++<translation id="6066742401428748382">Accès à la page Web refusé</translation> ++<translation id="5111692334209731439">&Gestionnaire de favoris</translation> ++<translation id="8295070100601117548">Erreur serveur</translation> ++<translation id="5661272705528507004">Cette carte SIM est désactivée et ne peut être utilisée. Veuillez demander à votre fournisseur de services de la remplacer.</translation> ++<translation id="443008484043213881">Outils</translation> ++<translation id="2529657954821696995">Clavier néerlandais</translation> ++<translation id="1128128132059598906">EAP-TTLS</translation> ++<translation id="6585234750898046415">Choisissez une image à associer à votre compte. Celle-ci s'affichera sur l'écran de connexion.</translation> ++<translation id="7957054228628133943">Configurer le blocage des fenêtres pop-up...</translation> ++<translation id="179767530217573436">des 4 dernières semaines</translation> ++<translation id="2279770628980885996">Une situation inattendue s'est produite tandis que le serveur tentait de traiter la demande.</translation> ++<translation id="8079135502601738761">Impossible d'afficher certaines parties de ce document PDF. Souhaitez-vous l'ouvrir dans Adobe Reader ?</translation> ++<translation id="9123413579398459698">Proxy FTP</translation> ++<translation id="3887875461425980041">Si vous utilisez la version PPAPI de Flash, exécutez-la dans chaque processus de moteur du rendu plutôt que dans un processus de plug-in dédié.</translation> ++<translation id="8534801226027872331">Cela signifie que le certificat présenté à votre navigateur contient des erreurs et qu'il ne peut pas être compris. Il est possible que les informations sur l'identité du certificat ou que d'autres informations du certificat relatives à la sécurité de la connexion soient incompréhensibles. Ne poursuivez pas.</translation> ++<translation id="3608527593787258723">Activer l'onglet 1</translation> ++<translation id="4497369307931735818">Communication à distance</translation> ++<translation id="3855676282923585394">Importer les favoris et les paramètres...</translation> ++<translation id="1116694919640316211">À propos</translation> ++<translation id="4422347585044846479">Modifier le favori de cette page</translation> ++<translation id="1684638090259711957">Ajouter un format d'exception</translation> ++<translation id="4925481733100738363">Configurer l'accès à distance...</translation> ++<translation id="1880905663253319515">Supprimer le certificat "<ph name="CERTIFICATE_NAME"/>" ?</translation> ++<translation id="8546306075665861288">Cache des images</translation> ++<translation id="5904093760909470684">Configuration du proxy</translation> ++<translation id="2874027208508018603">En l'absence de connexion Wi-Fi, Google Chrome utilise les données 3G.</translation> ++<translation id="4558734465070698159">Appuyez sur <ph name="HOTKEY_NAME"/> pour sélectionner le mode de saisie précédent.</translation> ++<translation id="3348643303702027858">La création du support de récupération du système d'exploitation a été annulée.</translation> ++<translation id="3391060940042023865">Le plug-in suivant est bloqué : <ph name="PLUGIN_NAME"/></translation> ++<translation id="4237016987259239829">Erreur de connexion réseau</translation> ++<translation id="9050666287014529139">Mot de passe multiterme</translation> ++<translation id="5197255632782567636">Internet</translation> ++<translation id="4755860829306298968">Configurer les paramètres de blocage des plug-ins...</translation> ++<translation id="8879284080359814990">Afficher dan&s un onglet</translation> ++<translation id="2786847742169026523">Synchroniser vos mots de passe</translation> ++<translation id="41293960377217290">Le serveur proxy agit comme un intermédiaire entre votre ordinateur et les autres serveurs. Votre configuration système utilise actuellement un proxy, mais ++ <ph name="PRODUCT_NAME"/> ++ ne parvient pas à s'y connecter.</translation> ++<translation id="4520722934040288962">Sélectionner par type d'application</translation> ++<translation id="3873139305050062481">Procéder à l'i&nspection de l'élément</translation> ++<translation id="7445762425076701745">Impossible de valider entièrement l'identité du serveur auquel vous êtes connecté. Le nom utilisé pour cette connexion n'est valide que sur votre réseau et aucune autorité de certification externe ne peut en vérifier la propriété. Certaines autorités de certification délivrent tout de même des certificats pour ces types de nom, par conséquent nous ne sommes pas en mesure de vérifier que vous êtes connecté au site voulu et non à un site malveillant.</translation> ++<translation id="1556537182262721003">Impossible de déplacer le répertoire d'extensions dans le profil.</translation> ++<translation id="5866557323934807206">Supprimer ces paramètres pour les prochaines visites</translation> ++<translation id="6506104645588011859">L'accessibilité est activée.</translation> ++<translation id="5355351445385646029">Appuyer sur la touche Espace pour sélectionner la suggestion</translation> ++<translation id="6978622699095559061">Vos favoris</translation> ++<translation id="6370820475163108109"><ph name="ORGANIZATION_NAME"/> (<ph name="DOMAIN_NAME"/>)</translation> ++<translation id="5453029940327926427">Fermer les onglets</translation> ++<translation id="406070391919917862">Applications en arrière-plan</translation> ++<translation id="8820817407110198400">Favoris</translation> ++<translation id="3214837514330816581">Supprimer les données synchronisées de Google Dashboard</translation> ++<translation id="2580170710466019930">Veuillez patienter pendant que <ph name="PRODUCT_NAME"/> installe les dernières mises à jour système.</translation> ++<translation id="7428061718435085649">Utilisez les touches Maj gauche et droite pour sélectionner les 2e et 3e propositions</translation> ++<translation id="1070066693520972135">WEP</translation> ++<translation id="206683469794463668">Mode Zhuyin complet. La sélection automatique de la suggestion et les options associées sont désactivées ou ignorées.</translation> ++<translation id="5191625995327478163">&Paramètres linguistiques...</translation> ++<translation id="8833054222610756741">CRX-less Web Apps</translation> ++<translation id="4031729365043810780">Connexion au réseau</translation> ++<translation id="3332115613788466465">Reliure bord long</translation> ++<translation id="1985136186573666099"><ph name="PRODUCT_NAME"/> utilise les paramètres proxy du système pour se connecter au réseau.</translation> ++<translation id="6508261954199872201">Application : <ph name="APP_NAME"/></translation> ++<translation id="5585645215698205895">&Descendre</translation> ++<translation id="8366757838691703947">? Toutes les données présentes sur le périphérique seront supprimées.</translation> ++<translation id="6596816719288285829">Adresse IP</translation> ++<translation id="7747704580171477003">Active le nouveau design de la page "Nouvel onglet" (en cours de développement).</translation> ++<translation id="4508265954913339219">Échec de l'activation</translation> ++<translation id="8656768832129462377">Ne pas vérifier</translation> ++<translation id="715487527529576698">Le chinois simplifié est le mode de saisie initial</translation> ++<translation id="1674989413181946727">Paramètres SSL sur tout l'ordinateur :</translation> ++<translation id="8703575177326907206">Votre connexion à <ph name="DOMAIN"/> n'est pas chiffrée.</translation> ++<translation id="8472623782143987204">matériel requis</translation> ++<translation id="4865571580044923428">Gérer les exceptions...</translation> ++<translation id="2526619973349913024">Rechercher des mises à jour</translation> ++<translation id="3874070094967379652">Utiliser un mot de passe multiterme pour chiffrer mes données de synchronisation</translation> ++<translation id="4864369630010738180">Connexion en cours...</translation> ++<translation id="6500116422101723010">Le serveur ne parvient pas à traiter la demande pour le moment. Ce code indique une situation temporaire. Le serveur sera de nouveau opérationnel ultérieurement.</translation> ++<translation id="1644574205037202324">Historique</translation> ++<translation id="1297175357211070620">Destination</translation> ++<translation id="6219983382864672018">Web audio</translation> ++<translation id="479280082949089240">Cookies placés par cette page</translation> ++<translation id="4198861010405014042">Accès partagé</translation> ++<translation id="6204930791202015665">Afficher...</translation> ++<translation id="5941343993301164315">Veuillez vous connecter à <ph name="TOKEN_NAME"/>.</translation> ++<translation id="4417229845571722044">Ajouter un nouvel e-mail</translation> ++<translation id="8049151370369915255">Personnaliser les polices...</translation> ++<translation id="2886862922374605295">Matériel :</translation> ++<translation id="4497097279402334319">Erreur de connexion au réseau.</translation> ++<translation id="5303618139271450299">Cette page Web est introuvable.</translation> ++<translation id="4256316378292851214">En&registrer la vidéo sous...</translation> ++<translation id="3528171143076753409">Le certificat du serveur n'est pas approuvé.</translation> ++<translation id="6518014396551869914">Cop&ier l'image</translation> ++<translation id="3236997602556743698">Sebeol-sik 390</translation> ++<translation id="542155483965056918"><ph name="NUMBER_ZERO"/> mins ago</translation> ++<translation id="289426338439836048">Autre réseau mobile...</translation> ++<translation id="3986287159189541211">Erreur HTTP <ph name="ERROR_NUMBER"/> (<ph name="ERROR_NAME"/>) : <ph name="ERROR_TEXT"/></translation> ++<translation id="3225319735946384299">Signature du code</translation> ++<translation id="3118319026408854581">Aide <ph name="PRODUCT_NAME"/></translation> ++<translation id="2422426094670600218"><sans nom></translation> ++<translation id="2012766523151663935">Version du micrologiciel :</translation> ++<translation id="4120898696391891645">La page ne se charge pas</translation> ++<translation id="6060685159320643512">Attention, ces fonctionnalités expérimentales peuvent mordre.</translation> ++<translation id="5829990587040054282">Verrouiller l'écran ou éteindre</translation> ++<translation id="7800304661137206267">La connexion est chiffrée au moyen de <ph name="CIPHER"/>, avec <ph name="MAC"/> pour l'authentification des messages et <ph name="KX"/> pour la méthode d'échange de clés.</translation> ++<translation id="7706319470528945664">Clavier portugais</translation> ++<translation id="5584537427775243893">Importation</translation> ++<translation id="9128870381267983090">Connexion au réseau</translation> ++<translation id="4181841719683918333">Langues</translation> ++<translation id="6535131196824081346">Cette erreur peut se produire lors de la connexion à un serveur sécurisé (HTTPS). ++ Elle indique que le serveur tente d'établir une connexion sécurisée, mais ++ que celle-ci ne sera pas du tout sécurisée en raison d'une grave erreur de configuration. ++ <ph name="LINE_BREAK"/> Dans ce cas, une intervention ++ est requise sur le serveur. ++ <ph name="PRODUCT_NAME"/> ++ n'utilise pas de connexion non sécurisée pour protéger la confidentialité ++ de vos données.</translation> ++<translation id="5235889404533735074">La synchronisation de <ph name="PRODUCT_NAME"/> vous permet de partager vos données (favoris, préférences) sur vos ordinateurs en toute simplicité. Pour ce faire, <ph name="PRODUCT_NAME"/> enregistre vos données en ligne via Google lorsque vous vous connectez à votre compte.</translation> ++<translation id="6533668113756472185">Format ou mise en forme de la page</translation> ++<translation id="5640179856859982418">Clavier suisse</translation> ++<translation id="5910363049092958439">En&registrer l'image sous...</translation> ++<translation id="1363055550067308502">Basculer en mode pleine chasse ou demi-chasse</translation> ++<translation id="3108967419958202225">Sélectionner...</translation> ++<translation id="6451650035642342749">Effacer les paramètres d'ouverture automatique</translation> ++<translation id="5948544841277865110">Ajouter un réseau privé</translation> ++<translation id="7121570032414343252"><ph name="NUMBER_TWO"/> secondes</translation> ++<translation id="1378451347523657898">Ne pas envoyer de capture d'écran</translation> ++<translation id="5098629044894065541">Hébreu</translation> ++<translation id="7751559664766943798">Toujours afficher la barre de favoris</translation> ++<translation id="5098647635849512368">Impossible de trouver le chemin d'accès absolu du répertoire à empaqueter.</translation> ++<translation id="780617032715125782">Créer un profil</translation> ++<translation id="933712198907837967">Diners Club</translation> ++<translation id="6380224340023442078">Paramètres de contenu...</translation> ++<translation id="950108145290971791">Activer la recherche instantanée pour accélérer la recherche et la navigation ?</translation> ++<translation id="144136026008224475">Plus d'extensions >></translation> ++<translation id="5486326529110362464">La valeur d'entrée de la clé privée est obligatoire.</translation> ++<translation id="9039663905644212491">PEAP</translation> ++<translation id="62780591024586043">Fonctionnalités de localisation expérimentales</translation> ++<translation id="8584280235376696778">Ou&vrir la vidéo dans un nouvel onglet</translation> ++<translation id="2845382757467349449">Toujours afficher la barre de favoris</translation> ++<translation id="2516384155283419848">Reliure</translation> ++<translation id="3053013834507634016">Utilisation de la clé du certificat</translation> ++<translation id="4487088045714738411">Clavier belge</translation> ++<translation id="7511635910912978956"><ph name="NUMBER_FEW"/> heures restantes</translation> ++<translation id="2152580633399033274">Afficher toutes les images (recommandé)</translation> ++<translation id="7894567402659809897">Cliquez sur ++ <ph name="BEGIN_BOLD"/>Démarrer<ph name="END_BOLD"/>, ++ puis sur ++ <ph name="BEGIN_BOLD"/>Exécuter<ph name="END_BOLD"/>. ++ Saisissez ++ et cliquez sur ++ <ph name="BEGIN_BOLD"/>OK<ph name="END_BOLD"/>.</translation> ++<translation id="2934952234745269935">Nom de volume</translation> ++<translation id="7960533875494434480">Reliure bord court</translation> ++<translation id="6431347207794742960"><ph name="PRODUCT_NAME"/> va configurer les mises à jour automatiques pour tous les utilisateurs de cet ordinateur.</translation> ++<translation id="4973698491777102067">Effacer les éléments datant :</translation> ++<translation id="6074963268421707432">Interdire à tous les sites d'afficher des notifications sur le Bureau</translation> ++<translation id="8508050303181238566">Appuyez sur <ph name="HOTKEY_NAME"/> pour passer d'un mode de saisie à l'autre.</translation> ++<translation id="6273404661268779365">Ajouter un nouveau fax</translation> ++<translation id="1995173078718234136">Recherche de contenu en cours...</translation> ++<translation id="4735819417216076266">Style d'entrée avec Espace</translation> ++<translation id="2977095037388048586">Vous avez tenté d'accéder à <ph name="DOMAIN"/>, mais, au lieu de cela, vous communiquez actuellement avec un serveur identifié comme <ph name="DOMAIN2"/>. Cela est peut-être dû à un défaut de configuration du serveur ou à quelque chose de plus grave. Un pirate informatique sur votre réseau cherche peut-être à vous faire visiter une version falsifiée de <ph name="DOMAIN3"/>, donc potentiellement préjudiciable. Nous vous déconseillons vivement de continuer.</translation> ++<translation id="220138918934036434">Masquer le bouton</translation> ++<translation id="5374359983950678924">Modifier l'image</translation> ++<translation id="5158548125608505876">Ne pas synchroniser mes mots de passe</translation> ++<translation id="2167276631610992935">JavaScript</translation> ++<translation id="6974306300279582256">Activer les notifications de <ph name="SITE"/></translation> ++<translation id="492914099844938733">Afficher les incompatibilités</translation> ++<translation id="5233638681132016545">Nouvel onglet</translation> ++<translation id="6567688344210276845">Impossible de charger l'icône "<ph name="ICON"/>" d'action de page.</translation> ++<translation id="5210365745912300556">Fermer l'onglet</translation> ++<translation id="8628085465172583869">Nom d'hôte du serveur :</translation> ++<translation id="498765271601821113">Ajouter une carte de paiement</translation> ++<translation id="7694379099184430148"><ph name="FILENAME"/> : type de fichier inconnu</translation> ++<translation id="1992397118740194946">Non défini</translation> ++<translation id="7966826846893205925">Gérer les paramètres de saisie automatique...</translation> ++<translation id="8556732995053816225">Respecter la &casse</translation> ++<translation id="3314070176311241517">Autoriser tous les sites à exécuter JavaScript (recommandé)</translation> ++<translation id="2406911946387278693">Gérer vos périphériques depuis le cloud</translation> ++<translation id="7419631653042041064">Clavier catalan</translation> ++<translation id="5710740561465385694">Me demander lorsqu'un site essaie de stocker des données</translation> ++<translation id="3897092660631435901">Menu</translation> ++<translation id="7024867552176634416">Sélectionnez le périphérique de stockage amovible à utiliser.</translation> ++<translation id="8553075262323480129">La traduction a échoué, car nous n'avons pas pu déterminer la langue de la page.</translation> ++<translation id="5910680277043747137">Vous pouvez créer des profils supplémentaires pour autoriser plusieurs personnes à utiliser et personnaliser Google Chrome.</translation> ++<translation id="4381849418013903196">Deux-points</translation> ++<translation id="1103523840287552314">Toujours traduire en <ph name="LANGUAGE"/></translation> ++<translation id="2263497240924215535">(désactivée)</translation> ++<translation id="2159087636560291862">Cela signifie que le certificat n'a pas été vérifié par un tiers reconnu par votre ordinateur. N'importe qui peut émettre un certificat en se faisant passer pour un autre site Web. Ce certificat doit donc être vérifié par un tiers approuvé. Sans cette vérification, les informations sur l'identité du certificat sont sans intérêt. Par conséquent, il nous est impossible de vérifier que vous communiquez bien avec <ph name="DOMAIN"/> et non avec un pirate informatique ayant émis son propre certificat en prétendant être <ph name="DOMAIN2"/>. Nous vous déconseillons vivement de continuer.</translation> ++<translation id="58625595078799656"><ph name="PRODUCT_NAME"/> requiert que vous cryptiez vos données à l'aide de votre mot de passe Google ou de votre propre mot de passe multiterme.</translation> ++<translation id="8017335670460187064"><ph name="LABEL"/></translation> ++<translation id="6840184929775541289">N'est pas une autorité de certification</translation> ++<translation id="6099520380851856040">Date et heure : <ph name="CRASH_TIME"/></translation> ++<translation id="144518587530125858">Impossible de charger "<ph name="IMAGE_PATH"/>" pour le thème.</translation> ++<translation id="5355097969896547230">Rechercher à nouveau</translation> ++<translation id="7925285046818567682">En attente de <ph name="HOST_NAME"/>...</translation> ++<translation id="2553440850688409052">Masquer ce plug-in</translation> ++<translation id="3280237271814976245">Enregistrer &sous...</translation> ++<translation id="8301162128839682420">Ajouter une langue :</translation> ++<translation id="7658239707568436148">Annuler</translation> ++<translation id="8695825812785969222">Ouvrir une &adresse...</translation> ++<translation id="4538417792467843292">Supprimer le mot</translation> ++<translation id="8412392972487953978">Vous devez saisir deux fois le même mot de passe multiterme.</translation> ++<translation id="9121814364785106365">Ouvrir dans un onglet épinglé</translation> ++<translation id="6996264303975215450">Page Web, tout type de contenu</translation> ++<translation id="3435896845095436175">Activer</translation> ++<translation id="1891668193654680795">Considérer ce certificat comme fiable pour identifier les développeurs de logiciels.</translation> ++<translation id="5078638979202084724">Ajouter tous les onglets aux favoris</translation> ++<translation id="5585118885427931890">Impossible de créer le dossier de favoris.</translation> ++<translation id="2154710561487035718">Copier l'URL</translation> ++<translation id="8163672774605900272">Si vous pensez ne pas avoir à utiliser de serveur proxy, procédez comme suit : ++ <ph name="PLATFORM_TEXT"/></translation> ++<translation id="5510687173983454382">Définir les utilisateurs autorisés à se connecter à un périphérique et autoriser les sessions de navigation en tant qu'invité</translation> ++<translation id="3241680850019875542">Sélectionnez le répertoire racine de l'extension à empaqueter. Pour mettre à jour une extension, sélectionnez également le fichier de clé privée à réutiliser.</translation> ++<translation id="7500424997253660722">Pool restreint :</translation> ++<translation id="657402800789773160">&Rafraîchir cette page</translation> ++<translation id="6163363155248589649">&Normal</translation> ++<translation id="7972714317346275248">PKCS #1 SHA-384 avec chiffrement RSA</translation> ++<translation id="3020990233660977256">Numéro de série : <ph name="SERIAL_NUMBER"/></translation> ++<translation id="8426519927982004547">HTTPS/SSL</translation> ++<translation id="8216781342946147825">Toutes les données de votre ordinateur et des sites Web que vous visitez</translation> ++<translation id="5548207786079516019">Ceci est une installation secondaire de <ph name="PRODUCT_NAME"/> et ce dernier ne peut pas être défini comme navigateur par défaut.</translation> ++<translation id="3984413272403535372">Erreur lors de la signature de l'extension</translation> ++<translation id="8807083958935897582"><ph name="PRODUCT_NAME"/> permet d'effectuer des recherches sur Internet à l'aide du champ polyvalent. Sélectionnez le moteur de recherche à utiliser :</translation> ++<translation id="6629104427484407292">Sécurité : <ph name="SECURITY"/></translation> ++<translation id="9208886416788010685">Adobe Reader n'est pas à jour</translation> ++<translation id="3373604799988099680">Extensions ou applications</translation> ++<translation id="318408932946428277">Effacer les cookies et autres données de site et de plug-in lorsque je ferme le navigateur</translation> ++<translation id="314141447227043789">Téléchargement de l'image terminé.</translation> ++<translation id="8725178340343806893">Favoris</translation> ++<translation id="5177526793333269655">Afficher les vignettes</translation> ++<translation id="8926389886865778422">Ne plus afficher ce message</translation> ++<translation id="6985235333261347343">Agent de récupération de clé Microsoft</translation> ++<translation id="3605499851022050619">Page de diagnostic de navigation sécurisée</translation> ++<translation id="4417271111203525803">Adresse ligne 2</translation> ++<translation id="7617095560120859490">Décrivez-nous le problème recontré. (Champ obligatoire)</translation> ++<translation id="5618333180342767515">Cela peut prendre quelques minutes.</translation> ++<translation id="4307992518367153382">Options de base</translation> ++<translation id="8480417584335382321">Niveau de zoom par défaut :</translation> ++<translation id="3872166400289564527">Stockage externe</translation> ++<translation id="5912378097832178659">Modifi&er les moteurs de recherche...</translation> ++<translation id="8272426682713568063">Cartes de paiement</translation> ++<translation id="3749289110408117711">Nom du fichier</translation> ++<translation id="3173397526570909331">Arrêter la synchronisation</translation> ++<translation id="5538092967727216836">Actualiser le cadre</translation> ++<translation id="4813345808229079766">Connexion</translation> ++<translation id="411666854932687641">Mémoire privée</translation> ++<translation id="119944043368869598">Tout effacer</translation> ++<translation id="3467848195100883852">Activer la correction orthographique automatique</translation> ++<translation id="1336254985736398701">Afficher les &infos sur la page</translation> ++<translation id="7550830279652415241">favoris_<ph name="DATESTAMP"/>.html</translation> ++<translation id="6828153365543658583">Autoriser uniquement les utilisateurs suivants à se connecter :</translation> ++<translation id="1652965563555864525">&Muet</translation> ++<translation id="4200983522494130825">Nouvel ongle&t</translation> ++<translation id="7979036127916589816">Erreur de synchronisation</translation> ++<translation id="1029317248976101138">Zoom</translation> ++<translation id="5455790498993699893"><ph name="ACTIVE_MATCH"/> sur <ph name="TOTAL_MATCHCOUNT"/></translation> ++<translation id="8890069497175260255">Type de clavier</translation> ++<translation id="1202290638211552064">Délai d'expiration atteint au niveau de la passerelle ou du serveur proxy en attente d'une réponse d'un serveur en amont.</translation> ++<translation id="7765158879357617694">Déplacer</translation> ++<translation id="5731751937436428514">Mode de saisie du vietnamien (VIQR)</translation> ++<translation id="8412144371993786373">Ajouter la page actuelle aux favoris</translation> ++<translation id="7615851733760445951"><aucun cookie sélectionné></translation> ++<translation id="469553822757430352">Le mot de passe de l'application est incorrect.</translation> ++<translation id="2493021387995458222">Sélectionner "un mot à la fois"</translation> ++<translation id="5279600392753459966">Tout bloquer</translation> ++<translation id="6846298663435243399">Chargement en cours…</translation> ++<translation id="7392915005464253525">&Rouvrir la fenêtre fermée</translation> ++<translation id="1144684570366564048">Gérer les exceptions...</translation> ++<translation id="7400418766976504921">URL</translation> ++<translation id="1541725072327856736">Katakana demi-chasse</translation> ++<translation id="7456847797759667638">Ouvrir une adresse</translation> ++<translation id="1388866984373351434">Données de navigation</translation> ++<translation id="3754634516926225076">Code PIN incorrect. Veuillez réessayer.</translation> ++<translation id="7378627244592794276">Non</translation> ++<translation id="2800537048826676660">Utiliser cette langue pour corriger l'orthographe</translation> ++<translation id="68541483639528434">Fermer les autres onglets</translation> ++<translation id="941543339607623937">Clé privée non valide.</translation> ++<translation id="6499058468232888609">Une erreur réseau s'est produite pendant la communication avec le service de gestion des périphériques.</translation> ++<translation id="4433862206975946675">Importer les données d'un autre navigateur...</translation> ++<translation id="4022426551683927403">&Ajouter au dictionnaire</translation> ++<translation id="2897878306272793870">Voulez-vous vraiment ouvrir <ph name="TAB_COUNT"/> onglets ?</translation> ++<translation id="312759608736432009">Fabricant du périphérique :</translation> ++<translation id="362276910939193118">Afficher l'historique complet</translation> ++<translation id="6079696972035130497">Illimité</translation> ++<translation id="4365411729367255048">Clavier Neo2 allemand</translation> ++<translation id="6348657800373377022">Liste déroulante</translation> ++<translation id="8064671687106936412">Clé :</translation> ++<translation id="2218515861914035131">Coller en texte brut</translation> ++<translation id="1725149567830788547">Afficher les &commandes</translation> ++<translation id="3528033729920178817">Cette page suit votre position géographique.</translation> ++<translation id="5518584115117143805">Certificat de chiffrement de courrier électronique</translation> ++<translation id="9203398526606335860">&Profilage activé</translation> ++<translation id="4307281933914537745">En savoir plus sur la récupération du système</translation> ++<translation id="2849936225196189499">Essentielle</translation> ++<translation id="9001035236599590379">Type MIME</translation> ++<translation id="5612754943696799373">Autoriser le téléchargement ?</translation> ++<translation id="6353618411602605519">Clavier croate</translation> ++<translation id="5515810278159179124">Interdire à tous les sites de suivre ma position géographique</translation> ++<translation id="5999606216064768721">Utiliser la barre de titre du système et les bordures de la fenêtre</translation> ++<translation id="904752364881701675">En bas à gauche</translation> ++<translation id="3398951731874728419">Informations sur l'erreur :</translation> ++<translation id="1464570622807304272">Essayez : saisissez "orchidées", puis appuyez sur Entrée.</translation> ++<translation id="8026684114486203427">Pour utiliser Chrome Web Store, vous devez être connecté à un compte Google.</translation> ++<translation id="8417276187983054885">Configurer <ph name="CLOUD_PRINT_NAME"/></translation> ++<translation id="3056462238804545033">Petit problème... Nous n'avons pas réussi à vous authentifier. Veuillez vérifier vos identifiants de connexion puis réessayer.</translation> ++<translation id="5298420986276701358">Pour gérer à distance la configuration de ce périphérique <ph name="PRODUCT_NAME"/> depuis le cloud, connectez-vous avec votre compte Google Apps.</translation> ++<translation id="2678063897982469759">Réactiver</translation> ++<translation id="1779766957982586368">Fermer la fenêtre</translation> ++<translation id="4850886885716139402">Présentation</translation> ++<translation id="89217462949994770">Vous avez saisi un trop grand nombre de codes PIN incorrects. Veuillez contacter <ph name="CARRIER_ID"/> pour obtenir une nouvelle clé de déverrouillage du code PIN à 8 chiffres.</translation> ++<translation id="5920618722884262402">Bloquer le contenu inapproprié</translation> ++<translation id="5120247199412907247">Configuration avancée</translation> ++<translation id="5922220455727404691">Utiliser SSL 3.0</translation> ++<translation id="1368352873613152012">Règles de confidentialité liées à la navigation sécurisée</translation> ++<translation id="5105859138906591953">Vous devez être connecté à votre compte Google pour importer les favoris de la barre d'outils Google dans Google Chrome. Connectez-vous et relancez l'importation.</translation> ++<translation id="8899851313684471736">Ouvrir le lien dans une nouvelle &fenêtre</translation> ++<translation id="4110342520124362335">Les cookies de <ph name="DOMAIN"/> ont été bloqués.</translation> ++<translation id="3303818374450886607">Copies</translation> ++<translation id="2019718679933488176">&Ouvrir le fichier audio dans un nouvel onglet</translation> ++<translation id="4138267921960073861">Afficher les noms d'utilisateurs et leur photo sur la page de connexion</translation> ++<translation id="7465778193084373987">URL de révocation de certificat Netscape</translation> ++<translation id="5976690834266782200">Ajoute des options de regroupement des onglets dans le menu contextuel des onglets.</translation> ++<translation id="4755240240651974342">Clavier finnois</translation> ++<translation id="7049893973755373474">Vérifiez votre connexion Internet. Redémarrez votre routeur, votre modem ++ ou tout autre périphérique réseau que vous utilisez.</translation> ++<translation id="7421925624202799674">&Afficher le code source de la page</translation> ++<translation id="3940082421246752453">Le serveur ne prend pas en charge la version HTTP utilisée dans la demande.</translation> ++<translation id="661719348160586794">Vos mots de passe enregistrés s'afficheront ici.</translation> ++<translation id="6686490380836145850">Fermer les onglets sur la droite</translation> ++<translation id="5608669887400696928"><ph name="NUMBER_DEFAULT"/> heures</translation> ++<translation id="8844709414456935411"><ph name="PRODUCT_NAME"/> ++ indique qu'un produit ESET intercepte les connexions sécurisées. ++ En général, cela ne constitue pas un problème de sécurité car le ++ logiciel ESET s'exécute souvent sur le même ordinateur. Toutefois, en raison ++ de certaines incompatibilités avec les connexions sécurisées ++ <ph name="PRODUCT_NAME"/>, ++ vous devez configurer les produits ESET de manière à éviter ces ++ interceptions. Cliquez sur le lien En savoir plus pour obtenir des instructions.</translation> ++<translation id="3936877246852975078">Les requêtes adressées au serveur ont été temporairement limitées.</translation> ++<translation id="2600306978737826651">Impossible de télécharger l'image. Gravure annulée.</translation> ++<translation id="609978099044725181">Activer/désactiver le mode Hanja</translation> ++<translation id="1829483195200467833">Effacer les paramètres d'ouverture automatique</translation> ++<translation id="2738771556149464852">Pas après le</translation> ++<translation id="5774515636230743468">Manifeste :</translation> ++<translation id="719464814642662924">Visa</translation> ++<translation id="7474889694310679759">Clavier anglais canadien</translation> ++<translation id="1817871734039893258">Récupération de fichier Microsoft</translation> ++<translation id="2423578206845792524">En&registrer l'image sous...</translation> ++<translation id="6839929833149231406">Zone</translation> ++<translation id="9068931793451030927">Chemin :</translation> ++<translation id="283278805979278081">Prendre la photo</translation> ++<translation id="7320906967354320621">Inactif</translation> ++<translation id="1407050882688520094">Certains de vos certificats enregistrés identifient ces autorités de certification :</translation> ++<translation id="4287689875748136217">Impossible d'afficher la page Web, car le serveur n'a envoyé aucune donnée.</translation> ++<translation id="1634788685286903402">Considérer ce certificat comme fiable pour identifier les utilisateurs de messageries.</translation> ++<translation id="7052402604161570346">Ce type de fichier peut endommager votre ordinateur. Voulez-vous vraiment télécharger <ph name="FILE_NAME"/> ?</translation> ++<translation id="8642489171979176277">Importés depuis la barre d'outils Google</translation> ++<translation id="4142744419835627535">Recherche instantanée et saisie semi-automatique</translation> ++<translation id="4684427112815847243">Tout synchroniser</translation> ++<translation id="1125520545229165057">Dvorak (Hsu)</translation> ++<translation id="8940229512486821554">Exécuter la commande <ph name="EXTENSION_NAME"/> : <ph name="SEARCH_TERMS"/></translation> ++<translation id="2232876851878324699">Le fichier contenait un certificat, qui n'a pas été importé :</translation> ++<translation id="7787129790495067395">Vous utilisez actuellement un mot de passe multiterme. Si vous l'oubliez, vous pouvez réinitialiser la synchronisation afin de supprimer vos données des serveurs Google à l'aide de Google Dashboard.</translation> ++<translation id="2686759344028411998">Impossible de détecter les modules chargés.</translation> ++<translation id="572525680133754531">Cette fonctionnalité affiche une bordure autour des couches de rendu afin de déboguer et d'étudier leur composition.</translation> ++<translation id="2011110593081822050">Processus de traitement Web : <ph name="WORKER_NAME"/></translation> ++<translation id="3294437725009624529">Invité</translation> ++<translation id="350069200438440499">Nom du fichier :</translation> ++<translation id="9058204152876341570">Un élément est manquant.</translation> ++<translation id="8494979374722910010">Échec de la tentative de connexion au serveur.</translation> ++<translation id="7810202088502699111">Des fenêtres pop-up ont été bloquées sur cette page.</translation> ++<translation id="8190698733819146287">Personnaliser les langues et la saisie...</translation> ++<translation id="646727171725540434">Proxy HTTP</translation> ++<translation id="1006316751839332762">Mot de passe multiterme de chiffrement</translation> ++<translation id="8795916974678578410">Nouvelle fenêtre</translation> ++<translation id="2733275712367076659">Certains certificats provenant de ces organisations vous identifient :</translation> ++<translation id="4801512016965057443">Autoriser l'itinérance des données mobiles</translation> ++<translation id="2515586267016047495">Alt</translation> ++<translation id="2046040965693081040">Utiliser les pages actuelles</translation> ++<translation id="3798449238516105146">Version</translation> ++<translation id="5764483294734785780">En&registrer le fichier audio sous...</translation> ++<translation id="5252456968953390977">Itinérance</translation> ++<translation id="8744641000906923997">Romaji</translation> ++<translation id="8507996248087185956"><ph name="NUMBER_DEFAULT"/> minutes</translation> ++<translation id="4845656988780854088">Synchroniser uniquement les paramètres et\ndonnées qui ont changé depuis la dernière connexion\n(requiert votre mot de passe précédent)</translation> ++<translation id="348620396154188443">Autoriser tous les sites à afficher des notifications sur le Bureau</translation> ++<translation id="8214489666383623925">Ouvrir le fichier...</translation> ++<translation id="5376120287135475614">Changer de fenêtre</translation> ++<translation id="5230160809118287008">Chèvres téléportées</translation> ++<translation id="1701567960725324452">Si vous arrêtez la synchronisation, les données stockées sur cet ordinateur et dans votre compte Google demeureront à ces deux emplacements. Toutefois, les nouvelles données ou les modifications apportées au contenu existant ne seront pas synchronisées.</translation> ++<translation id="7761701407923456692">Le certificat du serveur ne correspond pas à l'URL.</translation> ++<translation id="3885155851504623709">Commune</translation> ++<translation id="4910171858422458941">Impossible d'activer les plug-ins désactivés par une stratégie d'entreprise.</translation> ++<translation id="4495419450179050807">Ne pas afficher sur cette page</translation> ++<translation id="4745800796303246012">Méthodes EAP en Wi-Fi expérimentales</translation> ++<translation id="1225544122210684390">Disque dur</translation> ++<translation id="939736085109172342">Nouveau dossier</translation> ++<translation id="4933484234309072027">intégration sur <ph name="URL"/></translation> ++<translation id="5554720593229208774">Autorité de certification de messagerie</translation> ++<translation id="862750493060684461">Cache CSS</translation> ++<translation id="2832519330402637498">En haut à gauche</translation> ++<translation id="6749695674681934117">Saisissez le nom du nouveau dossier.</translation> ++<translation id="6204994989617056362">L'extension de renégociation SSL était introuvable lors de la négociation sécurisée. Avec certains sites, connus pour leur prise en charge de l'extension de renégociation, Google Chrome exige une négociation mieux sécurisée afin de prévenir certaines attaques. L'absence de cette extension suggère que votre connexion a été interceptée et manipulée au cours du transfert.</translation> ++<translation id="6679492495854441399">Petit problème... Une erreur de communication avec le réseau est survenue lors de la tentative d'inscription de ce périphérique. Veuillez vérifier votre connexion réseau et réessayer.</translation> ++<translation id="7789962463072032349">pause</translation> ++<translation id="121827551500866099">Afficher tous les téléchargements...</translation> ++<translation id="1562633988311880769">Connexion à <ph name="CLOUD_PRINT_NAME"/></translation> ++<translation id="5949910269212525572">Impossible de résoudre l'adresse DNS du serveur.</translation> ++<translation id="3115147772012638511">En attente de l'affichage du cache</translation> ++<translation id="257088987046510401">Thèmes</translation> ++<translation id="6771079623344431310">Impossible de se connecter au serveur proxy.</translation> ++<translation id="2200129049109201305">Ignorer la synchronisation des données chiffrées ?</translation> ++<translation id="1426410128494586442">Oui</translation> ++<translation id="6725970970008349185">Nombre de suggestions par page</translation> ++<translation id="6198252989419008588">Modifier le code PIN</translation> ++<translation id="5749483996735055937">Un problème est survenu lors de la copie de l'image de récupération sur le périphérique.</translation> ++<translation id="3520476450377425184"><ph name="NUMBER_MANY"/> jours restants</translation> ++<translation id="7643817847124207232">La connexion Internet a été interrompue.</translation> ++<translation id="932327136139879170">Début</translation> ++<translation id="4764675709794295630">« Précédent</translation> ++<translation id="2560794850818211873">C&opier l'URL de la vidéo</translation> ++<translation id="6042708169578999844">Vos données sur <ph name="WEBSITE_1"/> et <ph name="WEBSITE_2"/></translation> ++<translation id="5302048478445481009">Langue</translation> ++<translation id="5553089923092577885">Mappages des stratégies de certificat</translation> ++<translation id="5600907569873192868"><ph name="NUMBER_MANY"/> minutes restantes</translation> ++<translation id="1519704592140256923">Sélectionner la position</translation> ++<translation id="1275018677838892971">Le site Web à l'adresse <ph name="HOST_NAME"/> contient des éléments provenant de sites signalés comme étant des sites de phishing. Ces derniers incitent les internautes à divulguer leurs informations personnelles en se faisant passer pour des institutions de confiance, telles que des banques.</translation> ++<translation id="702455272205692181"><ph name="EXTENSION_NAME"/></translation> ++<translation id="7170041865419449892">Hors de portée</translation> ++<translation id="908263542783690259">Effacer l'historique de navigation</translation> ++<translation id="7518003948725431193">Aucune page Web trouvée à l'adresse :<ph name="URL"/></translation> ++<translation id="745602119385594863">Nouveau moteur de recherche :</translation> ++<translation id="7484645889979462775">Jamais pour ce site</translation> ++<translation id="8666066831007952346"><ph name="NUMBER_TWO"/> jours restants</translation> ++<translation id="9086455579313502267">Impossible d'accéder au réseau.</translation> ++<translation id="5595485650161345191">Modifier l'adresse</translation> ++<translation id="2374144379568843525">&Masquer le panneau de la vérification orthographique</translation> ++<translation id="2694026874607847549">1 cookie</translation> ++<translation id="4393664266930911253">Activer ces fonctionnalités...</translation> ++<translation id="6390842777729054533"><ph name="NUMBER_ZERO"/> secondes restantes</translation> ++<translation id="3909791450649380159">Cou&per</translation> ++<translation id="2955913368246107853">Fermer la barre de recherche</translation> ++<translation id="5642508497713047">Signataire de la liste de révocation de certificats</translation> ++<translation id="813082847718468539">Afficher des informations à propos du site</translation> ++<translation id="3122464029669770682">UC</translation> ++<translation id="1684861821302948641">Fermer les pages</translation> ++<translation id="6092270396854197260">MSPY</translation> ++<translation id="6802031077390104172"><ph name="USAGE"/> (<ph name="OID"/>)</translation> ++<translation id="4052120076834320548">Très petite</translation> ++<translation id="6623138136890659562">Afficher les réseaux privés dans le menu Réseau pour activer la connexion à un VPN</translation> ++<translation id="8969837897925075737">Vérification de la mise à jour du système...</translation> ++<translation id="3393716657345709557">L'entrée demandée est introuvable dans le cache.</translation> ++<translation id="7241389281993241388">Connectez-vous à <ph name="TOKEN_NAME"/> pour importer le certificat client.</translation> ++<translation id="40334469106837974">Modifier la mise en page</translation> ++<translation id="4804818685124855865">Se déconnecter</translation> ++<translation id="2617919205928008385">Espace insuffisant.</translation> ++<translation id="210445503571712769">Préférences synchronisées</translation> ++<translation id="1608306110678187802">Imp&rimer le cadre...</translation> ++<translation id="7427315641433634153">MSCHAP</translation> ++<translation id="6622980291894852883">Continuer à bloquer les images</translation> ++<translation id="5937837224523037661">Lorsqu'un site utilise des plug-ins :</translation> ++<translation id="4988792151665380515">Échec d'exportation de la clé publique</translation> ++<translation id="6333049849394141510">Choisir les éléments à synchroniser</translation> ++<translation id="446322110108864323">Paramètres de saisie du Pinyin</translation> ++<translation id="4948468046837535074">Ouvrir les pages suivantes :</translation> ++<translation id="5222676887888702881">Déconnexion</translation> ++<translation id="6978121630131642226">Moteurs de recherche</translation> ++<translation id="6839225236531462745">Erreur de suppression de certificat</translation> ++<translation id="6745994589677103306">Ne rien faire</translation> ++<translation id="855081842937141170">Épingler l'onglet</translation> ++<translation id="6263541650532042179">réinitialiser la synchronisation</translation> ++<translation id="6055392876709372977">PKCS #1 SHA-256 avec chiffrement RSA</translation> ++<translation id="7903984238293908205">Katakana</translation> ++<translation id="3781488789734864345">Choisir un réseau mobile</translation> ++<translation id="268053382412112343">&Historique</translation> ++<translation id="2723893843198727027">Mode développeur :</translation> ++<translation id="1722567105086139392">Lien</translation> ++<translation id="2620436844016719705">Système</translation> ++<translation id="5362741141255528695">Sélectionnez le fichier de clé privée.</translation> ++<translation id="5292890015345653304">Insérez une carte SD ou une carte mémoire USB.</translation> ++<translation id="5583370583559395927">Temps restant : <ph name="TIME_REMAINING"/></translation> ++<translation id="8065982201906486420">Cliquez ici pour exécuter le plug-in <ph name="PLUGIN_NAME"/>.</translation> ++<translation id="6219717821796422795">Hanyu</translation> ++<translation id="3725367690636977613">pages</translation> ++<translation id="2688477613306174402">Configuration en cours</translation> ++<translation id="1195447618553298278">Erreur inconnue</translation> ++<translation id="3353284378027041011"><ph name="NUMBER_FEW"/> days ago</translation> ++<translation id="8811462119186190367">La langue utilisée pour Google Chrome est passée de "<ph name="FROM_LOCALE"/>" à "<ph name="TO_LOCALE"/>" après la synchronisation de vos paramètres.</translation> ++<translation id="1087119889335281750">&Aucune suggestion orthographique</translation> ++<translation id="5228309736894624122">Erreur de protocole SSL</translation> ++<translation id="8216170236829567922">Mode de saisie du thaï (clavier Pattachote)</translation> ++<translation id="8464132254133862871">Ce compte utilisateur n'est pas compatible avec ce service.</translation> ++<translation id="6812349420832218321"><ph name="PRODUCT_NAME"/> ne peut pas être exécuté en tant que root.</translation> ++<translation id="5076340679995252485">C&oller</translation> ++<translation id="2904348843321044456">Paramètres de contenu...</translation> ++<translation id="1055216403268280980">Dimensions de l'image</translation> ++<translation id="1784284518684746740">Sélectionner le fichier à enregistrer sous</translation> ++<translation id="7032947513385578725">Disque Flash</translation> ++<translation id="5518442882456325299">Moteur de recherche actuel :</translation> ++<translation id="14171126816530869">L'identité de <ph name="ORGANIZATION"/> situé à <ph name="LOCALITY"/> a été vérifiée par <ph name="ISSUER"/>.</translation> ++<translation id="6263082573641595914">Version de l'autorité de certification Microsoft</translation> ++<translation id="3105917916468784889">Enregistrer une capture d'écran</translation> ++<translation id="1741763547273950878">Page sur <ph name="SITE"/></translation> ++<translation id="1587275751631642843">Console &JavaScript</translation> ++<translation id="8460696843433742627">Réponse reçue incorrecte lors de la tentative de chargement de <ph name="URL"/>. ++ Cela peut être dû à une opération de maintenance ou à une configuration incorrecte sur le serveur.</translation> ++<translation id="297870353673992530">Serveur DNS :</translation> ++<translation id="3222066309010235055">Pré-rendu : <ph name="PRERENDER_CONTENTS_NAME"/></translation> ++<translation id="6410063390789552572">Impossible d'accéder à la bibliothèque réseau.</translation> ++<translation id="6880587130513028875">Des images ont été bloquées sur cette page.</translation> ++<translation id="851263357009351303">Toujours autoriser <ph name="HOST"/> à afficher les images</translation> ++<translation id="3511307672085573050">Copier l'adr&esse du lien</translation> ++<translation id="1134009406053225289">Ouvrir dans une fenêtre de navigation privée</translation> ++<translation id="6655190889273724601">Mode développeur</translation> ++<translation id="1071917609930274619">Chiffrement des données</translation> ++<translation id="3473105180351527598">Activer la protection contre le phishing et les logiciels malveillants</translation> ++<translation id="6151323131516309312">Appuyez sur <ph name="SEARCH_KEY"/> pour rechercher sur <ph name="SITE_NAME"/></translation> ++<translation id="3753317529742723206">Voulez-vous utiliser <ph name="HANDLER_TITLE"/> (<ph name="HANDLER_HOSTNAME"/>) au lieu de <ph name="REPLACED_HANDLER_TITLE"/> pour gérer les liens <ph name="PROTOCOL"/>:// à partir de maintenant ?</translation> ++<translation id="6216679966696797604">Démarrer une session en tant qu'invité</translation> ++<translation id="5456397824015721611">Nombre maximal de caractères chinois dans la mémoire tampon de pré-édition, notamment les entrées de symboles Zhuyin</translation> ++<translation id="2055443983279698110">Barre de menus GNOME expérimentale disponible</translation> ++<translation id="2342959293776168129">Effacer l'historique des téléchargements</translation> ++<translation id="2503522102815150840">Navigateur bloqué...</translation> ++<translation id="7201354769043018523">Parenthèse drte</translation> ++<translation id="425878420164891689">Calcul du temps de chargement</translation> ++<translation id="508794495705880051">Ajouter une carte de paiement...</translation> ++<translation id="1425975335069981043">Itinérance :</translation> ++<translation id="1272079795634619415">Arrêter</translation> ++<translation id="5442787703230926158">Erreur de synchronisation...</translation> ++<translation id="2462724976360937186">ID de clé de l'autorité de certification</translation> ++<translation id="6786747875388722282">Extensions</translation> ++<translation id="3944384147860595744">Imprimez où que vous soyez.</translation> ++<translation id="2570648609346224037">Un problème est survenu lors du téléchargement de l'image de récupération.</translation> ++<translation id="4306718255138772973">Cloud Print Proxy</translation> ++<translation id="9053965862400494292">Une erreur s'est produite lors de la configuration de la synchronisation.</translation> ++<translation id="8596540852772265699">Fichiers personnalisés</translation> ++<translation id="7017354871202642555">Impossible de définir le mode une fois la fenêtre créée.</translation> ++<translation id="3101709781009526431">Date et heure</translation> ++<translation id="69375245706918574">Personnaliser les préférences de synchronisation</translation> ++<translation id="833853299050699606">Aucune information disponible sur le forfait</translation> ++<translation id="1737968601308870607">Signaler un problème</translation> ++<translation id="4571852245489094179">Importer mes favoris et paramètres</translation> ++<translation id="99648783926443049">Sélectionnez le <ph name="BEGIN_BOLD"/>menu clé à molette > Paramètres > Options avancées > Modifier les paramètres du proxy<ph name="END_BOLD"/> et vérifiez que vos paramètres sont définis sur "sans proxy" ou "direct".</translation> ++<translation id="4421917670248123270">Fermer et annuler les téléchargements</translation> ++<translation id="5605623530403479164">Autres moteurs de recherche</translation> ++<translation id="8887243200615092733"><ph name="PRODUCT_NAME"/> peut maintenant synchroniser vos mots de passe. Pour protéger vos données, vous devez confirmer les informations relatives à votre compte.</translation> ++<translation id="4740663705480958372">Cette fonctionnalité active les API P2P Pepper et P2P JavaScript. L'API est en cours de développement et n'est pas encore opérationnelle.</translation> ++<translation id="5710435578057952990">L'identité de ce site Web n'a pas été vérifiée.</translation> ++<translation id="1421046588786494306">Sessions à l'étranger</translation> ++<translation id="1661245713600520330">Cette page répertorie tous les modules chargés dans le processus principal et les modules enregistrés de manière à être chargés ultérieurement.</translation> ++<translation id="5451646087589576080">Afficher les &infos sur le cadre</translation> ++<translation id="3368922792935385530">Connecté</translation> ++<translation id="3498309188699715599">Paramètres d'entrée en Chewing</translation> ++<translation id="8486154204771389705">Conserver sur cette page</translation> ++<translation id="3866443872548686097">Votre support de récupération est prêt. Vous pouvez le retirer du système.</translation> ++<translation id="6824564591481349393">Copi&er l'adresse e-mail</translation> ++<translation id="907148966137935206">Interdire à tous les sites d'afficher des fenêtres pop-up (recommandé)</translation> ++<translation id="5184063094292164363">Console &JavaScript</translation> ++<translation id="333371639341676808">Empêcher cette page de générer des boîtes de dialogue supplémentaires</translation> ++<translation id="7632380866023782514">En haut à droite</translation> ++<translation id="4925520021222027859">Entrez le mot de passe associé à votre application :</translation> ++<translation id="3494768541638400973">Mode de saisie Google du japonais (pour clavier japonais)</translation> ++<translation id="5844183150118566785"><ph name="PRODUCT_NAME"/> est à jour (<ph name="VERSION"/>)</translation> ++<translation id="3118046075435288765">Le serveur a mis fin à la connexion de manière inattendue.</translation> ++<translation id="8041140688818013446">Il est possible que le serveur hébergeant la page Web soit surchargé ou ait rencontré une erreur. Pour éviter de générer ++ trop de trafic et d'aggraver la situation, ++ <ph name="PRODUCT_NAME"/> a temporairement ++ bloqué l'acceptation des requêtes adressées au serveur. ++ <ph name="LINE_BREAK"/> ++ Si vous pensez que ce comportement n'est pas souhaitable, (par exemple, dans le cas où vous déboguez votre propre site Web), vous pouvez ++ consulter la page <ph name="NET_INTERNALS_PAGE"/>, ++ sur laquelle vous pourrez trouver plus d'informations ou désactiver cette fonctionnalité.</translation> ++<translation id="1725068750138367834">Gestionnaire de &fichiers</translation> ++<translation id="4254921211241441775">Arrêter la synchronisation du compte</translation> ++<translation id="7791543448312431591">Ajouter</translation> ++<translation id="8569764466147087991">Sélectionnez le fichier à ouvrir</translation> ++<translation id="5449451542704866098">Aucun forfait de données</translation> ++<translation id="307505906468538196">Créer un compte Google</translation> ++<translation id="2053553514270667976">Code postal</translation> ++<translation id="48838266408104654">&Gestionnaire de tâches</translation> ++<translation id="4378154925671717803">Téléphone</translation> ++<translation id="3694027410380121301">Sélectionner l'onglet précédent</translation> ++<translation id="6178664161104547336">Sélectionner un certificat</translation> ++<translation id="1375321115329958930">Mots de passe enregistrés</translation> ++<translation id="3341703758641437857">Autoriser l'accès aux URL de fichier</translation> ++<translation id="5702898740348134351">Modifi&er les moteurs de recherche...</translation> ++<translation id="734303607351427494">Gérer les moteurs de recherche...</translation> ++<translation id="8326478304147373412">PKCS #7, chaîne de certificats</translation> ++<translation id="3242765319725186192">Clé pré-partagée :</translation> ++<translation id="8089798106823170468">Contrôlez et partagez l'accès à vos imprimantes depuis n'importe quel compte Google.</translation> ++<translation id="5984992849064510607">Ajoute l'option "Utiliser les onglets latéraux" au menu contextuel de la barre d'onglets. Utilisez cette option pour déplacer les onglets du haut de l'écran (affichage par défaut) vers le côté. Particulièrement utile sur les grands écrans.</translation> ++<translation id="839736845446313156">S'inscrire</translation> ++<translation id="4668929960204016307">,</translation> ++<translation id="2409527877874991071">Saisissez un nouveau nom.</translation> ++<translation id="4240069395079660403"><ph name="PRODUCT_NAME"/> ne peut pas être affiché dans cette langue.</translation> ++<translation id="747114903913869239">Erreur : impossible de décoder l'extension.</translation> ++<translation id="5412637665001827670">Clavier bulgare</translation> ++<translation id="2113921862428609753">Accès aux informations de l'autorité</translation> ++<translation id="5227536357203429560">Ajouter un réseau privé...</translation> ++<translation id="732677191631732447">C&opier l'URL du fichier audio</translation> ++<translation id="7224023051066864079">Masque de sous-réseau :</translation> ++<translation id="2401813394437822086">Impossible d'accéder à votre compte ?</translation> ++<translation id="2344262275956902282">Utiliser les touches - et = pour paginer une liste d'entrées</translation> ++<translation id="3609138628363401169">Le serveur ne prend pas en charge l'extension de renégociation TLS.</translation> ++<translation id="3369624026883419694">Résolution de l'hôte...</translation> ++<translation id="8870413625673593573">Récemment fermés</translation> ++<translation id="9145357542626308749">Le certificat de sécurité du site a été signé avec un algorithme de signature faible.</translation> ++<translation id="8502803898357295528">Votre mot de passe a été modifié</translation> ++<translation id="4064488613268730704">Gérer les paramètres de saisie automatique...</translation> ++<translation id="6830600606572693159">La page Web <ph name="URL"/> n'est pas disponible pour le moment. Cela peut être dû à une surcharge ou à une opération de maintenance.</translation> ++<translation id="4145797339181155891">Éjecter</translation> ++<translation id="7886793013438592140">Impossible de lancer le processus de service.</translation> ++<translation id="8417944620073548444"><ph name="MEGABYTES"/> Mo restants</translation> ++<translation id="7339898014177206373">Nouvelle fenêtre</translation> ++<translation id="3026202950002788510">Sélectionnez ++ <ph name="BEGIN_BOLD"/> ++ Applications > Préférences système > Réseau > Avancé > Proxys ++ <ph name="END_BOLD"/> ++ et désélectionnez les serveurs proxy sélectionnés.</translation> ++<translation id="7033648024564583278">Gravure en cours d'initialisation...</translation> ++<translation id="2246340272688122454">Téléchargement de l'image de récupération...</translation> ++<translation id="7770995925463083016">il y a <ph name="NUMBER_TWO"/> minutes</translation> ++<translation id="2816269189405906839">Mode de saisie du chinois (cangjie)</translation> ++<translation id="7087282848513945231">Comté</translation> ++<translation id="2149951639139208969">Ouvrir l'adresse dans un nouvel onglet</translation> ++<translation id="175196451752279553">&Rouvrir l'onglet fermé</translation> ++<translation id="5992618901488170220">Impossible d'afficher la page Web, car votre ordinateur est passé en mode ++ veille ou hibernation. Dans ce cas, les connexions réseau sont ++ coupées et les requêtes réseau échouent. L'actualisation de la page ++ devrait permettre de résoudre ce problème.</translation> ++<translation id="2655386581175833247">Certificat utilisateur :</translation> ++<translation id="5039804452771397117">Autoriser</translation> ++<translation id="5435964418642993308">Appuyer sur Entrée pour revenir en arrière et sur la touche de menu contextuel pour afficher l'historique</translation> ++<translation id="81686154743329117">ZRM</translation> ++<translation id="7564146504836211400">Cookies et autres données</translation> ++<translation id="2266011376676382776">Page(s) ne répondant pas</translation> ++<translation id="2714313179822741882">Paramètres d'entrée hangûl</translation> ++<translation id="8658163650946386262">Configurer la synchronisation...</translation> ++<translation id="3100609564180505575">Modules (<ph name="TOTAL_COUNT"/>). Conflits connus : <ph name="BAD_COUNT"/>, conflits probables : <ph name="SUSPICIOUS_COUNT"/></translation> ++<translation id="3627671146180677314">Date de renouvellement du certificat Netscape</translation> ++<translation id="1319824869167805246">Ouvrir tous les favoris dans une nouvelle fenêtre</translation> ++<translation id="8652487083013326477">bouton radio concernant l'étendue de pages</translation> ++<translation id="5204967432542742771">Saisissez votre mot de passe</translation> ++<translation id="4388712255200933062"><ph name="CLOUD_PRINT_NAME"/> est conçu pour rendre l'impression plus intuitive, accessible et utile. <ph name="CLOUD_PRINT_NAME"/> vous permet de rendre vos imprimantes accessibles depuis n'importe quelle application Web ou mobile associée à <ph name="CLOUD_PRINT_NAME"/>.</translation> ++<translation id="2932611376188126394">Dictionnaire de kanji unique</translation> ++<translation id="5485754497697573575">Rétablir tous les onglets</translation> ++<translation id="3371861036502301517">Échec de l'installation de l'extension</translation> ++<translation id="644038709730536388">En savoir plus sur la manière de se protéger des logiciels malveillants en ligne</translation> ++<translation id="2155931291251286316">Toujours afficher les fenêtres pop-up de <ph name="HOST"/></translation> ++<translation id="3445830502289589282">Authentification phase 2 :</translation> ++<translation id="5650551054760837876">Aucun résultat de recherche trouvé</translation> ++<translation id="5494362494988149300">Ouvrir une fois le téléchargement &terminé</translation> ++<translation id="2956763290572484660"><ph name="COOKIES"/> cookies</translation> ++<translation id="6989836856146457314">Mode de saisie du japonais (pour clavier américain)</translation> ++<translation id="9187787570099877815">Continuer à bloquer les plug-ins</translation> ++<translation id="8425492902634685834">Épingler sur la barre des tâches</translation> ++<translation id="825608351287166772">Les certificats ont une période de validité, comme tous les documents relatifs à votre identité (tel qu'un passeport). Le certificat présenté à votre navigateur n'est pas encore valide ! Lorsqu'un certificat est en dehors de sa période de validité, il n'est pas nécessaire d'assurer la maintenance de certaines informations relatives à son état (s'il a été révoqué ou s'il n'est plus approuvé). Par conséquent, il est impossible de vérifier que le certificat est fiable. Ne poursuivez pas.</translation> ++<translation id="741630086309232721">Fermer la session d'invité</translation> ++<translation id="7309459761865060639">Contrôlez vos tâches d'impression et l'état de connexion de vos imprimantes en ligne.</translation> ++<translation id="4803909571878637176">Désinstallation</translation> ++<translation id="5209518306177824490">Empreinte SHA-1</translation> ++<translation id="3300768886937313568">Modifier le code PIN de la carte SIM</translation> ++<translation id="7447657194129453603">État du réseau :</translation> ++<translation id="1553538517812678578">sans limite</translation> ++<translation id="7947315300197525319">(Choisir une autre capture d'écran)</translation> ++<translation id="3612070600336666959">Désactivation</translation> ++<translation id="3759461132968374835">Aucune erreur n'a été signalée récemment. Les erreurs n'apparaissent ici que lorsque l'envoi de rapports d'erreur est activé.</translation> ++<translation id="1516602185768225813">Rouvrir les dernières pages ouvertes</translation> ++<translation id="189210018541388520">Ouvrir en mode plein écran</translation> ++<translation id="8795668016723474529">Ajouter une carte de paiement</translation> ++<translation id="5860033963881614850">Désactivé</translation> ++<translation id="3956882961292411849">Chargement des informations sur votre forfait Internet mobile, veuillez patienter...</translation> ++<translation id="689050928053557380">Acheter un forfait de données...</translation> ++<translation id="4235618124995926194">Inclure cet e-mail :</translation> ++<translation id="4874539263382920044">Le titre doit comporter au moins un caractère.</translation> ++<translation id="798525203920325731">Espaces de noms réseau</translation> ++<translation id="263325223718984101"><ph name="PRODUCT_NAME"/> n'a pas pu terminer l'installation, mais va poursuivre son exécution à partir de son image disque.</translation> ++<translation id="7025190659207909717">Gestion des services Internet mobiles</translation> ++<translation id="8265096285667890932">Utiliser les onglets latéraux</translation> ++<translation id="4250680216510889253">Non</translation> ++<translation id="3949593566929137881">Saisir le code PIN de la carte SIM</translation> ++<translation id="6291953229176937411">&Afficher dans le Finder</translation> ++<translation id="2476990193835943955">Maintenez la touche Ctrl, Alt ou Maj enfoncée<br>pour afficher le raccourci clavier qui lui est associé.</translation> ++<translation id="9187827965378254003">Vraiment désolé, aucun prototype n'est disponible pour le moment.</translation> ++<translation id="8933960630081805351">&Afficher dans le Finder</translation> ++<translation id="3041612393474885105">Informations relatives au certificat</translation> ++<translation id="7378810950367401542">/</translation> ++<translation id="4611079913162790275">La synchronisation des mots de passe requiert votre attention.</translation> ++<translation id="6562758426028728553">Veuillez saisir l'ancien et le nouveau code PIN.</translation> ++<translation id="614161640521680948">Langue :</translation> ++<translation id="3665650519256633768">Résultats de recherche</translation> ++<translation id="3733127536501031542">Serveur SSL avec fonction d'optimisation</translation> ++<translation id="3614837889828516995">Enregistrer en PDF</translation> ++<translation id="5745056705311424885">Mémoire USB détectée</translation> ++<translation id="5895875028328858187">M'avertir lorsque le flux de données est faible ou presque inexistant</translation> ++<translation id="939598580284253335">Saisir le mot de passe multiterme</translation> ++<translation id="7917972308273378936">Clavier lituanien</translation> ++<translation id="8371806639176876412">Les éléments saisis dans le champ polyvalent peuvent être enregistrés.</translation> ++<translation id="4216499942524365685">Les informations de connexion à votre compte sont obsolètes. Cliquez ici pour saisir à nouveau votre mot de passe.</translation> ++<translation id="8899388739470541164">Vietnamien</translation> ++<translation id="4091434297613116013">feuilles de papier</translation> ++<translation id="7475671414023905704">URL de mot de passe perdu Netscape</translation> ++<translation id="3335947283844343239">Rouvrir l'onglet fermé</translation> ++<translation id="4089663545127310568">Effacer les mots de passe enregistrés</translation> ++<translation id="6500444002471948304">Créer un nouveau dossier...</translation> ++<translation id="2480626392695177423">Basculer en mode ponctuation pleine chasse ou demi-chasse</translation> ++<translation id="5830410401012830739">Gérer les paramètres de localisation...</translation> ++<translation id="8977410484919641907">Synchronisé...</translation> ++<translation id="2794293857160098038">Options de recherche par défaut</translation> ++<translation id="3947376313153737208">Aucune sélection</translation> ++<translation id="1346104802985271895">Mode de saisie du vietnamien (TELEX)</translation> ++<translation id="5935630983280450497"><ph name="NUMBER_ONE"/> minute restante</translation> ++<translation id="5889282057229379085">Le nombre maximal d'autorités de certification intermédiaires a été dépassé : <ph name="NUM_INTERMEDIATE_CA"/></translation> ++<translation id="3180365125572747493">Saisissez un mot de passe pour chiffrer ce fichier de certificat.</translation> ++<translation id="5496587651328244253">Organiser</translation> ++<translation id="4821086771593057290">Votre mot de passe a changé. Veuillez réessayer avec votre nouveau mot de passe.</translation> ++<translation id="7075513071073410194">PKCS #1 MD5 avec chiffrement RSA</translation> ++<translation id="4378727699507047138">Utiliser le thème classique</translation> ++<translation id="7124398136655728606">Échap efface toute la mémoire tampon de pré-édition</translation> ++<translation id="8293206222192510085">Ajouter aux favoris</translation> ++<translation id="2592884116796016067">Un incident est survenu sur une partie de cette page (HTML WebWorker). Elle risque de ne pas fonctionner correctement.</translation> ++<translation id="2529133382850673012">Clavier américain</translation> ++<translation id="4411578466613447185">Signataire de code</translation> ++<translation id="1354868058853714482">Adobe Reader n'est pas à jour et risque de ne plus être sécurisé.</translation> ++<translation id="6252594924928912846">Personnaliser les paramètres de synchronisation...</translation> ++<translation id="8425755597197517046">Co&ller et rechercher</translation> ++<translation id="1093148655619282731">Détails du certificat sélectionné :</translation> ++<translation id="5568069709869097550">Impossible de se connecter</translation> ++<translation id="2743322561779022895">Activation :</translation> ++<translation id="4181898366589410653">Système de révocation introuvable dans le certificat du serveur</translation> ++<translation id="8705331520020532516">Numéro de série</translation> ++<translation id="1665770420914915777">Afficher la page "Nouvel onglet"</translation> ++<translation id="2629089419211541119">il y a <ph name="NUMBER_ONE"/> heure</translation> ++<translation id="1691063574428301566">Votre ordinateur redémarrera une fois la mise à jour effectuée.</translation> ++<translation id="131364520783682672">Verr. maj.</translation> ++<translation id="6259308910735500867">L'accès au répertoire de l'hôte de communication à distance a été refusé. Essayez avec un autre compte.</translation> ++<translation id="3415261598051655619">Accessible aux scripts :</translation> ++<translation id="2335122562899522968">Cette page place des cookies.</translation> ++<translation id="8461914792118322307">Proxy</translation> ++<translation id="4089521618207933045">Avec sous-menu</translation> ++<translation id="1936157145127842922">Afficher dans le dossier</translation> ++<translation id="6982279413068714821">il y a <ph name="NUMBER_DEFAULT"/> minutes</translation> ++<translation id="7977590112176369853"><saisir une requête></translation> ++<translation id="3449839693241009168">Appuyez sur <ph name="SEARCH_KEY"/> pour envoyer des commandes à <ph name="EXTENSION_NAME"/>.</translation> ++<translation id="7443484992065838938">Prévisualiser le rapport</translation> ++<translation id="5714678912774000384">Activer le dernier onglet</translation> ++<translation id="3799598397265899467">Lorsque je quitte le navigateur</translation> ++<translation id="2125314715136825419">Continuer sans mettre à jour Adobe Reader (non recommandé)</translation> ++<translation id="1120026268649657149">Le champ de mot clé doit être vide ou comporter un mot unique</translation> ++<translation id="542318722822983047">Déplacer le curseur automatiquement au caractère suivant</translation> ++<translation id="5317780077021120954">Enregistrer</translation> ++<translation id="9027459031423301635">Ouvrir le lien dans un nouvel ongle&t</translation> ++<translation id="2251809247798634662">Nouvelle fenêtre de navigation privée</translation> ++<translation id="358344266898797651">Celtique</translation> ++<translation id="3625870480639975468">Réinitialiser le zoom</translation> ++<translation id="5199729219167945352">Prototypes</translation> ++<translation id="5055518462594137986">Mémoriser mes choix pour tous les liens de ce type</translation> ++<translation id="246059062092993255">Les plug-ins de cette page ont été bloqués.</translation> ++<translation id="2870560284913253234">Site</translation> ++<translation id="6945221475159498467">Sélectionner</translation> ++<translation id="7724603315864178912">Couper</translation> ++<translation id="4164507027399414915">Restaurer toutes les miniatures supprimées</translation> ++<translation id="917051065831856788">Utiliser les onglets latéraux</translation> ++<translation id="1976150099241323601">Se connecter au dispositif de sécurité</translation> ++<translation id="6620110761915583480">Enregistrer le fichier</translation> ++<translation id="4988526792673242964">Pages</translation> ++<translation id="7543025879977230179">Options de <ph name="PRODUCT_NAME"/></translation> ++<translation id="2175607476662778685">Barre de lancement rapide</translation> ++<translation id="6434309073475700221">Annuler</translation> ++<translation id="1367951781824006909">Choisir un fichier</translation> ++<translation id="1425127764082410430">&Rechercher <ph name="SEARCH_TERMS"/> avec <ph name="SEARCH_ENGINE"/></translation> ++<translation id="684265517037058883">(pas encore valide)</translation> ++<translation id="2027538664690697700">Mettre à jour le plug-in...</translation> ++<translation id="8205333955675906842">Police Sans-Serif</translation> ++<translation id="39964277676607559">Impossible de charger le JavaScript "<ph name="RELATIVE_PATH"/>" du script de contenu.</translation> ++<translation id="4378551569595875038">Connexion...</translation> ++<translation id="7029809446516969842">Mots de passe</translation> ++<translation id="8053278772142718589">Fichiers PKCS #12</translation> ++<translation id="3129020372442395066">Options de saisie automatique de <ph name="PRODUCT_NAME_SHORT"/></translation> ++<translation id="4114360727879906392">Fenêtre précédente</translation> ++<translation id="8238649969398088015">Astuce</translation> ++<translation id="5958418293370246440"><ph name="SAVED_FILES"/> / <ph name="TOTAL_FILES"/> fichiers</translation> ++<translation id="2350172092385603347">Localisation utilisée, mais les paramètres régionaux par défaut (default_locale) n'ont pas été indiqués dans le manifeste. </translation> ++<translation id="8221729492052686226">Si vous n'êtes pas à l'origine de cette requête, il s'agit probablement d'une attaque contre votre système. Si vous n'avez pas lancé cette requête de manière intentionnelle, cliquez sur Ne rien faire.</translation> ++<translation id="5894314466642127212">Votre commentaire a bien été envoyé.</translation> ++<translation id="894360074127026135">Fonction d'optimisation internationale Netscape </translation> ++<translation id="6025294537656405544">Taille de police minimale</translation> ++<translation id="1201402288615127009">Suivant</translation> ++<translation id="1335588927966684346">Utilitaire :</translation> ++<translation id="7857823885309308051">Cette opération peut prendre une minute...</translation> ++<translation id="662870454757950142">Le format du mot de passe est incorrect.</translation> ++<translation id="370665806235115550">Chargement...</translation> ++<translation id="1808792122276977615">Ajouter la page...</translation> ++<translation id="2076269580855484719">Masquer ce plug-in</translation> ++<translation id="254416073296957292">&Paramètres linguistiques...</translation> ++<translation id="6652975592920847366">Créer un support de récupération du système d'exploitation</translation> ++<translation id="52912272896845572">Le fichier de clé privée est incorrect.</translation> ++<translation id="3232318083971127729">Valeur :</translation> ++<translation id="8807632654848257479">Stable</translation> ++<translation id="4209092469652827314">Grande</translation> ++<translation id="4222982218026733335">Certificat serveur invalide</translation> ++<translation id="152234381334907219">Jamais enregistrés</translation> ++<translation id="5600599436595580114">Cette page a été préchargée.</translation> ++<translation id="8926468725336609312">Google Chrome ne peut pas afficher l'aperçu avant impression lorsque la visionneuse de documents PDF intégrée est désactivée. Pour l'afficher, veuillez accéder à <ph name="BEGIN_LINK"/>chrome://plugins<ph name="END_LINK"/>, activer "Chrome PDF Viewer" et réessayer.</translation> ++<translation id="8494214181322051417">Nouveau !</translation> ++<translation id="7762841930144642410"><ph name="BEGIN_BOLD"/>Vous êtes passé en navigation privée<ph name="END_BOLD"/>. Les pages que vous consultez dans cette fenêtre n'apparaîtront ni dans l'historique de votre navigateur, ni dans l'historique des recherches, et ne laisseront aucune trace (comme les cookies) sur votre ordinateur une fois que vous aurez fermé la fenêtre de navigation privée. Tous les fichiers téléchargés et les favoris créés seront toutefois conservés. <ph name="LINE_BREAK"/> <ph name="BEGIN_BOLD"/>Passer en navigation privée n'a aucun effet sur les autres utilisateurs, serveurs ou logiciels. Méfiez-vous :<ph name="END_BOLD"/> <ph name="BEGIN_LIST"/> <ph name="BEGIN_LIST_ITEM"/>Des sites Web qui collectent ou partagent des informations vous concernant<ph name="END_LIST_ITEM"/> <ph name="BEGIN_LIST_ITEM"/>Des fournisseurs d'accès Internet ou des employeurs qui conservent une trace des pages que vous visitez<ph name="END_LIST_ITEM"/> <ph name="BEGIN_LIST_ITEM"/>Des programmes indésirables qui enregistrent vos frappes en échange d'émoticônes gratuites<ph name="END_LIST_ITEM"/> <ph name="BEGIN_LIST_ITEM"/>Des personnes qui pourraient surveiller vos activités<ph name="END_LIST_ITEM"/> <ph name="BEGIN_LIST_ITEM"/>Des personnes qui se tiennent derrière vous<ph name="END_LIST_ITEM"/> <ph name="END_LIST"/> <ph name="BEGIN_LINK"/>En savoir plus sur la navigation privée<ph name="END_LINK"/></translation> ++<translation id="2386255080630008482">Le certificat du serveur a été révoqué.</translation> ++<translation id="2135787500304447609">&Reprendre</translation> ++<translation id="8309505303672555187">Sélectionnez un réseau :</translation> ++<translation id="6143635259298204954">Impossible d'extraire les fichiers de l'extension. Pour effectuer cette opération en toute sécurité, vous devez disposer d'un chemin d'accès à votre répertoire de profils ne contenant pas de lien symbolique. Aucun chemin de ce type n'existe pour votre profil.</translation> ++<translation id="1813414402673211292">Effacer les données de navigation</translation> ++<translation id="4062903950301992112">Si vous êtes conscient que la visite de ce site peut être préjudiciable à votre ordinateur, vous pouvez <ph name="PROCEED_LINK"/>.</translation> ++<translation id="32330993344203779">Votre périphérique est inscrit pour bénéficier de la gestion d'entreprise.</translation> ++<translation id="2356762928523809690">Serveur de mise à jour non disponible (erreur : <ph name="ERROR_NUMBER"/>)</translation> ++<translation id="219008588003277019">Module client natif : <ph name="NEXE_NAME"/></translation> ++<translation id="5436510242972373446">Rechercher sur <ph name="SITE_NAME"/> :</translation> ++<translation id="3800764353337460026">Style de symboles</translation> ++<translation id="6719684875142564568"><ph name="NUMBER_ZERO"/> hours</translation> ++<translation id="2096368010154057602">Département</translation> ++<translation id="1036561994998035917">Continuer à utiliser <ph name="ENGINE_NAME"/></translation> ++<translation id="8730621377337864115">OK</translation> ++<translation id="665757950158579497">Essayez de désactiver les prédictions d'actions du réseau en procédant comme suit : ++ Sélectionnez le ++ <ph name="BEGIN_BOLD"/> ++ menu clé à molette > ++ <ph name="SETTINGS_TITLE"/> ++ > ++ <ph name="ADVANCED_TITLE"/> ++ <ph name="END_BOLD"/> ++ et désélectionnez "<ph name="NO_PREFETCH_DESCRIPTION"/>". ++ Si le problème n'est pas résolu, nous vous conseillons de sélectionner de nouveau ++ cette option pour améliorer les performances.</translation> ++<translation id="4932733599132424254">Date</translation> ++<translation id="6267166720438879315">Sélectionnez un certificat pour vous authentifier sur <ph name="HOST_NAME"/>.</translation> ++<translation id="2422927186524098759">Barre latérale</translation> ++<translation id="7839809549045544450">La clé publique éphémère Diffie-Hellman associée au serveur est peu sûre.</translation> ++<translation id="5515806255487262353">Rechercher dans Dictionnaire</translation> ++<translation id="350048665517711141">Sélectionnez un moteur de recherche</translation> ++<translation id="2790805296069989825">Clavier russe</translation> ++<translation id="5708171344853220004">Nom Microsoft principal</translation> ++<translation id="5464696796438641524">Clavier polonais</translation> ++<translation id="2080010875307505892">Clavier serbe</translation> ++<translation id="2953767478223974804"><ph name="NUMBER_ONE"/> minute</translation> ++<translation id="201192063813189384">Erreur lors de la lecture des données du cache.</translation> ++<translation id="7851768487828137624">Canary</translation> ++<translation id="6129938384427316298">Commentaire du certificat Netscape</translation> ++<translation id="8210608804940886430">Page suivante</translation> ++<translation id="9065596142905430007"><ph name="PRODUCT_NAME"/> est à jour.</translation> ++<translation id="1035650339541835006">Paramètres de saisie automatique...</translation> ++<translation id="6315493146179903667">Tout ramener au premier plan</translation> ++<translation id="1000498691615767391">Sélectionner le dossier à ouvrir</translation> ++<translation id="3593152357631900254">Activer le mode Pinyin fuzzy</translation> ++<translation id="5015344424288992913">Résolution du proxy...</translation> ++<translation id="8506299468868975633">Le téléchargement de l'image a été interrompu.</translation> ++<translation id="4724168406730866204">Eten 26</translation> ++<translation id="308268297242056490">URI</translation> ++<translation id="4479812471636796472">Clavier Dvorak américain</translation> ++<translation id="8673026256276578048">Rechercher sur le Web...</translation> ++<translation id="1437307674059038925">Si vous utilisez un serveur proxy, vérifiez les paramètres associés ou demandez à votre administrateur réseau ++ si ce serveur fonctionne.</translation> ++<translation id="149347756975725155">Impossible de charger l'icône de l'extension "<ph name="ICON"/>".</translation> ++<translation id="3675321783533846350">Définir un proxy pour se connecter au réseau</translation> ++<translation id="5451285724299252438">zone de texte concernant l'étendue de pages</translation> ++<translation id="5669267381087807207">Activation</translation> ++<translation id="7434823369735508263">Clavier Dvorak britannique</translation> ++<translation id="1572103024875503863"><ph name="NUMBER_MANY"/> jours</translation> ++<translation id="2084978867795361905">MS-IME</translation> ++<translation id="7227669995306390694">Aucun forfait de données <ph name="NETWORK"/></translation> ++<translation id="3481915276125965083">Les fenêtres pop-up suivantes ont été bloquées sur cette page :</translation> ++<translation id="7163503212501929773"><ph name="NUMBER_MANY"/> heures restantes</translation> ++<translation id="7705276765467986571">Impossible de charger le modèle du favori.</translation> ++<translation id="1196338895211115272">Échec d'exportation de la clé privée</translation> ++<translation id="5586329397967040209">Utiliser comme page d'accueil</translation> ++<translation id="629730747756840877">Compte</translation> ++<translation id="8525306231823319788">Plein écran</translation> ++<translation id="9054208318010838">Autoriser tous les sites à suivre ma position géographique</translation> ++<translation id="3058212636943679650">Si la restauration du système d'exploitation de votre ordinateur s'avère nécessaire, une carte SD ou une clé USB de récupération vous sera demandée.</translation> ++<translation id="2815382244540487333">Les cookies suivants ont été bloqués :</translation> ++<translation id="8882395288517865445">Inclure les adresses de ma fiche de Carnet d’adresses</translation> ++<translation id="374530189620960299">Le certificat de sécurité du site n'est pas approuvé !</translation> ++<translation id="8852407435047342287">Votre liste d'applications, d'extensions et de thèmes installés</translation> ++<translation id="5647283451836752568">Exécuter tous les plug-ins de cette page</translation> ++<translation id="8642947597466641025">Augmente la taille du texte</translation> ++<translation id="5188181431048702787">Accepter et continuer »</translation> ++<translation id="1293556467332435079">Fichiers ++</translation> ++<translation id="2490270303663597841">Appliquer uniquement à cette session de navigation privée</translation> ++<translation id="1757915090001272240">Latin large</translation> ++<translation id="8496717697661868878">Exécuter ce plug-in</translation> ++<translation id="3450660100078934250">MasterCard</translation> ++<translation id="2916073183900451334">Sur le Web, Tab permet de sélectionner les liens, ainsi que les champs de formulaire.</translation> ++<translation id="7772127298218883077">À propos de <ph name="PRODUCT_NAME"/></translation> ++<translation id="2090876986345970080">Paramètres de sécurité du système</translation> ++<translation id="9219103736887031265">Images</translation> ++<translation id="5453632173748266363">Cyrillique</translation> ++<translation id="1008557486741366299">Pas maintenant</translation> ++<translation id="8415351664471761088">Attendre la fin du téléchargement</translation> ++<translation id="1545775234664667895">Thème "<ph name="THEME_NAME"/>" installé</translation> ++<translation id="5329858601952122676">&Supprimer</translation> ++<translation id="6100736666660498114">Menu Démarrer</translation> ++<translation id="3994878504415702912">&Zoom</translation> ++<translation id="9009369504041480176">Transfert en cours (<ph name="PROGRESS_PERCENT"/> %)...</translation> ++<translation id="8995603266996330174">Géré par <ph name="DOMAIN"/></translation> ++<translation id="5602600725402519729">&Rafraîchir</translation> ++<translation id="172612876728038702">Configuration du module de plate-forme sécurisée (TPM) en cours. Veuillez patienter, cela peut prendre quelques minutes.</translation> ++<translation id="1362165759943288856">Vous avez acheté une quantité illimitée de données le <ph name="DATE"/>.</translation> ++<translation id="2078019350989722914">Confirmer avant de quitter (<ph name="KEY_EQUIVALENT"/>)</translation> ++<translation id="7965010376480416255">Mémoire partagée</translation> ++<translation id="6248988683584659830">Rech. dans les paramètres</translation> ++<translation id="8323232699731382745">mot de passe d'accès au réseau</translation> ++<translation id="6588399906604251380">Activer la vérification orthographique</translation> ++<translation id="7167621057293532233">Types de données</translation> ++<translation id="7053983685419859001">Bloquer</translation> ++<translation id="2485056306054380289">Certificat de l'autorité de certification du serveur :</translation> ++<translation id="6462109140674788769">Clavier grec</translation> ++<translation id="2727712005121231835">Taille réelle</translation> ++<translation id="8887733174653581061">Toujours en haut</translation> ++<translation id="5581211282705227543">Aucun plug-in installé.</translation> ++<translation id="610886263749567451">Alerte JavaScript</translation> ++<translation id="5488468185303821006">Autoriser en mode navigation privée</translation> ++<translation id="6556866813142980365">Rétablir</translation> ++<translation id="2107287771748948380"><ph name="OBFUSCATED_CC_NUMBER"/>, expire le : <ph name="CC_EXPIRATION_DATE"/></translation> ++<translation id="6584811624537923135">Confirmer la désinstallation</translation> ++<translation id="7429235532957570505">Impossible de désactiver les plug-ins ayant été activés par une stratégie d'entreprise.</translation> ++<translation id="7866522434127619318">Cette fonctionnalité active l'option "Lire en un clic" dans les paramètres de contenu du plug-in.</translation> ++<translation id="8860923508273563464">Attendre la fin des téléchargements</translation> ++<translation id="6406506848690869874">Synchronisation</translation> ++<translation id="5288678174502918605">&Rouvrir l'onglet fermé</translation> ++<translation id="7238461040709361198">Votre mot de passe de compte Google a changé depuis votre dernière connexion à partir de cet ordinateur.</translation> ++<translation id="1956050014111002555">Le fichier contenait plusieurs certificats, aucun d'eux n'a été importé :</translation> ++<translation id="302620147503052030">Afficher le bouton</translation> ++<translation id="5512074755152723588">La saisie dans le champ polyvalent d'une URL déjà ouverte dans un autre onglet entraîne l'affichage de l'onglet en question, et non l'affichage de l'URL dans l'onglet actuel.</translation> ++<translation id="9157595877708044936">Configuration en cours...</translation> ++<translation id="4475552974751346499">Rechercher dans les téléchargements</translation> ++<translation id="3021256392995617989">Me demander lorsqu'un site tente de suivre ma position géographique (recommandé)</translation> ++<translation id="5185386675596372454">La nouvelle version de "<ph name="EXTENSION_NAME"/>" a été désactivée, car elle nécessite davantage d'autorisations.</translation> ++<translation id="4285669636069255873">Clavier phonétique russe</translation> ++<translation id="4148925816941278100">American Express</translation> ++<translation id="2320435940785160168">Ce serveur exige un certificat d'authentification et n'a pas accepté celui envoyé par le navigateur. ++Votre certificat a peut-être expiré ou le serveur n'a pas approuvé l'émetteur. ++Réessayez avec un autre certificat si vous en avez un. ++Sinon, vous devrez en obtenir un nouveau d'un autre émetteur.</translation> ++<translation id="6295228342562451544">Lorsque vous vous connectez à un site Web sécurisé, le serveur hébergeant ce site présente à votre navigateur un "certificat" afin de vérifier l'identité du site. Ce certificat contient des informations d'identité, telles que l'adresse du site Web, laquelle est vérifiée par un tiers approuvé par votre ordinateur. En vérifiant que l'adresse du certificat correspond à l'adresse du site Web, il est possible de s'assurer que vous êtes connecté de façon sécurisée avec le site Web souhaité et non pas avec un tiers (tel qu'un pirate informatique sur votre réseau).</translation> ++<translation id="6342069812937806050">À l'instant</translation> ++<translation id="5605716740717446121">Votre carte SIM sera définitivement désactivée si vous ne saisissez pas correctement la clé de déverrouillage du code PIN. Nombre de tentatives restantes : <ph name="TRIES_COUNT"/></translation> ++<translation id="8836712291807476944"><ph name="SAVED_BYTES"/> / <ph name="TOTAL_BYTES"/> octets, Interrompu</translation> ++<translation id="5502500733115278303">Importés depuis Firefox</translation> ++<translation id="569109051430110155">Détection automatique</translation> ++<translation id="4408599188496843485">&Aide</translation> ++<translation id="5399158067281117682">Les codes PIN sont différents !</translation> ++<translation id="8494234776635784157">Contenu Web</translation> ++<translation id="2681441671465314329">Vider le cache</translation> ++<translation id="3646789916214779970">Rétablir le thème par défaut</translation> ++<translation id="1592960452683145077">Le service de communication à distance a démarré correctement. Vous devriez maintenant pouvoir vous connecter à distance à cet ordinateur.</translation> ++<translation id="1679068421605151609">Outils de développement</translation> ++<translation id="6648524591329069940">Police Serif</translation> ++<translation id="6896758677409633944">Copier</translation> ++<translation id="5260508466980570042">Adresse e-mail ou mot de passe incorrect. Veuillez réessayer.</translation> ++<translation id="7887998671651498201">Le plug-in suivant ne répond pas : souhaitez-vous interrompre <ph name="PLUGIN_NAME"/> ?</translation> ++<translation id="173188813625889224">Sens</translation> ++<translation id="8088823334188264070"><ph name="NUMBER_MANY"/> secondes</translation> ++<translation id="1337036551624197047">Clavier tchèque</translation> ++<translation id="4212108296677106246">Voulez-vous que "<ph name="CERTIFICATE_NAME"/>" soit considérée comme une autorité de certification fiable ?</translation> ++<translation id="2861941300086904918">Gestionnaire de sécurité natif du client</translation> ++<translation id="6991443949605114807"><p>Lorsque vous exécutez <ph name="PRODUCT_NAME"/> dans un environnement de bureau pris en charge, les paramètres proxy du système sont utilisés. Toutefois, soit votre système n'est pas pris en charge, soit un problème est survenu lors du lancement de votre configuration système.</p> ++ ++ <p>Vous avez toujours la possibilité d'effectuer la configuration via la ligne de commande. Pour plus d'informations sur les indicateurs et les variables d'environnement, veuillez vous reporter à <code>man <ph name="PRODUCT_BINARY_NAME"/></code>.</p></translation> ++<translation id="9071590393348537582">La page Web à l'adresse <ph name="URL"/> a déclenché trop de redirections. Pour résoudre le problème, effacez les cookies de ce site ou autorisez les cookies tiers. Si le problème persiste, il peut être dû à une mauvaise configuration du serveur et n'être aucunement lié à votre ordinateur.</translation> ++<translation id="7205869271332034173">SSID :</translation> ++<translation id="7084579131203911145">Nom du forfait :</translation> ++<translation id="5815645614496570556">Adresse X.400</translation> ++<translation id="3551320343578183772">Fermer l'onglet</translation> ++<translation id="3345886924813989455">Impossible de trouver un navigateur pris en charge.</translation> ++<translation id="74354239584446316">Le compte associé à la boutique en ligne est le suivant : <ph name="EMAIL_ADDRESS"/>. L'utilisation d'un autre compte pour la synchronisation provoque des erreurs.</translation> ++<translation id="3712897371525859903">Enregistrer la p&age sous...</translation> ++<translation id="7926251226597967072"><ph name="PRODUCT_NAME"/> importe actuellement les éléments suivants à partir de <ph name="IMPORT_BROWSER_NAME"/> :</translation> ++<translation id="2767649238005085901">Appuyez sur Entrée pour avancer et sur la touche de menu contextuel pour afficher l'historique</translation> ++<translation id="8580634710208701824">Actualiser le cadre</translation> ++<translation id="1018656279737460067">Annulé</translation> ++<translation id="7606992457248886637">Autorités</translation> ++<translation id="707392107419594760">Sélectionnez votre clavier :</translation> ++<translation id="2007404777272201486">Signaler un problème...</translation> ++<translation id="2390045462562521613">Ignorer ce réseau</translation> ++<translation id="3348038390189153836">Nouveau matériel détecté</translation> ++<translation id="1666788816626221136">Vous disposez de certificats qui n'appartiennent à aucune autre catégorie :</translation> ++<translation id="4821935166599369261">&Profilage activé</translation> ++<translation id="1603914832182249871">(Navigation privée)</translation> ++<translation id="7910768399700579500">&Nouveau dossier</translation> ++<translation id="7472639616520044048">Types MIME :</translation> ++<translation id="2307164895203900614">Afficher les pages en arrière-plan (<ph name="NUM_BACKGROUND_APPS"/>)</translation> ++<translation id="3192947282887913208">Fichiers audio</translation> ++<translation id="6295535972717341389">Plug-ins</translation> ++<translation id="8116190140324504026">Plus d'informations...</translation> ++<translation id="7469894403370665791">Se connecter automatiquement à ce réseau</translation> ++<translation id="4807098396393229769">Titulaire de la carte</translation> ++<translation id="4094130554533891764">Elle peut désormais accéder à :</translation> ++<translation id="4131410914670010031">Noir et blanc</translation> ++<translation id="3800503346337426623">Ignorer la connexion et naviguer en tant qu'invité</translation> ++<translation id="2615413226240911668">Toutefois, cette page inclut d'autres ressources qui ne sont pas sécurisées. Ces ressources peuvent être consultées par des tiers pendant leur transfert, et modifiées par un pirate informatique dans le but de changer l'aspect et le comportement de cette page.</translation> ++<translation id="5880867612172997051">Accès réseau interrompu</translation> ++<translation id="7842346819602959665">La dernière version de l'extension "<ph name="EXTENSION_NAME"/>" requiert d'autres permissions. Elle a donc été désactivée.</translation> ++<translation id="3776667127601582921">Dans ce cas, le certificat du serveur ou un certificat d'autorité intermédiaire présenté à votre navigateur n'est pas valide. Cela peut signifier que le certificat est incorrect, qu'il contient des champs non valides ou qu'il n'est pas compatible.</translation> ++<translation id="2412835451908901523">Veuillez saisir la clé de déverrouillage du code PIN à 8 chiffres fournie par <ph name="CARRIER_ID"/>.</translation> ++<translation id="6979448128170032817">Exceptions...</translation> ++<translation id="7584802760054545466">Connexion à <ph name="NETWORK_ID"/></translation> ++<translation id="208047771235602537">Voulez-vous vraiment quitter <ph name="PRODUCT_NAME"/> alors qu'un téléchargement est en cours ?</translation> ++<translation id="4060383410180771901">Le site Web ne parvient pas à gérer la demande associée à <ph name="URL"/>.</translation> ++<translation id="6710213216561001401">Précédent</translation> ++<translation id="1108600514891325577">&Arrêter</translation> ++<translation id="6035087343161522833">Lorsque l'option permettant de bloquer l'enregistrement des cookies tiers est activée, la lecture de ces cookies est également bloquée.</translation> ++<translation id="8619892228487928601"><ph name="CERTIFICATE_NAME"/> : <ph name="ERROR"/></translation> ++<translation id="1567993339577891801">Console JavaScript</translation> ++<translation id="1548132948283577726">Les sites pour lesquels vos mots de passe ne seront jamais enregistrés s'afficheront ici.</translation> ++<translation id="583281660410589416">Inconnu</translation> ++<translation id="3774278775728862009">Mode de saisie du thaï (clavier TIS-820.2538)</translation> ++<translation id="9115675100829699941">&Favoris</translation> ++<translation id="2485422356828889247">Désinstaller</translation> ++<translation id="2621889926470140926">Voulez-vous vraiment quitter <ph name="PRODUCT_NAME"/> alors que <ph name="DOWNLOAD_COUNT"/> téléchargements sont en cours ?</translation> ++<translation id="7279701417129455881">Configurer le blocage des cookies...</translation> ++<translation id="1166359541137214543">ABC</translation> ++<translation id="5412713837047574330">L'application hébergée par <ph name="HOST_NAME"/> est inaccessible, car vous êtes déconnecté du réseau. Cette page s'affichera dès que la connexion réseau sera rétablie. <br></translation> ++<translation id="5528368756083817449">Gestionnaire de favoris</translation> ++<translation id="7275974018215686543"><ph name="NUMBER_MANY"/> secs ago</translation> ++<translation id="215753907730220065">Quitter le mode plein écran</translation> ++<translation id="7849264908733290972">Ouvrir l'&image dans un nouvel onglet</translation> ++<translation id="1560991001553749272">Favori ajouté !</translation> ++<translation id="3966072572894326936">Choisir un autre dossier...</translation> ++<translation id="8766796754185931010">Kotoeri</translation> ++<translation id="7781829728241885113">Hier</translation> ++<translation id="2762402405578816341">Synchroniser automatiquement les éléments suivants :</translation> ++<translation id="1623661092385839831">Votre ordinateur intègre un périphérique de sécurité TPM (module de plate-forme sécurisée) qui permet de mettre en œuvre plusieurs fonctionnalités de sécurité critiques dans Google Chrome OS.</translation> ++<translation id="3359256513598016054">Contraintes des stratégies de certificat</translation> ++<translation id="4433914671537236274">Créer un support de récupération</translation> ++<translation id="4509345063551561634">Emplacement :</translation> ++<translation id="7596288230018319236">Toutes les pages que vous consultez apparaîtront ici à moins que vous ne les ouvriez dans une fenêtre en navigation privée. Vous pouvez utiliser le bouton Rechercher de cette page pour rechercher dans toutes les pages de votre historique.</translation> ++<translation id="7434509671034404296">Options pour les développeurs</translation> ++<translation id="6447842834002726250">Cookies</translation> ++<translation id="2609371827041010694">Toujours exécuter pour ce site</translation> ++<translation id="5170568018924773124">Afficher le dossier</translation> ++<translation id="883848425547221593">Autres favoris</translation> ++<translation id="6054173164583630569">Clavier français</translation> ++<translation id="4870177177395420201"><ph name="PRODUCT_NAME"/> ne parvient pas à déterminer ou à définir le navigateur par défaut.</translation> ++<translation id="8898786835233784856">Sélectionner l'onglet suivant</translation> ++<translation id="2674170444375937751">Voulez-vous vraiment supprimer ces pages de votre historique ?</translation> ++<translation id="9111102763498581341">Déverrouiller</translation> ++<translation id="289695669188700754">ID de clé : <ph name="KEY_ID"/></translation> ++<translation id="3067198360141518313">Exécuter ce plug-in</translation> ++<translation id="8767072502252310690">Utilisateurs</translation> ++<translation id="683526731807555621">Ajouter un moteur</translation> ++<translation id="6871644448911473373">Répondeur OCSP : <ph name="LOCATION"/></translation> ++<translation id="8281886186245836920">Ignorer</translation> ++<translation id="3867944738977021751">Champs de certificat</translation> ++<translation id="2114224913786726438">Modules (<ph name="TOTAL_COUNT"/>) : aucun conflit détecté.</translation> ++<translation id="7629827748548208700">Onglet : <ph name="TAB_NAME"/></translation> ++<translation id="388442998277590542">Impossible de charger la page d'options "<ph name="OPTIONS_PAGE"/>".</translation> ++<translation id="8449008133205184768">Coller en adaptant le style</translation> ++<translation id="9114223350847410618">Veuillez ajouter une autre langue avant de supprimer celle-ci.</translation> ++<translation id="4408427661507229495">nom du réseau</translation> ++<translation id="8886960478266132308"><ph name="PRODUCT_NAME"/> synchronise de manière sécurisée vos données avec votre compte Google.</translation> ++<translation id="8028993641010258682">Taille</translation> ++<translation id="5031603669928715570">Activer...</translation> ++<translation id="1383876407941801731">Recherche</translation> ++<translation id="8398877366907290961">Poursuivre quand même</translation> ++<translation id="5063180925553000800">Nouveau code PIN :</translation> ++<translation id="2496540304887968742">La capacité du périphérique doit être d'au moins 4 Go.</translation> ++<translation id="6974053822202609517">De droite à gauche</translation> ++<translation id="2370882663124746154">Activer le mode Pinyin double</translation> ++<translation id="5463856536939868464">Menu contenant des favoris masqués</translation> ++<translation id="8286227656784970313">Utiliser le dictionnaire système</translation> ++<translation id="5431084084184068621">Vous avez choisi de chiffrer les données à l'aide de votre mot de passe Google. Vous pouvez modifier vos paramètres de synchronisation à tout moment, si vous changez d'avis.</translation> ++<translation id="1493263392339817010">Personnaliser les polices...</translation> ++<translation id="5352033265844765294">Enregistrement des informations de date</translation> ++<translation id="6449085810994685586">&Vérifier l'orthographe du texte de ce champ</translation> ++<translation id="3621320549246006887">Ceci est un modèle expérimental qui permet aux enregistrements DNS (utilisant le protocole de sécurité DNSSEC) d'autoriser ou de refuser des certificats HTTPS. Ce message s'affiche lorsque vous activez des fonctionnalités expérimentales via des options de ligne de commande. Vous pouvez supprimer ces options de ligne de commande pour ignorer cette erreur.</translation> ++<translation id="50960180632766478"><ph name="NUMBER_FEW"/> minutes restantes</translation> ++<translation id="3174168572213147020">Île</translation> ++<translation id="748138892655239008">Contraintes de base du certificat</translation> ++<translation id="457386861538956877">Autres...</translation> ++<translation id="8063491445163840780">Activer l'onglet 4</translation> ++<translation id="5966654788342289517">Données personnelles</translation> ++<translation id="9137013805542155359">Afficher l'original</translation> ++<translation id="4792385443586519711">Nom de la société</translation> ++<translation id="6423731501149634044">Définir Adobe Reader comme visionneuse de documents PDF par défaut ?</translation> ++<translation id="8839907368860424444">Pour gérer les extensions installées, cliquez sur Extensions dans le menu Fenêtre.</translation> ++<translation id="2461687051570989462">Accédez à vos imprimantes depuis n'importe quel ordinateur ou smartphone. <ph name="BEGIN_LINK"/>En savoir plus<ph name="END_LINK"/></translation> ++<translation id="7194430665029924274">Me &le rappeler plus tard</translation> ++<translation id="5790085346892983794">Opération réussie !</translation> ++<translation id="1901769927849168791">Carte SD détectée.</translation> ++<translation id="818454486170715660"><ph name="NAME"/> - Propriétaire</translation> ++<translation id="1358032944105037487">Clavier japonais</translation> ++<translation id="8201956630388867069">WPA</translation> ++<translation id="603890000178803545">janv.^févr.^mars^avr.^mai^juin^juil.^août^sept.^oct.^nov.^déc.</translation> ++<translation id="8302838426652833913">Sélectionnez ++ <ph name="BEGIN_BOLD"/> ++ Applications > Préférences système > Réseau > Assistant ++ <ph name="END_BOLD"/> ++ pour tester votre connexion.</translation> ++<translation id="8664389313780386848">&Afficher le code source de la page</translation> ++<translation id="8970407809569722516">Micrologiciel :</translation> ++<translation id="1180549724812639004">Créer un profil</translation> ++<translation id="57646104491463491">Date de modification</translation> ++<translation id="5992752872167177798">Sandbox seccomp</translation> ++<translation id="6362853299801475928">Signale&r un problème...</translation> ++<translation id="3289566588497100676">Entrée de symboles simplifiée</translation> ++<translation id="6507969014813375884">Chinois simplifié</translation> ++<translation id="7314244761674113881">Hôte SOCKS</translation> ++<translation id="5285794783728826432">Considérer ce certificat comme fiable pour identifier les sites Web.</translation> ++<translation id="4224803122026931301">Exceptions de localisation</translation> ++<translation id="749452993132003881">Hiragana</translation> ++<translation id="8226742006292257240">Le mot de passe TPM ci-dessous, généré de façon aléatoire, a été attribué à votre ordinateur :</translation> ++<translation id="8487693399751278191">Importer mes favoris maintenant...</translation> ++<translation id="7985242821674907985"><ph name="PRODUCT_NAME"/></translation> ++<translation id="7484580869648358686">Avertissement : Un problème a été détecté sur cette page.</translation> ++<translation id="2074739700630368799">Avec Google Chrome OS for business, vous pouvez connecter votre périphérique à Google Apps, ce qui vous permet de le rechercher et de le contrôler depuis le panneau de configuration de Google Apps.</translation> ++<translation id="4474155171896946103">Ajouter tous les onglets aux favoris...</translation> ++<translation id="5895187275912066135">Émis le</translation> ++<translation id="1190844492833803334">Lorsque je ferme le navigateur</translation> ++<translation id="5646376287012673985">Localisation</translation> ++<translation id="1110155001042129815">Attendre</translation> ++<translation id="2607101320794533334">Infos sur la clé publique de l'objet</translation> ++<translation id="7071586181848220801">Plug-in inconnu</translation> ++<translation id="3354601307791487577">Connexion en mode invité</translation> ++<translation id="4419409365248380979">Toujours autoriser <ph name="HOST"/> à paramétrer les cookies</translation> ++<translation id="2956070106555335453">Résumé</translation> ++<translation id="917450738466192189">Le certificat du serveur n'est pas valide.</translation> ++<translation id="2649045351178520408">Chaîne de certificats codés Base 64 ASCII</translation> ++<translation id="7424526482660971538">Choisir mon propre mot de passe multiterme</translation> ++<translation id="380271916710942399">Certificat de serveur non répertorié</translation> ++<translation id="6459488832681039634">Rechercher la sélection</translation> ++<translation id="2392369802118427583">Activer</translation> ++<translation id="9040421302519041149">L'accès à ce réseau est protégé.</translation> ++<translation id="5659593005791499971">E-mail</translation> ++<translation id="8235325155053717782">Erreur <ph name="ERROR_NUMBER"/> (<ph name="ERROR_NAME"/>) : <ph name="ERROR_TEXT"/></translation> ++<translation id="6584878029876017575">Signature permanente Microsoft</translation> ++<translation id="562901740552630300">Sélectionnez ++ <ph name="BEGIN_BOLD"/> ++ Démarrer > Panneau de configuration > Réseau et Internet > Centre Réseau et partage > Résolution des problèmes (en bas) > Connexions Internet. ++ <ph name="END_BOLD"/></translation> ++<translation id="8816996941061600321">Gestionnaire de &fichiers</translation> ++<translation id="2773223079752808209">Service client</translation> ++<translation id="4585473702689066695">Impossible de se connecter au réseau "<ph name="NAME"/>".</translation> ++<translation id="4647175434312795566">J'accepte ces termes</translation> ++<translation id="1084824384139382525">Copier l'adr&esse du lien</translation> ++<translation id="1221462285898798023">Veuillez démarrer <ph name="PRODUCT_NAME"/> en tant qu'utilisateur normal. Pour l'exécuter en tant que root, vous devez indiquer un autre répertoire de données utilisateur pour stocker les informations du profil.</translation> ++<translation id="3220586366024592812">Le processus du connecteur <ph name="CLOUD_PRINT_NAME"/> est bloqué. Voulez-vous le redémarrer ?</translation> ++<translation id="5042992464904238023">Contenu Web</translation> ++<translation id="6254503684448816922">Clé compromise</translation> ++<translation id="1181037720776840403">Supprimer</translation> ++<translation id="4006726980536015530">Si vous fermez <ph name="PRODUCT_NAME"/> maintenant, ces téléchargements seront annulés.</translation> ++<translation id="4194415033234465088">Dachen 26</translation> ++<translation id="1664712100580477121">Voulez-vous vraiment graver l'image sur le périphérique suivant :</translation> ++<translation id="6639554308659482635">Mémoire SQLite</translation> ++<translation id="8141503649579618569"><ph name="DOWNLOAD_RECEIVED"/>/<ph name="DOWNLOAD_TOTAL"/>, <ph name="TIME_LEFT"/></translation> ++<translation id="7650701856438921772"><ph name="PRODUCT_NAME"/> est affiché dans cette langue.</translation> ++<translation id="740624631517654988">Fenêtre pop-up bloquée</translation> ++<translation id="3738924763801731196"><ph name="OID"/> :</translation> ++<translation id="6550769511678490130">Ouvrir tous les favoris</translation> ++<translation id="1847961471583915783">Effacer les cookies et autres données de site et de plug-in lorsque je ferme le navigateur</translation> ++<translation id="8870318296973696995">Page d'accueil</translation> ++<translation id="6659594942844771486">Onglet</translation> ++<translation id="6575134580692778371">Non configuré</translation> ++<translation id="4624768044135598934">Opération réussie !</translation> ++<translation id="6014776969142880350">Relancez <ph name="PRODUCT_NAME"/> pour terminer la mise à jour.</translation> ++<translation id="5582768900447355629">Chiffrer toutes mes données</translation> ++<translation id="6122365914076864562">Veuillez patienter pendant que nous configurons votre réseau pour mobile.</translation> ++<translation id="1974043046396539880">Points de distribution de listes de révocation des certificats</translation> ++<translation id="7049357003967926684">Association</translation> ++<translation id="8641392906089904981">Appuyez sur Maj+Alt pour changer la disposition du clavier.</translation> ++<translation id="3024374909719388945">Utiliser l'horloge au format 24 heures</translation> ++<translation id="1867780286110144690"><ph name="PRODUCT_NAME"/> est prêt à terminer l'installation.</translation> ++<translation id="5316814419223884568">Lancez votre recherche à partir d'ici</translation> ++<translation id="8142732521333266922">OK, synchroniser tout</translation> ++<translation id="965674096648379287">Afin d'être correctement affichée, cette page requiert des données que vous avez précédemment entrées. Vous pouvez de nouveau transmettre ces données, mais, en procédant ainsi, vous devrez répéter chaque action que cette page a effectuée auparavant. Cliquez sur Rafraîchir pour transmettre de nouveau ces données et pour afficher cette page.</translation> ++<translation id="43742617823094120">Cela signifie que le certificat présenté à votre navigateur a été révoqué par son émetteur. L'intégrité de ce certificat a certainement été compromise, et il ne doit donc pas être approuvé. Ne poursuivez pas.</translation> ++<translation id="9019654278847959325">Clavier slovaque</translation> ++<translation id="18139523105317219">Nom de partie EDI</translation> ++<translation id="6657193944556309583">Vous avez déjà chiffré des données avec un mot de passe multiterme. Saisissez-le ci-dessous.</translation> ++<translation id="3328801116991980348">Informations sur le site</translation> ++<translation id="1205605488412590044">Créer un raccourci vers l'application...</translation> ++<translation id="2065985942032347596">Authentification requise</translation> ++<translation id="2553340429761841190"><ph name="PRODUCT_NAME"/> n'est pas parvenu à se connecter à <ph name="NETWORK_ID"/>. Sélectionnez un autre réseau ou réessayez.</translation> ++<translation id="2086712242472027775">Votre compte n'est pas compatible avec <ph name="PRODUCT_NAME"/>. Contactez l'administrateur de votre domaine ou utilisez un compte Google standard pour vous connecter.</translation> ++<translation id="7222232353993864120">Adresse e-mail</translation> ++<translation id="2128531968068887769">Client natif</translation> ++<translation id="7175353351958621980">Chargé depuis :</translation> ++<translation id="4590074117005971373">Active les balises canvas hautes performances dans un contexte 2D, pour effectuer le rendu via le processeur graphique.</translation> ++<translation id="7186367841673660872">Cette page en<ph name="ORIGINAL_LANGUAGE"/>a été traduite en<ph name="LANGUAGE_LANGUAGE"/></translation> ++<translation id="8448695406146523553">Seule une personne en possession de votre mot de passe multiterme peut lire vos données chiffrées. Google ne reçoit ni n'enregistre votre mot de passe multiterme. Si vous oubliez votre mot de passe multiterme, vous devrez</translation> ++<translation id="6052976518993719690">Autorité de certification SSL</translation> ++<translation id="1636959874332483835"><ph name="HOST_NAME"/> contient un logiciel malveillant. Votre ordinateur pourrait être infecté par un virus si vous consultez ce site.</translation> ++<translation id="8050783156231782848">Aucune donnée disponible.</translation> ++<translation id="1175364870820465910">Im&primer...</translation> ++<translation id="3866249974567520381">Description</translation> ++<translation id="2900139581179749587">Voix non reconnue.</translation> ++<translation id="953692523250483872">Aucun fichier sélectionné</translation> ++<translation id="2294358108254308676">Souhaitez-vous installer <ph name="PRODUCT_NAME"/> ?</translation> ++<translation id="6549689063733911810">Activité récente</translation> ++<translation id="1529968269513889022">de la dernière semaine</translation> ++<translation id="5542132724887566711">Profil</translation> ++<translation id="5196117515621749903">Actualiser sans utiliser le cache</translation> ++<translation id="5552632479093547648">Logiciels malveillants et sites de phishing détectés !</translation> ++<translation id="4310537301481716192">Onglet fermé !</translation> ++<translation id="4988273303304146523">il y a <ph name="NUMBER_DEFAULT"/> jours</translation> ++<translation id="8428213095426709021">Paramètres</translation> ++<translation id="1588343679702972132">Ce site exige que vous vous identifiiez avec un certificat :</translation> ++<translation id="7211994749225247711">Supprimer...</translation> ++<translation id="2819994928625218237">&Aucune suggestion orthographique</translation> ++<translation id="1065449928621190041">Clavier franco-canadien</translation> ++<translation id="8327626790128680264">Clavier étendu américain</translation> ++<translation id="2950186680359523359">Le serveur a mis fin à la connexion sans envoyer de données.</translation> ++<translation id="9142623379911037913">Autoriser <ph name="SITE"/> à afficher des notifications sur le Bureau ?</translation> ++<translation id="4196320913210960460">Pour gérer les extensions installées, cliquez sur Extensions dans le menu Outils.</translation> ++<translation id="3449494395612243720">Erreur de synchronisation, veuillez vous connecter à nouveau.</translation> ++<translation id="9118804773997839291">La liste suivante fait état des éléments dangereux détectés sur la page. Cliquez sur le lien "Diagnostic" pour obtenir plus d'informations sur un élément particulier.</translation> ++<translation id="7139724024395191329">Émirat</translation> ++<translation id="1761265592227862828">Synchroniser tous les paramètres et toutes les données\n(peut prendre un certain temps)</translation> ++<translation id="7754704193130578113">Toujours demander où enregistrer les fichiers</translation> ++<translation id="204914487372604757">Créer un raccourci</translation> ++<translation id="2497284189126895209">Tous les fichiers</translation> ++<translation id="696036063053180184">Sebeol-sik No-shift</translation> ++<translation id="452785312504541111">Anglais (pleine chasse)</translation> ++<translation id="945332329539165145">2D avec canvas et accélération matérielle</translation> ++<translation id="5220797120063118010">Cette fonctionnalité autorise l'installation d'applications Google Chrome déployées à partir d'un manifeste situé sur une page Web, plutôt qu'avec un fichier crx contenant le manifeste et les icônes.</translation> ++<translation id="9148126808321036104">Nouvelle connexion</translation> ++<translation id="2282146716419988068">GPU</translation> ++<translation id="428771275901304970">Moins de 1 Mo disponible</translation> ++<translation id="1682548588986054654">Nouvelle fenêtre de navigation privée</translation> ++<translation id="6833901631330113163">Europe du Sud</translation> ++<translation id="8691262314411702087">Sélectionner les éléments à synchroniser</translation> ++<translation id="6065289257230303064">Attributs du répertoire de l'objet du certificat</translation> ++<translation id="2423017480076849397">Accédez à vos imprimantes et partagez-les en ligne via <ph name="CLOUD_PRINT_NAME"/>.</translation> ++<translation id="569520194956422927">&Ajouter...</translation> ++<translation id="4018133169783460046">Afficher <ph name="PRODUCT_NAME"/> dans cette langue</translation> ++<translation id="5110450810124758964">il y a <ph name="NUMBER_ONE"/> jour</translation> ++<translation id="3264544094376351444">Police Sans-Serif</translation> ++<translation id="5586942249556966598">Ne rien faire</translation> ++<translation id="2820806154655529776"><ph name="NUMBER_ONE"/> seconde</translation> ++<translation id="1077946062898560804">Configurer les mises à jour automatiques pour tous les utilisateurs</translation> ++<translation id="3122496702278727796">Échec de la création du répertoire des données</translation> ++<translation id="4517036173149081027">Fermer et annuler le chargement</translation> ++<translation id="7150146631451105528"><ph name="DATE"/></translation> ++<translation id="3166547286524371413">Adresse :</translation> ++<translation id="4522570452068850558">Détails</translation> ++<translation id="59659456909144943">Notification : <ph name="NOTIFICATION_NAME"/></translation> ++<translation id="6731320427842222405">Cette opération peut prendre quelques minutes.</translation> ++<translation id="4806525999832945986">Géré par <ph name="DOMAIN"/> (<ph name="STATUS"/>)</translation> ++<translation id="7503191893372251637">Type de certificat Netscape</translation> ++<translation id="1502960562739459116">Impossible d'afficher certaines parties de ce document PDF. Souhaitez-vous installer Adobe Reader ?</translation> ++<translation id="4135450933899346655">Vos certificats</translation> ++<translation id="4731578803613910821">Vos données personnelles sur <ph name="WEBSITE_1"/>, <ph name="WEBSITE_2"/> et <ph name="WEBSITE_3"/></translation> ++<translation id="7716781361494605745">URL de stratégie de l'autorité de certification Netscape</translation> ++<translation id="2881966438216424900">Dernier accès :</translation> ++<translation id="7552203043556919163">Synchroniser les mots de passe</translation> ++<translation id="630065524203833229">&Quitter</translation> ++<translation id="4647090755847581616">&Fermer l'onglet</translation> ++<translation id="2649204054376361687"><ph name="CITY"/>, <ph name="COUNTRY"/></translation> ++<translation id="7886758531743562066">Le site Web à l'adresse <ph name="HOST_NAME"/> contient des éléments provenant de sites qui semblent héberger des logiciels malveillants. Ces derniers peuvent nuire à votre ordinateur ou agir à votre insu. Le simple fait de visiter un site hébergeant ce type de logiciels peut infecter votre ordinateur.</translation> ++<translation id="2064746092913005102">Total : <ph name="NUMBER_OF_PAGES"/> <ph name="PAGE_OR_PAGES_LABEL"/> <ph name="TWO_SIDED"/> <ph name="TIMES"/> <ph name="NUMBER_OF_COPIES"/> <ph name="COPIES_LABEL"/> <ph name="EQUAL_SIGN"/> <ph name="NUMBER_OF_SHEETS"/> <ph name="SHEETS_LABEL"/></translation> ++<translation id="7538227655922918841">Les cookies de plusieurs sites ont été autorisés pour la session uniquement.</translation> ++<translation id="2385700042425247848">Nom du service :</translation> ++<translation id="7751005832163144684">Imprimer une page de test</translation> ++<translation id="3638865692466101147">Aperçu avant impression - <ph name="PREVIEW_TAB_TITLE"/></translation> ++<translation id="1471300011765310414"><ph name="PRODUCT_NAME"/> ++ ne peut pas à afficher la page Web, car votre ordinateur n'est pas connecté à Internet.</translation> ++<translation id="5464632865477611176">Exécuter cette fois</translation> ++<translation id="4268025649754414643">Chiffrement de la clé</translation> ++<translation id="7925247922861151263">Échec de la vérification AAA</translation> ++<translation id="1168020859489941584">Ouverture dans <ph name="TIME_REMAINING"/>...</translation> ++<translation id="7814458197256864873">&Copier</translation> ++<translation id="8186706823560132848">Logiciel</translation> ++<translation id="4692623383562244444">Moteurs de recherche</translation> ++<translation id="567760371929988174">&Méthodes d'entrée</translation> ++<translation id="10614374240317010">Jamais enregistrés</translation> ++<translation id="5116300307302421503">Impossible d'analyser le fichier.</translation> ++<translation id="2745080116229976798">Subordination qualifiée Microsoft</translation> ++<translation id="2526590354069164005">Bureau</translation> ++<translation id="7983301409776629893">Toujours traduire en <ph name="TARGET_LANGUAGE"/> les pages en <ph name="ORIGINAL_LANGUAGE"/></translation> ++<translation id="4890284164788142455">Thaï</translation> ++<translation id="4312207540304900419">Activer l'onglet suivant</translation> ++<translation id="8456362689280298700"><ph name="HOUR"/>:<ph name="MINUTE"/> de chargement</translation> ++<translation id="7648048654005891115">Style de mappage du clavier</translation> ++<translation id="539295039523818097">Un problème lié à votre microphone s'est produit.</translation> ++<translation id="4033319557821527966"><ph name="CLOUD_PRINT_NAME"/> vous permet d'accéder aux imprimantes de cet ordinateur, où que vous soyez. Connectez-vous pour l'activer.</translation> ++<translation id="6970216967273061347">District</translation> ++<translation id="4479639480957787382">Ethernet</translation> ++<translation id="6312403991423642364">Erreur de réseau inconnue.</translation> ++<translation id="751377616343077236">Nom du certificat</translation> ++<translation id="7154108546743862496">Plus d'informations</translation> ++<translation id="8637688295594795546">Mise à jour du système disponible. Préparation du téléchargement…</translation> ++<translation id="5167270755190684957">Galerie des thèmes Google Chrome</translation> ++<translation id="8382913212082956454">Copi&er l'adresse e-mail</translation> ++<translation id="7447930227192971403">Activer l'onglet 3</translation> ++<translation id="2903493209154104877">Adresses</translation> ++<translation id="2056143100006548702">Plug-in : <ph name="PLUGIN_NAME"/> (<ph name="PLUGIN_VERSION"/>)</translation> ++<translation id="3479552764303398839">Pas maintenant</translation> ++<translation id="6445051938772793705">Pays</translation> ++<translation id="3251759466064201842"><Ne fait pas partie du certificat></translation> ++<translation id="4229495110203539533">il y a <ph name="NUMBER_ONE"/> seconde</translation> ++<translation id="6410257289063177456">Fichiers image</translation> ++<translation id="6419902127459849040">Europe centrale</translation> ++<translation id="6707389671160270963">Certificat client SSL</translation> ++<translation id="6083557600037991373">Pour accélérer l'affichage des pages Web, ++ <ph name="PRODUCT_NAME"/> ++ enregistre temporairement les fichiers téléchargés sur le disque. Si ++ <ph name="PRODUCT_NAME"/> ++ ne s'arrête pas correctement, ces fichiers peuvent être endommagés, ce qui ++ génère cette erreur. L'actualisation de la page devrait permettre de résoudre ++ ce problème ; celui-ci ne se reproduira vraisemblablement plus si l'arrêt s'effectue ++ correctement. ++ <ph name="LINE_BREAK"/> ++ Si le problème persiste, essayez de supprimer le contenu du cache. Cette ++ erreur peut aussi indiquer que le matériel est sur le point de tomber ++ en panne.</translation> ++<translation id="5298219193514155779">Thème créé par</translation> ++<translation id="7366909168761621528">Données de navigation</translation> ++<translation id="1047726139967079566">Ajouter cette page aux favoris</translation> ++<translation id="9020142588544155172">Le serveur a refusé la connexion.</translation> ++<translation id="6113225828180044308">Module (<ph name="MODULUS_NUM_BITS"/> bits) :\n<ph name="MODULUS_HEX_DUMP"/>\n\nExposant public (<ph name="PUBLIC_EXPONENT_NUM_BITS"/> bits) :\n<ph name="EXPONENT_HEX_DUMP"/></translation> ++<translation id="2544782972264605588"><ph name="NUMBER_DEFAULT"/> secondes restantes</translation> ++<translation id="8871696467337989339">Vous utilisez un indicateur de ligne de commande non pris en charge : <ph name="BAD_FLAG"/>. La stabilité et la sécurité en seront affectées.</translation> ++<translation id="4767443964295394154">Emplacement de téléchargement</translation> ++<translation id="5031870354684148875">À propos de Google Traduction</translation> ++<translation id="720658115504386855">Les lettres ne sont pas sensibles à la casse.</translation> ++<translation id="2454247629720664989">Mot clé</translation> ++<translation id="3950820424414687140">Connexion</translation> ++<translation id="4626106357471783850">Redémarrez <ph name="PRODUCT_NAME"/> pour appliquer la mise à jour.</translation> ++<translation id="1697068104427956555">Sélectionner un carré dans l'image</translation> ++<translation id="2840798130349147766">Bases de données Web</translation> ++<translation id="1628736721748648976">Codage</translation> ++<translation id="1198271701881992799">Mise en route</translation> ++<translation id="782590969421016895">Utiliser les pages actuelles</translation> ++<translation id="6521850982405273806">Signaler une erreur</translation> ++<translation id="736515969993332243">Recherche de réseaux en cours</translation> ++<translation id="8026334261755873520">Effacer les données de navigation</translation> ++<translation id="1769104665586091481">Ouvrir le lien dans une nouvelle &fenêtre</translation> ++<translation id="8503813439785031346">Nom d'utilisateur</translation> ++<translation id="5319782540886810524">Clavier letton</translation> ++<translation id="8651585100578802546">Forcer l'actualisation de cette page</translation> ++<translation id="685714579710025096">Disposition du clavier :</translation> ++<translation id="1361655923249334273">Non utilisé</translation> ++<translation id="290555789621781773"><ph name="NUMBER_TWO"/> minutes</translation> ++<translation id="5434065355175441495">Chiffrement RSA PKCS #1</translation> ++<translation id="7073704676847768330">Ce n'est probablement pas le site que vous recherchez !</translation> ++<translation id="8477384620836102176">&Général</translation> ++<translation id="1074663319790387896">Configurer la synchronisation</translation> ++<translation id="4302315780171881488">État de connexion :</translation> ++<translation id="3391392691301057522">Ancien code PIN :</translation> ++<translation id="1344519653668879001">Désactiver le contrôle des liens hypertexte</translation> ++<translation id="6463795194797719782">&Modifier</translation> ++<translation id="4262113024799883061">Chinois</translation> ++<translation id="4775879719735953715">Navigateur par défaut</translation> ++<translation id="5575473780076478375">Extension en mode navigation privée :<ph name="EXTENSION_NAME"/></translation> ++<translation id="4188026131102273494">Mot clé :</translation> ++<translation id="2930644991850369934">Un problème est survenu lors du téléchargement de l'image de récupération. La connexion réseau a été perdue.</translation> ++<translation id="3461610253915486539">Votre administrateur a désactivé certaines préférences.</translation> ++<translation id="5750053751252005701">Forfait de données <ph name="NETWORK"/> épuisé</translation> ++<translation id="8858939932848080433">Veuillez indiquer à quel niveau vous rencontrez des problèmes avant d'envoyer vos commentaires.</translation> ++<translation id="1720318856472900922">Authentification du serveur WWW TLS</translation> ++<translation id="8550022383519221471">Le service de synchronisation n'est pas disponible pour votre domaine.</translation> ++<translation id="3355823806454867987">Modifier les paramètres du proxy...</translation> ++<translation id="4780374166989101364">Cette fonctionnalité active les API des extensions expérimentales. Notez que vous ne pouvez pas mettre en ligne des extensions qui font appel aux API expérimentales dans la galerie d'extensions.</translation> ++<translation id="7227780179130368205">Un logiciel malveillant a été détecté !</translation> ++<translation id="435243347905038008">Forfait de données <ph name="NETWORK"/> presque épuisé</translation> ++<translation id="2489428929217601177">des dernières 24 heures</translation> ++<translation id="7418490403869327287">Une fois activée, la recherche instantanée charge la plupart des pages Web dès que vous saisissez l'URL dans le champ polyvalent, avant même que vous n'appuyiez sur Entrée. Si votre moteur de recherche par défaut est compatible, toute lettre saisie dans ce champ offre de nouveaux résultats et les prédictions intégrées vous guident dans vos recherches.\n\nChaque touche utilisée fait l'objet d'une requête, par conséquent il se peut que les éléments saisies dans le champ polyvalent soient enregistrés par votre moteur de recherche par défaut.\n</translation> ++<translation id="5149131957118398098"><ph name="NUMBER_ZERO"/> hours left</translation> ++<translation id="2541913031883863396">poursuivre quand même</translation> ++<translation id="4278390842282768270">Autorisé</translation> ++<translation id="2074527029802029717">Retirer l'onglet</translation> ++<translation id="1533897085022183721">Moins de <ph name="MINUTES"/></translation> ++<translation id="7503821294401948377">Impossible de charger l'icône "<ph name="ICON"/>" d'action du navigateur.</translation> ++<translation id="5539694491979265537">Consulter Google Dashboard</translation> ++<translation id="3942946088478181888">Plus d'informations</translation> ++<translation id="3722396466546931176">Ajoutez des langues puis faites-les glisser pour les classer dans l'ordre souhaité.</translation> ++<translation id="7396845648024431313"><ph name="APP_NAME"/> sera lancé au démarrage du système et continuera de s'exécuter en arrière-plan, même toutes les fenêtres de <ph name="PRODUCT_NAME"/> sont fermées.</translation> ++<translation id="8539727552378197395">Non (HttpOnly)</translation> ++<translation id="4519351128520996510">Saisir votre mot de passe multiterme pour la synchronisation</translation> ++<translation id="2391419135980381625">Police standard</translation> ++<translation id="7893393459573308604"><ph name="ENGINE_NAME"/> (par défaut)</translation> ++<translation id="5392544185395226057">Cette fonctionnalité active la prise en charge du client natif.</translation> ++<translation id="5400640815024374115">La puce du module de plate-forme sécurisée (TPM) est désactivée ou inexistante.</translation> ++<translation id="2151576029659734873">L'index de l'onglet indiqué est incorrect.</translation> ++<translation id="5150254825601720210">Nom du serveur SSL du certificat Netscape</translation> ++<translation id="6771503742377376720">Est une autorité de certification</translation> ++<translation id="8814190375133053267">Wi-Fi</translation> ++<translation id="2040078585890208937">Connexion à <ph name="NAME"/></translation> ++<translation id="8410619858754994443">Confirmer le mot de passe :</translation> ++<translation id="2210840298541351314">Aperçu avant impression</translation> ++<translation id="3858678421048828670">Clavier italien</translation> ++<translation id="4938277090904056629">Impossible d'établir une connexion sécurisée à cause de l'antivirus ESET.</translation> ++<translation id="4521805507184738876">(expiré)</translation> ++<translation id="111844081046043029">Voulez-vous vraiment quitter cette page ?</translation> ++<translation id="1951615167417147110">Faire défiler d'une page vers le haut</translation> ++<translation id="4154664944169082762">Empreintes</translation> ++<translation id="3202578601642193415">Le plus récent</translation> ++<translation id="8112886015144590373"><ph name="NUMBER_FEW"/> heures</translation> ++<translation id="1398853756734560583">Agrandir</translation> ++<translation id="8988255471271407508">La page Web est introuvable dans le cache. Certaines ressources ne sont restituées fidèlement que si elles sont extraites du cache, notamment les pages générées à partir de données que vous avez envoyées. <ph name="LINE_BREAK"/> Cette erreur peut également être due à un cache endommagé lors d'une fermeture incorrecte. <ph name="LINE_BREAK"/> Si le problème persiste, essayez d'effacer le cache.</translation> ++<translation id="1195977189444203128">Le plug-in <ph name="PLUGIN_NAME"/> n'est plus à jour.</translation> ++<translation id="3878562341724547165">Vous avez changé de position. Souhaitez-vous utiliser <ph name="NEW_GOOGLE_URL"/> ?</translation> ++<translation id="1758018619400202187">EAP-TLS</translation> ++<translation id="6690744523875189208"><ph name="NUMBER_TWO"/> heures</translation> ++<translation id="8053390638574070785">Rafraîchir cette page</translation> ++<translation id="5507756662695126555">Non-répudiation</translation> ++<translation id="3678156199662914018">Extension : <ph name="EXTENSION_NAME"/></translation> ++<translation id="9194519262242876737">Active l'API Web audio.</translation> ++<translation id="3531250013160506608">Zone de saisie de mot de passe</translation> ++<translation id="8314066201485587418">Effacer les cookies et autres données de site lorsque je quitte le navigateur</translation> ++<translation id="4094105377635924481">Ajouter l'option de regroupement au menu contextuel des onglets</translation> ++<translation id="8655295600908251630">Version</translation> ++<translation id="8250690786522693009">Latin</translation> ++<translation id="2119721408814495896">Le connecteur <ph name="CLOUD_PRINT_NAME"/> requiert l'installation du pack Microsoft XML Paper Specification Essentials.</translation> ++<translation id="7624267205732106503">Effacer les cookies et autres données de site lorsque je ferme le navigateur</translation> ++<translation id="8401363965527883709">Case décochée</translation> ++<translation id="7771452384635174008">Mise en page</translation> ++<translation id="6188939051578398125">Saisir un nom ou une adresse</translation> ++<translation id="8443621894987748190">Choix de l'image du compte</translation> ++<translation id="10122177803156699">Me montrer</translation> ++<translation id="5260878308685146029"><ph name="NUMBER_TWO"/> minutes restantes</translation> ++<translation id="2192505247865591433">De :</translation> ++<translation id="238391805422906964">Ouvrir un rapport de phishing</translation> ++<translation id="5921544176073914576">Page de phishing</translation> ++<translation id="3727187387656390258">Inspecter le pop-up</translation> ++<translation id="569068482611873351">Importer...</translation> ++<translation id="6571070086367343653">Modifier la carte de paiement</translation> ++<translation id="1204242529756846967">Cette langue est utilisée pour corriger l'orthographe.</translation> ++<translation id="3981760180856053153">Le type d'enregistrement indiqué est incorrect.</translation> ++<translation id="8464591670878858520">Forfait de données <ph name="NETWORK"/> arrivé à expiration</translation> ++<translation id="4568660204877256194">Exporter mes favoris...</translation> ++<translation id="3116361045094675131">Clavier britannique</translation> ++<translation id="4577070033074325641">Importer des favoris...</translation> ++<translation id="1641504961675316934"><ph name="CLOUD_PRINT_NAME"/></translation> ++<translation id="1715941336038158809">Nom d'utilisateur ou mot de passe incorrect</translation> ++<translation id="1901303067676059328">&Tout sélectionner</translation> ++<translation id="674375294223700098">Erreur inconnue liée au certificat du serveur.</translation> ++<translation id="7780428956635859355">Envoyer une capture d'écran enregistrée</translation> ++<translation id="2850961597638370327">Émis pour : <ph name="NAME"/></translation> ++<translation id="2168039046890040389">Page précédente</translation> ++<translation id="1767519210550978135">Hsu</translation> ++<translation id="2498539833203011245">Réduire</translation> ++<translation id="2893168226686371498">Navigateur par défaut</translation> ++<translation id="2435457462613246316">Afficher le mot de passe</translation> ++<translation id="7988355189918024273">Activer les fonctionnalités d'accessibilité</translation> ++<translation id="5438653034651341183">Inclure la capture d'écran actuelle :</translation> ++<translation id="1899708097738826574"><ph name="OPTIONS_TITLE"/> - <ph name="SUBPAGE_TITLE"/></translation> ++<translation id="1765313842989969521">(cette extension est gérée et ne peut être désinstallée ni désactivée)</translation> ++<translation id="6983783921975806247">OID enregistré</translation> ++<translation id="394984172568887996">Importés depuis IE</translation> ++<translation id="5311260548612583999">Fichier de clé privée (facultatif) :</translation> ++<translation id="2430043402233747791">Autoriser pour la session uniquement</translation> ++<translation id="7363290921156020669"><ph name="NUMBER_ZERO"/> mins</translation> ++<translation id="7568790562536448087">Mise à jour en cours</translation> ++<translation id="4856408283021169561">Aucun microphone trouvé.</translation> ++<translation id="8190193592390505034">Connexion à <ph name="PROVIDER_NAME"/></translation> ++<translation id="6144890426075165477"><ph name="PRODUCT_NAME"/> n'est pas votre navigateur par défaut.</translation> ++<translation id="823241703361685511">Forfait</translation> ++<translation id="4068506536726151626">Cette page contient des éléments des sites ci-dessous qui suivent votre position géographique :</translation> ++<translation id="4721475475128190282">Plusieurs profils</translation> ++<translation id="4220128509585149162">Plantages</translation> ++<translation id="8798099450830957504">Par défaut</translation> ++<translation id="9107059250669762581"><ph name="NUMBER_DEFAULT"/> jours</translation> ++<translation id="1640283014264083726">PKCS #1 MD4 avec chiffrement RSA</translation> ++<translation id="872451400847464257">Modifier le moteur de recherche</translation> ++<translation id="6463061331681402734"><ph name="NUMBER_MANY"/> minutes</translation> ++<translation id="2466804342846034717">Indiquez le mot de passe approprié ci-dessus, puis saisissez les caractères figurant dans l'image ci-dessous.</translation> ++<translation id="3881435075661337013">Expiration de <ph name="NETWORK"/> imminente</translation> ++<translation id="5681833099441553262">Activer l'onglet précédent</translation> ++<translation id="4792057643643237295">Désactiver l'accès à distance</translation> ++<translation id="1681614449735360921">Afficher les incompatibilités</translation> ++<translation id="19094784437781028">Carte de débit Solo</translation> ++<translation id="2657327428424666237"><ph name="BEGIN_LINK"/>Actualisez<ph name="END_LINK"/> cette page Web ultérieurement.</translation> ++<translation id="7347751611463936647">Pour utiliser cette extension, saisissez "<ph name="EXTENSION_KEYWORD"/>", TAB, puis votre commande ou votre recherche.</translation> ++<translation id="659432221160402784"><ph name="PRODUCT_NAME"/> synchronisera les applications installées, afin que vous puissiez y accéder en vous connectant depuis tout navigateur <ph name="PRODUCT_NAME"/>.</translation> ++<translation id="892464165639979917">Langues et paramètres du correcteur orthographique...</translation> ++<translation id="5645845270586517071">Erreur de sécurité</translation> ++<translation id="2805756323405976993">Applications</translation> ++<translation id="3651020361689274926">La ressource demandée n'existe plus et aucune adresse de transfert n'est disponible. Il semble que cet état de fait soit permanent.</translation> ++<translation id="2989786307324390836">Certificat unique binaire codé DER</translation> ++<translation id="3827774300009121996">&Plein écran</translation> ++<translation id="3771294271822695279">Fichiers vidéo</translation> ++<translation id="6704875430222476107"><ph name="PRODUCT_NAME"/> indique que ++ NetNanny intercepte les connexions sécurisées. En général, cela ++ ne constitue pas un problème de sécurité, car le logiciel NetNanny s'exécute souvent ++ sur le même ordinateur. Toutefois, en raison de certaines incompatibilités avec ++ les connexions sécurisées Google Chrome, vous devez configurer NetNanny ++ de manière à éviter ces interceptions. Cliquez sur le lien En savoir plus pour obtenir des instructions.</translation> ++<translation id="3388026114049080752">Vos onglets et activités de navigation</translation> ++<translation id="7525067979554623046">Créer</translation> ++<translation id="4711094779914110278">Turc</translation> ++<translation id="1031460590482534116">Une erreur s'est produite lors de la tentative d'enregistrement du certificat client. Erreur <ph name="ERROR_NUMBER"/> (<ph name="ERROR_NAME"/>)</translation> ++<translation id="7136984461011502314">Bienvenue dans <ph name="PRODUCT_NAME"/></translation> ++<translation id="1594030484168838125">Sélectionner</translation> ++<translation id="204497730941176055">Nom du modèle de certificat Microsoft</translation> ++<translation id="6705264787989366486">Configuration de l'adresse IP pour <ph name="NAME"/></translation> ++<translation id="8970721300630048025">Immortalisez votre plus beau sourire et utilisez la photo comme image de compte.</translation> ++<translation id="4087089424473531098">Extension créée : ++ ++<ph name="EXTENSION_FILE"/></translation> ++<translation id="16620462294541761">Mot de passe incorrect. Veuillez réessayer.</translation> ++<translation id="5017508259293544172">LEAP</translation> ++<translation id="1394630846966197578">Échec de la connexion aux serveurs de reconnaissance vocale.</translation> ++<translation id="2498765460639677199">Très grande</translation> ++<translation id="2378982052244864789">Sélectionner le répertoire de l'extension</translation> ++<translation id="7861215335140947162">&Téléchargements</translation> ++<translation id="4778630024246633221">Gestionnaire des certificats</translation> ++<translation id="6705050455568279082"><ph name="URL"/> souhaite suivre votre position géographique</translation> ++<translation id="4708849949179781599">Quitter <ph name="PRODUCT_NAME"/></translation> ++<translation id="2505402373176859469"><ph name="RECEIVED_AMOUNT"/> sur <ph name="TOTAL_SIZE"/></translation> ++<translation id="6644512095122093795">Proposer d'enregistrer les mots de passe</translation> ++<translation id="4724450788351008910">Modification de l'affiliation</translation> ++<translation id="2249605167705922988">par exemple : 1-5, 8, 11-13</translation> ++<translation id="8691686986795184760">(Activé par une stratégie d'entreprise)</translation> ++<translation id="1911483096198679472">Qu'est-ce que c'est ?</translation> ++<translation id="1976323404609382849">Les cookies de plusieurs sites ont été bloqués.</translation> ++<translation id="2662952950313424742">Serveur DNS spécifié par l'utilisateur et utilisé par Google Chrome, à la place du paramètre système par défaut, pour les résolutions DNS.</translation> ++<translation id="4176463684765177261">Désactivé</translation> ++<translation id="2079545284768500474">Annuler</translation> ++<translation id="114140604515785785">Répertoire racine de l'extension :</translation> ++<translation id="4788968718241181184">Mode de saisie du vietnamien (TCVN6064)</translation> ++<translation id="1512064327686280138">Échec de l'activation</translation> ++<translation id="3254409185687681395">Ajouter cette page aux favoris</translation> ++<translation id="1384616079544830839">L'identité de ce site Web a été vérifiée par <ph name="ISSUER"/>.</translation> ++<translation id="8710160868773349942">Adresse e-mail : <ph name="EMAIL_ADDRESSES"/></translation> ++<translation id="4057991113334098539">Activation...</translation> ++<translation id="9073281213608662541">PAP</translation> ++<translation id="1800035677272595847">Sites de phishing</translation> ++<translation id="8448317557906454022"><ph name="NUMBER_ZERO"/> secs ago</translation> ++<translation id="402759845255257575">Interdire à tous les sites d'exécuter JavaScript</translation> ++<translation id="4610637590575890427">Vouliez-vous accéder à <ph name="SITE"/> ?</translation> ++<translation id="7723779034587221017">La connexion avec le service de configuration a été perdue. Veuillez réinitialiser votre périphérique ou contacter votre représentant de l'assistance technique.</translation> ++<translation id="3046388203776734202">Paramètres des fenêtres pop-up :</translation> ++<translation id="3437994698969764647">Tout exporter...</translation> ++<translation id="8349305172487531364">Barre de favoris</translation> ++<translation id="1898064240243672867">Stocké dans : <ph name="CERT_LOCATION"/></translation> ++<translation id="444134486829715816">Développer...</translation> ++<translation id="1401874662068168819">Gin Yieh</translation> ++<translation id="7208899522964477531">Rechercher <ph name="SEARCH_TERMS"/> sur <ph name="SITE_NAME"/></translation> ++<translation id="6255097610484507482">Modifier la carte de paiement</translation> ++<translation id="5584091888252706332">Au démarrage</translation> ++<translation id="8960795431111723921">Nous examinons actuellement le problème.</translation> ++<translation id="2482878487686419369">Notifications</translation> ++<translation id="8004582292198964060">Navigateur</translation> ++<translation id="695755122858488207">Case d'option décochée</translation> ++<translation id="6357135709975569075"><ph name="NUMBER_ZERO"/> days</translation> ++<translation id="8666678546361132282">Anglais</translation> ++<translation id="2224551243087462610">Modifier le nom du dossier</translation> ++<translation id="1358741672408003399">Grammaire et orthographe</translation> ++<translation id="4910673011243110136">Réseaux privés</translation> ++<translation id="2527167509808613699">Toutes sortes de connexions</translation> ++<translation id="9095710730982563314">Exceptions liées aux notifications</translation> ++<translation id="8072988827236813198">Épingler les onglets</translation> ++<translation id="1234466194727942574">Barre d'onglets</translation> ++<translation id="7974087985088771286">Activer l'onglet 6</translation> ++<translation id="4035758313003622889">Gestionnaire de &tâches</translation> ++<translation id="6356936121715252359">Paramètres de stockage d'Adobe Flash Player...</translation> ++<translation id="5885996401168273077">Connexion au réseau</translation> ++<translation id="7313804056609272439">Mode de saisie du vietnamien (VNI)</translation> ++<translation id="1768211415369530011">L'application suivante va être lancée si vous acceptez cette requête :\n\n<ph name="APPLICATION"/></translation> ++<translation id="8793043992023823866">Importation...</translation> ++<translation id="8106211421800660735">N° de carte</translation> ++<translation id="2550839177807794974">Gérer les moteurs de recherche...</translation> ++<translation id="7031711645186424727">Utiliser un moniteur externe</translation> ++<translation id="6316768948917110108">Gravure de l'image en cours...</translation> ++<translation id="5089810972385038852">État</translation> ++<translation id="2872961005593481000">Éteindre</translation> ++<translation id="8986267729801483565">Enregistrer les fichiers dans le dossier :</translation> ++<translation id="4322394346347055525">Fermer les autres onglets</translation> ++<translation id="4411770745820968260">Répertoire de fichiers</translation> ++<translation id="881799181680267069">Masquer les autres</translation> ++<translation id="1812631533912615985">Annuler l'épinglage des onglets</translation> ++<translation id="6042308850641462728">Plus</translation> ++<translation id="8318945219881683434">Échec de la vérification de la révocation</translation> ++<translation id="1650709179466243265">Ajouter www. et .com, puis ouvrir la page</translation> ++<translation id="3524079319150349823">Pour inspecter un pop-up, cliquez avec le bouton droit sur la page ou sur l'icône d'action du navigateur, puis sélectionnez Inspecter le pop-up.</translation> ++<translation id="994289308992179865">&Répéter</translation> ++<translation id="7793343764764530903"><ph name="CLOUD_PRINT_NAME"/> est à présent activé. <ph name="PRODUCT_NAME"/> a enregistré les imprimantes installées sur cette machine en les associant à <b><ph name="EMAIL_ADDRESSES"/></b>. Vous pouvez désormais utiliser vos imprimantes depuis n'importe quelle application Web ou mobile associée à <ph name="CLOUD_PRINT_NAME"/>.</translation> ++<translation id="1703490097606704369">Le serveur de <ph name="HOST_NAME"/> ++ est introuvable, car la résolution DNS a échoué. DNS est le service Web qui ++ traduit les noms de site Web en adresses Internet. Cette erreur est ++ généralement due à l'absence de connexion Internet ou à une configuration ++ incorrecte du réseau. Cela peut également venir d'un serveur DNS qui ne ++ répond pas ou d'un pare-feu interdisant l'accès de ++ <ph name="PRODUCT_NAME"/> ++ au réseau.</translation> ++<translation id="8887090188469175989">ZGPY</translation> ++<translation id="3302709122321372472">Impossible de charger le fichier css "<ph name="RELATIVE_PATH"/>" du script de contenu.</translation> ++<translation id="305803244554250778">Créer des raccourcis vers des applications aux emplacements suivants :</translation> ++<translation id="574392208103952083">Moyenne</translation> ++<translation id="3745810751851099214">Envoyé pour :</translation> ++<translation id="3937609171782005782">Aider Google à détecter les logiciels malveillants en envoyant des données supplémentaires concernant les sites pour lesquels cet avertissement s'affiche. Ces données seront gérées conformément aux règles définies sur la page <ph name="PRIVACY_PAGE_LINK"/>.</translation> ++<translation id="8877448029301136595">[répertoire parent]</translation> ++<translation id="7301360164412453905">Touches de sélection du clavier Hsu</translation> ++<translation id="8631271110654520730">Copie de l'image de récupération...</translation> ++<translation id="1963227389609234879">Tout supprimer</translation> ++<translation id="7779140087128114262">Seule une personne en possession de votre mot de passe multiterme peut lire vos données chiffrées. Google ne reçoit ni n'enregistre votre mot de passe multiterme. Si vous oubliez votre mot de passe multiterme, vous devrez réinitialiser la synchronisation.</translation> ++<translation id="8027581147000338959">Ouvrir dans une nouvelle fenêtre</translation> ++<translation id="8019305344918958688">Dommage... Aucune extension n'est installée. :-(</translation> ++<translation id="7466861475611330213">Style de ponctuation</translation> ++<translation id="2496180316473517155">Historique de navigation</translation> ++<translation id="602251597322198729">Ce site tente de télécharger plusieurs fichiers. Voulez-vous autoriser le chargement ?</translation> ++<translation id="5843685321177053287">Établissement de la liaison avec le service de gestion des périphériques en attente...</translation> ++<translation id="2052389551707911401"><ph name="NUMBER_MANY"/> heures</translation> ++<translation id="5411472733320185105">Ne pas utiliser les paramètres du proxy pour les hôtes et domaines suivants :</translation> ++<translation id="6691936601825168937">&Avancer</translation> ++<translation id="6566142449942033617">Impossible de charger "<ph name="PLUGIN_PATH"/>" pour le plug-in.</translation> ++<translation id="7065534935986314333">À propos du système</translation> ++<translation id="45025857977132537">Utilisation de la clé du certificat : <ph name="USAGES"/></translation> ++<translation id="6454421252317455908">Mode de saisie du chinois (quick)</translation> ++<translation id="368789413795732264">Une erreur s'est produite lors de la tentative d'écriture du fichier : <ph name="ERROR_TEXT"/>.</translation> ++<translation id="1173894706177603556">Renommer</translation> ++<translation id="5670032673361607750">La synchronisation requiert votre attention.</translation> ++<translation id="2148716181193084225">Aujourd'hui</translation> ++<translation id="1002064594444093641">Imp&rimer le cadre...</translation> ++<translation id="7234674978021619913">Le site <ph name="HOST_NAME"/> a déjà été informé qu'un logiciel malveillant a été détecté sur ses pages. Pour plus d'informations concernant les problèmes rencontrés sur <ph name="HOST_NAME2"/>, consultez notre <ph name="DIAGNOSTIC_PAGE"/> Google.</translation> ++<translation id="8202390211066742724">Adresse de serveur DNS spécifiée par l'utilisateur.</translation> ++<translation id="4608500690299898628">&Rechercher...</translation> ++<translation id="3574305903863751447"><ph name="CITY"/>, <ph name="STATE"/> <ph name="COUNTRY"/></translation> ++<translation id="8724859055372736596">&Afficher dans le dossier</translation> ++<translation id="4605399136610325267">Non connecté à Internet.</translation> ++<translation id="978407797571588532">Sélectionnez ++ <ph name="BEGIN_BOLD"/> ++ Démarrer > Panneau de configuration > Connexions réseau > Assistant Nouvelle connexion ++ <ph name="END_BOLD"/> ++ pour tester votre connexion.</translation> ++<translation id="5554489410841842733">Cette icône s'affiche lorsque l'extension peut agir sur la page active.</translation> ++<translation id="579702532610384533">Reconnexion</translation> ++<translation id="4862642413395066333">Réponses OCSP de signature</translation> ++<translation id="5266113311903163739">Erreur d'importation de l'autorité de certification</translation> ++<translation id="9563164493805065">Gravure de l'image terminée.</translation> ++<translation id="4756388243121344051">&Historique</translation> ++<translation id="3789841737615482174">Installer</translation> ++<translation id="4320697033624943677">Ajouter des utilisateurs</translation> ++<translation id="9153934054460603056">Enregistrer l'authentification et le mot de passe</translation> ++<translation id="1455548678241328678">Clavier norvégien</translation> ++<translation id="2520481907516975884">Basculer en mode chinois/anglais</translation> ++<translation id="8571890674111243710">Traduction de la page en <ph name="LANGUAGE"/>...</translation> ++<translation id="4789872672210757069">À propos de &<ph name="PRODUCT_NAME"/></translation> ++<translation id="4056561919922437609"><ph name="TAB_COUNT"/> onglets</translation> ++<translation id="4373894838514502496">il y a <ph name="NUMBER_FEW"/> minutes</translation> ++<translation id="6358450015545214790">Qu'est-ce que c'est ?</translation> ++<translation id="6264365405983206840">Tout &sélectionner</translation> ++<translation id="1017280919048282932">&Ajouter au dictionnaire</translation> ++<translation id="8319414634934645341">Utilisation étendue de la clé</translation> ++<translation id="4563210852471260509">Le chinois est la langue de saisie initiale</translation> ++<translation id="6897140037006041989">Agent utilisateur</translation> ++<translation id="3413122095806433232">Émetteurs de l'autorité de certification : <ph name="LOCATION"/></translation> ++<translation id="4115153316875436289"><ph name="NUMBER_TWO"/> jours</translation> ++<translation id="701080569351381435">Code source</translation> ++<translation id="3286538390144397061">Redémarrer maintenant</translation> ++<translation id="163309982320328737">La largeur de caractères initiale est Complète</translation> ++<translation id="5107325588313356747">Pour masquer l'accès à ce programme, vous devez le désinstaller au moyen de \n<ph name="CONTROL_PANEL_APPLET_NAME"/> du Panneau de configuration.\n\nSouhaitez-vous exécuter <ph name="CONTROL_PANEL_APPLET_NAME"/> ?</translation> ++<translation id="4841055638263130507">Paramètres du microphone</translation> ++<translation id="6965648386495488594">Port</translation> ++<translation id="7631887513477658702">&Toujours ouvrir les fichiers de ce type</translation> ++<translation id="8627795981664801467">Uniquement les connexions sécurisées</translation> ++<translation id="8680787084697685621">Les informations de connexion au compte sont obsolètes.</translation> ++<translation id="3228969707346345236">La traduction a échoué, car la page est déjà en <ph name="LANGUAGE"/>.</translation> ++<translation id="1873879463550486830">Sandbox SUID</translation> ++<translation id="2190355936436201913">(vide)</translation> ++<translation id="8515737884867295000">Échec de l'authentification basée sur le certificat</translation> ++<translation id="5868426874618963178">Envoyer le code source de la page actuelle</translation> ++<translation id="1269138312169077280">Votre administrateur a désactivé certains paramètres.</translation> ++<translation id="5818003990515275822">Coréen</translation> ++<translation id="4182252350869425879">Avertissement : Il s'agit peut-être d'un site de phishing !</translation> ++<translation id="5458214261780477893">Dvorak</translation> ++<translation id="5353719617589986386">Étendue de pages incorrecte</translation> ++<translation id="1164369517022005061"><ph name="NUMBER_DEFAULT"/> heures restantes</translation> ++<translation id="5943260032016910017">Exceptions liées aux cookies et aux données de site</translation> ++<translation id="2214283295778284209"><ph name="SITE"/> n'est pas accessible</translation> ++<translation id="8755376271068075440">P&lus grand</translation> ++<translation id="8132793192354020517">Connecté à <ph name="NAME"/></translation> ++<translation id="8187473050234053012">Le certificat de sécurité du site a été révoqué !</translation> ++<translation id="7444983668544353857">Désactiver <ph name="NETWORKDEVICE"/></translation> ++<translation id="6003177993629630467"><ph name="PRODUCT_NAME"/> risque de ne pas rester à jour.</translation> ++<translation id="421577943854572179">intégré sur tout autre site</translation> ++<translation id="580886651983547002"><ph name="PRODUCT_NAME"/> ++ ne parvient pas à atteindre le site Web. Cela vient probablement d'un problème de réseau, ++ mais peut également être dû à un pare-feu ou à un serveur proxy mal configuré.</translation> ++<translation id="5445557969380904478">À propos de la reconnaissance vocale</translation> ++<translation id="3093473105505681231">Langues et paramètres du correcteur orthographique...</translation> ++<translation id="152482086482215392"><ph name="NUMBER_ONE"/> seconde restante</translation> ++<translation id="529172024324796256">Nom d'utilisateur :</translation> ++<translation id="3308116878371095290">Le stockage des cookies n'est pas autorisé pour cette page.</translation> ++<translation id="7521387064766892559">JavaScript</translation> ++<translation id="7219179957768738017">La connexion utilise <ph name="SSL_VERSION"/>.</translation> ++<translation id="7014174261166285193">Échec de l'installation</translation> ++<translation id="1970746430676306437">Afficher les &infos sur la page</translation> ++<translation id="3199127022143353223">Serveurs</translation> ++<translation id="2805646850212350655">Système de fichiers de chiffrement Microsoft </translation> ++<translation id="8053959338015477773">Un plug-in supplémentaire est requis pour afficher certains éléments sur cette page.</translation> ++<translation id="3541661933757219855">Appuyez sur Ctrl+Alt+/ ou sur Échap pour masquer</translation> ++<translation id="8813873272012220470">Cette fonctionnalité effectue des vérifications en arrière-plan et vous avertit en cas d'incompatibilité logicielle (modules tiers bloquant le navigateur, par exemple).</translation> ++<translation id="5020734739305654865">Connexion avec</translation> ++<translation id="2679385451463308372">Imprimer depuis la boîte de dialogue système…</translation> ++<translation id="7414887922320653780"><ph name="NUMBER_ONE"/> heure restante</translation> ++<translation id="121632099317611328">Échec de l'initialisation de l'appareil photo</translation> ++<translation id="399179161741278232">Importés</translation> ++<translation id="3829932584934971895">Type de fournisseur :</translation> ++<translation id="462288279674432182">IP restreinte :</translation> ++<translation id="3927932062596804919">Refuser</translation> ++<translation id="3524915994314972210">Démarrage du téléchargement en cours...</translation> ++<translation id="6484929352454160200">Une nouvelle version de <ph name="PRODUCT_NAME"/> est disponible.</translation> ++<translation id="3187212781151025377">Clavier hébreu</translation> ++<translation id="351152300840026870">Police à largeur fixe</translation> ++<translation id="5827266244928330802">Safari</translation> ++<translation id="778881183694837592">Les champs obligatoires ne doivent pas rester vides.</translation> ++<translation id="2371076942591664043">Ouvrir une fois le téléchargement &terminé</translation> ++<translation id="3920504717067627103">Stratégies de certificat</translation> ++<translation id="155865706765934889">Pavé tactile</translation> ++<translation id="7701040980221191251">Aucun</translation> ++<translation id="5917011688104426363">Activer la barre d'adresse en mode recherche</translation> ++<translation id="6910239454641394402">Exceptions pour JavaScript</translation> ++<translation id="2979639724566107830">Ouvrir dans une nouvelle fenêtre</translation> ++<translation id="3269101346657272573">Veuillez saisir le code PIN.</translation> ++<translation id="9204065299849069896">Options de saisie automatique...</translation> ++<translation id="2822854841007275488">Arabe</translation> ++<translation id="5857090052475505287">Nouveau dossier</translation> ++<translation id="7450732239874446337">E/S réseau interrompue</translation> ++<translation id="5178667623289523808">Rechercher le précédent</translation> ++<translation id="2815448242176260024">Ne jamais enregistrer les mots de passe</translation> ++<translation id="2989805286512600854">Ouvrir dans un nouvel onglet</translation> ++<translation id="8687485617085920635">Fenêtre suivante</translation> ++<translation id="4122118036811378575">&Rechercher le suivant</translation> ++<translation id="6008256403891681546">JCB</translation> ++<translation id="2610780100389066815">Signature de liste d'approbation Microsoft</translation> ++<translation id="8289811203643526145">Gérer les certificats...</translation> ++<translation id="2788575669734834343">Sélectionnez le fichier de certificat.</translation> ++<translation id="8404409224170843728">Fabricant :</translation> ++<translation id="8267453826113867474">Bloquer le contenu inapproprié</translation> ++<translation id="7959074893852789871">Le fichier contenait plusieurs certificats, dont certains n'ont pas été importés :</translation> ++<translation id="1213999834285861200">Exceptions pour les images</translation> ++<translation id="2805707493867224476">Autoriser tous les sites à afficher des fenêtres pop-up</translation> ++<translation id="3561217442734750519">Vous devez indiquer un chemin valide comme valeur de clé privée.</translation> ++<translation id="2444609190341826949">Sans mot de passe multiterme, vos mots de passe et autres données chiffrées ne seront pas synchronisés sur cet ordinateur.</translation> ++<translation id="77221669950527621">Extensions ou applications</translation> ++<translation id="6650142020817594541">Ce site recommande Google Chrome Frame (déjà installé).</translation> ++<translation id="6503077044568424649">Les plus visités</translation> ++<translation id="4625904365165566833">Vous n'êtes pas autorisé à vous connecter. Consultez le propriétaire de cet ordinateur portable.</translation> ++<translation id="7450633916678972976">Remarque : Lorsque vous cliquez sur "Envoyer", Google Chrome joint à votre ++ envoi un journal indiquant votre version de Google Chrome et celle du système ++ d'exploitation utilisé, ainsi que l'URL associée à votre rapport. Vous pouvez ++ également joindre une capture d'écran. Ces informations nous ++ permettent de diagnostiquer les problèmes et d'améliorer les performances de ++ Google Chrome. Les informations personnelles fournies sciemment dans vos ++ commentaires ou involontairement dans le journal, l'URL ou la capture ++ d'écran sont protégées conformément à nos règles de ++ confidentialité. Si vous ne souhaitez pas indiquer d'URL et/ou de capture ++ d'écran, décochez les cases "Inclure cette URL" et/ou "Inclure cette capture d'écran". Vous acceptez que Google utilise vos commentaires pour améliorer ses produits ou services.</translation> ++<translation id="465365366590259328">Vos modifications seront prises en compte au prochain démarrage de <ph name="PRODUCT_NAME"/>.</translation> ++<translation id="7168109975831002660">Taille de police minimale</translation> ++<translation id="7070804685954057874">Entrée directe</translation> ++<translation id="3265459715026181080">Fermer la fenêtre</translation> ++<translation id="6074871234879228294">Mode de saisie du japonais (pour clavier japonais)</translation> ++<translation id="7855296476260297092">Inscription réussie</translation> ++<translation id="907841381057066561">Échec de création du fichier zip temporaire lors de la création du pack</translation> ++<translation id="1294298200424241932">Modifier les paramètres de confiance :</translation> ++<translation id="1384617406392001144">Votre historique de navigation</translation> ++<translation id="3831099738707437457">&Masquer le panneau de la vérification orthographique</translation> ++<translation id="1040471547130882189">Plug-in ne répondant pas</translation> ++<translation id="5473075389972733037">IBM</translation> ++<translation id="8307664665247532435">Les paramètres seront effacés lors de la prochaine actualisation.</translation> ++<translation id="790025292736025802"><ph name="URL"/> introuvable</translation> ++<translation id="895347679606913382">Démarrage...</translation> ++<translation id="3319048459796106952">Nouvelle fenêtre de nav&igation privée</translation> ++<translation id="5832669303303483065">Ajouter une adresse postale...</translation> ++<translation id="3127919023693423797">Authentification en cours...</translation> ++<translation id="4195643157523330669">Ouvrir dans un nouvel onglet</translation> ++<translation id="8030169304546394654">Déconnecté</translation> ++<translation id="4010065515774514159">Action du navigateur</translation> ++<translation id="4286563808063000730">Le mot de passe multiterme saisi ne peut pas être utilisé, car vous avez déjà chiffré des données avec un mot de passe multiterme. Entrez ci-dessous le mot de passe multiterme actuellement défini pour la synchronisation.</translation> ++<translation id="1154228249304313899">Ouvrir cette page :</translation> ++<translation id="9074348188580488499">Voulez-vous vraiment supprimer tous les mots de passe ?</translation> ++<translation id="6635491740861629599">Sélectionner par domaine</translation> ++<translation id="3627588569887975815">Ouvrir le lien dans une fenêtre en navi&gation privée</translation> ++<translation id="5851868085455377790">Émetteur</translation> ++<translation id="8223496248037436966">Options de saisie automatique</translation> ++<translation id="1470719357688513792">Les nouveaux paramètres des cookies seront appliqués quand vous aurez actualisé la page.</translation> ++<translation id="5578327870501192725">Votre connexion à <ph name="DOMAIN"/> est sécurisée par un chiffrement <ph name="BIT_COUNT"/> bits.</translation> ++<translation id="869884720829132584">Menu Applications</translation> ++<translation id="7764209408768029281">Outi&ls</translation> ++<translation id="1139892513581762545">Onglets latéraux</translation> ++<translation id="7634357567062076565">Reprendre</translation> ++<translation id="4779083564647765204">Zoom</translation> ++<translation id="3282430104564575032">Inspecteur de DOM</translation> ++<translation id="1526560967942511387">Document sans titre</translation> ++<translation id="1291144580684226670">Police standard</translation> ++<translation id="3979748722126423326">Activer <ph name="NETWORKDEVICE"/></translation> ++<translation id="5538307496474303926">Opération en cours...</translation> ++<translation id="4367133129601245178">C&opier l'URL de l'image</translation> ++<translation id="7542995811387359312">La saisie automatique des numéros de carte de paiement est désactivée, car la connexion utilisée par ce formulaire n'est pas sécurisée.</translation> ++<translation id="3494444535872870968">Enregistrer le &cadre sous...</translation> ++<translation id="987264212798334818">Général</translation> ++<translation id="7005812687360380971">Défaillance</translation> ++<translation id="2356070529366658676">Demander</translation> ++<translation id="5731247495086897348">Coller l'URL et y a&ccéder</translation> ++<translation id="8467548439852845758">Pour plus de sécurité, <ph name="PRODUCT_NAME"/> va chiffrer vos mots de passe.</translation> ++<translation id="2524947000814989347">Si vous avez oublié votre mot de passe multiterme, vous devrez arrêter la synchronisation via Google Dashboard.</translation> ++<translation id="8018154597338652331"><ph name="BURNT_AMOUNT"/> sur <ph name="TOTAL_SIZE"/></translation> ++<translation id="7635741716790924709">Adresse ligne 1</translation> ++<translation id="5135533361271311778">Impossible de créer le favori.</translation> ++<translation id="5271247532544265821">Basculer en mode chinois simplifié/traditionnel</translation> ++<translation id="2052610617971448509">Votre système Sandbox n'est pas correctement configuré.</translation> ++<translation id="7384913436093989340">Sélectionnez le <ph name="BEGIN_BOLD"/>menu clé à molette > Préférences > Options avancées > Modifier les paramètres du proxy<ph name="END_BOLD"/> et vérifiez que vos paramètres sont définis sur "sans proxy" ou "direct".</translation> ++<translation id="6417515091412812850">Impossible de vérifier si le certificat a été révoqué.</translation> ++<translation id="7282743297697561153">Stockage des données</translation> ++<translation id="3363332416643747536"><ph name="DOWNLOAD_RECEIVED"/>/<ph name="DOWNLOAD_TOTAL"/>, Interrompu</translation> ++<translation id="7347702518873971555">Acheter un forfait</translation> ++<translation id="5285267187067365830">Installer le plug-in...</translation> ++<translation id="5334844597069022743">Afficher le code source</translation> ++<translation id="1166212789817575481">Fermer les onglets sur la droite</translation> ++<translation id="6472893788822429178">Afficher le bouton "Accueil"</translation> ++<translation id="4270393598798225102">Version <ph name="NUMBER"/></translation> ++<translation id="534916491091036097">Parenthèse gche</translation> ++<translation id="4157869833395312646">Microsoft Server Gated Cryptography</translation> ++<translation id="8903921497873541725">Zoom avant</translation> ++<translation id="2195729137168608510">Protection du courrier électronique</translation> ++<translation id="1425734930786274278">Les cookies suivants ont été bloqués (tous les cookies tiers sont bloqués, sans exception) :</translation> ++<translation id="6805647936811177813">Connectez-vous à <ph name="TOKEN_NAME"/> pour importer le certificat client de <ph name="HOST_NAME"/></translation> ++<translation id="3437016096396740659">La batterie est chargée.</translation> ++<translation id="6916146760805488559">Créer un nouveau profil...</translation> ++<translation id="1199232041627643649">Maintenez la touche <ph name="KEY_EQUIVALENT"/> enfoncée pour quitter.</translation> ++<translation id="5428562714029661924">Masquer ce plug-in</translation> ++<translation id="7907591526440419938">Ouvrir le fichier</translation> ++<translation id="2568774940984945469">Conteneur de barres d'infos</translation> ++<translation id="8971063699422889582">Le certificat du serveur a expiré.</translation> ++<translation id="8281596639154340028">Utiliser <ph name="HANDLER_TITLE"/></translation> ++<translation id="7134098520442464001">Réduit la taille du texte</translation> ++<translation id="21133533946938348">Épingler l'onglet</translation> ++<translation id="1325040735987616223">Mise à jour du système</translation> ++<translation id="2864069933652346933"><ph name="NUMBER_ZERO"/> days left</translation> ++<translation id="9090669887503413452">Inclure les informations système</translation> ++<translation id="3084771660770137092">Google Chrome n'avait pas suffisamment de mémoire ou le processus de la page Web a été arrêté pour une autre raison. Pour continuer, actualisez la page ou ouvrez-en une autre.</translation> ++<translation id="1114901192629963971">Impossible de valider votre mot de passe sur le réseau actuel. Sélectionnez un autre réseau.</translation> ++<translation id="5179510805599951267">Cette page n'est pas rédigée en <ph name="ORIGINAL_LANGUAGE"/> ? Signaler l'erreur</translation> ++<translation id="6430814529589430811">Certificat unique codé Base 64 ASCII</translation> ++<translation id="5143712164865402236">Activer le mode plein écran</translation> ++<translation id="8434177709403049435">Codag&e</translation> ++<translation id="4051923669149193910"><ph name="HANDLER_TITLE"/> est déjà utilisé pour gérer les liens <ph name="PROTOCOL"/>://.</translation> ++<translation id="2722201176532936492">Touches de sélection</translation> ++<translation id="385120052649200804">Clavier international américain</translation> ++<translation id="9012607008263791152">Je comprends que la visite de ce site peut être préjudiciable à mon ordinateur.</translation> ++<translation id="6640442327198413730">Ressource cache manquante.</translation> ++<translation id="1441458099223378239">Impossible d'accéder à mon compte</translation> ++<translation id="5793220536715630615">C&opier l'URL de la vidéo</translation> ++<translation id="523397668577733901">Vous préférez <ph name="BEGIN_LINK"/>parcourir la galerie<ph name="END_LINK"/> ?</translation> ++<translation id="2922350208395188000">Impossible de vérifier le certificat du serveur.</translation> ++<translation id="3778740492972734840">Outils de &développement</translation> ++<translation id="8335971947739877923">Exporter...</translation> ++<translation id="5680966941935662618">Paramètres de saisie automatique</translation> ++<translation id="38385141699319881">Téléchargement de l'image en cours...</translation> ++<translation id="6004539838376062211">&Options du vérificateur d'orthographe</translation> ++<translation id="5350198318881239970">Impossible d'ouvrir votre profil correctement.\n\nIl est possible que certaines fonctionnalités ne soient pas disponibles. Vérifiez que ce profil existe et que vous disposez d'une autorisation d'accès à son contenu en lecture et en écriture.</translation> ++<translation id="4058793769387728514">Vérifier le document maintenant</translation> ++<translation id="1810107444790159527">Zone de liste</translation> ++<translation id="3338239663705455570">Clavier slovène</translation> ++<translation id="1859234291848436338">Sens de l'écriture</translation> ++<translation id="4567836003335927027">Vos données sur <ph name="WEBSITE_1"/></translation> ++<translation id="756445078718366910">Ouvrir une fenêtre du navigateur</translation> ++<translation id="4126154898592630571">Conversion de la date et de l'heure</translation> ++<translation id="5088534251099454936">PKCS #1 SHA-512 avec chiffrement RSA</translation> ++<translation id="6392373519963504642">Clavier coréen</translation> ++<translation id="7887334752153342268">Dupliquer</translation> ++<translation id="4980691186726139495">Ne pas conserver sur cette page</translation> ++<translation id="3081523290047420375">Désactiver <ph name="CLOUD_PRINT_NAME"/></translation> ++<translation id="9207194316435230304">ATOK</translation> ++<translation id="9026731007018893674">téléchargement</translation> ++<translation id="7646591409235458998">E-mail :</translation> ++<translation id="703748601351783580">Ouvrir tous les favoris dans une nouvelle &fenêtre</translation> ++<translation id="6199775032047436064">Rafraîchir la page actuelle</translation> ++<translation id="6981982820502123353">Accessibilité</translation> ++<translation id="112343676265501403">Exceptions pour les plug-ins</translation> ++<translation id="770273299705142744">Remplissage automatique des formulaires</translation> ++<translation id="7210998213739223319">Nom d'utilisateur</translation> ++<translation id="4478664379124702289">Enregistrer le lie&n sous...</translation> ++<translation id="8725066075913043281">Réessayer</translation> ++<translation id="8502249598105294518">Personnaliser et configurer <ph name="PRODUCT_NAME"/></translation> ++<translation id="7392089327262158658">Préférences de saisie automatique <ph name="PRODUCT_NAME_SHORT"/></translation> ++<translation id="4163521619127344201">Votre position géographique</translation> ++<translation id="3797008485206955964">Afficher les pages en arrière-plan (<ph name="NUM_BACKGROUND_APPS"/>)</translation> ++<translation id="8590375307970699841">Configurer les mises à jour automatiques</translation> ++<translation id="2797524280730715045">il y a <ph name="NUMBER_DEFAULT"/> heures</translation> ++<translation id="265390580714150011">Valeur du champ</translation> ++<translation id="9073247318500677671">Les dernières versions d'Unity et GNOME (ainsi que la prochaine version d'Ubuntu, Natty Narwhal) affichent une barre de menus de type OSX sur toute la largeur supérieure de l'écran.</translation> ++<translation id="3869917919960562512">Index erroné.</translation> ++<translation id="7031962166228839643">Préparation du module de plate-forme sécurisée (TPM) en cours. Veuillez patienter, l'opération peut prendre quelques minutes.</translation> ++<translation id="4250377793615429299">Nombre de copies incorrect</translation> ++<translation id="7180865173735832675">Personnaliser</translation> ++<translation id="5737306429639033676">Prédire les actions du réseau pour améliorer les performances de chargement des pages</translation> ++<translation id="8123426182923614874">Données restantes :</translation> ++<translation id="3707020109030358290">N'est pas une autorité de certification.</translation> ++<translation id="2115926821277323019">L'URL doit être valide.</translation> ++<translation id="8986494364107987395">Envoyer automatiquement les statistiques d'utilisation et les rapports d'erreur à Google</translation> ++<translation id="7070714457904110559">Cette fonctionnalité active la géolocalisation dans les extensions expérimentales. Cela implique l'utilisation des API de localisation du système d'exploitation (si disponibles) et l'envoi de données sur la configuration réseau locale au service de localisation de Google afin de déterminer une position précise.</translation> ++<translation id="6701535245008341853">Impossible de charger le profil.</translation> ++<translation id="527605982717517565">Toujours exécuter JavaScript sur <ph name="HOST"/></translation> ++<translation id="702373420751953740">Version PRL :</translation> ++<translation id="1307041843857566458">Confirmer la réactivation</translation> ++<translation id="8314308967132194952">Ajouter une adresse postale...</translation> ++<translation id="1221024147024329929">PKCS #1 MD2 avec chiffrement RSA</translation> ++<translation id="853265131227167869">Dim.^Lun.^Mar.^Mer.^Jeu.^Ven.^Sam.</translation> ++<translation id="3323447499041942178">Zone de saisie</translation> ++<translation id="580571955903695899">Trier par nom</translation> ++<translation id="5230516054153933099">Fenêtre</translation> ++<translation id="7554791636758816595">Nouvel onglet</translation> ++<translation id="5503844897713343920">Vous tentez d'accéder au site <ph name="DOMAIN"/>, mais le certificat présenté par le serveur a été révoqué par son émetteur. Cela signifie que les informations d'identification présentées par le serveur ne sont pas approuvées. Vous communiquez peut-être avec un pirate informatique. Nous vous déconseillons vivement de continuer.</translation> ++<translation id="6928853950228839340">Composition hors écran</translation> ++<translation id="1308727876662951186"><ph name="NUMBER_ZERO"/> mins left</translation> ++<translation id="7671576867600624">Technologie :</translation> ++<translation id="1103966635949043187">Accédez à la page d'accueil du site :</translation> ++<translation id="1951332921786364801">Configurer la communication à distance</translation> ++<translation id="1086613338090581534">L'émetteur d'un certificat n'ayant pas expiré est tenu d'assurer la maintenance de ce qui s'appelle "une liste de révocation". Si un certificat est compromis, l'émetteur peut le révoquer en l'ajoutant à la liste de révocation. Ce certificat n'est alors plus approuvé par votre navigateur. Il n'est pas nécessaire d'assurer la maintenance de l'état "révoqué" des certificats expirés. Donc, bien qu'un certificat ait été qualifié de valide pour le site Web que vous visitez actuellement, il est impossible de déterminer s'il a été, depuis, compromis puis révoqué ou s'il est toujours valide. Par conséquent, il n'est pas possible de s'assurer si vous communiquez avec un site Web légitime ou si le certificat a été compromis et se trouve maintenant en la possession d'un pirate informatique avec lequel vous communiquez. Ne poursuivez pas.</translation> ++<translation id="2645575947416143543">Néanmoins, si vous travaillez dans une entreprise qui génère ses propres certificats, et que vous essayez de vous connecter au site Web interne de l'entreprise avec un certificat de ce type, vous pouvez résoudre ce problème en toute sécurité. Pour ce faire, importez le certificat racine de l'entreprise en tant que "certificat racine". Par la suite, les certificats émis ou vérifiés par votre entreprise seront approuvés et vous ne verrez plus cette erreur lorsque vous tenterez de vous connecter à nouveau au site Web interne. Contactez le support informatique de votre entreprise pour savoir comment ajouter un nouveau certificat racine sur votre ordinateur.</translation> ++<translation id="376466258076168640">Définir <ph name="PRODUCT_NAME"/> en tant que navigateur par défaut</translation> ++<translation id="1056898198331236512">Avertissement</translation> ++<translation id="8630826211403662855">Préférences de recherche</translation> ++<translation id="8432745813735585631">Clavier Colemak américain</translation> ++<translation id="8151639108075998630">Activer la navigation en tant qu'invité</translation> ++<translation id="2608770217409477136">Utiliser les paramètres par défaut</translation> ++<translation id="3157931365184549694">Rétablir</translation> ++<translation id="7426243339717063209">Désinstaller "<ph name="EXTENSION_NAME"/>" ?</translation> ++<translation id="996250603853062861">Établissement de la connexion sécurisée...</translation> ++<translation id="6059232451013891645">Dossier :</translation> ++<translation id="4274292172790327596">Erreur non reconnue</translation> ++<translation id="760537465793895946">Consultez les conflits connus avec des modules tiers.</translation> ++<translation id="7042418530779813870">Co&ller et rechercher</translation> ++<translation id="9110447413660189038">&Remonter</translation> ++<translation id="375403751935624634">Échec de la traduction en raison d'une erreur de serveur</translation> ++<translation id="2101225219012730419">Version :</translation> ++<translation id="1570242578492689919">Polices et codage</translation> ++<translation id="3082374807674020857"><ph name="PAGE_TITLE"/> - <ph name="PAGE_URL"/></translation> ++<translation id="8050038245906040378">Signature du code commercial Microsoft</translation> ++<translation id="3031557471081358569">Sélectionnez les éléments à importer :</translation> ++<translation id="1368832886055348810">De gauche à droite</translation> ++<translation id="3031433885594348982">Votre connexion à <ph name="DOMAIN"/> est sécurisée par le biais d'un faible chiffrement.</translation> ++<translation id="4047345532928475040">sans objet</translation> ++<translation id="5604324414379907186">Toujours afficher la barre de favoris</translation> ++<translation id="3220630151624181591">Activer l'onglet 2</translation> ++<translation id="8898139864468905752">Aperçu des onglets</translation> ++<translation id="2799223571221894425">Redémarrer</translation> ++<translation id="5771816112378578655">Configuration en cours...</translation> ++<translation id="1197979282329025000">Une erreur s'est produite lors de la récupération des fonctions de l'imprimante <ph name="PRINTER_NAME"/>. Cette imprimante n'a pas pu être enregistrée dans <ph name="CLOUD_PRINT_NAME"/>.</translation> ++<translation id="8820901253980281117">Exceptions pour les fenêtres pop-up</translation> ++<translation id="1143142264369994168">Signataire du certificat </translation> ++<translation id="904949795138183864">La page Web <ph name="URL"/> n'existe plus.</translation> ++<translation id="3228279582454007836">Vous n'avez jamais visité ce site auparavant.</translation> ++<translation id="2159017110205600596">Personnaliser...</translation> ++<translation id="5449716055534515760">Fe&rmer la fenêtre</translation> ++<translation id="2814489978934728345">Arrêter le chargement de cette page</translation> ++<translation id="2354001756790975382">Autres favoris</translation> ++<translation id="8561574028787046517"><ph name="PRODUCT_NAME"/> a été mis à jour.</translation> ++<translation id="5234325087306733083">Mode hors connexion</translation> ++<translation id="1779392088388639487">Erreur d'importation de fichier PKCS #12</translation> ++<translation id="166278006618318542">Algorithme de clé publique de l'objet</translation> ++<translation id="5759272020525228995">Le site Web a rencontré une erreur lors de l'extraction de <ph name="URL"/>. ++ Cela peut être dû à une opération de maintenance ou à une configuration incorrecte.</translation> ++<translation id="641480858134062906">Échec du chargement de la page <ph name="URL"/></translation> ++<translation id="3693415264595406141">Mot de passe :</translation> ++<translation id="74568296546932365">Conserver <ph name="PAGE_TITLE"/> en tant que moteur de recherche par défaut</translation> ++<translation id="8602184400052594090">Fichier manifeste absent ou illisible</translation> ++<translation id="2784949926578158345">La connexion a été réinitialisée.</translation> ++<translation id="6663792236418322902">Le mot de passe choisi vous sera demandé pour restaurer le fichier. Veillez à le conserver en lieu sûr.</translation> ++<translation id="4532822216683966758">La vérification de la provenance du certificat DNS est activée, ce qui peut entraîner l'envoi d'informations privées à Google.</translation> ++<translation id="6321196148033717308">À propos de la reconnaissance vocale</translation> ++<translation id="3412265149091626468">Aller à la sélection</translation> ++<translation id="8167737133281862792">Ajouter un certificat</translation> ++<translation id="2911372483530471524">Espaces de noms PID</translation> ++<translation id="6093374025603915876">Préférences de saisie automatique</translation> ++<translation id="8584134039559266300">Activer l'onglet 8</translation> ++<translation id="5189060859917252173">Le certificat "<ph name="CERTIFICATE_NAME"/>" représente une autorité de certification.</translation> ++<translation id="3785852283863272759">Envoyer par e-mail l'emplacement de la page</translation> ++<translation id="2255317897038918278">Enregistrement des informations de date Microsoft</translation> ++<translation id="3493881266323043047">Validité</translation> ++<translation id="5979421442488174909">&Traduire en <ph name="LANGUAGE"/></translation> ++<translation id="7326526699920221209">Batterie : <ph name="PRECENTAGE"/> %</translation> ++<translation id="952992212772159698">Désactivé</translation> ++<translation id="8299269255470343364">Japonais</translation> ++<translation id="5187826826541650604"><ph name="KEY_NAME"/> (<ph name="DEVICE"/>)</translation> ++<translation id="6429639049555216915">L'application est actuellement inaccessible.</translation> ++<translation id="2144536955299248197">Lecteur du certificat : <ph name="CERTIFICATE_NAME"/></translation> ++<translation id="50030952220075532"><ph name="NUMBER_ONE"/> jour restant</translation> ++<translation id="2885378588091291677">Gestionnaire de tâches</translation> ++<translation id="5792852254658380406">Gérer les extensions...</translation> ++<translation id="2359808026110333948">Continuer</translation> ++<translation id="176759384517330673">Synchronisation avec <ph name="USER_EMAIL_ADDRESS"/> effectuée. Dernière synchronisation : <ph name="LAST_SYNC_TIME"/></translation> ++<translation id="1618661679583408047">Le certificat de sécurité du site n'est pas encore valide !</translation> ++<translation id="7039912931802252762">Ouverture de session par carte à puce Microsoft</translation> ++<translation id="6285074077487067719">Format</translation> ++<translation id="3065140616557457172">Tapez votre requête ou saisissez une URL pour commencer la navigation : c'est à vous de choisir.</translation> ++<translation id="5509693895992845810">Enregistrer &sous...</translation> ++<translation id="5986279928654338866">Le serveur <ph name="DOMAIN"/> requiert un nom d'utilisateur et un mot de passe.</translation> ++<translation id="521467793286158632">Supprimer tous les mots de passe</translation> ++<translation id="2491120439723279231">Le certificat du serveur contient des erreurs.</translation> ++<translation id="4448844063988177157">Recherche de réseaux Wi-Fi...</translation> ++<translation id="5765780083710877561">Description :</translation> ++<translation id="338583716107319301">Séparateur</translation> ++<translation id="2079053412993822885">Si vous supprimez l'un de vos propres certificats, vous ne pouvez plus l'utiliser pour vous identifier.</translation> ++<translation id="7221869452894271364">Rafraîchir cette page</translation> ++<translation id="6791443592650989371">État d'activation :</translation> ++<translation id="4801257000660565496">Créer des raccourcis vers des applications</translation> ++<translation id="6503256918647795660">Clavier franco-suisse</translation> ++<translation id="6175314957787328458">GUID de domaine Microsoft</translation> ++<translation id="8179976553408161302">Entrer</translation> ++<translation id="8261506727792406068">Supprimer</translation> ++<translation id="4404805853119650018">Échec de l'enregistrement de cet ordinateur pour l'accès à distance.</translation> ++<translation id="345693547134384690">Ouvrir l'&image dans un nouvel onglet</translation> ++<translation id="7422192691352527311">Préférences...</translation> ++<translation id="354211537509721945">L'administrateur a désactivé les mises à jour.</translation> ++<translation id="1375198122581997741">À propos de la version</translation> ++<translation id="7915471803647590281">Veuillez nous indiquer ce qu'il se passe avant d'envoyer votre rapport.</translation> ++<translation id="5725124651280963564">Connectez-vous à <ph name="TOKEN_NAME"/> afin de générer une clé pour <ph name="HOST_NAME"/>.</translation> ++<translation id="8418113698656761985">Clavier roumain</translation> ++<translation id="5976160379964388480">Autres</translation> ++<translation id="3665842570601375360">Sécurité :</translation> ++<translation id="1430915738399379752">Imprimer</translation> ++<translation id="7999087758969799248">Mode de saisie standard</translation> ++<translation id="2635276683026132559">Signature</translation> ++<translation id="4835836146030131423">Erreur lors de la connexion</translation> ++<translation id="7715454002193035316">Pour cette session uniquement</translation> ++<translation id="2475982808118771221">Une erreur s'est produite.</translation> ++<translation id="3324684065575061611">(Désactivé par une stratégie d'entreprise)</translation> ++<translation id="7385854874724088939">Erreur lors de la tentative d'impression. Vérifiez votre imprimante et réessayez.</translation> ++<translation id="770015031906360009">Grec</translation> ++<translation id="3834901049798243128">Ignorer les exceptions et bloquer l'enregistrement des cookies tiers</translation> ++<translation id="8116152017593700047">Cet outil vous permet de sélectionner une capture d'écran enregistrée. Aucune capture d'écran n'est disponible pour le moment. Appuyez simultanément sur Ctrl et sur la touche "Mode Présentation" pour enregistrer une capture d'écran. Vos trois dernières captures apparaissent ici.</translation> ++<translation id="3454157711543303649">Activation effectuée</translation> ++<translation id="884923133447025588">Aucun système de révocation trouvé</translation> ++<translation id="556042886152191864">Bouton</translation> ++<translation id="1352060938076340443">Interrompu</translation> ++<translation id="8571226144504132898">Dictionnaire de symboles</translation> ++<translation id="7229570126336867161">Technologie EvDo requise</translation> ++<translation id="7582844466922312471">Internet mobile</translation> ++<translation id="945522503751344254">Envoyer le commentaire</translation> ++<translation id="4539401194496451708">Associé au profil Chrome <ph name="USER_EMAIL_ADDRESS"/>. Dernière synchronisation : <ph name="LAST_SYNC_TIME"/></translation> ++<translation id="7369847606959702983">Carte de crédit (autre)</translation> ++<translation id="6867459744367338172">Langues et saisie</translation> ++<translation id="7671130400130574146">Utiliser la barre de titre et les bordures de fenêtre du système</translation> ++<translation id="9170848237812810038">Ann&uler</translation> ++<translation id="284970761985428403"><ph name="ASCII_NAME"/> (<ph name="UNICODE_NAME"/>)</translation> ++<translation id="3903912596042358459">Le serveur a refusé d'exécuter la demande.</translation> ++<translation id="8135557862853121765"><ph name="NUM_KILOBYTES"/> Ko</translation> ++<translation id="4444364671565852729"><ph name="PRODUCT_NAME"/> a été mis à jour vers la version <ph name="VERSION"/>.</translation> ++<translation id="5819890516935349394">Navigateur de contenu</translation> ++<translation id="2731392572903530958">&Rouvrir la fenêtre fermée</translation> ++<translation id="1254593899333212300">Se connecter directement à Internet</translation> ++<translation id="6107012941649240045">Émis pour</translation> ++<translation id="6483805311199035658">Ouverture de <ph name="FILE"/> en cours</translation> ++<translation id="3576278878016363465">Cibles disponibles pour l'image</translation> ++<translation id="895541991026785598">Signaler un problème</translation> ++<translation id="940425055435005472">Taille de police :</translation> ++<translation id="494286511941020793">Aide pour la configuration de proxy</translation> ++<translation id="2765217105034171413">Petite</translation> ++<translation id="1285266685456062655"><ph name="NUMBER_FEW"/> hours ago</translation> ++<translation id="9154176715500758432">Rester sur cette page</translation> ++<translation id="5875565123733157100">Type de bug :</translation> ++<translation id="6988771638657196063">Inclure cette URL :</translation> ++<translation id="5717920936024713315">Cookies et données de site...</translation> ++<translation id="3842552989725514455">Police Serif</translation> ++<translation id="1949795154112250744"><ph name="BEGIN_BOLD"/>Avertissement :<ph name="END_BOLD"/> <ph name="PRODUCT_NAME"/> ne peut pas empêcher les extensions d'enregistrer votre historique de navigation. Pour désactiver cette extension en mode navigation privée, désélectionnez-la.</translation> ++<translation id="4440967101351338638">ChromiumOs Image Burn</translation> ++<translation id="1813278315230285598">Services</translation> ++<translation id="6860097299815761905">Paramètres du proxy...</translation> ++<translation id="373572798843615002">1 onglet</translation> ++<translation id="4162393307849942816"><ph name="BEGIN_BOLD"/>Vous naviguez en tant qu'invité<ph name="END_BOLD"/>. Les pages que vous consultez dans cette fenêtre n'apparaîtront pas dans l'historique de votre navigateur ni dans votre historique des recherches. Les autres traces telles que les cookies seront supprimées de l'ordinateur à la fin de votre session. En revanche, les fichiers téléchargés et les favoris créés seront conservés. ++ <ph name="LINE_BREAK"/> ++ <ph name="BEGIN_LINK"/>En savoir plus<ph name="END_LINK"/> sur le mode invité</translation> ++<translation id="827924395145979961">Chargement des pages impossible</translation> ++<translation id="3092544800441494315">Inclure cette capture d'écran :</translation> ++<translation id="7714464543167945231">Certificat</translation> ++<translation id="3616741288025931835">&Effacer les données de navigation...</translation> ++<translation id="3313622045786997898">Valeur de signature du certificat</translation> ++<translation id="8535005006684281994">URL de renouvellement du certificat Netscape</translation> ++<translation id="2440604414813129000">Afficher la s&ource</translation> ++<translation id="816095449251911490"><ph name="SPEED"/> - <ph name="RECEIVED_AMOUNT"/>, <ph name="TIME_REMAINING"/></translation> ++<translation id="8200772114523450471">Reprendre</translation> ++<translation id="6358975074282722691"><ph name="NUMBER_TWO"/> secs ago</translation> ++<translation id="5423849171846380976">Activé</translation> ++<translation id="6748105842970712833">Carte SIM désactivée</translation> ++<translation id="7323391064335160098">Compatibilité avec VPN</translation> ++<translation id="3929673387302322681">Développement - Instable</translation> ++<translation id="4251486191409116828">Échec de création du raccourci vers l'application</translation> ++<translation id="5190835502935405962">Barre de favoris</translation> ++<translation id="7828272290962178636">Le serveur est en mesure de répondre à la demande.</translation> ++<translation id="7823073559911777904">Modifier les paramètres du proxy...</translation> ++<translation id="5438430601586617544">(non empaquetée)</translation> ++<translation id="6460601847208524483">Rechercher le suivant</translation> ++<translation id="8433186206711564395">Paramètres réseau</translation> ++<translation id="4856478137399998590">Votre service Internet mobile est activé et prêt à l'emploi.</translation> ++<translation id="1676388805288306495">Modifier la police et la langue par défaut des pages Web</translation> ++<translation id="8969761905474557563">Composition graphique avec accélération matérielle</translation> ++<translation id="3937640725563832867">Autre nom de l'émetteur du certificat</translation> ++<translation id="4701488924964507374"><ph name="SENTENCE1"/> <ph name="SENTENCE2"/></translation> ++<translation id="1163931534039071049">&Afficher le code source du cadre</translation> ++<translation id="8770196827482281187">Mode de saisie du persan (clavier ISIRI 2901)</translation> ++<translation id="6423239382391657905">OpenVPN</translation> ++<translation id="7564847347806291057">Arrêter le processus</translation> ++<translation id="1607220950420093847">Votre compte a peut-être été supprimé ou désactivé. Veuillez vous déconnecter.</translation> ++<translation id="5613695965848159202">Authentification anonyme :</translation> ++<translation id="2233320200890047564">Bases de données indexées</translation> ++<translation id="7063412606254013905">En savoir plus sur les escroqueries par phishing</translation> ++<translation id="307767688111441685">Page à l'apparence anormale</translation> ++<translation id="9076523132036239772">Adresse e-mail ou mot de passe incorrect. Essayez tout d'abord de vous connecter à un réseau.</translation> ++<translation id="6965978654500191972">Périphérique</translation> ++<translation id="1242521815104806351">Informations sur la connexion</translation> ++<translation id="5295309862264981122">Confirmer la navigation</translation> ++<translation id="1492817554256909552">Nom du point d'accès :</translation> ++<translation id="5546865291508181392">Rechercher</translation> ++<translation id="1999115740519098545">Au démarrage</translation> ++<translation id="2983818520079887040">Paramètres...</translation> ++<translation id="1465619815762735808">Lire en un clic</translation> ++<translation id="6941937518557314510">Connectez-vous à <ph name="TOKEN_NAME"/> pour vous authentifier auprès de <ph name="HOST_NAME"/> avec votre certificat.</translation> ++<translation id="2783600004153937501">Votre administrateur informatique a désactivé certaines options.</translation> ++<translation id="2099686503067610784">Supprimer le certificat de serveur "<ph name="CERTIFICATE_NAME"/>"?</translation> ++<translation id="9027603907212475920">Configurer la synchronisation...</translation> ++<translation id="6873213799448839504">Valider automatiquement une chaîne</translation> ++<translation id="7238585580608191973">Empreinte SHA-256</translation> ++<translation id="2501278716633472235">Retour</translation> ++<translation id="131461803491198646">Réseau domestique, sans itinérance</translation> ++<translation id="7377249249140280793"><ph name="RELATIVE_DATE"/> - <ph name="FULL_DATE"/></translation> ++<translation id="5679279978772703611">Gérer les mots de passe enregistrés...</translation> ++<translation id="4551440281920791563">Sélectionnez ++ <ph name="BEGIN_BOLD"/> ++ Menu clé à molette > Options > Options avancées > Modifier les paramètres du proxy > Paramètres réseau ++ <ph name="END_BOLD"/> ++ et désélectionnez l'option "Utiliser un serveur proxy pour votre réseau local".</translation> ++<translation id="1285320974508926690">Ne jamais traduire ce site</translation> ++<translation id="8954894007019320973">(suite)</translation> ++<translation id="3748412725338508953">Trop de redirections</translation> ++<translation id="5833726373896279253">Ces paramètres ne peuvent être modifiés que par le propriétaire :</translation> ++<translation id="6858960932090176617">Active la protection XSS Auditor de WebKit (protection contre le Cross-site Scripting), une fonctionnalité qui vous protège de certaines attaques de sites malveillants et offre une sécurité accrue, mais qui n'est pas compatible avec tous les sites Web.</translation> ++<translation id="6005282720244019462">Clavier latino-américain</translation> ++<translation id="8831104962952173133">Phishing détecté !</translation> ++<translation id="5141720258550370428">Voulez-vous utiliser <ph name="HANDLER_TITLE"/> (<ph name="HANDLER_HOSTNAME"/>) pour gérer les liens <ph name="PROTOCOL"/>:// à partir de maintenant ?</translation> ++<translation id="6751344591405861699"><ph name="WINDOW_TITLE"/> (Navigation privée)</translation> ++<translation id="6681668084120808868">Prendre une photo</translation> ++<translation id="780301667611848630">Non merci</translation> ++<translation id="2812989263793994277">Ne pas afficher les images</translation> ++<translation id="7190251665563814471">Toujours autoriser ces plug-ins sur <ph name="HOST"/></translation> ++<translation id="6845383723252244143">Sélectionner un dossier</translation> ++<translation id="8925458182817574960">&Paramètres</translation> ++<translation id="6361850914223837199">Informations sur l'erreur :</translation> ++<translation id="8948393169621400698">Toujours autoriser les plug-ins sur <ph name="HOST"/></translation> ++<translation id="3865082058368813534">Effacer les données de saisie automatique enregistrées</translation> ++<translation id="8288345061925649502">Changer de moteur de recherche</translation> ++<translation id="5436492226391861498">En attente du tunnel proxy...</translation> ++<translation id="3803991353670408298">Veuillez ajouter un autre mode de saisie avant de supprimer celui-ci.</translation> ++<translation id="1095623615273566396"><ph name="NUMBER_FEW"/> secondes</translation> ++<translation id="7006788746334555276">Paramètres de contenu</translation> ++<translation id="3369521687965833290">Impossible d'extraire les fichiers de l'extension. Pour effectuer cette opération en toute sécurité, vous devez disposer d'un chemin d'accès à votre répertoire de profils commençant par une lettre de lecteur et ne contenant ni jonction, ni point de montage, ni lien symbolique. Aucun chemin de ce type n'existe pour votre profil.</translation> ++<translation id="337920581046691015"><ph name="PRODUCT_NAME"/> va être installé.</translation> ++<translation id="6282194474023008486">Code postal</translation> ++<translation id="7733107687644253241">En bas à droite</translation> ++<translation id="5139955368427980650">&Ouvrir</translation> ++<translation id="8136149669168180907"><ph name="DOWNLOADED_AMOUNT"/> téléchargé(s) sur <ph name="TOTAL_SIZE"/></translation> ++<translation id="7375268158414503514">Commentaires d'ordre général/Autres</translation> ++<translation id="4643612240819915418">Ou&vrir la vidéo dans un nouvel onglet</translation> ++<translation id="7997479212858899587">Identité :</translation> ++<translation id="8300849813060516376">Échec de l'opération OTASP</translation> ++<translation id="2213819743710253654">Action sur la page</translation> ++<translation id="1317130519471511503">Modifier des éléments...</translation> ++<translation id="6391538222494443604">Le répertoire d'extensions est obligatoire.</translation> ++<translation id="8051695050440594747"><ph name="MEGABYTES"/> Mo disponibles</translation> ++<translation id="7088615885725309056">Ancien</translation> ++<translation id="461656879692943278"><ph name="HOST_NAME"/> fournit du contenu provenant de <ph name="ELEMENTS_HOST_NAME"/>, un site connu pour distribuer des logiciels malveillants. Votre ordinateur pourrait être infecté par un virus si vous consultez ce site.</translation> ++<translation id="1387022316521171484">Ces fonctionnalités expérimentales sont susceptibles d'être modifiées, interrompues ou supprimées à tout moment. Nous ne fournissons aucune garantie quant aux effets de leur activation. Votre navigateur pourrait bien prendre feu. Trêve de plaisanterie, il est possible que votre navigateur supprime toutes vos données ou que votre sécurité et votre vie privée soient compromises de manière inattendue. Nous vous prions d'agir avec précaution.</translation> ++<translation id="2143778271340628265">Configuration manuelle du proxy</translation> ++<translation id="5294529402252479912">Mettre à jour Adobe Reader maintenant</translation> ++<translation id="5263972071113911534"><ph name="NUMBER_MANY"/> days ago</translation> ++<translation id="7461850476009326849">Désactiver les plug-ins individuels...</translation> ++<translation id="4097411759948332224">Envoyer une capture d'écran de la page en cours</translation> ++<translation id="2231990265377706070">Point d'exclamation</translation> ++<translation id="7199540622786492483"><ph name="PRODUCT_NAME"/> n'est plus à jour, car il n'a pas été relancé depuis quelque temps. La mise à jour disponible sera installée dès que vous le relancerez.</translation> ++<translation id="8652722422052983852">Petit problème... Tentons de le résoudre.</translation> ++<translation id="5970231080121144965">Cette fonctionnalité permet d'établir des correspondances entre les sous-chaînes et plusieurs fragments d'URL figurant dans l'historique.</translation> ++<translation id="4665674675433053715">Page "Nouvel onglet" expérimentale</translation> ++<translation id="3726527440140411893">Les cookies suivants étaient autorisés lorsque vous avez consulté cette page :</translation> ++<translation id="3320859581025497771">votre opérateur</translation> ++<translation id="8828781037212165374">Activer ces fonctionnalités...</translation> ++<translation id="8562413501751825163">Quitter Firefox avant l'importation</translation> ++<translation id="3435541101098866721">Ajouter un nouveau téléphone</translation> ++<translation id="2448046586580826824">Proxy HTTP sécurisé</translation> ++<translation id="4032534284272647190">Accès à <ph name="URL"/> refusé.</translation> ++<translation id="4928569512886388887">Finalisation de la mise à jour du système...</translation> ++<translation id="8258002508340330928">Voulez-vous continuer ?</translation> ++<translation id="4309420042698375243"><ph name="NUM_KILOBYTES"/> Ko (<ph name="NUM_KILOBYTES_LIVE"/> Ko effectifs)</translation> ++<translation id="5554573843028719904">Autre réseau Wi-Fi...</translation> ++<translation id="5034259512732355072">Choisir un autre répertoire...</translation> ++<translation id="8885905466771744233">L'extension indiquée est déjà associée à une clé privée. Utilisez cette clé ou supprimez-la.</translation> ++<translation id="7831504847856284956">Ajouter une adresse</translation> ++<translation id="7505152414826719222">Stockage local</translation> ++<translation id="2541423446708352368">Afficher tous les téléchargements</translation> ++<translation id="4381021079159453506">Navigateur de contenu</translation> ++<translation id="8109246889182548008">Magasin de certificats</translation> ++<translation id="5030338702439866405">Émis par</translation> ++<translation id="5280833172404792470">Quitter le mode plein écran (<ph name="ACCELERATOR"/>)</translation> ++<translation id="2728127805433021124">Le certificat du serveur a été signé avec un algorithme de signature faible.</translation> ++<translation id="2137808486242513288">Ajouter un utilisateur</translation> ++<translation id="6193618946302416945">Me proposer de traduire les pages qui sont écrites dans une langue que je ne sais pas lire</translation> ++<translation id="129553762522093515">Récemment fermés</translation> ++<translation id="4287167099933143704">Saisir la clé de déverrouillage du code PIN</translation> ++<translation id="8355915647418390920"><ph name="NUMBER_FEW"/> jours</translation> ++<translation id="3129140854689651517">Rechercher du texte</translation> ++<translation id="7221585318879598658">Sans-Serif</translation> ++<translation id="5558129378926964177">Zoom &avant</translation> ++<translation id="6451458296329894277">Confirmer le nouvel envoi du formulaire</translation> ++<translation id="5116333507878097773"><ph name="NUMBER_ONE"/> heure</translation> ++<translation id="8028152732786498049">Cet élément doit être installé depuis <ph name="CHROME_WEB_STORE"/>.</translation> ++<translation id="9199258761842902152">Mise en veille ou reprise</translation> ++<translation id="1851266746056575977">Mettre à jour maintenant</translation> ++<translation id="7017219178341817193">Ajouter une page</translation> ++<translation id="1038168778161626396">Chiffrer seulement</translation> ++<translation id="2756651186786928409">Ne jamais intervertir les touches de modification</translation> ++<translation id="1217515703261622005">Conversion des numéros spéciaux</translation> ++<translation id="7179921470347911571">Relancer maintenant</translation> ++<translation id="3715099868207290855">Synchronisation avec <ph name="USER_EMAIL_ADDRESS"/> effectuée</translation> ++<translation id="2679312662830811292">il y a <ph name="NUMBER_ONE"/> minute</translation> ++<translation id="9065203028668620118">Édition</translation> ++<translation id="4718464510840275738">Préférences synchronisées</translation> ++<translation id="8788572795284305350"><ph name="NUMBER_ZERO"/> hours ago</translation> ++<translation id="1177863135347784049">Personnalisé</translation> ++<translation id="8236028464988198644">Rechercher à partir de la barre d'adresse</translation> ++<translation id="4881695831933465202">Ouvrir</translation> ++<translation id="5988520580879236902">Inspecter les vues actives :</translation> ++<translation id="3593965109698325041">Contraintes de nom du certificat</translation> ++<translation id="4358697938732213860">Ajouter une adresse</translation> ++<translation id="8396532978067103567">Mot de passe incorrect.</translation> ++<translation id="5981759340456370804">Statistiques avancées</translation> ++<translation id="8160015581537295331">Clavier espagnol</translation> ++<translation id="3505920073976671674">Sélectionnez votre réseau</translation> ++<translation id="6644971472240498405"><ph name="NUMBER_ONE"/> jour</translation> ++<translation id="1782924894173027610">Le serveur de synchronisation est occupé. Veuillez réessayer ultérieurement.</translation> ++<translation id="6512448926095770873">Quitter cette page</translation> ++<translation id="5457599981699367932">Naviguer en tant qu'invité</translation> ++<translation id="3169472444629675720">Discover</translation> ++<translation id="6294193300318171613">&Toujours afficher la barre de favoris</translation> ++<translation id="4088820693488683766">Options de recherche</translation> ++<translation id="3414952576877147120">Taille :</translation> ++<translation id="9098468523912235228">il y a <ph name="NUMBER_DEFAULT"/> secondes</translation> ++<translation id="7009102566764819240">La liste suivante fait état des éléments dangereux détectés sur la page. Cliquez sur le lien "Diagnostic" pour obtenir plus d'informations sur une ressource particulière. Si une ressource a été signalée comme site de phishing alors que vous êtes certain de sa fiabilité, cliquez sur le lien "Signaler une erreur".</translation> ++<translation id="4923417429809017348">Cette page rédigée dans une langue non identifiée a été traduite en <ph name="LANGUAGE_LANGUAGE"/>.</translation> ++<translation id="3631337165634322335">Les exceptions ci-dessous s'appliquent uniquement à la session de navigation privée actuelle.</translation> ++<translation id="676327646545845024">Ne plus afficher la boîte de dialogue pour les liens de ce type</translation> ++<translation id="494645311413743213"><ph name="NUMBER_TWO"/> secondes restantes</translation> ++<translation id="1485146213770915382">Insérez <ph name="SEARCH_TERMS_LITERAL"/> dans l'URL où les termes de recherche devraient apparaître.</translation> ++<translation id="4839303808932127586">En&registrer la vidéo sous...</translation> ++<translation id="5626134646977739690">Nom :</translation> ++<translation id="5854409662653665676">Si vous rencontrez des problèmes fréquents avec ce module, vous pouvez tenter d'y remédier en suivant la procédure ci-après :</translation> ++<translation id="3681007416295224113">Informations relatives au certificat</translation> ++<translation id="3046084099139788433">Activer l'onglet 7</translation> ++<translation id="721197778055552897"><ph name="BEGIN_LINK"/>En savoir plus<ph name="END_LINK"/> sur ce problème.</translation> ++<translation id="1699395855685456105">Version du matériel :</translation> ++<translation id="212464871579942993">Le site Web à l'adresse <ph name="HOST_NAME"/> contient des éléments provenant de sites qui semblent héberger des logiciels malveillants. Ces derniers peuvent nuire à votre ordinateur ou agir à votre insu. Le simple fait de visiter un site hébergeant ce type de logiciels peut infecter votre ordinateur. Ce site héberge également des informations provenant de sites signalés comme étant des sites de phishing. Ces derniers incitent les internautes à divulguer des informations personnelles en se faisant passer pour des institutions de confiance, telles que des banques.</translation> ++<translation id="8156020606310233796">Afficher la liste</translation> ++<translation id="957120528631539888">Désactivez l'affichage des messages de confirmation et le blocage de l'envoi des formulaires.</translation> ++<translation id="146000042969587795">Ce cadre a été bloqué, car il contient des éléments non sécurisés.</translation> ++<translation id="8112223930265703044">Tout</translation> ++<translation id="3968739731834770921">Kana</translation> ++<translation id="3729920814805072072">Gérer les mots de passe enregistrés...</translation> ++<translation id="7387829944233909572">Boîte de dialogue "Effacer les données de navigation"</translation> ++<translation id="8023801379949507775">Mettre à jour les extensions maintenant</translation> ++<translation id="6549677549082720666">Nouvelle application en arrière-plan installée</translation> ++<translation id="1983108933174595844">Envoyer une capture d'écran de la page actuelle</translation> ++<translation id="3298789223962368867">L'URL indiquée est incorrecte.</translation> ++<translation id="2202898655984161076">Un problème est survenu lors de l'affichage de la liste des imprimantes. Certaines de vos imprimantes ne sont peut-être pas correctement enregistrées dans <ph name="CLOUD_PRINT_NAME"/>.</translation> ++<translation id="6154697846084421647">Actuellement connecté</translation> ++<translation id="8241707690549784388">La page que vous recherchez a utilisé des informations que vous avez envoyées. Si vous revenez sur cette page, chaque action précédemment effectuée sera répétée. Souhaitez-vous continuer ?</translation> ++<translation id="5359419173856026110">Cette fonctionnalité indique la vitesse d'affichage réelle d'une page, en images par seconde, lorsque l'accélération matérielle est active.</translation> ++<translation id="4104163789986725820">E&xporter...</translation> ++<translation id="2113479184312716848">&Ouvrir un fichier...</translation> ++<translation id="8412709057120877195">Configurer le contrôle d'accès pour vos périphériques</translation> ++<translation id="486595306984036763">Ouvrir un rapport de phishing</translation> ++<translation id="3140353188828248647">Activer la barre d'adresse</translation> ++<translation id="4860787810836767172"><ph name="NUMBER_FEW"/> secs ago</translation> ++<translation id="5565871407246142825">Cartes de paiement</translation> ++<translation id="2587203970400270934">Code opérateur :</translation> ++<translation id="3355936511340229503">Erreur de connexion</translation> ++<translation id="1824910108648426227">Vous avez la possibilité de désactiver ces services.</translation> ++<translation id="3092040396860056776">Essayer d'afficher la page malgré tout</translation> ++<translation id="4350711002179453268">Impossible d'établir une connexion sécurisée avec le serveur. Le serveur a peut-être rencontré un problème ou exige un certificat d'authentification du client dont vous ne disposez pas.</translation> ++<translation id="91731790394942114">Ajouter un nouveau nom</translation> ++<translation id="5963026469094486319">Obtenir d'autres thèmes</translation> ++<translation id="2441719842399509963">Rétablir les valeurs par défaut</translation> ++<translation id="1893137424981664888">Aucun Plug-in installé.</translation> ++<translation id="3718288130002896473">Action</translation> ++<translation id="2168725742002792683">Extensions de fichier</translation> ++<translation id="1753905327828125965">Les plus visités</translation> ++<translation id="8116972784401310538">&Gestionnaire de favoris</translation> ++<translation id="1849632043866553433">Caches des applications</translation> ++<translation id="3591607774768458617">Cette langue est actuellement utilisée par <ph name="PRODUCT_NAME"/>.</translation> ++<translation id="621638399744152264"><ph name="VALUE"/> %</translation> ++<translation id="4927301649992043040">Empaqueter l'extension</translation> ++<translation id="8679658258416378906">Activer l'onglet 5</translation> ++<translation id="4763816722366148126">Sélectionner le mode de saisie précédent</translation> ++<translation id="6458308652667395253">Configurer le blocage de JavaScript...</translation> ++<translation id="8435334418765210033">Réseaux mémorisés</translation> ++<translation id="6516193643535292276">Impossible de se connecter à Internet.</translation> ++<translation id="5125751979347152379">URL incorrecte</translation> ++<translation id="2791364193466153585">Informations sur la sécurité</translation> ++<translation id="4673916386520338632">Impossible d'installer l'application, car elle est en conflit avec "<ph name="APP_NAME"/>", qui est déjà installé.</translation> ++<translation id="2024918351532495204">Votre périphérique n'est pas connecté.</translation> ++<translation id="6040143037577758943">Fermer</translation> ++<translation id="5787146423283493983">Accord de la clé</translation> ++<translation id="1101671447232096497"><ph name="NUMBER_MANY"/> mins ago</translation> ++<translation id="4265682251887479829">Vous ne trouvez pas ce que vous recherchez ?</translation> ++<translation id="1804251416207250805">Désactivez l'envoi des pings de contrôle des liens hypertexte.</translation> ++<translation id="5116628073786783676">En&registrer le fichier audio sous...</translation> ++<translation id="2557899542277210112">Accédez rapidement à vos favoris en les ajoutant à la barre de favoris.</translation> ++<translation id="2749881179542288782">Vérifier la grammaire et l'orthographe</translation> ++<translation id="5105855035535475848">Épingler les onglets</translation> ++<translation id="6892450194319317066">Sélectionner par type d'application</translation> ++<translation id="3549436232897695316">assembler</translation> ++<translation id="5414121716219514204"><ph name="ENGINE_HOST_NAME"/> souhaite devenir votre moteur de recherche.</translation> ++<translation id="2752805177271551234">Utiliser l'historique d'entrée</translation> ++<translation id="7268365133021434339">Fermer les onglets</translation> ++<translation id="4910619056351738551">Voici quelques suggestions :</translation> ++<translation id="9131598836763251128">Sélectionnez un ou plusieurs fichiers</translation> ++<translation id="5489059749897101717">Afficher le panneau de la &vérification orthographique</translation> ++<translation id="3423858849633684918">Veuillez relancer <ph name="PRODUCT_NAME"/>.</translation> ++<translation id="1232569758102978740">Sans titre</translation> ++<translation id="1903219944620007795">Pour saisir du texte, sélectionnez une langue et consultez la liste des modes de saisie disponibles.</translation> ++<translation id="4362187533051781987">Ville</translation> ++<translation id="9149866541089851383">Modifier...</translation> ++<translation id="7608619752233383356">Réinitialiser la synchronisation</translation> ++<translation id="1065245965611933814">Inclure une capture d'écran enregistrée :</translation> ++<translation id="7876243839304621966">Tout supprimer</translation> ++<translation id="5663459693447872156">Passer automatiquement en demi-chasse</translation> ++<translation id="4593021220803146968">&Accéder à <ph name="URL"/></translation> ++<translation id="1128987120443782698">La capacité de ce périphérique de stockage est de <ph name="DEVICE_CAPACITY"/>. Veuillez insérer une carte SD ou une clé USB d'au moins 4 Go.</translation> ++<translation id="869257642790614972">Rouvrir le dernier onglet fermé</translation> ++<translation id="3978267865113951599">(blocage)</translation> ++<translation id="8412145213513410671">Erreurs (<ph name="CRASH_COUNT"/>)</translation> ++<translation id="560602183358579978">Traitement de la sélection...</translation> ++<translation id="7649070708921625228">Aide</translation> ++<translation id="5994107996638824097">Désolé ! La visionneuse de documents PDF intégrée à Google Chrome, nécessaire à l'affichage de l'aperçu avant impression, n'est pas incluse dans Chromium.</translation> ++<translation id="976526967778596630">Impossible d'ouvrir <ph name="HOST_NAME"/>, car vous êtes déconnecté du réseau. Cette page s'affichera dès que la connexion réseau sera rétablie. <br></translation> ++<translation id="1734072960870006811">Télécopie</translation> ++<translation id="3095995014811312755">version</translation> ++<translation id="7052500709156631672">La passerelle ou le serveur proxy a reçu une réponse incorrecte d'un serveur en amont.</translation> ++<translation id="281133045296806353">Nouvelle fenêtre ouverte dans la session du navigateur</translation> ++<translation id="7144878232160441200">Réessayer</translation> ++<translation id="2860002559146138960"><ph name="PRODUCT_NAME"/> peut maintenant synchroniser vos mots de passe. Vos données seront chiffrées avec le mot de passe de votre compte Google ou le mot de passe multiterme de votre choix.</translation> ++<translation id="3951872452847539732">Les paramètres réseau de votre proxy sont gérés par une extension.</translation> ++<translation id="6442697326824312960">Retirer l'onglet</translation> ++<translation id="6382612843547381371">Valable du <ph name="START_DATE_TIME"/> au <ph name="END_DATE_TIME"/></translation> ++<translation id="6869402422344886127">Case cochée</translation> ++<translation id="5637380810526272785">Mode de saisie</translation> ++<translation id="404928562651467259">AVERTISSEMENT</translation> ++<translation id="7172053773111046550">Clavier estonien</translation> ++<translation id="497490572025913070">Ajout de bordures aux couches de rendu composées</translation> ++<translation id="9002707937526687073">Imp&rimer...</translation> ++<translation id="5953934840931207585">Paramètres de saisie automatique <ph name="PRODUCT_NAME_SHORT"/></translation> ++<translation id="5556459405103347317">Rafraîchir</translation> ++<translation id="8000020256436988724">Barre d'outils</translation> ++<translation id="8326395326942127023">Nom de la base de données :</translation> ++<translation id="7507930499305566459">Certificat du répondeur d'état</translation> ++<translation id="2689915906323125315">Utiliser le mot de passe de mon compte Google</translation> ++<translation id="6440205424473899061">Vos favoris sont maintenant synchronisés avec Google Documents ! ++Pour fusionner et synchroniser vos favoris dans <ph name="PRODUCT_NAME"/> sur un autre ordinateur, procédez de la même manière que précédemment sur l'ordinateur voulu.</translation> ++<translation id="7727721885715384408">Renommer...</translation> ++<translation id="2604243255129603442"><ph name="NAME_OF_EXTENSION"/> a été désactivé. Si vous arrêtez la synchronisation des favoris, vous pouvez la réactiver sur la page des extensions, via le menu Outils.</translation> ++<translation id="2024621544377454980">Affichage des pages impossible</translation> ++<translation id="7136694880210472378">Utiliser par défaut</translation> ++<translation id="7681202901521675750">La carte SIM est verrouillée. Veuillez saisir votre code PIN. Nombre de tentatives restantes : <ph name="TRIES_COUNT"/></translation> ++<translation id="1731346223650886555">Point-virgule</translation> ++<translation id="158849752021629804">Réseau domestique requis</translation> ++<translation id="7339763383339757376">PKCS #7, certificat unique</translation> ++<translation id="7587108133605326224">Langues baltes</translation> ++<translation id="3991936620356087075">Vous avez saisi un trop grand nombre de clés de verrouillage du code PIN incorrectes. Votre carte SIM est définitivement désactivée.</translation> ++<translation id="936801553271523408">Données de diagnostic système</translation> ++<translation id="6389701355360299052">Page Web, contenu HTML uniquement</translation> ++<translation id="8067791725177197206">Continuer »</translation> ++<translation id="9009144784540995197">Gérez vos imprimantes.</translation> ++<translation id="1055006259534905434">(Choisir un problème dans la liste ci-dessous)</translation> ++<translation id="3021678814754966447">&Afficher le code source du cadre</translation> ++<translation id="8601206103050338563">Authentification du client WWW TLS</translation> ++<translation id="1692799361700686467">Les cookies de plusieurs sites sont autorisés.</translation> ++<translation id="7074488040076962230">Impossible d'afficher la page de la barre latérale "<ph name="SIDEBAR_PAGE"/>".</translation> ++<translation id="529232389703829405">Vous avez acheté <ph name="DATA_AMOUNT"/> de données le <ph name="DATE"/>.</translation> ++<translation id="5271549068863921519">Enregistrer le mot de passe</translation> ++<translation id="4345587454538109430">Configurer...</translation> ++<translation id="8148264977957212129">Mode de saisie du pinyin</translation> ++<translation id="5787378733537687553">Intervertir les touches Ctrl et Alt de gauche</translation> ++<translation id="7772032839648071052">Confirmer le mot de passe multiterme</translation> ++<translation id="6857811139397017780">Activer <ph name="NETWORKSERVICE"/></translation> ++<translation id="3251855518428926750">Ajouter...</translation> ++<translation id="4120075327926916474">Voulez-vous que Google Chrome enregistre ces informations de carte de paiement pour le remplissage de formulaires Web ?</translation> ++<translation id="6929555043669117778">Continuer à bloquer les fenêtres pop-up</translation> ++<translation id="5864471791310927901">Échec de la vérification DHCP</translation> ++<translation id="3508920295779105875">Choisir un autre dossier...</translation> ++<translation id="2503458975635466059">Le profil semble être utilisé par le processus <ph name="PROCESS_ID"/> sur l'hôte <ph name="HOST_NAME"/>. Si vous êtes certain qu'aucun autre processus n'utilise ce profil, supprimez le fichier <ph name="LOCK_FILE"/> et relancez <ph name="PRODUCT_NAME"/>.</translation> ++<translation id="2987775926667433828">Chinois traditionnel</translation> ++<translation id="6684737638449364721">Effacer les données de navigation...</translation> ++<translation id="3954582159466790312">Ré&activer le son</translation> ++<translation id="1110772031432362678">Aucun réseau trouvé.</translation> ++<translation id="3936390757709632190">&Ouvrir le fichier audio dans un nouvel onglet</translation> ++<translation id="7297622089831776169">&Méthodes d'entrée</translation> ++<translation id="5731698828607291678">Onglets ou fenêtres</translation> ++<translation id="1152775729948968688">Toutefois, cette page inclut d'autres ressources qui ne sont pas sécurisées. Ces ressources peuvent être consultées par des tiers pendant leur transfert, et modifiées par un pirate informatique dans le but de changer le comportement de cette page.</translation> ++<translation id="604124094241169006">Automatique</translation> ++<translation id="862542460444371744">&Extensions</translation> ++<translation id="8045462269890919536">Roumain</translation> ++<translation id="6320286250305104236">Paramètres du réseau...</translation> ++<translation id="2927657246008729253">Changer...</translation> ++<translation id="7978412674231730200">Clé privée</translation> ++<translation id="464745974361668466">Format :</translation> ++<translation id="5308380583665731573">Se connecter</translation> ++<translation id="9111395131601239814"><ph name="NETWORKDEVICE"/> : <ph name="STATUS"/></translation> ++<translation id="9049981332609050619">Vous avez tenté de contacter <ph name="DOMAIN"/>, mais le certificat présenté par le serveur est incorrect.</translation> ++<translation id="4414232939543644979">Nouvelle fenêtre de nav&igation privée</translation> ++<translation id="1693754753824026215">La page à l'adresse <ph name="SITE"/> indique :</translation> ++<translation id="7148804936871729015">Le serveur associé à <ph name="URL"/> n'a pas répondu à temps. Cela peut être dû à une surcharge.</translation> ++<translation id="5950967683057767490">L2TP/IPSec + Clé pré-partagée</translation> ++<translation id="8108473539339615591">XSS Auditor</translation> ++<translation id="1902576642799138955">Durée de validité</translation> ++<translation id="4910021444507283344">WebGL</translation> ++<translation id="6692173217867674490">Mot de passe multiterme erroné</translation> ++<translation id="5550431144454300634">Corriger automatiquement la saisie</translation> ++<translation id="3308006649705061278">Unité d'organisation</translation> ++<translation id="8912362522468806198">Compte Google</translation> ++<translation id="4443536555189480885">&Aide</translation> ++<translation id="340485819826776184">Utiliser un service de prédiction afin de compléter les recherches et les URL saisies dans la barre d'adresse</translation> ++<translation id="4074900173531346617">Certificat du signataire de courrier électronique</translation> ++<translation id="6165508094623778733">En savoir plus</translation> ++<translation id="9052208328806230490">Vous avez enregistré vos imprimantes sur <ph name="CLOUD_PRINT_NAME"/> via le compte <ph name="EMAIL"/>.</translation> ++<translation id="822618367988303761">il y a <ph name="NUMBER_TWO"/> jours</translation> ++<translation id="7928333295097642153"><ph name="HOUR"/>:<ph name="MINUTE"/> restantes</translation> ++<translation id="7568593326407688803">Cette page est en<ph name="ORIGINAL_LANGUAGE"/>Voulez-vous la traduire ?</translation> ++<translation id="563969276220951735">Saisie automatique des formulaires</translation> ++<translation id="6870130893560916279">Clavier ukrainien</translation> ++<translation id="8629974950076222828">Ouvrir tous les favoris dans une fenêtre de navigation privée</translation> ++<translation id="3126026824346185272">Ctrl</translation> ++<translation id="4745438305783437565"><ph name="NUMBER_FEW"/> minutes</translation> ++<translation id="2649911884196340328">Le certificat de sécurité du serveur contient des erreurs !</translation> ++<translation id="6666647326143344290">avec votre compte Google</translation> ++<translation id="3828029223314399057">Rechercher dans les favoris</translation> ++<translation id="4885705234041587624">MSCHAPv2</translation> ++<translation id="5614190747811328134">Avertissement utilisateur</translation> ++<translation id="8906421963862390172">&Options du vérificateur d'orthographe</translation> ++<translation id="9046895021617826162">Échec de la connexion</translation> ++<translation id="1492188167929010410">Identifiant de l'erreur <ph name="CRASH_ID"/></translation> ++<translation id="1963692530539281474"><ph name="NUMBER_DEFAULT"/> jours restants</translation> ++<translation id="4470270245053809099">Émis par : <ph name="NAME"/></translation> ++<translation id="5365539031341696497">Mode de saisie du thaï (clavier Kesmanee)</translation> ++<translation id="2403091441537561402">Passerelle :</translation> ++<translation id="6337234675334993532">Chiffrement</translation> ++<translation id="668171684555832681">Autre...</translation> ++<translation id="1932098463447129402">Pas avant le</translation> ++<translation id="7845920762538502375"><ph name="PRODUCT_NAME"/> n'a pas pu synchroniser vos données, car la connexion avec le serveur de synchronisation n'a pas pu être établie. Nouvel essai...</translation> ++<translation id="2192664328428693215">Me demander lorsqu'un site souhaite afficher des notifications sur le Bureau (recommandé)</translation> ++<translation id="6708242697268981054">Source :</translation> ++<translation id="4786993863723020412">Erreur de lecture du cache</translation> ++<translation id="6630452975878488444">Raccourci de sélection</translation> ++<translation id="8709969075297564489">Vérifier la révocation du certificat serveur</translation> ++<translation id="8698171900303917290">Vous rencontrez des problèmes lors de l'installation ?</translation> ++<translation id="830868413617744215">Bêta</translation> ++<translation id="5925147183566400388">Pointeur de la déclaration CPS (Certification Practice Statement)</translation> ++<translation id="1497270430858433901">Le <ph name="DATE"/>, vous avez reçu <ph name="DATA_AMOUNT"/> à utiliser librement.</translation> ++<translation id="8150167929304790980">Nom complet</translation> ++<translation id="636850387210749493">Inscription d'entreprise</translation> ++<translation id="1947424002851288782">Clavier allemand</translation> ++<translation id="932508678520956232">Impossible de lancer l'impression.</translation> ++<translation id="4861833787540810454">&Lire</translation> ++<translation id="2552545117464357659">Récent</translation> ++<translation id="7269802741830436641">Cette page Web présente une boucle de redirection.</translation> ++<translation id="4180788401304023883">Supprimer le certificat "<ph name="CERTIFICATE_NAME"/>" émis par l'autorité de certification ?</translation> ++<translation id="5869522115854928033">Mots de passe enregistrés</translation> ++<translation id="2089090684895656482">Moins</translation> ++<translation id="1709220265083931213">Options avancées</translation> ++<translation id="5748266869826978907">Vérifiez vos paramètres DNS. Contactez votre administrateur réseau si vous n'êtes pas sûr de vous.</translation> ++<translation id="4771973620359291008">Une erreur inconnue s'est produite.</translation> ++<translation id="5509914365760201064">Émetteur : <ph name="CERTIFICATE_AUTHORITY"/></translation> ++<translation id="7073385929680664879">Passer d'un mode de saisie à l'autre</translation> ++<translation id="6898699227549475383">Organisation (O)</translation> ++<translation id="4333854382783149454">PKCS #1 SHA-1 avec chiffrement RSA</translation> ++<translation id="762904068808419792">Entrez la requête de recherche ici.</translation> ++<translation id="8615618338313291042">Application en mode navigation privée : <ph name="APP_NAME"/></translation> ++<translation id="978146274692397928">La largeur de ponctuation initiale est Complète</translation> ++<translation id="8959027566438633317">Installer <ph name="EXTENSION_NAME"/> ?</translation> ++<translation id="8155798677707647270">Installation d'une nouvelle version...</translation> ++<translation id="6886871292305414135">Ouvrir le lien dans un nouvel ongle&t</translation> ++<translation id="1639192739400715787">Pour accéder aux paramètres de sécurité, saisissez le code PIN de la carte SIM.</translation> ++<translation id="7961015016161918242">Jamais</translation> ++<translation id="3950924596163729246">Impossible d'accéder au réseau.</translation> ++<translation id="2835170189407361413">Effacer le formulaire</translation> ++<translation id="4631110328717267096">Échec de la mise à jour du système</translation> ++<translation id="3695919544155087829">Saisissez le mot de passe utilisé pour chiffrer ce fichier de certificat.</translation> ++<translation id="2230051135190148440">CHAP</translation> ++<translation id="6308937455967653460">Enregistrer le lie&n sous...</translation> ++<translation id="5421136146218899937">Effacer les données de navigation...</translation> ++<translation id="5783059781478674569">Options de reconnaissance vocale</translation> ++<translation id="5441100684135434593">Réseau câblé</translation> ++<translation id="3285322247471302225">Nouvel ongle&t</translation> ++<translation id="3943582379552582368">R&etour</translation> ++<translation id="7607002721634913082">Téléchargement suspendu</translation> ++<translation id="480990236307250886">Ouvrir la page d'accueil</translation> ++<translation id="8286036467436129157">Connexion</translation> ++<translation id="5999940714422617743">L'installation de <ph name="EXTENSION_NAME"/> est terminée.</translation> ++<translation id="1122198203221319518">&Outils</translation> ++<translation id="5757539081890243754">Page d'accueil</translation> ++<translation id="2760009672169282879">Clavier phonétique bulgare</translation> ++<translation id="6608140561353073361">Cookies et données de site...</translation> ++<translation id="8007030362289124303">Batterie faible</translation> ++<translation id="4513946894732546136">Commentaires</translation> ++<translation id="1135328998467923690">Package incorrect : "<ph name="ERROR_CODE"/>".</translation> ++<translation id="5906719743126878045"><ph name="NUMBER_TWO"/> heures restantes</translation> ++<translation id="1753682364559456262">Configurer les paramètres de blocage des images...</translation> ++<translation id="6550675742724504774">Options</translation> ++<translation id="8959208747503200525"><ph name="NUMBER_TWO"/> hours ago</translation> ++<translation id="431076611119798497">&Détails</translation> ++<translation id="737801893573836157">Masquer la barre de titre du système et utiliser les bordures</translation> ++<translation id="5352235189388345738">Elle peut accéder aux éléments suivants :</translation> ++<translation id="5040262127954254034">Confidentialité</translation> ++<translation id="7666868073052500132">Objets : <ph name="USAGES"/></translation> ++<translation id="6985345720668445131">Paramètres d'entrée du japonais</translation> ++<translation id="3258281577757096226">Sebeol-sik Final</translation> ++<translation id="6906268095242253962">Veuillez vous connecter à Internet pour continuer.</translation> ++<translation id="1908748899139377733">Afficher les &infos sur le cadre</translation> ++<translation id="803771048473350947">Fichier</translation> ++<translation id="6206311232642889873">Cop&ier l'image</translation> ++<translation id="5158983316805876233">Utiliser le même proxy pour tous les protocoles</translation> ++<translation id="7108338896283013870">Masquer</translation> ++<translation id="3366404380928138336">Requête de protocole externe</translation> ++<translation id="5300589172476337783">Afficher</translation> ++<translation id="3160041952246459240">Certains de vos certificats enregistrés identifient ces serveurs :</translation> ++<translation id="566920818739465183">Vous avez visité ce site pour la première fois le <ph name="VISIT_DATE"/>.</translation> ++<translation id="2961695502793809356">Cliquer pour avancer, maintenir pour voir l'historique</translation> ++<translation id="4092878864607680421">La dernière version de l'application "<ph name="APP_NAME"/>" requiert d'autres autorisations. Elle a donc été désactivée.</translation> ++<translation id="8421864404045570940"><ph name="NUMBER_DEFAULT"/> secondes</translation> ++<translation id="5828228029189342317">Vous avez choisi d'ouvrir automatiquement certains types de fichiers après leur téléchargement.</translation> ++<translation id="1416836038590872660">EAP-MD5</translation> ++<translation id="176587472219019965">&Nouvelle fenêtre</translation> ++<translation id="2788135150614412178">+</translation> ++<translation id="4055738107007928968">Vous avez essayé d'accéder au site <ph name="DOMAIN"/>, mais le serveur a présenté un certificat signé avec un algorithme de signature faible. Il se peut que les informations d'identification fournies par le serveur aient été falsifiées. Le serveur n'est peut-être pas celui auquel vous souhaitez accéder (il peut s'agir d'une tentative de piratage). Nous nous déconseillons vivement de continuer.</translation> ++<translation id="5308689395849655368">L'envoi de rapports d'erreur est désactivé.</translation> ++<translation id="8372369524088641025">Clé WEP incorrecte</translation> ++<translation id="8689341121182997459">Date d'expiration :</translation> ++<translation id="899403249577094719">URL de base du certificat Netscape</translation> ++<translation id="2737363922397526254">Réduire...</translation> ++<translation id="4880827082731008257">Rechercher dans l'historique</translation> ++<translation id="8661290697478713397">Ouvrir le lien dans la fenêtre de navi&gation privée</translation> ++<translation id="4197700912384709145"><ph name="NUMBER_ZERO"/> secondes</translation> ++<translation id="7454780465968211330">Historique avancé pour le champ polyvalent</translation> ++<translation id="2158448795143567596">Active l'utilisation de graphismes 3D dans les éléments canvas via l'API WebGL.</translation> ++<translation id="1702534956030472451">Occident</translation> ++<translation id="6636709850131805001">État non reconnu</translation> ++<translation id="6095984072944024315">−</translation> ++<translation id="9141716082071217089">Impossible de vérifier si le certificat du serveur a été révoqué.</translation> ++<translation id="4304224509867189079">Se connecter</translation> ++<translation id="5332624210073556029">Fuseau horaire :</translation> ++<translation id="4799797264838369263">Cette option est soumise à une stratégie d'entreprise. Contactez votre administrateur pour plus d'informations.</translation> ++<translation id="4492190037599258964">Résultats de recherche pour "<ph name="SEARCH_STRING"/>"</translation> ++<translation id="3573179567135747900">Revenir à "<ph name="FROM_LOCALE"/>" (redémarrage requis)</translation> ++<translation id="2238123906478057869"><ph name="PRODUCT_NAME"/> va exécuter les tâches suivantes :</translation> ++<translation id="4042471398575101546">Ajouter la page</translation> ++<translation id="8848709220963126773">Changement de mode via la touche Maj</translation> ++<translation id="4871865824885782245">Options de date et d'heure...</translation> ++<translation id="8828933418460119530">Nom DNS</translation> ++<translation id="988159990683914416">Build de développement</translation> ++<translation id="8026354464835030469"><ph name="BURNT_AMOUNT"/> sur ...</translation> ++<translation id="4114470632216071239">Verrouiller la carte SIM (code PIN obligatoire pour utiliser les données mobiles)</translation> ++<translation id="2183426022964444701">Sélectionnez le répertoire racine de l'extension.</translation> ++<translation id="2517143724531502372">Les cookies de <ph name="DOMAIN"/> sont autorisés uniquement pour cette session.</translation> ++<translation id="9018524897810991865">Confirmer les préférences de synchronisation</translation> ++<translation id="4719905780348837473">RSN</translation> ++<translation id="5212108862377457573">Ajuster la conversion en fonction de l'entrée précédente</translation> ++<translation id="5398353896536222911">Afficher le panneau de la &vérification orthographique</translation> ++<translation id="5811533512835101223">(Revenir à la capture d'écran d'origine)</translation> ++<translation id="5131817835990480221">Mettre à jour &<ph name="PRODUCT_NAME"/></translation> ++<translation id="939519157834106403">SSID</translation> ++<translation id="3705722231355495246">-</translation> ++<translation id="2635102990349508383">Les informations de connexion au compte n'ont pas encore été saisies.</translation> ++<translation id="6902055721023340732">URL de configuration automatique</translation> ++<translation id="4268574628540273656">URL :</translation> ++<translation id="7481312909269577407">Avancer</translation> ++<translation id="3759876923365568382"><ph name="NUMBER_FEW"/> jours restants</translation> ++<translation id="295228163843771014">Vous avez choisi de ne pas synchroniser les mots de passe. Vous pouvez à tout moment modifier vos paramètres de synchronisation, si vous changez d'avis.</translation> ++<translation id="5972826969634861500">Lancer <ph name="PRODUCT_NAME"/></translation> ++<translation id="7828702903116529889"><ph name="PRODUCT_NAME"/> ++ ne parvient pas à accéder au réseau. ++ <ph name="LINE_BREAK"/> ++ Il est possible que votre pare-feu ou votre antivirus considère ++ <ph name="PRODUCT_NAME"/> ++ comme un intrus dans votre ordinateur et qu'il bloque ses tentatives de connexion à Internet.</translation> ++<translation id="878069093594050299">Ce certificat a été vérifié pour les utilisations suivantes :</translation> ++<translation id="5852112051279473187">Petit problème ! Une erreur est survenue lors de l'inscription de ce périphérique. Veuillez réessayer ou contacter votre représentant de l'assistance technique.</translation> ++<translation id="1664314758578115406">Ajouter aux favoris</translation> ++<translation id="7088418943933034707">Gérer les certificats...</translation> ++<translation id="8482183012530311851">Analyse du périphérique...</translation> ++<translation id="3127589841327267804">PYJJ</translation> ++<translation id="8808478386290700967">Web Store</translation> ++<translation id="1732215134274276513">Annuler l'épinglage des onglets</translation> ++<translation id="4084682180776658562">Favori</translation> ++<translation id="8859057652521303089">Sélectionnez votre langue :</translation> ++<translation id="3030138564564344289">Réessayer le téléchargement</translation> ++<translation id="8525552230188318924">Configurer la synchronisation des mots de passe</translation> ++<translation id="4381091992796011497">Nom d'utilisateur :</translation> ++<translation id="5830720307094128296">Enregistrer la p&age sous...</translation> ++<translation id="8114439576766120195">Vos données sur tous les sites Web</translation> ++<translation id="4668954208278016290">Un problème est survenu lors de l'extraction de l'image sur l'ordinateur.</translation> ++<translation id="5822838715583768518">Lancer l'application</translation> ++<translation id="3942974664341190312">Dubeol-sik</translation> ++<translation id="8477241577829954800">Remplacé</translation> ++<translation id="6735304988756581115">Afficher les cookies et autres données de site...</translation> ++<translation id="3048564749795856202">Si vous pensez avoir cerné les risques, vous pouvez <ph name="PROCEED_LINK"/>.</translation> ++<translation id="2433507940547922241">Apparence</translation> ++<translation id="839072384475670817">Créer des raccourci&s vers des applications...</translation> ++<translation id="1478632774608054702">Exécuter le flash PPAPI dans le processus du moteur de rendu</translation> ++<translation id="6756161853376828318">Définir <ph name="PRODUCT_NAME"/> en tant que navigateur par défaut</translation> ++<translation id="9112614144067920641">Veuillez choisir un nouveau code PIN.</translation> ++<translation id="2061855250933714566"><ph name="ENCODING_CATEGORY"/> (<ph name="ENCODING_NAME"/>)</translation> ++<translation id="7138678301420049075">Autre</translation> ++<translation id="9147392381910171771">&Options</translation> ++<translation id="1803557475693955505">Impossible de charger la page d'arrière-plan "<ph name="BACKGROUND_PAGE"/>".</translation> ++<translation id="5818334088068591797">À quel niveau rencontrez-vous des problèmes ? (Champ obligatoire)</translation> ++<translation id="6264485186158353794">Retour à la sécurité</translation> ++<translation id="5130080518784460891">Eten</translation> ++<translation id="5847724078457510387">Ce site répertorie tous ses certificats valides dans le système DNS. Un certificat non répertorié a cependant été utilisé par le serveur.</translation> ++<translation id="1394853081832053657">Options de reconnaissance vocale</translation> ++<translation id="5037676449506322593">Tout sélectionner</translation> ++<translation id="2785530881066938471">Impossible de charger le fichier "<ph name="RELATIVE_PATH"/>" pour le script de contenu, car ce fichier n'est pas codé en UTF-8.</translation> ++<translation id="3807747707162121253">&Annuler</translation> ++<translation id="3306897190788753224">Désactiver temporairement la personnalisation des conversions, les suggestions basées sur l'historique et le dictionnaire utilisateur</translation> ++<translation id="2574102660421949343">Les cookies de <ph name="DOMAIN"/> sont autorisés.</translation> ++<translation id="77999321721642562">Au fil du temps, la zone ci-dessous affichera les huit sites que vous avez le plus visités.</translation> ++<translation id="1503894213707460512">Le plug-in <ph name="PLUGIN_NAME"/> a besoin de votre autorisation pour s'exécuter.</translation> ++<translation id="471800408830181311">Échec de création de clé privée</translation> ++<translation id="1273291576878293349">Ouvrir tous les favoris dans une fenêtre de navigation privée</translation> ++<translation id="1639058970766796751">Placer dans la file d'attente</translation> ++<translation id="1177437665183591855">Erreur de certificat serveur inconnue</translation> ++<translation id="8467473010914675605">Mode de saisie du coréen</translation> ++<translation id="3819800052061700452">&Plein écran</translation> ++<translation id="5419540894229653647"><ph name="ERROR_DESCRIPTION_TEXT"/> ++ <ph name="LINE_BREAK"/> ++ Vous pouvez essayer de diagnostiquer le problème en procédant comme suit : ++ <ph name="LINE_BREAK"/> ++ <ph name="PLATFORM_TEXT"/></translation> ++<translation id="3533943170037501541">Bienvenue sur votre page d'accueil !</translation> ++<translation id="2333340435262918287">Vos modifications seront prises en compte au prochain démarrage de <ph name="PRODUCT_NAME"/>.</translation> ++<translation id="5906065664303289925">Adresse du matériel :</translation> ++<translation id="3178000186192127858">Lecture seule</translation> ++<translation id="2187895286714876935">Erreur d'importation du certificat serveur</translation> ++<translation id="5460896875189097758">Données stockées localement</translation> ++<translation id="4618990963915449444">Tous les fichiers de <ph name="DEVICE_NAME"/> vont être effacés.</translation> ++<translation id="614998064310228828">Modèle du périphérique :</translation> ++<translation id="1581962803218266616">Afficher dans le Finder</translation> ++<translation id="6096326118418049043">Nom X.500</translation> ++<translation id="6086259540486894113">Vous devez sélectionner au moins un type de données à synchroniser.</translation> ++<translation id="923467487918828349">Tout afficher</translation> ++<translation id="5101042277149003567">Ouvrir tous les favoris</translation> ++<translation id="4298972503445160211">Clavier danois</translation> ++<translation id="6621440228032089700">Cette fonctionnalité permet de réaliser un rendu hors écran de la texture, au lieu d'un affichage direct.</translation> ++<translation id="3488065109653206955">Partiellement activé</translation> ++<translation id="1481244281142949601">Votre système Sandbox est correctement configuré.</translation> ++<translation id="4849517651082200438">Ne pas installer</translation> ++<translation id="8602882075393902833">Activer la recherche instantanée pour accélérer la recherche et la navigation</translation> ++<translation id="6349678711452810642">Utiliser par défaut</translation> ++<translation id="6263284346895336537">Non essentielle</translation> ++<translation id="6409731863280057959">Fenêtres pop-up</translation> ++<translation id="3459774175445953971">Dernière modification :</translation> ++<translation id="73289266812733869">Désélectionné</translation> ++<translation id="3435738964857648380">Sécurité</translation> ++<translation id="9112987648460918699">Rechercher...</translation> ++<translation id="2231233239095101917">Le script de la page utilisait trop de mémoire. Rafraîchissez la page pour réactiver le script.</translation> ++<translation id="870805141700401153">Signature du code individuel Microsoft</translation> ++<translation id="5119173345047096771">Mozilla Firefox</translation> ++<translation id="9020278534503090146">Page Web inaccessible</translation> ++<translation id="4768698601728450387">Recadrer l'image</translation> ++<translation id="6245028464673554252">Si vous fermez <ph name="PRODUCT_NAME"/> maintenant, le téléchargement sera annulé.</translation> ++<translation id="3943857333388298514">Coller</translation> ++<translation id="385051799172605136">Retour</translation> ++<translation id="1742300158964248589">Impossible de graver l'image.</translation> ++<translation id="2670965183549957348">Mode de saisie du Chewing</translation> ++<translation id="5095208057601539847">Province</translation> ++<translation id="4085298594534903246">JavaScript a été bloqué sur cette page.</translation> ++<translation id="5630492933376732170">Remarque : Lorsque vous cliquez sur "Envoyer", Google Chrome OS ++ joint à votre envoi un journal des événements système de ++ votre périphérique. Ces informations nous permettent de diagnostiquer les ++ problèmes, de comprendre comment vous interagissez avec votre ++ périphérique et d'améliorer les performances de ce dernier. Les ++ informations personnelles fournies sciemment dans vos commentaires ou ++ involontairement dans les journaux système et la capture d'écran sont ++ protégées conformément à nos <ph name="BEGIN_LINK"/>Règles de confidentialité<ph name="END_LINK"/>. ++ Si vous ne souhaitez pas envoyer de journaux système, décochez la case ++ "Inclure les informations système".</translation> ++<translation id="4341977339441987045">Interdire à tous les sites de stocker des données</translation> ++<translation id="806812017500012252">Trier par nom</translation> ++<translation id="3781751432212184938">Afficher un aperçu des onglets...</translation> ++<translation id="2960316970329790041">Annuler l'importation</translation> ++<translation id="3835522725882634757">Ce serveur envoie des données que <ph name="PRODUCT_NAME"/> ne comprend pas. Veuillez <ph name="BEGIN_LINK"/>signaler un bug<ph name="END_LINK"/> et inclure la <ph name="BEGIN2_LINK"/>liste des raw<ph name="END2_LINK"/>.</translation> ++<translation id="5361734574074701223">Calcul de la durée restante</translation> ++<translation id="6937152069980083337">Mode de saisie Google du japonais (pour clavier américain)</translation> ++<translation id="1731911755844941020">Envoi de la requête...</translation> ++<translation id="8371695176452482769">Parlez maintenant</translation> ++<translation id="2988488679308982380">Impossible d'installer le package : "<ph name="ERROR_CODE"/>"</translation> ++<translation id="2904079386864173492">Modèle :</translation> ++<translation id="3447644283769633681">Bloquer tous les cookies tiers</translation> ++<translation id="8917047707340793412">Remplacer par <ph name="ENGINE_NAME"/></translation> ++<translation id="6129953537138746214">Espace</translation> ++<translation id="3704331259350077894">Arrêt du fonctionnement</translation> ++<translation id="5801568494490449797">Préférences</translation> ++<translation id="1038842779957582377">Nom inconnu</translation> ++<translation id="5327248766486351172">Nom</translation> ++<translation id="5553784454066145694">Choisir un nouveau code PIN</translation> ++<translation id="8989148748219918422"><ph name="ORGANIZATION"/> [<ph name="COUNTRY"/>]</translation> ++<translation id="4664482161435122549">Erreur d'exportation de fichier PKCS #12</translation> ++<translation id="2445081178310039857">Le répertoire racine de l'extension doit être indiqué.</translation> ++<translation id="8251578425305135684">Miniature supprimée</translation> ++<translation id="6163522313638838258">Tout développer...</translation> ++<translation id="3037605927509011580">Aie aie aie</translation> ++<translation id="5803531701633845775">Choisir les expressions en arrière-plan, sans déplacer le pointeur</translation> ++<translation id="1918141783557917887">Plu&s petit</translation> ++<translation id="6996550240668667907">Afficher le clavier en superposition</translation> ++<translation id="4065006016613364460">C&opier l'URL de l'image</translation> ++<translation id="6965382102122355670">OK</translation> ++<translation id="8000066093800657092">Aucun réseau détecté</translation> ++<translation id="4481249487722541506">Charger l'extension non empaquetée...</translation> ++<translation id="8180239481735238521">page</translation> ++<translation id="8321738493186308836">Active l'interface utilisateur et le code de support pour le processus du service de communication à distance, de même que le plug-in client. Avertissement : ce service n'est actuellement disponible que pour les tests de développeurs. Si vous ne faites pas partie de l'équipe de développement et ne figurez pas sur la liste blanche, aucun élément de l'interface utilisateur activée ne fonctionnera.</translation> ++<translation id="2963783323012015985">Clavier turc</translation> ++<translation id="2149973817440762519">Modifier le favori</translation> ++<translation id="5431318178759467895">Couleur</translation> ++<translation id="7064842770504520784">Personnaliser les paramètres de synchronisation...</translation> ++<translation id="2784407158394623927">Activation de votre service Internet mobile</translation> ++<translation id="3679848754951088761"><ph name="SOURCE_ORIGIN"/></translation> ++<translation id="6920989436227028121">Ouvrir dans un onglet standard</translation> ++<translation id="4057041477816018958"><ph name="SPEED"/> - <ph name="RECEIVED_AMOUNT"/></translation> ++<translation id="2050339315714019657">Portrait</translation> ++<translation id="6978839998405419496"><ph name="NUMBER_ZERO"/> days ago</translation> ++<translation id="6139139147415955203">Active un service en arrière-plan qui connecte le service <ph name="CLOUD_PRINT_NAME"/> aux éventuelles imprimantes installées sur cet ordinateur. Une fois ce labo activé, vous pouvez lancer <ph name="CLOUD_PRINT_NAME"/> en vous connectant à votre compte Google via Options/Préférences dans la section Options avancées.</translation> ++<translation id="5112577000029535889">Outils de &développement</translation> ++<translation id="2301382460326681002">Le répertoire racine de l'extension est incorrect.</translation> ++<translation id="7839192898639727867">ID de clé de l'objet du certificat</translation> ++<translation id="4759238208242260848">Téléchargements</translation> ++<translation id="2879560882721503072">Le stockage du certificat client généré par <ph name="ISSUER"/> a réussi.</translation> ++<translation id="1275718070701477396">Sélectionnée</translation> ++<translation id="1178581264944972037">Suspendre</translation> ++<translation id="6492313032770352219">Taille sur le disque :</translation> ++<translation id="5233231016133573565">ID du processus</translation> ++<translation id="5941711191222866238">Réduire</translation> ++<translation id="4121428309786185360">Expire le</translation> ++<translation id="2049137146490122801">Votre administrateur a désactivé l'accès aux fichiers locaux sur votre ordinateur.</translation> ++<translation id="1146498888431277930">Erreur de connexion SSL</translation> ++<translation id="8041089156583427627">Envoyer</translation> ++<translation id="6394627529324717982">Virgule</translation> ++<translation id="253434972992662860">&Pause</translation> ++<translation id="335985608243443814">Parcourir...</translation> ++<translation id="7802488492289385605">Mode de saisie Google du japonais (pour clavier Dvorak américain)</translation> ++<translation id="7452120598248906474">Police à largeur fixe</translation> ++<translation id="3129687551880844787">Stockage de session</translation> ++<translation id="7427348830195639090">Page en arrière-plan : <ph name="BACKGROUND_PAGE_URL"/></translation> ++<translation id="5898154795085152510">Le serveur a renvoyé un certificat client incorrect. Erreur <ph name="ERROR_NUMBER"/> (<ph name="ERROR_NAME"/>)</translation> ++<translation id="2704184184447774363">Signature de document Microsoft</translation> ++<translation id="5677928146339483299">Bloqué</translation> ++<translation id="1474842329983231719">Gérer les paramètres d'impression...</translation> ++<translation id="2455981314101692989">Cette page Web a désactivé la saisie automatique dans ce formulaire.</translation> ++<translation id="1646136617204068573">Clavier hongrois</translation> ++<translation id="5988840637546770870">Les versions en développement permettent de tester de nouvelles idées, mais elles peuvent s'avérer très instables. Nous vous prions d'agir avec précaution.</translation> ++<translation id="3569713929051927529">Ajouter un dossier...</translation> ++<translation id="4032664149172368180">Mode de saisie du japonais (pour clavier Dvorak américain)</translation> ++<translation id="3748706263662799310">Signaler un bug</translation> ++<translation id="7167486101654761064">&Toujours ouvrir les fichiers de ce type</translation> ++<translation id="4283623729247862189">Disque optique</translation> ++<translation id="5826507051599432481">Nom commun</translation> ++<translation id="8914326144705007149">Très grande</translation> ++<translation id="4215444178533108414">Modification terminée</translation> ++<translation id="5154702632169343078">Objet</translation> ++<translation id="2273562597641264981">Opérateur :</translation> ++<translation id="122082903575839559">Algorithme de signature du certificat</translation> ++<translation id="2181257377760181418">Cette fonctionnalité permet d'afficher un onglet d'aperçu avant de lancer une impression.</translation> ++<translation id="7240120331469437312">Autre nom de l'objet du certificat</translation> ++<translation id="6900113680982781280">Activer la saisie automatique pour remplir les formulaires Web d'un simple clic</translation> ++<translation id="1131850611586448366">Le site Web à l'adresse <ph name="HOST_NAME"/> a été signalé comme étant un site de phishing. Ces sites tentent d'amener les internautes à divulguer leurs informations personnelles en se faisant passer pour des institutions de confiance, telles que des banques.</translation> ++<translation id="5413218268059792983">Rechercher directement sur <ph name="SEARCH_ENGINE"/></translation> ++<translation id="1161575384898972166">Connectez-vous à <ph name="TOKEN_NAME"/> pour exporter le certificat client.</translation> ++<translation id="1718559768876751602">Créer un compte Google maintenant</translation> ++<translation id="1884319566525838835">État Sandbox</translation> ++<translation id="2770465223704140727">Retirer de la liste</translation> ++<translation id="3590587280253938212">rapide</translation> ++<translation id="6053401458108962351">&Effacer les données de navigation…</translation> ++<translation id="2339641773402824483">Vérification des mises à jour...</translation> ++<translation id="9111742992492686570">Télécharger les mises à jour de sécurité essentielles</translation> ++<translation id="8636666366616799973">Package incorrect. Détails : "<ph name="ERROR_MESSAGE"/>".</translation> ++<translation id="2045969484888636535">Continuer à bloquer les cookies</translation> ++<translation id="7353601530677266744">Ligne de commande</translation> ++<translation id="2766006623206032690">Coller l'URL et y a&ccéder</translation> ++<translation id="4394049700291259645">Désactiver</translation> ++<translation id="969892804517981540">Build officiel</translation> ++<translation id="445923051607553918">Se connecter à un réseau Wi-Fi</translation> ++<translation id="100242374795662595">Périphérique inconnu</translation> ++<translation id="9087725134750123268">Supprimer les cookies et autres données de site</translation> ++<translation id="5050255233730056751">URL saisies</translation> ++<translation id="3349155901412833452">Utiliser les touches , et . pour paginer une liste d'entrées</translation> ++<translation id="6872947427305732831">Vider la mémoire</translation> ++<translation id="2742870351467570537">Supprimer les éléments sélectionnés</translation> ++<translation id="7561196759112975576">Toujours</translation> ++<translation id="2116673936380190819">de moins d'une heure</translation> ++<translation id="5765491088802881382">Aucun réseau n'est disponible.</translation> ++<translation id="1971538228422220140">Supprimer les cookies et autres données de site et de plug-in</translation> ++<translation id="883487340845134897">Intervertir les touches Rechercher et Ctrl gauche</translation> ++<translation id="5692957461404855190">Faites glisser trois doigts sur la surface de votre trackpad pour afficher un aperçu de tous vos onglets. Cliquez sur une vignette pour la sélectionner. Idéal en mode plein écran.</translation> ++<translation id="1375215959205954975">Nouveau ! Configurer la synchronisation des mots de passe</translation> ++<translation id="5183088099396036950">Échec de la tentative de connexion au serveur</translation> ++<translation id="4469842253116033348">Désactiver les notifications de <ph name="SITE"/></translation> ++<translation id="7999229196265990314">Les fichiers suivants ont été créés : ++ ++Extension : <ph name="EXTENSION_FILE"/> ++Fichier de clé : <ph name="KEY_FILE"/> ++ ++Conservez votre fichier de clé en lieu sûr. Vous en aurez besoin lors de la création de nouvelles versions de l'extension.</translation> ++<translation id="1846078536247420691">&Oui</translation> ++<translation id="3036649622769666520">Ouvrir les fichiers</translation> ++<translation id="2966459079597787514">Clavier suédois</translation> ++<translation id="7685049629764448582">Mémoire JavaScript </translation> ++<translation id="6398765197997659313">Quitter le mode plein écran</translation> ++<translation id="6059652578941944813">Hiérarchie des certificats</translation> ++<translation id="4886690096315032939">Afficher l'onglet existant si l'URL associée est demandée dans un autre</translation> ++<translation id="5729712731028706266">&Afficher</translation> ++<translation id="774576312655125744">Vos données personnelles sur <ph name="WEBSITE_1"/>, <ph name="WEBSITE_2"/> et sur <ph name="NUMBER_OF_OTHER_WEBSITES"/> autres sites Web</translation> ++<translation id="6359806961507272919">SMS de <ph name="PHONE_NUMBER"/></translation> ++<translation id="4508765956121923607">Afficher la s&ource</translation> ++<translation id="5975083100439434680">Zoom arrière</translation> ++<translation id="8080048886850452639">C&opier l'URL du fichier audio</translation> ++<translation id="2817109084437064140">Importer et associer au périphérique...</translation> ++<translation id="3331321258768829690">(<ph name="UTCOFFSET"/>) <ph name="LONGTZNAME"/> (<ph name="EXEMPLARCITY"/>)</translation> ++<translation id="619398760000422129">Plug-ins (par ex. Adobe Flash Player, QuickTime, etc.)</translation> ++<translation id="5849869942539715694">Empaqueter l'extension...</translation> ++<translation id="7339785458027436441">Vérifier l'orthographe lors de la frappe</translation> ++<translation id="8308427013383895095">Échec de la traduction en raison d'un problème de connexion réseau</translation> ++<translation id="1801298019027379214">Code PIN incorrect. Veuillez réessayer. Nombre de tentatives restantes : <ph name="TRIES_COUNT"/></translation> ++<translation id="1384721974622518101">Vous pouvez effectuer une recherche directement à partir du champ ci-dessus.</translation> ++<translation id="992543612453727859">Ajouter les expressions au premier plan</translation> ++<translation id="3857773447683694438">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</translation> ++<translation id="1244147615850840081">Opérateur</translation> ++<translation id="8203365863660628138">Confirmer l'installation</translation> ++<translation id="406259880812417922">(Mot clé : <ph name="KEYWORD"/>)</translation> ++<translation id="309628958563171656">Sensibilité :</translation> ++</translationbundle> +diff --git a/tools/grit/grit/testdata/generated_resources_iw.xtb b/tools/grit/grit/testdata/generated_resources_iw.xtb +new file mode 100644 +index 0000000000..86b55334c0 +--- /dev/null ++++ b/tools/grit/grit/testdata/generated_resources_iw.xtb +@@ -0,0 +1,4 @@ ++<?xml version="1.0" ?> ++<!DOCTYPE translationbundle> ++<translationbundle lang="iw"> ++</translationbundle> +diff --git a/tools/grit/grit/testdata/generated_resources_no.xtb b/tools/grit/grit/testdata/generated_resources_no.xtb new file mode 100644 -index 0000000000..aa90a95eb3 +index 0000000000..913638ba4e --- /dev/null -+++ b/tools/clang/plugins/tests/nested_class_inline_ctor.cpp ++++ b/tools/grit/grit/testdata/generated_resources_no.xtb +@@ -0,0 +1,4 @@ ++<?xml version="1.0" ?> ++<!DOCTYPE translationbundle> ++<translationbundle lang="no"> ++</translationbundle> +diff --git a/tools/grit/grit/testdata/grit_part.grdp b/tools/grit/grit/testdata/grit_part.grdp +new file mode 100644 +index 0000000000..c8e9d92692 +--- /dev/null ++++ b/tools/grit/grit/testdata/grit_part.grdp @@ -0,0 +1,5 @@ -+// Copyright (c) 2012 The Chromium Authors. All rights reserved. -+// Use of this source code is governed by a BSD-style license that can be -+// found in the LICENSE file. ++<?xml version="1.0" encoding="UTF-8"?> ++<grit-part> ++ <!-- Important for test purposes that this file not exist. --> ++ <structure type="chrome_scaled_image" name="IDR_DOES_NOT_EXIST" file="does-not-exist.png" /> ++</grit-part> +diff --git a/tools/grit/grit/testdata/header.html b/tools/grit/grit/testdata/header.html +new file mode 100644 +index 0000000000..8e9d10ec50 +--- /dev/null ++++ b/tools/grit/grit/testdata/header.html +@@ -0,0 +1,39 @@ ++<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ++<html><head><title>[$~TITLE~$]</title> ++<meta http-equiv="cache-control" content="no-cache"> ++<meta http-equiv="content-type" content="text/html; charset=utf-8"> ++<meta http-equiv="pragma" content="no-cache"> ++<meta http-equiv="expires" content="-1"> ++[EXTRA_META] ++<style> ++BODY,TD,DIV,.P,A { FONT-FAMILY: arial,sans-serif} ++DIV,TD { COLOR: #000} ++.f { COLOR: #6f6f6f} ++.fl:link { COLOR: #6f6f6f} ++A:link, .w, A.w:link, .w A:link { COLOR: #00c} ++A:visited { COLOR: #551a8b} ++.fl:visited { COLOR: #551a8b} ++A:active, .fl:active { COLOR: #f00} ++.h { COLOR: #3399CC} ++.i { COLOR: #a90a08} ++.i:link { COLOR: #a90a08} ++.a, .a:link, .a:visited { COLOR: #008000} ++DIV.n { MARGIN-TOP: 1ex} ++.n A { FONT-SIZE: 10pt; COLOR: #000} ++.n .i { FONT-WEIGHT: bold; FONT-SIZE: 10pt} ++.q A:visited { COLOR: #00c} ++.q A:link { COLOR: #00c} ++.q A:active { COLOR: #00c} ++.q { COLOR: #00c} ++.b { FONT-WEIGHT: bold; FONT-SIZE: 12pt; COLOR: #00c} ++.ch { CURSOR: hand} ++.e { MARGIN-TOP: 0.75em; MARGIN-BOTTOM: 0.75em} ++.g { MARGIN-TOP: 1em; MARGIN-BOTTOM: 1em} ++.f { MARGIN-TOP: 0.5em; MARGIN-BOTTOM: 0.25em} ++.s { HEIGHT: 10px } ++.c:active { COLOR: #ff0000} ++.c:visited { COLOR: #551a8b} ++.c:link { COLOR: #7777cc} ++.c { COLOR: #7777cc } ++</style> ++</head> +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/homepage.html b/tools/grit/grit/testdata/homepage.html +new file mode 100644 +index 0000000000..cce4f2cf35 +--- /dev/null ++++ b/tools/grit/grit/testdata/homepage.html +@@ -0,0 +1,37 @@ ++<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ++<html><head><title>Google Desktop Search</title> ++<meta http-equiv="content-type" content="text/html; charset=utf-8"> ++<meta http-equiv="cache-control" content="no-cache"> ++<meta http-equiv="pragma" content="no-cache"> ++<meta http-equiv="expires" content="-1"> ++<style> ++BODY,TD,A,P {FONT-FAMILY: arial,sans-serif} ++.q {COLOR: #0000cc} ++</style> ++<script> ++<!-- ++function sf(){document.f.q.focus();} ++// --> ++</script> ++</head> ++<BODY text=#000000 vLink=#551a8b aLink=#ff0000 link=#0000cc bgColor=#ffffff onload=sf()> ++<center> ++<TABLE cellSpacing=0 cellPadding=0 border=0> ++<tr><td><a href="[$~HOMEPAGE~$]"><IMG border=0 height=110 alt="Google Desktop Search" src="hp_logo.gif" width=276></a></td></tr></table><BR> ++<FORM name=f method=GET action='[$~SEARCHURL~$]'> ++<TABLE cellSpacing=0 cellPadding=4 border=0> ++<tr> ++<TD class=q noWrap><FONT size=-1> ++[$~LINKS~$] ++</font></td> ++</tr></table> ++<table cellspacing=0 cellpadding=0> ++<tr vAlign=top> ++<td width=25%> </td> ++<td align=center><input maxlength=256 size=62 name=q value="[DISP_QUERY]"><br><input type=submit value="Search Desktop" name=btnG><INPUT type=submit value="Search the Web" name="redir" accesskey=w></td> ++<td align=left valign=top nowrap width=25%><font size=-2> <A href="[$~PREFERENCES~$]">Desktop Preferences</a></font></td> ++</tr></table></FORM> ++<p><FONT color=#224499><B>Search your own computer.</B></font></p> ++<span style='width:29em'>[$~MESSAGE~$]</span><br> ++<br><FONT size=-1>[$~SETHOMEPAGE~$][$~BOTTOMLINE~$]</font></p> ++<p><FONT size=-2>©2005 Google - Searching [NUM_ITEMS] items</font></p></center></body></html> +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/hover.html b/tools/grit/grit/testdata/hover.html +new file mode 100644 +index 0000000000..b8f9ce0200 +--- /dev/null ++++ b/tools/grit/grit/testdata/hover.html +@@ -0,0 +1,177 @@ ++<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ++<html><head> ++<meta http-equiv="content-type" content="text/html; charset=utf-8"> ++<meta http-equiv="cache-control" content="no-cache"> ++<meta http-equiv="pragma" content="no-cache"> ++<meta http-equiv="expires" content="-1"> ++<style> ++BODY { FONT-SIZE: 8pt; FONT-FAMILY: verdana,arial,san-serif } ++P { FONT-SIZE: 8pt; FONT-FAMILY: verdana,arial,san-serif } ++TD { FONT-SIZE: 8pt; FONT-FAMILY: verdana,arial,san-serif } ++A { FONT-SIZE: 8pt; FONT-FAMILY: verdana,arial,san-serif } ++DIV { FONT-SIZE: 8pt; TEXT-DECORATION: none } ++A:hover { COLOR: #ffffff } ++.border { BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px } ++</style> ++ ++<!-- menu experiment start --> ++ ++<style> ++<!-- ++.menu1 { ++cursor:default; ++position:absolute; ++left: 10; ++top: 0; ++text-align: left; ++font-family: Arial, Helvetica, sans-serif; ++font-size: 8pt; ++background-color: menu; ++visibility: hidden; ++padding-top: 2px; ++padding-bottom: 2px; ++border: 1 solid; ++border-color: #888888; ++z-index: 100; ++} ++.menuitems { ++padding-left: 5px; ++padding-right: 5px; ++} ++--> ++</style> ++<SCRIPT LANGUAGE="JavaScript1.2"> ++<!-- ++var menustyle = "menu1"; ++ ++function showmenu() { ++ // var rightedge = document.body.clientWidth-event.clientX; ++ // var bottomedge = document.body.clientHeight-event.clientY; ++ // if (rightedge < rcmenu.offsetWidth) ++ // rcmenu.style.left = document.body.scrollLeft + event.clientX - rcmenu.offsetWidth; ++ // else ++ // rcmenu.style.left = document.body.scrollLeft + event.clientX; ++ // if (bottomedge < rcmenu.offsetHeight) ++ // rcmenu.style.top = document.body.scrollTop + event.clientY - rcmenu.offsetHeight; ++ // else ++ // rcmenu.style.top = document.body.scrollTop + event.clientY; ++ ++ rcmenu.style.visibility = "visible"; ++ // rcmenu.style.zindex = 0; ++ // document.all('rcmenu').style.zindex = 20; ++ document.onkeydown=ck; ++ return false; ++} ++ ++function hidemenu() { ++ rcmenu.style.visibility = "hidden"; ++} ++ ++function ck(e){ ++ evt=document.all?window.event:e; ++ k=document.all?window.event.keyCode:e.keyCode; ++ ++ if(k==27 /*<Esc>*/) { ++ hidemenu(); ++ } ++} ++ ++function menumouseover() { ++ if (event.srcElement.className == "menuitems") { ++ event.srcElement.style.backgroundColor = "highlight"; ++ event.srcElement.style.color = "white"; ++ } ++} ++ ++function menumouseout() { ++ if (event.srcElement.className == "menuitems") { ++ event.srcElement.style.backgroundColor = ""; ++ event.srcElement.style.color = "black"; ++ window.status = ""; ++ } ++} ++ ++function menuselect() { ++ if (event.srcElement.className == "menuitems") { ++ if (event.srcElement.getAttribute("target") != null) ++ window.open(event.srcElement.url, event.srcElement.getAttribute("target")); ++ else if (event.srcElement.url.length) ++ window.location = event.srcElement.url; ++ } ++} ++// --> ++</script> ++ ++<!-- menu experiment end --> ++ ++</head> ++<BODY bottomMargin=0 bgColor=#3300cc leftMargin=0 topMargin=0 rightMargin=0 marginwidth="0" marginheight="0" border=0 style="border-width:0;" scroll=no> ++ ++<!-- <br> --> ++ ++<!-- menu experiment start --> ++ ++<div id="rcmenu" class="skin0" onMouseover="menumouseover()" onMouseout="menumouseout()" onClick="menuselect();"> ++<span class="menuitems" url="[$~SETDISP1~$]">Sidebar</span> ++<span class="menuitems" url="[$~SETDISP4~$]">Minibar</span> ++<span class="menuitems" url="[$~HIDE2~$]">Close</span> ++</div> ++ ++<script language="JavaScript1.2"> ++if (document.all && window.print) { ++ rcmenu.className = menustyle; ++ document.oncontextmenu = showmenu; ++ document.body.onclick = hidemenu; ++} ++</script> ++ ++<!-- menu experiment end --> ++ ++<script> ++function hide() { ++ return 1; ++ // return confirm("Are you sure you want to hide the minibar?\nYou can show it again in Google Desktop Search Preferences. "); ++} ++function clear() { ++ document.getElementById('q').value=''; ++} ++</script> ++ ++<TABLE cellSpacing=0 cellPadding=0 bgColor=#3300cc border=0><TBODY> ++<tr><TD vAlign=top> ++ ++<form method=get action="[$~SEARCHURL~$]" [$~SEARCH_TARGET~$] name=f1 ID="f1" onsubmit="window.setTimeout('clear()', 500)"> ++<input type=hidden name=src value=3> ++<input type=hidden name=redir value='' ID="redir"> ++ ++<TABLE cellSpacing=0 cellPadding=0 bgColor=#3300cc border=0><TBODY> ++ ++<tr> ++<!-- border-top: #414a4f 0px solid; --> ++<!-- z-index:2; z-order:2; --> ++<TD vAlign=top> <INPUT name=q style="position:relative; height=19px;" class=border size=12> </td> ++ ++<TD TABINDEX="2" onkeydown='if(event.keyCode!=16&&event.keyCode!=9)onclick()' onclick="f1.submit();q.value=''" class=ch onmouseover="this.bgColor='6666FF'" style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #6666cc 1px solid; BORDER-LEFT: #6666cc 1px solid; BORDER-BOTTOM: #000000 1px solid" onmouseout="this.bgColor='#000099'" vAlign=center align=middle bgColor=#000099><IMG src="logo.gif" align=middle></td> ++ ++<TD width=2><IMG height=1 width=1></td> ++ ++<TD TABINDEX="3" onkeydown='if(event.keyCode!=16&&event.keyCode!=9)onclick()' onclick="redir.value='google'; f1.submit(); redir.value='';q.value=''" class=ch onmouseover="this.bgColor='6666FF'" style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #6666cc 1px solid; BORDER-LEFT: #6666cc 1px solid; BORDER-BOTTOM: #000000 1px solid" onmouseout="this.bgColor='#000099'" vAlign=center align=middle bgColor=#000099><IMG src="gfavicon.ico" align=middle></td></tr> ++</TBODY></table> ++</td> ++ ++<TD width=5><IMG height=1 width=1></td> ++ ++<TD vAlign=top> ++ ++<TABLE cellSpacing=0 cellPadding=1 bgColor=#000099><TBODY> ++<tr><TD TABINDEX="4" onkeydown='if(event.keyCode!=16&&event.keyCode!=9)onclick()' valign=top onclick="location.href='[$~SETDISP1~$]';" class=ch onmouseover="this.bgColor='6666FF'" style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #6666cc 1px solid; BORDER-LEFT: #6666cc 1px solid; BORDER-BOTTOM: #000000 1px solid" onmouseout="this.bgColor='#000099'" vAlign=top noWrap bgColor=#000099><IMG src="down.gif"></td></tr></TBODY></table> ++ ++</td> ++ ++<TD width=1><IMG height=1 width=1></td> ++ ++<TD vAlign=top><TABLE cellSpacing=0 cellPadding=1><TBODY> ++<tr><TD TABINDEX="5" onkeydown='if(event.keyCode!=16&&event.keyCode!=9)onclick()' valign=top onclick="if (hide())location.href='[$~HIDE2~$]';" class=ch onmouseover="this.bgColor='6666FF'" style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #6666cc 1px solid; BORDER-LEFT: #6666cc 1px solid; BORDER-BOTTOM: #000000 1px solid" onmouseout="this.bgColor='#000099'" vAlign=top noWrap bgColor=#000099><IMG src="close.gif"></td></tr></TBODY></table></td></tr></TBODY></table> ++ ++</form> ++</body></html> +diff --git a/tools/grit/grit/testdata/include_test.html b/tools/grit/grit/testdata/include_test.html +new file mode 100644 +index 0000000000..e08f2e2e8a +--- /dev/null ++++ b/tools/grit/grit/testdata/include_test.html +@@ -0,0 +1,31 @@ ++<include src="included_sample.html"> ++<if expr="True"> ++should be kept ++</if> ++in the middle... ++<if expr="False"> ++should be removed ++</if> ++ ++<if expr="False"> ++should be removed ++ <if expr="True"> ++ should be removed because outer expr is False ++ </if> ++should be removed ++</if> ++ ++<if expr="True"> ++ <if expr="True"> ++ <if expr="True"> ++ nested true should be kept ++ </if> ++ <if expr="False"> ++ should be removed ++ </if> ++ </if> ++ <if expr="True"> ++ silbing true should be kept ++ </if> ++</if> ++at the end... +diff --git a/tools/grit/grit/testdata/included_sample.html b/tools/grit/grit/testdata/included_sample.html +new file mode 100644 +index 0000000000..7150ffcbea +--- /dev/null ++++ b/tools/grit/grit/testdata/included_sample.html +@@ -0,0 +1 @@ ++Hello Include! +diff --git a/tools/grit/grit/testdata/indexing_speed.html b/tools/grit/grit/testdata/indexing_speed.html +new file mode 100644 +index 0000000000..db1787b0e2 +--- /dev/null ++++ b/tools/grit/grit/testdata/indexing_speed.html +@@ -0,0 +1,58 @@ ++<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ++<html><head><title>Google Desktop Search Index Speed</title> ++<meta http-equiv=content-type content="text/html; charset=utf-8"> ++<style> ++BODY { ++ MARGIN-LEFT: 3em; MARGIN-RIGHT: 3em; FONT-FAMILY: arial,sans-serif ++} ++</style> ++</head> ++<BODY text=#000000 vLink=#551a8b aLink=#ff0000 link=#0000cc bgColor=#ffffff> ++<TABLE cellSpacing=2 cellPadding=0 width="100%" border=0> ++ <tr> ++ <TD vAlign=top width="1%"><A href="[$~HOMEPAGE~$]"> ++ <IMG alt="Go to Google Desktop Search" src="/logo3.gif" border=0></A></td> ++ <td> </td> ++ <TD noWrap> ++ <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0> ++ <tr> ++ <TD bgColor=#3399CC><IMG height=1 alt="" width=1></td> ++ </tr> ++ </table> ++ <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0> ++ <tr> ++ <TD noWrap bgColor=#efefef><B> Index Speed</B></td> ++ <TD noWrap align=right bgColor=#efefef><FONT size=-1><A href="/customize.html">Index Speed ++ Help</A> | <A href="[$~ABOUT~$]"> About Google Desktop Search</A></font></td> ++ </tr></table></td></tr></table> ++<FONT size=-1> ++<p> ++To make your emails, files, and previously viewed web pages searchable, Google Desktop Search ++needs to index them. This indexing process is currently occuring in the background ++and your computer performance is minimally impacted. ++<p> ++You have the option of speeding up this process. ++<p><B><FONT color=#FF0000>Warning:</font></B> Speeding up indexing will cause your computer ++to become unusable for many minutes, depending on how many items need to be indexed. FAST INDEXING IS NOT ++RECOMMENDED. ++<BR> <BR> ++<FORM action="[$~SETINDEXSPEED~$]" method=GET> ++<input name=url value="[PREVPAGE]" type=hidden> ++<input type=radio name=FAST value="0" [FAST0-CHECKED] id=f0><label for=f0>Use background indexing (recommended)</label><br> ++<input type=radio name=FAST value="1" [FAST1-CHECKED] id=f1><label for=f1>Use fast indexing</label><br><br> ++<input type=submit value="Set Indexing Speed"> ++</FORM> ++<BR> ++ ++<p> <BR> ++<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0> ++<TR bgColor=#3399CC> ++ <TD align=middle height=1><IMG height=1 alt="" width=1></td></tr> ++</table> ++ ++<TABLE cellSpacing=0 cellPadding=0 width="100%" align=center bgColor=#efefef border=0> ++<tr> ++ <TD align=middle height=20><FONT size=-1><A href="[$~HOMEPAGE~$]">Google Desktop Search Home</A> - <a href="[$~STATUS~$]">Status</a> - <A href="[$~ABOUT~$]">About Google Desktop Search</A> - [$~BUILDNUMBER~$] - ©2005 Google </font> </td></tr> ++</table><BR> ++</body> ++</html> +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/install_prefs.html b/tools/grit/grit/testdata/install_prefs.html +new file mode 100644 +index 0000000000..eca0b56de5 +--- /dev/null ++++ b/tools/grit/grit/testdata/install_prefs.html +@@ -0,0 +1,92 @@ ++<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ++<html><head><title>Google Desktop Search: Initial Preferences</title> ++<meta http-equiv="cache-control" content="no-cache"> ++<meta http-equiv="content-type" content="text/html; charset=utf-8"> ++<meta http-equiv="pragma" content="no-cache"> ++<meta http-equiv="expires" content="-1"> ++<style> ++BODY { FONT-FAMILY: arial,sans-serif } ++.c:active { COLOR: #FF0000 } ++.c:visited { COLOR: #7777CC } ++.c:link { COLOR: #7777CC } ++</style> ++<script> ++<!-- ++override = 1; ++function ee() {if (override==1) {(new Image()).src="[COMPLETING]";}} ++// --> ++</script> ++</head><body leftmargin=30 rightmargin=30 onresize="stw()" onunload="ee()"> ++<form onsubmit='override=0;return true;' action='[STEP2]' name=f method=post> ++<img src="logo3.gif" border=0> ++<div id=c1 style="width:600px"> ++<br><font color=#00218a><b>To continue, please set these initial preferences:</b></font><br><br> ++<table border=0 id=t1 width=100%> ++<tr> ++ <td valign=top><input name=AIM id=chat type=checkbox checked></td> ++ <td> </td><td><label for=chat><font size=-1><B>Enable search over Instant Messenger chats</b><br> ++ <font size=-1>Google Desktop Search will store your chats and make them searchable. ++</font></label></td></tr> ++<tr height=1><td height=10px></td></tr> ++<tr> ++ <td valign=top><input name=HTTPS id=https type=checkbox checked></td> ++ <td> </td><td><label for=https><font size=-1><b>Enable search over secure web pages (HTTPS)</b> ++ <br><font size=-1>Google Desktop Search will store secure web pages that you view and make them ++ searchable.</font></label> </td></tr> ++<tr height=1px><td height=10px></td></tr> ++ ++<tr> ++ <td valign=top><input name=SEARCHBOX id=SEARCHBOX type=checkbox checked ++ onclick="handleSBClick(this)"></td> ++ <td> </td><td><label for=searchbox><font size=-1><b>Display search box</b></label> ++ <br><table border=0 cellpadding=0><tr><td valign=top> ++ ++<input type="radio" name="SBDISPLAY" id="DISPLAYDB" [DB-CHECKED] value="DISPLAYDB"></td><td> ++<label for=DISPLAYDB><font size=-1>Deskbar - A search box in your taskbar</font></label></td></tr> ++<tr><td></td></tr> ++<tr><td></td><td><img src="deskbar.gif" alt="Deskbar" width="268" height="34"></td></tr> ++<tr><td height=2></td></tr> ++<tr><td valign=top> ++ ++<input type="radio" name="SBDISPLAY" id="DISPLAYMB" [MB-CHECKED] VALUE="DISPLAYMB"></td><td> ++<label for=DISPLAYMB><font size=-1>Floating Deskbar - A search box that you can put anywhere on your desktop</font></label></td></tr> ++<tr><td></td></tr> ++<tr><td></td><td><img src="minibar.gif" width="137" height="27"></td></tr> ++<tr><td height=2></td></tr> ++ ++</table> ++</td></tr> ++ ++<tr> ++ <td valign=top><input name=SENDDATA id=usage type=checkbox checked></td> ++ <td> </td><td><label for=usage><font size=-1><b>Help us improve Google Desktop Search by sending usage data and crash reports</b></label> ++</font></td></tr> ++<tr height=8px><td colspan=3 height=8px></td></tr> ++<tr><td colspan=3><font size=-1>You can change these and other preferences at any time.</font></td></tr> ++</table></div> ++<p><input type=submit value="Set Preferences and Continue" id=s><br> ++</form> ++</center> ++[SCRIPT] ++<script> ++<!-- ++function handleSBClick(checkbox) { ++ document.getElementById("DISPLAYDB").disabled = !checkbox.checked; ++ document.getElementById("DISPLAYMB").disabled = !checkbox.checked; ++} ++function stw() { ++if (document.all && document.body.clientWidth < 600) { ++ var w = document.body.clientWidth-35; ++ if (w < 10) { w = 10; } ++ w = w + 'px'; ++ document.getElementById('c1').style.width=w; ++ return false; ++} ++document.getElementById('c1').style.width='600px'; ++} ++stw(); ++document.f.s.focus(); ++// --> ++</script> ++<img SRC="http://www.google.com" WIDTH="0" HEIGHT="0" ALIGN="right"></img> ++</body></html> +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/install_prefs2.html b/tools/grit/grit/testdata/install_prefs2.html +new file mode 100644 +index 0000000000..18380397c2 +--- /dev/null ++++ b/tools/grit/grit/testdata/install_prefs2.html +@@ -0,0 +1,52 @@ ++<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ++<html><head><title>Indexing has Started</title> ++<meta http-equiv="cache-control" content="no-cache"> ++<meta http-equiv="content-type" content="text/html; charset=utf-8"> ++<meta http-equiv="pragma" content="no-cache"> ++<meta http-equiv="expires" content="-1"> ++<style> ++BODY { FONT-FAMILY: arial,sans-serif } ++} ++</style> ++<script> ++<!-- ++override = 1; ++function ee() {if (override==1) {(new Image()).src="[COMPLETING]";}} ++// --> ++</script> ++</head><body leftmargin=30 rightmargin=30 onresize="stw()" onunload="ee()"> ++<form onsubmit='override=0;return true;' action="[STEP3]" name=f> ++<img src="/logo3.gif" border=0><br><br> ++<div id=c1 style="width:575px"> ++<table border=0 id=t1 width=100%><tr><td> ++<font color=#00218a><b>One-time indexing has started.</b></font><br><br> ++<font size=-1>An index is being prepared on your computer to allow you ++to search your information as fast as you can search the web.<br><br> ++<li>This is a one-time process that may take several hours. ++<li>You may continue to use your computer as usual and it is safe to shut down your computer. ++<li>Indexing will be performed only when your computer is idle. ++</ul> ++</font> ++<p><input type=submit value="Go to the Desktop Search homepage" name=s><br> ++</center> ++</td></tr></table> ++</form> ++</div> ++<script> ++<!-- ++function stw() { ++if (document.all && document.body.clientWidth < 575) { ++ var w = document.body.clientWidth-35; ++ if (w < 10) { w = 10; } ++ w = w + 'px'; ++ document.getElementById('c1').style.width=w; ++ return false; ++} ++document.getElementById('c1').style.width='575px'; ++} ++stw(); ++// --> ++document.f.s.focus(); ++</script> ++[SCRIPT] ++</body></html> +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/klonk-alternate-skeleton.rc b/tools/grit/grit/testdata/klonk-alternate-skeleton.rc +new file mode 100644 +index 0000000000000000000000000000000000000000..5f2c82a55469ddaab246c095826ad9e6743c0015 +GIT binary patch +literal 1088 +zcmbW0Pfr3t48`AhKZV)z#sGrI5!gjnU?DC>IT2z!82=r_L=!)}zjnmk5b$6oGo9&7 +z+t=4lu9UG-Ujxl_t%b{59ih$9PSBn!lW7`iGrKMm&Q10vTRK5!yRJHlRN`fcWril@ +zv|?uHM))d_NBa7`nW9TQ&PZ3tsax6ojav@U&9TYdHduz6k{G4GFTfpX_hk&`!z0F` +z!gJ>6WBh&UO&i_oS+VOvUfcD9JR=y&;3OxP2%KT$#JB9W=UtgQpDT@>(E^#^A;oG% +z4omjIK7rLXcRgmyS+%u_Gl2`MhOxMB{GGM&5o6cXF<vdhEe5Mu-+3OQZF~Ht$8Yl5 +z&=^M*j(xG~y3(sxz{#AtW^kPoyR!dZ9)}Sd$_6;Qjx#V<A+O@5j%7~Al)9jj*71v4 +z<zn{ZUuJA?73tB}iB6fJ)6H}8)1l|&XFq3N%P!P%;Wv{#b&7SVweIxDUCbEh>E~=G +z`!#F5=z%_bq95y7+aIx?IdcSN`A)xX^vZjCS7lnS#=iZ)E7W%eX8!kr-#RDO36^!o +Qqn&wY8qX0d7T}2V4SbP+*8l(j + +literal 0 +HcmV?d00001 + +diff --git a/tools/grit/grit/testdata/klonk.ico b/tools/grit/grit/testdata/klonk.ico +new file mode 100644 +index 0000000000000000000000000000000000000000..d371b214dc366249870efccc5da278d023aa91f1 +GIT binary patch +literal 766 +zcmeH_F%H5o5CqSFL>Ve71Sxq1;TtsMEB*!Fv6LbmDQFSUL1mXjO7OC0gpl|G?B1ML +zXS=a1V(2`di0U>FnQ~o{oUDnF5j(}bxAgSuhE8lMu~rkI8Ju%mb%Im^Xd<+ZwEgwd +zFTg+WQOj5lfvO*4mbEA^bCj9KHh65vjx^zvsKW{eA8|Ah`w&r;%!`QgmEiG3hXCcC +L+@V2V6oA7MJIRBx + +literal 0 +HcmV?d00001 + +diff --git a/tools/grit/grit/testdata/klonk.rc b/tools/grit/grit/testdata/klonk.rc +new file mode 100644 +index 0000000000000000000000000000000000000000..35652c4e6dd7cf7b7f62f637e191acf66f487235 +GIT binary patch +literal 9824 +zcmeI2+j1L48poSUd<zdSObP?FE=Nu{E-aL6%Z`X;t1MXwwb^nxw&R#MQm|was(2h8 +z0*VVRxZyQ;25z?&e*drad1j>1!LS!j6*Z-q>7MTIeClrf{=b{yW=KLKoQA`29(tkA +z?@<`g*P*W;F2X@LqqP?P!IgxQa2&e)&gmcUJfiQMr{-PocF21|OVCckGsY~31#sNt +zeuJJaU(OhLWaHAYxy#{kNExfq8uQ5J2xc`jLo2kyURV$HuoL#fZm7|_&ii)Q3SZFE +z;@$|W^lb4S@e23#yIdxsED4)%Ix5vi$fg&b@^yerB!M>k-sfJ2-!(XtBx>~E;y0>; +zywqpO@eUBz4c2yv49m3k+_Z88eb3Rg>+A-4?GCk8rmyLEuD7;k@iyBQuQz|u4r}P| +z1pk!hKgO!w#>STMq~-8ViH-G#etL?RCgF{OzaBBS8aA-k=%+1wau1JP!(#WbwJk2e +z{FW=3II|6mUA$wTS=-Ei$KrzUMVn6ea?kwXHeRp*%qrtH8Cm5n-|(IYVUu<pe(r=N +zzO@*)I&s84Ull`c5XBVjPVmJ8W*uVn!oE+xdXM3B1?=zfi}cBtkC36HBDof6y#96& +zDNK-*c<mwsaiN$Tt;G8iy#LgqQ-aMX7AOxWcPO4D;cMihSg+XijJE^e#f+h-em)#K +zU}i#pm$ov9MjtR<GnAE-XHJcd#M&7}G3rSx$}4^5MSA<RMTcOD8qE;QGcM((Z-!r= +z@>HA@wRN;~7h6y+xyz_&R~;+XxM^eZ-_q~|%%b86_{3Asa-8FBk+Z7c-kJgN>UjHR +zv*J6C_vNv`hUxGkXMvL0T0vKhVQf$p6QjfeUR}fgl_wW2W!gk%O?<jZPZ}19O{d7^ +z*finVDx2ru9D3dIaKoU~fb#-41E46PT;&oc4LDIw7tD-Ohf;>IO<b0BC*h%aN($z? +zm)50Lg3jeb@}4KgpHn7``|w@I(iDZ;#6d+vaXpT`D6f;D{i-%|`usUfYCfinmyGTN +zIW7V>a`tbcYLDwE{AY?>BR88vkIj3pcp9ftwy~b;A8i-;T|_p=$nY5yWU!`jTE^ib +ze*F+mE-Vf$<AuvpIC5FVr`t!>>e;=5g*fg0^w_NUeElxZA2EAWiGRui^1Zl<=<)P1 +zF&Y;=yo$%KVIA>VGwa=@)kgQbrt31jq~WuvvL2VO`$<s`-l~FW4S%T*JzWty@3kqC +zpB4rFU-(`|ov-8B%D+84yQpbJq|Cy#a=VYFm5(Lg9joHhbBjy*SqUH5^H#VWD)#mP +zmDd8gX|wiIT+{3pP+PpWiFV4=ZF*H_#xD)})(!p!_EWXI5x?KFnQQblnWI&vvb<)- +zFIrzJTT2IfU>zNqGSmHCaU;Y2q0yQ$JF7mTwL~ub{sOMb^Vh8GFZ(K1F-x>#wroJR +z&tF1@??TN-{BD^Hb<bj)tU9hU-SUgid^Mw80(r42u2^L$1ARm5q2(uK*A(fk5cewP +z9Zr$-B@Y%=OVA@~R*aezo@z;A8C69Z##=4Z+%_6(qSKmXx%;{Kv$<M>gJ;mLeTx&a +ztSZO1p-!t5NvMLINn_JEi1N%h$mrKfeZ%Sxtv*(<o;FujMW(#py@aoK$>Sq%E`|5` +zMQa!2rJ*fu!l%|$%^a7pE^XVFE$AM-((pNcct~BK8YqR1Sd~Aqmi*&@D)rQ&bN`YW +zMPvC%+;<TLnyH+o+P!PzGEPTvj<#1#Q&p3I;<v-i%S09-uHQ3$KQw!lbu5_YDT~KE +zq3F><0?G_uSf2bldXz_x`Rp$tXUa07m0#5g^O>n*TJE4PW#|}5_jztxOjO*+fAM}< +zk=Lii5sD#879SKTSIp++>5AlgXumxIv246U-XKqCe;}^ATDIP+P{%8`Yynw2Uilpc +z$xha}X;{ahB+#YVajq(xJ|2|kCBqoURxZc-PC<V34wS`l@7lObCdzS5sL5l@zQ+BG +z;+Tl3tUl7t#}1OyYFBw_V3AMzKfW@m<J*t$@OdlXBE$+_TOoq!`H*`aipPX9y8N3z +zJLpP#o#HyZq-`Au=XaT7{)rj2n4zkrdkJOKOvhNvbdE_@DQ#r;l~PX2VN1f=r#R=S +z`e>WGR&NeH+c%h>-Yw>z7_{+>=5WWql;yg~F}<jhong+@E{wQv`%$Z$n`LNxVSLVu +zqX`bJ2rtN9gE2WJxg8d*6Uugv=9gd**I(1S$3)lvXuIe$9VB*sDZi`wUr{S<ASs*o +zEyw#FTC@PgtLUAvrjGSZrVFRipYc2<9~H+>V-&+XR>jna$uG|ylUKW<KRZ>)Rw*m^ +z_oOjp@vHny>%lMrW)jt@&DG$}J`tOC!twxncz`|R{U9wplS^%1SD7h)zLPS$9KxSJ +z^(luqF00#DmestFZxDq%2fL5@KE>#H<EVwdOuH`m{4TpYASY`FCbM&`$abwl+vH7a +za;>I|)#R(g69An@YFD|(_t^K?Y(=LYvGR$s)LKbvaYc(JPp$Xb2G?a>eC9KE-cEhZ +zHSZ3+_C$Rze-w`BSsn7ZgI%TJO=9FfdDBy)V;pqaYpnOHjNdZ)cZhIWOV;71NPE_b +z5ZwYd@EV=tI))^?mN>3>KBO~=3-s|NvQu_bO!m`Xy&s`1RS8A9bec9lO`@(ym$)sX +zMVVq?wjta)kvTJp%Bk>bSh}4@HcmwuW}T<$ta~!gT03ja*d|hI1w9*Uk>}TwPvL12 +z=Q{J$UgQ8RXmu+(2GDd)J#{>6mrEh;W{57|8=6JgB)U>?#`vQXEaBEZgsP}6H0c~I +zlTn_wQLB~3>U1IQ2y}Rh=cM|##66Rnd!p7F(K=LbM6B`LtO3?OS3Ko>03~gD6g5tu +zOSRooa>4*SqvO;gSO;d)IuFc4e&rSY3#4arR~e}tmqXie5w!0rzg2#y{KWm2%CD85 +zD?e8LTlv1?UR>st9pKlDtGM^mfuA&df=7MIT`QQ#k8mnxoriygx5#|&^UZ&6F?Nx! +z2jMH^+zTJm>H?vU#6L!6XLz9~{RHheL_xo4SVUcx*(c|e8ZfVRzJC37^PM7DoUXW9 +zRu0v_b;|ztF`73W!u5N4HWX!l^<O!vStkE0N0PgK{5wU`>ZH1;i+3m{&0Ya4gg*c` +C>9bG( + +literal 0 +HcmV?d00001 + +diff --git a/tools/grit/grit/testdata/ko_oem_enable_bug.html b/tools/grit/grit/testdata/ko_oem_enable_bug.html +new file mode 100644 +index 0000000000..f2c199cc15 +--- /dev/null ++++ b/tools/grit/grit/testdata/ko_oem_enable_bug.html +@@ -0,0 +1 @@ ++<IMG style="VERTICAL-ALIGN: middle" height=16 alt=아웃룩 src="/email.gif" width=16> +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/ko_oem_non_admin_bug.html b/tools/grit/grit/testdata/ko_oem_non_admin_bug.html +new file mode 100644 +index 0000000000..b9e8a1f288 +--- /dev/null ++++ b/tools/grit/grit/testdata/ko_oem_non_admin_bug.html +@@ -0,0 +1 @@ ++<INPUT id=s type=submit value=" 확인 "> +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/mini.html b/tools/grit/grit/testdata/mini.html +new file mode 100644 +index 0000000000..8ac0a231a0 +--- /dev/null ++++ b/tools/grit/grit/testdata/mini.html +@@ -0,0 +1,36 @@ ++<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ++<html><head> ++<meta http-equiv=content-type content="text/html; charset=windows-1252"> ++<meta http-equiv="cache-control" content="no-cache"> ++<meta http-equiv="pragma" content="no-cache"> ++<meta http-equiv="expires" content="-1"> ++<style> ++BODY { FONT-SIZE: 8pt; FONT-FAMILY: verdana,arial,san-serif } ++P { FONT-SIZE: 8pt; FONT-FAMILY: verdana,arial,san-serif } ++TD { FONT-SIZE: 8pt; FONT-FAMILY: verdana,arial,san-serif } ++A { FONT-SIZE: 8pt; FONT-FAMILY: verdana,arial,san-serif } ++DIV { FONT-SIZE: 8pt; TEXT-DECORATION: none } ++A:hover { COLOR: #ffffff } ++.border { BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px } ++</style> ++</head> ++ ++<BODY bottomMargin=0 bgColor=#3300cc leftMargin=0 topMargin=0 rightMargin=0 marginwidth="0" marginheight="0"> ++ ++<TABLE cellSpacing=0 cellPadding=0 bgColor=#3300cc border=0><TBODY> ++<tr><TD vAlign=top> ++ ++<TABLE cellSpacing=0 cellPadding=0 bgColor=#3300cc border=0><TBODY> ++ ++<tr> ++<TD vAlign=top> <INPUT style="position:relative; height=17px;" class=border size=10> </td> ++ ++<TD class=ch onmouseover="this.bgColor='6666FF'" style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #6666cc 1px solid; BORDER-LEFT: #6666cc 1px solid; BORDER-BOTTOM: #000000 1px solid" onmouseout="this.bgColor='#000099'" vAlign=center align=middle bgColor=#000099><img height=1 width=1><IMG src="logo.gif" align=middle><img height=1 width=1></td> ++ ++</TBODY></table> ++</td> ++ ++<TD width=2><IMG height=1 width=1></td> ++ ++<TD vAlign=top><TABLE cellSpacing=0 cellPadding=1><TBODY> ++<tr><TD class=ch onmouseover="this.bgColor='6666FF'" style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #6666cc 1px solid; BORDER-LEFT: #6666cc 1px solid; BORDER-BOTTOM: #000000 1px solid" onmouseout="this.bgColor='#000099'" vAlign=top noWrap bgColor=#000099><IMG src="mini_close.gif"></td></tr></TBODY></table></td></tr></TBODY></table></body></html> +diff --git a/tools/grit/grit/testdata/oem_enable.html b/tools/grit/grit/testdata/oem_enable.html +new file mode 100644 +index 0000000000..db6b85eca6 +--- /dev/null ++++ b/tools/grit/grit/testdata/oem_enable.html +@@ -0,0 +1,106 @@ ++<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ++<html><head><title>Google Desktop Search Download</title> ++<meta http-equiv=content-type content="text/html; charset=utf-8"> ++<style>BODY { ++ FONT-FAMILY: arial,sans-serif ++} ++TD { ++ FONT-FAMILY: arial,sans-serif ++} ++DIV { ++ FONT-FAMILY: arial,sans-serif ++} ++.p { ++ FONT-FAMILY: arial,sans-serif ++} ++A { ++ FONT-FAMILY: arial,sans-serif ++} ++DIV { ++ COLOR: #000 ++} ++TD { ++ COLOR: #000 ++} ++A:link { ++ COLOR: #00c ++} ++A:visited { ++ COLOR: #551a8b ++} ++</style> ++ ++<meta content="mshtml 6.00.2800.1476" name=generator></head> ++<body> ++<center> ++<TABLE cellSpacing=0 cellPadding=0 border=0> ++ <TBODY> ++ <TR vAlign=center> ++ <td> ++ <DIV align=center><IMG height=55 alt="Google Desktop Search" ++ src="/logo3.gif" width=150 border=0 search="" ++ desktop=""></DIV></td> ++ <td> </td> ++ <td><FONT size=+1><B>Search your own ++computer.</B></font></td></tr></TBODY></table><BR> ++<TABLE cellSpacing=0 cellPadding=0 width=630 border=0> ++ <TBODY> ++ <tr> ++ <TD vAlign=top width="53%"><FONT size=-1> ++ <LI>Find your email, files, web history and chats instantly <NOBR> ++ <LI>View web pages you've seen, even when you're not online</NOBR> ++ <LI>Search as easily as you do on Google ++ <p><B>Google Desktop Search finds:</B></p></font> ++ <TABLE cellSpacing=1 cellPadding=0 width=325 border=0 valign="center"> ++ <TBODY> ++ <TR vAlign=center> ++ <TD colSpan=3><FONT size=-1><IMG style="VERTICAL-ALIGN: middle" ++ height=16 alt=Outlook src="/email.gif" ++ width=16> Email from Outlook, Outlook Express, & ++ Thunderbird</font></td></tr> ++ <tr> ++ <TD noWrap colSpan=3><FONT size=-1><IMG ++ style="VERTICAL-ALIGN: middle" height=16 alt="Internet Explorer" ++ src="/html.gif" width=16> Web history ++ from IE/Firefox/Mozilla/Netscape</font></td></tr> ++ <tr> ++ <TD noWrap colSpan=3><FONT size=-1><IMG ++ style="VERTICAL-ALIGN: middle" height=16 alt=Text ++ src="/file.gif" width=16> Files in Word, ++ Excel, Powerpoint, PDF, & media formats</font></td></tr> ++ <tr> ++ <TD vAlign=top colSpan=3><FONT size=-1><IMG ++ style="VERTICAL-ALIGN: middle" height=16 alt="AOL IM" ++ src="/aim.gif" width=16> Chats from AOL ++ Instant Messenger</font></td></tr> ++ <tr> ++ <TD noWrap><FONT size=-1> </font></td></tr></TBODY></table><FONT ++ size=-1> </font><FONT size=-1><A ++ href="http://desktop.google.com/about.html">About Desktop ++ Search</A> <A ++ href="http://desktop.google.com/screenshots.html">Screenshots</A> ++ <A href="http://desktop.google.com/support">Help</A> <A ++ href="http://desktop.google.com/feedback.html">Contact ++ Us</A><BR></font></LI></td> ++ <td> </td> ++ <TD vAlign=top width="53%"> ++ <TABLE cellPadding=2 width="100%" align=center> ++ <TBODY> ++ <tr> ++ <TD ++ style="BORDER-RIGHT: rgb(204,204,204) 1px solid; BORDER-TOP: rgb(204,204,204) 1px solid; BORDER-LEFT: rgb(204,204,204) 1px solid; BORDER-BOTTOM: rgb(204,204,204) 1px solid" ++ width="100%" bgColor=#e7eff7 blah2="#fff8dd" blah="#e7eaf7"><BR> ++ <center><FONT size=-1>By using, you agree to our <A ++ href="http://desktop.google.com/eula.html"><BR>Terms & ++ Conditions</A> and <A ++ href="http://desktop.google.com/privacypolicy.html">Privacy ++ Policy</A></font></center> ++ <p></p> ++ <FORM action='[STEP2]'> ++ <P align=center><INPUT style="PADDING-RIGHT: 3px; PADDING-LEFT: 3px; FONT-WEIGHT: bold; FONT-SIZE: 17px; PADDING-BOTTOM: 4px; PADDING-TOP: 4px" type=submit value="Agree and Start Using" name=Submit> ++ </p></FORM><FONT size=-2>* Automatically starts when you turn on ++ your computer</font> </td></tr></TBODY></table> ++ <p></p></td></tr></TBODY></table></center> ++<p></p> ++<center><FONT color=#666666 size=-2>©2005 Google</font> ++<p></p></center></body></html> +diff --git a/tools/grit/grit/testdata/oem_non_admin.html b/tools/grit/grit/testdata/oem_non_admin.html +new file mode 100644 +index 0000000000..8b7ca13e21 +--- /dev/null ++++ b/tools/grit/grit/testdata/oem_non_admin.html +@@ -0,0 +1,39 @@ ++<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ++<html><head><title>Google Desktop Search Preferences</title> ++<meta http-equiv=cache-control content=no-cache> ++<meta http-equiv=content-type content="text/html; charset=utf-8"> ++<meta http-equiv=pragma content=no-cache> ++<meta http-equiv=expires content=-1> ++<style>BODY { ++ FONT-FAMILY: arial,sans-serif ++} ++.c:active { ++ COLOR: #ff0000 ++} ++.c:visited { ++ COLOR: #7777cc ++} ++.c:link { ++ COLOR: #7777cc ++} ++</style> ++ ++<script> ++<!-- ++override = 1; ++function ee() {if (override==1) {(new Image()).src="/doneinstallprefs&s=3286011577";}} ++// --> ++</script> ++ ++<meta content="mshtml 6.00.2800.1476" name=generator></head> ++<BODY onresize=stw() leftMargin=30 rightMargin=30 onunload=ee()> ++<FORM name=f onsubmit=javascript:window.close();><IMG ++src="/logo3.gif" border=0> ++<DIV id=c1 style="WIDTH: 600px"> ++<p><BR><FONT color=#00218a><B>We're sorry, but you need administrator access to ++enable Desktop Search.</B></font></p><FONT size=-1> ++<p>To install or run Google Desktop Search you need administrator access on this ++computer. Please try installing again once you have administrator ++access.</p></font></DIV> ++<p><INPUT id=s type=submit value= OK > <BR></p> ++<center></center></FORM></body></html> +diff --git a/tools/grit/grit/testdata/onebox.html b/tools/grit/grit/testdata/onebox.html +new file mode 100644 +index 0000000000..c24ff043a5 +--- /dev/null ++++ b/tools/grit/grit/testdata/onebox.html +@@ -0,0 +1,21 @@ ++<html><head><title>Google Desktop Search Results</title> ++<style><!-- ++body,td,div,.p,a{font-family:arial,sans-serif } ++body{ background-color: transparent } ++div,td{color:#000} ++.f,.fl:link{color:#6f6f6f} ++a:link,.w,a.w:link,.w a:link{color:#00c} ++a:visited,.fl:visited{color:#551a8b} ++a:active,.fl:active{color:#f00} ++.t a:link,.t a:active,.t a:visited,.t{color:#000} ++//--> ++</style> ++</head> ++<body> ++<table cellspacing=0 cellpadding=1 border=0 ID="Google Desktop Search"> ++<tr><td colspan=2><nobr><a href="http://[WEBSERVER][$~QUERY~$]" target=_parent>[NUMRESULTS] [RESULT-STRING] stored on your computer</a><font size=-1> - <a href="[HIDENOW]" style="color:#7777cc;" target=_parent>Hide</a> - <a href="http://desktop.google.com/integration.html" style="color:#7777cc;" target=_parent>About</a></font></nobr></td></tr> ++<tr><td valign=top width=40><img height=27 style="margin-top:2px;" src="http://[WEBSERVER]/onebox.gif"></td> ++<td valign=top width="99%"><font size=-1>[RESULTS]</font></td></tr> ++</table> ++</body> ++</html> +diff --git a/tools/grit/grit/testdata/oneclick.html b/tools/grit/grit/testdata/oneclick.html +new file mode 100644 +index 0000000000..32dc6459dd +--- /dev/null ++++ b/tools/grit/grit/testdata/oneclick.html +@@ -0,0 +1,34 @@ ++[HEADER] ++ ++ ++<TABLE cellSpacing=4 cellPadding=0 width="100%" border=0> ++<tr> ++ <TD vAlign=top align=left width=50%> ++ [EMAIL_TOP_CHROME] ++ ++ <p class=f> ++ <TABLE cellSpacing=6 cellPadding=0 width="100%" border=0> ++ [EMAIL] ++ </table> ++ </td> ++ ++ ++ <TD width=1 align=middle bgColor=#cfcfcf><IMG height=1 width=1></td> ++ <TD width=50% vAlign=top align=left> ++ [FREQ_TOP_CHROME] ++ <p class=f> ++ <TABLE cellSpacing=6 cellPadding=0 width="100%" border=0 ID="Table1"> ++ [$~FREQ~$] ++ </table> ++ <p class=g> ++ [RECENT_TOP_CHROME] ++ <TABLE cellSpacing=6 cellPadding=0 width="100%" border=0 ID="Table2"> ++ [$~RECENT~$] ++ </table> ++ </td> ++ </tr> ++</table> ++<center><BR> ++ ++ ++[FOOTER] +diff --git a/tools/grit/grit/testdata/password.html b/tools/grit/grit/testdata/password.html +new file mode 100644 +index 0000000000..16007a1ac0 +--- /dev/null ++++ b/tools/grit/grit/testdata/password.html +@@ -0,0 +1,37 @@ ++<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ++<html><head><title>Password Required</title> ++<meta http-equiv="content-type" content="text/html; charset=utf-8"> ++<meta http-equiv="cache-control" content="no-cache"> ++<meta http-equiv="pragma" content="no-cache"> ++<meta http-equiv="expires" content="-1"> ++<style> ++BODY,TD,A,P {FONT-FAMILY: arial,sans-serif} ++.q {COLOR: #0000cc} ++</style> ++<script> ++<!-- ++function sf(){document.f.q.focus();} ++// --> ++</script> ++</head> ++<body text=#000000 vLink=#551a8b aLink=#ff0000 link=#0000cc bgColor=#ffffff onload=sf()> ++<center> ++<table cellSpacing=0 cellPadding=0 border=0> ++<tr><td><a href="[$~HOMEPAGE~$]"><IMG border=0 height=110 alt="Google Desktop Search" src="hp_logo.gif" width=276></a></td></tr></table><BR> ++<form name=f method=GET action='/password'> ++<table cellSpacing=0 cellPadding=4 border=0> ++<tr><td class=q noWrap><font size=-1> ++ <table cellSpacing=0 cellPadding=0> ++ <tr vAlign=top> ++ <td align=middle>Password required: <input maxLength=80 size=30 type=password name=pw value=""> ++ <script> ++ document.f.q.focus(); ++ </script> ++ <input type=submit value="Submit" name=submit> ++ </td></tr> ++ </table> ++ </form> ++</td></tr> ++</table> ++<br><font size=-1>[$~BOTTOMLINE~$]</font></p> ++<p><font size=-2>©2005 Google</font></p></center></body></html> +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/preferences.html b/tools/grit/grit/testdata/preferences.html +new file mode 100644 +index 0000000000..b37412436b +--- /dev/null ++++ b/tools/grit/grit/testdata/preferences.html +@@ -0,0 +1,234 @@ ++<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ++"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ++<html><head><title>Google Desktop Search Preferences</title> ++<meta http-equiv=content-type content="text/html; charset=utf-8"> ++<style> ++body { ++ margin-left: 2em; margin-right: 2em; ++ font-family: arial,sans-serif; ++ color:#000; background-color:#fff; ++} ++a:active { color:#f00 } ++a:visited { color:#551a8b } ++a:link { color:#00c } ++a.c:active { color: #ff0000 } ++a.c:visited { color: #7777cc } ++a.c:link { color: #7777cc } ++.b { font-weight: bold } ++.shaded-header { background-color: #e8f4f7; border-top: 1px solid #39c; ++margin: 0px; padding: 0px } ++.shaded-subheader { background-color: #e8f4f7; margin: 12px 0px 0px 0px; ++ padding: 0px } ++.plain-subheader { background-color: #fff; margin: 12px 0px 0px 0px; ++ padding: 0px } ++.header-element { margin: 0px; padding: 2px} ++.expand { width: 98% } ++.s { font-size: smaller } ++.prefgroup { border: 2px solid #e8f4f7; width: 100% } ++.phead { font-weight: bold; font-size: smaller; vertical-align: top; ++text-transform: capitalize; border-bottom: 2px solid #e8f4f7; margin: 0px; ++padding: 8px} ++.pbody { border-bottom: 2px solid #e8f4f7; margin: 0px; ++padding: 8px} ++.pref-last { border-bottom: 0px } ++.example { color: gray; font-family: monospace; } ++</style> ++<script> ++<!-- ++function validate() {} ++function fnOnClickAll() {for (var i = 0; i < document.langform.lr.length; i++) { ++document.langform.lr[i].checked = false;}} ++function fnOnClickSome() { ++var count = 0;for (var i = 0; i < document.langform.lr.length; i++) { ++if (document.langform.lr[i].checked) {count++;}} ++document.langform.lang[0].checked = (count <= 0); ++document.langform.lang[1].checked = (count > 0);} ++// --> ++</script> ++</head> ++<body onload="checkOffice()"> ++<form name=prefs action="[$~SETPREFS~$]" method=post><input name=url ++value="[PREVPAGE]" type=hidden> ++<table cellspacing=2 cellpadding=0 width="100%" border=0> ++<tr> ++<td valign=top width="1%"><a href="[$~HOMEPAGE~$]"> ++<img alt="Go to Google Desktop Search" src="logo3.gif" border=0></a></td> ++<td> </td> ++<td nowrap> ++ ++<table class="shaded-header"><tr> ++<td class="header-element b expand">Preferences</td> ++<td class="header-element s"> ++<a href="http://desktop.google.com/preferences.html">Preferences Help</a> ++</td> ++</tr></table> ++ ++</tr></table> ++ ++<table class="shaded-subheader"><tr> ++<td class="header-element expand s"> ++<span class="b">Save</span> your preferences when finished.</td> ++<td class="header-element"><input type=submit value="Save Preferences" ++name=submit2></td> ++</tr></table> ++ ++[STATUS-MESSAGE] ++<table class="plain-subheader"><tr> ++<td class="header-element expand"><span class="b">Preferences</span><span ++class="s"> (changes apply to Google Desktop Search application)</span></td> ++</tr></table> ++ ++<table class="prefgroup" cellpadding=0 cellspacing=0> ++ ++<!-- --> ++<tr> ++<td class="phead">Search types</td> ++<td class="pbody"><div class="s">Index the following items so that you can ++search for them:<br /> </div> ++<div> ++ <table border=0> ++ <tr> ++ <td width=150 nowrap valign=top><span class="s"> ++ <input type=checkbox [CHECK-EMAIL] name=EMAIL id=h3><label for=h3> ++ Email</label><br> ++ <input type=checkbox [CHECK-AIM] name=AIM id=h5><label for=h5> Chats ++ (AOL/MSN IM)</label><br> ++ <input type=checkbox onclick='if(!this.checked){h12.checked=0;h12.disabled=1;} ++ else {h12.disabled=0;}' [CHECK-WEB] name=WEB id=h11><label for=h11> Web ++ history</label> ++ ++ </span></td> ++ <td width=120 nowrap valign=top><span class="s"> ++ <script> ++<!-- ++function checkOffice() { var w = document.getElementById("h7"); ++var e = document.getElementById("h8"); var o = document.getElementById("h10"); ++if (!(w.checked || e.checked)) { o.checked=0;o.disabled=1;} else {o.disabled=0;} } ++// --> ++ </script> ++ <input type=checkbox [CHECK-DOC] name=DOC id=h7 onclick='checkOffice()'> ++ <label for=h7> Word</label><br> ++ <input type=checkbox [CHECK-XLS] name=XLS id=h8 onclick='checkOffice()'> ++ <label for=h8> Excel</label><br> ++ <input type=checkbox [CHECK-PPT] name=PPT id=h9> ++ <label for=h9> PowerPoint</label><br> ++ </span></td><td nowrap valign=top><span class="s"> ++ <input type=checkbox [CHECK-PDF] name=PDF id=hpdf> ++ <label for=hpdf> PDF</label><br> ++ <input type=checkbox [CHECK-TXT] name=TXT id=h6> ++ <label for=h6> Text, media, and other files</label><br> ++ </tr> ++ <tr><td nowrap valign=top colspan=3><span class="s"><br /> ++ <input type=checkbox [CHECK-SECUREOFFICE] name=SECUREOFFICE id=h10> ++ <label for=h10> Password-protected Office documents (Word, Excel)</label><br /> ++ <input type=checkbox [DISABLED-HTTPS] [CHECK-HTTPS] name=HTTPS id=h12><label ++ for=h12> Secure pages (HTTPS) in web history</label></span></td></tr> ++</table> ++</div></td></tr> ++</div> ++</td> ++</tr> ++ ++<!-- --> ++<tr> ++<td class="phead">Plug-ins</td> ++<td class="pbody"><div class="s" ++style="display:[ADDIN-DISPLAYSTYLE]">Index these additional items:<p> ++[ADDIN-DO] ++[ADDIN-OPTIONS]</div><div class="s"> ++To install plug-ins to index other items, visit the ++<a href="http://desktop.google.com/plugins.html">Plug-ins Download page</a>.</div> ++</tr> ++ ++<!-- --> ++<tr> ++<td class="phead">Don't search these items</td> ++<td class="pbody"><div class="s"> ++<label for=FORBIDDEN>Do not search web sites with the following URLs or files ++with the following paths. Put each entry on a separate line. Examples:</label><br> ++<span class="example">c:\Documents and Settings\username\Private Stuff</span><br> ++<span class="example">http://www.domain.com/</span><br> ++<div> </div> ++<div><TEXTAREA rows=3 cols=65 name=FORBIDDEN id=FORBIDDEN>[FORBIDDEN] ++</TEXTAREA></div> ++</tr> ++ ++<!-- --> ++<tr> ++<td class="phead pref">Search Box Display</td> ++<td class="pbody pref" valign=top> ++ ++<table border=0 cellpadding=0><tr><td valign=top> ++ ++<input type="radio" name="SBDISPLAY" id="DISPLAYDB" [CHECK-DISPLAYDB] value="DISPLAYDB"></td><td> ++<label for=DISPLAYDB><font size=-1>Deskbar - A search box in your taskbar</font></label></td></tr> ++<tr><td></td></tr> ++<tr><td></td><td><img src="deskbar.gif" alt="Deskbar" width="268" height="34"></td></tr> ++<tr><td height=2></td></tr> ++<tr><td valign=top> ++ ++<input type="radio" name="SBDISPLAY" id="DISPLAYMB" [CHECK-DISPLAYMB] VALUE="DISPLAYMB"></td><td> ++<label for=DISPLAYMB><font size=-1>Floating Deskbar - A search box you can put anywhere on your desktop</font></label></td></tr> ++<tr><td></td></tr> ++<tr><td></td><td><img src="minibar.gif" width="137" height="27"></td></tr> ++<tr><td height=2></td></tr> ++<tr><td valign=top> ++ ++<input type=radio name="SBDISPLAY" id="DISPLAYNONE" [CHECK-DISPLAYNONE] VALUE="DISPLAYNONE"></td><td valign=top> ++<label for=DISPLAYNONE><font size=-1> None</font></label> ++</td></tr> ++</table> ++ ++</td></tr> ++ ++<!-- --> ++<tr> ++<td class="phead pref">Number of Results</td> ++<td class="pbody pref"><label for=num><span class="s"> ++Display <select name=num id="num"> ++<option [CHECK-NUM-10]>10 ++<option [CHECK-NUM-20]>20 ++<option [CHECK-NUM-30]>30 ++<option [CHECK-NUM-50]>50 ++<option [CHECK-NUM-100]>100</select> ++ results per page</span></label> ++</td> ++</tr> ++ ++<!-- --> ++<tr> ++<td class="phead">Google integration</td> ++<td class="pbody"> ++<table border=0 cellpadding=0> ++<tr><td><input type=CHECKBOX name=ONEBOX [CHECK-ONEBOX] id=onebox></td> ++<td><label for=onebox> ++ <span class="s">Show Desktop Search results on Google Web Search result pages. ++ </span></label></td></tr> ++ <tr><td></td><td> ++ <span class="s">Your personal results are private from Google.</span> ++ </td></tr></table> ++</td> ++</tr> ++ ++<!-- --> ++<tr> ++<td class="phead pref-last">Help us improve</td> ++<td class="pbody pref-last"> ++<input type=CHECKBOX name=SENDDATA id="SENDDATA" [CHECK-SENDDATA]><label for= ++SENDDATA> <span class="s">Send non-personal usage data and crash reports to ++Google to help improve Desktop Search.</span></label> ++</td> ++</tr> ++ ++</table> ++ ++<table class="shaded-subheader"><tr> ++<td class="header-element expand s"><span class="b">Save</span> your preferences ++when finished.</td> ++<td class="header-element"><input type=submit value="Save Preferences" ++name=submit2></td> ++</tr></table> ++ ++<p><div align=center>[$~BOTTOMLINE~$]</div> ++<br><center><span class="s">©2005 Google</span></center> ++</form></body></html> +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/preprocess_test.html b/tools/grit/grit/testdata/preprocess_test.html +new file mode 100644 +index 0000000000..13ece9a9f6 +--- /dev/null ++++ b/tools/grit/grit/testdata/preprocess_test.html +@@ -0,0 +1,7 @@ ++<if expr="True"> ++should be kept ++</if> ++in the middle... ++<if expr="False"> ++should be removed ++</if> +diff --git a/tools/grit/grit/testdata/privacy.html b/tools/grit/grit/testdata/privacy.html +new file mode 100644 +index 0000000000..1d45f4a539 +--- /dev/null ++++ b/tools/grit/grit/testdata/privacy.html +@@ -0,0 +1,35 @@ ++[!] ++title Privacy and Google Desktop Search ++template ++privacy_bottomline ++hp_image ++ ++<TABLE CELLSPACING=0 CELLPADDING=5 WIDTH="98%" BORDER=0> ++<TR VALIGN=TOP> ++<td> ++<h4>Privacy and Google Desktop Search</h4> ++ ++<p><FONT SIZE=-1>Google is committed to making search on your desktop as easy ++as searching the web. We recognize that privacy is an important issue, ++so we designed and built Google Desktop Search with respect for your privacy. ++<p> ++So that you can easily search your computer, the Google Desktop Search application indexes ++and stores versions of your files and other computer activity, ++such as email, chats, and web history. These versions may also be mixed ++with your Web search results to produce ++results pages for you that integrate relevant content from your computer and ++information from the Web. ++<p> ++Your computer's content is not made accessible to Google or anyone else without your explicit permission. ++ ++<p>You can read the ++<A HREF='http://desktop.google.com/privacypolicy.html?hl=[LANG_CODE]'>Privacy Policy</A> ++and <A HREF='http://desktop.google.com/privacyfaq.html?hl=[LANG_CODE]'>Privacy FAQ</A> online. ++</font> ++</td></tr></table> ++ ++<center><br> ++<TABLE CELLSPACING=0 CELLPADDING=0 WIDTH="100%" BORDER=0> ++<TR BGCOLOR=#3399CC><TD ALIGN=MIDDLE HEIGHT=1><IMG HEIGHT=1 ALT="" WIDTH=1></td></tr></table> ++<FONT SIZE=-1>[$~PRIVACY_BOTTOMLINE~$] - ©2005 Google </font> ++</center> +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/quit_apps.html b/tools/grit/grit/testdata/quit_apps.html +new file mode 100644 +index 0000000000..a501b0e2bf +--- /dev/null ++++ b/tools/grit/grit/testdata/quit_apps.html +@@ -0,0 +1,49 @@ ++<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ++<html><head><title>Google Desktop Search Preferences</title> ++<meta http-equiv=cache-control content=no-cache> ++<meta http-equiv=content-type content="text/html; charset=utf-8"> ++<meta http-equiv=pragma content=no-cache> ++<meta http-equiv=expires content=-1> ++<style>BODY { ++ FONT-FAMILY: arial,sans-serif ++} ++.c:active { ++ COLOR: #ff0000 ++} ++.c:visited { ++ COLOR: #7777cc ++} ++.c:link { ++ COLOR: #7777cc ++} ++</style> ++ ++<script> ++<!-- ++// --> ++</script> ++ ++<meta content="mshtml 6.00.2800.1476" name=generator></head> ++<BODY onresize=stw() leftMargin=30 rightMargin=30> ++<FORM name=f action='[NEXTSTEP]' method=post><IMG src="/logo3.gif" ++border=0> ++<DIV id=c1 style="WIDTH: 600px"> ++<p><BR><FONT color=#00218a><B>To start using Google Desktop Search, we may need to close the following programs if they are running:</B></font></p> ++<FONT size=-1><p>You can start these programs once Google Desktop Search is running.</p></font> ++ ++<LI><FONT size=-1>AOL Instant Messenger</font> ++<LI><FONT size=-1>Firefox</font> ++<LI><FONT size=-1>Internet Explorer</font> ++<LI><FONT size=-1>Microsoft Excel</font> ++<LI><FONT size=-1>Microsoft Outlook </font> ++<LI><FONT size=-1>Microsoft Word </font> ++<LI><FONT size=-1>Mozilla</font> ++<LI><FONT size=-1>Mozilla Thunderbird</font> ++<LI><FONT size=-1>Netscape</font> ++<LI><FONT size=-1>Opera</font> ++<LI><FONT size=-1>Other web browsers</font> ++<FONT size=-1> ++<p>This will take only a few seconds to complete. </p></font></LI></DIV> ++<p><INPUT id=s type=submit name="quit" value=" OK. Close these applications "> ++ <INPUT id=s type=submit name="redir" value=" Cancel. I'll run this later "><BR></p> ++<center></center></FORM></body></html> +diff --git a/tools/grit/grit/testdata/recrawl.html b/tools/grit/grit/testdata/recrawl.html +new file mode 100644 +index 0000000000..0401e7c2b0 +--- /dev/null ++++ b/tools/grit/grit/testdata/recrawl.html +@@ -0,0 +1,30 @@ ++<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ++<html><head><title>Refresh index</title> ++<meta http-equiv="content-type" content="text/html; charset=utf-8"> ++<meta http-equiv="cache-control" content="no-cache"> ++<meta http-equiv="pragma" content="no-cache"> ++<meta http-equiv="expires" content="-1"> ++<style> ++BODY,TD,A,P {FONT-FAMILY: arial,sans-serif} ++.q {COLOR: #0000cc} ++</style> ++</head> ++<body text="#000000" vLink="#551a8b" aLink="#ff0000" link="#0000cc" bgColor="#ffffff"> ++<center> ++<table cellSpacing="0" cellPadding="0" border="0"> ++<tr> ++<td><a href="[$~HOMEPAGE~$]"><img border="0" height="110" alt="Google Desktop Search" src="hp_logo.gif" width="276"></a> ++</td> ++</tr> ++</table> ++<br> ++<center>Google Desktop Search is now recrawling your drive to index new files.</center> ++<center>Note that new files are indexed automatically, and this step is generally not needed.</center> ++<center>Click <a href="[$~HOMEPAGE~$]">here</a> to continue.</center> ++</td></tr></table> ++<br> ++<font size="-1">[$~BOTTOMLINE~$]</font> ++<p><font size="-2">©2005 Google</font></p> ++</center> ++</body> ++</html> +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/resource_ids b/tools/grit/grit/testdata/resource_ids +new file mode 100644 +index 0000000000..d5d440d57f +--- /dev/null ++++ b/tools/grit/grit/testdata/resource_ids +@@ -0,0 +1,13 @@ ++{ ++ "SRCDIR": ".", ++ "test.grd": { ++ "messages": [100, 10000], ++ }, ++ "substitute_no_ids.grd": { ++ "messages": [10000, 20000], ++ }, ++ "<(FOO)/file.grd": { ++ }, ++ "<(SHARED_INTERMEDIATE_DIR)/devtools/devtools.grd": { ++ }, ++} +diff --git a/tools/grit/grit/testdata/script.html b/tools/grit/grit/testdata/script.html +new file mode 100644 +index 0000000000..f177d9c30e +--- /dev/null ++++ b/tools/grit/grit/testdata/script.html +@@ -0,0 +1,38 @@ ++<script> ++function run(n,cut){ ++ var out = "", str = "abcdefghijklmnopqrstuvwxyz 1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ,./:;'\"()*!?-_@[]{}#%`+=|\\>"; ++ n.innerHTML = 'aa'; ++ ++ var base = n.scrollWidth; ++ for(var i=0;i<str.length;i++) { ++ n.innerHTML = 'a'+str.charAt(i)+'a'; ++ out += str.charAt(i) + (n.scrollWidth-base) +";"; ++ ++ if(cut && !i && (n.scrollWidth-base == cut)) { ++ return '\x02'+"0;"; ++ } ++ } ++ // extra cases for literals ++ n.innerHTML = 'a<a'; ++ out += '<' + (n.scrollWidth-base) +";"; ++ n.innerHTML = 'a&a'; ++ out += '&' + (n.scrollWidth-base) +";"; ++ ++ var base_height = n.scrollHeight; ++ n.innerHTML += '<br>a'; ++ out += '\x01' + (n.scrollHeight-base_height) +";"; ++ ++ return out; ++} + -+#include "nested_class_inline_ctor.h" -diff --git a/tools/clang/plugins/tests/nested_class_inline_ctor.h b/tools/clang/plugins/tests/nested_class_inline_ctor.h ++function TEST_WIDTH() { ++ var n = document.getElementById('test'); ++ var out = run(n[$~CUT~$]); ++ if (out.length>4){ ++ n.style.fontWeight='bold'; ++ out += run(n); ++ } ++ n.outerHTML = ""; ++ (new Image()).src="[$~SETWIDTH~$]?src=[COMPONENT]&data="+escape(out).replace(/\+/g,"%2B"); ++} ++</script> +diff --git a/tools/grit/grit/testdata/searchbox.html b/tools/grit/grit/testdata/searchbox.html new file mode 100644 -index 0000000000..01cfea9232 +index 0000000000..9eccba99a5 --- /dev/null -+++ b/tools/clang/plugins/tests/nested_class_inline_ctor.h ++++ b/tools/grit/grit/testdata/searchbox.html @@ -0,0 +1,22 @@ -+// Copyright (c) 2012 The Chromium Authors. All rights reserved. -+// Use of this source code is governed by a BSD-style license that can be -+// found in the LICENSE file. ++<body bgcolor=#ffffff topmargin=2 marginheight=2> ++<table border=0 cellpadding=0 cellspacing=0 width=1%> ++<tr> ++<td valign=top><a href='[$~HOMEPAGE~$]'><img width=150 height=55 src="/logo3.gif" alt="Go to Google Desktop Search" border=0 vspace=12></a></td> ++<td> </td> ++<td valign=top> ++<table cellpadding=0 cellspacing=0 border=0><tr><td colspan=2 height=14 valign=bottom> ++<table border=0 cellpadding=4 cellspacing=0> ++<tr><td class=q><font size=-1> ++[$~LINKS~$] ++</tr> ++</table> ++</td> ++</tr> ++<tr><td nowrap><form name=gs method=GET action='[$~SEARCHURL~$]'><input type=text name=q size=41 maxlength=2048 value="[DISP_QUERY]"><input type=hidden name=ie value="UTF-8"> ++<font size=-1>[$~FLAGS~$]<input type=submit name="btnG" value="Search Desktop"><span id=hf></span></font></td> ++<td><font size=-2> <a href='[$~PREFERENCES~$]'>Desktop Preferences</a><br> <a [DELETE_EXTRA] href=[DELETE_PAGE]><nobr>[DELETE_NAME]</nobr></a></font></td> ++</tr></table> ++<table cellpadding=0 cellspacing=0 border=0> ++<tr><td><font size=-1> </font></td></tr> ++</table> ++</td></tr></form></table> +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/sidebar_h.html b/tools/grit/grit/testdata/sidebar_h.html +new file mode 100644 +index 0000000000..e103e8f8db +--- /dev/null ++++ b/tools/grit/grit/testdata/sidebar_h.html +@@ -0,0 +1,82 @@ ++<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ++<html><head> ++<meta http-equiv="content-type" content="text/html; charset=utf-8"> ++<meta http-equiv="cache-control" content="no-cache"> ++<meta http-equiv="pragma" content="no-cache"> ++<meta http-equiv="expires" content="-1"> ++<style> ++BODY,TD,DIV,A,.p { FONT-FAMILY: arial,sans-serif; SCROLL: no} ++DIV,TD {COLOR: #000} ++.f, .fl:link {COLOR: #6f6f6f} ++A:link { COLOR: #00c} ++A:visited { COLOR: #551a8b} ++A:active { COLOR: #f00} ++.fl:active { COLOR: #f00} ++.h { COLOR: #3399CC} ++.a, .a:link {COLOR: #008000} ++.b { FONT-WEIGHT: bold; FONT-SIZE: 12pt; COLOR: #00c} ++.g { MARGIN-TOP: .5em; MARGIN-BOTTOM: .5em} ++.f { MARGIN-TOP: 0.5em; MARGIN-BOTTOM: 0.25em} ++.c:active, .c:visited, .c:link { COLOR: #6f6f6f} ++.ch {CURSOR: hand} ++</style> ++</head> ++<BODY onload="TEST_WIDTH();" bottomMargin=0 leftMargin=2 topMargin=0 rightMargin=2 marginwidth=0 marginheight=0 SCROLL=NO bgcolor=#E0E0E0 style="border-style:solid; border-width:0;" oncontextmenu="return false;"> ++ ++<script> ++function hide() { ++ return 1; ++ // return confirm("Are you sure you want to hide the sidebar?\nYou can show it again in Google Desktop Search Preferences. "); ++} ++</script> + -+#ifndef NESTED_CLASS_INLINE_CTOR_H_ -+#define NESTED_CLASS_INLINE_CTOR_H_ + -+#include <string> -+#include <vector> ++<TABLE border=0 cellPadding=0 cellSpacing=0 width="100%"><tr> ++<TD WIDTH="19%" VALIGN=TOP> + -+// See crbug.com/136863. ++<form method=get action="[$~SEARCHURL~$]"> ++<input type=hidden name=src value=4> + -+class Foo { -+ class Bar { -+ Bar() {} -+ ~Bar() {} ++ <table cellspacing=0 cellpadding=0 width='1%'> ++ <tr><td nowrap align=center valign=middle><nobr><img width=16 height=16 src=logo.gif> <b><i><font color=#6F6F6F>Google Desktop Search</font></i></b><IMG id=ctl src="[CONTROL_IMAGE]" border=0 usemap="#control"></nobr></td></tr> ++ <tr><td nowrap align=center valign=middle><nobr><input TABINDEX="1" style="font-size:10px; width:'100%';" name="q" id="q"></nobr></td></tr> ++ <tr><td nowrap align=center valign=middle><nobr><input TABINDEX="2" style="font-size:10px" type=submit value="Local search" name=btnG> <input TABINDEX="3" style="font-size:9px" type=submit value="Web search" name=redir></nobr></td></tr> ++<MAP name="control"> ++<area TABINDEX="4" onkeydown='if(event.keyCode==13)location.href="movesidebar?side=1"' title="Move sidebar to Top" shape="rect" coords="9,0,22,8" href="/movesidebar?side=1" onmouseover="ctl.src='control1.gif'" onmouseout="ctl.src='[CONTROL_IMAGE]'"> ++<area TABINDEX="5" onkeydown='if(event.keyCode==13)location.href="movesidebar?side=3"' title="Move sidebar to Bottom" shape="rect" coords="9,9,22,17" href="/movesidebar?side=3" onmouseover="ctl.src='control3.gif'" onmouseout="ctl.src='[CONTROL_IMAGE]'"> ++<area TABINDEX="6" onkeydown='if(event.keyCode==13)location.href="movesidebar?side=0"' title="Move sidebar to Left" shape="rect" coords="0,2,8,15" href="/movesidebar?side=0" onmouseover="ctl.src='control0.gif'" onmouseout="ctl.src='[CONTROL_IMAGE]'"> ++<area TABINDEX="7" onkeydown='if(event.keyCode==13)location.href="movesidebar?side=2"' title="Move sidebar to Right" shape="rect" coords="23,2,31,15" href="/movesidebar?side=2" onmouseover="ctl.src='control2.gif'" onmouseout="ctl.src='[CONTROL_IMAGE]'"> ++</MAP> ++ </table> ++</form> + -+ std::vector<std::string> a; -+ }; -+}; ++</td> ++<TD WIDTH="27%" VALIGN=TOP> ++ ++[HEADER_SECTION1] ++[CONTENT_INBOX] ++ ++</td> ++<TD WIDTH="27%" VALIGN=top> + -+#endif // NESTED_CLASS_INLINE_CTOR_H_ -diff --git a/tools/clang/plugins/tests/nested_class_inline_ctor.txt b/tools/clang/plugins/tests/nested_class_inline_ctor.txt ++[HEADER_SECTION2] ++[CONTENT_HIST] ++ ++</td> ++<TD WIDTH="27%" VALIGN=top> ++ ++[CONTENT_NEWS] ++[CONTENT_OTHER] ++ ++</td> ++<TD WIDTH="1%" VALIGN=top> ++ ++<a TABINDEX="8" onkeydown='if(event.keyCode!=16&&event.keyCode!=9)onclick()' onclick='return hide()' href='[$~HIDE1~$]' class=ch><img width=12 height=11 style='vertical-align:top;' src=/hide.gif valign=top border=0></a> ++ ++</td> ++</tr></table> ++ ++<font size=-1><span style="visibility:hidden" id='test'>t</span></font> ++ ++[SCRIPT] ++</body></html> +diff --git a/tools/grit/grit/testdata/sidebar_v.html b/tools/grit/grit/testdata/sidebar_v.html new file mode 100644 -index 0000000000..39bd6e1dce +index 0000000000..e040d8ec59 --- /dev/null -+++ b/tools/clang/plugins/tests/nested_class_inline_ctor.txt -@@ -0,0 +1,8 @@ -+In file included from nested_class_inline_ctor.cpp:5: -+./nested_class_inline_ctor.h:15:5: warning: [chromium-style] Complex constructor has an inlined body. -+ Bar() {} -+ ^ -+./nested_class_inline_ctor.h:16:5: warning: [chromium-style] Complex destructor has an inline body. -+ ~Bar() {} -+ ^ -+2 warnings generated. -diff --git a/tools/clang/plugins/tests/overridden_methods.cpp b/tools/clang/plugins/tests/overridden_methods.cpp -new file mode 100644 -index 0000000000..f572a41733 ---- /dev/null -+++ b/tools/clang/plugins/tests/overridden_methods.cpp -@@ -0,0 +1,38 @@ -+// Copyright (c) 2012 The Chromium Authors. All rights reserved. -+// Use of this source code is governed by a BSD-style license that can be -+// found in the LICENSE file. ++++ b/tools/grit/grit/testdata/sidebar_v.html +@@ -0,0 +1,267 @@ ++<html><head> ++<title>Google Desktop Search Sidebar</title> ++<meta http-equiv="content-type" content="text/html; charset=utf-8"> ++<meta http-equiv="cache-control" content="no-cache"> ++<meta http-equiv="pragma" content="no-cache"> ++<meta http-equiv="expires" content="-1"> ++<style> ++BODY,TD,P,A {FONT-FAMILY: verdana,arial,sans-serif;font-size:8pt; color:#fff} ++a:link, a:visited, a:hover, b, q b { color: #ffffff} ++a:active { color: #ff0000} ++a:link,a:active,a:visited,div { text-decoration: none;font-size:8pt } ++.g{margin-top: 1em;} ++.gg{margin-top: .4em;} ++.norepeat { background-repeat: no-repeat } ++.indent{margin-top: 0px; margin-bottom: 0px;margin-left:3px;} ++.c:link, .c:visited, .c:active { color: #959595;font-size:8pt } ++.ch{cursor:pointer;cursor:hand} ++.gap{margin-top: 10px; margin-bottom: 10px;} ++.off {display:none} ++.on {display:on} ++.but { border-top: 1px solid #73787E;border-bottom: 1px solid #000000;border-right: 1px solid #000000;border-left: 1px solid #73787E;margin-top: 0px; margin-bottom: 0px; cursor:pointer;cursor:hand} ++</style> ++<script> ++ ++function toggle(i) { ++ var v = document.getElementById(i); ++ var vi = document.getElementById(i+'icon'); ++ var c = (v['className'] == 'on'); ++ if (c) { ++ v['className'] = 'off'; ++ vi.src='up.gif'; ++ } ++ else { ++ v['className'] = 'on'; ++ vi.src='down.gif'; ++ } ++ (new Image()).src="[$~TOGGLE~$]?setting="+i+"&mode="+v['className']+"&rnd="+Math.random(); ++ ++ if (!c && (v['oclass'] == 'off')) { ++ location.href = location.href; ++ } ++ ++ return true; ++} ++function hide() { ++ // return confirm("Are you sure you want to hide the sidebar?\nYou can show it again in Google Desktop Search Preferences."); ++ return 1; ++} ++</script> ++ ++<!-- menu experiment start --> ++ ++<style> ++<!-- ++.menu1 { ++cursor:default; ++position:absolute; ++text-align: left; ++font-family: Arial, Helvetica, sans-serif; ++font-size: 8pt; ++font-color: #000000; ++color: #000000; ++background-color: menu; ++visibility: hidden; ++padding-top: 2px; ++padding-bottom: 2px; ++border: 1 solid; ++border-color: #888888; ++z-index: 100; ++} ++.menuitems { ++padding-left: 5px; ++padding-right: 5px; ++} ++--> ++</style> ++<SCRIPT LANGUAGE="JavaScript1.2"> ++<!-- ++var menustyle = "menu1"; ++ ++function showmenu() { ++ var rightedge = document.body.clientWidth-event.clientX; ++ var bottomedge = document.body.clientHeight-event.clientY; ++ // if (rightedge < rcmenu.offsetWidth) ++ // rcmenu.style.left = document.body.scrollLeft + event.clientX - rcmenu.offsetWidth; ++ // else ++ // rcmenu.style.left = document.body.scrollLeft + event.clientX; ++ ++ // if (rcmenu.style.left < 0) rcmenu.style.left = 0; ++ rcmenu.style.left = 0; ++ ++ if (bottomedge < rcmenu.offsetHeight) ++ rcmenu.style.top = document.body.scrollTop + event.clientY - rcmenu.offsetHeight; ++ else ++ rcmenu.style.top = document.body.scrollTop + event.clientY; + -+#include "overridden_methods.h" ++ if (rcmenu.style.top < 0) rcmenu.style.top = 0; + -+// Fill in the implementations -+void DerivedClass::SomeMethod() {} -+void DerivedClass::SomeOtherMethod() {} -+void DerivedClass::WebKitModifiedSomething() {} ++ rcmenu.style.visibility = "visible"; ++ // rcmenu.style.zindex = 0; ++ // document.all('rcmenu').style.zindex = 20; ++ document.onkeydown=ck; ++ return false; ++} + -+class ImplementationInterimClass : public BaseClass { -+ public: -+ // Should not warn about pure virtual methods. -+ virtual void SomeMethod() = 0; -+}; ++function hidemenu() { ++ rcmenu.style.visibility = "hidden"; ++} + -+class ImplementationDerivedClass : public ImplementationInterimClass, -+ public webkit_glue::WebKitObserverImpl { -+ public: -+ // Should not warn about destructors. -+ virtual ~ImplementationDerivedClass() {} -+ // Should warn. -+ virtual void SomeMethod(); -+ // Should not warn if marked as override. -+ virtual void SomeOtherMethod() override; -+ // Should not warn for inline implementations in implementation files. -+ virtual void SomeInlineMethod() {} -+ // Should not warn if overriding a method whose origin is WebKit. -+ virtual void WebKitModifiedSomething(); -+ // Should warn if overridden method isn't pure. -+ virtual void SomeNonPureBaseMethod() {} -+}; ++function ck(e){ ++ evt=document.all?window.event:e; ++ k=document.all?window.event.keyCode:e.keyCode; ++ ++ if(k==27 /*<Esc>*/) { ++ hidemenu(); ++ } ++} + -+int main() { -+ DerivedClass something; -+ ImplementationDerivedClass something_else; ++function menumouseover() { ++ if (event.srcElement.className == "menuitems") { ++ event.srcElement.style.backgroundColor = "highlight"; ++ event.srcElement.style.color = "white"; ++ } ++} ++ ++function menumouseout() { ++ if (event.srcElement.className == "menuitems") { ++ event.srcElement.style.backgroundColor = ""; ++ event.srcElement.style.color = "black"; ++ window.status = ""; ++ } +} -diff --git a/tools/clang/plugins/tests/overridden_methods.h b/tools/clang/plugins/tests/overridden_methods.h ++ ++function menuselect() { ++ if (event.srcElement.className == "menuitems") { ++ if (event.srcElement.getAttribute("target") != null) ++ window.open(event.srcElement.url, event.srcElement.getAttribute("target")); ++ else if (event.srcElement.url.length) ++ window.location = event.srcElement.url; ++ } ++} ++// --> ++</script> ++ ++<!-- menu experiment end --> ++ ++</head> ++ ++<body onload="TEST_WIDTH();" bottommargin=0 leftmargin=0 marginheight=0 marginwidth=0 rightmargin=0 topmargin=0 style="background-color:'#384146'; background-repeat: repeat-y; border-style:solid; border-width:0;" background="greyback.jpg" scroll=NO oncontextmenu="return false;"> ++ ++<!-- menu experiment start --> ++ ++<div id="rcmenu" class="skin0" onMouseover="menumouseover()" onMouseout="menumouseout()" onClick="menuselect();"> ++<div class="menuitems" url="[$~SETDISP4~$]">Switch to minibar</div> ++<div class="menuitems" url="[$~SETDISP2~$]">Switch to hoverbar</div> ++<div class="menuitems" url="[$~HIDE1~$]">Close sidebar</div> ++<div class="menuitems" url="">No change</div> ++</div> ++ ++<script language="JavaScript1.2"> ++if (document.all && window.print) { ++ rcmenu.className = menustyle; ++ document.oncontextmenu = showmenu; ++ document.body.onclick = hidemenu; ++} ++</script> ++ ++<!-- menu experiment end --> ++ ++<div id="oneliner" style="visibility:hidden; position:absolute; left:0px; top:0px;"></div> ++<script> ++var h = document.getElementById("oneliner").offsetHeight*2; ++document.write("<style type='text/css'>.truncme { overflow:hidden;height: " +h+"px; }</style>"); ++</script> ++ ++<table cellpadding=0 cellspacing=0 border=0 width='100%'> ++<form method=get action="[$~SEARCHURL~$]" id=f1> ++<input type=hidden name=src value=5> ++<input type=hidden name=redir value=''> ++<tr> ++ <td width='1%'><IMG id=ctl src="[CONTROL_IMAGE]" border=0 usemap="#control"></td> ++ <td width='97%'><input TABINDEX="1" NAME="q" style="width:'100%'; FONT-FAMILY: verdana,arial,sans-serif;font-size:8pt"></td> ++ <td width='1%'><table cellpadding=2 cellspacing=0><tr><td> </td><td TABINDEX="8" onkeydown='if(event.keyCode!=16&&event.keyCode!=9)onclick()' onmouseover="this.bgColor='4C535B'" onmouseout="this.bgColor='#414A4F'" class=but bgcolor=414A4F valign=top onclick="location.href='[$~SETDISP2~$]';"><img src="mini_mini.gif"></td></tr></table></td> ++ <td width='1%'><table cellpadding=2 cellspacing=0><tr><td TABINDEX="9" onkeydown='if(event.keyCode!=16&&event.keyCode!=9)onclick()' onmouseover="this.bgColor='4C535B'" onmouseout="this.bgColor='#414A4F'" class=but bgcolor=414A4F valign=top onclick="if (hide())location.href='[$~HIDE1~$]';"><img src="mini_close.gif"></td></tr></table></td> ++</tr> ++<MAP name="control"> ++<area TABINDEX="4" onkeydown='if(event.keyCode==13)location.href="movesidebar?side=1"' title="Move sidebar to Top" shape="rect" coords="9,0,22,8" href="/movesidebar?side=1" onmouseover="ctl.src='control1.gif'" onmouseout="ctl.src='[CONTROL_IMAGE]'"> ++<area TABINDEX="5" onkeydown='if(event.keyCode==13)location.href="movesidebar?side=3"' title="Move sidebar to Bottom" shape="rect" coords="9,9,22,17" href="/movesidebar?side=3" onmouseover="ctl.src='control3.gif'" onmouseout="ctl.src='[CONTROL_IMAGE]'"> ++<area TABINDEX="6" onkeydown='if(event.keyCode==13)location.href="movesidebar?side=0"' title="Move sidebar to Left" shape="rect" coords="0,2,8,15" href="/movesidebar?side=0" onmouseover="ctl.src='control0.gif'" onmouseout="ctl.src='[CONTROL_IMAGE]'"> ++<area TABINDEX="7" onkeydown='if(event.keyCode==13)location.href="movesidebar?side=2"' title="Move sidebar to Right" shape="rect" coords="23,2,31,15" href="/movesidebar?side=2" onmouseover="ctl.src='control2.gif'" onmouseout="ctl.src='[CONTROL_IMAGE]'"> ++</MAP> ++</table> ++ ++<center> ++<table cellpadding=2 cellspacing=3> ++<tr> ++ <td TABINDEX="2" onkeydown='if(event.keyCode!=16&&event.keyCode!=9)onclick()' onclick="f1.submit()" onmouseover="this.bgColor='4C535B'" onmouseout="this.bgColor='#414A4F'" class=ch nowrap bgcolor=414A4F valign=top style="border-top: 1px solid #73787E;border-bottom: 1px solid #252C30;border-right: 1px solid #252C30;border-left: 1px solid #73787E;"><img src="logo.gif" align="texttop"> <font color=ffffff>Google Desktop Search </td> ++ <td TABINDEX="3" onkeydown='if(event.keyCode!=16&&event.keyCode!=9)onclick()' onclick="redir.value='google'; f1.submit(); redir.value='';" onmouseover="this.bgColor='4C535B'" onmouseout="this.bgColor='#414A4F'" class=ch bgcolor=414A4F nowrap valign=top style="border-top: 1px solid #73787E;border-bottom: 1px solid #252C30;border-right: 1px solid #252C30;border-left: 1px solid #73787E;"> <font color=ffffff>Web </td> ++</tr> ++</form> ++</table> ++</center> ++ ++<p class=gg> ++<table width=100% cellpadding=0 cellspacing=0><tr><td bgcolor=4E555C><img width=1 height=1></td></tr></table> ++<table class=ch cellpadding=0 cellspacing=0 style="background-color:'#424B50'; background-repeat: repeat-y;" background="section.jpg" width=100% height=18><tr onDblClick='return toggle("news");' onclick='return toggle("news");' onmouseover="this.bgColor='#465055'" onmouseout="this.bgColor=''"><td width=16 align=right><img id=newsicon src="[$~NEWS_MODE~$]" border=0></td><td valign=middle> <font color=ffffff>News</td></tr></table> ++<table width=100% cellpadding=0 cellspacing=0><tr><td bgcolor=313B40><img width=1 height=1></td></tr></table> ++ ++<span id="news" class=[$~NEWS_CLASS~$] oclass=[$~NEWS_CLASS~$]> ++[CONTENT_NEWS] ++<p class=g> ++</span> ++ ++<table width=100% cellpadding=0 cellspacing=0><tr><td bgcolor=4E555C><img width=1 height=1></td></tr></table> ++<table class=ch cellpadding=0 cellspacing=0 style="background-color:'#424B50'; background-repeat: repeat-y;" background="section.jpg" width=100% height=18><tr onDblClick='return toggle("inbox");' onclick='return toggle("inbox");' onmouseover="this.bgColor='#465055'" onmouseout="this.bgColor=''"><td width=16 align=right><img id=inboxicon src="[$~INBOX_MODE~$]" border=0></td><td valign=middle> <font color=ffffff>Email</td></tr></table> ++<table width=100% cellpadding=0 cellspacing=0><tr><td bgcolor=313B40><img width=1 height=1></td></tr></table> ++ ++<span id=inbox class=[$~INBOX_CLASS~$] oclass=[$~INBOX_CLASS~$]> ++[CONTENT_INBOX] ++<p class=g> ++</span> ++ ++<table width=100% cellpadding=0 cellspacing=0><tr><td bgcolor=4E555C><img width=1 height=1></td></tr></table> ++<table class=ch cellpadding=0 cellspacing=0 style="background-color:'#424B50'; background-repeat: repeat-y;" background="section.jpg" width=100% height=18><tr onDblClick='return toggle("hist");' onclick='return toggle("hist");' onmouseover="this.bgColor='#465055'" onmouseout="this.bgColor=''"><td width=16 align=right><img id=histicon src="[$~HIST_MODE~$]" border=0></td><td valign=middle> <font color=ffffff>Related History</td></tr></table> ++<table width=100% cellpadding=0 cellspacing=0><tr><td bgcolor=313B40><img width=1 height=1></td></tr></table> ++ ++<span id="hist" class=[$~HIST_CLASS~$] oclass=[$~HIST_CLASS~$]> ++[CONTENT_HIST] ++<p class=g> ++</span> ++ ++ ++<table width=100% cellpadding=0 cellspacing=0><tr><td bgcolor=4E555C><img width=1 height=1></td></tr></table> ++<table class=ch cellpadding=0 cellspacing=0 style="background-color:'#424B50'; background-repeat: repeat-y;" background="section.jpg" width=100% height=18><tr onDblClick='return toggle("recent");' onclick='return toggle("recent");' onmouseover="this.bgColor='#465055'" onmouseout="this.bgColor=''"><td width=16 align=right><img id=recenticon src="[$~RECENT_MODE~$]" border=0></td><td valign=middle> <font color=ffffff>Recent</td></tr></table> ++<table width=100% cellpadding=0 cellspacing=0><tr><td bgcolor=313B40><img width=1 height=1></td></tr></table> ++ ++<span id="recent" class=[$~RECENT_CLASS~$] oclass=[$~RECENT_CLASS~$]> ++[CONTENT_RECENT] ++<p class=g> ++</span> ++ ++ ++<table width=100% cellpadding=0 cellspacing=0><tr><td bgcolor=4E555C><img width=1 height=1></td></tr></table> ++<table class=ch cellpadding=0 cellspacing=0 style="background-color:'#424B50'; background-repeat: repeat-y;" background="section.jpg" width=100% height=18><tr onDblClick='return toggle("popular");' onclick='return toggle("popular");' onmouseover="this.bgColor='#465055'" onmouseout="this.bgColor=''"><td width=16 align=right><img id=popularicon src="[$~POPULAR_MODE~$]" border=0></td><td valign=middle> <font color=ffffff>Frequently Visited</td></tr></table> ++<table width=100% cellpadding=0 cellspacing=0><tr><td bgcolor=313B40><img width=1 height=1></td></tr></table> ++ ++<span id="popular" class=[$~POPULAR_CLASS~$] oclass=[$~POPULAR_CLASS~$]> ++[CONTENT_POPULAR] ++<p class=g> ++</span> ++ ++ ++<table width=100% cellpadding=0 cellspacing=0><tr><td bgcolor=4E555C><img width=1 height=1></td></tr></table> ++<table class=ch cellpadding=0 cellspacing=0 style="background-color:'#424B50'; background-repeat: repeat-y;" background="section.jpg" width=100% height=18><tr onDblClick='return toggle("quib_debug");' onclick='return toggle("quib_debug");' onmouseover="this.bgColor='#465055'" onmouseout="this.bgColor=''"><td width=16 align=right><img id=quib_debugicon src="[$~QUIB_DEBUG_MODE~$]" border=0></td><td valign=middle> <font color=ffffff>Implicit Query Debug</td></tr></table> ++<table width=100% cellpadding=0 cellspacing=0><tr><td bgcolor=313B40><img width=1 height=1></td></tr></table> ++ ++<span id="quib_debug" class=[$~QUIB_DEBUG_CLASS~$] oclass=[$~QUIB_DEBUG_CLASS~$]> ++[CONTENT_QUIB_DEBUG] ++</span> ++ ++<span style="visibility:hidden" id='test'>t</span> ++ ++[CONTENT_OTHER] ++ ++[SCRIPT] ++</body> ++</html> +diff --git a/tools/grit/grit/testdata/simple-input.xml b/tools/grit/grit/testdata/simple-input.xml +new file mode 100644 +index 0000000000..92827fa4b5 +--- /dev/null ++++ b/tools/grit/grit/testdata/simple-input.xml +@@ -0,0 +1,52 @@ ++<?xml version="1.0" encoding="UTF-8"?> ++<grit base_dir="." latest_public_release="2" current_release="3" source_lang_id="en-US"> ++ <release seq="2"> ++ <messages> ++ <message name="IDS_OLD_MESSAGE" translateable="true">Hello earthlings!</message> ++ </messages> ++ </release> ++ <release seq="3"> ++ <includes> ++ <include name="ID_EDIT_BOX_ICON" type="icon" translateable="false" file="images/edit_box.ico" /> ++ <include name="ID_LOGO" type="gif" translateable="true" file="images/logo.gif"/> ++ </includes> ++ <messages> ++ <message name="IDS_BTN_GO" desc="Button text" meaning="verb">Go!</message> ++ <message name="IDS_GREETING" desc="Printed to greet the currently logged in user"> ++ Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today? ++ </message> ++ </messages> ++ <structures> ++ <structure type="menu" name="IDM_FOO" file="rc_files/menus.rc" /> ++ <structure type="dialog" name="IDD_BLAT" file="rc_files/dialogs.rc" /> ++ <structure type="tr_html" name="IDR_HTML_TEMPLATE" file="templates/homepage.html" /> ++ <structure type="dialog" name="IDD_NARROW_DIALOG" file="rc_files/dialogs.rc"> ++ <skeleton expr="lang == 'fr-FR'" variant_of_revision="3"> ++ <![CDATA[IDD_DIALOG1 DIALOGEX 0, 0, 186, 90 ++STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | ++ WS_SYSMENU ++CAPTION "TRANSLATEABLEPLACEHOLDER1" ++FONT 8, "MS Shell Dlg", 400, 0, 0x1 ++BEGIN ++ DEFPUSHBUTTON "TRANSLATEABLEPLACEHOLDER2",IDOK,129,7,50,14 ++ PUSHBUTTON "TRANSLATEABLEPLACEHOLDER3",IDCANCEL,129,24,50,14 ++ LTEXT "TRANSLATEABLEPLACEHOLDER4",IDC_STATIC,23,31,40,8 ++END]]> ++ </skeleton> ++ </structure> ++ <structure type="version" name="VS_VERSION_INFO" file="rc_files/version.rc"/> ++ </structures> ++ </release> ++ <translations> ++ <file path="figs_nl_translations.xml" /> ++ <file path="cjk_translations.xml" /> ++ </translations> ++ <outputs> ++ <output filename="resource.h" type="rc_header" /> ++ <output filename="resource_en.rc" type="rc_all" lang="en-US" /> ++ <output filename="resource_fr.rc" type="rc_all" lang="fr-FR" /> ++ <output filename="resource_it.rc" type="rc_translateable" lang="it-IT" /> ++ <output filename="resource_zh_cn.rc" type="rc_translateable" lang="zh-CN" /> ++ <output filename="nontranslateable.rc" type="rc_nontranslateable" /> ++ </outputs> ++</grit> +diff --git a/tools/grit/grit/testdata/simple.html b/tools/grit/grit/testdata/simple.html new file mode 100644 -index 0000000000..150c79913f +index 0000000000..4392d23e98 --- /dev/null -+++ b/tools/clang/plugins/tests/overridden_methods.h ++++ b/tools/grit/grit/testdata/simple.html +@@ -0,0 +1,3 @@ ++<p> ++ Hello! ++</p> +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/source.rc b/tools/grit/grit/testdata/source.rc +new file mode 100644 +index 0000000000..fbc72284e9 +--- /dev/null ++++ b/tools/grit/grit/testdata/source.rc +@@ -0,0 +1,57 @@ ++IDC_KLONKMENU MENU ++BEGIN ++ POPUP "&File" ++ BEGIN ++ MENUITEM "E&xit", IDM_EXIT ++ MENUITEM "This be ""Klonk"" me like", ID_FILE_THISBE ++ POPUP "gonk" ++ BEGIN ++ MENUITEM "Klonk && is [good]", ID_GONK_KLONKIS ++ END ++ END ++ POPUP "&Help" ++ BEGIN ++ MENUITEM "&About ...", IDM_ABOUT ++ END ++END ++ ++IDD_ABOUTBOX DIALOGEX 22, 17, 230, 75 ++STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU ++CAPTION "About" ++FONT 8, "System", 0, 0, 0x0 ++BEGIN ++ ICON IDI_KLONK,IDC_MYICON,14,9,20,20 ++ LTEXT "klonk Version ""yibbee"" 1.0",IDC_STATIC,49,10,119,8, ++ SS_NOPREFIX ++ LTEXT "Copyright (C) 2005",IDC_STATIC,49,20,119,8 ++ DEFPUSHBUTTON "OK",IDOK,195,6,30,11,WS_GROUP ++ CONTROL "Jack ""Black"" Daniels",IDC_RADIO1,"Button", ++ BS_AUTORADIOBUTTON,46,51,84,10 ++END ++ ++IDD_DIFFERENT_LENGTH_IN_TRANSL DIALOGEX 22, 17, 230, 75 ++STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU ++CAPTION "Bingobobbi" ++FONT 8, "System", 0, 0, 0x0 ++BEGIN ++ LTEXT "Howdie dodie!",IDC_STATIC,49,10,119,8,SS_NOPREFIX ++ LTEXT "Yo froodie!",IDC_STATIC,49,20,119,8 ++END ++ ++STRINGTABLE ++BEGIN ++ IDS_SIMPLE "One" ++ IDS_PLACEHOLDER "%s birds" ++ IDS_PLACEHOLDERS "%d of %d" ++ IDS_REORDERED_PLACEHOLDERS "$1 of $2" ++ // Won't be in translations list because it has changed ++ IDS_CHANGED "This was the old version" ++ IDS_TWIN_1 "Hello" ++ IDS_TWIN_2 "Hello" ++ IDS_NOT_TRANSLATEABLE ":" ++ IDS_LONGER_TRANSLATED "Removed document $1" ++ // Won't appear in the list of translations because it's not in the .grd file ++ IDS_NO_LONGER_USED "Not used" ++ IDS_DIFFERENT_TWIN_1 "Howdie" ++ IDS_DIFFERENT_TWIN_2 "Howdie" ++END +diff --git a/tools/grit/grit/testdata/special_100_percent/a.png b/tools/grit/grit/testdata/special_100_percent/a.png +new file mode 100644 +index 0000000000000000000000000000000000000000..5d5089038ca71172e95db9e7aae1e1fa5cebd505 +GIT binary patch +literal 159 +zcmeAS@N?(olHy`uVBq!ia0vp^oFL4>0wld=oSO}#(mY)pLnNjq|2Y3)zGGzYPN&L+ +zMSC}CcCfp=Dtxv4%6W%G#Q=|R|L;6pCCLUWO)Z<5eoL%TkDTw=s4X!^d(Qa<2khAN +zZPy!XToBAic1Ss}vcWiD27B3&`Zj^H6CO>7R1{ToQ;=ggdEYbV=IISvfHpFCy85}S +Ib4q9e0O9jEh5!Hn + +literal 0 +HcmV?d00001 + +diff --git a/tools/grit/grit/testdata/status.html b/tools/grit/grit/testdata/status.html +new file mode 100644 +index 0000000000..6b997b9369 +--- /dev/null ++++ b/tools/grit/grit/testdata/status.html +@@ -0,0 +1,44 @@ ++[HEADER] ++<table cellspacing=0 cellPadding=0 width="100%" border=0> ++<tr bgcolor=#3399cc><td align=middle height=1><img height=1 width=1></td></tr> ++</table> ++<table cellspacing=0 cellPadding=1 width="100%" bgcolor=#e8f4f7 border=0> ++<tr><td height=20><font size=+1 color=#000000> <b>Desktop Search Status</b></font></td></tr> ++</table> ++<br> ++<center> ++[$~MESSAGE~$] ++<table cellspacing=0 cellPadding=6 width=500 border=0> ++<tr> ++ <td> </td> ++ <td align=right nowrap><i><font size=-1>Number of items</font></i></td> ++ <td align=right nowrap><i><font size=-1>Time of newest item</font></i></td> ++</tr> ++<tr> ++ <td width=1% nowrap><img style="vertical-align:middle" width=16 height=16 src=favicon.ico> Total searchable items</td> ++ <td align=right><b>[TOTAL_COUNT]</b></td> ++ <td align=right><b>[TOTAL_TIME]</b></td> ++</tr> ++<tr> ++ <td><font size=-1> <img style="vertical-align:middle" src=email.gif width=16 height=16> Emails</font></td> ++ <td align=right><font size=-1>[EMAIL_COUNT]</font></td> ++ <td align=right><font size=-1>[EMAIL_TIME]</font></td> ++</tr> ++<tr> ++ <td><font size=-1> <img style="vertical-align:middle" src="16x16_chat.gif" width=16 height=16> Chats</font></td> ++ <td align=right><font size=-1>[IM_COUNT]</font></td> ++ <td align=right><font size=-1>[IM_TIME]</font></td> ++</tr> ++<tr> ++ <td><font size=-1> <img style="vertical-align:middle" src=html.gif width=16 height=16> Web history</font></td> ++ <td align=right><font size=-1>[WEB_COUNT]</font></td> ++ <td align=right><font size=-1>[WEB_TIME]</font></td> ++</tr> ++<tr> ++ <td><font size=-1> <img style="vertical-align:middle" src=file.gif width=16 height=16> Files</font></td> ++ <td align=right><font size=-1>[FILE_COUNT]</font></td> ++ <td align=right><font size=-1>[FILE_TIME]</font></td> ++</tr> ++</table> ++</center> ++[FOOTER] +\ No newline at end of file +diff --git a/tools/grit/grit/testdata/structure_variables.html b/tools/grit/grit/testdata/structure_variables.html +new file mode 100644 +index 0000000000..2a15de8072 +--- /dev/null ++++ b/tools/grit/grit/testdata/structure_variables.html +@@ -0,0 +1,4 @@ ++<h1>[GREETING]!</h1> ++Some cool things are [THINGS]. ++Did you know that [EQUATION]? ++<include src="[filename].html"> +diff --git a/tools/grit/grit/testdata/substitute.grd b/tools/grit/grit/testdata/substitute.grd +new file mode 100644 +index 0000000000..95dcc56e1d +--- /dev/null ++++ b/tools/grit/grit/testdata/substitute.grd +@@ -0,0 +1,31 @@ ++<?xml version="1.0" encoding="UTF-8"?> <!-- -*- XML -*- --> ++<grit ++ base_dir="." ++ source_lang_id="en" ++ tc_project="GoogleDesktopWindowsClient" ++ latest_public_release="0" ++ current_release="1" ++ enc_check="möl"> ++ <outputs> ++ <output filename="resource.h" type="rc_header" /> ++ <output filename="en_generated_resources.rc" type="rc_all" lang="en" /> ++ <output filename="sv_generated_resources.rc" type="rc_all" lang="sv" /> ++ </outputs> ++ <translations> ++ <file path="substitute.xmb" lang="sv" /> ++ </translations> ++ <release seq="1" allow_pseudo="false"> ++ <messages first_id="8192"> ++ <message name="IDS_COPYRIGHT_GOOGLE_LONG" sub_variable="true" desc="Gadget copyright notice. Needs to be updated every year."> ++ Copyright 2008 Google Inc. All Rights Reserved. ++ </message> ++ <message name="IDS_NEWS_PANEL_COPYRIGHT"> ++ Google Desktop News gadget ++[IDS_COPYRIGHT_GOOGLE_LONG] ++View news that is personalized based on the articles you read. ++ ++For example, if you read lots of sports news, you'll see more sports articles. If you read technology news less often, you'll see fewer of those articles. ++ </message> ++ </messages> ++ </release> ++</grit> +diff --git a/tools/grit/grit/testdata/substitute.xmb b/tools/grit/grit/testdata/substitute.xmb +new file mode 100644 +index 0000000000..e592069c8b +--- /dev/null ++++ b/tools/grit/grit/testdata/substitute.xmb +@@ -0,0 +1,10 @@ ++<?xml version="1.0" encoding="UTF-8"?> ++<!DOCTYPE translationbundle SYSTEM "/home/build/nonconf/google3/i18n/translationbundle.dtd"> ++<translationbundle lang="sv"> ++<translation id="7239109800378180620">© 2008 Google Inc. Med ensamrätt.</translation> ++<translation id="6212022020330010625">Google Desktop News gadget ++<ph name="IDS_COPYRIGHT_GOOGLE_LONG_1"/> ++Se nyheter som är anpassade till dig, baserat på de artiklar du läser. ++ ++Om du t.ex. läser massor av sportnyheter kommer du att se fler sportartiklar. Om du inte läser tekniknyheter lika ofta ser du färre av dessa artiklar.</translation> ++</translationbundle> +diff --git a/tools/grit/grit/testdata/substitute_no_ids.grd b/tools/grit/grit/testdata/substitute_no_ids.grd +new file mode 100644 +index 0000000000..d569d1cacd +--- /dev/null ++++ b/tools/grit/grit/testdata/substitute_no_ids.grd +@@ -0,0 +1,31 @@ ++<?xml version="1.0" encoding="UTF-8"?> <!-- -*- XML -*- --> ++<grit ++ base_dir="." ++ source_lang_id="en" ++ tc_project="GoogleDesktopWindowsClient" ++ latest_public_release="0" ++ current_release="1" ++ enc_check="möl"> ++ <outputs> ++ <output filename="resource.h" type="rc_header" /> ++ <output filename="en_generated_resources.rc" type="rc_all" lang="en" /> ++ <output filename="sv_generated_resources.rc" type="rc_all" lang="sv" /> ++ </outputs> ++ <translations> ++ <file path="substitute.xmb" lang="sv" /> ++ </translations> ++ <release seq="1" allow_pseudo="false"> ++ <messages> ++ <message name="IDS_COPYRIGHT_GOOGLE_LONG" sub_variable="true" desc="Gadget copyright notice. Needs to be updated every year."> ++ Copyright 2008 Google Inc. All Rights Reserved. ++ </message> ++ <message name="IDS_NEWS_PANEL_COPYRIGHT"> ++ Google Desktop News gadget ++[IDS_COPYRIGHT_GOOGLE_LONG] ++View news that is personalized based on the articles you read. ++ ++For example, if you read lots of sports news, you'll see more sports articles. If you read technology news less often, you'll see fewer of those articles. ++ </message> ++ </messages> ++ </release> ++</grit> +diff --git a/tools/grit/grit/testdata/substitute_tmpl.grd b/tools/grit/grit/testdata/substitute_tmpl.grd +new file mode 100644 +index 0000000000..be7b601707 +--- /dev/null ++++ b/tools/grit/grit/testdata/substitute_tmpl.grd +@@ -0,0 +1,31 @@ ++<?xml version="1.0" encoding="UTF-8"?> <!-- -*- XML -*- --> ++<grit ++ base_dir="." ++ source_lang_id="en" ++ tc_project="GoogleDesktopWindowsClient" ++ latest_public_release="0" ++ current_release="1" ++ enc_check="möl"> ++ <outputs> ++ <output filename="resource.h" type="rc_header" /> ++ <output filename="en_${name}_resources.rc" type="rc_all" lang="en" /> ++ <output filename="sv_${name}_resources.rc" type="rc_all" lang="sv" /> ++ </outputs> ++ <translations> ++ <file path="substitute.xmb" lang="sv" /> ++ </translations> ++ <release seq="1" allow_pseudo="false"> ++ <messages first_id="8192"> ++ <message name="IDS_COPYRIGHT_GOOGLE_LONG" sub_variable="true" desc="Gadget copyright notice. Needs to be updated every year."> ++ Copyright 2008 Google Inc. All Rights Reserved. ++ </message> ++ <message name="IDS_NEWS_PANEL_COPYRIGHT"> ++ Google Desktop News gadget ++[IDS_COPYRIGHT_GOOGLE_LONG] ++View news that is personalized based on the articles you read. ++ ++For example, if you read lots of sports news, you'll see more sports articles. If you read technology news less often, you'll see fewer of those articles. ++ </message> ++ </messages> ++ </release> ++</grit> +diff --git a/tools/grit/grit/testdata/test_css.css b/tools/grit/grit/testdata/test_css.css +new file mode 100644 +index 0000000000..55d5dd1770 +--- /dev/null ++++ b/tools/grit/grit/testdata/test_css.css +@@ -0,0 +1 @@ ++This is a test! +diff --git a/tools/grit/grit/testdata/test_html.html b/tools/grit/grit/testdata/test_html.html +new file mode 100644 +index 0000000000..55d5dd1770 +--- /dev/null ++++ b/tools/grit/grit/testdata/test_html.html +@@ -0,0 +1 @@ ++This is a test! +diff --git a/tools/grit/grit/testdata/test_js.js b/tools/grit/grit/testdata/test_js.js +new file mode 100644 +index 0000000000..55d5dd1770 +--- /dev/null ++++ b/tools/grit/grit/testdata/test_js.js +@@ -0,0 +1 @@ ++This is a test! +diff --git a/tools/grit/grit/testdata/test_svg.svg b/tools/grit/grit/testdata/test_svg.svg +new file mode 100644 +index 0000000000..55d5dd1770 +--- /dev/null ++++ b/tools/grit/grit/testdata/test_svg.svg +@@ -0,0 +1 @@ ++This is a test! +diff --git a/tools/grit/grit/testdata/test_text.txt b/tools/grit/grit/testdata/test_text.txt +new file mode 100644 +index 0000000000..55d5dd1770 +--- /dev/null ++++ b/tools/grit/grit/testdata/test_text.txt +@@ -0,0 +1 @@ ++This is a test! +diff --git a/tools/grit/grit/testdata/time_related.html b/tools/grit/grit/testdata/time_related.html +new file mode 100644 +index 0000000000..ee64b1665e +--- /dev/null ++++ b/tools/grit/grit/testdata/time_related.html +@@ -0,0 +1,11 @@ ++[HEADER] ++[CHROME] ++[NAV_PRE_POST] ++[$~MESSAGE~$]<br> ++<table border=0 cellpadding=2 cellspacing=0 width='100%'> ++[CONTENTS] ++</table><br> ++ ++[NAV_PRE_POST] ++[FOOTER] ++ +diff --git a/tools/grit/grit/testdata/toolbar_about.html b/tools/grit/grit/testdata/toolbar_about.html +new file mode 100644 +index 0000000000..bb4b0eb355 +--- /dev/null ++++ b/tools/grit/grit/testdata/toolbar_about.html +@@ -0,0 +1,138 @@ ++<html id=dlgAbout STYLE="width: 25.8em; height: 17em" [GRITDIR]> ++<head> ++<meta http-equiv="content-type" content="text/html; charset=utf-8"> ++<title>About Google Toolbar</title> ++<style> ++.button { ++ width: 7em; ++ height: 2.2em; ++ color: buttontext; ++ font-family: MS Sans Serif; ++ font-size:8pt; ++ cursor: hand; ++} ++</style> ++ ++<script> <!-- ++ function HandleError(message, url, line) { ++ var L_Dialog_ErrorMessage = "An error has occured in this dialog."; ++ var L_ErrorNumber_Text = "Error: "; ++ var str = L_Dialog_ErrorMessage + "\n\n" ++ + L_ErrorNumber_Text + line + "\n" ++ + message; ++ alert (str); ++ window.close(); ++ return true; ++ } ++ ++ function OnKeyPress(nCode) { ++ if (nCode == 27) { ++ window.close(); ++ return; ++ } ++ } ++ ++ function OnLoad() { ++ if ((null != window.dialogArguments) && (window.dialogArguments.indexOf("&") == -1) && (window.dialogArguments.indexOf("<") == -1)) { ++ version.innerHTML = window.dialogArguments; ++ } else { ++ version.innerText = "Version: Unknown"; ++ } ++ } ++ ++ window.onerror = HandleError; ++ // --> ++</script> ++ ++</head> ++ ++ ++<body bgcolor="#FFFFFF" onload="OnLoad()" onkeydown="OnKeyPress(event.keyCode)" onkeypress="OnKeyPress(event.keyCode)" scroll=no> ++ ++<table border=0> ++ ++ <tr height=5> ++ <td width=5></td> ++ <td></td> ++ <td></td> ++ <td></td> ++ <td width=5></td> ++ </tr> ++ ++ <tr> ++ <td></td> ++ <td colspan=3> ++ ++ ++<table border="0" cellpadding="0" cellspacing="0" valign="top"> ++ <tr> ++ <td valign="top" height="47" width="155"> ++ <div align="center"><img src="title_toolbar.gif" width="275" height="59" alt="Google Toolbar"></div> ++ </td> ++ <td valign="middle" height="47" width="713"> ++ <hr size=1 color=25479D></td></tr> ++</table> ++ ++ ++ </td> ++ <!-- ++ <TD colspan=2> ++ <span style="COLOR: black; FONT: 18pt Tahoma, MS Shell Dlg"><b> ++ Google Toolbar™</b> ++ </span> ++ </TD> ++ --> ++ <td valign="middle"> ++ </td> ++ </tr> ++ ++ <tr> ++ <td></td> ++ <td align=center><img src="googly.gif"></td> ++ <td colspan=2 align=left> ++ <span style="WIDTH: 25em; height:6em COLOR: black; FONT: 8pt Tahoma, MS Shell Dlg"> ++ <span id=version></span><br> ++ </span> ++ </td> ++ <td></td> ++ </tr> ++ ++ <tr height=50> ++ <td></td> ++ <td></td> ++ <td colspan=2 align=left> ++ <span style="WIDTH: 25em; height:6em COLOR: black; FONT: 8pt Tahoma, MS Shell Dlg"> ++ <!--$/translate--> ++ <i>De parvis grandis acervus erit</i> ++ <!--$translate--> ++ </span> ++ </td> ++ <td></td> ++ </tr> ++ ++ <tr height=40> ++ <td></td> ++ <td></td> ++ <td></td> ++ <td></td> ++ <td></td> ++ </tr> ++ ++ <tr> ++ <td></td> ++ <td width=80></td> ++ <td> ++ <!--$/translate--> ++ <span style="WIDTH: 20em; COLOR: black; FONT: 8pt Tahoma, MS Shell Dlg" id="copyright">© 2006 Google</span> ++ <!--$translate--> ++ </td> ++ <td id=ok-button align=right><button tabindex=1 type=submit align=right id="okButton" class=button onClick="window.close();" >OK</button> ++ </td> ++ <td></td> ++ </tr> ++ ++</table> ++</span> ++ ++</body> ++</html> +diff --git a/tools/grit/grit/testdata/tools/grit/resource_ids b/tools/grit/grit/testdata/tools/grit/resource_ids +new file mode 100644 +index 0000000000..8a2b608df1 +--- /dev/null ++++ b/tools/grit/grit/testdata/tools/grit/resource_ids +@@ -0,0 +1,176 @@ ++# Copyright (c) 2011 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++# ++# This file is used to assign starting resource ids for resources and strings ++# used by Chromium. This is done to ensure that resource ids are unique ++# across all the grd files. If you are adding a new grd file, please add ++# a new entry to this file. ++# ++# The first entry in the file, SRCDIR, is special: It is a relative path from ++# this file to the base of your checkout. ++# ++# http://msdn.microsoft.com/en-us/library/t2zechd4(VS.71).aspx says that the ++# range for IDR_ is 1 to 28,671 and the range for IDS_ is 1 to 32,767 and ++# common convention starts practical use of IDs at 100 or 101. ++{ ++ "SRCDIR": "../..", ++ ++ "chrome/browser/browser_resources.grd": { ++ "includes": [500], ++ }, ++ "chrome/browser/resources/component_extension_resources.grd": { ++ "includes": [1000], ++ }, ++ "chrome/browser/resources/net_internals_resources.grd": { ++ "includes": [1500], ++ }, ++ "chrome/browser/resources/shared_resources.grd": { ++ "includes": [2000], ++ }, ++ "chrome/common/common_resources.grd": { ++ "includes": [2500], ++ }, ++ "chrome/default_plugin/default_plugin_resources.grd": { ++ "includes": [3000], ++ }, ++ "chrome/renderer/renderer_resources.grd": { ++ "includes": [3500], ++ }, ++ "net/base/net_resources.grd": { ++ "includes": [4000], ++ }, ++ "webkit/glue/webkit_resources.grd": { ++ "includes": [4500], ++ }, ++ "webkit/tools/test_shell/test_shell_resources.grd": { ++ "includes": [5000], ++ }, ++ "ui/resources/ui_resources.grd": { ++ "includes": [5500], ++ }, ++ "chrome/app/theme/theme_resources.grd": { ++ "includes": [6000], ++ }, ++ "chrome_frame/resources/chrome_frame_resources.grd": { ++ "includes": [6500], ++ }, ++ # WebKit.grd can be in two different places depending on whether we are ++ # in a chromium checkout or a webkit-only checkout. ++ "third_party/WebKit/Source/WebKit/chromium/WebKit.grd": { ++ "includes": [7000], ++ }, ++ "WebKit.grd": { ++ "includes": [7000], ++ }, ++ ++ "ui/base/strings/app_locale_settings.grd": { ++ "META": {"join": 2}, ++ "messages": [7500], ++ }, ++ "chrome/app/resources/locale_settings.grd": { ++ "includes": [8000], ++ "messages": [8500], ++ }, ++ # These each start with the same resource id because we only use one ++ # file for each build (cros, linux, mac, or win). ++ "chrome/app/resources/locale_settings_cros.grd": { ++ "messages": [9000], ++ }, ++ "chrome/app/resources/locale_settings_linux.grd": { ++ "messages": [9000], ++ }, ++ "chrome/app/resources/locale_settings_mac.grd": { ++ "messages": [9000], ++ }, ++ "chrome/app/resources/locale_settings_win.grd": { ++ "messages": [9000], ++ }, ++ ++ "ui/base/strings/ui_strings.grd": { ++ "META": {"join": 4}, ++ "messages": [9500], ++ }, ++ # Chromium strings and Google Chrome strings must start at the same id. ++ # We only use one file depending on whether we're building Chromium or ++ # Google Chrome. ++ "chrome/app/chromium_strings.grd": { ++ "messages": [10000], ++ }, ++ "chrome/app/google_chrome_strings.grd": { ++ "messages": [10000], ++ }, ++ # Leave lots of space for generated_resources since it has most of our ++ # strings. ++ "chrome/app/generated_resources.grd": { ++ "META": {"join": 2}, ++ "structures": [10500], ++ "messages": [11000], ++ }, ++ # The chrome frame dialogs are also in generated_resources.grd so they ++ # get included by the translation console. We make sure that the ids ++ # for structures here are the same as for generated_resources.grd. ++ "chrome_frame/resources/chrome_frame_dialogs.grd": { ++ "structures": [10500], ++ "includes": [10750], ++ }, ++ "webkit/glue/inspector_strings.grd": { ++ "messages": [16000], ++ }, ++ "webkit/glue/webkit_strings.grd": { ++ "messages": [16500], ++ }, ++ ++ "chrome_frame/resources/chrome_frame_resources.grd": { ++ "includes": [17500], ++ "structures": [18000], ++ }, ++ ++ "ui/gfx/gfx_resources.grd": { ++ "includes": [18500], ++ }, ++ ++ "chrome/app/policy/policy_templates.grd": { ++ "structures": [19000], ++ "messages": [19010], ++ }, ++ ++ "chrome/browser/autofill/autofill_resources.grd": { ++ "messages": [19500], ++ }, ++ "chrome/browser/resources/sync_internals_resources.grd": { ++ "includes": [20000], ++ }, ++ # This file is generated during the build. ++ "<(SHARED_INTERMEDIATE_DIR)/devtools/devtools_resources.grd": { ++ "includes": [20500], ++ }, ++ # All standard and large theme resources should have the same IDs. ++ "chrome/app/theme/theme_resources_standard.grd": { ++ "includes": [21000], ++ }, ++ "chrome/app/theme/theme_resources_large.grd": { ++ "includes": [21000], ++ }, ++ # This file is generated during the build. ++ "chrome/browser/debugger/frontend/devtools_frontend_resources.grd": { ++ "META": {"join": 2}, ++ "includes": [21500], ++ }, ++ "cloud_print/virtual_driver/win/install/virtual_driver_setup_resources.grd": { ++ "messages": [22500], ++ }, ++ "chrome/browser/resources/quota_internals_resources.grd": { ++ "includes": [23000], ++ }, ++ "chrome/browser/resources/workers_resources.grd": { ++ "includes": [23500], ++ }, ++ # All standard and large theme resources should have the same IDs. ++ "ui/resources/ui_resources_standard.grd": { ++ "includes": [24000], ++ }, ++ "ui/resources/ui_resources_large.grd": { ++ "includes": [24000], ++ }, ++} +diff --git a/tools/grit/grit/testdata/transl.rc b/tools/grit/grit/testdata/transl.rc +new file mode 100644 +index 0000000000..2f2595db3f +--- /dev/null ++++ b/tools/grit/grit/testdata/transl.rc +@@ -0,0 +1,56 @@ ++IDC_KLONKMENU MENU ++BEGIN ++ POPUP "&Skra" ++ BEGIN ++ MENUITEM "&Haetta", IDM_EXIT ++ MENUITEM "Thetta er ""Klonk"" sem eg fyla", ID_FILE_THISBE ++ POPUP "gonkurinn" ++ BEGIN ++ MENUITEM "Klonk && er [good]", ID_GONK_KLONKIS ++ END ++ END ++ POPUP "&Hjalp" ++ BEGIN ++ MENUITEM "&Um...", IDM_ABOUT ++ END ++END ++ ++IDD_ABOUTBOX DIALOGEX 22, 17, 230, 75 ++STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU ++CAPTION "Um Klonk" ++FONT 8, "System", 0, 0, 0x0 ++BEGIN ++ ICON IDI_KLONK,IDC_MYICON,14,9,20,20 ++ LTEXT "klonk utgafa ""jibbi"" 1.0",IDC_STATIC,49,10,119,8, ++ SS_NOPREFIX ++ LTEXT "Hofundarrettur (C) 2005",IDC_STATIC,49,20,119,8 ++ DEFPUSHBUTTON "I lagi",IDOK,195,6,30,11,WS_GROUP ++ CONTROL "Jack ""Black"" Daniels",IDC_RADIO1,"Button", ++ BS_AUTORADIOBUTTON,46,51,84,10 ++END ++ ++IDD_DIFFERENT_LENGTH_IN_TRANSL DIALOGEX 22, 17, 230, 75 ++STYLE DS_SETFONT | DS_MODALFRAME | WS_CAPTION | WS_SYSMENU ++CAPTION "Bingobobbi" ++FONT 8, "System", 0, 0, 0x0 ++BEGIN ++ LTEXT "Howdie dodie!",IDC_STATIC,49,10,119,8,SS_NOPREFIX ++END ++ ++STRINGTABLE ++BEGIN ++ IDS_SIMPLE "Ein" ++ IDS_PLACEHOLDER "%s Vogeln" ++ IDS_PLACEHOLDERS "%d von %d" ++ // Shouldn't be part of translations list because the translation is ++ // reordered so placeholder fixup fails ++ IDS_REORDERED_PLACEHOLDERS "$2 auf $1" ++ IDS_CHANGED "Dass war die alte Version" ++ IDS_TWIN_1 "Hallo" ++ IDS_TWIN_2 "Hallo" ++ IDS_NOT_TRANSLATEABLE ":" ++ IDS_LONGER_TRANSLATED "Dokument $1 ist entfernt worden" ++ IDS_NO_LONGER_USED "Nicht verwendet" ++ IDS_DIFFERENT_TWIN_1 "Howdie" ++ IDS_DIFFERENT_TWIN_2 "Hallo sagt man" ++END +diff --git a/tools/grit/grit/testdata/versions.html b/tools/grit/grit/testdata/versions.html +new file mode 100644 +index 0000000000..d1f40d8d72 +--- /dev/null ++++ b/tools/grit/grit/testdata/versions.html +@@ -0,0 +1,7 @@ ++[HEADER] ++ ++[TOP_CHROME] ++[CONTENTS] ++ ++[NEXT_PREV] ++[FOOTER] +diff --git a/tools/grit/grit/testdata/whitelist.txt b/tools/grit/grit/testdata/whitelist.txt +new file mode 100644 +index 0000000000..5b3aca40b5 +--- /dev/null ++++ b/tools/grit/grit/testdata/whitelist.txt +@@ -0,0 +1,4 @@ ++IDS_MESSAGE_WHITELISTED ++IDR_STRUCTURE_WHITELISTED ++IDR_STRUCTURE_IN_TRUE_IF_WHITELISTED ++IDR_INCLUDE_WHITELISTED +diff --git a/tools/grit/grit/testdata/whitelist_resources.grd b/tools/grit/grit/testdata/whitelist_resources.grd +new file mode 100644 +index 0000000000..9925688ff5 +--- /dev/null ++++ b/tools/grit/grit/testdata/whitelist_resources.grd @@ -0,0 +1,54 @@ -+// Copyright (c) 2011 The Chromium Authors. All rights reserved. -+// Use of this source code is governed by a BSD-style license that can be -+// found in the LICENSE file. -+ -+#ifndef OVERRIDDEN_METHODS_H_ -+#define OVERRIDDEN_METHODS_H_ -+ -+// Should warn about overriding of methods. -+class BaseClass { -+ public: -+ virtual ~BaseClass() {} -+ virtual void SomeMethod() = 0; -+ virtual void SomeOtherMethod() = 0; -+ virtual void SomeInlineMethod() = 0; -+ virtual void SomeNonPureBaseMethod() {} -+}; ++<?xml version="1.0" encoding="UTF-8"?> ++<grit latest_public_release="0" ++ current_release="1" ++ output_all_resource_defines="false"> ++ <outputs> ++ <output filename="whitelist_test_resources.h" type="rc_header"> ++ <emit emit_type='prepend'></emit> ++ </output> ++ <output filename="whitelist_test_resources_map.cc" ++ type="resource_file_map_source" /> ++ <output filename="whitelist_test_resources_map.h" ++ type="resource_map_header" /> ++ <output filename="whitelist_test_resources.pak" type="data_package" /> ++ </outputs> ++ <translations> ++ <file path="substitute.xmb" lang="sv" /> ++ </translations> ++ <release seq="1"> ++ <structures> ++ <structure name="IDR_STRUCTURE_WHITELISTED" file="browser.html" ++ type="chrome_html" > ++ </structure> ++ <structure name="IDR_STRUCTURE_NOT_WHITELISTED" file="deleted.html" ++ type="chrome_html" > ++ </structure> ++ <if expr="True"> ++ <structure name="IDR_STRUCTURE_IN_TRUE_IF_WHITELISTED" ++ file="details.html" ++ type="chrome_html" > ++ </structure> ++ <structure name="IDR_STRUCTURE_IN_TRUE_IF_NOT_WHITELISTED" ++ file="error.html" ++ type="chrome_html" > ++ </structure> ++ </if> ++ <if expr="False"> ++ <structure name="IDR_STRUCTURE_IN_FALSE_IF_WHITELISTED" ++ file="status.html" ++ type="chrome_html" > ++ </structure> ++ <structure name="IDR_STRUCTURE_IN_FALSE_IF_NOT_WHITELISTED" ++ file="simple.html" ++ type="chrome_html" > ++ </structure> ++ </if> ++ </structures> ++ <includes> ++ <include name="IDR_INCLUDE_WHITELISTED" file="klonk.ico" ++ type="BINDATA" /> ++ <include name="IDR_INCLUDE_NOT_WHITELISTED" file="klonk.rc" ++ type="BINDATA" /> ++ </includes> ++ </release> ++</grit> +diff --git a/tools/grit/grit/testdata/whitelist_strings.grd b/tools/grit/grit/testdata/whitelist_strings.grd +new file mode 100644 +index 0000000000..df80f5fd32 +--- /dev/null ++++ b/tools/grit/grit/testdata/whitelist_strings.grd +@@ -0,0 +1,23 @@ ++<?xml version="1.0" encoding="UTF-8"?> ++<grit latest_public_release="0" ++ current_release="1" ++ output_all_resource_defines="false"> ++ <outputs > ++ <output filename="whitelist_test_resources.h" type="rc_header"> ++ <emit emit_type='prepend'></emit> ++ </output> ++ <output filename="en_whitelist_test_strings.rc" type="rc_all" lang="en" /> ++ </outputs> ++ <release seq="1"> ++ <messages> ++ <message name="IDS_MESSAGE_WHITELISTED" ++ desc="A message in the whiltelist file."> ++ Whitelisted. ++ </message> ++ <message name="IDS_MESSAGE_NOT_WHITELISTED" ++ desc="A message that isn't in the whiltelist file."> ++ Not whitelisted. ++ </message> ++ </messages> ++ </release> ++</grit> +diff --git a/tools/grit/grit/tool/__init__.py b/tools/grit/grit/tool/__init__.py +new file mode 100644 +index 0000000000..cc455b36e7 +--- /dev/null ++++ b/tools/grit/grit/tool/__init__.py +@@ -0,0 +1,8 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+class InterimClass : public BaseClass { -+ // Should not warn about pure virtual methods. -+ virtual void SomeMethod() = 0; -+}; ++'''Package grit.tool ++''' + -+namespace WebKit { -+class WebKitObserver { -+ public: -+ virtual void WebKitModifiedSomething() {}; -+}; -+} // namespace WebKit ++pass +diff --git a/tools/grit/grit/tool/android2grd.py b/tools/grit/grit/tool/android2grd.py +new file mode 100644 +index 0000000000..005297bafe +--- /dev/null ++++ b/tools/grit/grit/tool/android2grd.py +@@ -0,0 +1,484 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+namespace webkit_glue { -+class WebKitObserverImpl : WebKit::WebKitObserver { -+ public: -+ virtual void WebKitModifiedSomething() {}; -+}; -+} // namespace webkit_glue -+ -+class DerivedClass : public InterimClass, -+ public webkit_glue::WebKitObserverImpl { -+ public: -+ // Should not warn about destructors. -+ virtual ~DerivedClass() {} -+ // Should warn. -+ virtual void SomeMethod(); -+ // Should not warn if marked as override. -+ virtual void SomeOtherMethod() override; -+ // Should warn for inline implementations. -+ virtual void SomeInlineMethod() {} -+ // Should not warn if overriding a method whose origin is WebKit. -+ virtual void WebKitModifiedSomething(); -+ // Should warn if overridden method isn't pure. -+ virtual void SomeNonPureBaseMethod() {} -+}; ++"""The 'grit android2grd' tool.""" + -+#endif // OVERRIDDEN_METHODS_H_ -diff --git a/tools/clang/plugins/tests/overridden_methods.txt b/tools/clang/plugins/tests/overridden_methods.txt -new file mode 100644 -index 0000000000..7553ade70e ---- /dev/null -+++ b/tools/clang/plugins/tests/overridden_methods.txt -@@ -0,0 +1,20 @@ -+In file included from overridden_methods.cpp:5: -+./overridden_methods.h:43:11: warning: [chromium-style] Overriding method must be marked with OVERRIDE. -+ virtual void SomeMethod(); -+ ^ -+./overridden_methods.h:47:11: warning: [chromium-style] Overriding method must be marked with OVERRIDE. -+ virtual void SomeInlineMethod() {} -+ ^ -+./overridden_methods.h:51:11: warning: [chromium-style] Overriding method must be marked with OVERRIDE. -+ virtual void SomeNonPureBaseMethod() {} -+ ^ -+overridden_methods.cpp:24:11: warning: [chromium-style] Overriding method must be marked with OVERRIDE. -+ virtual void SomeMethod(); -+ ^ -+overridden_methods.cpp:28:11: warning: [chromium-style] Overriding method must be marked with OVERRIDE. -+ virtual void SomeInlineMethod() {} -+ ^ -+overridden_methods.cpp:32:11: warning: [chromium-style] Overriding method must be marked with OVERRIDE. -+ virtual void SomeNonPureBaseMethod() {} -+ ^ -+6 warnings generated. -diff --git a/tools/clang/plugins/tests/test.sh b/tools/clang/plugins/tests/test.sh -new file mode 100755 -index 0000000000..262ebbba29 ---- /dev/null -+++ b/tools/clang/plugins/tests/test.sh -@@ -0,0 +1,72 @@ -+#!/bin/bash -+# -+# Copyright (c) 2011 The Chromium Authors. All rights reserved. ++from __future__ import print_function ++ ++import getopt ++import os.path ++import sys ++from xml.dom import Node ++import xml.dom.minidom ++ ++import six ++from six import StringIO ++ ++import grit.node.empty ++from grit.node import node_io ++from grit.node import message ++ ++from grit.tool import interface ++ ++from grit import grd_reader ++from grit import lazy_re ++from grit import tclib ++ ++ ++# The name of a string in strings.xml ++_STRING_NAME = lazy_re.compile(r'[a-z0-9_]+\Z') ++ ++# A string's character limit in strings.xml ++_CHAR_LIMIT = lazy_re.compile(r'\[CHAR-LIMIT=(\d+)\]') ++ ++# Finds String.Format() style format specifiers such as "%-5.2f". ++_FORMAT_SPECIFIER = lazy_re.compile( ++ r'%' ++ r'([1-9][0-9]*\$|<)?' # argument_index ++ r'([-#+ 0,(]*)' # flags ++ r'([0-9]+)?' # width ++ r'(\.[0-9]+)?' # precision ++ r'([bBhHsScCdoxXeEfgGaAtT%n])') # conversion ++ ++ ++class Android2Grd(interface.Tool): ++ """Tool for converting Android string.xml files into chrome Grd files. ++ ++Usage: grit [global options] android2grd [OPTIONS] STRINGS_XML ++ ++The Android2Grd tool will convert an Android strings.xml file (whose path is ++specified by STRINGS_XML) and create a chrome style grd file containing the ++relevant information. ++ ++Because grd documents are much richer than strings.xml documents we supplement ++the information required by grds using OPTIONS with sensible defaults. ++ ++OPTIONS may be any of the following: ++ ++ --name FILENAME Specify the base FILENAME. This should be without ++ any file type suffix. By default ++ "chrome_android_strings" will be used. ++ ++ --languages LANGUAGES Comma separated list of ISO language codes (e.g. ++ en-US, en-GB, ru, zh-CN). These codes will be used ++ to determine the names of resource and translations ++ files that will be declared by the output grd file. ++ ++ --grd-dir GRD_DIR Specify where the resultant grd file ++ (FILENAME.grd) should be output. By default this ++ will be the present working directory. ++ ++ --header-dir HEADER_DIR Specify the location of the directory where grit ++ generated C++ headers (whose name will be ++ FILENAME.h) will be placed. Use an empty string to ++ disable rc generation. Default: empty. ++ ++ --rc-dir RC_DIR Specify the directory where resource files will ++ be located relative to grit build's output ++ directory. Use an empty string to disable rc ++ generation. Default: empty. ++ ++ --xml-dir XML_DIR Specify where to place localized strings.xml files ++ relative to grit build's output directory. For each ++ language xx a values-xx/strings.xml file will be ++ generated. Use an empty string to disable ++ strings.xml generation. Default: '.'. ++ ++ --xtb-dir XTB_DIR Specify where the xtb files containing translations ++ will be located relative to the grd file. Default: ++ '.'. ++""" ++ ++ _NAME_FLAG = 'name' ++ _LANGUAGES_FLAG = 'languages' ++ _GRD_DIR_FLAG = 'grd-dir' ++ _RC_DIR_FLAG = 'rc-dir' ++ _HEADER_DIR_FLAG = 'header-dir' ++ _XTB_DIR_FLAG = 'xtb-dir' ++ _XML_DIR_FLAG = 'xml-dir' ++ ++ def __init__(self): ++ self.name = 'chrome_android_strings' ++ self.languages = [] ++ self.grd_dir = '.' ++ self.rc_dir = None ++ self.xtb_dir = '.' ++ self.xml_res_dir = '.' ++ self.header_dir = None ++ ++ def ShortDescription(self): ++ """Returns a short description of the Android2Grd tool. ++ ++ Overridden from grit.interface.Tool ++ ++ Returns: ++ A string containing a short description of the android2grd tool. ++ """ ++ return 'Converts Android string.xml files into Chrome grd files.' ++ ++ def ParseOptions(self, args): ++ """Set this objects and return all non-option arguments.""" ++ flags = [ ++ Android2Grd._NAME_FLAG, ++ Android2Grd._LANGUAGES_FLAG, ++ Android2Grd._GRD_DIR_FLAG, ++ Android2Grd._RC_DIR_FLAG, ++ Android2Grd._HEADER_DIR_FLAG, ++ Android2Grd._XTB_DIR_FLAG, ++ Android2Grd._XML_DIR_FLAG, ] ++ (opts, args) = getopt.getopt( ++ args, None, ['%s=' % o for o in flags] + ['help']) ++ ++ for key, val in opts: ++ # Get rid of the preceding hypens. ++ k = key[2:] ++ if k == Android2Grd._NAME_FLAG: ++ self.name = val ++ elif k == Android2Grd._LANGUAGES_FLAG: ++ self.languages = val.split(',') ++ elif k == Android2Grd._GRD_DIR_FLAG: ++ self.grd_dir = val ++ elif k == Android2Grd._RC_DIR_FLAG: ++ self.rc_dir = val ++ elif k == Android2Grd._HEADER_DIR_FLAG: ++ self.header_dir = val ++ elif k == Android2Grd._XTB_DIR_FLAG: ++ self.xtb_dir = val ++ elif k == Android2Grd._XML_DIR_FLAG: ++ self.xml_res_dir = val ++ elif k == 'help': ++ self.ShowUsage() ++ sys.exit(0) ++ return args ++ ++ def Run(self, opts, args): ++ """Runs the Android2Grd tool. ++ ++ Inherited from grit.interface.Tool. ++ ++ Args: ++ opts: List of string arguments that should be parsed. ++ args: String containing the path of the strings.xml file to be converted. ++ """ ++ args = self.ParseOptions(args) ++ if len(args) != 1: ++ print('Tool requires one argument, the path to the Android ' ++ 'strings.xml resource file to be converted.') ++ return 2 ++ self.SetOptions(opts) ++ ++ android_path = args[0] ++ ++ # Read and parse the Android strings.xml file. ++ with open(android_path) as android_file: ++ android_dom = xml.dom.minidom.parse(android_file) ++ ++ # Do the hard work -- convert the Android dom to grd file contents. ++ grd_dom = self.AndroidDomToGrdDom(android_dom) ++ grd_string = six.text_type(grd_dom) ++ ++ # Write the grd string to a file in grd_dir. ++ grd_filename = self.name + '.grd' ++ grd_path = os.path.join(self.grd_dir, grd_filename) ++ with open(grd_path, 'w') as grd_file: ++ grd_file.write(grd_string) ++ ++ def AndroidDomToGrdDom(self, android_dom): ++ """Converts a strings.xml DOM into a DOM representing the contents of ++ a grd file. ++ ++ Args: ++ android_dom: A xml.dom.Document containing the contents of the Android ++ string.xml document. ++ Returns: ++ The DOM for the grd xml document produced by converting the Android DOM. ++ """ ++ ++ # Start with a basic skeleton for the .grd file. ++ root = grd_reader.Parse(StringIO( ++ '''<?xml version="1.0" encoding="UTF-8"?> ++ <grit base_dir="." latest_public_release="0" ++ current_release="1" source_lang_id="en"> ++ <outputs /> ++ <translations /> ++ <release allow_pseudo="false" seq="1"> ++ <messages fallback_to_english="true" /> ++ </release> ++ </grit>'''), dir='.') ++ outputs = root.children[0] ++ translations = root.children[1] ++ messages = root.children[2].children[0] ++ assert (isinstance(messages, grit.node.empty.MessagesNode) and ++ isinstance(translations, grit.node.empty.TranslationsNode) and ++ isinstance(outputs, grit.node.empty.OutputsNode)) ++ ++ if self.header_dir: ++ cpp_header = self.__CreateCppHeaderOutputNode(outputs, self.header_dir) ++ for lang in self.languages: ++ # Create an output element for each language. ++ if self.rc_dir: ++ self.__CreateRcOutputNode(outputs, lang, self.rc_dir) ++ if self.xml_res_dir: ++ self.__CreateAndroidXmlOutputNode(outputs, lang, self.xml_res_dir) ++ if lang != 'en': ++ self.__CreateFileNode(translations, lang) ++ # Convert all the strings.xml strings into grd messages. ++ self.__CreateMessageNodes(messages, android_dom.documentElement) ++ ++ return root ++ ++ def __CreateMessageNodes(self, messages, resources): ++ """Creates the <message> elements and adds them as children of <messages>. ++ ++ Args: ++ messages: the <messages> element in the strings.xml dom. ++ resources: the <resources> element in the grd dom. ++ """ ++ # <string> elements contain the definition of the resource. ++ # The description of a <string> element is contained within the comment ++ # node element immediately preceeding the string element in question. ++ description = '' ++ for child in resources.childNodes: ++ if child.nodeType == Node.COMMENT_NODE: ++ # Remove leading/trailing whitespace; collapse consecutive whitespaces. ++ description = ' '.join(child.data.split()) ++ elif child.nodeType == Node.ELEMENT_NODE: ++ if child.tagName != 'string': ++ print('Warning: ignoring unknown tag <%s>' % child.tagName) ++ else: ++ translatable = self.IsTranslatable(child) ++ raw_name = child.getAttribute('name') ++ if not _STRING_NAME.match(raw_name): ++ print('Error: illegal string name: %s' % raw_name) ++ grd_name = 'IDS_' + raw_name.upper() ++ # Transform the <string> node contents into a tclib.Message, taking ++ # care to handle whitespace transformations and escaped characters, ++ # and coverting <xliff:g> placeholders into <ph> placeholders. ++ msg = self.CreateTclibMessage(child) ++ msg_node = self.__CreateMessageNode(messages, grd_name, description, ++ msg, translatable) ++ messages.AddChild(msg_node) ++ # Reset the description once a message has been parsed. ++ description = '' ++ ++ def CreateTclibMessage(self, android_string): ++ """Transforms a <string/> element from strings.xml into a tclib.Message. ++ ++ Interprets whitespace, quotes, and escaped characters in the android_string ++ according to Android's formatting and styling rules for strings. Also ++ converts <xliff:g> placeholders into <ph> placeholders, e.g.: ++ ++ <xliff:g id="website" example="google.com">%s</xliff:g> ++ becomes ++ <ph name="website"><ex>google.com</ex>%s</ph> ++ ++ Returns: ++ The tclib.Message. ++ """ ++ msg = tclib.Message() ++ current_text = '' # Accumulated text that hasn't yet been added to msg. ++ nodes = android_string.childNodes ++ ++ for i, node in enumerate(nodes): ++ # Handle text nodes. ++ if node.nodeType in (Node.TEXT_NODE, Node.CDATA_SECTION_NODE): ++ current_text += node.data ++ ++ # Handle <xliff:g> and other tags. ++ elif node.nodeType == Node.ELEMENT_NODE: ++ if node.tagName == 'xliff:g': ++ assert node.hasAttribute('id'), 'missing id: ' + node.data() ++ placeholder_id = node.getAttribute('id') ++ placeholder_text = self.__FormatPlaceholderText(node) ++ placeholder_example = node.getAttribute('example') ++ if not placeholder_example: ++ print('Info: placeholder does not contain an example: %s' % ++ node.toxml()) ++ placeholder_example = placeholder_id.upper() ++ msg.AppendPlaceholder(tclib.Placeholder(placeholder_id, ++ placeholder_text, placeholder_example)) ++ else: ++ print('Warning: removing tag <%s> which must be inside a ' ++ 'placeholder: %s' % (node.tagName, node.toxml())) ++ msg.AppendText(self.__FormatPlaceholderText(node)) ++ ++ # Handle other nodes. ++ elif node.nodeType != Node.COMMENT_NODE: ++ assert False, 'Unknown node type: %s' % node.nodeType ++ ++ is_last_node = (i == len(nodes) - 1) ++ if (current_text and ++ (is_last_node or nodes[i + 1].nodeType == Node.ELEMENT_NODE)): ++ # For messages containing just text and comments (no xml tags) Android ++ # strips leading and trailing whitespace. We mimic that behavior. ++ if not msg.GetContent() and is_last_node: ++ current_text = current_text.strip() ++ msg.AppendText(self.__FormatAndroidString(current_text)) ++ current_text = '' ++ ++ return msg ++ ++ def __FormatAndroidString(self, android_string, inside_placeholder=False): ++ r"""Returns android_string formatted for a .grd file. ++ ++ * Collapses consecutive whitespaces, except when inside double-quotes. ++ * Replaces \\, \n, \t, \", \' with \, newline, tab, ", '. ++ """ ++ backslash_map = {'\\' : '\\', 'n' : '\n', 't' : '\t', '"' : '"', "'" : "'"} ++ is_quoted_section = False # True when we're inside double quotes. ++ is_backslash_sequence = False # True after seeing an unescaped backslash. ++ prev_char = '' ++ output = [] ++ for c in android_string: ++ if is_backslash_sequence: ++ # Unescape \\, \n, \t, \", and \'. ++ assert c in backslash_map, 'Illegal escape sequence: \\%s' % c ++ output.append(backslash_map[c]) ++ is_backslash_sequence = False ++ elif c == '\\': ++ is_backslash_sequence = True ++ elif c.isspace() and not is_quoted_section: ++ # Turn whitespace into ' ' and collapse consecutive whitespaces. ++ if not prev_char.isspace(): ++ output.append(' ') ++ elif c == '"': ++ is_quoted_section = not is_quoted_section ++ else: ++ output.append(c) ++ prev_char = c ++ output = ''.join(output) ++ ++ if is_quoted_section: ++ print('Warning: unbalanced quotes in string: %s' % android_string) ++ ++ if is_backslash_sequence: ++ print('Warning: trailing backslash in string: %s' % android_string) ++ ++ # Check for format specifiers outside of placeholder tags. ++ if not inside_placeholder: ++ format_specifier = _FORMAT_SPECIFIER.search(output) ++ if format_specifier: ++ print('Warning: format specifiers are not inside a placeholder ' ++ '<xliff:g/> tag: %s' % output) ++ ++ return output ++ ++ def __FormatPlaceholderText(self, placeholder_node): ++ """Returns the text inside of an <xliff:g> placeholder node.""" ++ text = [] ++ for childNode in placeholder_node.childNodes: ++ if childNode.nodeType in (Node.TEXT_NODE, Node.CDATA_SECTION_NODE): ++ text.append(childNode.data) ++ elif childNode.nodeType != Node.COMMENT_NODE: ++ assert False, 'Unknown node type in ' + placeholder_node.toxml() ++ return self.__FormatAndroidString(''.join(text), inside_placeholder=True) ++ ++ def __CreateMessageNode(self, messages_node, grd_name, description, msg, ++ translatable): ++ """Creates and initializes a <message> element. ++ ++ Message elements correspond to Android <string> elements in that they ++ declare a string resource along with a programmatic id. ++ """ ++ if not description: ++ print('Warning: no description for %s' % grd_name) ++ # Check that we actually fit within the character limit we've specified. ++ match = _CHAR_LIMIT.search(description) ++ if match: ++ char_limit = int(match.group(1)) ++ msg_content = msg.GetRealContent() ++ if len(msg_content) > char_limit: ++ print('Warning: char-limit for %s is %d, but length is %d: %s' % ++ (grd_name, char_limit, len(msg_content), msg_content)) ++ return message.MessageNode.Construct(parent=messages_node, ++ name=grd_name, ++ message=msg, ++ desc=description, ++ translateable=translatable) ++ ++ def __CreateFileNode(self, translations_node, lang): ++ """Creates and initializes the <file> elements. ++ ++ File elements provide information on the location of translation files ++ (xtbs) ++ """ ++ xtb_file = os.path.normpath(os.path.join( ++ self.xtb_dir, '%s_%s.xtb' % (self.name, lang))) ++ fnode = node_io.FileNode() ++ fnode.StartParsing(u'file', translations_node) ++ fnode.HandleAttribute('path', xtb_file) ++ fnode.HandleAttribute('lang', lang) ++ fnode.EndParsing() ++ translations_node.AddChild(fnode) ++ return fnode ++ ++ def __CreateCppHeaderOutputNode(self, outputs_node, header_dir): ++ """Creates the <output> element corresponding to the generated c header.""" ++ header_file_name = os.path.join(header_dir, self.name + '.h') ++ header_node = node_io.OutputNode() ++ header_node.StartParsing(u'output', outputs_node) ++ header_node.HandleAttribute('filename', header_file_name) ++ header_node.HandleAttribute('type', 'rc_header') ++ emit_node = node_io.EmitNode() ++ emit_node.StartParsing(u'emit', header_node) ++ emit_node.HandleAttribute('emit_type', 'prepend') ++ emit_node.EndParsing() ++ header_node.AddChild(emit_node) ++ header_node.EndParsing() ++ outputs_node.AddChild(header_node) ++ return header_node ++ ++ def __CreateRcOutputNode(self, outputs_node, lang, rc_dir): ++ """Creates the <output> element corresponding to various rc file output.""" ++ rc_file_name = self.name + '_' + lang + ".rc" ++ rc_path = os.path.join(rc_dir, rc_file_name) ++ node = node_io.OutputNode() ++ node.StartParsing(u'output', outputs_node) ++ node.HandleAttribute('filename', rc_path) ++ node.HandleAttribute('lang', lang) ++ node.HandleAttribute('type', 'rc_all') ++ node.EndParsing() ++ outputs_node.AddChild(node) ++ return node ++ ++ def __CreateAndroidXmlOutputNode(self, outputs_node, locale, xml_res_dir): ++ """Creates the <output> element corresponding to various rc file output.""" ++ # Need to check to see if the locale has a region, e.g. the GB in en-GB. ++ # When a locale has a region Android expects the region to be prefixed ++ # with an 'r'. For example for en-GB Android expects a values-en-rGB ++ # directory. Also, Android expects nb, tl, in, iw, ji as the language ++ # codes for Norwegian, Tagalog/Filipino, Indonesian, Hebrew, and Yiddish: ++ # http://developer.android.com/reference/java/util/Locale.html ++ if locale == 'es-419': ++ android_locale = 'es-rUS' ++ else: ++ android_lang, dash, region = locale.partition('-') ++ lang_map = {'no': 'nb', 'fil': 'tl', 'id': 'in', 'he': 'iw', 'yi': 'ji'} ++ android_lang = lang_map.get(android_lang, android_lang) ++ android_locale = android_lang + ('-r' + region if region else '') ++ values = 'values-' + android_locale if android_locale != 'en' else 'values' ++ xml_path = os.path.normpath(os.path.join( ++ xml_res_dir, values, 'strings.xml')) ++ ++ node = node_io.OutputNode() ++ node.StartParsing(u'output', outputs_node) ++ node.HandleAttribute('filename', xml_path) ++ node.HandleAttribute('lang', locale) ++ node.HandleAttribute('type', 'android') ++ node.EndParsing() ++ outputs_node.AddChild(node) ++ return node ++ ++ def IsTranslatable(self, android_string): ++ """Determines if a <string> element is a candidate for translation. ++ ++ A <string> element is by default translatable unless otherwise marked. ++ """ ++ if android_string.hasAttribute('translatable'): ++ value = android_string.getAttribute('translatable').lower() ++ if value not in ('true', 'false'): ++ print('Warning: translatable attribute has invalid value: %s' % value) ++ return value == 'true' ++ else: ++ return True +diff --git a/tools/grit/grit/tool/android2grd_unittest.py b/tools/grit/grit/tool/android2grd_unittest.py +new file mode 100644 +index 0000000000..a6934a707c +--- /dev/null ++++ b/tools/grit/grit/tool/android2grd_unittest.py +@@ -0,0 +1,181 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. -+# -+# Hacky, primitive testing: This runs the style plugin for a set of input files -+# and compares the output with golden result files. -+ -+E_BADARGS=65 -+E_FAILEDTEST=1 -+ -+failed_any_test= -+ -+# Prints usage information. -+usage() { -+ echo "Usage: $(basename "${0}")" \ -+ "<Path to the llvm build dir, usually Release+Asserts>" -+ echo "" -+ echo " Runs all the libFindBadConstructs unit tests" -+ echo "" -+} -+ -+# Runs a single test case. -+do_testcase() { -+ local output="$("${CLANG_DIR}"/bin/clang -c -Wno-c++11-extensions \ -+ -Xclang -load -Xclang "${CLANG_DIR}"/lib/libFindBadConstructs.${LIB} \ -+ -Xclang -plugin -Xclang find-bad-constructs ${1} 2>&1)" -+ local diffout="$(echo "${output}" | diff - "${2}")" -+ if [ "${diffout}" = "" ]; then -+ echo "PASS: ${1}" -+ else -+ failed_any_test=yes -+ echo "FAIL: ${1}" -+ echo "Output of compiler:" -+ echo "${output}" -+ echo "Expected output:" -+ cat "${2}" -+ echo -+ fi -+} -+ -+# Validate input to the script. -+if [[ -z "${1}" ]]; then -+ usage -+ exit ${E_BADARGS} -+elif [[ ! -d "${1}" ]]; then -+ echo "${1} is not a directory." -+ usage -+ exit ${E_BADARGS} -+else -+ export CLANG_DIR="${PWD}/${1}" -+ echo "Using clang directory ${CLANG_DIR}..." -+ -+ # The golden files assume that the cwd is this directory. To make the script -+ # work no matter what the cwd is, explicitly cd to there. -+ cd "$(dirname "${0}")" -+ -+ if [ "$(uname -s)" = "Linux" ]; then -+ export LIB=so -+ elif [ "$(uname -s)" = "Darwin" ]; then -+ export LIB=dylib -+ fi -+fi -+ -+for input in *.cpp; do -+ do_testcase "${input}" "${input%cpp}txt" -+done -+ -+if [[ "${failed_any_test}" ]]; then -+ exit ${E_FAILEDTEST} -+fi -diff --git a/tools/clang/plugins/tests/virtual_methods.cpp b/tools/clang/plugins/tests/virtual_methods.cpp -new file mode 100644 -index 0000000000..a07cbe4875 ---- /dev/null -+++ b/tools/clang/plugins/tests/virtual_methods.cpp -@@ -0,0 +1,36 @@ -+// Copyright (c) 2012 The Chromium Authors. All rights reserved. -+// Use of this source code is governed by a BSD-style license that can be -+// found in the LICENSE file. -+ -+#include "virtual_methods.h" -+ -+// Shouldn't warn about method usage in the implementation file. -+class VirtualMethodsInImplementation { -+ public: -+ virtual void MethodIsAbstract() = 0; -+ virtual void MethodHasNoArguments(); -+ virtual void MethodHasEmptyDefaultImpl() {} -+ virtual bool ComplainAboutThis() { return true; } -+}; + -+// Stubs to fill in the abstract method -+class ConcreteVirtualMethodsInHeaders : public VirtualMethodsInHeaders { -+ public: -+ virtual void MethodIsAbstract() override {} -+}; ++'''Unit tests for grit.tool.android2grd''' + -+class ConcreteVirtualMethodsInImplementation -+ : public VirtualMethodsInImplementation { -+ public: -+ virtual void MethodIsAbstract() override {} -+}; ++from __future__ import print_function ++ ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++import unittest ++import xml.dom.minidom ++ ++from grit import util ++from grit.node import empty ++from grit.node import message ++from grit.node import misc ++from grit.node import node_io ++from grit.tool import android2grd ++ ++ ++class Android2GrdUnittest(unittest.TestCase): ++ ++ def __Parse(self, xml_string): ++ return xml.dom.minidom.parseString(xml_string).childNodes[0] ++ ++ def testCreateTclibMessage(self): ++ tool = android2grd.Android2Grd() ++ msg = tool.CreateTclibMessage(self.__Parse(r''' ++ <string name="simple">A simple string</string>''')) ++ self.assertEqual(msg.GetRealContent(), 'A simple string') ++ msg = tool.CreateTclibMessage(self.__Parse(r''' ++ <string name="outer_whitespace"> ++ Strip leading/trailing whitespace ++ </string>''')) ++ self.assertEqual(msg.GetRealContent(), 'Strip leading/trailing whitespace') ++ msg = tool.CreateTclibMessage(self.__Parse(r''' ++ <string name="inner_whitespace">Fold multiple spaces</string>''')) ++ self.assertEqual(msg.GetRealContent(), 'Fold multiple spaces') ++ msg = tool.CreateTclibMessage(self.__Parse(r''' ++ <string name="escaped_spaces">Retain \n escaped\t spaces</string>''')) ++ self.assertEqual(msg.GetRealContent(), 'Retain \n escaped\t spaces') ++ msg = tool.CreateTclibMessage(self.__Parse(r''' ++ <string name="quotes"> " Quotes preserve ++ whitespace" but only for "enclosed elements " ++ </string>''')) ++ self.assertEqual(msg.GetRealContent(), ''' Quotes preserve ++ whitespace but only for enclosed elements ''') ++ msg = tool.CreateTclibMessage(self.__Parse( ++ r'''<string name="escaped_characters">Escaped characters: \"\'\\\t\n''' ++ '</string>')) ++ self.assertEqual(msg.GetRealContent(), '''Escaped characters: "'\\\t\n''') ++ msg = tool.CreateTclibMessage(self.__Parse( ++ '<string xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2" ' ++ 'name="placeholders">' ++ 'Open <xliff:g id="FILENAME" example="internet.html">%s</xliff:g>?' ++ '</string>')) ++ self.assertEqual(msg.GetRealContent(), 'Open %s?') ++ self.assertEqual(len(msg.GetPlaceholders()), 1) ++ self.assertEqual(msg.GetPlaceholders()[0].presentation, 'FILENAME') ++ self.assertEqual(msg.GetPlaceholders()[0].original, '%s') ++ self.assertEqual(msg.GetPlaceholders()[0].example, 'internet.html') ++ msg = tool.CreateTclibMessage(self.__Parse(r''' ++ <string name="comment">Contains a <!-- ignore this --> comment ++ </string>''')) ++ self.assertEqual(msg.GetRealContent(), 'Contains a comment') ++ ++ def testIsTranslatable(self): ++ tool = android2grd.Android2Grd() ++ string_el = self.__Parse('<string>Hi</string>') ++ self.assertTrue(tool.IsTranslatable(string_el)) ++ string_el = self.__Parse( ++ '<string translatable="true">Hi</string>') ++ self.assertTrue(tool.IsTranslatable(string_el)) ++ string_el = self.__Parse( ++ '<string translatable="false">Hi</string>') ++ self.assertFalse(tool.IsTranslatable(string_el)) ++ ++ def __ParseAndroidXml(self, options = []): ++ tool = android2grd.Android2Grd() ++ ++ tool.ParseOptions(options) ++ ++ android_path = util.PathFromRoot('grit/testdata/android.xml') ++ with open(android_path) as android_file: ++ android_dom = xml.dom.minidom.parse(android_file) ++ ++ grd = tool.AndroidDomToGrdDom(android_dom) ++ self.assertTrue(isinstance(grd, misc.GritNode)) ++ ++ return grd ++ ++ def testAndroidDomToGrdDom(self): ++ grd = self.__ParseAndroidXml(['--languages', 'en-US,en-GB,ru']) ++ ++ # Check that the structure of the GritNode is as expected. ++ messages = grd.GetChildrenOfType(message.MessageNode) ++ translations = grd.GetChildrenOfType(empty.TranslationsNode) ++ files = grd.GetChildrenOfType(node_io.FileNode) ++ ++ self.assertEqual(len(translations), 1) ++ self.assertEqual(len(files), 3) ++ self.assertEqual(len(messages), 5) ++ ++ # Check that a message node is constructed correctly. ++ msg = [x for x in messages if x.GetTextualIds()[0] == 'IDS_PLACEHOLDERS'] ++ self.assertTrue(msg) ++ msg = msg[0] ++ ++ self.assertTrue(msg.IsTranslateable()) ++ self.assertEqual(msg.attrs["desc"], "A string with placeholder.") ++ ++ def testTranslatableAttribute(self): ++ grd = self.__ParseAndroidXml([]) ++ messages = grd.GetChildrenOfType(message.MessageNode) ++ msgs = [x for x in messages if x.GetTextualIds()[0] == 'IDS_CONSTANT'] ++ self.assertTrue(msgs) ++ self.assertFalse(msgs[0].IsTranslateable()) ++ ++ def testTranslations(self): ++ grd = self.__ParseAndroidXml(['--languages', 'en-US,en-GB,ru,id']) ++ ++ files = grd.GetChildrenOfType(node_io.FileNode) ++ us_file = [x for x in files if x.attrs['lang'] == 'en-US'] ++ self.assertTrue(us_file) ++ self.assertEqual(us_file[0].GetInputPath(), ++ 'chrome_android_strings_en-US.xtb') ++ ++ id_file = [x for x in files if x.attrs['lang'] == 'id'] ++ self.assertTrue(id_file) ++ self.assertEqual(id_file[0].GetInputPath(), ++ 'chrome_android_strings_id.xtb') ++ ++ def testOutputs(self): ++ grd = self.__ParseAndroidXml(['--languages', 'en-US,ru,id', ++ '--rc-dir', 'rc/dir', ++ '--header-dir', 'header/dir', ++ '--xtb-dir', 'xtb/dir', ++ '--xml-dir', 'xml/dir']) ++ ++ outputs = grd.GetChildrenOfType(node_io.OutputNode) ++ self.assertEqual(len(outputs), 7) ++ ++ header_outputs = [x for x in outputs if x.GetType() == 'rc_header'] ++ rc_outputs = [x for x in outputs if x.GetType() == 'rc_all'] ++ xml_outputs = [x for x in outputs if x.GetType() == 'android'] ++ ++ self.assertEqual(len(header_outputs), 1) ++ self.assertEqual(len(rc_outputs), 3) ++ self.assertEqual(len(xml_outputs), 3) ++ ++ # The header node should have an "<emit>" child and the proper filename. ++ self.assertTrue(header_outputs[0].GetChildrenOfType(node_io.EmitNode)) ++ self.assertEqual(util.normpath(header_outputs[0].GetFilename()), ++ util.normpath('header/dir/chrome_android_strings.h')) ++ ++ id_rc = [x for x in rc_outputs if x.GetLanguage() == 'id'] ++ id_xml = [x for x in xml_outputs if x.GetLanguage() == 'id'] ++ self.assertTrue(id_rc) ++ self.assertTrue(id_xml) ++ self.assertEqual(util.normpath(id_rc[0].GetFilename()), ++ util.normpath('rc/dir/chrome_android_strings_id.rc')) ++ self.assertEqual(util.normpath(id_xml[0].GetFilename()), ++ util.normpath('xml/dir/values-in/strings.xml')) ++ ++ us_rc = [x for x in rc_outputs if x.GetLanguage() == 'en-US'] ++ us_xml = [x for x in xml_outputs if x.GetLanguage() == 'en-US'] ++ self.assertTrue(us_rc) ++ self.assertTrue(us_xml) ++ self.assertEqual(util.normpath(us_rc[0].GetFilename()), ++ util.normpath('rc/dir/chrome_android_strings_en-US.rc')) ++ self.assertEqual(util.normpath(us_xml[0].GetFilename()), ++ util.normpath('xml/dir/values-en-rUS/strings.xml')) ++ ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/tool/build.py b/tools/grit/grit/tool/build.py +new file mode 100644 +index 0000000000..204592bf0d +--- /dev/null ++++ b/tools/grit/grit/tool/build.py +@@ -0,0 +1,556 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''The 'grit build' tool. ++''' ++ ++from __future__ import print_function + -+// Fill in the implementations -+void VirtualMethodsInHeaders::MethodHasNoArguments() {} -+void WarnOnMissingVirtual::MethodHasNoArguments() {} -+void VirtualMethodsInImplementation::MethodHasNoArguments() {} ++import codecs ++import filecmp ++import getopt ++import gzip ++import os ++import shutil ++import sys + -+int main() { -+ ConcreteVirtualMethodsInHeaders one; -+ ConcreteVirtualMethodsInImplementation two; ++import six ++ ++from grit import grd_reader ++from grit import shortcuts ++from grit import util ++from grit.format import minifier ++from grit.node import brotli_util ++from grit.node import include ++from grit.node import message ++from grit.node import structure ++from grit.tool import interface ++ ++ ++# It would be cleaner to have each module register itself, but that would ++# require importing all of them on every run of GRIT. ++'''Map from <output> node types to modules under grit.format.''' ++_format_modules = { ++ 'android': 'android_xml', ++ 'c_format': 'c_format', ++ 'chrome_messages_json': 'chrome_messages_json', ++ 'chrome_messages_json_gzip': 'chrome_messages_json', ++ 'data_package': 'data_pack', ++ 'policy_templates': 'policy_templates_json', ++ 'rc_all': 'rc', ++ 'rc_header': 'rc_header', ++ 'rc_nontranslateable': 'rc', ++ 'rc_translateable': 'rc', ++ 'resource_file_map_source': 'resource_map', ++ 'resource_map_header': 'resource_map', ++ 'resource_map_source': 'resource_map', +} -diff --git a/tools/clang/plugins/tests/virtual_methods.h b/tools/clang/plugins/tests/virtual_methods.h ++ ++def GetFormatter(type): ++ modulename = 'grit.format.' + _format_modules[type] ++ __import__(modulename) ++ module = sys.modules[modulename] ++ try: ++ return module.Format ++ except AttributeError: ++ return module.GetFormatter(type) ++ ++ ++class RcBuilder(interface.Tool): ++ '''A tool that builds RC files and resource header files for compilation. ++ ++Usage: grit build [-o OUTPUTDIR] [-D NAME[=VAL]]* ++ ++All output options for this tool are specified in the input file (see ++'grit help' for details on how to specify the input file - it is a global ++option). ++ ++Options: ++ ++ -a FILE Assert that the given file is an output. There can be ++ multiple "-a" flags listed for multiple outputs. If a "-a" ++ or "--assert-file-list" argument is present, then the list ++ of asserted files must match the output files or the tool ++ will fail. The use-case is for the build system to maintain ++ separate lists of output files and to catch errors if the ++ build system's list and the grit list are out-of-sync. ++ ++ --assert-file-list Provide a file listing multiple asserted output files. ++ There is one file name per line. This acts like specifying ++ each file with "-a" on the command line, but without the ++ possibility of running into OS line-length limits for very ++ long lists. ++ ++ -o OUTPUTDIR Specify what directory output paths are relative to. ++ Defaults to the current directory. ++ ++ -p FILE Specify a file containing a pre-determined mapping from ++ resource names to resource ids which will be used to assign ++ resource ids to those resources. Resources not found in this ++ file will be assigned ids normally. The motivation is to run ++ your app's startup and have it dump the resources it loads, ++ and then pass these via this flag. This will pack startup ++ resources together, thus reducing paging while all other ++ resources are unperturbed. The file should have the format: ++ RESOURCE_ONE_NAME 123 ++ RESOURCE_TWO_NAME 124 ++ ++ -D NAME[=VAL] Specify a C-preprocessor-like define NAME with optional ++ value VAL (defaults to 1) which will be used to control ++ conditional inclusion of resources. ++ ++ -E NAME=VALUE Set environment variable NAME to VALUE (within grit). ++ ++ -f FIRSTIDSFILE Path to a python file that specifies the first id of ++ value to use for resources. A non-empty value here will ++ override the value specified in the <grit> node's ++ first_ids_file. ++ ++ -w WHITELISTFILE Path to a file containing the string names of the ++ resources to include. Anything not listed is dropped. ++ ++ -t PLATFORM Specifies the platform the build is targeting; defaults ++ to the value of sys.platform. The value provided via this ++ flag should match what sys.platform would report for your ++ target platform; see grit.node.base.EvaluateCondition. ++ ++ --whitelist-support ++ Generate code to support extracting a resource whitelist ++ from executables. ++ ++ --write-only-new flag ++ If flag is non-0, write output files to a temporary file ++ first, and copy it to the real output only if the new file ++ is different from the old file. This allows some build ++ systems to realize that dependent build steps might be ++ unnecessary, at the cost of comparing the output data at ++ grit time. ++ ++ --depend-on-stamp ++ If specified along with --depfile and --depdir, the depfile ++ generated will depend on a stampfile instead of the first ++ output in the input .grd file. ++ ++ --js-minifier A command to run the Javascript minifier. If not set then ++ Javascript won't be minified. The command should read the ++ original Javascript from standard input, and output the ++ minified Javascript to standard output. A non-zero exit ++ status will be taken as indicating failure. ++ ++ --css-minifier A command to run the CSS minifier. If not set then CSS won't ++ be minified. The command should read the original CSS from ++ standard input, and output the minified CSS to standard ++ output. A non-zero exit status will be taken as indicating ++ failure. ++ ++ --brotli The full path to the brotli executable generated by ++ third_party/brotli/BUILD.gn, required if any entries use ++ compress="brotli". ++ ++Conditional inclusion of resources only affects the output of files which ++control which resources get linked into a binary, e.g. it affects .rc files ++meant for compilation but it does not affect resource header files (that define ++IDs). This helps ensure that values of IDs stay the same, that all messages ++are exported to translation interchange files (e.g. XMB files), etc. ++''' ++ ++ def ShortDescription(self): ++ return 'A tool that builds RC files for compilation.' ++ ++ def Run(self, opts, args): ++ brotli_util.SetBrotliCommand(None) ++ os.environ['cwd'] = os.getcwd() ++ self.output_directory = '.' ++ first_ids_file = None ++ predetermined_ids_file = None ++ whitelist_filenames = [] ++ assert_output_files = [] ++ target_platform = None ++ depfile = None ++ depdir = None ++ whitelist_support = False ++ write_only_new = False ++ depend_on_stamp = False ++ js_minifier = None ++ css_minifier = None ++ replace_ellipsis = True ++ (own_opts, args) = getopt.getopt( ++ args, 'a:p:o:D:E:f:w:t:', ++ ('depdir=', 'depfile=', 'assert-file-list=', 'help', ++ 'output-all-resource-defines', 'no-output-all-resource-defines', ++ 'no-replace-ellipsis', 'depend-on-stamp', 'js-minifier=', ++ 'css-minifier=', 'write-only-new=', 'whitelist-support', 'brotli=')) ++ for (key, val) in own_opts: ++ if key == '-a': ++ assert_output_files.append(val) ++ elif key == '--assert-file-list': ++ with open(val) as f: ++ assert_output_files += f.read().splitlines() ++ elif key == '-o': ++ self.output_directory = val ++ elif key == '-D': ++ name, val = util.ParseDefine(val) ++ self.defines[name] = val ++ elif key == '-E': ++ (env_name, env_value) = val.split('=', 1) ++ os.environ[env_name] = env_value ++ elif key == '-f': ++ # TODO(joi@chromium.org): Remove this override once change ++ # lands in WebKit.grd to specify the first_ids_file in the ++ # .grd itself. ++ first_ids_file = val ++ elif key == '-w': ++ whitelist_filenames.append(val) ++ elif key == '--no-replace-ellipsis': ++ replace_ellipsis = False ++ elif key == '-p': ++ predetermined_ids_file = val ++ elif key == '-t': ++ target_platform = val ++ elif key == '--depdir': ++ depdir = val ++ elif key == '--depfile': ++ depfile = val ++ elif key == '--write-only-new': ++ write_only_new = val != '0' ++ elif key == '--depend-on-stamp': ++ depend_on_stamp = True ++ elif key == '--js-minifier': ++ js_minifier = val ++ elif key == '--css-minifier': ++ css_minifier = val ++ elif key == '--whitelist-support': ++ whitelist_support = True ++ elif key == '--brotli': ++ brotli_util.SetBrotliCommand([os.path.abspath(val)]) ++ elif key == '--help': ++ self.ShowUsage() ++ sys.exit(0) ++ ++ if len(args): ++ print('This tool takes no tool-specific arguments.') ++ return 2 ++ self.SetOptions(opts) ++ self.VerboseOut('Output directory: %s (absolute path: %s)\n' % ++ (self.output_directory, ++ os.path.abspath(self.output_directory))) ++ ++ if whitelist_filenames: ++ self.whitelist_names = set() ++ for whitelist_filename in whitelist_filenames: ++ self.VerboseOut('Using whitelist: %s\n' % whitelist_filename); ++ whitelist_contents = util.ReadFile(whitelist_filename, 'utf-8') ++ self.whitelist_names.update(whitelist_contents.strip().split('\n')) ++ ++ if js_minifier: ++ minifier.SetJsMinifier(js_minifier) ++ ++ if css_minifier: ++ minifier.SetCssMinifier(css_minifier) ++ ++ self.write_only_new = write_only_new ++ ++ self.res = grd_reader.Parse(opts.input, ++ debug=opts.extra_verbose, ++ first_ids_file=first_ids_file, ++ predetermined_ids_file=predetermined_ids_file, ++ defines=self.defines, ++ target_platform=target_platform) ++ ++ # Set an output context so that conditionals can use defines during the ++ # gathering stage; we use a dummy language here since we are not outputting ++ # a specific language. ++ self.res.SetOutputLanguage('en') ++ self.res.SetWhitelistSupportEnabled(whitelist_support) ++ self.res.RunGatherers() ++ ++ # Replace ... with the single-character version. http://crbug.com/621772 ++ if replace_ellipsis: ++ for node in self.res: ++ if isinstance(node, message.MessageNode): ++ node.SetReplaceEllipsis(True) ++ ++ self.Process() ++ ++ if assert_output_files: ++ if not self.CheckAssertedOutputFiles(assert_output_files): ++ return 2 ++ ++ if depfile and depdir: ++ self.GenerateDepfile(depfile, depdir, first_ids_file, depend_on_stamp) ++ ++ return 0 ++ ++ def __init__(self, defines=None): ++ # Default file-creation function is codecs.open(). Only done to allow ++ # overriding by unit test. ++ self.fo_create = codecs.open ++ ++ # key/value pairs of C-preprocessor like defines that are used for ++ # conditional output of resources ++ self.defines = defines or {} ++ ++ # self.res is a fully-populated resource tree if Run() ++ # has been called, otherwise None. ++ self.res = None ++ ++ # The set of names that are whitelisted to actually be included in the ++ # output. ++ self.whitelist_names = None ++ ++ # Whether to compare outputs to their old contents before writing. ++ self.write_only_new = False ++ ++ @staticmethod ++ def AddWhitelistTags(start_node, whitelist_names): ++ # Walk the tree of nodes added attributes for the nodes that shouldn't ++ # be written into the target files (skip markers). ++ for node in start_node: ++ # Same trick data_pack.py uses to see what nodes actually result in ++ # real items. ++ if (isinstance(node, include.IncludeNode) or ++ isinstance(node, message.MessageNode) or ++ isinstance(node, structure.StructureNode)): ++ text_ids = node.GetTextualIds() ++ # Mark the item to be skipped if it wasn't in the whitelist. ++ if text_ids and text_ids[0] not in whitelist_names: ++ node.SetWhitelistMarkedAsSkip(True) ++ ++ @staticmethod ++ def ProcessNode(node, output_node, outfile): ++ '''Processes a node in-order, calling its formatter before and after ++ recursing to its children. ++ ++ Args: ++ node: grit.node.base.Node subclass ++ output_node: grit.node.io.OutputNode ++ outfile: open filehandle ++ ''' ++ base_dir = util.dirname(output_node.GetOutputFilename()) ++ ++ formatter = GetFormatter(output_node.GetType()) ++ formatted = formatter(node, output_node.GetLanguage(), output_dir=base_dir) ++ # NB: Formatters may be generators or return lists. The writelines API ++ # accepts iterables as a shortcut to calling write directly. That means ++ # you can pass strings (iteration yields characters), but not bytes (as ++ # iteration yields integers). Python 2 worked due to its quirks with ++ # bytes/string implementation, but Python 3 fails. It's also a bit more ++ # inefficient to call write once per character/byte. Handle all of this ++ # ourselves by calling write directly on strings/bytes before falling back ++ # to writelines. ++ if isinstance(formatted, (six.string_types, six.binary_type)): ++ outfile.write(formatted) ++ else: ++ outfile.writelines(formatted) ++ if output_node.GetType() == 'data_package': ++ with open(output_node.GetOutputFilename() + '.info', 'w') as infofile: ++ if node.info: ++ # We terminate with a newline so that when these files are ++ # concatenated later we consistently terminate with a newline so ++ # consumers can account for terminating newlines. ++ infofile.writelines(['\n'.join(node.info), '\n']) ++ ++ @staticmethod ++ def _EncodingForOutputType(output_type): ++ # Microsoft's RC compiler can only deal with single-byte or double-byte ++ # files (no UTF-8), so we make all RC files UTF-16 to support all ++ # character sets. ++ if output_type in ('rc_header', 'resource_file_map_source', ++ 'resource_map_header', 'resource_map_source'): ++ return 'cp1252' ++ if output_type in ('android', 'c_format', 'plist', 'plist_strings', 'doc', ++ 'json', 'android_policy', 'chrome_messages_json', ++ 'chrome_messages_json_gzip', 'policy_templates'): ++ return 'utf_8' ++ # TODO(gfeher) modify here to set utf-8 encoding for admx/adml ++ return 'utf_16' ++ ++ def Process(self): ++ for output in self.res.GetOutputFiles(): ++ output.output_filename = os.path.abspath(os.path.join( ++ self.output_directory, output.GetOutputFilename())) ++ ++ # If there are whitelisted names, tag the tree once up front, this way ++ # while looping through the actual output, it is just an attribute check. ++ if self.whitelist_names: ++ self.AddWhitelistTags(self.res, self.whitelist_names) ++ ++ for output in self.res.GetOutputFiles(): ++ self.VerboseOut('Creating %s...' % output.GetOutputFilename()) ++ ++ # Set the context, for conditional inclusion of resources ++ self.res.SetOutputLanguage(output.GetLanguage()) ++ self.res.SetOutputContext(output.GetContext()) ++ self.res.SetFallbackToDefaultLayout(output.GetFallbackToDefaultLayout()) ++ self.res.SetDefines(self.defines) ++ ++ # Assign IDs only once to ensure that all outputs use the same IDs. ++ if self.res.GetIdMap() is None: ++ self.res.InitializeIds() ++ ++ # Make the output directory if it doesn't exist. ++ self.MakeDirectoriesTo(output.GetOutputFilename()) ++ ++ # Write the results to a temporary file and only overwrite the original ++ # if the file changed. This avoids unnecessary rebuilds. ++ out_filename = output.GetOutputFilename() ++ tmp_filename = out_filename + '.tmp' ++ tmpfile = self.fo_create(tmp_filename, 'wb') ++ ++ output_type = output.GetType() ++ if output_type != 'data_package': ++ encoding = self._EncodingForOutputType(output_type) ++ tmpfile = util.WrapOutputStream(tmpfile, encoding) ++ ++ # Iterate in-order through entire resource tree, calling formatters on ++ # the entry into a node and on exit out of it. ++ with tmpfile: ++ self.ProcessNode(self.res, output, tmpfile) ++ ++ if output_type == 'chrome_messages_json_gzip': ++ gz_filename = tmp_filename + '.gz' ++ with open(tmp_filename, 'rb') as tmpfile, open(gz_filename, 'wb') as f: ++ with gzip.GzipFile(filename='', mode='wb', fileobj=f, mtime=0) as fgz: ++ shutil.copyfileobj(tmpfile, fgz) ++ os.remove(tmp_filename) ++ tmp_filename = gz_filename ++ ++ # Now copy from the temp file back to the real output, but on Windows, ++ # only if the real output doesn't exist or the contents of the file ++ # changed. This prevents identical headers from being written and .cc ++ # files from recompiling (which is painful on Windows). ++ if not os.path.exists(out_filename): ++ os.rename(tmp_filename, out_filename) ++ else: ++ # CHROMIUM SPECIFIC CHANGE. ++ # This clashes with gyp + vstudio, which expect the output timestamp ++ # to change on a rebuild, even if nothing has changed, so only do ++ # it when opted in. ++ if not self.write_only_new: ++ write_file = True ++ else: ++ files_match = filecmp.cmp(out_filename, tmp_filename) ++ write_file = not files_match ++ if write_file: ++ shutil.copy2(tmp_filename, out_filename) ++ os.remove(tmp_filename) ++ ++ self.VerboseOut(' done.\n') ++ ++ # Print warnings if there are any duplicate shortcuts. ++ warnings = shortcuts.GenerateDuplicateShortcutsWarnings( ++ self.res.UberClique(), self.res.GetTcProject()) ++ if warnings: ++ print('\n'.join(warnings)) ++ ++ # Print out any fallback warnings, and missing translation errors, and ++ # exit with an error code if there are missing translations in a non-pseudo ++ # and non-official build. ++ warnings = (self.res.UberClique().MissingTranslationsReport(). ++ encode('ascii', 'replace')) ++ if warnings: ++ self.VerboseOut(warnings) ++ if self.res.UberClique().HasMissingTranslations(): ++ print(self.res.UberClique().missing_translations_) ++ sys.exit(-1) ++ ++ ++ def CheckAssertedOutputFiles(self, assert_output_files): ++ '''Checks that the asserted output files are specified in the given list. ++ ++ Returns true if the asserted files are present. If they are not, returns ++ False and prints the failure. ++ ''' ++ # Compare the absolute path names, sorted. ++ asserted = sorted([os.path.abspath(i) for i in assert_output_files]) ++ actual = sorted([ ++ os.path.abspath(os.path.join(self.output_directory, ++ i.GetOutputFilename())) ++ for i in self.res.GetOutputFiles()]) ++ ++ if asserted != actual: ++ missing = list(set(asserted) - set(actual)) ++ extra = list(set(actual) - set(asserted)) ++ error = '''Asserted file list does not match. ++ ++Expected output files: ++%s ++Actual output files: ++%s ++Missing output files: ++%s ++Extra output files: ++%s ++''' ++ print(error % ('\n'.join(asserted), '\n'.join(actual), '\n'.join(missing), ++ ' \n'.join(extra))) ++ return False ++ return True ++ ++ ++ def GenerateDepfile(self, depfile, depdir, first_ids_file, depend_on_stamp): ++ '''Generate a depfile that contains the imlicit dependencies of the input ++ grd. The depfile will be in the same format as a makefile, and will contain ++ references to files relative to |depdir|. It will be put in |depfile|. ++ ++ For example, supposing we have three files in a directory src/ ++ ++ src/ ++ blah.grd <- depends on input{1,2}.xtb ++ input1.xtb ++ input2.xtb ++ ++ and we run ++ ++ grit -i blah.grd -o ../out/gen \ ++ --depdir ../out \ ++ --depfile ../out/gen/blah.rd.d ++ ++ from the directory src/ we will generate a depfile ../out/gen/blah.grd.d ++ that has the contents ++ ++ gen/blah.h: ../src/input1.xtb ../src/input2.xtb ++ ++ Where "gen/blah.h" is the first output (Ninja expects the .d file to list ++ the first output in cases where there is more than one). If the flag ++ --depend-on-stamp is specified, "gen/blah.rd.d.stamp" will be used that is ++ 'touched' whenever a new depfile is generated. ++ ++ Note that all paths in the depfile are relative to ../out, the depdir. ++ ''' ++ depfile = os.path.abspath(depfile) ++ depdir = os.path.abspath(depdir) ++ infiles = self.res.GetInputFiles() ++ ++ # We want to trigger a rebuild if the first ids change. ++ if first_ids_file is not None: ++ infiles.append(first_ids_file) ++ ++ if (depend_on_stamp): ++ output_file = depfile + ".stamp" ++ # Touch the stamp file before generating the depfile. ++ with open(output_file, 'a'): ++ os.utime(output_file, None) ++ else: ++ # Get the first output file relative to the depdir. ++ outputs = self.res.GetOutputFiles() ++ output_file = os.path.join(self.output_directory, ++ outputs[0].GetOutputFilename()) ++ ++ output_file = os.path.relpath(output_file, depdir) ++ # The path prefix to prepend to dependencies in the depfile. ++ prefix = os.path.relpath(os.getcwd(), depdir) ++ deps_text = ' '.join([os.path.join(prefix, i) for i in infiles]) ++ ++ depfile_contents = output_file + ': ' + deps_text ++ self.MakeDirectoriesTo(depfile) ++ outfile = self.fo_create(depfile, 'w', encoding='utf-8') ++ outfile.write(depfile_contents) ++ ++ @staticmethod ++ def MakeDirectoriesTo(file): ++ '''Creates directories necessary to contain |file|.''' ++ dir = os.path.split(file)[0] ++ if not os.path.exists(dir): ++ os.makedirs(dir) +diff --git a/tools/grit/grit/tool/build_unittest.py b/tools/grit/grit/tool/build_unittest.py new file mode 100644 -index 0000000000..d9fbf96ed3 +index 0000000000..c4a2f2752b --- /dev/null -+++ b/tools/clang/plugins/tests/virtual_methods.h -@@ -0,0 +1,39 @@ -+// Copyright (c) 2011 The Chromium Authors. All rights reserved. -+// Use of this source code is governed by a BSD-style license that can be -+// found in the LICENSE file. -+ -+#ifndef VIRTUAL_METHODS_H_ -+#define VIRTUAL_METHODS_H_ -+ -+// Should warn about virtual method usage. -+class VirtualMethodsInHeaders { -+ public: -+ // Don't complain about these. -+ virtual void MethodIsAbstract() = 0; -+ virtual void MethodHasNoArguments(); -+ virtual void MethodHasEmptyDefaultImpl() {} -+ -+ // But complain about this: -+ virtual bool ComplainAboutThis() { return true; } -+}; ++++ b/tools/grit/grit/tool/build_unittest.py +@@ -0,0 +1,341 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+// Complain on missing 'virtual' keyword in overrides. -+class WarnOnMissingVirtual : public VirtualMethodsInHeaders { -+ public: -+ void MethodHasNoArguments() override; -+}; ++'''Unit tests for the 'grit build' tool. ++''' + -+// Don't complain about things in a 'testing' namespace. -+namespace testing { -+struct TestStruct {}; -+} // namespace testing -+ -+class VirtualMethodsInHeadersTesting : public VirtualMethodsInHeaders { -+ public: -+ // Don't complain about no virtual testing methods. -+ void MethodHasNoArguments(); -+ private: -+ testing::TestStruct tester_; -+}; ++from __future__ import print_function ++ ++import codecs ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) + -+#endif // VIRTUAL_METHODS_H_ -diff --git a/tools/clang/plugins/tests/virtual_methods.txt b/tools/clang/plugins/tests/virtual_methods.txt ++import unittest ++ ++from grit import util ++from grit.tool import build ++ ++ ++class BuildUnittest(unittest.TestCase): ++ ++ # IDs should not change based on whitelisting. ++ # Android WebView currently relies on this. ++ EXPECTED_ID_MAP = { ++ 'IDS_MESSAGE_WHITELISTED': 6889, ++ 'IDR_STRUCTURE_WHITELISTED': 11546, ++ 'IDR_STRUCTURE_IN_TRUE_IF_WHITELISTED': 11548, ++ 'IDR_INCLUDE_WHITELISTED': 15601, ++ } ++ ++ def testFindTranslationsWithSubstitutions(self): ++ # This is a regression test; we had a bug where GRIT would fail to find ++ # messages with substitutions e.g. "Hello [IDS_USER]" where IDS_USER is ++ # another <message>. ++ output_dir = util.TempDir({}) ++ builder = build.RcBuilder() ++ class DummyOpts(object): ++ def __init__(self): ++ self.input = util.PathFromRoot('grit/testdata/substitute.grd') ++ self.verbose = False ++ self.extra_verbose = False ++ builder.Run(DummyOpts(), ['-o', output_dir.GetPath()]) ++ output_dir.CleanUp() ++ ++ def testGenerateDepFile(self): ++ output_dir = util.TempDir({}) ++ builder = build.RcBuilder() ++ class DummyOpts(object): ++ def __init__(self): ++ self.input = util.PathFromRoot('grit/testdata/depfile.grd') ++ self.verbose = False ++ self.extra_verbose = False ++ expected_dep_file = output_dir.GetPath('substitute.grd.d') ++ builder.Run(DummyOpts(), ['-o', output_dir.GetPath(), ++ '--depdir', output_dir.GetPath(), ++ '--depfile', expected_dep_file]) ++ ++ self.failUnless(os.path.isfile(expected_dep_file)) ++ with open(expected_dep_file) as f: ++ line = f.readline() ++ (dep_output_file, deps_string) = line.split(': ') ++ deps = deps_string.split(' ') ++ ++ self.failUnlessEqual("default_100_percent.pak", dep_output_file) ++ self.failUnlessEqual(deps, [ ++ util.PathFromRoot('grit/testdata/default_100_percent/a.png'), ++ util.PathFromRoot('grit/testdata/grit_part.grdp'), ++ util.PathFromRoot('grit/testdata/special_100_percent/a.png'), ++ ]) ++ output_dir.CleanUp() ++ ++ def testGenerateDepFileWithResourceIds(self): ++ output_dir = util.TempDir({}) ++ builder = build.RcBuilder() ++ class DummyOpts(object): ++ def __init__(self): ++ self.input = util.PathFromRoot('grit/testdata/substitute_no_ids.grd') ++ self.verbose = False ++ self.extra_verbose = False ++ expected_dep_file = output_dir.GetPath('substitute_no_ids.grd.d') ++ builder.Run(DummyOpts(), ++ ['-f', util.PathFromRoot('grit/testdata/resource_ids'), ++ '-o', output_dir.GetPath(), ++ '--depdir', output_dir.GetPath(), ++ '--depfile', expected_dep_file]) ++ ++ self.failUnless(os.path.isfile(expected_dep_file)) ++ with open(expected_dep_file) as f: ++ line = f.readline() ++ (dep_output_file, deps_string) = line.split(': ') ++ deps = deps_string.split(' ') ++ ++ self.failUnlessEqual("resource.h", dep_output_file) ++ self.failUnlessEqual(2, len(deps)) ++ self.failUnlessEqual(deps[0], ++ util.PathFromRoot('grit/testdata/substitute.xmb')) ++ self.failUnlessEqual(deps[1], ++ util.PathFromRoot('grit/testdata/resource_ids')) ++ output_dir.CleanUp() ++ ++ def testAssertOutputs(self): ++ output_dir = util.TempDir({}) ++ class DummyOpts(object): ++ def __init__(self): ++ self.input = util.PathFromRoot('grit/testdata/substitute.grd') ++ self.verbose = False ++ self.extra_verbose = False ++ ++ # Incomplete output file list should fail. ++ builder_fail = build.RcBuilder() ++ self.failUnlessEqual(2, ++ builder_fail.Run(DummyOpts(), [ ++ '-o', output_dir.GetPath(), ++ '-a', os.path.abspath( ++ output_dir.GetPath('en_generated_resources.rc'))])) ++ ++ # Complete output file list should succeed. ++ builder_ok = build.RcBuilder() ++ self.failUnlessEqual(0, ++ builder_ok.Run(DummyOpts(), [ ++ '-o', output_dir.GetPath(), ++ '-a', os.path.abspath( ++ output_dir.GetPath('en_generated_resources.rc')), ++ '-a', os.path.abspath( ++ output_dir.GetPath('sv_generated_resources.rc')), ++ '-a', os.path.abspath(output_dir.GetPath('resource.h'))])) ++ output_dir.CleanUp() ++ ++ def testAssertTemplateOutputs(self): ++ output_dir = util.TempDir({}) ++ class DummyOpts(object): ++ def __init__(self): ++ self.input = util.PathFromRoot('grit/testdata/substitute_tmpl.grd') ++ self.verbose = False ++ self.extra_verbose = False ++ ++ # Incomplete output file list should fail. ++ builder_fail = build.RcBuilder() ++ self.failUnlessEqual(2, ++ builder_fail.Run(DummyOpts(), [ ++ '-o', output_dir.GetPath(), ++ '-E', 'name=foo', ++ '-a', os.path.abspath(output_dir.GetPath('en_foo_resources.rc'))])) ++ ++ # Complete output file list should succeed. ++ builder_ok = build.RcBuilder() ++ self.failUnlessEqual(0, ++ builder_ok.Run(DummyOpts(), [ ++ '-o', output_dir.GetPath(), ++ '-E', 'name=foo', ++ '-a', os.path.abspath(output_dir.GetPath('en_foo_resources.rc')), ++ '-a', os.path.abspath(output_dir.GetPath('sv_foo_resources.rc')), ++ '-a', os.path.abspath(output_dir.GetPath('resource.h'))])) ++ output_dir.CleanUp() ++ ++ def _verifyWhitelistedOutput(self, ++ filename, ++ whitelisted_ids, ++ non_whitelisted_ids, ++ encoding='utf8'): ++ self.failUnless(os.path.exists(filename)) ++ whitelisted_ids_found = [] ++ non_whitelisted_ids_found = [] ++ with codecs.open(filename, encoding=encoding) as f: ++ for line in f.readlines(): ++ for whitelisted_id in whitelisted_ids: ++ if whitelisted_id in line: ++ whitelisted_ids_found.append(whitelisted_id) ++ if filename.endswith('.h'): ++ numeric_id = int(line.split()[2]) ++ expected_numeric_id = self.EXPECTED_ID_MAP.get(whitelisted_id) ++ self.assertEqual( ++ expected_numeric_id, numeric_id, ++ 'Numeric ID for {} was {} should be {}'.format( ++ whitelisted_id, numeric_id, expected_numeric_id)) ++ for non_whitelisted_id in non_whitelisted_ids: ++ if non_whitelisted_id in line: ++ non_whitelisted_ids_found.append(non_whitelisted_id) ++ self.longMessage = True ++ self.assertEqual(whitelisted_ids, ++ whitelisted_ids_found, ++ '\nin file {}'.format(os.path.basename(filename))) ++ non_whitelisted_msg = ('Non-Whitelisted IDs {} found in {}' ++ .format(non_whitelisted_ids_found, os.path.basename(filename))) ++ self.assertFalse(non_whitelisted_ids_found, non_whitelisted_msg) ++ ++ def testWhitelistStrings(self): ++ output_dir = util.TempDir({}) ++ builder = build.RcBuilder() ++ class DummyOpts(object): ++ def __init__(self): ++ self.input = util.PathFromRoot('grit/testdata/whitelist_strings.grd') ++ self.verbose = False ++ self.extra_verbose = False ++ whitelist_file = util.PathFromRoot('grit/testdata/whitelist.txt') ++ builder.Run(DummyOpts(), ['-o', output_dir.GetPath(), ++ '-w', whitelist_file]) ++ header = output_dir.GetPath('whitelist_test_resources.h') ++ rc = output_dir.GetPath('en_whitelist_test_strings.rc') ++ ++ whitelisted_ids = ['IDS_MESSAGE_WHITELISTED'] ++ non_whitelisted_ids = ['IDS_MESSAGE_NOT_WHITELISTED'] ++ self._verifyWhitelistedOutput( ++ header, ++ whitelisted_ids, ++ non_whitelisted_ids, ++ ) ++ self._verifyWhitelistedOutput( ++ rc, ++ whitelisted_ids, ++ non_whitelisted_ids, ++ encoding='utf16' ++ ) ++ output_dir.CleanUp() ++ ++ def testWhitelistResources(self): ++ output_dir = util.TempDir({}) ++ builder = build.RcBuilder() ++ class DummyOpts(object): ++ def __init__(self): ++ self.input = util.PathFromRoot('grit/testdata/whitelist_resources.grd') ++ self.verbose = False ++ self.extra_verbose = False ++ whitelist_file = util.PathFromRoot('grit/testdata/whitelist.txt') ++ builder.Run(DummyOpts(), ['-o', output_dir.GetPath(), ++ '-w', whitelist_file]) ++ header = output_dir.GetPath('whitelist_test_resources.h') ++ map_cc = output_dir.GetPath('whitelist_test_resources_map.cc') ++ map_h = output_dir.GetPath('whitelist_test_resources_map.h') ++ pak = output_dir.GetPath('whitelist_test_resources.pak') ++ ++ # Ensure the resource map header and .pak files exist, but don't verify ++ # their content. ++ self.failUnless(os.path.exists(map_h)) ++ self.failUnless(os.path.exists(pak)) ++ ++ whitelisted_ids = [ ++ 'IDR_STRUCTURE_WHITELISTED', ++ 'IDR_STRUCTURE_IN_TRUE_IF_WHITELISTED', ++ 'IDR_INCLUDE_WHITELISTED', ++ ] ++ non_whitelisted_ids = [ ++ 'IDR_STRUCTURE_NOT_WHITELISTED', ++ 'IDR_STRUCTURE_IN_TRUE_IF_NOT_WHITELISTED', ++ 'IDR_STRUCTURE_IN_FALSE_IF_WHITELISTED', ++ 'IDR_STRUCTURE_IN_FALSE_IF_NOT_WHITELISTED', ++ 'IDR_INCLUDE_NOT_WHITELISTED', ++ ] ++ for output_file in (header, map_cc): ++ self._verifyWhitelistedOutput( ++ output_file, ++ whitelisted_ids, ++ non_whitelisted_ids, ++ ) ++ output_dir.CleanUp() ++ ++ def testWriteOnlyNew(self): ++ output_dir = util.TempDir({}) ++ builder = build.RcBuilder() ++ class DummyOpts(object): ++ def __init__(self): ++ self.input = util.PathFromRoot('grit/testdata/substitute.grd') ++ self.verbose = False ++ self.extra_verbose = False ++ UNCHANGED = 10 ++ header = output_dir.GetPath('resource.h') ++ ++ builder.Run(DummyOpts(), ['-o', output_dir.GetPath()]) ++ self.failUnless(os.path.exists(header)) ++ first_mtime = os.stat(header).st_mtime ++ ++ os.utime(header, (UNCHANGED, UNCHANGED)) ++ builder.Run(DummyOpts(), ++ ['-o', output_dir.GetPath(), '--write-only-new', '0']) ++ self.failUnless(os.path.exists(header)) ++ second_mtime = os.stat(header).st_mtime ++ ++ os.utime(header, (UNCHANGED, UNCHANGED)) ++ builder.Run(DummyOpts(), ++ ['-o', output_dir.GetPath(), '--write-only-new', '1']) ++ self.failUnless(os.path.exists(header)) ++ third_mtime = os.stat(header).st_mtime ++ ++ self.assertTrue(abs(second_mtime - UNCHANGED) > 5) ++ self.assertTrue(abs(third_mtime - UNCHANGED) < 5) ++ output_dir.CleanUp() ++ ++ def testGenerateDepFileWithDependOnStamp(self): ++ output_dir = util.TempDir({}) ++ builder = build.RcBuilder() ++ class DummyOpts(object): ++ def __init__(self): ++ self.input = util.PathFromRoot('grit/testdata/substitute.grd') ++ self.verbose = False ++ self.extra_verbose = False ++ expected_dep_file_name = 'substitute.grd.d' ++ expected_stamp_file_name = expected_dep_file_name + '.stamp' ++ expected_dep_file = output_dir.GetPath(expected_dep_file_name) ++ expected_stamp_file = output_dir.GetPath(expected_stamp_file_name) ++ if os.path.isfile(expected_stamp_file): ++ os.remove(expected_stamp_file) ++ builder.Run(DummyOpts(), ['-o', output_dir.GetPath(), ++ '--depdir', output_dir.GetPath(), ++ '--depfile', expected_dep_file, ++ '--depend-on-stamp']) ++ self.failUnless(os.path.isfile(expected_stamp_file)) ++ first_mtime = os.stat(expected_stamp_file).st_mtime ++ ++ # Reset mtime to very old. ++ OLDTIME = 10 ++ os.utime(expected_stamp_file, (OLDTIME, OLDTIME)) ++ ++ builder.Run(DummyOpts(), ['-o', output_dir.GetPath(), ++ '--depdir', output_dir.GetPath(), ++ '--depfile', expected_dep_file, ++ '--depend-on-stamp']) ++ self.failUnless(os.path.isfile(expected_stamp_file)) ++ second_mtime = os.stat(expected_stamp_file).st_mtime ++ ++ # Some OS have a 2s stat resolution window, so can't do a direct comparison. ++ self.assertTrue((second_mtime - OLDTIME) > 5) ++ self.assertTrue(abs(second_mtime - first_mtime) < 5) ++ ++ self.failUnless(os.path.isfile(expected_dep_file)) ++ with open(expected_dep_file) as f: ++ line = f.readline() ++ (dep_output_file, deps_string) = line.split(': ') ++ deps = deps_string.split(' ') ++ ++ self.failUnlessEqual(expected_stamp_file_name, dep_output_file) ++ self.failUnlessEqual(deps, [ ++ util.PathFromRoot('grit/testdata/substitute.xmb'), ++ ]) ++ output_dir.CleanUp() ++ ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/tool/buildinfo.py b/tools/grit/grit/tool/buildinfo.py new file mode 100644 -index 0000000000..571d6d667d +index 0000000000..7f8d1a3b04 --- /dev/null -+++ b/tools/clang/plugins/tests/virtual_methods.txt -@@ -0,0 +1,8 @@ -+In file included from virtual_methods.cpp:5: -+./virtual_methods.h:17:36: warning: [chromium-style] virtual methods with non-empty bodies shouldn't be declared inline. -+ virtual bool ComplainAboutThis() { return true; } -+ ^ -+./virtual_methods.h:23:3: warning: [chromium-style] Overriding method must have "virtual" keyword. -+ void MethodHasNoArguments() override; -+ ^ -+2 warnings generated. -diff --git a/tools/clang/scripts/package.sh b/tools/clang/scripts/package.sh -new file mode 100755 -index 0000000000..eb345810b9 ---- /dev/null -+++ b/tools/clang/scripts/package.sh -@@ -0,0 +1,87 @@ -+#!/bin/bash -+# Copyright (c) 2012 The Chromium Authors. All rights reserved. -+# Use of this source code is governed by a BSD-style license that can be -+# found in the LICENSE file. -+ -+# This script will check out llvm and clang, and then package the results up -+# to a tgz file. -+ -+THIS_DIR="$(dirname "${0}")" -+LLVM_DIR="${THIS_DIR}/../../../third_party/llvm" -+LLVM_BOOTSTRAP_DIR="${THIS_DIR}/../../../third_party/llvm-bootstrap" -+LLVM_BUILD_DIR="${THIS_DIR}/../../../third_party/llvm-build" -+LLVM_BIN_DIR="${LLVM_BUILD_DIR}/Release+Asserts/bin" -+LLVM_LIB_DIR="${LLVM_BUILD_DIR}/Release+Asserts/lib" -+ -+echo "Diff in llvm:" | tee buildlog.txt -+svn stat "${LLVM_DIR}" 2>&1 | tee -a buildlog.txt -+svn diff "${LLVM_DIR}" 2>&1 | tee -a buildlog.txt -+echo "Diff in llvm/tools/clang:" | tee -a buildlog.txt -+svn stat "${LLVM_DIR}/tools/clang" 2>&1 | tee -a buildlog.txt -+svn diff "${LLVM_DIR}/tools/clang" 2>&1 | tee -a buildlog.txt -+echo "Diff in llvm/projects/compiler-rt:" | tee -a buildlog.txt -+svn stat "${LLVM_DIR}/projects/compiler-rt" 2>&1 | tee -a buildlog.txt -+svn diff "${LLVM_DIR}/projects/compiler-rt" 2>&1 | tee -a buildlog.txt -+ -+echo "Starting build" | tee -a buildlog.txt -+ -+set -ex -+ -+# Do a clobber build. -+rm -rf "${LLVM_BOOTSTRAP_DIR}" -+rm -rf "${LLVM_BUILD_DIR}" -+"${THIS_DIR}"/update.sh --run-tests --bootstrap --force-local-build 2>&1 | \ -+ tee -a buildlog.txt -+ -+R=$("${LLVM_BIN_DIR}/clang" --version | \ -+ sed -ne 's/clang version .*(trunk \([0-9]*\))/\1/p') -+ -+PDIR=clang-$R -+rm -rf $PDIR -+mkdir $PDIR -+mkdir $PDIR/bin -+mkdir $PDIR/lib -+ -+# Copy buildlog over. -+cp buildlog.txt $PDIR/ -+ -+# Copy clang into pdir, symlink clang++ to it. -+cp "${LLVM_BIN_DIR}/clang" $PDIR/bin/ -+(cd $PDIR/bin && ln -sf clang clang++ && cd -) -+ -+# Copy plugins. Some of the dylibs are pretty big, so copy only the ones we -+# care about. -+if [ "$(uname -s)" = "Darwin" ]; then -+ cp "${LLVM_LIB_DIR}/libFindBadConstructs.dylib" $PDIR/lib -+else -+ cp "${LLVM_LIB_DIR}/libFindBadConstructs.so" $PDIR/lib -+fi -+ -+# Copy built-in headers (lib/clang/3.2/include). -+# libcompiler-rt puts all kinds of libraries there too, but we want only ASan. -+if [ "$(uname -s)" = "Darwin" ]; then -+ # Keep only Release+Asserts/lib/clang/3.2/lib/darwin/libclang_rt.asan_osx.a -+ find "${LLVM_LIB_DIR}/clang" -type f -path '*lib/darwin*' | grep -v asan | \ -+ xargs rm -+else -+ # Keep only -+ # Release+Asserts/lib/clang/3.2/lib/linux/libclang_rt.{asan,tsan}-x86_64.a -+ # TODO(thakis): Make sure the 32bit version of ASan runtime is kept too once -+ # that's built. TSan runtime exists only for 64 bits. -+ find "${LLVM_LIB_DIR}/clang" -type f -path '*lib/linux*' | \ -+ grep -v "asan\|tsan" | xargs rm -+fi -+ -+cp -R "${LLVM_LIB_DIR}/clang" $PDIR/lib -+ -+tar zcf $PDIR.tgz -C $PDIR bin lib buildlog.txt -+ -+if [ "$(uname -s)" = "Darwin" ]; then -+ PLATFORM=Mac -+else -+ PLATFORM=Linux_x64 -+fi -+ -+echo To upload, run: -+echo gsutil cp -a public-read $PDIR.tgz \ -+ gs://chromium-browser-clang/$PLATFORM/$PDIR.tgz -diff --git a/tools/clang/scripts/plugin_flags.sh b/tools/clang/scripts/plugin_flags.sh -new file mode 100755 -index 0000000000..217c5c3bd6 ---- /dev/null -+++ b/tools/clang/scripts/plugin_flags.sh -@@ -0,0 +1,24 @@ -+#!/bin/bash ++++ b/tools/grit/grit/tool/buildinfo.py +@@ -0,0 +1,78 @@ +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + -+# This script returns the flags that should be used when GYP_DEFINES contains -+# clang_use_chrome_plugins. The flags are stored in a script so that they can -+# be changed on the bots without requiring a master restart. ++"""Output the list of files to be generated by GRIT from an input. ++""" + -+THIS_ABS_DIR=$(cd $(dirname $0) && echo $PWD) -+CLANG_LIB_PATH=$THIS_ABS_DIR/../../../third_party/llvm-build/Release+Asserts/lib ++from __future__ import print_function + -+if uname -s | grep -q Darwin; then -+ LIBSUFFIX=dylib -+else -+ LIBSUFFIX=so -+fi ++import getopt ++import os ++import sys + -+echo -Xclang -load -Xclang $CLANG_LIB_PATH/libFindBadConstructs.$LIBSUFFIX \ -+ -Xclang -add-plugin -Xclang find-bad-constructs \ -+ -Xclang -plugin-arg-find-bad-constructs \ -+ -Xclang skip-virtuals-in-implementations \ -+ -Xclang -plugin-arg-find-bad-constructs \ -+ -Xclang check-cc-directory -diff --git a/tools/clang/scripts/update.py b/tools/clang/scripts/update.py -new file mode 100755 -index 0000000000..bdc781f715 ++from grit import grd_reader ++from grit.node import structure ++from grit.tool import interface ++ ++class DetermineBuildInfo(interface.Tool): ++ """Determine what files will be read and output by GRIT. ++Outputs the list of generated files and inputs used to stdout. ++ ++Usage: grit buildinfo [-o DIR] ++ ++The output directory is used for display only. ++""" ++ ++ def __init__(self): ++ pass ++ ++ def ShortDescription(self): ++ """Describes this tool for the usage message.""" ++ return ('Determine what files will be needed and\n' ++ 'output by GRIT with a given input.') ++ ++ def Run(self, opts, args): ++ """Main method for the buildinfo tool.""" ++ self.output_directory = '.' ++ (own_opts, args) = getopt.getopt(args, 'o:', ('help',)) ++ for (key, val) in own_opts: ++ if key == '-o': ++ self.output_directory = val ++ elif key == '--help': ++ self.ShowUsage() ++ sys.exit(0) ++ if len(args) > 0: ++ print('This tool takes exactly one argument: the output directory via -o') ++ return 2 ++ self.SetOptions(opts) ++ ++ res_tree = grd_reader.Parse(opts.input, debug=opts.extra_verbose) ++ ++ langs = {} ++ for output in res_tree.GetOutputFiles(): ++ if output.attrs['lang']: ++ langs[output.attrs['lang']] = os.path.dirname(output.GetFilename()) ++ ++ for lang, dirname in langs.items(): ++ old_output_language = res_tree.output_language ++ res_tree.SetOutputLanguage(lang) ++ for node in res_tree.ActiveDescendants(): ++ with node: ++ if (isinstance(node, structure.StructureNode) and ++ node.HasFileForLanguage()): ++ path = node.FileForLanguage(lang, dirname, create_file=False, ++ return_if_not_generated=False) ++ if path: ++ path = os.path.join(self.output_directory, path) ++ path = os.path.normpath(path) ++ print('%s|%s' % ('rc_all', path)) ++ res_tree.SetOutputLanguage(old_output_language) ++ ++ for output in res_tree.GetOutputFiles(): ++ path = os.path.join(self.output_directory, output.GetFilename()) ++ path = os.path.normpath(path) ++ print('%s|%s' % (output.GetType(), path)) ++ ++ for infile in res_tree.GetInputFiles(): ++ print('input|%s' % os.path.normpath(infile)) +diff --git a/tools/grit/grit/tool/buildinfo_unittest.py b/tools/grit/grit/tool/buildinfo_unittest.py +new file mode 100644 +index 0000000000..24e9ddf8d8 --- /dev/null -+++ b/tools/clang/scripts/update.py -@@ -0,0 +1,34 @@ ++++ b/tools/grit/grit/tool/buildinfo_unittest.py +@@ -0,0 +1,90 @@ +#!/usr/bin/env python +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + -+"""Windows can't run .sh files, so this is a small python wrapper around -+update.sh. ++"""Unit tests for the 'grit buildinfo' tool. +""" + ++from __future__ import print_function ++ +import os -+import subprocess +import sys ++import unittest ++ ++# This is needed to find some of the imports below. ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++from six import StringIO ++ ++# pylint: disable-msg=C6204 ++from grit.tool import buildinfo ++ ++ ++class BuildInfoUnittest(unittest.TestCase): ++ def setUp(self): ++ self.old_cwd = os.getcwd() ++ # Change CWD to make tests work independently of callers CWD. ++ os.chdir(os.path.dirname(__file__)) ++ os.chdir('..') ++ self.buf = StringIO() ++ self.old_stdout = sys.stdout ++ sys.stdout = self.buf ++ ++ def tearDown(self): ++ sys.stdout = self.old_stdout ++ os.chdir(self.old_cwd) ++ ++ def testBuildOutput(self): ++ """Find all of the inputs and outputs for a GRD file.""" ++ info_object = buildinfo.DetermineBuildInfo() ++ ++ class DummyOpts(object): ++ def __init__(self): ++ self.input = '../grit/testdata/buildinfo.grd' ++ self.print_header = False ++ self.verbose = False ++ self.extra_verbose = False ++ info_object.Run(DummyOpts(), []) ++ output = self.buf.getvalue().replace('\\', '/') ++ self.failUnless(output.count(r'rc_all|sv_sidebar_loading.html')) ++ self.failUnless(output.count(r'rc_header|resource.h')) ++ self.failUnless(output.count(r'rc_all|en_generated_resources.rc')) ++ self.failUnless(output.count(r'rc_all|sv_generated_resources.rc')) ++ self.failUnless(output.count(r'input|../grit/testdata/substitute.xmb')) ++ self.failUnless(output.count(r'input|../grit/testdata/pr.bmp')) ++ self.failUnless(output.count(r'input|../grit/testdata/pr2.bmp')) ++ self.failUnless( ++ output.count(r'input|../grit/testdata/sidebar_loading.html')) ++ self.failUnless(output.count(r'input|../grit/testdata/transl.rc')) ++ self.failUnless(output.count(r'input|../grit/testdata/transl1.rc')) ++ ++ def testBuildOutputWithDir(self): ++ """Find all the inputs and outputs for a GRD file with an output dir.""" ++ info_object = buildinfo.DetermineBuildInfo() ++ ++ class DummyOpts(object): ++ def __init__(self): ++ self.input = '../grit/testdata/buildinfo.grd' ++ self.print_header = False ++ self.verbose = False ++ self.extra_verbose = False ++ info_object.Run(DummyOpts(), ['-o', '../grit/testdata']) ++ output = self.buf.getvalue().replace('\\', '/') ++ self.failUnless( ++ output.count(r'rc_all|../grit/testdata/sv_sidebar_loading.html')) ++ self.failUnless(output.count(r'rc_header|../grit/testdata/resource.h')) ++ self.failUnless( ++ output.count(r'rc_all|../grit/testdata/en_generated_resources.rc')) ++ self.failUnless( ++ output.count(r'rc_all|../grit/testdata/sv_generated_resources.rc')) ++ self.failUnless(output.count(r'input|../grit/testdata/substitute.xmb')) ++ self.failUnlessEqual(0, ++ output.count(r'rc_all|../grit/testdata/sv_welcome_toast.html')) ++ self.failUnless( ++ output.count(r'rc_all|../grit/testdata/en_welcome_toast.html')) + + -+def main(): -+ if sys.platform in ['win32', 'cygwin']: ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/tool/count.py b/tools/grit/grit/tool/count.py +new file mode 100644 +index 0000000000..ab37f2ddb3 +--- /dev/null ++++ b/tools/grit/grit/tool/count.py +@@ -0,0 +1,52 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Count number of occurrences of a given message ID.''' ++ ++from __future__ import print_function ++ ++import getopt ++import sys ++ ++from grit import grd_reader ++from grit.tool import interface ++ ++ ++class CountMessage(interface.Tool): ++ '''Count the number of times a given message ID is used.''' ++ ++ def __init__(self): ++ pass ++ ++ def ShortDescription(self): ++ return 'Count the number of times a given message ID is used.' ++ ++ def ParseOptions(self, args): ++ """Set this objects and return all non-option arguments.""" ++ own_opts, args = getopt.getopt(args, '', ('help',)) ++ for key, val in own_opts: ++ if key == '--help': ++ self.ShowUsage() ++ sys.exit(0) ++ return args ++ ++ def Run(self, opts, args): ++ args = self.ParseOptions(args) ++ if len(args) != 1: ++ print('This tool takes a single tool-specific argument, the message ' ++ 'ID to count.') ++ return 2 ++ self.SetOptions(opts) ++ ++ id = args[0] ++ res_tree = grd_reader.Parse(opts.input, debug=opts.extra_verbose) ++ res_tree.OnlyTheseTranslations([]) ++ res_tree.RunGatherers() ++ ++ count = 0 ++ for c in res_tree.UberClique().AllCliques(): ++ if c.GetId() == id: ++ count += 1 ++ ++ print("There are %d occurrences of message %s." % (count, id)) +diff --git a/tools/grit/grit/tool/diff_structures.py b/tools/grit/grit/tool/diff_structures.py +new file mode 100644 +index 0000000000..d69e009b58 +--- /dev/null ++++ b/tools/grit/grit/tool/diff_structures.py +@@ -0,0 +1,119 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''The 'grit sdiff' tool. ++''' ++ ++from __future__ import print_function ++ ++import os ++import getopt ++import sys ++import tempfile ++ ++from grit.node import structure ++from grit.tool import interface ++ ++from grit import constants ++from grit import util ++ ++# Builds the description for the tool (used as the __doc__ ++# for the DiffStructures class). ++_class_doc = """\ ++Allows you to view the differences in the structure of two files, ++disregarding their translateable content. Translateable portions of ++each file are changed to the string "TTTTTT" before invoking the diff program ++specified by the P4DIFF environment variable. ++ ++Usage: grit sdiff [-t TYPE] [-s SECTION] [-e ENCODING] LEFT RIGHT ++ ++LEFT and RIGHT are the files you want to diff. SECTION is required ++for structure types like 'dialog' to identify the part of the file to look at. ++ENCODING indicates the encoding of the left and right files (default 'cp1252'). ++TYPE can be one of the following, defaults to 'tr_html': ++""" ++for gatherer in structure._GATHERERS: ++ _class_doc += " - %s\n" % gatherer ++ ++ ++class DiffStructures(interface.Tool): ++ __doc__ = _class_doc ++ ++ def __init__(self): ++ self.section = None ++ self.left_encoding = 'cp1252' ++ self.right_encoding = 'cp1252' ++ self.structure_type = 'tr_html' ++ ++ def ShortDescription(self): ++ return 'View differences without regard for translateable portions.' ++ ++ def Run(self, global_opts, args): ++ (opts, args) = getopt.getopt(args, 's:e:t:', ++ ('help', 'left_encoding=', 'right_encoding=')) ++ for key, val in opts: ++ if key == '-s': ++ self.section = val ++ elif key == '-e': ++ self.left_encoding = val ++ self.right_encoding = val ++ elif key == '-t': ++ self.structure_type = val ++ elif key == '--left_encoding': ++ self.left_encoding = val ++ elif key == '--right_encoding': ++ self.right_encoding == val ++ elif key == '--help': ++ self.ShowUsage() ++ sys.exit(0) ++ ++ if len(args) != 2: ++ print("Incorrect usage - 'grit help sdiff' for usage details.") ++ return 2 ++ ++ if 'P4DIFF' not in os.environ: ++ print("Environment variable P4DIFF not set; defaulting to 'windiff'.") ++ diff_program = 'windiff' ++ else: ++ diff_program = os.environ['P4DIFF'] ++ ++ left_trans = self.MakeStaticTranslation(args[0], self.left_encoding) ++ try: ++ try: ++ right_trans = self.MakeStaticTranslation(args[1], self.right_encoding) ++ ++ os.system('%s %s %s' % (diff_program, left_trans, right_trans)) ++ finally: ++ os.unlink(right_trans) ++ finally: ++ os.unlink(left_trans) ++ ++ def MakeStaticTranslation(self, original_filename, encoding): ++ """Given the name of the structure type (self.structure_type), the filename ++ of the file holding the original structure, and optionally the "section" key ++ identifying the part of the file to look at (self.section), creates a ++ temporary file holding a "static" translation of the original structure ++ (i.e. one where all translateable parts have been replaced with "TTTTTT") ++ and returns the temporary file name. It is the caller's responsibility to ++ delete the file when finished. ++ ++ Args: ++ original_filename: 'c:\\bingo\\bla.rc' ++ ++ Return: ++ 'c:\\temp\\werlkjsdf334.tmp' ++ """ ++ original = structure._GATHERERS[self.structure_type](original_filename, ++ extkey=self.section, ++ encoding=encoding) ++ original.Parse() ++ translated = original.Translate(constants.CONSTANT_LANGUAGE, False) ++ ++ fname = tempfile.mktemp() ++ with util.WrapOutputStream(open(fname, 'wb')) as writer: ++ writer.write("Original filename: %s\n=============\n\n" ++ % original_filename) ++ writer.write(translated) # write in UTF-8 ++ ++ return fname +diff --git a/tools/grit/grit/tool/diff_structures_unittest.py b/tools/grit/grit/tool/diff_structures_unittest.py +new file mode 100644 +index 0000000000..a6d7585761 +--- /dev/null ++++ b/tools/grit/grit/tool/diff_structures_unittest.py +@@ -0,0 +1,46 @@ ++#!/usr/bin/env python ++# Copyright 2020 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for the 'grit newgrd' tool.''' ++ ++from __future__ import print_function ++ ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++import unittest ++ ++from grit.tool import diff_structures ++ ++ ++class DummyOpts(object): ++ """Options needed by NewGrd.""" ++ ++ ++class DiffStructuresUnittest(unittest.TestCase): ++ ++ def testMissingFiles(self): ++ """Verify failure w/out file inputs.""" ++ tool = diff_structures.DiffStructures() ++ ret = tool.Run(DummyOpts(), []) ++ self.assertIsNotNone(ret) ++ self.assertGreater(ret, 0) ++ ++ ret = tool.Run(DummyOpts(), ['left']) ++ self.assertIsNotNone(ret) ++ self.assertGreater(ret, 0) ++ ++ def testTooManyArgs(self): ++ """Verify failure w/too many inputs.""" ++ tool = diff_structures.DiffStructures() ++ ret = tool.Run(DummyOpts(), ['a', 'b', 'c']) ++ self.assertIsNotNone(ret) ++ self.assertGreater(ret, 0) ++ ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/tool/interface.py b/tools/grit/grit/tool/interface.py +new file mode 100644 +index 0000000000..e923205223 +--- /dev/null ++++ b/tools/grit/grit/tool/interface.py +@@ -0,0 +1,62 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Base class and interface for tools. ++''' ++ ++from __future__ import print_function ++ ++class Tool(object): ++ '''Base class for all tools. Tools should use their docstring (i.e. the ++ class-level docstring) for the help they want to have printed when they ++ are invoked.''' ++ ++ # ++ # Interface (abstract methods) ++ # ++ ++ def ShortDescription(self): ++ '''Returns a short description of the functionality of the tool.''' ++ raise NotImplementedError() ++ ++ def Run(self, global_options, my_arguments): ++ '''Runs the tool. ++ ++ Args: ++ global_options: object grit_runner.Options ++ my_arguments: [arg1 arg2 ...] ++ ++ Return: ++ 0 for success, non-0 for error ++ ''' ++ raise NotImplementedError() ++ ++ # ++ # Base class implementation ++ # ++ ++ def __init__(self): ++ self.o = None ++ ++ def ShowUsage(self): ++ '''Show usage text for this tool.''' ++ print(self.__doc__) ++ ++ def SetOptions(self, opts): ++ self.o = opts ++ ++ def Out(self, text): ++ '''Always writes out 'text'.''' ++ self.o.output_stream.write(text) ++ ++ def VerboseOut(self, text): ++ '''Writes out 'text' if the verbose option is on.''' ++ if self.o.verbose: ++ self.o.output_stream.write(text) ++ ++ def ExtraVerboseOut(self, text): ++ '''Writes out 'text' if the extra-verbose option is on. ++ ''' ++ if self.o.extra_verbose: ++ self.o.output_stream.write(text) +diff --git a/tools/grit/grit/tool/menu_from_parts.py b/tools/grit/grit/tool/menu_from_parts.py +new file mode 100644 +index 0000000000..fcec26c5b1 +--- /dev/null ++++ b/tools/grit/grit/tool/menu_from_parts.py +@@ -0,0 +1,79 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''The 'grit menufromparts' tool.''' ++ ++from __future__ import print_function ++ ++import six ++ ++from grit import grd_reader ++from grit import util ++from grit import xtb_reader ++from grit.tool import interface ++from grit.tool import transl2tc ++ ++import grit.extern.tclib ++ ++ ++class MenuTranslationsFromParts(interface.Tool): ++ '''One-off tool to generate translated menu messages (where each menu is kept ++in a single message) based on existing translations of the individual menu ++items. Was needed when changing menus from being one message per menu item ++to being one message for the whole menu.''' ++ ++ def ShortDescription(self): ++ return ('Create translations of whole menus from existing translations of ' ++ 'menu items.') ++ ++ def Run(self, globopt, args): ++ self.SetOptions(globopt) ++ assert len(args) == 2, "Need exactly two arguments, the XTB file and the output file" ++ ++ xtb_file = args[0] ++ output_file = args[1] ++ ++ grd = grd_reader.Parse(self.o.input, debug=self.o.extra_verbose) ++ grd.OnlyTheseTranslations([]) # don't load translations ++ grd.RunGatherers() ++ ++ xtb = {} ++ def Callback(msg_id, parts): ++ msg = [] ++ for part in parts: ++ if part[0]: ++ msg = [] ++ break # it had a placeholder so ignore it ++ else: ++ msg.append(part[1]) ++ if len(msg): ++ xtb[msg_id] = ''.join(msg) ++ with open(xtb_file, 'rb') as f: ++ xtb_reader.Parse(f, Callback) ++ ++ translations = [] # list of translations as per transl2tc.WriteTranslations ++ for node in grd: ++ if node.name == 'structure' and node.attrs['type'] == 'menu': ++ assert len(node.GetCliques()) == 1 ++ message = node.GetCliques()[0].GetMessage() ++ translation = [] ++ ++ contents = message.GetContent() ++ for part in contents: ++ if isinstance(part, six.string_types): ++ id = grit.extern.tclib.GenerateMessageId(part) ++ if id not in xtb: ++ print("WARNING didn't find all translations for menu %s" % ++ (node.attrs['name'],)) ++ translation = [] ++ break ++ translation.append(xtb[id]) ++ else: ++ translation.append(part.GetPresentation()) ++ ++ if len(translation): ++ translations.append([message.GetId(), ''.join(translation)]) ++ ++ with util.WrapOutputStream(open(output_file, 'wb')) as f: ++ transl2tc.TranslationToTc.WriteTranslations(f, translations) +diff --git a/tools/grit/grit/tool/newgrd.py b/tools/grit/grit/tool/newgrd.py +new file mode 100644 +index 0000000000..66a18e9c04 +--- /dev/null ++++ b/tools/grit/grit/tool/newgrd.py +@@ -0,0 +1,85 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Tool to create a new, empty .grd file with all the basic sections. ++''' ++ ++from __future__ import print_function ++ ++import getopt ++import sys ++ ++from grit.tool import interface ++from grit import constants ++from grit import util ++ ++# The contents of the new .grd file ++_FILE_CONTENTS = '''\ ++<?xml version="1.0" encoding="UTF-8"?> ++<grit base_dir="." latest_public_release="0" current_release="1" ++ source_lang_id="en" enc_check="%s"> ++ <outputs> ++ <!-- TODO add each of your output files. Modify the three below, and add ++ your own for your various languages. See the user's guide for more ++ details. ++ Note that all output references are relative to the output directory ++ which is specified at build time. --> ++ <output filename="resource.h" type="rc_header" /> ++ <output filename="en_resource.rc" type="rc_all" /> ++ <output filename="fr_resource.rc" type="rc_all" /> ++ </outputs> ++ <translations> ++ <!-- TODO add references to each of the XTB files (from the Translation ++ Console) that contain translations of messages in your project. Each ++ takes a form like <file path="english.xtb" />. Remember that all file ++ references are relative to this .grd file. --> ++ </translations> ++ <release seq="1"> ++ <includes> ++ <!-- TODO add a list of your included resources here, e.g. BMP and GIF ++ resources. --> ++ </includes> ++ <structures> ++ <!-- TODO add a list of all your structured resources here, e.g. HTML ++ templates, menus, dialogs etc. Note that for menus, dialogs and version ++ information resources you reference an .rc file containing them.--> ++ </structures> ++ <messages> ++ <!-- TODO add all of your "string table" messages here. Remember to ++ change nontranslateable parts of the messages into placeholders (using the ++ <ph> element). You can also use the 'grit add' tool to help you identify ++ nontranslateable parts and create placeholders for them. --> ++ </messages> ++ </release> ++</grit>''' % constants.ENCODING_CHECK ++ ++ ++class NewGrd(interface.Tool): ++ '''Usage: grit newgrd OUTPUT_FILE ++ ++Creates a new, empty .grd file OUTPUT_FILE with comments about what to put ++where in the file.''' ++ ++ def ShortDescription(self): ++ return 'Create a new empty .grd file.' ++ ++ def ParseOptions(self, args): ++ """Set this objects and return all non-option arguments.""" ++ own_opts, args = getopt.getopt(args, '', ('help',)) ++ for key, val in own_opts: ++ if key == '--help': ++ self.ShowUsage() ++ sys.exit(0) ++ return args ++ ++ def Run(self, opts, args): ++ args = self.ParseOptions(args) ++ if len(args) != 1: ++ print('This tool requires exactly one argument, the name of the output ' ++ 'file.') ++ return 2 ++ filename = args[0] ++ with util.WrapOutputStream(open(filename, 'wb'), 'utf-8') as out: ++ out.write(_FILE_CONTENTS) ++ print("Wrote file %s" % filename) +diff --git a/tools/grit/grit/tool/newgrd_unittest.py b/tools/grit/grit/tool/newgrd_unittest.py +new file mode 100644 +index 0000000000..f7c8831df5 +--- /dev/null ++++ b/tools/grit/grit/tool/newgrd_unittest.py +@@ -0,0 +1,51 @@ ++#!/usr/bin/env python ++# Copyright 2020 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for the 'grit newgrd' tool.''' ++ ++from __future__ import print_function ++ ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++import unittest ++ ++from grit import util ++from grit.tool import newgrd ++ ++ ++class DummyOpts(object): ++ """Options needed by NewGrd.""" ++ ++ ++class NewgrdUnittest(unittest.TestCase): ++ ++ def testNewFile(self): ++ """Create a new file.""" ++ tool = newgrd.NewGrd() ++ with util.TempDir({}) as output_dir: ++ output_file = os.path.join(output_dir.GetPath(), 'new.grd') ++ self.assertIsNone(tool.Run(DummyOpts(), [output_file])) ++ self.assertTrue(os.path.exists(output_file)) ++ ++ def testMissingFile(self): ++ """Verify failure w/out file output.""" ++ tool = newgrd.NewGrd() ++ ret = tool.Run(DummyOpts(), []) ++ self.assertIsNotNone(ret) ++ self.assertGreater(ret, 0) ++ ++ def testTooManyArgs(self): ++ """Verify failure w/too many outputs.""" ++ tool = newgrd.NewGrd() ++ ret = tool.Run(DummyOpts(), ['a', 'b']) ++ self.assertIsNotNone(ret) ++ self.assertGreater(ret, 0) ++ ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/tool/postprocess_interface.py b/tools/grit/grit/tool/postprocess_interface.py +new file mode 100644 +index 0000000000..4bb8c5871f +--- /dev/null ++++ b/tools/grit/grit/tool/postprocess_interface.py +@@ -0,0 +1,29 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++''' Base class for postprocessing of RC files. ++''' ++ ++from __future__ import print_function ++ ++class PostProcessor(object): ++ ''' Base class for postprocessing of the RC file data before being ++ output through the RC2GRD tool. You should implement this class if ++ you want GRIT to do specific things to the RC files after it has ++ converted the data into GRD format, i.e. change the content of the ++ RC file, and put it into a P4 changelist, etc.''' ++ ++ ++ def Process(self, rctext, rcpath, grdnode): ++ ''' Processes the data in rctext and grdnode. ++ Args: ++ rctext: string containing the contents of the RC file being processed. ++ rcpath: the path used to access the file. ++ grdtext: the root node of the grd xml data generated by ++ the rc2grd tool. ++ ++ Return: ++ The root node of the processed GRD tree. ++ ''' ++ raise NotImplementedError() +diff --git a/tools/grit/grit/tool/postprocess_unittest.py b/tools/grit/grit/tool/postprocess_unittest.py +new file mode 100644 +index 0000000000..77fe228bbe +--- /dev/null ++++ b/tools/grit/grit/tool/postprocess_unittest.py +@@ -0,0 +1,64 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit test that checks postprocessing of files. ++ Tests postprocessing by having the postprocessor ++ modify the grd data tree, changing the message name attributes. ++''' ++ ++from __future__ import print_function ++ ++import os ++import re ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++import unittest ++ ++import grit.tool.postprocess_interface ++from grit.tool import rc2grd ++ ++ ++class PostProcessingUnittest(unittest.TestCase): ++ ++ def testPostProcessing(self): ++ rctext = '''STRINGTABLE ++BEGIN ++ DUMMY_STRING_1 "String 1" ++ // Some random description ++ DUMMY_STRING_2 "This text was added during preprocessing" ++END ++ ''' ++ tool = rc2grd.Rc2Grd() ++ class DummyOpts(object): ++ verbose = False ++ extra_verbose = False ++ tool.o = DummyOpts() ++ tool.post_process = 'grit.tool.postprocess_unittest.DummyPostProcessor' ++ result = tool.Process(rctext, '.\resource.rc') ++ ++ self.failUnless( ++ result.children[2].children[2].children[0].attrs['name'] == 'SMART_STRING_1') ++ self.failUnless( ++ result.children[2].children[2].children[1].attrs['name'] == 'SMART_STRING_2') ++ ++class DummyPostProcessor(grit.tool.postprocess_interface.PostProcessor): ++ ''' ++ Post processing replaces all message name attributes containing "DUMMY" to ++ "SMART". ++ ''' ++ def Process(self, rctext, rcpath, grdnode): ++ smarter = re.compile(r'(DUMMY)(.*)') ++ messages = grdnode.children[2].children[2] ++ for node in messages.children: ++ name_attr = node.attrs['name'] ++ m = smarter.search(name_attr) ++ if m: ++ node.attrs['name'] = 'SMART' + m.group(2) ++ return grdnode ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/tool/preprocess_interface.py b/tools/grit/grit/tool/preprocess_interface.py +new file mode 100644 +index 0000000000..67974e704e +--- /dev/null ++++ b/tools/grit/grit/tool/preprocess_interface.py +@@ -0,0 +1,25 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++''' Base class for preprocessing of RC files. ++''' ++ ++from __future__ import print_function ++ ++class PreProcessor(object): ++ ''' Base class for preprocessing of the RC file data before being ++ output through the RC2GRD tool. You should implement this class if ++ you have specific constructs in your RC files that GRIT cannot handle.''' ++ ++ ++ def Process(self, rctext, rcpath): ++ ''' Processes the data in rctext. ++ Args: ++ rctext: string containing the contents of the RC file being processed ++ rcpath: the path used to access the file. ++ ++ Return: ++ The processed text. ++ ''' ++ raise NotImplementedError() +diff --git a/tools/grit/grit/tool/preprocess_unittest.py b/tools/grit/grit/tool/preprocess_unittest.py +new file mode 100644 +index 0000000000..40b95cd6f8 +--- /dev/null ++++ b/tools/grit/grit/tool/preprocess_unittest.py +@@ -0,0 +1,50 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit test that checks preprocessing of files. ++ Tests preprocessing by adding having the preprocessor ++ provide the actual rctext data. ++''' ++ ++from __future__ import print_function ++ ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++import unittest ++ ++import grit.tool.preprocess_interface ++from grit.tool import rc2grd ++ ++ ++class PreProcessingUnittest(unittest.TestCase): ++ ++ def testPreProcessing(self): ++ tool = rc2grd.Rc2Grd() ++ class DummyOpts(object): ++ verbose = False ++ extra_verbose = False ++ tool.o = DummyOpts() ++ tool.pre_process = 'grit.tool.preprocess_unittest.DummyPreProcessor' ++ result = tool.Process('', '.\resource.rc') ++ ++ self.failUnless( ++ result.children[2].children[2].children[0].attrs['name'] == 'DUMMY_STRING_1') ++ ++class DummyPreProcessor(grit.tool.preprocess_interface.PreProcessor): ++ def Process(self, rctext, rcpath): ++ rctext = '''STRINGTABLE ++BEGIN ++ DUMMY_STRING_1 "String 1" ++ // Some random description ++ DUMMY_STRING_2 "This text was added during preprocessing" ++END ++ ''' ++ return rctext ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/tool/rc2grd.py b/tools/grit/grit/tool/rc2grd.py +new file mode 100644 +index 0000000000..3195b39000 +--- /dev/null ++++ b/tools/grit/grit/tool/rc2grd.py +@@ -0,0 +1,418 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''The 'grit rc2grd' tool.''' ++ ++from __future__ import print_function ++ ++import os.path ++import getopt ++import re ++import sys ++ ++import six ++from six import StringIO ++ ++import grit.node.empty ++from grit.node import include ++from grit.node import structure ++from grit.node import message ++ ++from grit.gather import rc ++from grit.gather import tr_html ++ ++from grit.tool import interface ++from grit.tool import postprocess_interface ++from grit.tool import preprocess_interface ++ ++from grit import grd_reader ++from grit import lazy_re ++from grit import tclib ++from grit import util ++ ++ ++# Matches files referenced from an .rc file ++_FILE_REF = lazy_re.compile(r''' ++ ^(?P<id>[A-Z_0-9.]+)[ \t]+ ++ (?P<type>[A-Z_0-9]+)[ \t]+ ++ "(?P<file>.*?([^"]|""))"[ \t]*$''', re.VERBOSE | re.MULTILINE) ++ ++ ++# Matches a dialog section ++_DIALOG = lazy_re.compile( ++ r'^(?P<id>[A-Z0-9_]+)\s+DIALOG(EX)?\s.+?^BEGIN\s*$.+?^END\s*$', ++ re.MULTILINE | re.DOTALL) ++ ++ ++# Matches a menu section ++_MENU = lazy_re.compile(r'^(?P<id>[A-Z0-9_]+)\s+MENU.+?^BEGIN\s*$.+?^END\s*$', ++ re.MULTILINE | re.DOTALL) ++ ++ ++# Matches a versioninfo section ++_VERSIONINFO = lazy_re.compile( ++ r'^(?P<id>[A-Z0-9_]+)\s+VERSIONINFO\s.+?^BEGIN\s*$.+?^END\s*$', ++ re.MULTILINE | re.DOTALL) ++ ++ ++# Matches a stringtable ++_STRING_TABLE = lazy_re.compile( ++ (r'^STRINGTABLE(\s+(PRELOAD|DISCARDABLE|CHARACTERISTICS.+|LANGUAGE.+|' ++ r'VERSION.+))*\s*\nBEGIN\s*$(?P<body>.+?)^END\s*$'), ++ re.MULTILINE | re.DOTALL) ++ ++ ++# Matches each message inside a stringtable, breaking it up into comments, ++# the ID of the message, and the (RC-escaped) message text. ++_MESSAGE = lazy_re.compile(r''' ++ (?P<comment>(^\s+//.+?)*) # 0 or more lines of comments preceding the message ++ ^\s* ++ (?P<id>[A-Za-z0-9_]+) # id ++ \s+ ++ "(?P<text>.*?([^"]|""))"([^"]|$) # The message itself ++ ''', re.MULTILINE | re.DOTALL | re.VERBOSE) ++ ++ ++# Matches each line of comment text in a multi-line comment. ++_COMMENT_TEXT = lazy_re.compile(r'^\s*//\s*(?P<text>.+?)$', re.MULTILINE) ++ ++ ++# Matches a string that is empty or all whitespace ++_WHITESPACE_ONLY = lazy_re.compile(r'\A\s*\Z', re.MULTILINE) ++ ++ ++# Finds printf and FormatMessage style format specifiers ++# Uses non-capturing groups except for the outermost group, so the output of ++# re.split() should include both the normal text and what we intend to ++# replace with placeholders. ++# TODO(joi) Check documentation for printf (and Windows variants) and FormatMessage ++_FORMAT_SPECIFIER = lazy_re.compile( ++ r'(%[-# +]?(?:[0-9]*|\*)(?:\.(?:[0-9]+|\*))?(?:h|l|L)?' # printf up to last char ++ r'(?:d|i|o|u|x|X|e|E|f|F|g|G|c|r|s|ls|ws)' # printf last char ++ r'|\$[1-9][0-9]*)') # FormatMessage ++ ++ ++class Rc2Grd(interface.Tool): ++ '''A tool for converting .rc files to .grd files. This tool is only for ++converting the source (nontranslated) .rc file to a .grd file. For importing ++existing translations, use the rc2xtb tool. ++ ++Usage: grit [global options] rc2grd [OPTIONS] RCFILE ++ ++The tool takes a single argument, which is the path to the .rc file to convert. ++It outputs a .grd file with the same name in the same directory as the .rc file. ++The .grd file may have one or more TODO comments for things that have to be ++cleaned up manually. ++ ++OPTIONS may be any of the following: ++ ++ -e ENCODING Specify the ENCODING of the .rc file. Default is 'cp1252'. ++ ++ -h TYPE Specify the TYPE attribute for HTML structures. ++ Default is 'tr_html'. ++ ++ -u ENCODING Specify the ENCODING of HTML files. Default is 'utf-8'. ++ ++ -n MATCH Specify the regular expression to match in comments that will ++ indicate that the resource the comment belongs to is not ++ translateable. Default is 'Not locali(s|z)able'. ++ ++ -r GRDFILE Specify that GRDFILE should be used as a "role model" for ++ any placeholders that otherwise would have had TODO names. ++ This attempts to find an identical message in the GRDFILE ++ and uses that instead of the automatically placeholderized ++ message. ++ ++ --pre CLASS Specify an optional, fully qualified classname, which ++ has to be a subclass of grit.tool.PreProcessor, to ++ run on the text of the RC file before conversion occurs. ++ This can be used to support constructs in the RC files ++ that GRIT cannot handle on its own. ++ ++ --post CLASS Specify an optional, fully qualified classname, which ++ has to be a subclass of grit.tool.PostProcessor, to ++ run on the text of the converted RC file. ++ This can be used to alter the content of the RC file ++ based on the conversion that occured. ++ ++For menus, dialogs and version info, the .grd file will refer to the original ++.rc file. Once conversion is complete, you can strip the original .rc file ++of its string table and all comments as these will be available in the .grd ++file. ++ ++Note that this tool WILL NOT obey C preprocessor rules, so even if something ++is #if 0-ed out it will still be included in the output of this tool ++Therefore, if your .rc file contains sections like this, you should run the ++C preprocessor on the .rc file or manually edit it before using this tool. ++''' ++ ++ def ShortDescription(self): ++ return 'A tool for converting .rc source files to .grd files.' ++ ++ def __init__(self): ++ self.input_encoding = 'cp1252' ++ self.html_type = 'tr_html' ++ self.html_encoding = 'utf-8' ++ self.not_localizable_re = re.compile('Not locali(s|z)able') ++ self.role_model = None ++ self.pre_process = None ++ self.post_process = None ++ ++ def ParseOptions(self, args, help_func=None): ++ '''Given a list of arguments, set this object's options and return ++ all non-option arguments. ++ ''' ++ (own_opts, args) = getopt.getopt(args, 'e:h:u:n:r', ++ ('help', 'pre=', 'post=')) ++ for (key, val) in own_opts: ++ if key == '-e': ++ self.input_encoding = val ++ elif key == '-h': ++ self.html_type = val ++ elif key == '-u': ++ self.html_encoding = val ++ elif key == '-n': ++ self.not_localizable_re = re.compile(val) ++ elif key == '-r': ++ self.role_model = grd_reader.Parse(val) ++ elif key == '--pre': ++ self.pre_process = val ++ elif key == '--post': ++ self.post_process = val ++ elif key == '--help': ++ if help_func is None: ++ self.ShowUsage() ++ else: ++ help_func() ++ sys.exit(0) ++ return args ++ ++ def Run(self, opts, args): ++ args = self.ParseOptions(args) ++ if len(args) != 1: ++ print('This tool takes a single tool-specific argument, the path to the\n' ++ '.rc file to process.') ++ return 2 ++ self.SetOptions(opts) ++ ++ path = args[0] ++ out_path = os.path.join(util.dirname(path), ++ os.path.splitext(os.path.basename(path))[0] + '.grd') ++ ++ rctext = util.ReadFile(path, self.input_encoding) ++ grd_text = six.text_type(self.Process(rctext, path)) ++ with util.WrapOutputStream(open(out_path, 'wb'), 'utf-8') as outfile: ++ outfile.write(grd_text) ++ ++ print('Wrote output file %s.\nPlease check for TODO items in the file.' % ++ (out_path,)) ++ ++ ++ def Process(self, rctext, rc_path): ++ '''Processes 'rctext' and returns a resource tree corresponding to it. ++ ++ Args: ++ rctext: complete text of the rc file ++ rc_path: 'resource\resource.rc' ++ ++ Return: ++ grit.node.base.Node subclass ++ ''' ++ ++ if self.pre_process: ++ preprocess_class = util.NewClassInstance(self.pre_process, ++ preprocess_interface.PreProcessor) ++ if preprocess_class: ++ rctext = preprocess_class.Process(rctext, rc_path) ++ else: ++ self.Out( ++ 'PreProcessing class could not be found. Skipping preprocessing.\n') ++ ++ # Start with a basic skeleton for the .grd file ++ root = grd_reader.Parse(StringIO( ++ '''<?xml version="1.0" encoding="UTF-8"?> ++ <grit base_dir="." latest_public_release="0" ++ current_release="1" source_lang_id="en"> ++ <outputs /> ++ <translations /> ++ <release seq="1"> ++ <includes /> ++ <structures /> ++ <messages /> ++ </release> ++ </grit>'''), util.dirname(rc_path)) ++ includes = root.children[2].children[0] ++ structures = root.children[2].children[1] ++ messages = root.children[2].children[2] ++ assert (isinstance(includes, grit.node.empty.IncludesNode) and ++ isinstance(structures, grit.node.empty.StructuresNode) and ++ isinstance(messages, grit.node.empty.MessagesNode)) ++ ++ self.AddIncludes(rctext, includes) ++ self.AddStructures(rctext, structures, os.path.basename(rc_path)) ++ self.AddMessages(rctext, messages) ++ ++ self.VerboseOut('Validating that all IDs are unique...\n') ++ root.ValidateUniqueIds() ++ self.ExtraVerboseOut('Done validating that all IDs are unique.\n') ++ ++ if self.post_process: ++ postprocess_class = util.NewClassInstance(self.post_process, ++ postprocess_interface.PostProcessor) ++ if postprocess_class: ++ root = postprocess_class.Process(rctext, rc_path, root) ++ else: ++ self.Out( ++ 'PostProcessing class could not be found. Skipping postprocessing.\n') ++ ++ return root ++ ++ ++ def IsHtml(self, res_type, fname): ++ '''Check whether both the type and file extension indicate HTML''' ++ fext = fname.split('.')[-1].lower() ++ return res_type == 'HTML' and fext in ('htm', 'html') ++ ++ ++ def AddIncludes(self, rctext, node): ++ '''Scans 'rctext' for included resources (e.g. BITMAP, ICON) and ++ adds each included resource as an <include> child node of 'node'.''' ++ for m in _FILE_REF.finditer(rctext): ++ id = m.group('id') ++ res_type = m.group('type').upper() ++ fname = rc.Section.UnEscape(m.group('file')) ++ assert fname.find('\n') == -1 ++ if not self.IsHtml(res_type, fname): ++ self.VerboseOut('Processing %s with ID %s (filename: %s)\n' % ++ (res_type, id, fname)) ++ node.AddChild(include.IncludeNode.Construct(node, id, res_type, fname)) ++ ++ ++ def AddStructures(self, rctext, node, rc_filename): ++ '''Scans 'rctext' for structured resources (e.g. menus, dialogs, version ++ information resources and HTML templates) and adds each as a <structure> ++ child of 'node'.''' ++ # First add HTML includes ++ for m in _FILE_REF.finditer(rctext): ++ id = m.group('id') ++ res_type = m.group('type').upper() ++ fname = rc.Section.UnEscape(m.group('file')) ++ if self.IsHtml(type, fname): ++ node.AddChild(structure.StructureNode.Construct( ++ node, id, self.html_type, fname, self.html_encoding)) ++ ++ # Then add all RC includes ++ def AddStructure(res_type, id): ++ self.VerboseOut('Processing %s with ID %s\n' % (res_type, id)) ++ node.AddChild(structure.StructureNode.Construct(node, id, res_type, ++ rc_filename, ++ encoding=self.input_encoding)) ++ for m in _MENU.finditer(rctext): ++ AddStructure('menu', m.group('id')) ++ for m in _DIALOG.finditer(rctext): ++ AddStructure('dialog', m.group('id')) ++ for m in _VERSIONINFO.finditer(rctext): ++ AddStructure('version', m.group('id')) ++ ++ ++ def AddMessages(self, rctext, node): ++ '''Scans 'rctext' for all messages in string tables, preprocesses them as ++ much as possible for placeholders (e.g. messages containing $1, $2 or %s, %d ++ type format specifiers get those specifiers replaced with placeholders, and ++ HTML-formatted messages get run through the HTML-placeholderizer). Adds ++ each message as a <message> node child of 'node'.''' ++ for tm in _STRING_TABLE.finditer(rctext): ++ table = tm.group('body') ++ for mm in _MESSAGE.finditer(table): ++ comment_block = mm.group('comment') ++ comment_text = [] ++ for cm in _COMMENT_TEXT.finditer(comment_block): ++ comment_text.append(cm.group('text')) ++ comment_text = ' '.join(comment_text) ++ ++ id = mm.group('id') ++ text = rc.Section.UnEscape(mm.group('text')) ++ ++ self.VerboseOut('Processing message %s (text: "%s")\n' % (id, text)) ++ ++ msg_obj = self.Placeholderize(text) ++ ++ # Messages that contain only placeholders do not need translation. ++ is_translateable = False ++ for item in msg_obj.GetContent(): ++ if isinstance(item, six.string_types): ++ if not _WHITESPACE_ONLY.match(item): ++ is_translateable = True ++ ++ if self.not_localizable_re.search(comment_text): ++ is_translateable = False ++ ++ message_meaning = '' ++ internal_comment = '' ++ ++ # If we have a "role model" (existing GRD file) and this node exists ++ # in the role model, use the description, meaning and translateable ++ # attributes from the role model. ++ if self.role_model: ++ role_node = self.role_model.GetNodeById(id) ++ if role_node: ++ is_translateable = role_node.IsTranslateable() ++ message_meaning = role_node.attrs['meaning'] ++ comment_text = role_node.attrs['desc'] ++ internal_comment = role_node.attrs['internal_comment'] ++ ++ # For nontranslateable messages, we don't want the complexity of ++ # placeholderizing everything. ++ if not is_translateable: ++ msg_obj = tclib.Message(text=text) ++ ++ msg_node = message.MessageNode.Construct(node, msg_obj, id, ++ desc=comment_text, ++ translateable=is_translateable, ++ meaning=message_meaning) ++ msg_node.attrs['internal_comment'] = internal_comment ++ ++ node.AddChild(msg_node) ++ self.ExtraVerboseOut('Done processing message %s\n' % id) ++ ++ ++ def Placeholderize(self, text): ++ '''Creates a tclib.Message object from 'text', attempting to recognize ++ a few different formats of text that can be automatically placeholderized ++ (HTML code, printf-style format strings, and FormatMessage-style format ++ strings). ++ ''' ++ ++ try: ++ # First try HTML placeholderizing. ++ # TODO(joi) Allow use of non-TotalRecall flavors of HTML placeholderizing ++ msg = tr_html.HtmlToMessage(text, True) ++ for item in msg.GetContent(): ++ if not isinstance(item, six.string_types): ++ return msg # Contained at least one placeholder, so we're done ++ ++ # HTML placeholderization didn't do anything, so try to find printf or ++ # FormatMessage format specifiers and change them into placeholders. ++ msg = tclib.Message() ++ parts = _FORMAT_SPECIFIER.split(text) ++ todo_counter = 1 # We make placeholder IDs 'TODO_0001' etc. ++ for part in parts: ++ if _FORMAT_SPECIFIER.match(part): ++ msg.AppendPlaceholder(tclib.Placeholder( ++ 'TODO_%04d' % todo_counter, part, 'TODO')) ++ todo_counter += 1 ++ elif part != '': ++ msg.AppendText(part) ++ ++ if self.role_model and len(parts) > 1: # there are TODO placeholders ++ role_model_msg = self.role_model.UberClique().BestCliqueByOriginalText( ++ msg.GetRealContent(), '') ++ if role_model_msg: ++ # replace wholesale to get placeholder names and examples ++ msg = role_model_msg ++ ++ return msg ++ except: ++ print('Exception processing message with text "%s"' % text) ++ raise +diff --git a/tools/grit/grit/tool/rc2grd_unittest.py b/tools/grit/grit/tool/rc2grd_unittest.py +new file mode 100644 +index 0000000000..6d53794c27 +--- /dev/null ++++ b/tools/grit/grit/tool/rc2grd_unittest.py +@@ -0,0 +1,163 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for grit.tool.rc2grd''' ++ ++from __future__ import print_function ++ ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++import re ++import unittest ++ ++from six import StringIO ++ ++from grit import grd_reader ++from grit import util ++from grit.node import base ++from grit.tool import rc2grd ++ ++ ++class Rc2GrdUnittest(unittest.TestCase): ++ def testPlaceholderize(self): ++ tool = rc2grd.Rc2Grd() ++ original = "Hello %s, how are you? I'm $1 years old!" ++ msg = tool.Placeholderize(original) ++ self.failUnless(msg.GetPresentableContent() == "Hello TODO_0001, how are you? I'm TODO_0002 years old!") ++ self.failUnless(msg.GetRealContent() == original) ++ ++ def testHtmlPlaceholderize(self): ++ tool = rc2grd.Rc2Grd() ++ original = "Hello <b>[USERNAME]</b>, how are you? I'm [AGE] years old!" ++ msg = tool.Placeholderize(original) ++ self.failUnless(msg.GetPresentableContent() == ++ "Hello BEGIN_BOLDX_USERNAME_XEND_BOLD, how are you? I'm X_AGE_X years old!") ++ self.failUnless(msg.GetRealContent() == original) ++ ++ def testMenuWithoutWhitespaceRegression(self): ++ # There was a problem in the original regular expression for parsing out ++ # menu sections, that would parse the following block of text as a single ++ # menu instead of two. ++ two_menus = ''' ++// Hyper context menus ++IDR_HYPERMENU_FOLDER MENU ++BEGIN ++ POPUP "HyperFolder" ++ BEGIN ++ MENUITEM "Open Containing Folder", IDM_OPENFOLDER ++ END ++END ++ ++IDR_HYPERMENU_FILE MENU ++BEGIN ++ POPUP "HyperFile" ++ BEGIN ++ MENUITEM "Open Folder", IDM_OPENFOLDER ++ END ++END ++ ++''' ++ self.failUnless(len(rc2grd._MENU.findall(two_menus)) == 2) ++ ++ def testRegressionScriptWithTranslateable(self): ++ tool = rc2grd.Rc2Grd() ++ ++ # test rig ++ class DummyNode(base.Node): ++ def AddChild(self, item): ++ self.node = item ++ verbose = False ++ extra_verbose = False ++ tool.not_localizable_re = re.compile('') ++ tool.o = DummyNode() ++ ++ rc_text = '''STRINGTABLE\nBEGIN\nID_BINGO "<SPAN id=hp style='BEHAVIOR: url(#default#homepage)'></SPAN><script>if (!hp.isHomePage('[$~HOMEPAGE~$]')) {document.write(""<a href=\\""[$~SETHOMEPAGEURL~$]\\"" >Set As Homepage</a> - "");}</script>"\nEND\n''' ++ tool.AddMessages(rc_text, tool.o) ++ self.failUnless(tool.o.node.GetCdata().find('Set As Homepage') != -1) ++ ++ # TODO(joi) Improve the HTML parser to support translateables inside ++ # <script> blocks? ++ self.failUnless(tool.o.node.attrs['translateable'] == 'false') ++ ++ def testRoleModel(self): ++ rc_text = ('STRINGTABLE\n' ++ 'BEGIN\n' ++ ' // This should not show up\n' ++ ' IDS_BINGO "Hello %s, how are you?"\n' ++ ' // The first description\n' ++ ' IDS_BONGO "Hello %s, my name is %s, and yours?"\n' ++ ' IDS_PROGRAMS_SHUTDOWN_TEXT "Google Desktop Search needs to close the following programs:\\n\\n$1\\nThe installation will not proceed if you choose to cancel."\n' ++ 'END\n') ++ tool = rc2grd.Rc2Grd() ++ tool.role_model = grd_reader.Parse(StringIO( ++ '''<?xml version="1.0" encoding="UTF-8"?> ++ <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <release seq="3"> ++ <messages> ++ <message name="IDS_BINGO"> ++ Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you? ++ </message> ++ <message name="IDS_BONGO" desc="The other description"> ++ Hello <ph name="USERNAME">%s<ex>Jakob</ex></ph>, my name is <ph name="ADMINNAME">%s<ex>Joi</ex></ph>, and yours? ++ </message> ++ <message name="IDS_PROGRAMS_SHUTDOWN_TEXT" desc="LIST_OF_PROGRAMS is replaced by a bulleted list of program names."> ++ Google Desktop Search needs to close the following programs: ++ ++<ph name="LIST_OF_PROGRAMS">$1<ex>Program 1, Program 2</ex></ph> ++The installation will not proceed if you choose to cancel. ++ </message> ++ </messages> ++ </release> ++ </grit>'''), dir='.') ++ ++ # test rig ++ class DummyOpts(object): ++ verbose = False ++ extra_verbose = False ++ tool.o = DummyOpts() ++ result = tool.Process(rc_text, '.\resource.rc') ++ self.failUnless( ++ result.children[2].children[2].children[0].attrs['desc'] == '') ++ self.failUnless( ++ result.children[2].children[2].children[0].children[0].attrs['name'] == 'USERNAME') ++ self.failUnless( ++ result.children[2].children[2].children[1].attrs['desc'] == 'The other description') ++ self.failUnless( ++ result.children[2].children[2].children[1].attrs['meaning'] == '') ++ self.failUnless( ++ result.children[2].children[2].children[1].children[0].attrs['name'] == 'USERNAME') ++ self.failUnless( ++ result.children[2].children[2].children[1].children[1].attrs['name'] == 'ADMINNAME') ++ self.failUnless( ++ result.children[2].children[2].children[2].children[0].attrs['name'] == 'LIST_OF_PROGRAMS') ++ ++ def testRunOutput(self): ++ """Verify basic correct Run behavior.""" ++ tool = rc2grd.Rc2Grd() ++ class DummyOpts(object): ++ verbose = False ++ extra_verbose = False ++ with util.TempDir({}) as output_dir: ++ rcfile = os.path.join(output_dir.GetPath(), 'foo.rc') ++ open(rcfile, 'w').close() ++ self.assertIsNone(tool.Run(DummyOpts(), [rcfile])) ++ self.assertTrue(os.path.exists(os.path.join(output_dir.GetPath(), 'foo.grd'))) ++ ++ def testMissingOutput(self): ++ """Verify failure with no args.""" ++ tool = rc2grd.Rc2Grd() ++ class DummyOpts(object): ++ verbose = False ++ extra_verbose = False ++ ret = tool.Run(DummyOpts(), []) ++ self.assertIsNotNone(ret) ++ self.assertGreater(ret, 0) ++ ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/tool/resize.py b/tools/grit/grit/tool/resize.py +new file mode 100644 +index 0000000000..6a897c077e +--- /dev/null ++++ b/tools/grit/grit/tool/resize.py +@@ -0,0 +1,295 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''The 'grit resize' tool. ++''' ++ ++from __future__ import print_function ++ ++import getopt ++import os ++import sys ++ ++from grit import grd_reader ++from grit import pseudo ++from grit import util ++from grit.format import rc ++from grit.format import rc_header ++from grit.node import include ++from grit.tool import interface ++ ++ ++# Template for the .vcproj file, with a couple of [[REPLACEABLE]] parts. ++PROJECT_TEMPLATE = '''\ ++<?xml version="1.0" encoding="Windows-1252"?> ++<VisualStudioProject ++ ProjectType="Visual C++" ++ Version="7.10" ++ Name="[[DIALOG_NAME]]" ++ ProjectGUID="[[PROJECT_GUID]]" ++ Keyword="Win32Proj"> ++ <Platforms> ++ <Platform ++ Name="Win32"/> ++ </Platforms> ++ <Configurations> ++ <Configuration ++ Name="Debug|Win32" ++ OutputDirectory="Debug" ++ IntermediateDirectory="Debug" ++ ConfigurationType="1" ++ CharacterSet="2"> ++ </Configuration> ++ </Configurations> ++ <References> ++ </References> ++ <Files> ++ <Filter ++ Name="Resource Files" ++ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" ++ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"> ++ <File ++ RelativePath=".\\[[DIALOG_NAME]].rc"> ++ </File> ++ </Filter> ++ </Files> ++ <Globals> ++ </Globals> ++</VisualStudioProject>''' ++ ++ ++# Template for the .rc file with a couple of [[REPLACEABLE]] parts. ++# TODO(joi) Improve this (and the resource.h template) to allow saving and then ++# reopening of the RC file in Visual Studio. Currently you can only open it ++# once and change it, then after you close it you won't be able to reopen it. ++RC_TEMPLATE = '''\ ++// This file is automatically generated by GRIT and intended for editing ++// the layout of the dialogs contained in it. Do not edit anything but the ++// dialogs. Any changes made to translateable portions of the dialogs will ++// be ignored by GRIT. ++ ++#include "resource.h" ++#include <winresrc.h> ++#ifdef IDC_STATIC ++#undef IDC_STATIC ++#endif ++#define IDC_STATIC (-1) ++ ++LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL ++ ++#pragma code_page([[CODEPAGE_NUM]]) ++ ++[[INCLUDES]] ++ ++[[DIALOGS]] ++''' ++ ++ ++# Template for the resource.h file with a couple of [[REPLACEABLE]] parts. ++HEADER_TEMPLATE = '''\ ++// This file is automatically generated by GRIT. Do not edit. ++ ++#pragma once ++ ++// Edit commands ++#define ID_EDIT_CLEAR 0xE120 ++#define ID_EDIT_CLEAR_ALL 0xE121 ++#define ID_EDIT_COPY 0xE122 ++#define ID_EDIT_CUT 0xE123 ++#define ID_EDIT_FIND 0xE124 ++#define ID_EDIT_PASTE 0xE125 ++#define ID_EDIT_PASTE_LINK 0xE126 ++#define ID_EDIT_PASTE_SPECIAL 0xE127 ++#define ID_EDIT_REPEAT 0xE128 ++#define ID_EDIT_REPLACE 0xE129 ++#define ID_EDIT_SELECT_ALL 0xE12A ++#define ID_EDIT_UNDO 0xE12B ++#define ID_EDIT_REDO 0xE12C ++ ++ ++[[DEFINES]] ++''' ++ ++ ++class ResizeDialog(interface.Tool): ++ '''Generates an RC file, header and Visual Studio project that you can use ++with Visual Studio's GUI resource editor to modify the layout of dialogs for ++the language of your choice. You then use the RC file, after you resize the ++dialog, for the language or languages of your choice, using the <skeleton> child ++of the <structure> node for the dialog. The translateable bits of the dialog ++will be ignored when you use the <skeleton> node (GRIT will instead use the ++translateable bits from the original dialog) but the layout changes you make ++will be used. Note that your layout changes must preserve the order of the ++translateable elements in the RC file. ++ ++Usage: grit resize [-f BASEFOLDER] [-l LANG] [-e RCENCODING] DIALOGID* ++ ++Arguments: ++ DIALOGID The 'name' attribute of a dialog to output for resizing. Zero ++ or more of these parameters can be used. If none are ++ specified, all dialogs from the input .grd file are output. ++ ++Options: ++ ++ -f BASEFOLDER The project will be created in a subfolder of BASEFOLDER. ++ The name of the subfolder will be the first DIALOGID you ++ specify. Defaults to '.' ++ ++ -l LANG Specifies that the RC file should contain a dialog translated ++ into the language LANG. The default is a cp1252-representable ++ pseudotranslation, because Visual Studio's GUI RC editor only ++ supports single-byte encodings. ++ ++ -c CODEPAGE Code page number to indicate to the RC compiler the encoding ++ of the RC file, default is something reasonable for the ++ language you selected (but this does not work for every single ++ language). See details on codepages below. NOTE that you do ++ not need to specify the codepage unless the tool complains ++ that it's not sure which codepage to use. See the following ++ page for codepage numbers supported by Windows: ++ http://www.microsoft.com/globaldev/reference/wincp.mspx ++ ++ -D NAME[=VAL] Specify a C-preprocessor-like define NAME with optional ++ value VAL (defaults to 1) which will be used to control ++ conditional inclusion of resources. ++ ++ ++IMPORTANT NOTE: For now, the tool outputs a UTF-8 encoded file for any language ++that can not be represented in cp1252 (i.e. anything other than Western ++European languages). You will need to open this file in a text editor and ++save it using the codepage indicated in the #pragma code_page(XXXX) command ++near the top of the file, before you open it in Visual Studio. ++ ++''' ++ ++ # TODO(joi) It would be cool to have this tool note the Perforce revision ++ # of the original RC file somewhere, such that the <skeleton> node could warn ++ # if the original RC file gets updated without the skeleton file being updated. ++ ++ # TODO(joi) Would be cool to have option to add the files to Perforce ++ ++ def __init__(self): ++ self.lang = pseudo.PSEUDO_LANG ++ self.defines = {} ++ self.base_folder = '.' ++ self.codepage_number = 1252 ++ self.codepage_number_specified_explicitly = False ++ ++ def SetLanguage(self, lang): ++ '''Sets the language code to output things in. ++ ''' ++ self.lang = lang ++ if not self.codepage_number_specified_explicitly: ++ self.codepage_number = util.LanguageToCodepage(lang) ++ ++ def GetEncoding(self): ++ if self.codepage_number == 1200: ++ return 'utf_16' ++ if self.codepage_number == 65001: ++ return 'utf_8' ++ return 'cp%d' % self.codepage_number ++ ++ def ShortDescription(self): ++ return 'Generate a file where you can resize a given dialog.' ++ ++ def Run(self, opts, args): ++ self.SetOptions(opts) ++ ++ own_opts, args = getopt.getopt(args, 'l:f:c:D:', ('help',)) ++ for key, val in own_opts: ++ if key == '-l': ++ self.SetLanguage(val) ++ if key == '-f': ++ self.base_folder = val ++ if key == '-c': ++ self.codepage_number = int(val) ++ self.codepage_number_specified_explicitly = True ++ if key == '-D': ++ name, val = util.ParseDefine(val) ++ self.defines[name] = val ++ elif key == '--help': ++ self.ShowUsage() ++ sys.exit(0) ++ ++ res_tree = grd_reader.Parse(opts.input, debug=opts.extra_verbose) ++ res_tree.OnlyTheseTranslations([self.lang]) ++ res_tree.RunGatherers() ++ ++ # Dialog IDs are either explicitly listed, or we output all dialogs from the ++ # .grd file ++ dialog_ids = args ++ if not len(dialog_ids): ++ for node in res_tree: ++ if node.name == 'structure' and node.attrs['type'] == 'dialog': ++ dialog_ids.append(node.attrs['name']) ++ ++ self.Process(res_tree, dialog_ids) ++ ++ def Process(self, grd, dialog_ids): ++ '''Outputs an RC file and header file for the dialog 'dialog_id' stored in ++ resource tree 'grd', to self.base_folder, as discussed in this class's ++ documentation. ++ ++ Arguments: ++ grd: grd = grd_reader.Parse(...); grd.RunGatherers() ++ dialog_ids: ['IDD_MYDIALOG', 'IDD_OTHERDIALOG'] ++ ''' ++ grd.SetOutputLanguage(self.lang) ++ grd.SetDefines(self.defines) ++ ++ project_name = dialog_ids[0] ++ ++ dir_path = os.path.join(self.base_folder, project_name) ++ if not os.path.isdir(dir_path): ++ os.mkdir(dir_path) ++ ++ # If this fails then we're not on Windows (or you don't have the required ++ # win32all Python libraries installed), so what are you doing mucking ++ # about with RC files anyway? :) ++ # pylint: disable=import-error ++ import pythoncom ++ ++ # Create the .vcproj file ++ project_text = PROJECT_TEMPLATE.replace( ++ '[[PROJECT_GUID]]', str(pythoncom.CreateGuid()) ++ ).replace('[[DIALOG_NAME]]', project_name) ++ fname = os.path.join(dir_path, '%s.vcproj' % project_name) ++ self.WriteFile(fname, project_text) ++ print("Wrote %s" % fname) ++ ++ # Create the .rc file ++ # Output all <include> nodes since the dialogs might depend on them (e.g. ++ # for icons and bitmaps). ++ include_items = [] ++ for node in grd.ActiveDescendants(): ++ if isinstance(node, include.IncludeNode): ++ include_items.append(rc.FormatInclude(node, self.lang, '.')) ++ rc_text = RC_TEMPLATE.replace('[[CODEPAGE_NUM]]', ++ str(self.codepage_number)) ++ rc_text = rc_text.replace('[[INCLUDES]]', ''.join(include_items)) ++ ++ # Then output the dialogs we have been asked to output. ++ dialogs = [] ++ for dialog_id in dialog_ids: ++ node = grd.GetNodeById(dialog_id) ++ assert node.name == 'structure' and node.attrs['type'] == 'dialog' ++ # TODO(joi) Add exception handling for better error reporting ++ dialogs.append(rc.FormatStructure(node, self.lang, '.')) ++ rc_text = rc_text.replace('[[DIALOGS]]', ''.join(dialogs)) ++ ++ fname = os.path.join(dir_path, '%s.rc' % project_name) ++ self.WriteFile(fname, rc_text, self.GetEncoding()) ++ print("Wrote %s" % fname) ++ ++ # Create the resource.h file ++ header_defines = ''.join(rc_header.FormatDefines(grd)) ++ header_text = HEADER_TEMPLATE.replace('[[DEFINES]]', header_defines) ++ fname = os.path.join(dir_path, 'resource.h') ++ self.WriteFile(fname, header_text) ++ print("Wrote %s" % fname) ++ ++ def WriteFile(self, filename, contents, encoding='cp1252'): ++ with open(filename, 'wb') as f: ++ writer = util.WrapOutputStream(f, encoding) ++ writer.write(contents) +diff --git a/tools/grit/grit/tool/test.py b/tools/grit/grit/tool/test.py +new file mode 100644 +index 0000000000..241a976d74 +--- /dev/null ++++ b/tools/grit/grit/tool/test.py +@@ -0,0 +1,24 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++from __future__ import print_function ++ ++from grit.tool import interface ++ ++class TestTool(interface.Tool): ++ '''This tool does nothing except print out the global options and ++tool-specific arguments that it receives. It is intended only for testing, ++hence the name :) ++''' ++ ++ def ShortDescription(self): ++ return 'A do-nothing tool for testing command-line parsing.' ++ ++ def Run(self, global_options, my_arguments): ++ print('NOTE This tool is only for testing the parsing of global options and') ++ print('tool-specific arguments that it receives. You may have intended to') ++ print('run "grit unit" which is the unit-test suite for GRIT.') ++ print('Options: %s' % repr(global_options)) ++ print('Arguments: %s' % repr(my_arguments)) + return 0 +diff --git a/tools/grit/grit/tool/transl2tc.py b/tools/grit/grit/tool/transl2tc.py +new file mode 100644 +index 0000000000..45301bbf58 +--- /dev/null ++++ b/tools/grit/grit/tool/transl2tc.py +@@ -0,0 +1,251 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. + -+ # This script is called by gclient. gclient opens its hooks subprocesses with -+ # (stdout=subprocess.PIPE, stderr=subprocess.STDOUT) and then does custom -+ # output processing that breaks printing '\r' characters for single-line -+ # updating status messages as printed by curl and wget. -+ # Work around this by setting stderr of the update.sh process to stdin (!): -+ # gclient doesn't redirect stdin, and while stdin itself is read-only, a -+ # dup()ed sys.stdin is writable, try -+ # fd2 = os.dup(sys.stdin.fileno()); os.write(fd2, 'hi') -+ # TODO: Fix gclient instead, http://crbug.com/95350 -+ return subprocess.call( -+ [os.path.join(os.path.dirname(__file__), 'update.sh')] + sys.argv[1:], -+ stderr=os.fdopen(os.dup(sys.stdin.fileno()))) ++'''The 'grit transl2tc' tool. ++''' ++ ++from __future__ import print_function ++ ++from grit import grd_reader ++from grit import util ++from grit.tool import interface ++from grit.tool import rc2grd ++ ++from grit.extern import tclib ++ ++ ++class TranslationToTc(interface.Tool): ++ '''A tool for importing existing translations in RC format into the ++Translation Console. ++ ++Usage: ++ ++grit -i GRD transl2tc [-l LIMITS] [RCOPTS] SOURCE_RC TRANSLATED_RC OUT_FILE ++ ++The tool needs a "source" RC file, i.e. in English, and an RC file that is a ++translation of precisely the source RC file (not of an older or newer version). ++ ++The tool also requires you to provide a .grd file (input file) e.g. using the ++-i global option or the GRIT_INPUT environment variable. The tool uses ++information from your .grd file to correct placeholder names in the ++translations and ensure that only translatable items and translations still ++being used are output. ++ ++This tool will accept all the same RCOPTS as the 'grit rc2grd' tool. To get ++a list of these options, run 'grit help rc2grd'. ++ ++Additionally, you can use the -l option (which must be the first option to the ++tool) to specify a file containing a list of message IDs to which output should ++be limited. This is only useful if you are limiting the output to your XMB ++files using the 'grit xmb' tool's -l option. See 'grit help xmb' for how to ++generate a file containing a list of the message IDs in an XMB file. ++ ++The tool will scan through both of the RC files as well as any HTML files they ++refer to, and match together the source messages and translated messages. It ++will output a file (OUTPUT_FILE) you can import directly into the TC using the ++Bulk Translation Upload tool. ++''' ++ ++ def ShortDescription(self): ++ return 'Import existing translations in RC format into the TC' ++ ++ def Setup(self, globopt, args): ++ '''Sets the instance up for use. ++ ''' ++ self.SetOptions(globopt) ++ self.rc2grd = rc2grd.Rc2Grd() ++ self.rc2grd.SetOptions(globopt) ++ self.limits = None ++ if len(args) and args[0] == '-l': ++ self.limits = util.ReadFile(args[1], 'utf-8').splitlines() ++ args = args[2:] ++ return self.rc2grd.ParseOptions(args, help_func=self.ShowUsage) ++ ++ def Run(self, globopt, args): ++ args = self.Setup(globopt, args) ++ ++ if len(args) != 3: ++ self.Out('This tool takes exactly three arguments:\n' ++ ' 1. The path to the original RC file\n' ++ ' 2. The path to the translated RC file\n' ++ ' 3. The output file path.\n') ++ return 2 ++ ++ grd = grd_reader.Parse(self.o.input, debug=self.o.extra_verbose) ++ grd.RunGatherers() ++ ++ source_rc = util.ReadFile(args[0], self.rc2grd.input_encoding) ++ transl_rc = util.ReadFile(args[1], self.rc2grd.input_encoding) ++ translations = self.ExtractTranslations(grd, ++ source_rc, args[0], ++ transl_rc, args[1]) ++ ++ with util.WrapOutputStream(open(args[2], 'wb')) as output_file: ++ self.WriteTranslations(output_file, translations.items()) ++ ++ self.Out('Wrote output file %s' % args[2]) ++ ++ def ExtractTranslations(self, current_grd, source_rc, source_path, ++ transl_rc, transl_path): ++ '''Extracts translations from the translated RC file, matching them with ++ translations in the source RC file to calculate their ID, and correcting ++ placeholders, limiting output to translateables, etc. using the supplied ++ .grd file which is the current .grd file for your project. ++ ++ If this object's 'limits' attribute is not None but a list, the output of ++ this function will be further limited to include only messages that have ++ message IDs in the 'limits' list. ++ ++ Args: ++ current_grd: grit.node.base.Node child, that has had RunGatherers() run ++ on it ++ source_rc: Complete text of source RC file ++ source_path: Path to the source RC file ++ transl_rc: Complete text of translated RC file ++ transl_path: Path to the translated RC file ++ ++ Return: ++ { id1 : text1, '12345678' : 'Hello USERNAME, howzit?' } ++ ''' ++ source_grd = self.rc2grd.Process(source_rc, source_path) ++ self.VerboseOut('Read %s into GRIT format, running gatherers.\n' % source_path) ++ source_grd.SetOutputLanguage(current_grd.output_language) ++ source_grd.SetDefines(current_grd.defines) ++ source_grd.RunGatherers(debug=self.o.extra_verbose) ++ transl_grd = self.rc2grd.Process(transl_rc, transl_path) ++ transl_grd.SetOutputLanguage(current_grd.output_language) ++ transl_grd.SetDefines(current_grd.defines) ++ self.VerboseOut('Read %s into GRIT format, running gatherers.\n' % transl_path) ++ transl_grd.RunGatherers(debug=self.o.extra_verbose) ++ self.VerboseOut('Done running gatherers for %s.\n' % transl_path) ++ ++ # Proceed to create a map from ID to translation, getting the ID from the ++ # source GRD and the translation from the translated GRD. ++ id2transl = {} ++ for source_node in source_grd: ++ source_cliques = source_node.GetCliques() ++ if not len(source_cliques): ++ continue ++ ++ assert 'name' in source_node.attrs, 'All nodes with cliques should have an ID' ++ node_id = source_node.attrs['name'] ++ self.ExtraVerboseOut('Processing node %s\n' % node_id) ++ transl_node = transl_grd.GetNodeById(node_id) ++ ++ if transl_node: ++ transl_cliques = transl_node.GetCliques() ++ if not len(transl_cliques) == len(source_cliques): ++ self.Out( ++ 'Warning: Translation for %s has wrong # of cliques, skipping.\n' % ++ node_id) ++ continue ++ else: ++ self.Out('Warning: No translation for %s, skipping.\n' % node_id) ++ continue ++ ++ if source_node.name == 'message': ++ # Fixup placeholders as well as possible based on information from ++ # the current .grd file if they are 'TODO_XXXX' placeholders. We need ++ # to fixup placeholders in the translated message so that it looks right ++ # and we also need to fixup placeholders in the source message so that ++ # its calculated ID will match the current message. ++ current_node = current_grd.GetNodeById(node_id) ++ if current_node: ++ assert len(source_cliques) == len(current_node.GetCliques()) == 1 ++ ++ source_msg = source_cliques[0].GetMessage() ++ current_msg = current_node.GetCliques()[0].GetMessage() ++ ++ # Only do this for messages whose source version has not changed. ++ if (source_msg.GetRealContent() != current_msg.GetRealContent()): ++ self.VerboseOut('Info: Message %s has changed; skipping\n' % node_id) ++ else: ++ transl_msg = transl_cliques[0].GetMessage() ++ transl_content = transl_msg.GetContent() ++ current_content = current_msg.GetContent() ++ source_content = source_msg.GetContent() ++ ++ ok_to_fixup = True ++ if (len(transl_content) != len(current_content)): ++ # message structure of translation is different, don't try fixup ++ ok_to_fixup = False ++ if ok_to_fixup: ++ for ix in range(len(transl_content)): ++ if isinstance(transl_content[ix], tclib.Placeholder): ++ if not isinstance(current_content[ix], tclib.Placeholder): ++ ok_to_fixup = False # structure has changed ++ break ++ if (transl_content[ix].GetOriginal() != ++ current_content[ix].GetOriginal()): ++ ok_to_fixup = False # placeholders have likely been reordered ++ break ++ else: # translated part is not a placeholder but a string ++ if isinstance(current_content[ix], tclib.Placeholder): ++ ok_to_fixup = False # placeholders have likely been reordered ++ break ++ ++ if not ok_to_fixup: ++ self.VerboseOut( ++ 'Info: Structure of message %s has changed; skipping.\n' % node_id) ++ else: ++ def Fixup(content, ix): ++ if (isinstance(content[ix], tclib.Placeholder) and ++ content[ix].GetPresentation().startswith('TODO_')): ++ assert isinstance(current_content[ix], tclib.Placeholder) ++ # Get the placeholder ID and example from the current message ++ content[ix] = current_content[ix] ++ for ix in range(len(transl_content)): ++ Fixup(transl_content, ix) ++ Fixup(source_content, ix) ++ ++ # Only put each translation once into the map. Warn if translations ++ # for the same message are different. ++ for ix in range(len(transl_cliques)): ++ source_msg = source_cliques[ix].GetMessage() ++ source_msg.GenerateId() # needed to refresh ID based on new placeholders ++ message_id = source_msg.GetId() ++ translated_content = transl_cliques[ix].GetMessage().GetPresentableContent() ++ ++ if message_id in id2transl: ++ existing_translation = id2transl[message_id] ++ if existing_translation != translated_content: ++ original_text = source_cliques[ix].GetMessage().GetPresentableContent() ++ self.Out('Warning: Two different translations for "%s":\n' ++ ' Translation 1: "%s"\n' ++ ' Translation 2: "%s"\n' % ++ (original_text, existing_translation, translated_content)) ++ else: ++ id2transl[message_id] = translated_content ++ ++ # Remove translations for messages that do not occur in the current .grd ++ # or have been marked as not translateable, or do not occur in the 'limits' ++ # list (if it has been set). ++ current_message_ids = current_grd.UberClique().AllMessageIds() ++ for message_id in list(id2transl.keys()): ++ if (message_id not in current_message_ids or ++ not current_grd.UberClique().BestClique(message_id).IsTranslateable() or ++ (self.limits and message_id not in self.limits)): ++ del id2transl[message_id] ++ ++ return id2transl ++ ++ @staticmethod ++ def WriteTranslations(output_file, translations): ++ '''Writes the provided list of translations to the provided output file ++ in the format used by the TC's Bulk Translation Upload tool. The file ++ must be UTF-8 encoded. ++ ++ Args: ++ output_file: util.WrapOutputStream(open('bingo.out', 'wb')) ++ translations: [ [id1, text1], ['12345678', 'Hello USERNAME, howzit?'] ] ++ ++ Return: ++ None ++ ''' ++ for id, text in translations: ++ text = text.replace('<', '<').replace('>', '>') ++ output_file.write(id) ++ output_file.write(' ') ++ output_file.write(text) ++ output_file.write('\n') +diff --git a/tools/grit/grit/tool/transl2tc_unittest.py b/tools/grit/grit/tool/transl2tc_unittest.py +new file mode 100644 +index 0000000000..22e937f9f2 +--- /dev/null ++++ b/tools/grit/grit/tool/transl2tc_unittest.py +@@ -0,0 +1,133 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for the 'grit transl2tc' tool.''' ++ ++from __future__ import print_function ++ ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++import unittest ++ ++from six import StringIO ++ ++from grit.tool import transl2tc ++from grit import grd_reader ++from grit import util ++ ++ ++def MakeOptions(): ++ from grit import grit_runner ++ return grit_runner.Options() ++ ++ ++class TranslationToTcUnittest(unittest.TestCase): ++ ++ def testOutput(self): ++ buf = StringIO() ++ tool = transl2tc.TranslationToTc() ++ translations = [ ++ ['1', 'Hello USERNAME, how are you?'], ++ ['12', 'Howdie doodie!'], ++ ['123', 'Hello\n\nthere\n\nhow are you?'], ++ ['1234', 'Hello is > goodbye but < howdie pardner'], ++ ] ++ tool.WriteTranslations(buf, translations) ++ output = buf.getvalue() ++ self.failUnless(output.strip() == ''' ++1 Hello USERNAME, how are you? ++12 Howdie doodie! ++123 Hello ++ ++there ++ ++how are you? ++1234 Hello is > goodbye but < howdie pardner ++'''.strip()) ++ ++ def testExtractTranslations(self): ++ path = util.PathFromRoot('grit/testdata') ++ current_grd = grd_reader.Parse(StringIO('''<?xml version="1.0" encoding="UTF-8"?> ++ <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <release seq="3"> ++ <messages> ++ <message name="IDS_SIMPLE"> ++ One ++ </message> ++ <message name="IDS_PLACEHOLDER"> ++ <ph name="NUMBIRDS">%s<ex>3</ex></ph> birds ++ </message> ++ <message name="IDS_PLACEHOLDERS"> ++ <ph name="ITEM">%d<ex>1</ex></ph> of <ph name="COUNT">%d<ex>3</ex></ph> ++ </message> ++ <message name="IDS_REORDERED_PLACEHOLDERS"> ++ <ph name="ITEM">$1<ex>1</ex></ph> of <ph name="COUNT">$2<ex>3</ex></ph> ++ </message> ++ <message name="IDS_CHANGED"> ++ This is the new version ++ </message> ++ <message name="IDS_TWIN_1">Hello</message> ++ <message name="IDS_TWIN_2">Hello</message> ++ <message name="IDS_NOT_TRANSLATEABLE" translateable="false">:</message> ++ <message name="IDS_LONGER_TRANSLATED"> ++ Removed document <ph name="FILENAME">$1<ex>c:\temp</ex></ph> ++ </message> ++ <message name="IDS_DIFFERENT_TWIN_1">Howdie</message> ++ <message name="IDS_DIFFERENT_TWIN_2">Howdie</message> ++ </messages> ++ <structures> ++ <structure type="dialog" name="IDD_ABOUTBOX" encoding="utf-16" file="klonk.rc" /> ++ <structure type="menu" name="IDC_KLONKMENU" encoding="utf-16" file="klonk.rc" /> ++ </structures> ++ </release> ++ </grit>'''), path) ++ current_grd.SetOutputLanguage('en') ++ current_grd.RunGatherers() ++ ++ source_rc_path = util.PathFromRoot('grit/testdata/source.rc') ++ source_rc = util.ReadFile(source_rc_path, 'utf-8') ++ transl_rc_path = util.PathFromRoot('grit/testdata/transl.rc') ++ transl_rc = util.ReadFile(transl_rc_path, 'utf-8') ++ ++ tool = transl2tc.TranslationToTc() ++ output_buf = StringIO() ++ globopts = MakeOptions() ++ globopts.verbose = True ++ globopts.output_stream = output_buf ++ tool.Setup(globopts, []) ++ translations = tool.ExtractTranslations(current_grd, ++ source_rc, source_rc_path, ++ transl_rc, transl_rc_path) ++ ++ values = list(translations.values()) ++ output = output_buf.getvalue() ++ ++ self.failUnless('Ein' in values) ++ self.failUnless('NUMBIRDS Vogeln' in values) ++ self.failUnless('ITEM von COUNT' in values) ++ self.failUnless(values.count('Hallo') == 1) ++ self.failIf('Dass war die alte Version' in values) ++ self.failIf(':' in values) ++ self.failIf('Dokument FILENAME ist entfernt worden' in values) ++ self.failIf('Nicht verwendet' in values) ++ self.failUnless(('Howdie' in values or 'Hallo sagt man' in values) and not ++ ('Howdie' in values and 'Hallo sagt man' in values)) ++ ++ self.failUnless('XX01XX&SkraXX02XX&HaettaXX03XXThetta er "Klonk" sem eg fylaXX04XXgonkurinnXX05XXKlonk && er [good]XX06XX&HjalpXX07XX&Um...XX08XX' in values) ++ ++ self.failUnless('I lagi' in values) ++ ++ self.failUnless(output.count('Structure of message IDS_REORDERED_PLACEHOLDERS has changed')) ++ self.failUnless(output.count('Message IDS_CHANGED has changed')) ++ self.failUnless(output.count('Structure of message IDS_LONGER_TRANSLATED has changed')) ++ self.failUnless(output.count('Two different translations for "Howdie"')) ++ self.failUnless(output.count('IDD_DIFFERENT_LENGTH_IN_TRANSL has wrong # of cliques')) + + +if __name__ == '__main__': -+ sys.exit(main()) -diff --git a/tools/clang/scripts/update.sh b/tools/clang/scripts/update.sh -new file mode 100755 -index 0000000000..e9448236c8 ++ unittest.main() +diff --git a/tools/grit/grit/tool/unit.py b/tools/grit/grit/tool/unit.py +new file mode 100644 +index 0000000000..7e96b699c3 +--- /dev/null ++++ b/tools/grit/grit/tool/unit.py +@@ -0,0 +1,43 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''GRIT tool that runs the unit test suite for GRIT.''' ++ ++from __future__ import print_function ++ ++import getopt ++import sys ++import unittest ++ ++try: ++ import grit.test_suite_all ++except ImportError: ++ pass ++from grit.tool import interface ++ ++ ++class UnitTestTool(interface.Tool): ++ '''By using this tool (e.g. 'grit unit') you run all the unit tests for GRIT. ++This happens in the environment that is set up by the basic GRIT runner.''' ++ ++ def ShortDescription(self): ++ return 'Use this tool to run all the unit tests for GRIT.' ++ ++ def ParseOptions(self, args): ++ """Set this objects and return all non-option arguments.""" ++ own_opts, args = getopt.getopt(args, '', ('help',)) ++ for key, val in own_opts: ++ if key == '--help': ++ self.ShowUsage() ++ sys.exit(0) ++ return args ++ ++ def Run(self, opts, args): ++ args = self.ParseOptions(args) ++ if args: ++ print('This tool takes no arguments.') ++ return 2 ++ ++ return unittest.TextTestRunner(verbosity=2).run( ++ grit.test_suite_all.TestSuiteAll()) +diff --git a/tools/grit/grit/tool/update_resource_ids/__init__.py b/tools/grit/grit/tool/update_resource_ids/__init__.py +new file mode 100644 +index 0000000000..3006fbffab +--- /dev/null ++++ b/tools/grit/grit/tool/update_resource_ids/__init__.py +@@ -0,0 +1,305 @@ ++# Copyright 2019 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++"""Package grit.tool.update_resource_ids ++ ++Updates GRID resource_ids from linked GRD files, while preserving structure. ++ ++A resource_ids file is a JSON dict (with Python comments) that maps GRD paths ++to *items*. Item order is ignored by GRIT, but is important since it establishes ++a narrative of item dependency (needs non-overlapping IDs) and mutual exclusion ++(allows ID overlap). Example: ++ ++{ ++ # The first entry in the file, SRCDIR, is special: It is a relative path from ++ # this file to the base of your checkout. ++ "SRCDIR": "../..", ++ ++ # First GRD file. This entry is an "Item". ++ "1.grd": { ++ "messages": [400], # "Tag". ++ }, ++ # Depends on 1.grd, i.e., 500 >= 400 + (# of IDs used in 1.grd). ++ "2a.grd": { ++ "includes": [500], # "Tag". ++ "structures": [510], # "Tag" (etc.). ++ }, ++ # Depends on 2a.grd. ++ "3a.grd": { ++ "includes": [1000], ++ }, ++ # Depends on 2a.grd, but overlaps with 3b.grd due to mutually exclusivity. ++ "3b.grd": { ++ "includes": [1000], ++ }, ++ # Depends on {3a.grd, 3b.grd}. ++ "4.grd": { ++ "META": {"join": 2}, # Hint for update_resource_ids. ++ "structures": [1500], ++ }, ++ # Depends on 1.grd but overlaps with 2a.grd. ++ "2b.grd": { ++ "includes": [500], ++ "structures": [540], ++ }, ++ # Depends on {4.grd, 2b.grd}. ++ "5.grd": { ++ "META": {"join": 2}, # Hint for update_resource_ids. ++ "includes": [600], ++ }, ++ # Depends on 5.grd. File is generated, so hint is needed for sizes. ++ "<(SHARED_INTERMEDIATE_DIR)/6.grd": { ++ "META": {"sizes": {"includes": [10]}}, ++ "includes": [700], ++ }, ++} ++ ++The "structure" within a resouces_ids file are as follows: ++1. Comments and spacing. ++2. Item ordering, to establish dependency and grouping. ++3. Special provision to allow ID overlaps from mutual exclusion. ++ ++This module parses a resource_ids file, reads ID usages from GRD files it refers ++to, and generates an updated version of the resource_ids file while preserving ++structure elements 1-3 stated above. ++""" ++ ++from __future__ import print_function ++ ++import collections ++import getopt ++import os ++import shutil ++import sys ++import tempfile ++ ++from grit.tool import interface ++from grit.tool.update_resource_ids import assigner, common, parser, reader ++ ++ ++def _ReadData(input_file): ++ if input_file == '-': ++ data = sys.stdin.read() ++ file_dir = os.getcwd() ++ else: ++ with open(input_file, 'rt') as f: ++ data = f.read() ++ file_dir = os.path.dirname(input_file) ++ return data, file_dir ++ ++ ++def _MultiReplace(data, repl): ++ """Multi-replacement of text |data| by ranges and replacement text. ++ ++ Args: ++ data: Original text. ++ repl: List of (lo, hi, s) tuples, specifying that |data[lo:hi]| should be ++ replaced with |s|. The ranges must be inside |data|, and not overlap. ++ Returns: New text. ++ """ ++ res = [] ++ prev = 0 ++ for (lo, hi, s) in sorted(repl): ++ if prev < lo: ++ res.append(data[prev:lo]) ++ res.append(s) ++ prev = hi ++ res.append(data[prev:]) ++ return ''.join(res) ++ ++ ++def _WriteFileIfChanged(output, new_data): ++ if not output: ++ sys.stdout.write(new_data) ++ return ++ ++ # Avoid touching outputs if file contents has not changed so that ninja ++ # does not rebuild dependent when not necessary. ++ if os.path.exists(output) and _ReadData(output)[0] == new_data: ++ return ++ ++ # Write to a temporary file to ensure atomic changes. ++ with tempfile.NamedTemporaryFile('wt', delete=False) as f: ++ f.write(new_data) ++ shutil.move(f.name, output) ++ ++ ++class _Args: ++ """Encapsulated arguments for this module.""" ++ def __init__(self): ++ self.add_header = False ++ self.analyze_inputs = False ++ self.count = False ++ self.depfile = None ++ self.fake = False ++ self.input = None ++ self.naive = False ++ self.output = None ++ self.parse = False ++ self.tokenize = False ++ ++ @staticmethod ++ def Parse(raw_args): ++ own_opts, raw_args = getopt.getopt(raw_args, 'o:cpt', [ ++ 'add-header', ++ 'analyze-inputs', ++ 'count', ++ 'depfile=', ++ 'fake', ++ 'naive', ++ 'parse', ++ 'tokenize', ++ ]) ++ args = _Args(); ++ if not len(raw_args) == 1: ++ print('grit update_resource_ids takes exactly one argument, the path to ' ++ 'the resource ids file.') ++ return 2 ++ args.input = raw_args[0] ++ for (key, val) in own_opts: ++ if key == '-o': ++ args.output = val ++ elif key == '--add-header': ++ args.add_header = True ++ elif key == '--analyze-inputs': ++ args.analyze_inputs = True ++ elif key in ('--count', '-c'): ++ args.count = True ++ elif key == '--depfile': ++ args.depfile = val ++ elif key == '--fake': ++ args.fake = True ++ elif key == '--naive': ++ args.naive = True ++ elif key in ('--parse', '-p'): ++ args.parse = True ++ elif key in ('--tokenize', '-t'): ++ args.tokenize = True ++ return args ++ ++ ++class UpdateResourceIds(interface.Tool): ++ """Updates all start IDs in an resource_ids file by reading all GRD files it ++refers to, estimating the number of required IDs of each type, then rewrites ++start IDs while preserving structure. ++ ++Usage: grit update_resource_ids [--parse|-p] [--read-grd|-r] [--tokenize|-t] ++ [--naive] [--fake] [-o OUTPUT_FILE] ++ [--analyze-inputs] [--depfile DEPFILE] ++ [--add-header] RESOURCE_IDS_FILE ++ ++RESOURCE_IDS_FILE is the path of the input resource_ids file. ++ ++The -o option redirects output (default stdout) to OUPTUT_FILE, which can also ++be RESOURCE_IDS_FILE. ++ ++Other options: ++ ++ -E NAME=VALUE Sets environment variable NAME to VALUE (within grit). ++ ++ --count|-c Parses RESOURCE_IDS_FILE, reads the GRD files, and prints ++ required sizes. ++ ++ --fake For testing: Skips reading GRD files, and assigns 10 as the ++ usage of every tag. ++ ++ --naive Use naive coarse assigner. ++ ++ --parse|-p Parses RESOURCE_IDS_FILE and dumps its nodes to console. ++ ++ --tokenize|-t Tokenizes RESOURCE_IDS_FILE and reprints it as syntax- ++ highlighted output. ++ ++ --depfile=DEPFILE Write out a depfile for ninja to know about dependencies. ++ --analyze-inputs Writes dependencies to stdout. ++ --add-header Adds a "THIS FILE IS GENERATED" header to the output. ++""" ++ ++ def __init(self): ++ super(UpdateResourceIds, self).__init__() ++ ++ def ShortDescription(self): ++ return 'Updates a resource_ids file based on usage, preserving structure' ++ ++ def _DumpTokens(self, data, tok_gen): ++ # Reprint |data| with syntax highlight. ++ color_map = { ++ '#': common.Color.GRAY, ++ 'S': common.Color.CYAN, ++ '0': common.Color.RED, ++ '{': common.Color.YELLOW, ++ '}': common.Color.YELLOW, ++ '[': common.Color.GREEN, ++ ']': common.Color.GREEN, ++ ':': common.Color.MAGENTA, ++ ',': common.Color.MAGENTA, ++ } ++ for t, lo, hi in tok_gen: ++ c = color_map.get(t, common.Color.NONE) ++ sys.stdout.write(c(data[lo:hi])) ++ ++ def _DumpRootObj(self, root_obj): ++ print(root_obj) ++ ++ def _DumpResourceCounts(self, usage_gen): ++ tot = collections.Counter() ++ for item, tag_name_to_usage in usage_gen: ++ c = common.Color.YELLOW if item.grd.startswith('<') else common.Color.CYAN ++ print('%s: %r' % (c(item.grd), dict(tag_name_to_usage))) ++ tot += collections.Counter(tag_name_to_usage) ++ print(common.Color.GRAY('-' * 80)) ++ print('%s: %r' % (common.Color.GREEN('Total'), dict(tot))) ++ print('%s: %d' % (common.Color.GREEN('Grand Total'), sum(tot.values()))) ++ ++ def Run(self, opts, raw_args): ++ self.SetOptions(opts) ++ ++ args = _Args.Parse(raw_args) ++ data, file_dir = _ReadData(args.input) ++ ++ tok_gen = parser.Tokenize(data) ++ if args.tokenize: ++ return self._DumpTokens(data, tok_gen) ++ ++ root_obj = parser.ResourceIdParser(data, tok_gen).Parse() ++ if args.parse: ++ return self._DumpRootObj(root_obj) ++ item_list = common.BuildItemList(root_obj) ++ ++ src_dir = os.path.normpath(os.path.join(file_dir, root_obj['SRCDIR'].val)) ++ seen_files = set() ++ usage_gen = reader.GenerateResourceUsages(item_list, src_dir, args.fake, ++ seen_files) ++ if args.count: ++ return self._DumpResourceCounts(usage_gen) ++ for item, tag_name_to_usage in usage_gen: ++ item.SetUsages(tag_name_to_usage) ++ ++ if args.analyze_inputs: ++ print('\n'.join(sorted(seen_files))) ++ return 0 ++ ++ new_ids_gen = assigner.GenerateNewIds(item_list, args.naive) ++ # Create replacement specs usable by _MultiReplace(). ++ repl = [(tag.lo, tag.hi, str(new_id)) for tag, new_id in new_ids_gen] ++ rel_input_dir = args.input ++ # Update "SRCDIR" entry if output is specified. ++ if args.output: ++ new_srcdir = os.path.relpath(src_dir, os.path.dirname(args.output)) ++ repl.append((root_obj['SRCDIR'].lo, root_obj['SRCDIR'].hi, ++ repr(new_srcdir))) ++ rel_input_dir = os.path.join('$SRCDIR', ++ os.path.relpath(rel_input_dir, new_srcdir)) ++ ++ new_data = _MultiReplace(data, repl) ++ if args.add_header: ++ header = [] ++ header.append('# GENERATED FILE.') ++ header.append('# Edit %s instead.' % rel_input_dir) ++ header.append('#' * 80) ++ new_data = '\n'.join(header + ['']) + new_data ++ _WriteFileIfChanged(args.output, new_data) ++ ++ if args.depfile: ++ deps_data = '{}: {}'.format(args.output, ' '.join(sorted(seen_files))) ++ _WriteFileIfChanged(args.depfile, deps_data) +diff --git a/tools/grit/grit/tool/update_resource_ids/assigner.py b/tools/grit/grit/tool/update_resource_ids/assigner.py +new file mode 100644 +index 0000000000..6cd46031a6 --- /dev/null -+++ b/tools/clang/scripts/update.sh ++++ b/tools/grit/grit/tool/update_resource_ids/assigner.py @@ -0,0 +1,286 @@ -+#!/usr/bin/env bash -+# Copyright (c) 2012 The Chromium Authors. All rights reserved. -+# Use of this source code is governed by a BSD-style license that can be -+# found in the LICENSE file. -+ -+# This script will check out llvm and clang into third_party/llvm and build it. -+ -+# Do NOT CHANGE this if you don't know what you're doing -- see -+# https://code.google.com/p/chromium/wiki/UpdatingClang -+# Reverting problematic clang rolls is safe, though. -+CLANG_REVISION=163674 -+ -+THIS_DIR="$(dirname "${0}")" -+LLVM_DIR="${THIS_DIR}/../../../third_party/llvm" -+LLVM_BUILD_DIR="${LLVM_DIR}/../llvm-build" -+LLVM_BOOTSTRAP_DIR="${LLVM_DIR}/../llvm-bootstrap" -+CLANG_DIR="${LLVM_DIR}/tools/clang" -+COMPILER_RT_DIR="${LLVM_DIR}/projects/compiler-rt" -+STAMP_FILE="${LLVM_BUILD_DIR}/cr_build_revision" -+ -+# ${A:-a} returns $A if it's set, a else. -+LLVM_REPO_URL=${LLVM_URL:-https://llvm.org/svn/llvm-project} -+ -+# Die if any command dies. -+set -e -+ -+OS="$(uname -s)" -+ -+# Parse command line options. -+force_local_build= -+mac_only= -+run_tests= -+bootstrap= -+while [[ $# > 0 ]]; do -+ case $1 in -+ --bootstrap) -+ bootstrap=yes -+ ;; -+ --force-local-build) -+ force_local_build=yes -+ ;; -+ --mac-only) -+ mac_only=yes -+ ;; -+ --run-tests) -+ run_tests=yes -+ ;; -+ --help) -+ echo "usage: $0 [--force-local-build] [--mac-only] [--run-tests] " -+ echo "--bootstrap: First build clang with CC, then with itself." -+ echo "--force-local-build: Don't try to download prebuilt binaries." -+ echo "--mac-only: Do initial download only on Mac systems." -+ echo "--run-tests: Run tests after building. Only for local builds." -+ exit 1 -+ ;; -+ esac -+ shift -+done -+ -+# --mac-only prevents the initial download on non-mac systems, but if clang has -+# already been downloaded in the past, this script keeps it up to date even if -+# --mac-only is passed in and the system isn't a mac. People who don't like this -+# can just delete their third_party/llvm-build directory. -+if [[ -n "$mac_only" ]] && [[ "${OS}" != "Darwin" ]] && -+ [[ "$GYP_DEFINES" != *clang=1* ]] && ! [[ -d "${LLVM_BUILD_DIR}" ]]; then -+ exit 0 -+fi -+ -+# Xcode and clang don't get along when predictive compilation is enabled. -+# http://crbug.com/96315 -+if [[ "${OS}" = "Darwin" ]] && xcodebuild -version | grep -q 'Xcode 3.2' ; then -+ XCONF=com.apple.Xcode -+ if [[ "${GYP_GENERATORS}" != "make" ]] && \ -+ [ "$(defaults read "${XCONF}" EnablePredictiveCompilation)" != "0" ]; then -+ echo -+ echo " HEARKEN!" -+ echo "You're using Xcode3 and you have 'Predictive Compilation' enabled." -+ echo "This does not work well with clang (http://crbug.com/96315)." -+ echo "Disable it in Preferences->Building (lower right), or run" -+ echo " defaults write ${XCONF} EnablePredictiveCompilation -boolean NO" -+ echo "while Xcode is not running." -+ echo -+ fi -+ -+ SUB_VERSION=$(xcodebuild -version | sed -Ene 's/Xcode 3\.2\.([0-9]+)/\1/p') -+ if [[ "${SUB_VERSION}" < 6 ]]; then -+ echo -+ echo " YOUR LD IS BUGGY!" -+ echo "Please upgrade Xcode to at least 3.2.6." -+ echo -+ fi -+fi -+ -+ -+# Check if there's anything to be done, exit early if not. -+if [[ -f "${STAMP_FILE}" ]]; then -+ PREVIOUSLY_BUILT_REVISON=$(cat "${STAMP_FILE}") -+ if [[ -z "$force_local_build" ]] && \ -+ [[ "${PREVIOUSLY_BUILT_REVISON}" = "${CLANG_REVISION}" ]]; then -+ echo "Clang already at ${CLANG_REVISION}" -+ exit 0 -+ fi -+fi -+# To always force a new build if someone interrupts their build half way. -+rm -f "${STAMP_FILE}" -+ -+# Clobber pch files, since they only work with the compiler version that -+# created them. Also clobber .o files, to make sure everything will be built -+# with the new compiler. -+if [[ "${OS}" = "Darwin" ]]; then -+ XCODEBUILD_DIR="${THIS_DIR}/../../../xcodebuild" -+ -+ # Xcode groups .o files by project first, configuration second. -+ if [[ -d "${XCODEBUILD_DIR}" ]]; then -+ echo "Clobbering .o files for Xcode build" -+ find "${XCODEBUILD_DIR}" -name '*.o' -exec rm {} + -+ fi -+fi -+ -+if [ -f "${THIS_DIR}/../../../WebKit.gyp" ]; then -+ # We're inside a WebKit checkout. -+ # TODO(thakis): try to unify the directory layout of the xcode- and -+ # make-based builds. http://crbug.com/110455 -+ MAKE_DIR="${THIS_DIR}/../../../../../../out" -+else -+ # We're inside a Chromium checkout. -+ MAKE_DIR="${THIS_DIR}/../../../out" -+fi -+ -+for CONFIG in Debug Release; do -+ if [[ -d "${MAKE_DIR}/${CONFIG}/obj.target" || -+ -d "${MAKE_DIR}/${CONFIG}/obj.host" ]]; then -+ echo "Clobbering ${CONFIG} PCH and .o files for make build" -+ if [[ -d "${MAKE_DIR}/${CONFIG}/obj.target" ]]; then -+ find "${MAKE_DIR}/${CONFIG}/obj.target" -name '*.gch' -exec rm {} + -+ find "${MAKE_DIR}/${CONFIG}/obj.target" -name '*.o' -exec rm {} + -+ fi -+ if [[ -d "${MAKE_DIR}/${CONFIG}/obj.host" ]]; then -+ find "${MAKE_DIR}/${CONFIG}/obj.host" -name '*.o' -exec rm {} + -+ fi -+ fi -+ -+ # ninja puts its output below ${MAKE_DIR} as well. -+ if [[ -d "${MAKE_DIR}/${CONFIG}/obj" ]]; then -+ echo "Clobbering ${CONFIG} PCH and .o files for ninja build" -+ find "${MAKE_DIR}/${CONFIG}/obj" -name '*.gch' -exec rm {} + -+ find "${MAKE_DIR}/${CONFIG}/obj" -name '*.o' -exec rm {} + -+ find "${MAKE_DIR}/${CONFIG}/obj" -name '*.o.d' -exec rm {} + -+ fi -+ -+ if [[ "${OS}" = "Darwin" ]]; then -+ if [[ -d "${XCODEBUILD_DIR}/${CONFIG}/SharedPrecompiledHeaders" ]]; then -+ echo "Clobbering ${CONFIG} PCH files for Xcode build" -+ rm -rf "${XCODEBUILD_DIR}/${CONFIG}/SharedPrecompiledHeaders" -+ fi -+ fi -+done -+ -+if [[ -z "$force_local_build" ]]; then -+ # Check if there's a prebuilt binary and if so just fetch that. That's faster, -+ # and goma relies on having matching binary hashes on client and server too. -+ CDS_URL=https://commondatastorage.googleapis.com/chromium-browser-clang -+ CDS_FILE="clang-${CLANG_REVISION}.tgz" -+ CDS_OUT_DIR=$(mktemp -d -t clang_download.XXXXXX) -+ CDS_OUTPUT="${CDS_OUT_DIR}/${CDS_FILE}" -+ if [ "${OS}" = "Linux" ]; then -+ CDS_FULL_URL="${CDS_URL}/Linux_x64/${CDS_FILE}" -+ elif [ "${OS}" = "Darwin" ]; then -+ CDS_FULL_URL="${CDS_URL}/Mac/${CDS_FILE}" -+ fi -+ echo Trying to download prebuilt clang -+ if which curl > /dev/null; then -+ curl -L --fail "${CDS_FULL_URL}" -o "${CDS_OUTPUT}" || \ -+ rm -rf "${CDS_OUT_DIR}" -+ elif which wget > /dev/null; then -+ wget "${CDS_FULL_URL}" -O "${CDS_OUTPUT}" || rm -rf "${CDS_OUT_DIR}" -+ else -+ echo "Neither curl nor wget found. Please install one of these." -+ exit 1 -+ fi -+ if [ -f "${CDS_OUTPUT}" ]; then -+ rm -rf "${LLVM_BUILD_DIR}/Release+Asserts" -+ mkdir -p "${LLVM_BUILD_DIR}/Release+Asserts" -+ tar -xzf "${CDS_OUTPUT}" -C "${LLVM_BUILD_DIR}/Release+Asserts" -+ echo clang "${CLANG_REVISION}" unpacked -+ echo "${CLANG_REVISION}" > "${STAMP_FILE}" -+ rm -rf "${CDS_OUT_DIR}" -+ exit 0 -+ else -+ echo Did not find prebuilt clang at r"${CLANG_REVISION}", building -+ fi -+fi -+ -+echo Getting LLVM r"${CLANG_REVISION}" in "${LLVM_DIR}" -+if ! svn co --force "${LLVM_REPO_URL}/llvm/trunk@${CLANG_REVISION}" \ -+ "${LLVM_DIR}"; then -+ echo Checkout failed, retrying -+ rm -rf "${LLVM_DIR}" -+ svn co --force "${LLVM_REPO_URL}/llvm/trunk@${CLANG_REVISION}" "${LLVM_DIR}" -+fi -+ -+echo Getting clang r"${CLANG_REVISION}" in "${CLANG_DIR}" -+svn co --force "${LLVM_REPO_URL}/cfe/trunk@${CLANG_REVISION}" "${CLANG_DIR}" -+ -+echo Getting compiler-rt r"${CLANG_REVISION}" in "${COMPILER_RT_DIR}" -+svn co --force "${LLVM_REPO_URL}/compiler-rt/trunk@${CLANG_REVISION}" \ -+ "${COMPILER_RT_DIR}" -+ -+# Echo all commands. -+set -x -+ -+NUM_JOBS=3 -+if [[ "${OS}" = "Linux" ]]; then -+ NUM_JOBS="$(grep -c "^processor" /proc/cpuinfo)" -+elif [ "${OS}" = "Darwin" ]; then -+ NUM_JOBS="$(sysctl -n hw.ncpu)" -+fi -+ -+# Build bootstrap clang if requested. -+if [[ -n "${bootstrap}" ]]; then -+ echo "Building bootstrap compiler" -+ mkdir -p "${LLVM_BOOTSTRAP_DIR}" -+ cd "${LLVM_BOOTSTRAP_DIR}" -+ if [[ ! -f ./config.status ]]; then -+ # The bootstrap compiler only needs to be able to build the real compiler, -+ # so it needs no cross-compiler output support. In general, the host -+ # compiler should be as similar to the final compiler as possible, so do -+ # keep --disable-threads & co. -+ ../llvm/configure \ -+ --enable-optimized \ -+ --enable-targets=host-only \ -+ --disable-threads \ -+ --disable-pthreads \ -+ --without-llvmgcc \ -+ --without-llvmgxx -+ MACOSX_DEPLOYMENT_TARGET=10.5 make -j"${NUM_JOBS}" -+ fi -+ if [[ -n "${run_tests}" ]]; then -+ make check-all -+ fi -+ cd - -+ export CC="${PWD}/${LLVM_BOOTSTRAP_DIR}/Release+Asserts/bin/clang" -+ export CXX="${PWD}/${LLVM_BOOTSTRAP_DIR}/Release+Asserts/bin/clang++" -+ echo "Building final compiler" -+fi -+ -+# Build clang (in a separate directory). -+# The clang bots have this path hardcoded in built/scripts/slave/compile.py, -+# so if you change it you also need to change these links. -+mkdir -p "${LLVM_BUILD_DIR}" -+cd "${LLVM_BUILD_DIR}" -+if [[ ! -f ./config.status ]]; then -+ ../llvm/configure \ -+ --enable-optimized \ -+ --disable-threads \ -+ --disable-pthreads \ -+ --without-llvmgcc \ -+ --without-llvmgxx -+fi -+ -+MACOSX_DEPLOYMENT_TARGET=10.5 make -j"${NUM_JOBS}" -+cd - -+ -+# Build plugin. -+# Copy it into the clang tree and use clang's build system to compile the -+# plugin. -+PLUGIN_SRC_DIR="${THIS_DIR}/../plugins" -+PLUGIN_DST_DIR="${LLVM_DIR}/tools/clang/tools/chrome-plugin" -+PLUGIN_BUILD_DIR="${LLVM_BUILD_DIR}/tools/clang/tools/chrome-plugin" -+rm -rf "${PLUGIN_DST_DIR}" -+cp -R "${PLUGIN_SRC_DIR}" "${PLUGIN_DST_DIR}" -+rm -rf "${PLUGIN_BUILD_DIR}" -+mkdir -p "${PLUGIN_BUILD_DIR}" -+cp "${PLUGIN_SRC_DIR}/Makefile" "${PLUGIN_BUILD_DIR}" -+MACOSX_DEPLOYMENT_TARGET=10.5 make -j"${NUM_JOBS}" -C "${PLUGIN_BUILD_DIR}" -+ -+if [[ -n "$run_tests" ]]; then -+ # Run a few tests. -+ "${PLUGIN_SRC_DIR}/tests/test.sh" "${LLVM_BUILD_DIR}/Release+Asserts" -+ cd "${LLVM_BUILD_DIR}" -+ make check-all -+ cd - -+fi -+ -+# After everything is done, log success for this revision. -+echo "${CLANG_REVISION}" > "${STAMP_FILE}" ++# Copyright 2019 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++"""Assign IDs to resource_ids file based on usage, while preserving structure. ++ ++resource_ids assignment is divided into two parts: ++(A) Coarse assignment: Assigns start IDs of items. ++(B) Quota assignment: Assigns per-tag ID allotments for a given item, allowing ++ padding for IDs. ++ ++These parts are interdependent: Start IDs (A) of an item depends on ID ++allotments (B) of *other* items; and ID allotment (B) of an item depends on its ++start IDs (A) to compute alignment. ++ ++(B) hides padding and alignment details of tags so that (A) can be abstracted ++into the graph construction and traversal problem in DagCoarseIdAssigner. ++""" ++ ++import math ++ ++from grit.tool.update_resource_ids import common ++ ++ ++class Aligner: ++ """Helper to allot IDs, given start ID and ID usage. ++ ++ Args: ++ expand: Scale factor relative to ID usage. Must be >= 1.0. ++ slack: Minimum number of reserved ID at end. Must be >= 0. ++ align: ID alignment of results. Must be >= 1. ++ """ ++ ++ def __init__(self, expand=1.0, slack=0, align=1): ++ assert expand >= 1.0 and slack >= 0 and align >= 1 ++ self._expand = expand ++ self._slack = slack ++ self._align = align ++ ++ def Calc(self, cur_id, usage): ++ quota = max(int(math.ceil(usage * self._expand)), usage + self._slack) ++ return common.AlignUp(cur_id + quota, self._align) ++ ++ ++class QuotaAssigner: ++ """Main class for (B), for ID allotment of tags for an item.""" ++ ++ def __init__(self, aligner): ++ self._aligner = aligner ++ ++ def Gen(self, item, start_id): ++ """Generates per-tag *end* ID in |item|, succeeding |start_id|.""" ++ cur_id = start_id ++ for tag in item.tags: # Sorted by |tag.lo|. ++ cur_id = self._aligner.Calc(cur_id, tag.usage) ++ yield tag, cur_id ++ ++ ++class BaseCoarseIdAssigner(object): ++ """Base class for coarse assignment.""" ++ ++ def __init__(self, item_list, align): ++ self._item_list = item_list ++ self._align = align ++ ++ def GenStartIds(self): ++ """Visits |_item_list| and yields (|item|, new |start_id|). ++ ++ Visit follows dependency order: If item B succeeds item A, then A is visited ++ before B. Caller must call FeedWeight() to assign ID allotment. ++ """ ++ raise NotImplementedError() ++ ++ def FeedWeight(self, item, weight): ++ """Callback to assign number of IDs allotted to |item|.""" ++ raise NotImplementedError() ++ ++ ++class NaiveCoarseIdAssigner(BaseCoarseIdAssigner): ++ """CoarseIdAssigner that assigns item with non-overlapping start IDs.""" ++ ++ def __init__(self, item_list, align): ++ super(NaiveCoarseIdAssigner, self).__init__(item_list, align) ++ first_id = self._item_list[0].tags[0].id ++ self._cur_id = common.AlignUp(first_id, self._align) ++ ++ def GenStartIds(self): ++ """Visits items in array order.""" ++ for item in self._item_list: ++ yield item, self._cur_id ++ ++ def FeedWeight(self, item, weight): ++ self._cur_id = common.AlignUp(self._cur_id + weight, self._align) ++ ++ ++class DagCoarseIdAssigner(BaseCoarseIdAssigner): ++ """CoarseIdAssigner that preserves existing structure. ++ ++Start ID assignment in resource_ids is structured a Series-Parallel Graph, which ++is a directed, acyclic multi-graph generated by the following: ++* Start: Single directed edge. S <-- T. ++* Operation 1: A <-- B becomes A <-- C <-- B. ++* Operation 2: A <-- B becomes A <== B (add parallel edge). ++ ++Each vertex (A, B, ...) is a start ID. S = globally minimal ID. T = \infty is an ++implicit sentinel. Each edge maps to an item, and edge weight is ID allotment. ++The edge A <-- B means "A's ID assignment needs to be determined before B's" ++(i.e., "B depends on A"), and requires A < B. ++ ++resource_ids stores a "flattened" representation of the graph, as a list of ++items (with meta data). Thus coarse ID assignment consists of the following: ++(1) Process list of items (with old start ID and meta data) to rebuild graph. ++(2) Traverse graph in an order that satisfies dependencies. ++(3) When vertex A has its ID assigned, the weight of each edge "A <--" (i.e., an ++ item) can have its weight (ID allotment) computed via quota assignment of A. ++(4) New start IDs satisfy A + w <= B for each edge A <-- B with weight w > 0. ++ ++The key algorithm challenge is (1). Note that it does not need weight details, ++so we only assume A < B whenever A <-- B. Now we're faced with 2 subproblems: ++(1a) How to represent the graph as a list of integers (with meta data)? ++(1b) Given the list representation, how to recover the graph? ++ ++For (1a), we start with DFS traversal of the (transposed, i.e., reversed) graph ++starting from S, and apply the following: ++* For each edge A <-- B traversed, emit A into sequence, ++* Traverse a B <-- Y only when all X <-- B have been traversed. ++ ++The resulting sequence has the length as the number of edges, and has the useful ++property that a vertex's dependencies always appear before the vertex itself! ++Note this the sentinel T is omitted. ++ ++Example 1: ++ S <-- A <-- B <-- C <-- T => "SABC". ++ ++Example 2: ++ S <-- A <-- B <-- C <-- T => "SA|AB|SDEC|SF", ++ | | | | | or "SF|SA|AB|SDEC", ++ | + <-- + | | or "SDE|SA|ABC|SF", ++ | | | or "SF|SDE|SA|ABC". ++ + <---D <-- E <---+ | ++ | | ++ + <-- F <---------------+ ++ ++Here, "X|Y" denotes backtracking between visiting X and visiting Y. This appears ++if and only if X >= Y, so "|" an optional (but illustrative) character that's ++not in the actual output. We will use it consistently in comments, and so the ++absence of "|" denotes the converse. For example, "XY" implies X < Y. ++ ++In terms of the basic operations: ++* Start: S <-- T => "S". ++* Operation 1: "...AB..." => "...ACB..." (or "...A" => "...AB"). ++* Operation 2: "...AB..." => "...A|AB..." (or "...A" => "...A|A"). ++ ++For Example 2, a viable "evolution path" is: ++"S" => "S|S" => "SC|S" => "S|SC|S" => "SA|SC|S" => "SAB|SC|S" => "SA|AB|SC|S" ++ => "SA|AB|SDC|S" => "SA|AB|SDEC|S" => "SA|AB|SDEC|SF". ++(Alternative: "S|S" => "S|SC" => etc.). ++ ++Note: {A, ...} are *unlabelled* integers, and "spurious equalities" such as ++A = D or A = F can occur! ++ ++For (1b), we wish to build the graph from the sequence. This requires (1a) to be ++injective (up to isomorphism). Unfortunately, this does not always hold. ++Example: ++ S <-- A <-- C <-- D <-- T => "SA|SBCD". ++ | | ++ + <-- B <---+ ++vs. ++ S <----- A <----- D <-- T => "SA|SBCD". ++ | | ++ + <-- B <-- C <---+ ++ ++To fix this, we prepend a "join" label (*) to each vertex that has multiple ++dependencies. With this, the example above produce different results: ++ "SA|SB*CD" != "SA|SBC*D". ++ ++Unfortunately, this is also inadequate. Example: ++ S <-------- B <-- T => "S|S|S|S*A*B", ++ | | ++ + <---------+ ++ | | ++ + <-- A <---+ ++ | | ++ + <---+ ++vs. ++ S <-------- B <-- T => "S|S|S|S*A*B". ++ | | ++ + <---A <---+ ++ | | ++ + <---+ ++ | | ++ + <---+ ++ ++To fix this, we also label the number of dependencies. In text representation, ++we just show multiple (#dependencies - 1) copies of '*'. Now we have: ++ "S|S|S|S*A**B" != "S|S|S|S**A*B". ++ ++The "join" label with count adequately addresses the issue (proof omitted). In ++the resource_ids files, these are stored as the "join" field of an item's meta ++data. ++ ++Additional comments for (1b) and other steps are detailed below. ++""" ++ ++ class DagNode: ++ """An element of the implicit graph, corresponding to an item. ++ ++ This actually represents an edge-vertex pair, corresponding to an item. ++ A vertex is represented by a collection of DagNode that uses |sib| to link ++ to a "representative node". The representative node, in turn, holds the list ++ of all |deps| (dependencies) of the vertex. ++ """ ++ ++ def __init__(self, item, old_id): ++ self.item = item ++ self.old_id = old_id ++ self.new_id = None ++ self.weight = None ++ ++ def __init__(self, item_list, align): ++ super(DagCoarseIdAssigner, self).__init__(item_list, align) ++ self._node_dict = {} # Maps from |lo| to item. ++ ++ def GenStartIds(self): ++ """Traverses implicit graph and yields new IDs. ++ ++ Algorithm: Process |old_id| of items sequentially. Successive items A and B ++ can be "AB" (A < B), "A*...B" (A < B), or "A|B" (A >= B). "AB" and "A*...B" ++ imply A <-- B, and are accumulated in |trace|. "A|B" are jumps that rewinds ++ |trace| to the latest B (must exist), and A is pushed into |jumps|. A join ++ "A*...B" also pops |num_join - 1| items {X_i} in |jump|, and X_i <-- B. In ++ the end, unprocessed elements in |jumps| all link to sentinel T, and can be ++ ignored. ++ """ ++ # DagNode stack of "A" when "AB" is found (increasing |old_id|). ++ trace = [] ++ # DagNode stack of "A" when "A|B" jumps is found. ++ jumps = [] ++ for item in self._item_list: # Sorted by |lo|. ++ meta = item.meta ++ # |num_join| indicates "*" in "A*...B", and specify B's dependencies: +1 ++ # from A, and +count("*") from |jumps|. ++ num_join = meta['join'].val if meta and 'join' in meta else None ++ node = DagCoarseIdAssigner.DagNode(item, item.tags[0].id) ++ self._node_dict[item.lo] = node ++ if trace: ++ if trace[-1].old_id >= node.old_id: # "A|B". ++ if num_join: ++ raise ValueError('Cannot join on jump: %d' % node.old_id) ++ jumps.append(trace[-1]) # Add A to |jumps|, for later join. ++ while trace and trace[-1].old_id > node.old_id: # Rewind to find B. ++ trace.pop() ++ if not trace or trace[-1].old_id != node.old_id: # ++ raise ValueError('Cannot jump to unvisited: %d' % node.old_id) ++ node.new_id = trace.pop().new_id # Copy B & remove. Will re-add B. ++ else: # "AB" or "A*...B". ++ node.new_id = trace[-1].new_id + trace[-1].weight # A --> B ++ if num_join: # "A*...B". ++ for _ in range(1, num_join): ++ t = jumps.pop() ++ node.new_id = max(node.new_id, t.new_id + t.weight) # X_i --> B. ++ else: ++ node.new_id = node.old_id # Initial S. ++ trace.append(node) # Add B. ++ align = meta['align'].val if meta and 'align' in meta else self._align ++ node.new_id = common.AlignUp(node.new_id, align) ++ yield node.item, node.new_id ++ # Expect caller to calling FreedWeight() and update |node.weight|. ++ ++ def FeedWeight(self, item, weight): ++ self._node_dict[item.lo].weight = weight ++ ++ ++def GenerateNewIds(item_list, use_naive): ++ """Visits all tags in |item_list| and generates new ids. ++ ++ New ids are generated based on old ids and usages. ++ """ ++ Assigner = NaiveCoarseIdAssigner if use_naive else DagCoarseIdAssigner ++ coarse_id_assigner = Assigner(item_list, 10) ++ quota_assigner = QuotaAssigner(Aligner(expand=1.15, slack=3, align=10)) ++ for item, start_id in coarse_id_assigner.GenStartIds(): # Topo-sorted. ++ cur_id = start_id ++ for tag, next_id in quota_assigner.Gen(item, start_id): # Sorted by |lo|. ++ yield tag, cur_id ++ cur_id = next_id ++ coarse_id_assigner.FeedWeight(item, next_id - start_id) +diff --git a/tools/grit/grit/tool/update_resource_ids/assigner_unittest.py b/tools/grit/grit/tool/update_resource_ids/assigner_unittest.py +new file mode 100644 +index 0000000000..164d820762 +--- /dev/null ++++ b/tools/grit/grit/tool/update_resource_ids/assigner_unittest.py +@@ -0,0 +1,154 @@ ++#!/usr/bin/env python ++# Copyright 2019 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++from __future__ import print_function ++ ++import os ++import sys ++import traceback ++import unittest ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../../..')) ++ ++from grit.tool.update_resource_ids import assigner, common, parser ++ ++# |spec| format: A comma-separated list of (old) start IDs. Modifiers: ++# * Prefix with n '*' to assign the item's META "join" field to n + 1. ++# * Suffix with "+[usage]" to assign |usage| for the item (else default=10) ++ ++ ++def _RenderTestResourceId(spec): ++ """Renders barebone resource_ids data based on |spec|.""" ++ data = '{"SRCDIR": ".",' ++ for i, tok in enumerate(spec.split(',')): ++ num_star = len(tok) - len(tok.lstrip('*')) ++ tok = tok[num_star:] ++ meta = '"META":{"join": %d},' % (num_star + 1) if num_star else '' ++ start_id = tok.split('+')[0] # Strip '+usage'. ++ data += '"foo%d.grd": {%s"includes": [%s]},' % (i, meta, start_id) ++ data += '}' ++ return data ++ ++ ++def _CreateTestItemList(spec): ++ """Creates list of ItemInfo based on |spec|.""" ++ data = _RenderTestResourceId(spec) ++ item_list = common.BuildItemList( ++ parser.ResourceIdParser(data, parser.Tokenize(data)).Parse()) ++ # Assign usages from "id+usage", default to 10. ++ for i, tok in enumerate(spec.split(',')): ++ item_list[i].tags[0].usage = int((tok.split('+') + ['10'])[1]) ++ return item_list ++ ++ ++def _RunCoarseIdAssigner(spec): ++ item_list = _CreateTestItemList(spec) ++ coarse_id_assigner = assigner.DagCoarseIdAssigner(item_list, 1) ++ new_id_list = [] # List of new IDs, to check ID assignment. ++ new_spec_list = [] # List of new tokens to construct new |spec|. ++ for item, start_id in coarse_id_assigner.GenStartIds(): # Topo-sorted.. ++ new_id_list.append(str(start_id)) ++ meta = item.meta ++ num_join = meta['join'].val if meta and 'join' in meta else 0 ++ t = '*' * max(0, num_join - 1) ++ t += str(start_id) ++ t += '' if item.tags[0].usage == 10 else '+' + str(item.tags[0].usage) ++ new_spec_list.append((item.lo, t)) ++ coarse_id_assigner.FeedWeight(item, item.tags[0].usage) ++ new_spec = ','.join(s for _, s in sorted(new_spec_list)) ++ return ','.join(new_id_list), new_spec ++ ++ ++class AssignerUnittest(unittest.TestCase): ++ ++ def testDagAssigner(self): ++ test_cases = [ ++ # Trivial. ++ ('0', '0'), ++ ('137', '137'), ++ ('5,15', '5,6'), ++ ('11,18', '11+7,12'), ++ ('5,5', '5,5'), ++ # Series only. ++ ('0,10,20,30,40', '0,1,2,3,4'), ++ ('5,15,25,35,45,55', '5,6,7,8,9,10'), ++ ('5,15,25,35,45,55', '5,7,100,101,256,1001'), ++ ('0,10,20,45,85', '0,1,2+25,3+40,4'), ++ # Branching with and without join. ++ ('0,0,10,20,20,30,40', '0,0,1,2,2,3,4'), ++ ('0,0,10,20,20,30,40', '0,0,*1,2,2,*3,4'), ++ ('0,0,2,12,12,16,26', '0+4,0+2,1,2+8,2+4,3,4'), ++ ('0,0,4,14,14,22,32', '0+4,0+2,*1,2+8,2+4,*3,4'), ++ # Wide branching with and without join. ++ ('0,10,10,10,10,10,10,20,30', '0,1,1,1,1,1,1,2,3'), ++ ('0,10,10,10,10,10,10,20,30', '0,1,1,1,1,1,1,*****2,3'), ++ ('0,2,2,2,2,2,2,7,17', '0+2,1+4,1+19,1,1+4,1+2,1+5,2,3'), ++ ('0,2,2,2,2,2,2,21,31', '0+2,1+4,1+19,1,1+4,1+2,1+5,*****2,3'), ++ # Expanding different branch, without join. ++ ('0,10,10,10,60,70,80', '0,1+15,1+15,1+50,2,3,4'), ++ ('0,10,10,10,25,35,45', '0,1+15,1+50,1+15,2,3,4'), ++ ('0,10,10,10,25,35,45', '0,1+50,1+15,1+15,2,3,4'), ++ # ... with join. ++ ('0,10,10,10,60,70,80', '0,1+15,1+15,1+50,**2,3,4'), ++ ('0,10,10,10,60,70,80', '0,1+15,1+50,1+15,**2,3,4'), ++ ('0,10,10,10,60,70,80', '0,1+50,1+15,1+15,**2,3,4'), ++ # ... with alternative join. ++ ('0,10,10,10,60,70,80', '0,1+15,1+15,1+50,2,**3,4'), ++ ('0,10,10,10,25,60,70', '0,1+15,1+50,1+15,2,**3,4'), ++ ('0,10,10,10,25,60,70', '0,1+50,1+15,1+15,2,**3,4'), ++ # Examples from assigner.py. ++ ('0,10,10,20,0,10,20,30,0,10', ++ '0,1,1,*2,0,4,5,*6,0,7'), # SA|AB|SDEC|SF ++ ('0,10,0,10,20,30', '0,1,0,2,*3,4'), # SA|SB*CD ++ ('0,10,0,10,20,30', '0,1,0,2,3,*4'), # SA|SBC*D ++ ('0,7,0,5,11,21', '0+7,1+4,0+5,2+3,*3,4'), # SA|SB*CD ++ ('0,7,0,5,8,18', '0+7,1+4,0+5,2+3,3,*4'), # SA|SBC*D ++ ('0,0,0,0,10,20', '0,0,0,0,*1,**2'), # S|S|S|S*A**B ++ ('0,0,0,0,10,20', '0,0,0,0,**1,*2'), # S|S|S|S**A*B ++ ('0,0,0,0,6,16', '0+8,0+7,0+6,0+5,*1,**2'), # S|S|S|S*A**B ++ ('0,0,0,0,7,17', '0+8,0+7,0+6,0+5,**1,*2'), # S|S|S|S**A*B ++ # Long branches without join. ++ ('0,10,0,0,10,20,0,10,20,30', '0,1,0,0,1,2,0,1,2,3'), ++ ('0,30,0,0,20,30,0,10,13,28', '0+30,1,0+50,0+20,1,2+17,0,1+3,2+15,3'), ++ # Long branches with join. ++ ('0,10,0,0,10,20,0,10,20,30', '0,1,0,0,1,2,0,1,2,***3'), ++ ('0,30,0,0,20,30,0,10,13,50', ++ '0+30,1,0+50,0+20,1,2+17,0,1+3,2+15,***3'), ++ # 2-level hierarchy. ++ ('0,10,10,20,0,10,10,20,30', '0,1,1,*2,0,1,1,*2,*3'), ++ ('0,2,2,10,0,3,3,6,34', '0+2,1+5,1+8,*2+24,0+3,1+2,1+3,*2+27,*3'), ++ ('0,2,2,10,0,3,3,6,34', '0+2,1+5,1+8,*2+24,0+3,1+2,1+3,*2+28,*3'), ++ ('0,2,2,10,0,3,3,6,35', '0+2,1+5,1+8,*2+24,0+3,1+2,1+3,*2+29,*3'), ++ # Binary hierarchy. ++ ('0,0,10,0,0,10,20,0,0,10,0,0,10,20,30', ++ '0,0,*1,0,0,*1,*2,0,0,*1,0,0,*1,*2,*3'), ++ ('0,0,2,0,0,5,11,0,0,8,0,0,5,14,18', ++ '0+1,0+2,*1+3,0+4,0+5,*1+6,*2+7,0+8,0+7,*1+6,0+5,0+4,*1+3,*2+2,*3+1'), ++ # Joining from different heads. ++ ('0,10,20,30,40,30,20,10,0,50', '0,1,2,3,4,3,2,1,0,****5'), ++ # Miscellaneous. ++ ('0,1,0,11', '0+1,1,0,*1'), ++ ] ++ for exp, spec in test_cases: ++ try: ++ actual, new_spec = _RunCoarseIdAssigner(spec) ++ self.failUnlessEqual(exp, actual) ++ # Test that assignment is idempotent. ++ actual2, new_spec2 = _RunCoarseIdAssigner(new_spec) ++ self.failUnlessEqual(actual, actual2) ++ self.failUnlessEqual(new_spec, new_spec2) ++ except Exception as e: ++ print(common.Color.RED(traceback.format_exc().rstrip())) ++ print('Failed spec: %s' % common.Color.CYAN(spec)) ++ print(' Expected: %s' % common.Color.YELLOW(exp)) ++ print(' Actual: %s' % common.Color.YELLOW(actual)) ++ if new_spec != new_spec2: ++ print('Not idempotent') ++ if isinstance(e, AssertionError): ++ raise e ++ ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/tool/update_resource_ids/common.py b/tools/grit/grit/tool/update_resource_ids/common.py +new file mode 100644 +index 0000000000..004d8aa0e3 +--- /dev/null ++++ b/tools/grit/grit/tool/update_resource_ids/common.py +@@ -0,0 +1,101 @@ ++# Copyright 2019 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++ ++def AlignUp(v, align): ++ return (v + align - 1) // align * align ++ ++ ++def StripPlural(s): ++ assert s.endswith('s'), 'Expect %s to be plural' % s ++ return s[:-1] ++ ++ ++class Color: ++ ++ def _MakeColor(code): ++ t = '\033[' + code + 'm%s\033[0m' ++ return lambda s: t % s ++ ++ NONE = staticmethod(lambda s: s) ++ RED = staticmethod(_MakeColor('31')) ++ GREEN = staticmethod(_MakeColor('32')) ++ YELLOW = staticmethod(_MakeColor('33')) ++ BLUE = staticmethod(_MakeColor('34')) ++ MAGENTA = staticmethod(_MakeColor('35')) ++ CYAN = staticmethod(_MakeColor('36')) ++ WHITE = staticmethod(_MakeColor('37')) ++ GRAY = staticmethod(_MakeColor('30;1')) ++ ++ ++class TagInfo: ++ """Stores resource_ids tag entry (e.g., {"includes": 100} pair).""" ++ ++ def __init__(self, raw_key, raw_value): ++ """TagInfo Constructor. ++ ++ Args: ++ raw_key: parser.AnnotatedValue for the parsed key, e.g., "includes". ++ raw_value: parser.AnnotatedValue for the parsed value, e.g., 100. ++ """ ++ # Tag name, e.g., 'include' (no "s" at end). ++ self.name = StripPlural(raw_key.val) ++ # |len(raw_value) > 1| is possible, e.g., see grd_reader_unittest.py's ++ # testAssignFirstIdsMultipleMessages. This feature seems unused though. ++ # TODO(huangs): Reconcile this (may end up removing multi-value feature). ++ assert len(raw_value) == 1 ++ # Inclusive start *position* of the tag's start ID in resource_ids. ++ self.lo = raw_value[0].lo ++ # Exclusive end *position* of the tag's start ID in resource_ids. ++ self.hi = raw_value[0].hi ++ # The tag's start ID. Initially the old value, but may be reassigned to new. ++ self.id = raw_value[0].val ++ # The number of IDs the tag uses, to be assigned by ItemInfo.SetUsages(). ++ self.usage = None ++ ++ ++class ItemInfo: ++ """resource_ids item, containing multiple TagInfo.""" ++ ++ def __init__(self, lo, grd, raw_item): ++ # Inclusive start position of the item's key. Serve as unique identifier. ++ self.lo = lo ++ # The GRD filename for the item. ++ self.grd = grd ++ # Optional META information for the item. ++ self.meta = None ++ # List of TagInfo associated witih the item. ++ self.tags = [] ++ for k, v in raw_item.items(): ++ if k.val == 'META': ++ assert self.meta is None ++ self.meta = v # Not flattened. ++ else: ++ self.tags.append(TagInfo(k, v)) ++ self.tags.sort(key=lambda tag: tag.lo) ++ ++ def SetUsages(self, tag_name_to_usage): ++ for tag in self.tags: ++ tag.usage = tag_name_to_usage.get(tag.name, 0) ++ ++ ++def BuildItemList(root_obj): ++ """Extracts ID assignments and structure from parsed resource_ids. ++ ++ Returns: A list of ItemInfo, ordered by |lo|. ++ """ ++ item_list = [] ++ grd_seen = set() ++ for raw_key, raw_item in root_obj.items(): # Unordered. ++ grd = raw_key.val ++ if grd == 'SRCDIR': ++ continue ++ if not grd.endswith('.grd'): ++ raise ValueError('Invalid GRD file: %s' % grd) ++ if grd in grd_seen: ++ raise ValueError('Duplicate GRD: %s' % grd) ++ grd_seen.add(grd) ++ item_list.append(ItemInfo(raw_key.lo, grd, raw_item)) ++ item_list.sort(key=lambda item: item.lo) ++ return item_list +diff --git a/tools/grit/grit/tool/update_resource_ids/parser.py b/tools/grit/grit/tool/update_resource_ids/parser.py +new file mode 100644 +index 0000000000..da956bbd1c +--- /dev/null ++++ b/tools/grit/grit/tool/update_resource_ids/parser.py +@@ -0,0 +1,231 @@ ++# Copyright 2019 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++"""Structure-preserving parser for resource_ids files. ++ ++Naive usage of eval() destroys resource_ids structure. This module provides a ++custom parser that annotates source byte ranges of "leaf values" (strings and ++integers). ++""" ++ ++from __future__ import print_function ++ ++_isWhitespace = lambda ch: ch in ' \t\n' ++_isNotNewline = lambda ch: ch != '\n' ++_isDigit = lambda ch: ch.isdigit() ++ ++ ++def _RenderLineCol(data, pos): ++ """Renders |pos| within text |data| in as text showing line and column.""" ++ # This is used to pinpoint fatal parse errors, so okay to be inefficient. ++ new_lines = [i for i in range(pos) if data[i] == '\n'] ++ row = 1 + len(new_lines) ++ col = (pos - new_lines[-1]) if new_lines else 1 + pos ++ return 'line %d, column %d' % (row, col) ++ ++ ++def Tokenize(data): ++ """Generator to split |data| into tokens. ++ ++ Each token is specified as |(t, lo, hi)|: ++ * |t|: Type, with '#' = space / comments, '0' = int, 'S' = string, 'E' = end, ++ and other characters denoting themselves. ++ * |lo, hi|: Token's range within |data| (as |data[lo:hi]|). ++ """ ++ ++ class ctx: # Local context for mutable data shared across inner functions. ++ pos = 0 ++ ++ def _HasData(): ++ return ctx.pos < len(data) ++ ++ # Returns True if ended by |not pred()|, or False if ended by EOF. ++ def _EatWhile(pred): ++ while _HasData(): ++ if pred(data[ctx.pos]): ++ ctx.pos += 1 ++ else: ++ return True ++ return False ++ ++ def _NextBlank(): ++ lo = ctx.pos ++ while True: ++ if not _EatWhile(_isWhitespace) or data[ctx.pos] != '#': ++ break ++ ctx.pos += 1 ++ if not _EatWhile(_isNotNewline): ++ break ++ ctx.pos += 1 ++ return None if ctx.pos == lo else (lo, ctx.pos) ++ ++ def _EatString(): ++ lo = ctx.pos ++ delim = data[ctx.pos] ++ is_escaped = False ++ ctx.pos += 1 ++ while _HasData(): ++ ch = data[ctx.pos] ++ ctx.pos += 1 ++ if is_escaped: ++ is_escaped = False ++ elif ch == '\\': ++ is_escaped = True ++ elif ch == delim: ++ return ++ raise ValueError('Unterminated string at %s' % _RenderLineCol(data, lo)) ++ ++ while _HasData(): ++ blank = _NextBlank() ++ if blank is not None: ++ yield ('#', blank[0], blank[1]) ++ if not _HasData(): ++ break ++ lo = ctx.pos ++ ch = data[ctx.pos] ++ if ch in '{}[],:': ++ ctx.pos += 1 ++ t = ch ++ elif ch.isdigit(): ++ _EatWhile(_isDigit) ++ t = '0' ++ elif ch in '+-': ++ ctx.pos += 1 ++ if not _HasData() or not data[ctx.pos].isdigit(): ++ raise ValueError('Invalid int at %s' % _RenderLineCol(data, lo)) ++ _EatWhile(_isDigit) ++ t = '0' ++ elif ch in '"\'': ++ _EatString() ++ t = 'S' ++ else: ++ raise ValueError('Unknown char %s at %s' % ++ (repr(ch), _RenderLineCol(data, lo))) ++ yield (t, lo, ctx.pos) ++ yield ('E', ctx.pos, ctx.pos) # End sentinel. ++ ++ ++def _SkipBlanks(toks): ++ """Generator to remove whitespace and comments from Tokenize().""" ++ for t, lo, hi in toks: ++ if t != '#': ++ yield t, lo, hi ++ ++ ++class AnnotatedValue: ++ """Container for leaf values (ints or strings) with an annotated range.""" ++ ++ def __init__(self, val, lo, hi): ++ self.val = val ++ self.lo = lo ++ self.hi = hi ++ ++ def __str__(self): ++ return '<%s@%d:%d>' % (str(self.val), self.lo, self.hi) ++ ++ def __repr__(self): ++ return '<%r@%d:%d>' % (self.val, self.lo, self.hi) ++ ++ def __hash__(self): ++ return hash(self.val) ++ ++ def __eq__(self, other): ++ return self.val == other ++ ++ ++class ResourceIdParser: ++ """resource_ids parser that stores leaf values as AnnotatedValue. ++ ++ Algorithm: Use Tokenize() to split |data| into tokens and _SkipBlanks() to ++ ignore comments and spacing, then apply a recursive parsing, using a one-token ++ look-ahead for decision making. ++ """ ++ ++ def __init__(self, data, tok_gen): ++ self.data = data ++ self.state = [] ++ self.toks = _SkipBlanks(tok_gen) ++ self.tok_look_ahead = None ++ ++ def _MakeErr(self, msg, pos): ++ return ValueError(msg + ' at ' + _RenderLineCol(self.data, pos)) ++ ++ def _PeekTok(self): ++ if self.tok_look_ahead is None: ++ self.tok_look_ahead = next(self.toks) ++ return self.tok_look_ahead ++ ++ def _NextTok(self): ++ if self.tok_look_ahead is None: ++ return next(self.toks) ++ ret = self.tok_look_ahead ++ self.tok_look_ahead = None ++ return ret ++ ++ def _EatTok(self, exp_t, tok_name=None): ++ t, lo, _ = self._NextTok() ++ if t != exp_t: ++ raise self._MakeErr('Bad token: Expect \'%s\'' % (tok_name or exp_t), lo) ++ ++ def _NextIntOrString(self): ++ t, lo, hi = self._NextTok() ++ if t != '0' and t != 'S': ++ raise self._MakeErr('Expected number or string', lo) ++ value = eval(self.data[lo:hi]) ++ return AnnotatedValue(value, lo, hi) ++ ++ # Consumes separator ',' and returns whether |end_ch| is encountered. ++ def _EatSep(self, end_ch): ++ t, lo, _ = self._PeekTok() ++ if t == ',': ++ self._EatTok(',') ++ # Allow trailing ','. ++ t, _, _ = self._PeekTok() ++ return t == end_ch ++ elif t == end_ch: ++ return True ++ else: ++ raise self._MakeErr('Expect \',\' or \'%s\'' % end_ch, lo) ++ ++ def _NextList(self): ++ self._EatTok('[') ++ ret = [] ++ t, _, _ = self._PeekTok() ++ if t != ']': ++ while True: ++ ret.append(self._NextObject()) ++ if self._EatSep(']'): ++ break ++ self._EatTok(']') ++ return ret ++ ++ def _NextDict(self): ++ self._EatTok('{') ++ ret = {} ++ t, _, _ = self._PeekTok() ++ if t != '}': ++ while True: ++ k = self._NextIntOrString() ++ self._EatTok(':') ++ v = self._NextObject() ++ ret[k] = v ++ if self._EatSep('}'): ++ break ++ self._EatTok('}') ++ return ret ++ ++ def _NextObject(self): ++ t, lo, _ = self._PeekTok() ++ if t == '[': ++ return self._NextList() ++ elif t == '{': ++ return self._NextDict() ++ elif t == '0' or t == 'S': ++ return self._NextIntOrString() ++ else: ++ raise self._MakeErr('Bad token: Type = %s' % t, lo) ++ ++ def Parse(self): ++ root_obj = self._NextObject() ++ self._EatTok('E', 'EOF') ++ return root_obj +diff --git a/tools/grit/grit/tool/update_resource_ids/reader.py b/tools/grit/grit/tool/update_resource_ids/reader.py +new file mode 100644 +index 0000000000..0a156d2deb +--- /dev/null ++++ b/tools/grit/grit/tool/update_resource_ids/reader.py +@@ -0,0 +1,83 @@ ++# Copyright 2019 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++"""Helpers to read GRD files and estimate resource ID usages. ++ ++This module uses grit.grd_reader to estimate resource ID usages in GRD ++(and GRDP) files by counting the occurrences of {include, message, structure} ++tags. This approach avoids the complexties of conditional inclusions, but ++produces a conservative estimate of ID usages. ++""" ++ ++from __future__ import print_function ++ ++import collections ++import os ++ ++from grit import grd_reader ++from grit import util ++from grit.tool.update_resource_ids import common ++ ++TAGS_OF_INTEREST = set(['include', 'message', 'structure']) ++ ++def _CountResourceUsage(grd, seen_files): ++ tag_name_to_count = {tag: set() for tag in TAGS_OF_INTEREST} ++ # Pass '_chromium', but '_google_chrome' would produce the same result. ++ root = grd_reader.Parse(grd, defines={'_chromium': True}) ++ seen_files.add(grd) ++ # Count all descendant tags, regardless of whether they're active. ++ for node in root.Preorder(): ++ if node.name in TAGS_OF_INTEREST: ++ tag_name_to_count[node.name].add(node.attrs['name']) ++ elif node.name == 'part': ++ part_path = os.path.join(os.path.dirname(grd), node.GetInputPath()) ++ seen_files.add(util.normpath(part_path)) ++ return {k: len(v) for k, v in tag_name_to_count.items() if v} ++ ++ ++def GenerateResourceUsages(item_list, src_dir, fake, seen_files): ++ """Visits a list of ItemInfo to generate maps from tag name to usage. ++ ++ Args: ++ root_obj: Root dict of a resource_ids file. ++ src_dir: Absolute directory of Chrome's src/ directory. ++ fake: For testing: Sets 10 as usages for all tags, to avoid reading GRD. ++ seen_files: A set to collect paths of files read. ++ Yields: ++ Tuple (item, tag_name_to_usage), where |item| is from |item_list| and ++ |tag_name_to_usage| is a dict() mapping tag name to (int) usage. ++ """ ++ if fake: ++ for item in item_list: ++ tag_name_to_usage = collections.Counter({t.name: 10 for t in item.tags}) ++ yield item, tag_name_to_usage ++ return ++ for item in item_list: ++ supported_tag_names = set(tag.name for tag in item.tags) ++ if item.meta and 'sizes' in item.meta: ++ # If META has "sizes" field, use it instead of reading GRD. ++ tag_name_to_usage = collections.Counter() ++ for k, vlist in item.meta['sizes'].items(): ++ tag_name_to_usage[common.StripPlural(k.val)] = sum(v.val for v in vlist) ++ tag_names = set(tag_name_to_usage.keys()) ++ if tag_names != supported_tag_names: ++ raise ValueError('META "sizes" field have identical fields as actual ' ++ '"sizes" field.') ++ else: ++ # Generated GRD start with '<(SHARED_INTERMEDIATE_DIR)'. Just check '<'. ++ if item.grd.startswith('<'): ++ raise ValueError('%s: Generated GRD must use META with "sizes" field ' ++ 'to specify size bounds.' % item.grd) ++ grd_file = os.path.join(src_dir, item.grd) ++ if not os.path.exists(grd_file): ++ # Silently skip missing files so that src-internal files do not break ++ # public checkouts. ++ yield item, {} ++ continue ++ tag_name_to_usage = _CountResourceUsage(grd_file, seen_files) ++ tag_names = set(tag_name_to_usage.keys()) ++ if not tag_names.issubset(supported_tag_names): ++ missing = [t + 's' for t in tag_names - supported_tag_names] ++ raise ValueError( ++ 'Resource ids for %s needs entry for %s' % (item.grd, missing)) ++ yield item, tag_name_to_usage +diff --git a/tools/grit/grit/tool/xmb.py b/tools/grit/grit/tool/xmb.py +new file mode 100644 +index 0000000000..b821308369 +--- /dev/null ++++ b/tools/grit/grit/tool/xmb.py +@@ -0,0 +1,295 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++"""The 'grit xmb' tool. ++""" ++ ++from __future__ import print_function ++ ++import getopt ++import os ++import sys ++ ++from xml.sax import saxutils ++ ++import six ++ ++from grit import grd_reader ++from grit import lazy_re ++from grit import tclib ++from grit import util ++from grit.tool import interface ++ ++ ++# Used to collapse presentable content to determine if ++# xml:space="preserve" is needed. ++_WHITESPACES_REGEX = lazy_re.compile(r'\s\s*') ++ ++ ++# See XmlEscape below. ++_XML_QUOTE_ESCAPES = { ++ u"'": u''', ++ u'"': u'"', ++} ++ ++def _XmlEscape(s): ++ """Returns text escaped for XML in a way compatible with Google's ++ internal Translation Console tool. May be used for attributes as ++ well as for contents. ++ """ ++ return saxutils.escape(six.text_type(s), _XML_QUOTE_ESCAPES).encode('utf-8') ++ ++ ++def _WriteAttribute(file, name, value): ++ """Writes an XML attribute to the specified file. ++ ++ Args: ++ file: file to write to ++ name: name of the attribute ++ value: (unescaped) value of the attribute ++ """ ++ name = name.encode('utf-8') ++ if value: ++ file.write(b' %s="%s"' % (name, _XmlEscape(value))) ++ ++ ++def _WriteMessage(file, message): ++ presentable_content = message.GetPresentableContent() ++ assert (isinstance(presentable_content, six.string_types) or ++ (len(message.parts) == 1 and ++ type(message.parts[0] == tclib.Placeholder))) ++ preserve_space = presentable_content != _WHITESPACES_REGEX.sub( ++ u' ', presentable_content.strip()) ++ ++ file.write(b'<msg') ++ _WriteAttribute(file, 'desc', message.GetDescription()) ++ _WriteAttribute(file, 'id', message.GetId()) ++ _WriteAttribute(file, 'meaning', message.GetMeaning()) ++ if preserve_space: ++ _WriteAttribute(file, 'xml:space', 'preserve') ++ file.write(b'>') ++ if not preserve_space: ++ file.write(b'\n ') ++ ++ parts = message.GetContent() ++ for part in parts: ++ if isinstance(part, tclib.Placeholder): ++ file.write(b'<ph') ++ _WriteAttribute(file, 'name', part.GetPresentation()) ++ file.write(b'><ex>') ++ file.write(_XmlEscape(part.GetExample())) ++ file.write(b'</ex>') ++ file.write(_XmlEscape(part.GetOriginal())) ++ file.write(b'</ph>') ++ else: ++ file.write(_XmlEscape(part)) ++ if not preserve_space: ++ file.write(b'\n') ++ file.write(b'</msg>\n') ++ ++ ++def WriteXmbFile(file, messages): ++ """Writes the given grit.tclib.Message items to the specified open ++ file-like object in the XMB format. ++ """ ++ file.write(b"""<?xml version="1.0" encoding="UTF-8"?> ++<!DOCTYPE messagebundle [ ++<!ELEMENT messagebundle (msg)*> ++<!ATTLIST messagebundle class CDATA #IMPLIED> ++ ++<!ELEMENT msg (#PCDATA|ph|source)*> ++<!ATTLIST msg id CDATA #IMPLIED> ++<!ATTLIST msg seq CDATA #IMPLIED> ++<!ATTLIST msg name CDATA #IMPLIED> ++<!ATTLIST msg desc CDATA #IMPLIED> ++<!ATTLIST msg meaning CDATA #IMPLIED> ++<!ATTLIST msg obsolete (obsolete) #IMPLIED> ++<!ATTLIST msg xml:space (default|preserve) "default"> ++<!ATTLIST msg is_hidden CDATA #IMPLIED> ++ ++<!ELEMENT source (#PCDATA)> ++ ++<!ELEMENT ph (#PCDATA|ex)*> ++<!ATTLIST ph name CDATA #REQUIRED> ++ ++<!ELEMENT ex (#PCDATA)> ++]> ++<messagebundle> ++""") ++ for message in messages: ++ _WriteMessage(file, message) ++ file.write(b'</messagebundle>') ++ ++ ++class OutputXmb(interface.Tool): ++ """Outputs all translateable messages in the .grd input file to an ++.xmb file, which is the format used to give source messages to ++Google's internal Translation Console tool. The format could easily ++be used for other systems. ++ ++Usage: grit xmb [-i|-h] [-l LIMITFILE] OUTPUTPATH ++ ++OUTPUTPATH is the path you want to output the .xmb file to. ++ ++The -l option can be used to output only some of the resources to the .xmb file. ++LIMITFILE is the path to a file that is used to limit the items output to the ++xmb file. If the filename extension is .grd, the file must be a .grd file ++and the tool only output the contents of nodes from the input file that also ++exist in the limit file (as compared on the 'name' attribute). Otherwise it must ++contain a list of the IDs that output should be limited to, one ID per line, and ++the tool will only output nodes with 'name' attributes that match one of the ++IDs. ++ ++The -i option causes 'grit xmb' to output an "IDs only" file instead of an XMB ++file. The "IDs only" file contains the message ID of each message that would ++normally be output to the XMB file, one message ID per line. It is designed for ++use with the 'grit transl2tc' tool's -l option. ++ ++Other options: ++ ++ -D NAME[=VAL] Specify a C-preprocessor-like define NAME with optional ++ value VAL (defaults to 1) which will be used to control ++ conditional inclusion of resources. ++ ++ -E NAME=VALUE Set environment variable NAME to VALUE (within grit). ++ ++""" ++ # The different output formats supported by this tool ++ FORMAT_XMB = 0 ++ FORMAT_IDS_ONLY = 1 ++ ++ def __init__(self, defines=None): ++ super(OutputXmb, self).__init__() ++ self.format = self.FORMAT_XMB ++ self.defines = defines or {} ++ ++ def ShortDescription(self): ++ return 'Exports all translateable messages into an XMB file.' ++ ++ def Run(self, opts, args): ++ os.environ['cwd'] = os.getcwd() ++ ++ self.SetOptions(opts) ++ ++ limit_file = None ++ limit_is_grd = False ++ limit_file_dir = None ++ own_opts, args = getopt.getopt(args, 'l:D:ih', ('help',)) ++ for key, val in own_opts: ++ if key == '-l': ++ limit_file = open(val, 'r') ++ limit_file_dir = util.dirname(val) ++ if not len(limit_file_dir): ++ limit_file_dir = '.' ++ limit_is_grd = os.path.splitext(val)[1] == '.grd' ++ elif key == '-i': ++ self.format = self.FORMAT_IDS_ONLY ++ elif key == '-D': ++ name, val = util.ParseDefine(val) ++ self.defines[name] = val ++ elif key == '-E': ++ (env_name, env_value) = val.split('=', 1) ++ os.environ[env_name] = env_value ++ elif key == '--help': ++ self.ShowUsage() ++ sys.exit(0) ++ if not len(args) == 1: ++ print('grit xmb takes exactly one argument, the path to the XMB file ' ++ 'to output.') ++ return 2 ++ ++ xmb_path = args[0] ++ res_tree = grd_reader.Parse(opts.input, debug=opts.extra_verbose, defines=self.defines) ++ res_tree.SetOutputLanguage('en') ++ res_tree.SetDefines(self.defines) ++ res_tree.OnlyTheseTranslations([]) ++ res_tree.RunGatherers() ++ ++ with open(xmb_path, 'wb') as output_file: ++ self.Process( ++ res_tree, output_file, limit_file, limit_is_grd, limit_file_dir) ++ if limit_file: ++ limit_file.close() ++ print("Wrote %s" % xmb_path) ++ ++ def Process(self, res_tree, output_file, limit_file=None, limit_is_grd=False, ++ dir=None): ++ """Writes a document with the contents of res_tree into output_file, ++ limiting output to the IDs specified in limit_file, which is a GRD file if ++ limit_is_grd is true, otherwise a file with one ID per line. ++ ++ The format of the output document depends on this object's format attribute. ++ It can be FORMAT_XMB or FORMAT_IDS_ONLY. ++ ++ The FORMAT_IDS_ONLY format causes this function to write just a list ++ of the IDs of all messages that would have been added to the XMB file, one ++ ID per line. ++ ++ The FORMAT_XMB format causes this function to output the (default) XMB ++ format. ++ ++ Args: ++ res_tree: base.Node() ++ output_file: file open for writing ++ limit_file: None or file open for reading ++ limit_is_grd: True | False ++ dir: Directory of the limit file ++ """ ++ if limit_file: ++ if limit_is_grd: ++ limit_list = [] ++ limit_tree = grd_reader.Parse(limit_file, ++ dir=dir, ++ debug=self.o.extra_verbose) ++ for node in limit_tree: ++ if 'name' in node.attrs: ++ limit_list.append(node.attrs['name']) ++ else: ++ # Not a GRD file, so it's just a file with one ID per line ++ limit_list = [item.strip() for item in limit_file.read().split('\n')] ++ ++ ids_already_done = {} ++ messages = [] ++ for node in res_tree: ++ if (limit_file and ++ not ('name' in node.attrs and node.attrs['name'] in limit_list)): ++ continue ++ if not node.IsTranslateable(): ++ continue ++ ++ for clique in node.GetCliques(): ++ if not clique.IsTranslateable(): ++ continue ++ if not clique.GetMessage().GetRealContent(): ++ continue ++ ++ # Some explanation is in order here. Note that we can have ++ # many messages with the same ID. ++ # ++ # The way we work around this is to maintain a list of cliques ++ # per message ID (in the UberClique) and select the "best" one ++ # (the first one that has a description, or an arbitrary one ++ # if there is no description) for inclusion in the XMB file. ++ # The translations are all going to be the same for messages ++ # with the same ID, although the way we replace placeholders ++ # might be slightly different. ++ id = clique.GetMessage().GetId() ++ if id in ids_already_done: ++ continue ++ ids_already_done[id] = 1 ++ ++ message = node.UberClique().BestClique(id).GetMessage() ++ messages += [message] ++ ++ # Ensure a stable order of messages, to help regression testing. ++ messages.sort(key=lambda x:x.GetId()) ++ ++ if self.format == self.FORMAT_IDS_ONLY: ++ # We just print the list of IDs to the output file. ++ for msg in messages: ++ output_file.write(msg.GetId()) ++ output_file.write('\n') ++ else: ++ assert self.format == self.FORMAT_XMB ++ WriteXmbFile(output_file, messages) +diff --git a/tools/grit/grit/tool/xmb_unittest.py b/tools/grit/grit/tool/xmb_unittest.py +new file mode 100644 +index 0000000000..3c7e92cee7 +--- /dev/null ++++ b/tools/grit/grit/tool/xmb_unittest.py +@@ -0,0 +1,132 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for 'grit xmb' tool.''' ++ ++from __future__ import print_function ++ ++import io ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) ++ ++import unittest ++import xml.sax ++ ++from six import StringIO ++ ++from grit import grd_reader ++from grit import util ++from grit.tool import xmb ++ ++ ++class XmbUnittest(unittest.TestCase): ++ def setUp(self): ++ self.res_tree = grd_reader.Parse( ++ io.BytesIO(u'''<?xml version="1.0" encoding="UTF-8"?> ++ <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <release seq="3"> ++ <includes> ++ <include type="gif" name="ID_LOGO" file="images/logo.gif" /> ++ </includes> ++ <messages> ++ <message name="GOOD" desc="sub" sub_variable="true"> ++ excellent ++ </message> ++ <message name="IDS_GREETING" desc="Printed to greet the currently logged in user"> ++ Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, are you doing [GOOD] today? ++ </message> ++ <message name="IDS_BONGOBINGO"> ++ Yibbee ++ </message> ++ <message name="IDS_UNICODE"> ++ Ol\xe1, \u4eca\u65e5\u306f! \U0001F60A ++ </message> ++ </messages> ++ <structures> ++ <structure type="dialog" name="IDD_SPACYBOX" encoding="utf-16" file="grit/testdata/klonk.rc" /> ++ </structures> ++ </release> ++ </grit>'''.encode('utf-8')), '.') ++ self.xmb_file = io.BytesIO() ++ ++ def testNormalOutput(self): ++ xmb.OutputXmb().Process(self.res_tree, self.xmb_file) ++ output = self.xmb_file.getvalue().decode('utf-8') ++ self.failUnless(output.count('Joi')) ++ self.failUnless(output.count('Yibbee')) ++ self.failUnless(output.count(u'Ol\xe1, \u4eca\u65e5\u306f! \U0001F60A')) ++ ++ def testLimitList(self): ++ limit_file = StringIO( ++ 'IDS_BONGOBINGO\nIDS_DOES_NOT_EXIST\nIDS_ALSO_DOES_NOT_EXIST') ++ xmb.OutputXmb().Process(self.res_tree, self.xmb_file, limit_file, False) ++ output = self.xmb_file.getvalue().decode('utf-8') ++ self.failUnless(output.count('Yibbee')) ++ self.failUnless(not output.count('Joi')) ++ ++ def testLimitGrd(self): ++ limit_file = StringIO('''<?xml version="1.0" encoding="UTF-8"?> ++ <grit latest_public_release="2" source_lang_id="en-US" current_release="3" base_dir="."> ++ <release seq="3"> ++ <messages> ++ <message name="IDS_GREETING" desc="Printed to greet the currently logged in user"> ++ Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today? ++ </message> ++ </messages> ++ </release> ++ </grit>''') ++ tool = xmb.OutputXmb() ++ class DummyOpts(object): ++ extra_verbose = False ++ tool.o = DummyOpts() ++ tool.Process(self.res_tree, self.xmb_file, limit_file, True, dir='.') ++ output = self.xmb_file.getvalue().decode('utf-8') ++ self.failUnless(output.count('Joi')) ++ self.failUnless(not output.count('Yibbee')) ++ ++ def testSubstitution(self): ++ self.res_tree.SetOutputLanguage('en') ++ os.chdir(util.PathFromRoot('.')) # so it can find klonk.rc ++ self.res_tree.RunGatherers() ++ xmb.OutputXmb().Process(self.res_tree, self.xmb_file) ++ output = self.xmb_file.getvalue().decode('utf-8') ++ self.failUnless(output.count( ++ '<ph name="GOOD_1"><ex>excellent</ex>[GOOD]</ph>')) ++ ++ def testLeadingTrailingWhitespace(self): ++ # Regression test for problems outputting messages with leading or ++ # trailing whitespace (these come in via structures only, as ++ # message nodes already strip and store whitespace). ++ self.res_tree.SetOutputLanguage('en') ++ os.chdir(util.PathFromRoot('.')) # so it can find klonk.rc ++ self.res_tree.RunGatherers() ++ xmb.OutputXmb().Process(self.res_tree, self.xmb_file) ++ output = self.xmb_file.getvalue().decode('utf-8') ++ self.failUnless(output.count('OK ? </msg>')) ++ ++ def testDisallowedChars(self): ++ # Validate that the invalid unicode is not accepted. Since it's not valid, ++ # we can't specify it in a string literal, so write as a byte sequence. ++ bad_xml = io.BytesIO() ++ bad_xml.write(b'''<?xml version="1.0" encoding="UTF-8"?> ++ <grit latest_public_release="2" source_lang_id="en-US" ++ current_release="3" base_dir="."> ++ <release seq="3"> ++ <messages> ++ <message name="ID_FOO">''') ++ # UTF-8 corresponding to to \U00110000 ++ # http://apps.timwhitlock.info/unicode/inspect/hex/110000 ++ bad_xml.write(b'\xF4\x90\x80\x80') ++ bad_xml.write(b'''</message> ++ </messages> ++ </release> ++ </grit>''') ++ bad_xml.seek(0) ++ self.assertRaises(xml.sax.SAXParseException, grd_reader.Parse, bad_xml, '.') ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/util.py b/tools/grit/grit/util.py +new file mode 100644 +index 0000000000..98433d154c +--- /dev/null ++++ b/tools/grit/grit/util.py +@@ -0,0 +1,691 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Utilities used by GRIT. ++''' ++ ++from __future__ import print_function ++ ++import codecs ++import io ++import os ++import re ++import shutil ++import sys ++import tempfile ++from xml.sax import saxutils ++ ++import six ++from six import StringIO ++from six.moves import html_entities as entities ++ ++from grit import lazy_re ++ ++_root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) ++ ++ ++# Unique constants for use by ReadFile(). ++BINARY = 0 ++ ++ ++# Unique constants representing data pack encodings. ++_, UTF8, UTF16 = range(3) ++ ++ ++def Encode(message, encoding): ++ '''Returns a byte stream that represents |message| in the given |encoding|.''' ++ # |message| is a python unicode string, so convert to a byte stream that ++ # has the correct encoding requested for the datapacks. We skip the first ++ # 2 bytes of text resources because it is the BOM. ++ if encoding == UTF8: ++ return message.encode('utf8') ++ if encoding == UTF16: ++ return message.encode('utf16')[2:] ++ # Default is BINARY ++ return message ++ ++ ++# Matches all different types of linebreaks. ++LINEBREAKS = re.compile('\r\n|\n|\r') ++ ++def MakeRelativePath(base_path, path_to_make_relative): ++ """Returns a relative path such from the base_path to ++ the path_to_make_relative. ++ ++ In other words, os.join(base_path, ++ MakeRelativePath(base_path, path_to_make_relative)) ++ is the same location as path_to_make_relative. ++ ++ Args: ++ base_path: the root path ++ path_to_make_relative: an absolute path that is on the same drive ++ as base_path ++ """ ++ ++ def _GetPathAfterPrefix(prefix_path, path_with_prefix): ++ """Gets the subpath within in prefix_path for the path_with_prefix ++ with no beginning or trailing path separators. ++ ++ Args: ++ prefix_path: the base path ++ path_with_prefix: a path that starts with prefix_path ++ """ ++ assert path_with_prefix.startswith(prefix_path) ++ path_without_prefix = path_with_prefix[len(prefix_path):] ++ normalized_path = os.path.normpath(path_without_prefix.strip(os.path.sep)) ++ if normalized_path == '.': ++ normalized_path = '' ++ return normalized_path ++ ++ def _GetCommonBaseDirectory(*args): ++ """Returns the common prefix directory for the given paths ++ ++ Args: ++ The list of paths (at least one of which should be a directory) ++ """ ++ prefix = os.path.commonprefix(args) ++ # prefix is a character-by-character prefix (i.e. it does not end ++ # on a directory bound, so this code fixes that) ++ ++ # if the prefix ends with the separator, then it is prefect. ++ if len(prefix) > 0 and prefix[-1] == os.path.sep: ++ return prefix ++ ++ # We need to loop through all paths or else we can get ++ # tripped up by "c:\a" and "c:\abc". The common prefix ++ # is "c:\a" which is a directory and looks good with ++ # respect to the first directory but it is clear that ++ # isn't a common directory when the second path is ++ # examined. ++ for path in args: ++ assert len(path) >= len(prefix) ++ # If the prefix the same length as the path, ++ # then the prefix must be a directory (since one ++ # of the arguements should be a directory). ++ if path == prefix: ++ continue ++ # if the character after the prefix in the path ++ # is the separator, then the prefix appears to be a ++ # valid a directory as well for the given path ++ if path[len(prefix)] == os.path.sep: ++ continue ++ # Otherwise, the prefix is not a directory, so it needs ++ # to be shortened to be one ++ index_sep = prefix.rfind(os.path.sep) ++ # The use "index_sep + 1" because it includes the final sep ++ # and it handles the case when the index_sep is -1 as well ++ prefix = prefix[:index_sep + 1] ++ # At this point we backed up to a directory bound which is ++ # common to all paths, so we can quit going through all of ++ # the paths. ++ break ++ return prefix ++ ++ prefix = _GetCommonBaseDirectory(base_path, path_to_make_relative) ++ # If the paths had no commonality at all, then return the absolute path ++ # because it is the best that can be done. If the path had to be relative ++ # then eventually this absolute path will be discovered (when a build breaks) ++ # and an appropriate fix can be made, but having this allows for the best ++ # backward compatibility with the absolute path behavior in the past. ++ if len(prefix) <= 0: ++ return path_to_make_relative ++ # Build a path from the base dir to the common prefix ++ remaining_base_path = _GetPathAfterPrefix(prefix, base_path) ++ ++ # The follow handles two case: "" and "foo\\bar" ++ path_pieces = remaining_base_path.split(os.path.sep) ++ base_depth_from_prefix = len([d for d in path_pieces if len(d)]) ++ base_to_prefix = (".." + os.path.sep) * base_depth_from_prefix ++ ++ # Put add in the path from the prefix to the path_to_make_relative ++ remaining_other_path = _GetPathAfterPrefix(prefix, path_to_make_relative) ++ return base_to_prefix + remaining_other_path ++ ++ ++KNOWN_SYSTEM_IDENTIFIERS = set() ++ ++SYSTEM_IDENTIFIERS = None ++ ++def SetupSystemIdentifiers(ids): ++ '''Adds ids to a regexp of known system identifiers. ++ ++ Can be called many times, ids will be accumulated. ++ ++ Args: ++ ids: an iterable of strings ++ ''' ++ KNOWN_SYSTEM_IDENTIFIERS.update(ids) ++ global SYSTEM_IDENTIFIERS ++ SYSTEM_IDENTIFIERS = lazy_re.compile( ++ ' | '.join([r'\b%s\b' % i for i in KNOWN_SYSTEM_IDENTIFIERS]), ++ re.VERBOSE) ++ ++ ++# Matches all of the resource IDs predefined by Windows. ++SetupSystemIdentifiers(( ++ 'IDOK', 'IDCANCEL', 'IDC_STATIC', 'IDYES', 'IDNO', ++ 'ID_FILE_NEW', 'ID_FILE_OPEN', 'ID_FILE_CLOSE', 'ID_FILE_SAVE', ++ 'ID_FILE_SAVE_AS', 'ID_FILE_PAGE_SETUP', 'ID_FILE_PRINT_SETUP', ++ 'ID_FILE_PRINT', 'ID_FILE_PRINT_DIRECT', 'ID_FILE_PRINT_PREVIEW', ++ 'ID_FILE_UPDATE', 'ID_FILE_SAVE_COPY_AS', 'ID_FILE_SEND_MAIL', ++ 'ID_FILE_MRU_FIRST', 'ID_FILE_MRU_LAST', ++ 'ID_EDIT_CLEAR', 'ID_EDIT_CLEAR_ALL', 'ID_EDIT_COPY', ++ 'ID_EDIT_CUT', 'ID_EDIT_FIND', 'ID_EDIT_PASTE', 'ID_EDIT_PASTE_LINK', ++ 'ID_EDIT_PASTE_SPECIAL', 'ID_EDIT_REPEAT', 'ID_EDIT_REPLACE', ++ 'ID_EDIT_SELECT_ALL', 'ID_EDIT_UNDO', 'ID_EDIT_REDO', ++ 'VS_VERSION_INFO', 'IDRETRY', ++ 'ID_APP_ABOUT', 'ID_APP_EXIT', ++ 'ID_NEXT_PANE', 'ID_PREV_PANE', ++ 'ID_WINDOW_NEW', 'ID_WINDOW_ARRANGE', 'ID_WINDOW_CASCADE', ++ 'ID_WINDOW_TILE_HORZ', 'ID_WINDOW_TILE_VERT', 'ID_WINDOW_SPLIT', ++ 'ATL_IDS_SCSIZE', 'ATL_IDS_SCMOVE', 'ATL_IDS_SCMINIMIZE', ++ 'ATL_IDS_SCMAXIMIZE', 'ATL_IDS_SCNEXTWINDOW', 'ATL_IDS_SCPREVWINDOW', ++ 'ATL_IDS_SCCLOSE', 'ATL_IDS_SCRESTORE', 'ATL_IDS_SCTASKLIST', ++ 'ATL_IDS_MDICHILD', 'ATL_IDS_IDLEMESSAGE', 'ATL_IDS_MRU_FILE' )) ++ ++ ++# Matches character entities, whether specified by name, decimal or hex. ++_HTML_ENTITY = lazy_re.compile( ++ '&(#(?P<decimal>[0-9]+)|#x(?P<hex>[a-fA-F0-9]+)|(?P<named>[a-z0-9]+));', ++ re.IGNORECASE) ++ ++# Matches characters that should be HTML-escaped. This is <, > and &, but only ++# if the & is not the start of an HTML character entity. ++_HTML_CHARS_TO_ESCAPE = lazy_re.compile( ++ '"|<|>|&(?!#[0-9]+|#x[0-9a-z]+|[a-z]+;)', ++ re.IGNORECASE | re.MULTILINE) ++ ++ ++def ReadFile(filename, encoding): ++ '''Reads and returns the entire contents of the given file. ++ ++ Args: ++ filename: The path to the file. ++ encoding: A Python codec name or the special value: BINARY to read ++ the file in binary mode. ++ ''' ++ if encoding == BINARY: ++ mode = 'rb' ++ encoding = None ++ else: ++ mode = 'rU' ++ ++ with io.open(filename, mode, encoding=encoding) as f: ++ return f.read() ++ ++ ++def WrapOutputStream(stream, encoding = 'utf-8'): ++ '''Returns a stream that wraps the provided stream, making it write ++ characters using the specified encoding.''' ++ return codecs.getwriter(encoding)(stream) ++ ++ ++def ChangeStdoutEncoding(encoding = 'utf-8'): ++ '''Changes STDOUT to print characters using the specified encoding.''' ++ # If we're unittesting, don't reconfigure. ++ if isinstance(sys.stdout, StringIO): ++ return ++ ++ if sys.version_info.major < 3: ++ # Python 2 has binary streams by default, so reconfigure directly. ++ sys.stdout = WrapOutputStream(sys.stdout, encoding) ++ sys.stderr = WrapOutputStream(sys.stderr, encoding) ++ elif sys.version_info < (3, 7): ++ # Python 3 has text streams by default, so we have to detach them first. ++ sys.stdout = WrapOutputStream(sys.stdout.detach(), encoding) ++ sys.stderr = WrapOutputStream(sys.stderr.detach(), encoding) ++ else: ++ # Python 3.7+ provides an API for this specifically. ++ sys.stdout.reconfigure(encoding=encoding) ++ sys.stderr.reconfigure(encoding=encoding) ++ ++ ++def EscapeHtml(text, escape_quotes = False): ++ '''Returns 'text' with <, > and & (and optionally ") escaped to named HTML ++ entities. Any existing named entity or HTML entity defined by decimal or ++ hex code will be left untouched. This is appropriate for escaping text for ++ inclusion in HTML, but not for XML. ++ ''' ++ def Replace(match): ++ if match.group() == '&': return '&' ++ elif match.group() == '<': return '<' ++ elif match.group() == '>': return '>' ++ elif match.group() == '"': ++ if escape_quotes: return '"' ++ else: return match.group() ++ else: assert False ++ out = _HTML_CHARS_TO_ESCAPE.sub(Replace, text) ++ return out ++ ++ ++def UnescapeHtml(text, replace_nbsp=True): ++ '''Returns 'text' with all HTML character entities (both named character ++ entities and those specified by decimal or hexadecimal Unicode ordinal) ++ replaced by their Unicode characters (or latin1 characters if possible). ++ ++ The only exception is that will not be escaped if 'replace_nbsp' is ++ False. ++ ''' ++ def Replace(match): ++ groups = match.groupdict() ++ if groups['hex']: ++ return six.unichr(int(groups['hex'], 16)) ++ elif groups['decimal']: ++ return six.unichr(int(groups['decimal'], 10)) ++ else: ++ name = groups['named'] ++ if name == 'nbsp' and not replace_nbsp: ++ return match.group() # Don't replace ++ assert name != None ++ if name in entities.name2codepoint: ++ return six.unichr(entities.name2codepoint[name]) ++ else: ++ return match.group() # Unknown HTML character entity - don't replace ++ ++ out = _HTML_ENTITY.sub(Replace, text) ++ return out ++ ++ ++def EncodeCdata(cdata): ++ '''Returns the provided cdata in either escaped format or <![CDATA[xxx]]> ++ format, depending on which is more appropriate for easy editing. The data ++ is escaped for inclusion in an XML element's body. ++ ++ Args: ++ cdata: 'If x < y and y < z then x < z' ++ ++ Return: ++ '<![CDATA[If x < y and y < z then x < z]]>' ++ ''' ++ if cdata.count('<') > 1 or cdata.count('>') > 1 and cdata.count(']]>') == 0: ++ return '<![CDATA[%s]]>' % cdata ++ else: ++ return saxutils.escape(cdata) ++ ++ ++def FixupNamedParam(function, param_name, param_value): ++ '''Returns a closure that is identical to 'function' but ensures that the ++ named parameter 'param_name' is always set to 'param_value' unless explicitly ++ set by the caller. ++ ++ Args: ++ function: callable ++ param_name: 'bingo' ++ param_value: 'bongo' (any type) ++ ++ Return: ++ callable ++ ''' ++ def FixupClosure(*args, **kw): ++ if not param_name in kw: ++ kw[param_name] = param_value ++ return function(*args, **kw) ++ return FixupClosure ++ ++ ++def PathFromRoot(path): ++ r'''Takes a path relative to the root directory for GRIT (the one that grit.py ++ resides in) and returns a path that is either absolute or relative to the ++ current working directory (i.e .a path you can use to open the file). ++ ++ Args: ++ path: 'rel_dir\file.ext' ++ ++ Return: ++ 'c:\src\tools\rel_dir\file.ext ++ ''' ++ return os.path.normpath(os.path.join(_root_dir, path)) ++ ++ ++def ParseGrdForUnittest(body, base_dir=None, predetermined_ids_file=None, ++ run_gatherers=False): ++ '''Parse a skeleton .grd file and return it, for use in unit tests. ++ ++ Args: ++ body: XML that goes inside the <release> element. ++ base_dir: The base_dir attribute of the <grit> tag. ++ ''' ++ from grit import grd_reader ++ if isinstance(body, six.text_type): ++ body = body.encode('utf-8') ++ if base_dir is None: ++ base_dir = PathFromRoot('.') ++ lines = [b'<?xml version="1.0" encoding="UTF-8"?>'] ++ lines.append(b'<grit latest_public_release="2" current_release="3" ' ++ b'source_lang_id="en" base_dir="%s">' % base_dir.encode('utf-8')) ++ if b'<outputs>' in body: ++ lines.append(body) ++ else: ++ lines.append(b' <outputs></outputs>') ++ lines.append(b' <release seq="3">') ++ lines.append(body) ++ lines.append(b' </release>') ++ lines.append(b'</grit>') ++ ret = grd_reader.Parse(io.BytesIO(b'\n'.join(lines)), dir='.') ++ ret.SetOutputLanguage('en') ++ if run_gatherers: ++ ret.RunGatherers() ++ ret.SetPredeterminedIdsFile(predetermined_ids_file) ++ ret.InitializeIds() ++ return ret ++ ++ ++def StripBlankLinesAndComments(text): ++ '''Strips blank lines and comments from C source code, for unit tests.''' ++ return '\n'.join(line for line in text.splitlines() ++ if line and not line.startswith('//')) ++ ++ ++def dirname(filename): ++ '''Version of os.path.dirname() that never returns empty paths (returns ++ '.' if the result of os.path.dirname() is empty). ++ ''' ++ ret = os.path.dirname(filename) ++ if ret == '': ++ ret = '.' ++ return ret ++ ++ ++def normpath(path): ++ '''Version of os.path.normpath that also changes backward slashes to ++ forward slashes when not running on Windows. ++ ''' ++ # This is safe to always do because the Windows version of os.path.normpath ++ # will replace forward slashes with backward slashes. ++ path = path.replace('\\', '/') ++ return os.path.normpath(path) ++ ++ ++_LANGUAGE_SPLIT_RE = lazy_re.compile('-|_|/') ++ ++ ++def CanonicalLanguage(code): ++ '''Canonicalizes two-part language codes by using a dash and making the ++ second part upper case. Returns one-part language codes unchanged. ++ ++ Args: ++ code: 'zh_cn' ++ ++ Return: ++ code: 'zh-CN' ++ ''' ++ parts = _LANGUAGE_SPLIT_RE.split(code) ++ code = [ parts[0] ] ++ for part in parts[1:]: ++ code.append(part.upper()) ++ return '-'.join(code) ++ ++ ++_LANG_TO_CODEPAGE = { ++ 'en' : 1252, ++ 'fr' : 1252, ++ 'it' : 1252, ++ 'de' : 1252, ++ 'es' : 1252, ++ 'nl' : 1252, ++ 'sv' : 1252, ++ 'no' : 1252, ++ 'da' : 1252, ++ 'fi' : 1252, ++ 'pt-BR' : 1252, ++ 'ru' : 1251, ++ 'ja' : 932, ++ 'zh-TW' : 950, ++ 'zh-CN' : 936, ++ 'ko' : 949, ++} ++ ++ ++def LanguageToCodepage(lang): ++ '''Returns the codepage _number_ that can be used to represent 'lang', which ++ may be either in formats such as 'en', 'pt_br', 'pt-BR', etc. ++ ++ The codepage returned will be one of the 'cpXXXX' codepage numbers. ++ ++ Args: ++ lang: 'de' ++ ++ Return: ++ 1252 ++ ''' ++ lang = CanonicalLanguage(lang) ++ if lang in _LANG_TO_CODEPAGE: ++ return _LANG_TO_CODEPAGE[lang] ++ else: ++ print("Not sure which codepage to use for %s, assuming cp1252" % lang) ++ return 1252 ++ ++def NewClassInstance(class_name, class_type): ++ '''Returns an instance of the class specified in classname ++ ++ Args: ++ class_name: the fully qualified, dot separated package + classname, ++ i.e. "my.package.name.MyClass". Short class names are not supported. ++ class_type: the class or superclass this object must implement ++ ++ Return: ++ An instance of the class, or None if none was found ++ ''' ++ lastdot = class_name.rfind('.') ++ module_name = '' ++ if lastdot >= 0: ++ module_name = class_name[0:lastdot] ++ if module_name: ++ class_name = class_name[lastdot+1:] ++ module = __import__(module_name, globals(), locals(), ['']) ++ if hasattr(module, class_name): ++ class_ = getattr(module, class_name) ++ class_instance = class_() ++ if isinstance(class_instance, class_type): ++ return class_instance ++ return None ++ ++ ++def FixLineEnd(text, line_end): ++ # First normalize ++ text = text.replace('\r\n', '\n') ++ text = text.replace('\r', '\n') ++ # Then fix ++ text = text.replace('\n', line_end) ++ return text ++ ++ ++def BoolToString(bool): ++ if bool: ++ return 'true' ++ else: ++ return 'false' ++ ++ ++verbose = False ++extra_verbose = False ++ ++def IsVerbose(): ++ return verbose ++ ++def IsExtraVerbose(): ++ return extra_verbose ++ ++def ParseDefine(define): ++ '''Parses a define argument and returns the name and value. ++ ++ The format is either "NAME=VAL" or "NAME", using True as the default value. ++ Values of "1"/"true" and "0"/"false" are transformed to True and False ++ respectively. ++ ++ Args: ++ define: a string of the form "NAME=VAL" or "NAME". ++ ++ Returns: ++ A (name, value) pair. name is a string, value a string or boolean. ++ ''' ++ parts = [part.strip() for part in define.split('=', 1)] ++ assert len(parts) >= 1 ++ name = parts[0] ++ val = True ++ if len(parts) > 1: ++ val = parts[1] ++ if val == "1" or val == "true": val = True ++ elif val == "0" or val == "false": val = False ++ return (name, val) ++ ++ ++class Substituter(object): ++ '''Finds and substitutes variable names in text strings. ++ ++ Given a dictionary of variable names and values, prepares to ++ search for patterns of the form [VAR_NAME] in a text. ++ The value will be substituted back efficiently. ++ Also applies to tclib.Message objects. ++ ''' ++ ++ def __init__(self): ++ '''Create an empty substituter.''' ++ self.substitutions_ = {} ++ self.dirty_ = True ++ ++ def AddSubstitutions(self, subs): ++ '''Add new values to the substitutor. ++ ++ Args: ++ subs: A dictionary of new substitutions. ++ ''' ++ self.substitutions_.update(subs) ++ self.dirty_ = True ++ ++ def AddMessages(self, messages, lang): ++ '''Adds substitutions extracted from node.Message objects. ++ ++ Args: ++ messages: a list of node.Message objects. ++ lang: The translation language to use in substitutions. ++ ''' ++ subs = [(str(msg.attrs['name']), msg.Translate(lang)) for msg in messages] ++ self.AddSubstitutions(dict(subs)) ++ self.dirty_ = True ++ ++ def GetExp(self): ++ '''Obtain a regular expression that will find substitution keys in text. ++ ++ Create and cache if the substituter has been updated. Use the cached value ++ otherwise. Keys will be enclosed in [square brackets] in text. ++ ++ Returns: ++ A regular expression object. ++ ''' ++ if self.dirty_: ++ components = [r'\[%s\]' % (k,) for k in self.substitutions_] ++ self.exp = re.compile(r'(%s)' % ('|'.join(components),)) ++ self.dirty_ = False ++ return self.exp ++ ++ def Substitute(self, text): ++ '''Substitute the variable values in the given text. ++ ++ Text of the form [message_name] will be replaced by the message's value. ++ ++ Args: ++ text: A string of text. ++ ++ Returns: ++ A string of text with substitutions done. ++ ''' ++ return ''.join([self._SubFragment(f) for f in self.GetExp().split(text)]) ++ ++ def _SubFragment(self, fragment): ++ '''Utility function for Substitute. ++ ++ Performs a simple substitution if the fragment is exactly of the form ++ [message_name]. ++ ++ Args: ++ fragment: A simple string. ++ ++ Returns: ++ A string with the substitution done. ++ ''' ++ if len(fragment) > 2 and fragment[0] == '[' and fragment[-1] == ']': ++ sub = self.substitutions_.get(fragment[1:-1], None) ++ if sub is not None: ++ return sub ++ return fragment ++ ++ def SubstituteMessage(self, msg): ++ '''Apply substitutions to a tclib.Message object. ++ ++ Text of the form [message_name] will be replaced by a new placeholder, ++ whose presentation will take the form the message_name_{UsageCount}, and ++ whose example will be the message's value. Existing placeholders are ++ not affected. ++ ++ Args: ++ msg: A tclib.Message object. ++ ++ Returns: ++ A tclib.Message object, with substitutions done. ++ ''' ++ from grit import tclib # avoid circular import ++ counts = {} ++ text = msg.GetPresentableContent() ++ placeholders = [] ++ newtext = '' ++ for f in self.GetExp().split(text): ++ sub = self._SubFragment(f) ++ if f != sub: ++ f = str(f) ++ count = counts.get(f, 0) + 1 ++ counts[f] = count ++ name = "%s_%d" % (f[1:-1], count) ++ placeholders.append(tclib.Placeholder(name, f, sub)) ++ newtext += name ++ else: ++ newtext += f ++ if placeholders: ++ return tclib.Message(newtext, msg.GetPlaceholders() + placeholders, ++ msg.GetDescription(), msg.GetMeaning()) ++ else: ++ return msg ++ ++ ++class TempDir(object): ++ '''Creates files with the specified contents in a temporary directory, ++ for unit testing. ++ ''' ++ ++ def __init__(self, file_data, mode='w'): ++ self._tmp_dir_name = tempfile.mkdtemp() ++ assert not os.listdir(self.GetPath()) ++ for name, contents in file_data.items(): ++ file_path = self.GetPath(name) ++ dir_path = os.path.split(file_path)[0] ++ if not os.path.exists(dir_path): ++ os.makedirs(dir_path) ++ with open(file_path, mode) as f: ++ f.write(file_data[name]) ++ ++ def __enter__(self): ++ return self ++ ++ def __exit__(self, *exc_info): ++ self.CleanUp() ++ ++ def CleanUp(self): ++ shutil.rmtree(self.GetPath()) ++ ++ def GetPath(self, name=''): ++ name = os.path.join(self._tmp_dir_name, name) ++ assert name.startswith(self._tmp_dir_name) ++ return name ++ ++ def AsCurrentDir(self): ++ return self._AsCurrentDirClass(self.GetPath()) ++ ++ class _AsCurrentDirClass(object): ++ def __init__(self, path): ++ self.path = path ++ def __enter__(self): ++ self.oldpath = os.getcwd() ++ os.chdir(self.path) ++ def __exit__(self, *exc_info): ++ os.chdir(self.oldpath) +diff --git a/tools/grit/grit/util_unittest.py b/tools/grit/grit/util_unittest.py +new file mode 100644 +index 0000000000..7d6efaf858 +--- /dev/null ++++ b/tools/grit/grit/util_unittest.py +@@ -0,0 +1,118 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit test that checks some of util functions. ++''' ++ ++from __future__ import print_function ++ ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '..')) ++ ++import unittest ++ ++import six ++ ++from grit import util ++ ++ ++class UtilUnittest(unittest.TestCase): ++ ''' Tests functions from util ++ ''' ++ ++ def testNewClassInstance(self): ++ # Test short class name with no fully qualified package name ++ # Should fail, it is not supported by the function now (as documented) ++ cls = util.NewClassInstance('grit.util.TestClassToLoad', ++ TestBaseClassToLoad) ++ self.failUnless(cls == None) ++ ++ # Test non existent class name ++ cls = util.NewClassInstance('grit.util_unittest.NotExistingClass', ++ TestBaseClassToLoad) ++ self.failUnless(cls == None) ++ ++ # Test valid class name and valid base class ++ cls = util.NewClassInstance('grit.util_unittest.TestClassToLoad', ++ TestBaseClassToLoad) ++ self.failUnless(isinstance(cls, TestBaseClassToLoad)) ++ ++ # Test valid class name with wrong hierarchy ++ cls = util.NewClassInstance('grit.util_unittest.TestClassNoBase', ++ TestBaseClassToLoad) ++ self.failUnless(cls == None) ++ ++ def testCanonicalLanguage(self): ++ self.failUnless(util.CanonicalLanguage('en') == 'en') ++ self.failUnless(util.CanonicalLanguage('pt_br') == 'pt-BR') ++ self.failUnless(util.CanonicalLanguage('pt-br') == 'pt-BR') ++ self.failUnless(util.CanonicalLanguage('pt-BR') == 'pt-BR') ++ self.failUnless(util.CanonicalLanguage('pt/br') == 'pt-BR') ++ self.failUnless(util.CanonicalLanguage('pt/BR') == 'pt-BR') ++ self.failUnless(util.CanonicalLanguage('no_no_bokmal') == 'no-NO-BOKMAL') ++ ++ def testUnescapeHtml(self): ++ self.failUnless(util.UnescapeHtml('ϲ') == six.unichr(1010)) ++ self.failUnless(util.UnescapeHtml('ꯍ') == six.unichr(43981)) ++ ++ def testRelativePath(self): ++ """ Verify that MakeRelativePath works in some tricky cases.""" ++ ++ def TestRelativePathCombinations(base_path, other_path, expected_result): ++ """ Verify that the relative path function works for ++ the given paths regardless of whether or not they end with ++ a trailing slash.""" ++ for path1 in [base_path, base_path + os.path.sep]: ++ for path2 in [other_path, other_path + os.path.sep]: ++ result = util.MakeRelativePath(path1, path2) ++ self.failUnless(result == expected_result) ++ ++ # set-up variables ++ root_dir = 'c:%sa' % os.path.sep ++ result1 = '..%sabc' % os.path.sep ++ path1 = root_dir + 'bc' ++ result2 = 'bc' ++ path2 = '%s%s%s' % (root_dir, os.path.sep, result2) ++ # run the tests ++ TestRelativePathCombinations(root_dir, path1, result1) ++ TestRelativePathCombinations(root_dir, path2, result2) ++ ++ def testReadFile(self): ++ def Test(data, encoding, expected_result): ++ with open('testfile', 'wb') as f: ++ f.write(data) ++ self.assertEqual(util.ReadFile('testfile', encoding), expected_result) ++ ++ test_std_newline = b'\xEF\xBB\xBFabc\ndef' # EF BB BF is UTF-8 BOM ++ newlines = [b'\n', b'\r\n', b'\r'] ++ ++ with util.TempDir({}) as tmp_dir: ++ with tmp_dir.AsCurrentDir(): ++ for newline in newlines: ++ test = test_std_newline.replace(b'\n', newline) ++ Test(test, util.BINARY, test) ++ # utf-8 doesn't strip BOM ++ Test(test, 'utf-8', test_std_newline.decode('utf-8')) ++ # utf-8-sig strips BOM ++ Test(test, 'utf-8-sig', test_std_newline.decode('utf-8')[1:]) ++ # test another encoding ++ Test(test, 'cp1252', test_std_newline.decode('cp1252')) ++ self.assertRaises(UnicodeDecodeError, Test, b'\x80', 'utf-8', None) ++ ++ ++class TestBaseClassToLoad(object): ++ pass ++ ++class TestClassToLoad(TestBaseClassToLoad): ++ pass ++ ++class TestClassNoBase(object): ++ pass ++ ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit/xtb_reader.py b/tools/grit/grit/xtb_reader.py +new file mode 100644 +index 0000000000..e0f842588a +--- /dev/null ++++ b/tools/grit/grit/xtb_reader.py +@@ -0,0 +1,140 @@ ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Fast and efficient parser for XTB files. ++''' ++ ++from __future__ import print_function ++ ++import sys ++import xml.sax ++import xml.sax.handler ++ ++import grit.node.base ++ ++ ++class XtbContentHandler(xml.sax.handler.ContentHandler): ++ '''A content handler that calls a given callback function for each ++ translation in the XTB file. ++ ''' ++ ++ def __init__(self, callback, defs=None, debug=False, target_platform=None): ++ self.callback = callback ++ self.debug = debug ++ # 0 if we are not currently parsing a translation, otherwise the message ++ # ID of that translation. ++ self.current_id = 0 ++ # Empty if we are not currently parsing a translation, otherwise the ++ # parts we have for that translation - a list of tuples ++ # (is_placeholder, text) ++ self.current_structure = [] ++ # Set to the language ID when we see the <translationbundle> node. ++ self.language = '' ++ # Keep track of the if block we're inside. We can't nest ifs. ++ self.if_expr = None ++ # Root defines to be used with if expr. ++ if defs: ++ self.defines = defs ++ else: ++ self.defines = {} ++ # Target platform for build. ++ if target_platform: ++ self.target_platform = target_platform ++ else: ++ self.target_platform = sys.platform ++ ++ def startElement(self, name, attrs): ++ if name == 'translation': ++ assert self.current_id == 0 and len(self.current_structure) == 0, ( ++ "Didn't expect a <translation> element here.") ++ self.current_id = attrs.getValue('id') ++ elif name == 'ph': ++ assert self.current_id != 0, "Didn't expect a <ph> element here." ++ self.current_structure.append((True, attrs.getValue('name'))) ++ elif name == 'translationbundle': ++ self.language = attrs.getValue('lang') ++ elif name in ('if', 'then', 'else'): ++ assert self.if_expr is None, "Can't nest <if> or use <else> in xtb files" ++ self.if_expr = attrs.getValue('expr') ++ ++ def endElement(self, name): ++ if name == 'translation': ++ assert self.current_id != 0 ++ ++ defs = self.defines ++ def pp_ifdef(define): ++ return define in defs ++ def pp_if(define): ++ return define in defs and defs[define] ++ ++ # If we're in an if block, only call the callback (add the translation) ++ # if the expression is True. ++ should_run_callback = True ++ if self.if_expr: ++ should_run_callback = grit.node.base.Node.EvaluateExpression( ++ self.if_expr, self.defines, self.target_platform) ++ if should_run_callback: ++ self.callback(self.current_id, self.current_structure) ++ ++ self.current_id = 0 ++ self.current_structure = [] ++ elif name == 'if': ++ assert self.if_expr is not None ++ self.if_expr = None ++ ++ def characters(self, content): ++ if self.current_id != 0: ++ # We are inside a <translation> node so just add the characters to our ++ # structure. ++ # ++ # This naive way of handling characters is OK because in the XTB format, ++ # <ph> nodes are always empty (always <ph name="XXX"/>) and whitespace ++ # inside the <translation> node should be preserved. ++ self.current_structure.append((False, content)) ++ ++ ++class XtbErrorHandler(xml.sax.handler.ErrorHandler): ++ def error(self, exception): ++ pass ++ ++ def fatalError(self, exception): ++ raise exception ++ ++ def warning(self, exception): ++ pass ++ ++ ++def Parse(xtb_file, callback_function, defs=None, debug=False, ++ target_platform=None): ++ '''Parse xtb_file, making a call to callback_function for every translation ++ in the XTB file. ++ ++ The callback function must have the signature as described below. The 'parts' ++ parameter is a list of tuples (is_placeholder, text). The 'text' part is ++ either the raw text (if is_placeholder is False) or the name of the placeholder ++ (if is_placeholder is True). ++ ++ Args: ++ xtb_file: open('fr.xtb', 'rb') ++ callback_function: def Callback(msg_id, parts): pass ++ defs: None, or a dictionary of preprocessor definitions. ++ debug: Default False. Set True for verbose debug output. ++ target_platform: None, or a sys.platform-like identifier of the build ++ target platform. ++ ++ Return: ++ The language of the XTB, e.g. 'fr' ++ ''' ++ # Start by advancing the file pointer past the DOCTYPE thing, as the TC ++ # uses a path to the DTD that only works in Unix. ++ # TODO(joi) Remove this ugly hack by getting the TC gang to change the ++ # XTB files somehow? ++ front_of_file = xtb_file.read(1024) ++ xtb_file.seek(front_of_file.find(b'<translationbundle')) ++ ++ handler = XtbContentHandler(callback=callback_function, defs=defs, ++ debug=debug, target_platform=target_platform) ++ xml.sax.parse(xtb_file, handler) ++ assert handler.language != '' ++ return handler.language +diff --git a/tools/grit/grit/xtb_reader_unittest.py b/tools/grit/grit/xtb_reader_unittest.py +new file mode 100644 +index 0000000000..79c0ac9ef1 +--- /dev/null ++++ b/tools/grit/grit/xtb_reader_unittest.py +@@ -0,0 +1,110 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Unit tests for grit.xtb_reader''' ++ ++from __future__ import print_function ++ ++import io ++import os ++import sys ++if __name__ == '__main__': ++ sys.path.append(os.path.join(os.path.dirname(__file__), '..')) ++ ++import unittest ++ ++from grit import util ++from grit import xtb_reader ++from grit.node import empty ++ ++ ++class XtbReaderUnittest(unittest.TestCase): ++ def testParsing(self): ++ xtb_file = io.BytesIO(b'''<?xml version="1.0" encoding="UTF-8"?> ++ <!DOCTYPE translationbundle> ++ <translationbundle lang="fr"> ++ <translation id="5282608565720904145">Bingo.</translation> ++ <translation id="2955977306445326147">Bongo longo.</translation> ++ <translation id="238824332917605038">Hullo</translation> ++ <translation id="6629135689895381486"><ph name="PROBLEM_REPORT"/> peut <ph name="START_LINK"/>utilisation excessive de majuscules<ph name="END_LINK"/>.</translation> ++ <translation id="7729135689895381486">Hello ++this is another line ++and another ++ ++and another after a blank line.</translation> ++ </translationbundle>''') ++ ++ messages = [] ++ def Callback(id, structure): ++ messages.append((id, structure)) ++ xtb_reader.Parse(xtb_file, Callback) ++ self.failUnless(len(messages[0][1]) == 1) ++ self.failUnless(messages[3][1][0]) # PROBLEM_REPORT placeholder ++ self.failUnless(messages[4][0] == '7729135689895381486') ++ self.failUnless(messages[4][1][7][1] == 'and another after a blank line.') ++ ++ def testParsingIntoMessages(self): ++ root = util.ParseGrdForUnittest(''' ++ <messages> ++ <message name="ID_MEGA">Fantastic!</message> ++ <message name="ID_HELLO_USER">Hello <ph name="USERNAME">%s<ex>Joi</ex></ph></message> ++ </messages>''') ++ ++ msgs, = root.GetChildrenOfType(empty.MessagesNode) ++ clique_mega = msgs.children[0].GetCliques()[0] ++ msg_mega = clique_mega.GetMessage() ++ clique_hello_user = msgs.children[1].GetCliques()[0] ++ msg_hello_user = clique_hello_user.GetMessage() ++ ++ xtb_file = io.BytesIO(b'''<?xml version="1.0" encoding="UTF-8"?> ++ <!DOCTYPE translationbundle> ++ <translationbundle lang="is"> ++ <translation id="%s">Meirihattar!</translation> ++ <translation id="%s">Saelir <ph name="USERNAME"/></translation> ++ </translationbundle>''' % ( ++ msg_mega.GetId().encode('utf-8'), ++ msg_hello_user.GetId().encode('utf-8'))) ++ ++ xtb_reader.Parse(xtb_file, ++ msgs.UberClique().GenerateXtbParserCallback('is')) ++ self.assertEqual('Meirihattar!', ++ clique_mega.MessageForLanguage('is').GetRealContent()) ++ self.failUnless('Saelir %s', ++ clique_hello_user.MessageForLanguage('is').GetRealContent()) ++ ++ def testIfNodesWithUseNameForId(self): ++ root = util.ParseGrdForUnittest(''' ++ <messages> ++ <message name="ID_BINGO" use_name_for_id="true">Bingo!</message> ++ </messages>''') ++ msgs, = root.GetChildrenOfType(empty.MessagesNode) ++ clique = msgs.children[0].GetCliques()[0] ++ msg = clique.GetMessage() ++ ++ xtb_file = io.BytesIO(b'''<?xml version="1.0" encoding="UTF-8"?> ++ <!DOCTYPE translationbundle> ++ <translationbundle lang="is"> ++ <if expr="is_linux"> ++ <translation id="ID_BINGO">Bongo!</translation> ++ </if> ++ <if expr="not is_linux"> ++ <translation id="ID_BINGO">Congo!</translation> ++ </if> ++ </translationbundle>''') ++ xtb_reader.Parse(xtb_file, ++ msgs.UberClique().GenerateXtbParserCallback('is'), ++ target_platform='darwin') ++ self.assertEqual('Congo!', clique.MessageForLanguage('is').GetRealContent()) ++ ++ def testParseLargeFile(self): ++ def Callback(id, structure): ++ pass ++ path = util.PathFromRoot('grit/testdata/generated_resources_fr.xtb') ++ with open(path, 'rb') as xtb: ++ xtb_reader.Parse(xtb, Callback) ++ ++ ++if __name__ == '__main__': ++ unittest.main() +diff --git a/tools/grit/grit_info.py b/tools/grit/grit_info.py +new file mode 100644 +index 0000000000..55738f25f6 +--- /dev/null ++++ b/tools/grit/grit_info.py +@@ -0,0 +1,173 @@ ++#!/usr/bin/env python ++# Copyright (c) 2012 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++'''Tool to determine inputs and outputs of a grit file. ++''' ++ ++from __future__ import print_function ++ ++import optparse ++import os ++import posixpath ++import sys ++ ++from grit import grd_reader ++from grit import util ++ ++class WrongNumberOfArguments(Exception): ++ pass ++ ++ ++def Outputs(filename, defines, ids_file, target_platform=None): ++ grd = grd_reader.Parse( ++ filename, defines=defines, tags_to_ignore=set(['messages']), ++ first_ids_file=ids_file, target_platform=target_platform) ++ ++ target = [] ++ lang_folders = {} ++ # Add all explicitly-specified output files ++ for output in grd.GetOutputFiles(): ++ path = output.GetFilename() ++ target.append(path) ++ ++ if path.endswith('.h'): ++ path, filename = os.path.split(path) ++ if output.attrs['lang']: ++ lang_folders[output.attrs['lang']] = os.path.dirname(path) ++ ++ return [t.replace('\\', '/') for t in target] ++ ++ ++def GritSourceFiles(): ++ files = [] ++ grit_root_dir = os.path.relpath(os.path.dirname(__file__), os.getcwd()) ++ for root, dirs, filenames in os.walk(grit_root_dir): ++ grit_src = [os.path.join(root, f) for f in filenames ++ if f.endswith('.py') and not f.endswith('_unittest.py')] ++ files.extend(grit_src) ++ return sorted(files) ++ ++ ++def Inputs(filename, defines, ids_file, target_platform=None): ++ grd = grd_reader.Parse( ++ filename, debug=False, defines=defines, tags_to_ignore=set(['message']), ++ first_ids_file=ids_file, target_platform=target_platform) ++ files = set() ++ for lang, ctx, fallback in grd.GetConfigurations(): ++ # TODO(tdanderson): Refactor all places which perform the action of setting ++ # output attributes on the root. See crbug.com/503637. ++ grd.SetOutputLanguage(lang or grd.GetSourceLanguage()) ++ grd.SetOutputContext(ctx) ++ grd.SetFallbackToDefaultLayout(fallback) ++ for node in grd.ActiveDescendants(): ++ with node: ++ if (node.name == 'structure' or node.name == 'skeleton' or ++ (node.name == 'file' and node.parent and ++ node.parent.name == 'translations')): ++ path = node.GetInputPath() ++ if path is not None: ++ files.add(grd.ToRealPath(path)) ++ ++ # If it's a flattened node, grab inlined resources too. ++ if node.name == 'structure' and node.attrs['flattenhtml'] == 'true': ++ node.RunPreSubstitutionGatherer() ++ files.update(node.GetHtmlResourceFilenames()) ++ elif node.name == 'grit': ++ first_ids_file = node.GetFirstIdsFile() ++ if first_ids_file: ++ files.add(first_ids_file) ++ elif node.name == 'include': ++ files.add(grd.ToRealPath(node.GetInputPath())) ++ # If it's a flattened node, grab inlined resources too. ++ if node.attrs['flattenhtml'] == 'true': ++ files.update(node.GetHtmlResourceFilenames()) ++ elif node.name == 'part': ++ files.add(util.normpath(os.path.join(os.path.dirname(filename), ++ node.GetInputPath()))) ++ ++ cwd = os.getcwd() ++ return [os.path.relpath(f, cwd) for f in sorted(files)] ++ ++ ++def PrintUsage(): ++ print('USAGE: ./grit_info.py --inputs [-D foo] [-f resource_ids] <grd-file>') ++ print(' ./grit_info.py --outputs [-D foo] [-f resource_ids] ' + ++ '<out-prefix> <grd-file>') ++ ++ ++def DoMain(argv): ++ os.environ['cwd'] = os.getcwd() ++ ++ parser = optparse.OptionParser() ++ parser.add_option("--inputs", action="store_true", dest="inputs") ++ parser.add_option("--outputs", action="store_true", dest="outputs") ++ parser.add_option("-D", action="append", dest="defines", default=[]) ++ # grit build also supports '-E KEY=VALUE', support that to share command ++ # line flags. ++ parser.add_option("-E", action="append", dest="build_env", default=[]) ++ parser.add_option("-p", action="store", dest="predetermined_ids_file") ++ parser.add_option("-w", action="append", dest="whitelist_files", default=[]) ++ parser.add_option("-f", dest="ids_file", default="") ++ parser.add_option("-t", dest="target_platform", default=None) ++ ++ options, args = parser.parse_args(argv) ++ ++ defines = {} ++ for define in options.defines: ++ name, val = util.ParseDefine(define) ++ defines[name] = val ++ ++ for env_pair in options.build_env: ++ (env_name, env_value) = env_pair.split('=', 1) ++ os.environ[env_name] = env_value ++ ++ if options.inputs: ++ if len(args) > 1: ++ raise WrongNumberOfArguments("Expected 0 or 1 arguments for --inputs.") ++ ++ inputs = [] ++ if len(args) == 1: ++ filename = args[0] ++ inputs = Inputs(filename, defines, options.ids_file, ++ options.target_platform) ++ ++ # Add in the grit source files. If one of these change, we want to re-run ++ # grit. ++ inputs.extend(GritSourceFiles()) ++ inputs = [f.replace('\\', '/') for f in inputs] ++ ++ if len(args) == 1: ++ # Include grd file as second input (works around gyp expecting it). ++ inputs.insert(1, args[0]) ++ if options.whitelist_files: ++ inputs.extend(options.whitelist_files) ++ return '\n'.join(inputs) ++ elif options.outputs: ++ if len(args) != 2: ++ raise WrongNumberOfArguments( ++ "Expected exactly 2 arguments for --outputs.") ++ ++ prefix, filename = args ++ outputs = [posixpath.join(prefix, f) ++ for f in Outputs(filename, defines, ++ options.ids_file, options.target_platform)] ++ return '\n'.join(outputs) ++ else: ++ raise WrongNumberOfArguments("Expected --inputs or --outputs.") ++ ++ ++def main(argv): ++ try: ++ result = DoMain(argv[1:]) ++ except WrongNumberOfArguments as e: ++ PrintUsage() ++ print(e) ++ return 1 ++ print(result) ++ return 0 ++ ++ ++if __name__ == '__main__': ++ sys.exit(main(sys.argv)) +diff --git a/tools/grit/grit_rule.gni b/tools/grit/grit_rule.gni +new file mode 100644 +index 0000000000..fb107ef1a3 +--- /dev/null ++++ b/tools/grit/grit_rule.gni +@@ -0,0 +1,485 @@ ++# Copyright 2014 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++# Instantiate grit. This will produce a script target to run grit (named ++# ${target_name}_grit), and a static library that compiles the .cc files. ++# ++# In general, code should depend on the static library. However, if the ++# generated files are only processed by other actions to generate other ++# files, it is possible to depend on the script target directly. ++# ++# Parameters ++# ++# source (required) ++# Path to .grd file. ++# ++# enable_input_discovery_for_gn_analyze (default=true) ++# Runs grit_info.py via exec_script() when compute_inputs_for_analyze=true ++# in order to discover all files that affect this target. ++# Turn this off when the .grd file is generated, or an <include> with ++# flattenhtml=true points to a generated file. ++# For "gn analyze" to be correct with this arg disabled, all inputs ++# must be listed via |inputs|. ++# ++# inputs (optional) ++# List of additional files, required for grit to process source file. ++# ++# outputs (required) ++# List of outputs from grit, relative to the target_gen_dir. Grit will ++# verify at build time that this list is correct and will fail if there ++# is a mismatch between the outputs specified by the .grd file and the ++# outputs list here. ++# ++# To get this list, you can look in the .grd file for ++# <output filename="..." and put those filename here. The base directory ++# of the list in Grit and the output list specified in the GN grit target ++# are the same (the target_gen_dir) so you can generally copy the names ++# exactly. ++# ++# To get the list of outputs programatically, run: ++# python tools/grit/grit_info.py --outputs . path/to/your.grd ++# And strip the leading "./" from the output files. ++# ++# defines (optional) ++# Extra defines to pass to grit (on top of the global grit_defines list). ++# ++# grit_flags (optional) ++# List of strings containing extra command-line flags to pass to Grit. ++# ++# resource_ids (optional) ++# Path to a grit "firstidsfile". Default is ++# //tools/gritsettings/resource_ids. Set to "" to use the value specified ++# in the <grit> nodes of the processed files. ++# ++# output_dir (optional) ++# Directory for generated files. If you specify this, you will often ++# want to specify output_name if the target name is not particularly ++# unique, since this can cause files from multiple grit targets to ++# overwrite each other. ++# ++# output_name (optional) ++# Provide an alternate base name for the generated files, like the .d ++# files. Normally these are based on the target name and go in the ++# output_dir, but if multiple targets with the same name end up in ++# the same output_dir, they can collide. ++# ++# configs (optional) ++# List of additional configs to be applied to the generated target. ++# ++# deps (optional) ++# testonly (optional) ++# visibility (optional) ++# Normal meaning. ++# ++# Example ++# ++# grit("my_resources") { ++# # Source and outputs are required. ++# source = "myfile.grd" ++# outputs = [ ++# "foo_strings.h", ++# "foo_strings.pak", ++# ] ++# ++# grit_flags = [ "-E", "foo=bar" ] # Optional extra flags. ++# # You can also put deps here if the grit source depends on generated ++# # files. ++# } ++import("//build/config/chrome_build.gni") ++import("//build/config/chromeos/ui_mode.gni") ++import("//build/config/compiler/compiler.gni") ++import("//build/config/compute_inputs_for_analyze.gni") ++import("//build/config/crypto.gni") ++import("//build/config/features.gni") ++import("//build/config/sanitizers/sanitizers.gni") ++import("//build/config/ui.gni") ++import("//build/toolchain/gcc_toolchain.gni") ++ ++declare_args() { ++ enable_resource_whitelist_generation = is_android && is_official_build ++} ++ ++if (enable_resource_whitelist_generation) { ++ assert(target_os == "android" || target_os == "win", ++ "unsupported platform for resource whitelist generation") ++ assert( ++ symbol_level > 0 && !strip_debug_info && !is_component_build, ++ "resource whitelist generation only works on non-component builds with debug info enabled.") ++} ++ ++grit_defines = [] ++ ++if (is_mac || is_win || is_linux || is_chromeos || is_ios) { ++ grit_defines += [ ++ "-D", ++ "scale_factors=2x", ++ ] ++} ++ ++# Mac and iOS want Title Case strings. ++use_titlecase_in_grd_files = is_apple ++if (use_titlecase_in_grd_files) { ++ grit_defines += [ ++ "-D", ++ "use_titlecase", ++ ] ++} ++ ++if (is_chrome_branded) { ++ grit_defines += [ ++ "-D", ++ "_google_chrome", ++ "-E", ++ "CHROMIUM_BUILD=google_chrome", ++ ] ++} else { ++ grit_defines += [ ++ "-D", ++ "_chromium", ++ "-E", ++ "CHROMIUM_BUILD=chromium", ++ ] ++} ++ ++if (is_chromeos) { ++ grit_defines += [ ++ "-D", ++ "chromeos", ++ ] ++} ++ ++if (chromeos_is_browser_only) { ++ grit_defines += [ ++ "-D", ++ "lacros", ++ ] ++} ++ ++if (is_desktop_linux) { ++ grit_defines += [ ++ "-D", ++ "desktop_linux", ++ ] ++} ++ ++if (toolkit_views) { ++ grit_defines += [ ++ "-D", ++ "toolkit_views", ++ ] ++} ++ ++if (use_aura) { ++ grit_defines += [ ++ "-D", ++ "use_aura", ++ ] ++} ++ ++if (use_nss_certs) { ++ grit_defines += [ ++ "-D", ++ "use_nss_certs", ++ ] ++} ++ ++if (use_ozone) { ++ grit_defines += [ ++ "-D", ++ "use_ozone", ++ ] ++} ++ ++if (is_android) { ++ grit_defines += [ ++ "-E", ++ "ANDROID_JAVA_TAGGED_ONLY=true", ++ ] ++} ++ ++# When cross-compiling, explicitly pass the target system to grit. ++if (current_toolchain != host_toolchain) { ++ if (is_android) { ++ grit_defines += [ ++ "-t", ++ "android", ++ ] ++ } ++ if (is_ios) { ++ grit_defines += [ ++ "-t", ++ "ios", ++ ] ++ } ++ if (is_linux || is_chromeos) { ++ grit_defines += [ ++ "-t", ++ "linux2", ++ ] ++ } ++ if (is_mac) { ++ grit_defines += [ ++ "-t", ++ "darwin", ++ ] ++ } ++ if (is_win) { ++ grit_defines += [ ++ "-t", ++ "win32", ++ ] ++ } ++} ++ ++_strip_resource_files = is_android && is_official_build ++_js_minifier = "//tools/grit/minify_with_uglify.py" ++_css_minifier = "//tools/grit/minimize_css.py" ++ ++grit_resource_id_target = "//tools/gritsettings:default_resource_ids" ++grit_resource_id_file = ++ get_label_info(grit_resource_id_target, "target_gen_dir") + ++ "/default_resource_ids" ++grit_info_script = "//tools/grit/grit_info.py" ++ ++# TODO(asvitkine): Add predetermined ids files for other platforms. ++grit_predetermined_resource_ids_file = "" ++if (is_mac) { ++ grit_predetermined_resource_ids_file = ++ "//tools/gritsettings/startup_resources_mac.txt" ++} ++if (is_win) { ++ grit_predetermined_resource_ids_file = ++ "//tools/gritsettings/startup_resources_win.txt" ++} ++ ++template("grit") { ++ if (defined(invoker.output_dir)) { ++ _output_dir = invoker.output_dir ++ } else { ++ _output_dir = target_gen_dir ++ } ++ ++ _grit_outputs = ++ get_path_info(rebase_path(invoker.outputs, ".", _output_dir), "abspath") ++ ++ # Add .info output for all pak files ++ _pak_info_outputs = [] ++ foreach(output, _grit_outputs) { ++ if (get_path_info(output, "extension") == "pak") { ++ _pak_info_outputs += [ output + ".info" ] ++ } ++ } ++ ++ if (defined(invoker.output_name)) { ++ _grit_output_name = invoker.output_name ++ } else { ++ _grit_output_name = target_name ++ } ++ ++ _grit_custom_target = target_name + "_grit" ++ action(_grit_custom_target) { ++ testonly = defined(invoker.testonly) && invoker.testonly ++ ++ script = "//tools/grit/grit.py" ++ depfile = "$target_gen_dir/$target_name.d" ++ ++ inputs = [ invoker.source ] ++ deps = [ "//tools/grit:grit_sources" ] ++ outputs = [ "${depfile}.stamp" ] + _grit_outputs + _pak_info_outputs ++ ++ _grit_flags = grit_defines ++ ++ # Add extra defines with -D flags. ++ if (defined(invoker.defines)) { ++ foreach(i, invoker.defines) { ++ _grit_flags += [ ++ "-D", ++ i, ++ ] ++ } ++ } ++ ++ if (defined(invoker.grit_flags)) { ++ _grit_flags += invoker.grit_flags ++ } ++ ++ _rebased_source_path = rebase_path(invoker.source, root_build_dir) ++ _enable_grit_info = ++ !defined(invoker.enable_input_discovery_for_gn_analyze) || ++ invoker.enable_input_discovery_for_gn_analyze ++ if (_enable_grit_info && compute_inputs_for_analyze) { ++ # Only call exec_script when the user has explicitly opted into greater ++ # precision at the expense of performance. ++ _rel_inputs = exec_script("//tools/grit/grit_info.py", ++ [ ++ "--inputs", ++ _rebased_source_path, ++ ] + _grit_flags, ++ "list lines") ++ inputs += rebase_path(_rel_inputs, ".", root_build_dir) ++ } ++ ++ args = [ ++ "-i", ++ _rebased_source_path, ++ "build", ++ "-o", ++ rebase_path(_output_dir, root_build_dir), ++ "--depdir", ++ ".", ++ "--depfile", ++ rebase_path(depfile, root_build_dir), ++ "--write-only-new=1", ++ "--depend-on-stamp", ++ ] + _grit_flags ++ ++ # Add brotli executable if using brotli. ++ if (defined(invoker.use_brotli) && invoker.use_brotli) { ++ _brotli_target = "//third_party/brotli:brotli($host_toolchain)" ++ _brotli_executable = get_label_info(_brotli_target, "root_out_dir") + ++ "/" + get_label_info(_brotli_target, "name") ++ if (host_os == "win") { ++ _brotli_executable += ".exe" ++ } ++ ++ inputs += [ _brotli_executable ] ++ args += [ ++ "--brotli", ++ rebase_path(_brotli_executable, root_build_dir), ++ ] ++ } ++ ++ _resource_ids = grit_resource_id_file ++ if (defined(invoker.resource_ids)) { ++ _resource_ids = invoker.resource_ids ++ } ++ ++ if (_resource_ids != "") { ++ inputs += [ _resource_ids ] ++ args += [ ++ "-f", ++ rebase_path(_resource_ids, root_build_dir), ++ ] ++ if (_resource_ids == grit_resource_id_file) { ++ deps += [ grit_resource_id_target ] ++ } ++ } ++ if (grit_predetermined_resource_ids_file != "") { ++ inputs += [ grit_predetermined_resource_ids_file ] ++ args += [ ++ "-p", ++ rebase_path(grit_predetermined_resource_ids_file, root_build_dir), ++ ] ++ } ++ ++ # We want to make sure the declared outputs actually match what Grit is ++ # writing. We write the list to a file (some of the output lists are long ++ # enough to not fit on a Windows command line) and ask Grit to verify those ++ # are the actual outputs at runtime. ++ _asserted_list_file = ++ "$target_out_dir/${_grit_output_name}_expected_outputs.txt" ++ write_file(_asserted_list_file, ++ rebase_path(invoker.outputs, root_build_dir, _output_dir)) ++ inputs += [ _asserted_list_file ] ++ args += [ ++ "--assert-file-list", ++ rebase_path(_asserted_list_file, root_build_dir), ++ ] ++ ++ if (enable_resource_whitelist_generation) { ++ _rc_grit_outputs = [] ++ foreach(output, _grit_outputs) { ++ if (get_path_info(output, "extension") == "rc") { ++ _rc_grit_outputs += [ output ] ++ } ++ } ++ ++ if (_rc_grit_outputs != []) { ++ # Resource whitelisting cannot be used with .rc files. ++ # Make sure that there aren't any .pak outputs which would require ++ # whitelist annotations. ++ assert(_pak_info_outputs == [], "can't combine .pak and .rc outputs") ++ } else { ++ args += [ "--whitelist-support" ] ++ } ++ } ++ if (_strip_resource_files) { ++ _js_minifier_command = rebase_path(_js_minifier, root_build_dir) ++ _css_minifier_command = rebase_path(_css_minifier, root_build_dir) ++ args += [ ++ "--js-minifier", ++ _js_minifier_command, ++ "--css-minifier", ++ _css_minifier_command, ++ ] ++ inputs += [ ++ _js_minifier, ++ _css_minifier, ++ ] ++ } ++ ++ if (defined(invoker.visibility)) { ++ # This needs to include both what the invoker specified (since they ++ # probably include generated headers from this target), as well as the ++ # generated source set (since there's no guarantee that the visibility ++ # specified by the invoker includes our target). ++ # ++ # Only define visibility at all if the invoker specified it. Otherwise, ++ # we want to keep the public "no visibility specified" default. ++ visibility = [ ":${invoker.target_name}" ] + invoker.visibility ++ } ++ ++ if (defined(invoker.use_brotli) && invoker.use_brotli) { ++ if (is_mac && is_asan) { ++ deps += [ "//tools/grit:brotli_mac_asan_workaround" ] ++ } else { ++ deps += [ "//third_party/brotli:brotli($host_toolchain)" ] ++ } ++ } ++ if (defined(invoker.deps)) { ++ deps += invoker.deps ++ } ++ if (defined(invoker.inputs)) { ++ inputs += invoker.inputs ++ } ++ } ++ ++ # This is the thing that people actually link with, it must be named the ++ # same as the argument the template was invoked with. ++ source_set(target_name) { ++ testonly = defined(invoker.testonly) && invoker.testonly ++ ++ # Since we generate a file, we need to be run before the targets that ++ # depend on us. ++ sources = [] ++ foreach(_output, _grit_outputs) { ++ _extension = get_path_info(_output, "extension") ++ if (_extension != "json" && _extension != "gz" && _extension != "pak" && ++ _extension != "xml") { ++ sources += [ _output ] ++ } ++ } ++ ++ # Deps set on the template invocation will go on the action that runs ++ # grit above rather than this library. This target needs to depend on the ++ # action publicly so other scripts can take the outputs from the grit ++ # script as inputs. ++ public_deps = [ ":$_grit_custom_target" ] ++ ++ deps = [ "//base" ] ++ ++ if (defined(invoker.public_configs)) { ++ public_configs += invoker.public_configs ++ } ++ ++ if (defined(invoker.configs)) { ++ configs += invoker.configs ++ } ++ ++ if (defined(invoker.visibility)) { ++ visibility = invoker.visibility ++ } ++ output_name = _grit_output_name ++ } ++} +diff --git a/tools/grit/minify_with_uglify.py b/tools/grit/minify_with_uglify.py +new file mode 100644 +index 0000000000..788ffa6a75 +--- /dev/null ++++ b/tools/grit/minify_with_uglify.py +@@ -0,0 +1,44 @@ ++#!/usr/bin/env python ++# Copyright 2019 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++from __future__ import print_function ++ ++import os ++import sys ++import tempfile ++ ++_HERE_PATH = os.path.dirname(__file__) ++_SRC_PATH = os.path.normpath(os.path.join(_HERE_PATH, '..', '..')) ++sys.path.append(os.path.join(_SRC_PATH, 'third_party', 'node')) ++ ++import node ++import node_modules ++ ++def Minify(source): ++ # Open two temporary files, so that uglify can read the input from one and ++ # write its output to the other. ++ with tempfile.NamedTemporaryFile(suffix='.js') as infile, \ ++ tempfile.NamedTemporaryFile(suffix='.js') as outfile: ++ infile.write(source) ++ infile.flush(); ++ node.RunNode([ ++ node_modules.PathToUglify(), infile.name, '--output', outfile.name]) ++ result = outfile.read() ++ return result ++ ++ ++def main(): ++ orig_stdout = sys.stdout ++ result = '' ++ try: ++ sys.stdout = sys.stderr ++ result = Minify(sys.stdin.read()) ++ finally: ++ sys.stdout = orig_stdout ++ print(result) ++ ++ ++if __name__ == '__main__': ++ main() +diff --git a/tools/grit/minimize_css.py b/tools/grit/minimize_css.py +new file mode 100644 +index 0000000000..2c3b8aeb1e +--- /dev/null ++++ b/tools/grit/minimize_css.py +@@ -0,0 +1,105 @@ ++#!/usr/bin/env python ++# Copyright 2016 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++import re ++import sys ++ ++class CSSMinimizer(object): ++ ++ INITIAL = 0 ++ MAYBE_COMMENT_START = 1 ++ INSIDE_COMMENT = 2 ++ MAYBE_COMMENT_END = 3 ++ INSIDE_SINGLE_QUOTE = 4 ++ INSIDE_SINGLE_QUOTE_ESCAPE = 5 ++ INSIDE_DOUBLE_QUOTE = 6 ++ INSIDE_DOUBLE_QUOTE_ESCAPE = 7 ++ ++ def __init__(self): ++ self._output = '' ++ self._codeblock = '' ++ ++ def flush_codeblock(self): ++ stripped = re.sub(r"\s+", ' ', self._codeblock) ++ stripped = re.sub(r";?\s*(?P<op>[{};])\s*", r'\g<op>', stripped) ++ self._output += stripped ++ self._codeblock = '' ++ ++ def parse(self, content): ++ state = self.INITIAL ++ for char in content: ++ if state == self.INITIAL: ++ if char == '/': ++ state = self.MAYBE_COMMENT_START ++ elif char == "'": ++ self.flush_codeblock() ++ self._output += char ++ state = self.INSIDE_SINGLE_QUOTE ++ elif char == '"': ++ self.flush_codeblock() ++ self._output += char ++ state = self.INSIDE_DOUBLE_QUOTE ++ else: ++ self._codeblock += char ++ elif state == self.MAYBE_COMMENT_START: ++ if char == '*': ++ self.flush_codeblock() ++ state = self.INSIDE_COMMENT ++ else: ++ self._codeblock += '/' + char ++ state = self.INITIAL ++ elif state == self.INSIDE_COMMENT: ++ if char == '*': ++ state = self.MAYBE_COMMENT_END ++ else: ++ pass ++ elif state == self.MAYBE_COMMENT_END: ++ if char == '/': ++ state = self.INITIAL ++ else: ++ state = self.INSIDE_COMMENT ++ elif state == self.INSIDE_SINGLE_QUOTE: ++ if char == '\\': ++ self._output += char ++ state = self.INSIDE_SINGLE_QUOTE_ESCAPE ++ elif char == "'": ++ self._output += char ++ state = self.INITIAL ++ else: ++ self._output += char ++ elif state == self.INSIDE_SINGLE_QUOTE_ESCAPE: ++ self._output += char ++ state = self.INSIDE_SINGLE_QUOTE ++ elif state == self.INSIDE_DOUBLE_QUOTE: ++ if char == '\\': ++ self._output += char ++ state = self.INSIDE_DOUBLE_QUOTE_ESCAPE ++ elif char == '"': ++ self._output += char ++ state = self.INITIAL ++ else: ++ self._output += char ++ elif state == self.INSIDE_DOUBLE_QUOTE_ESCAPE: ++ self._output += char ++ state = self.INSIDE_DOUBLE_QUOTE ++ ++ self.flush_codeblock() ++ self._output = self._output.strip() ++ return self._output ++ ++ @classmethod ++ def minimize_css(cls, content): ++ minimizer = CSSMinimizer() ++ return minimizer.parse(content) ++ ++def main(): ++ result = '' ++ try: ++ result = CSSMinimizer.minimize_css(sys.stdin.read()) ++ finally: ++ print(result) ++ ++if __name__ == '__main__': ++ main() +diff --git a/tools/grit/minimize_css_unittest.py b/tools/grit/minimize_css_unittest.py +new file mode 100644 +index 0000000000..cddc313078 +--- /dev/null ++++ b/tools/grit/minimize_css_unittest.py +@@ -0,0 +1,58 @@ ++#!/usr/bin/env python ++# Copyright 2016 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++import unittest ++ ++import minimize_css ++ ++ ++class CSSMinimizerTest(unittest.TestCase): ++ ++ def test_simple(self): ++ source = """ ++ div { ++ color: blue; ++ } ++ """ ++ minimized = minimize_css.CSSMinimizer.minimize_css(source) ++ self.assertEquals(minimized, "div{color: blue}") ++ ++ def test_attribute_selectors(self): ++ source = """ ++ input[type="search" i]::-webkit-textfield-decoration-container { ++ direction: ltr; ++ } ++ """ ++ minimized = minimize_css.CSSMinimizer.minimize_css(source) ++ self.assertEquals( ++ minimized, ++ # pylint: disable=line-too-long ++ """input[type="search" i]::-webkit-textfield-decoration-container{direction: ltr}""") ++ ++ def test_strip_comment(self): ++ source = """ ++ /* header */ ++ html { ++ /* inside block */ ++ display: block; ++ } ++ /* footer */ ++ """ ++ minimized = minimize_css.CSSMinimizer.minimize_css(source) ++ self.assertEquals(minimized, "html{ display: block}") ++ ++ def test_no_strip_inside_quotes(self): ++ source = """div[foo=' bar ']""" ++ minimized = minimize_css.CSSMinimizer.minimize_css(source) ++ self.assertEquals(minimized, source) ++ ++ source = """div[foo=" bar "]""" ++ minimized = minimize_css.CSSMinimizer.minimize_css(source) ++ self.assertEquals(minimized, source) ++ ++ def test_escape_string(self): ++ source = """content: " <a onclick=\\\"javascript: alert ( 'foobar' ); \\\">";""" ++ minimized = minimize_css.CSSMinimizer.minimize_css(source) ++ self.assertEquals(minimized, source) +diff --git a/tools/grit/pak_util.py b/tools/grit/pak_util.py +new file mode 100644 +index 0000000000..ede638bbe1 +--- /dev/null ++++ b/tools/grit/pak_util.py +@@ -0,0 +1,223 @@ ++#!/usr/bin/env python ++# Copyright 2017 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++"""A tool for interacting with .pak files. ++ ++For details on the pak file format, see: ++https://dev.chromium.org/developers/design-documents/linuxresourcesandlocalizedstrings ++""" ++ ++from __future__ import print_function ++ ++import argparse ++import gzip ++import hashlib ++import os ++import shutil ++import sys ++import tempfile ++ ++# Import grit first to get local third_party modules. ++import grit # pylint: disable=ungrouped-imports,unused-import ++ ++import six ++ ++from grit.format import data_pack ++ ++ ++def _RepackMain(args): ++ output_info_filepath = args.output_pak_file + '.info' ++ if args.compress: ++ # If the file needs to be compressed, call RePack with a tempfile path, ++ # then compress the tempfile to args.output_pak_file. ++ temp_outfile = tempfile.NamedTemporaryFile() ++ out_path = temp_outfile.name ++ # Strip any non .pak extension from the .info output file path. ++ splitext = os.path.splitext(args.output_pak_file) ++ if splitext[1] != '.pak': ++ output_info_filepath = splitext[0] + '.info' ++ else: ++ out_path = args.output_pak_file ++ data_pack.RePack(out_path, args.input_pak_files, args.whitelist, ++ args.suppress_removed_key_output, ++ output_info_filepath=output_info_filepath) ++ if args.compress: ++ with open(args.output_pak_file, 'wb') as out: ++ with gzip.GzipFile(filename='', mode='wb', fileobj=out, mtime=0) as outgz: ++ shutil.copyfileobj(temp_outfile, outgz) ++ ++ ++def _ExtractMain(args): ++ pak = data_pack.ReadDataPack(args.pak_file) ++ if args.textual_id: ++ info_dict = data_pack.ReadGrdInfo(args.pak_file) ++ for resource_id, payload in pak.resources.items(): ++ filename = ( ++ info_dict[resource_id].textual_id ++ if args.textual_id else str(resource_id)) ++ path = os.path.join(args.output_dir, filename) ++ with open(path, 'w') as f: ++ f.write(payload) ++ ++ ++def _CreateMain(args): ++ pak = {} ++ for name in os.listdir(args.input_dir): ++ try: ++ resource_id = int(name) ++ except: ++ continue ++ filename = os.path.join(args.input_dir, name) ++ if os.path.isfile(filename): ++ with open(filename, 'rb') as f: ++ pak[resource_id] = f.read() ++ data_pack.WriteDataPack(pak, args.output_pak_file, data_pack.UTF8) ++ ++ ++def _PrintMain(args): ++ pak = data_pack.ReadDataPack(args.pak_file) ++ if args.textual_id: ++ info_dict = data_pack.ReadGrdInfo(args.pak_file) ++ output = args.output ++ encoding = 'binary' ++ if pak.encoding == 1: ++ encoding = 'utf-8' ++ elif pak.encoding == 2: ++ encoding = 'utf-16' ++ else: ++ encoding = '?' + str(pak.encoding) ++ ++ output.write('version: {}\n'.format(pak.version)) ++ output.write('encoding: {}\n'.format(encoding)) ++ output.write('num_resources: {}\n'.format(len(pak.resources))) ++ output.write('num_aliases: {}\n'.format(len(pak.aliases))) ++ breakdown = ', '.join('{}: {}'.format(*x) for x in pak.sizes) ++ output.write('total_size: {} ({})\n'.format(pak.sizes.total, breakdown)) ++ ++ try_decode = args.decode and encoding.startswith('utf') ++ # Print IDs in ascending order, since that's the order in which they appear in ++ # the file (order is lost by Python dict). ++ for resource_id in sorted(pak.resources): ++ data = pak.resources[resource_id] ++ canonical_id = pak.aliases.get(resource_id, resource_id) ++ desc = '<data>' ++ if try_decode: ++ try: ++ desc = six.text_type(data, encoding) ++ if len(desc) > 60: ++ desc = desc[:60] + u'...' ++ desc = desc.replace('\n', '\\n') ++ except UnicodeDecodeError: ++ pass ++ sha1 = hashlib.sha1(data).hexdigest()[:10] ++ if args.textual_id: ++ textual_id = info_dict[resource_id].textual_id ++ canonical_textual_id = info_dict[canonical_id].textual_id ++ output.write( ++ u'Entry(id={}, canonical_id={}, size={}, sha1={}): {}\n'.format( ++ textual_id, canonical_textual_id, len(data), sha1, ++ desc).encode('utf-8')) ++ else: ++ output.write( ++ u'Entry(id={}, canonical_id={}, size={}, sha1={}): {}\n'.format( ++ resource_id, canonical_id, len(data), sha1, desc).encode('utf-8')) ++ ++ ++def _ListMain(args): ++ pak = data_pack.ReadDataPack(args.pak_file) ++ if args.textual_id or args.path: ++ info_dict = data_pack.ReadGrdInfo(args.pak_file) ++ fmt = ''.join([ ++ '{id}', ' = {textual_id}' if args.textual_id else '', ++ ' @ {path}' if args.path else '', '\n' ++ ]) ++ for resource_id in sorted(pak.resources): ++ item = info_dict[resource_id] ++ args.output.write( ++ fmt.format(textual_id=item.textual_id, id=item.id, path=item.path)) ++ else: ++ for resource_id in sorted(pak.resources): ++ args.output.write('%d\n' % resource_id) ++ ++ ++def main(): ++ parser = argparse.ArgumentParser( ++ description=__doc__, formatter_class=argparse.RawTextHelpFormatter) ++ # Subparsers are required by default under Python 2. Python 3 changed to ++ # not required, but didn't include a required option until 3.7. Setting ++ # the required member works in all versions (and setting dest name). ++ sub_parsers = parser.add_subparsers(dest='action') ++ sub_parsers.required = True ++ ++ sub_parser = sub_parsers.add_parser('repack', ++ help='Combines several .pak files into one.') ++ sub_parser.add_argument('output_pak_file', help='File to create.') ++ sub_parser.add_argument('input_pak_files', nargs='+', ++ help='Input .pak files.') ++ sub_parser.add_argument('--whitelist', ++ help='Path to a whitelist used to filter output pak file resource IDs.') ++ sub_parser.add_argument('--suppress-removed-key-output', action='store_true', ++ help='Do not log which keys were removed by the whitelist.') ++ sub_parser.add_argument('--compress', dest='compress', action='store_true', ++ default=False, help='Compress output_pak_file using gzip.') ++ sub_parser.set_defaults(func=_RepackMain) ++ ++ sub_parser = sub_parsers.add_parser('extract', help='Extracts pak file') ++ sub_parser.add_argument('pak_file') ++ sub_parser.add_argument('-o', '--output-dir', default='.', ++ help='Directory to extract to.') ++ sub_parser.add_argument( ++ '-t', ++ '--textual-id', ++ action='store_true', ++ help='Use textual resource ID (name) (from .info file) as filenames.') ++ sub_parser.set_defaults(func=_ExtractMain) ++ ++ sub_parser = sub_parsers.add_parser('create', ++ help='Creates pak file from extracted directory.') ++ sub_parser.add_argument('output_pak_file', help='File to create.') ++ sub_parser.add_argument('-i', '--input-dir', default='.', ++ help='Directory to create from.') ++ sub_parser.set_defaults(func=_CreateMain) ++ ++ sub_parser = sub_parsers.add_parser('print', ++ help='Prints all pak IDs and contents. Useful for diffing.') ++ sub_parser.add_argument('pak_file') ++ sub_parser.add_argument('--output', type=argparse.FileType('w'), ++ default=sys.stdout, ++ help='The resource list path to write (default stdout)') ++ sub_parser.add_argument('--no-decode', dest='decode', action='store_false', ++ default=True, help='Do not print entry data.') ++ sub_parser.add_argument( ++ '-t', ++ '--textual-id', ++ action='store_true', ++ help='Print textual ID (name) (from .info file) instead of the ID.') ++ sub_parser.set_defaults(func=_PrintMain) ++ ++ sub_parser = sub_parsers.add_parser('list-id', ++ help='Outputs all resource IDs to a file.') ++ sub_parser.add_argument('pak_file') ++ sub_parser.add_argument('--output', type=argparse.FileType('w'), ++ default=sys.stdout, ++ help='The resource list path to write (default stdout)') ++ sub_parser.add_argument( ++ '-t', ++ '--textual-id', ++ action='store_true', ++ help='Print the textual resource ID (from .info file).') ++ sub_parser.add_argument( ++ '-p', ++ '--path', ++ action='store_true', ++ help='Print the resource path (from .info file).') ++ sub_parser.set_defaults(func=_ListMain) ++ ++ args = parser.parse_args() ++ args.func(args) ++ ++ ++if __name__ == '__main__': ++ main() +diff --git a/tools/grit/repack.gni b/tools/grit/repack.gni +new file mode 100644 +index 0000000000..193f2dc43f +--- /dev/null ++++ b/tools/grit/repack.gni +@@ -0,0 +1,189 @@ ++# Copyright 2014 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++import("//tools/grit/grit_rule.gni") ++ ++# This file defines a template to invoke grit repack in a consistent manner. ++# ++# Parameters: ++# sources [required] ++# List of pak files that need to be combined. ++# ++# output [required] ++# File name (single string) of the output file. ++# ++# copy_data_to_bundle [optional] ++# Whether to define a bundle_data() for the resulting pak. ++# ++# bundle_output [optional] ++# Path of the file in the application bundle, defaults to ++# {{bundle_resources_dir}}/{{source_file_part}}. ++# ++# compress [optional] ++# Gzip the resulting bundle (and append .gz to the output name). ++# ++# deps [optional] ++# public_deps [optional] ++# visibility [optional] ++# Normal meaning. ++template("repack") { ++ _copy_data_to_bundle = ++ defined(invoker.copy_data_to_bundle) && invoker.copy_data_to_bundle ++ _repack_target_name = target_name ++ if (_copy_data_to_bundle) { ++ _repack_target_name = "${target_name}__repack" ++ } ++ ++ _compress = defined(invoker.compress) && invoker.compress ++ ++ action(_repack_target_name) { ++ forward_variables_from(invoker, ++ [ ++ "deps", ++ "public_deps", ++ "testonly", ++ "visibility", ++ ]) ++ if (defined(visibility) && _copy_data_to_bundle) { ++ visibility += [ ":${invoker.target_name}" ] ++ } ++ assert(defined(invoker.sources), "Need sources for $target_name") ++ assert(defined(invoker.output), "Need output for $target_name") ++ ++ script = "//tools/grit/pak_util.py" ++ ++ inputs = invoker.sources ++ outputs = [ ++ invoker.output, ++ "${invoker.output}.info", ++ ] ++ ++ args = [ "repack" ] ++ if (defined(invoker.repack_whitelist)) { ++ inputs += [ invoker.repack_whitelist ] ++ _rebased_whitelist = rebase_path(invoker.repack_whitelist) ++ args += [ "--whitelist=$_rebased_whitelist" ] ++ args += [ "--suppress-removed-key-output" ] ++ } ++ args += [ rebase_path(invoker.output, root_build_dir) ] ++ args += rebase_path(invoker.sources, root_build_dir) ++ if (_compress) { ++ args += [ "--compress" ] ++ } ++ } ++ ++ if (_copy_data_to_bundle) { ++ bundle_data(target_name) { ++ forward_variables_from(invoker, ++ [ ++ "testonly", ++ "visibility", ++ ]) ++ ++ public_deps = [ ":$_repack_target_name" ] ++ sources = [ invoker.output ] ++ if (defined(invoker.bundle_output)) { ++ outputs = [ invoker.bundle_output ] ++ } else { ++ outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ] ++ } ++ } ++ } ++} ++ ++# Repacks a set of .pak files for each locale. ++# ++# Parameters: ++# ++# input_locales [required] ++# List of locale names to use as inputs. ++# ++# output_locales [required] ++# A list containing the corresponding output names for each of the ++# input names. Mac and iOS use different names in some cases. ++# ++# source_patterns [required] ++# The pattern for pak files which need repacked. The filenames always end ++# with "${locale}.pak". ++# E.g.: ++# ${root_gen_dir}/foo_ expands to ${root_gen_dir}/foo_zh-CN.pak ++# when locale is zh-CN. ++# ++# output_dir [optional] ++# Directory in which to put all pak files. ++# ++# deps [optional] ++# visibility [optional] ++# testonly [optional] ++# copy_data_to_bundle [optional] ++# repack_whitelist [optional] ++# Normal meaning. ++template("repack_locales") { ++ if (defined(invoker.output_dir)) { ++ _output_dir = invoker.output_dir ++ } else if (is_ios) { ++ _output_dir = "$target_gen_dir" ++ } else { ++ _output_dir = "$target_gen_dir/$target_name" ++ } ++ ++ # GN can't handle invoker.output_locales[foo] (http://crbug.com/614747). ++ _output_locales = invoker.output_locales ++ ++ # Collects all targets the loop generates. ++ _locale_targets = [] ++ ++ # This loop iterates over the input locales and also keeps a counter so it ++ # can simultaneously iterate over the output locales (using GN's very ++ # limited looping capabilities). ++ _current_index = 0 ++ foreach(_input_locale, invoker.input_locales) { ++ _output_locale = _output_locales[_current_index] ++ ++ # Compute the name of the target for the current file. Save it for the deps. ++ _current_name = "${target_name}_${_input_locale}" ++ _locale_targets += [ ":$_current_name" ] ++ ++ repack(_current_name) { ++ forward_variables_from(invoker, ++ [ ++ "copy_data_to_bundle", ++ "bundle_output", ++ "compress", ++ "deps", ++ "repack_whitelist", ++ "testonly", ++ ]) ++ visibility = [ ":${invoker.target_name}" ] ++ if (is_ios) { ++ output = "$_output_dir/${_output_locale}.lproj/locale.pak" ++ } else { ++ output = "$_output_dir/${_output_locale}.pak" ++ } ++ if (defined(copy_data_to_bundle) && copy_data_to_bundle) { ++ bundle_output = ++ "{{bundle_resources_dir}}/${_output_locale}.lproj/locale.pak" ++ } ++ sources = [] ++ foreach(_pattern, invoker.source_patterns) { ++ sources += [ "${_pattern}${_input_locale}.pak" ] ++ } ++ } ++ ++ _current_index = _current_index + 1 ++ } ++ ++ # The group that external targets depend on which collects all deps. ++ group(target_name) { ++ forward_variables_from(invoker, ++ [ ++ "visibility", ++ "testonly", ++ ]) ++ public_deps = _locale_targets ++ if (!defined(invoker.copy_data_to_bundle) || !invoker.copy_data_to_bundle) { ++ data_deps = public_deps ++ } ++ } ++} +diff --git a/tools/grit/setup.py b/tools/grit/setup.py +new file mode 100644 +index 0000000000..5d86dfc2fc +--- /dev/null ++++ b/tools/grit/setup.py +@@ -0,0 +1,46 @@ ++#!/usr/bin/env python3 ++# Copyright 2020 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++"""Install the package!""" ++ ++from __future__ import absolute_import ++ ++import setuptools ++ ++ ++setuptools.setup( ++ name='grit', ++ version='0', ++ entry_points={ ++ 'console_scripts': ['grit = grit.grit_runner:Main'], ++ }, ++ packages=setuptools.find_packages(), ++ install_requires=[ ++ 'six >= 1.10', ++ ], ++ author='The Chromium Authors', ++ author_email='chromium-dev@chromium.org', ++ description='Google Resource and Internationalization Tool for managing ' ++ 'translations & resource files', ++ license='BSD-3', ++ url='https://chromium.googlesource.com/chromium/src/tools/grit/', ++ classifiers=[ ++ 'Development Status :: 6 - Mature', ++ 'Environment :: Console', ++ 'Intended Audience :: Developers', ++ 'License :: OSI Approved :: BSD License', ++ 'Operating System :: MacOS', ++ 'Operating System :: Microsoft :: Windows', ++ 'Operating System :: POSIX :: Linux', ++ 'Programming Language :: Python', ++ 'Programming Language :: Python :: 2.7', ++ 'Programming Language :: Python :: 3', ++ 'Programming Language :: Python :: 3.6', ++ 'Programming Language :: Python :: 3.7', ++ 'Programming Language :: Python :: 3.8', ++ 'Programming Language :: Python :: 3.9', ++ 'Topic :: Utilities', ++ ], ++) +diff --git a/tools/grit/stamp_grit_sources.py b/tools/grit/stamp_grit_sources.py +new file mode 100644 +index 0000000000..bc7265c6cb +--- /dev/null ++++ b/tools/grit/stamp_grit_sources.py +@@ -0,0 +1,57 @@ ++# Copyright 2014 The Chromium Authors. All rights reserved. ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++# This script enumerates the files in the given directory, writing an empty ++# stamp file and a .d file listing the inputs required to make the stamp. This ++# allows us to dynamically depend on the grit sources without enumerating the ++# grit directory for every invocation of grit (which is what adding the source ++# files to every .grd file's .d file would entail) or shelling out to grit ++# synchronously during GN execution to get the list (which would be slow). ++# ++# Usage: ++# stamp_grit_sources.py <directory> <stamp-file> <.d-file> ++ ++from __future__ import print_function ++ ++import os ++import sys ++ ++def GritSourceFiles(grit_root_dir): ++ files = [] ++ for root, _, filenames in os.walk(grit_root_dir): ++ grit_src = [os.path.join(root, f) for f in filenames ++ if f.endswith('.py') and not f.endswith('_unittest.py')] ++ files.extend(grit_src) ++ files = [f.replace('\\', '/') for f in files] ++ return sorted(files) ++ ++ ++def WriteDepFile(dep_file, stamp_file, source_files): ++ with open(dep_file, "w") as f: ++ f.write(stamp_file) ++ f.write(": ") ++ f.write(' '.join(source_files)) ++ ++ ++def WriteStampFile(stamp_file): ++ with open(stamp_file, "w"): ++ pass ++ ++ ++def main(argv): ++ if len(argv) != 4: ++ print("Error: expecting 3 args.") ++ return 1 ++ ++ grit_root_dir = sys.argv[1] ++ stamp_file = sys.argv[2] ++ dep_file = sys.argv[3] ++ ++ WriteStampFile(stamp_file) ++ WriteDepFile(dep_file, stamp_file, GritSourceFiles(grit_root_dir)) ++ return 0 ++ ++ ++if __name__ == '__main__': ++ sys.exit(main(sys.argv)) +diff --git a/tools/grit/third_party/six/LICENSE b/tools/grit/third_party/six/LICENSE +new file mode 100644 +index 0000000000..e558f9d494 +--- /dev/null ++++ b/tools/grit/third_party/six/LICENSE +@@ -0,0 +1,18 @@ ++Copyright (c) 2010-2015 Benjamin Peterson ++ ++Permission is hereby granted, free of charge, to any person obtaining a copy of ++this software and associated documentation files (the "Software"), to deal in ++the Software without restriction, including without limitation the rights to ++use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of ++the Software, and to permit persons to whom the Software is furnished to do so, ++subject to the following conditions: ++ ++The above copyright notice and this permission notice shall be included in all ++copies or substantial portions of the Software. ++ ++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS ++FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR ++COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER ++IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ++CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +diff --git a/tools/grit/third_party/six/README b/tools/grit/third_party/six/README +new file mode 100644 +index 0000000000..ee628a9db6 +--- /dev/null ++++ b/tools/grit/third_party/six/README +@@ -0,0 +1,16 @@ ++Six is a Python 2 and 3 compatibility library. It provides utility functions ++for smoothing over the differences between the Python versions with the goal of ++writing Python code that is compatible on both Python versions. See the ++documentation for more information on what is provided. ++ ++Six supports every Python version since 2.6. It is contained in only one Python ++file, so it can be easily copied into your project. (The copyright and license ++notice must be retained.) ++ ++Online documentation is at https://pythonhosted.org/six/. ++ ++Bugs can be reported to https://bitbucket.org/gutworth/six. The code can also ++be found there. ++ ++For questions about six or porting in general, email the python-porting mailing ++list: https://mail.python.org/mailman/listinfo/python-porting +diff --git a/tools/grit/third_party/six/README.chromium b/tools/grit/third_party/six/README.chromium +new file mode 100644 +index 0000000000..100b24d046 +--- /dev/null ++++ b/tools/grit/third_party/six/README.chromium +@@ -0,0 +1,13 @@ ++Name: six ++Short Name: six ++URL: https://bitbucket.org/gutworth/six/commits/tag/1.10.0 ++Version: 1.10.0 ++Revision: 403:e5218c3f66a2 ++License: Apache License, Version 2.0 ++ ++Description: ++Six is a Python 2 and 3 compatibility library. ++ ++Local Modifications: ++- Copied six.py as __init__.py. ++- Kept LICENSE and README. +diff --git a/tools/grit/third_party/six/__init__.py b/tools/grit/third_party/six/__init__.py +new file mode 100644 +index 0000000000..56e4272cb3 +--- /dev/null ++++ b/tools/grit/third_party/six/__init__.py +@@ -0,0 +1,868 @@ ++# Copyright (c) 2010-2015 Benjamin Peterson ++# ++# Permission is hereby granted, free of charge, to any person obtaining a copy ++# of this software and associated documentation files (the "Software"), to deal ++# in the Software without restriction, including without limitation the rights ++# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ++# copies of the Software, and to permit persons to whom the Software is ++# furnished to do so, subject to the following conditions: ++# ++# The above copyright notice and this permission notice shall be included in all ++# copies or substantial portions of the Software. ++# ++# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ++# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ++# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ++# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ++# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ++# SOFTWARE. ++ ++"""Utilities for writing code that runs on Python 2 and 3""" ++ ++from __future__ import absolute_import ++ ++import functools ++import itertools ++import operator ++import sys ++import types ++ ++__author__ = "Benjamin Peterson <benjamin@python.org>" ++__version__ = "1.10.0" ++ ++ ++# Useful for very coarse version differentiation. ++PY2 = sys.version_info[0] == 2 ++PY3 = sys.version_info[0] == 3 ++PY34 = sys.version_info[0:2] >= (3, 4) ++ ++if PY3: ++ string_types = str, ++ integer_types = int, ++ class_types = type, ++ text_type = str ++ binary_type = bytes ++ ++ MAXSIZE = sys.maxsize ++else: ++ string_types = basestring, ++ integer_types = (int, long) ++ class_types = (type, types.ClassType) ++ text_type = unicode ++ binary_type = str ++ ++ if sys.platform.startswith("java"): ++ # Jython always uses 32 bits. ++ MAXSIZE = int((1 << 31) - 1) ++ else: ++ # It's possible to have sizeof(long) != sizeof(Py_ssize_t). ++ class X(object): ++ ++ def __len__(self): ++ return 1 << 31 ++ try: ++ len(X()) ++ except OverflowError: ++ # 32-bit ++ MAXSIZE = int((1 << 31) - 1) ++ else: ++ # 64-bit ++ MAXSIZE = int((1 << 63) - 1) ++ del X ++ ++ ++def _add_doc(func, doc): ++ """Add documentation to a function.""" ++ func.__doc__ = doc ++ ++ ++def _import_module(name): ++ """Import module, returning the module after the last dot.""" ++ __import__(name) ++ return sys.modules[name] ++ ++ ++class _LazyDescr(object): ++ ++ def __init__(self, name): ++ self.name = name ++ ++ def __get__(self, obj, tp): ++ result = self._resolve() ++ setattr(obj, self.name, result) # Invokes __set__. ++ try: ++ # This is a bit ugly, but it avoids running this again by ++ # removing this descriptor. ++ delattr(obj.__class__, self.name) ++ except AttributeError: ++ pass ++ return result ++ ++ ++class MovedModule(_LazyDescr): ++ ++ def __init__(self, name, old, new=None): ++ super(MovedModule, self).__init__(name) ++ if PY3: ++ if new is None: ++ new = name ++ self.mod = new ++ else: ++ self.mod = old ++ ++ def _resolve(self): ++ return _import_module(self.mod) ++ ++ def __getattr__(self, attr): ++ _module = self._resolve() ++ value = getattr(_module, attr) ++ setattr(self, attr, value) ++ return value ++ ++ ++class _LazyModule(types.ModuleType): ++ ++ def __init__(self, name): ++ super(_LazyModule, self).__init__(name) ++ self.__doc__ = self.__class__.__doc__ ++ ++ def __dir__(self): ++ attrs = ["__doc__", "__name__"] ++ attrs += [attr.name for attr in self._moved_attributes] ++ return attrs ++ ++ # Subclasses should override this ++ _moved_attributes = [] ++ ++ ++class MovedAttribute(_LazyDescr): ++ ++ def __init__(self, name, old_mod, new_mod, old_attr=None, new_attr=None): ++ super(MovedAttribute, self).__init__(name) ++ if PY3: ++ if new_mod is None: ++ new_mod = name ++ self.mod = new_mod ++ if new_attr is None: ++ if old_attr is None: ++ new_attr = name ++ else: ++ new_attr = old_attr ++ self.attr = new_attr ++ else: ++ self.mod = old_mod ++ if old_attr is None: ++ old_attr = name ++ self.attr = old_attr ++ ++ def _resolve(self): ++ module = _import_module(self.mod) ++ return getattr(module, self.attr) ++ ++ ++class _SixMetaPathImporter(object): ++ ++ """ ++ A meta path importer to import six.moves and its submodules. ++ ++ This class implements a PEP302 finder and loader. It should be compatible ++ with Python 2.5 and all existing versions of Python3 ++ """ ++ ++ def __init__(self, six_module_name): ++ self.name = six_module_name ++ self.known_modules = {} ++ ++ def _add_module(self, mod, *fullnames): ++ for fullname in fullnames: ++ self.known_modules[self.name + "." + fullname] = mod ++ ++ def _get_module(self, fullname): ++ return self.known_modules[self.name + "." + fullname] ++ ++ def find_module(self, fullname, path=None): ++ if fullname in self.known_modules: ++ return self ++ return None ++ ++ def __get_module(self, fullname): ++ try: ++ return self.known_modules[fullname] ++ except KeyError: ++ raise ImportError("This loader does not know module " + fullname) ++ ++ def load_module(self, fullname): ++ try: ++ # in case of a reload ++ return sys.modules[fullname] ++ except KeyError: ++ pass ++ mod = self.__get_module(fullname) ++ if isinstance(mod, MovedModule): ++ mod = mod._resolve() ++ else: ++ mod.__loader__ = self ++ sys.modules[fullname] = mod ++ return mod ++ ++ def is_package(self, fullname): ++ """ ++ Return true, if the named module is a package. ++ ++ We need this method to get correct spec objects with ++ Python 3.4 (see PEP451) ++ """ ++ return hasattr(self.__get_module(fullname), "__path__") ++ ++ def get_code(self, fullname): ++ """Return None ++ ++ Required, if is_package is implemented""" ++ self.__get_module(fullname) # eventually raises ImportError ++ return None ++ get_source = get_code # same as get_code ++ ++_importer = _SixMetaPathImporter(__name__) ++ ++ ++class _MovedItems(_LazyModule): ++ ++ """Lazy loading of moved objects""" ++ __path__ = [] # mark as package ++ ++ ++_moved_attributes = [ ++ MovedAttribute("cStringIO", "cStringIO", "io", "StringIO"), ++ MovedAttribute("filter", "itertools", "builtins", "ifilter", "filter"), ++ MovedAttribute("filterfalse", "itertools", "itertools", "ifilterfalse", "filterfalse"), ++ MovedAttribute("input", "__builtin__", "builtins", "raw_input", "input"), ++ MovedAttribute("intern", "__builtin__", "sys"), ++ MovedAttribute("map", "itertools", "builtins", "imap", "map"), ++ MovedAttribute("getcwd", "os", "os", "getcwdu", "getcwd"), ++ MovedAttribute("getcwdb", "os", "os", "getcwd", "getcwdb"), ++ MovedAttribute("range", "__builtin__", "builtins", "xrange", "range"), ++ MovedAttribute("reload_module", "__builtin__", "importlib" if PY34 else "imp", "reload"), ++ MovedAttribute("reduce", "__builtin__", "functools"), ++ MovedAttribute("shlex_quote", "pipes", "shlex", "quote"), ++ MovedAttribute("StringIO", "StringIO", "io"), ++ MovedAttribute("UserDict", "UserDict", "collections"), ++ MovedAttribute("UserList", "UserList", "collections"), ++ MovedAttribute("UserString", "UserString", "collections"), ++ MovedAttribute("xrange", "__builtin__", "builtins", "xrange", "range"), ++ MovedAttribute("zip", "itertools", "builtins", "izip", "zip"), ++ MovedAttribute("zip_longest", "itertools", "itertools", "izip_longest", "zip_longest"), ++ MovedModule("builtins", "__builtin__"), ++ MovedModule("configparser", "ConfigParser"), ++ MovedModule("copyreg", "copy_reg"), ++ MovedModule("dbm_gnu", "gdbm", "dbm.gnu"), ++ MovedModule("_dummy_thread", "dummy_thread", "_dummy_thread"), ++ MovedModule("http_cookiejar", "cookielib", "http.cookiejar"), ++ MovedModule("http_cookies", "Cookie", "http.cookies"), ++ MovedModule("html_entities", "htmlentitydefs", "html.entities"), ++ MovedModule("html_parser", "HTMLParser", "html.parser"), ++ MovedModule("http_client", "httplib", "http.client"), ++ MovedModule("email_mime_multipart", "email.MIMEMultipart", "email.mime.multipart"), ++ MovedModule("email_mime_nonmultipart", "email.MIMENonMultipart", "email.mime.nonmultipart"), ++ MovedModule("email_mime_text", "email.MIMEText", "email.mime.text"), ++ MovedModule("email_mime_base", "email.MIMEBase", "email.mime.base"), ++ MovedModule("BaseHTTPServer", "BaseHTTPServer", "http.server"), ++ MovedModule("CGIHTTPServer", "CGIHTTPServer", "http.server"), ++ MovedModule("SimpleHTTPServer", "SimpleHTTPServer", "http.server"), ++ MovedModule("cPickle", "cPickle", "pickle"), ++ MovedModule("queue", "Queue"), ++ MovedModule("reprlib", "repr"), ++ MovedModule("socketserver", "SocketServer"), ++ MovedModule("_thread", "thread", "_thread"), ++ MovedModule("tkinter", "Tkinter"), ++ MovedModule("tkinter_dialog", "Dialog", "tkinter.dialog"), ++ MovedModule("tkinter_filedialog", "FileDialog", "tkinter.filedialog"), ++ MovedModule("tkinter_scrolledtext", "ScrolledText", "tkinter.scrolledtext"), ++ MovedModule("tkinter_simpledialog", "SimpleDialog", "tkinter.simpledialog"), ++ MovedModule("tkinter_tix", "Tix", "tkinter.tix"), ++ MovedModule("tkinter_ttk", "ttk", "tkinter.ttk"), ++ MovedModule("tkinter_constants", "Tkconstants", "tkinter.constants"), ++ MovedModule("tkinter_dnd", "Tkdnd", "tkinter.dnd"), ++ MovedModule("tkinter_colorchooser", "tkColorChooser", ++ "tkinter.colorchooser"), ++ MovedModule("tkinter_commondialog", "tkCommonDialog", ++ "tkinter.commondialog"), ++ MovedModule("tkinter_tkfiledialog", "tkFileDialog", "tkinter.filedialog"), ++ MovedModule("tkinter_font", "tkFont", "tkinter.font"), ++ MovedModule("tkinter_messagebox", "tkMessageBox", "tkinter.messagebox"), ++ MovedModule("tkinter_tksimpledialog", "tkSimpleDialog", ++ "tkinter.simpledialog"), ++ MovedModule("urllib_parse", __name__ + ".moves.urllib_parse", "urllib.parse"), ++ MovedModule("urllib_error", __name__ + ".moves.urllib_error", "urllib.error"), ++ MovedModule("urllib", __name__ + ".moves.urllib", __name__ + ".moves.urllib"), ++ MovedModule("urllib_robotparser", "robotparser", "urllib.robotparser"), ++ MovedModule("xmlrpc_client", "xmlrpclib", "xmlrpc.client"), ++ MovedModule("xmlrpc_server", "SimpleXMLRPCServer", "xmlrpc.server"), ++] ++# Add windows specific modules. ++if sys.platform == "win32": ++ _moved_attributes += [ ++ MovedModule("winreg", "_winreg"), ++ ] ++ ++for attr in _moved_attributes: ++ setattr(_MovedItems, attr.name, attr) ++ if isinstance(attr, MovedModule): ++ _importer._add_module(attr, "moves." + attr.name) ++del attr ++ ++_MovedItems._moved_attributes = _moved_attributes ++ ++moves = _MovedItems(__name__ + ".moves") ++_importer._add_module(moves, "moves") ++ ++ ++class Module_six_moves_urllib_parse(_LazyModule): ++ ++ """Lazy loading of moved objects in six.moves.urllib_parse""" ++ ++ ++_urllib_parse_moved_attributes = [ ++ MovedAttribute("ParseResult", "urlparse", "urllib.parse"), ++ MovedAttribute("SplitResult", "urlparse", "urllib.parse"), ++ MovedAttribute("parse_qs", "urlparse", "urllib.parse"), ++ MovedAttribute("parse_qsl", "urlparse", "urllib.parse"), ++ MovedAttribute("urldefrag", "urlparse", "urllib.parse"), ++ MovedAttribute("urljoin", "urlparse", "urllib.parse"), ++ MovedAttribute("urlparse", "urlparse", "urllib.parse"), ++ MovedAttribute("urlsplit", "urlparse", "urllib.parse"), ++ MovedAttribute("urlunparse", "urlparse", "urllib.parse"), ++ MovedAttribute("urlunsplit", "urlparse", "urllib.parse"), ++ MovedAttribute("quote", "urllib", "urllib.parse"), ++ MovedAttribute("quote_plus", "urllib", "urllib.parse"), ++ MovedAttribute("unquote", "urllib", "urllib.parse"), ++ MovedAttribute("unquote_plus", "urllib", "urllib.parse"), ++ MovedAttribute("urlencode", "urllib", "urllib.parse"), ++ MovedAttribute("splitquery", "urllib", "urllib.parse"), ++ MovedAttribute("splittag", "urllib", "urllib.parse"), ++ MovedAttribute("splituser", "urllib", "urllib.parse"), ++ MovedAttribute("uses_fragment", "urlparse", "urllib.parse"), ++ MovedAttribute("uses_netloc", "urlparse", "urllib.parse"), ++ MovedAttribute("uses_params", "urlparse", "urllib.parse"), ++ MovedAttribute("uses_query", "urlparse", "urllib.parse"), ++ MovedAttribute("uses_relative", "urlparse", "urllib.parse"), ++] ++for attr in _urllib_parse_moved_attributes: ++ setattr(Module_six_moves_urllib_parse, attr.name, attr) ++del attr ++ ++Module_six_moves_urllib_parse._moved_attributes = _urllib_parse_moved_attributes ++ ++_importer._add_module(Module_six_moves_urllib_parse(__name__ + ".moves.urllib_parse"), ++ "moves.urllib_parse", "moves.urllib.parse") ++ ++ ++class Module_six_moves_urllib_error(_LazyModule): ++ ++ """Lazy loading of moved objects in six.moves.urllib_error""" ++ ++ ++_urllib_error_moved_attributes = [ ++ MovedAttribute("URLError", "urllib2", "urllib.error"), ++ MovedAttribute("HTTPError", "urllib2", "urllib.error"), ++ MovedAttribute("ContentTooShortError", "urllib", "urllib.error"), ++] ++for attr in _urllib_error_moved_attributes: ++ setattr(Module_six_moves_urllib_error, attr.name, attr) ++del attr ++ ++Module_six_moves_urllib_error._moved_attributes = _urllib_error_moved_attributes ++ ++_importer._add_module(Module_six_moves_urllib_error(__name__ + ".moves.urllib.error"), ++ "moves.urllib_error", "moves.urllib.error") ++ ++ ++class Module_six_moves_urllib_request(_LazyModule): ++ ++ """Lazy loading of moved objects in six.moves.urllib_request""" ++ ++ ++_urllib_request_moved_attributes = [ ++ MovedAttribute("urlopen", "urllib2", "urllib.request"), ++ MovedAttribute("install_opener", "urllib2", "urllib.request"), ++ MovedAttribute("build_opener", "urllib2", "urllib.request"), ++ MovedAttribute("pathname2url", "urllib", "urllib.request"), ++ MovedAttribute("url2pathname", "urllib", "urllib.request"), ++ MovedAttribute("getproxies", "urllib", "urllib.request"), ++ MovedAttribute("Request", "urllib2", "urllib.request"), ++ MovedAttribute("OpenerDirector", "urllib2", "urllib.request"), ++ MovedAttribute("HTTPDefaultErrorHandler", "urllib2", "urllib.request"), ++ MovedAttribute("HTTPRedirectHandler", "urllib2", "urllib.request"), ++ MovedAttribute("HTTPCookieProcessor", "urllib2", "urllib.request"), ++ MovedAttribute("ProxyHandler", "urllib2", "urllib.request"), ++ MovedAttribute("BaseHandler", "urllib2", "urllib.request"), ++ MovedAttribute("HTTPPasswordMgr", "urllib2", "urllib.request"), ++ MovedAttribute("HTTPPasswordMgrWithDefaultRealm", "urllib2", "urllib.request"), ++ MovedAttribute("AbstractBasicAuthHandler", "urllib2", "urllib.request"), ++ MovedAttribute("HTTPBasicAuthHandler", "urllib2", "urllib.request"), ++ MovedAttribute("ProxyBasicAuthHandler", "urllib2", "urllib.request"), ++ MovedAttribute("AbstractDigestAuthHandler", "urllib2", "urllib.request"), ++ MovedAttribute("HTTPDigestAuthHandler", "urllib2", "urllib.request"), ++ MovedAttribute("ProxyDigestAuthHandler", "urllib2", "urllib.request"), ++ MovedAttribute("HTTPHandler", "urllib2", "urllib.request"), ++ MovedAttribute("HTTPSHandler", "urllib2", "urllib.request"), ++ MovedAttribute("FileHandler", "urllib2", "urllib.request"), ++ MovedAttribute("FTPHandler", "urllib2", "urllib.request"), ++ MovedAttribute("CacheFTPHandler", "urllib2", "urllib.request"), ++ MovedAttribute("UnknownHandler", "urllib2", "urllib.request"), ++ MovedAttribute("HTTPErrorProcessor", "urllib2", "urllib.request"), ++ MovedAttribute("urlretrieve", "urllib", "urllib.request"), ++ MovedAttribute("urlcleanup", "urllib", "urllib.request"), ++ MovedAttribute("URLopener", "urllib", "urllib.request"), ++ MovedAttribute("FancyURLopener", "urllib", "urllib.request"), ++ MovedAttribute("proxy_bypass", "urllib", "urllib.request"), ++] ++for attr in _urllib_request_moved_attributes: ++ setattr(Module_six_moves_urllib_request, attr.name, attr) ++del attr ++ ++Module_six_moves_urllib_request._moved_attributes = _urllib_request_moved_attributes ++ ++_importer._add_module(Module_six_moves_urllib_request(__name__ + ".moves.urllib.request"), ++ "moves.urllib_request", "moves.urllib.request") ++ ++ ++class Module_six_moves_urllib_response(_LazyModule): ++ ++ """Lazy loading of moved objects in six.moves.urllib_response""" ++ ++ ++_urllib_response_moved_attributes = [ ++ MovedAttribute("addbase", "urllib", "urllib.response"), ++ MovedAttribute("addclosehook", "urllib", "urllib.response"), ++ MovedAttribute("addinfo", "urllib", "urllib.response"), ++ MovedAttribute("addinfourl", "urllib", "urllib.response"), ++] ++for attr in _urllib_response_moved_attributes: ++ setattr(Module_six_moves_urllib_response, attr.name, attr) ++del attr ++ ++Module_six_moves_urllib_response._moved_attributes = _urllib_response_moved_attributes ++ ++_importer._add_module(Module_six_moves_urllib_response(__name__ + ".moves.urllib.response"), ++ "moves.urllib_response", "moves.urllib.response") ++ ++ ++class Module_six_moves_urllib_robotparser(_LazyModule): ++ ++ """Lazy loading of moved objects in six.moves.urllib_robotparser""" ++ ++ ++_urllib_robotparser_moved_attributes = [ ++ MovedAttribute("RobotFileParser", "robotparser", "urllib.robotparser"), ++] ++for attr in _urllib_robotparser_moved_attributes: ++ setattr(Module_six_moves_urllib_robotparser, attr.name, attr) ++del attr ++ ++Module_six_moves_urllib_robotparser._moved_attributes = _urllib_robotparser_moved_attributes ++ ++_importer._add_module(Module_six_moves_urllib_robotparser(__name__ + ".moves.urllib.robotparser"), ++ "moves.urllib_robotparser", "moves.urllib.robotparser") ++ ++ ++class Module_six_moves_urllib(types.ModuleType): ++ ++ """Create a six.moves.urllib namespace that resembles the Python 3 namespace""" ++ __path__ = [] # mark as package ++ parse = _importer._get_module("moves.urllib_parse") ++ error = _importer._get_module("moves.urllib_error") ++ request = _importer._get_module("moves.urllib_request") ++ response = _importer._get_module("moves.urllib_response") ++ robotparser = _importer._get_module("moves.urllib_robotparser") ++ ++ def __dir__(self): ++ return ['parse', 'error', 'request', 'response', 'robotparser'] ++ ++_importer._add_module(Module_six_moves_urllib(__name__ + ".moves.urllib"), ++ "moves.urllib") ++ ++ ++def add_move(move): ++ """Add an item to six.moves.""" ++ setattr(_MovedItems, move.name, move) ++ ++ ++def remove_move(name): ++ """Remove item from six.moves.""" ++ try: ++ delattr(_MovedItems, name) ++ except AttributeError: ++ try: ++ del moves.__dict__[name] ++ except KeyError: ++ raise AttributeError("no such move, %r" % (name,)) ++ ++ ++if PY3: ++ _meth_func = "__func__" ++ _meth_self = "__self__" ++ ++ _func_closure = "__closure__" ++ _func_code = "__code__" ++ _func_defaults = "__defaults__" ++ _func_globals = "__globals__" ++else: ++ _meth_func = "im_func" ++ _meth_self = "im_self" ++ ++ _func_closure = "func_closure" ++ _func_code = "func_code" ++ _func_defaults = "func_defaults" ++ _func_globals = "func_globals" ++ ++ ++try: ++ advance_iterator = next ++except NameError: ++ def advance_iterator(it): ++ return it.next() ++next = advance_iterator ++ ++ ++try: ++ callable = callable ++except NameError: ++ def callable(obj): ++ return any("__call__" in klass.__dict__ for klass in type(obj).__mro__) ++ ++ ++if PY3: ++ def get_unbound_function(unbound): ++ return unbound ++ ++ create_bound_method = types.MethodType ++ ++ def create_unbound_method(func, cls): ++ return func ++ ++ Iterator = object ++else: ++ def get_unbound_function(unbound): ++ return unbound.im_func ++ ++ def create_bound_method(func, obj): ++ return types.MethodType(func, obj, obj.__class__) ++ ++ def create_unbound_method(func, cls): ++ return types.MethodType(func, None, cls) ++ ++ class Iterator(object): ++ ++ def next(self): ++ return type(self).__next__(self) ++ ++ callable = callable ++_add_doc(get_unbound_function, ++ """Get the function out of a possibly unbound function""") ++ ++ ++get_method_function = operator.attrgetter(_meth_func) ++get_method_self = operator.attrgetter(_meth_self) ++get_function_closure = operator.attrgetter(_func_closure) ++get_function_code = operator.attrgetter(_func_code) ++get_function_defaults = operator.attrgetter(_func_defaults) ++get_function_globals = operator.attrgetter(_func_globals) ++ ++ ++if PY3: ++ def iterkeys(d, **kw): ++ return iter(d.keys(**kw)) ++ ++ def itervalues(d, **kw): ++ return iter(d.values(**kw)) ++ ++ def iteritems(d, **kw): ++ return iter(d.items(**kw)) ++ ++ def iterlists(d, **kw): ++ return iter(d.lists(**kw)) ++ ++ viewkeys = operator.methodcaller("keys") ++ ++ viewvalues = operator.methodcaller("values") ++ ++ viewitems = operator.methodcaller("items") ++else: ++ def iterkeys(d, **kw): ++ return d.iterkeys(**kw) ++ ++ def itervalues(d, **kw): ++ return d.itervalues(**kw) ++ ++ def iteritems(d, **kw): ++ return d.iteritems(**kw) ++ ++ def iterlists(d, **kw): ++ return d.iterlists(**kw) ++ ++ viewkeys = operator.methodcaller("viewkeys") ++ ++ viewvalues = operator.methodcaller("viewvalues") ++ ++ viewitems = operator.methodcaller("viewitems") ++ ++_add_doc(iterkeys, "Return an iterator over the keys of a dictionary.") ++_add_doc(itervalues, "Return an iterator over the values of a dictionary.") ++_add_doc(iteritems, ++ "Return an iterator over the (key, value) pairs of a dictionary.") ++_add_doc(iterlists, ++ "Return an iterator over the (key, [values]) pairs of a dictionary.") ++ ++ ++if PY3: ++ def b(s): ++ return s.encode("latin-1") ++ ++ def u(s): ++ return s ++ unichr = chr ++ import struct ++ int2byte = struct.Struct(">B").pack ++ del struct ++ byte2int = operator.itemgetter(0) ++ indexbytes = operator.getitem ++ iterbytes = iter ++ import io ++ StringIO = io.StringIO ++ BytesIO = io.BytesIO ++ _assertCountEqual = "assertCountEqual" ++ if sys.version_info[1] <= 1: ++ _assertRaisesRegex = "assertRaisesRegexp" ++ _assertRegex = "assertRegexpMatches" ++ else: ++ _assertRaisesRegex = "assertRaisesRegex" ++ _assertRegex = "assertRegex" ++else: ++ def b(s): ++ return s ++ # Workaround for standalone backslash ++ ++ def u(s): ++ return unicode(s.replace(r'\\', r'\\\\'), "unicode_escape") ++ unichr = unichr ++ int2byte = chr ++ ++ def byte2int(bs): ++ return ord(bs[0]) ++ ++ def indexbytes(buf, i): ++ return ord(buf[i]) ++ iterbytes = functools.partial(itertools.imap, ord) ++ import StringIO ++ StringIO = BytesIO = StringIO.StringIO ++ _assertCountEqual = "assertItemsEqual" ++ _assertRaisesRegex = "assertRaisesRegexp" ++ _assertRegex = "assertRegexpMatches" ++_add_doc(b, """Byte literal""") ++_add_doc(u, """Text literal""") ++ ++ ++def assertCountEqual(self, *args, **kwargs): ++ return getattr(self, _assertCountEqual)(*args, **kwargs) ++ ++ ++def assertRaisesRegex(self, *args, **kwargs): ++ return getattr(self, _assertRaisesRegex)(*args, **kwargs) ++ ++ ++def assertRegex(self, *args, **kwargs): ++ return getattr(self, _assertRegex)(*args, **kwargs) ++ ++ ++if PY3: ++ exec_ = getattr(moves.builtins, "exec") ++ ++ def reraise(tp, value, tb=None): ++ if value is None: ++ value = tp() ++ if value.__traceback__ is not tb: ++ raise value.with_traceback(tb) ++ raise value ++ ++else: ++ def exec_(_code_, _globs_=None, _locs_=None): ++ """Execute code in a namespace.""" ++ if _globs_ is None: ++ frame = sys._getframe(1) ++ _globs_ = frame.f_globals ++ if _locs_ is None: ++ _locs_ = frame.f_locals ++ del frame ++ elif _locs_ is None: ++ _locs_ = _globs_ ++ exec("""exec _code_ in _globs_, _locs_""") ++ ++ exec_("""def reraise(tp, value, tb=None): ++ raise tp, value, tb ++""") ++ ++ ++if sys.version_info[:2] == (3, 2): ++ exec_("""def raise_from(value, from_value): ++ if from_value is None: ++ raise value ++ raise value from from_value ++""") ++elif sys.version_info[:2] > (3, 2): ++ exec_("""def raise_from(value, from_value): ++ raise value from from_value ++""") ++else: ++ def raise_from(value, from_value): ++ raise value ++ ++ ++print_ = getattr(moves.builtins, "print", None) ++if print_ is None: ++ def print_(*args, **kwargs): ++ """The new-style print function for Python 2.4 and 2.5.""" ++ fp = kwargs.pop("file", sys.stdout) ++ if fp is None: ++ return ++ ++ def write(data): ++ if not isinstance(data, basestring): ++ data = str(data) ++ # If the file has an encoding, encode unicode with it. ++ if (isinstance(fp, file) and ++ isinstance(data, unicode) and ++ fp.encoding is not None): ++ errors = getattr(fp, "errors", None) ++ if errors is None: ++ errors = "strict" ++ data = data.encode(fp.encoding, errors) ++ fp.write(data) ++ want_unicode = False ++ sep = kwargs.pop("sep", None) ++ if sep is not None: ++ if isinstance(sep, unicode): ++ want_unicode = True ++ elif not isinstance(sep, str): ++ raise TypeError("sep must be None or a string") ++ end = kwargs.pop("end", None) ++ if end is not None: ++ if isinstance(end, unicode): ++ want_unicode = True ++ elif not isinstance(end, str): ++ raise TypeError("end must be None or a string") ++ if kwargs: ++ raise TypeError("invalid keyword arguments to print()") ++ if not want_unicode: ++ for arg in args: ++ if isinstance(arg, unicode): ++ want_unicode = True ++ break ++ if want_unicode: ++ newline = unicode("\n") ++ space = unicode(" ") ++ else: ++ newline = "\n" ++ space = " " ++ if sep is None: ++ sep = space ++ if end is None: ++ end = newline ++ for i, arg in enumerate(args): ++ if i: ++ write(sep) ++ write(arg) ++ write(end) ++if sys.version_info[:2] < (3, 3): ++ _print = print_ ++ ++ def print_(*args, **kwargs): ++ fp = kwargs.get("file", sys.stdout) ++ flush = kwargs.pop("flush", False) ++ _print(*args, **kwargs) ++ if flush and fp is not None: ++ fp.flush() ++ ++_add_doc(reraise, """Reraise an exception.""") ++ ++if sys.version_info[0:2] < (3, 4): ++ def wraps(wrapped, assigned=functools.WRAPPER_ASSIGNMENTS, ++ updated=functools.WRAPPER_UPDATES): ++ def wrapper(f): ++ f = functools.wraps(wrapped, assigned, updated)(f) ++ f.__wrapped__ = wrapped ++ return f ++ return wrapper ++else: ++ wraps = functools.wraps ++ ++ ++def with_metaclass(meta, *bases): ++ """Create a base class with a metaclass.""" ++ # This requires a bit of explanation: the basic idea is to make a dummy ++ # metaclass for one level of class instantiation that replaces itself with ++ # the actual metaclass. ++ class metaclass(meta): ++ ++ def __new__(cls, name, this_bases, d): ++ return meta(name, bases, d) ++ return type.__new__(metaclass, 'temporary_class', (), {}) ++ ++ ++def add_metaclass(metaclass): ++ """Class decorator for creating a class with a metaclass.""" ++ def wrapper(cls): ++ orig_vars = cls.__dict__.copy() ++ slots = orig_vars.get('__slots__') ++ if slots is not None: ++ if isinstance(slots, str): ++ slots = [slots] ++ for slots_var in slots: ++ orig_vars.pop(slots_var) ++ orig_vars.pop('__dict__', None) ++ orig_vars.pop('__weakref__', None) ++ return metaclass(cls.__name__, cls.__bases__, orig_vars) ++ return wrapper ++ ++ ++def python_2_unicode_compatible(klass): ++ """ ++ A decorator that defines __unicode__ and __str__ methods under Python 2. ++ Under Python 3 it does nothing. ++ ++ To support Python 2 and 3 with a single code base, define a __str__ method ++ returning text and apply this decorator to the class. ++ """ ++ if PY2: ++ if '__str__' not in klass.__dict__: ++ raise ValueError("@python_2_unicode_compatible cannot be applied " ++ "to %s because it doesn't define __str__()." % ++ klass.__name__) ++ klass.__unicode__ = klass.__str__ ++ klass.__str__ = lambda self: self.__unicode__().encode('utf-8') ++ return klass ++ ++ ++# Complete the moves implementation. ++# This code is at the end of this module to speed up module loading. ++# Turn this module into a package. ++__path__ = [] # required for PEP 302 and PEP 451 ++__package__ = __name__ # see PEP 366 @ReservedAssignment ++if globals().get("__spec__") is not None: ++ __spec__.submodule_search_locations = [] # PEP 451 @UndefinedVariable ++# Remove other six meta path importers, since they cause problems. This can ++# happen if six is removed from sys.modules and then reloaded. (Setuptools does ++# this for some reason.) ++if sys.meta_path: ++ for i, importer in enumerate(sys.meta_path): ++ # Here's some real nastiness: Another "instance" of the six module might ++ # be floating around. Therefore, we can't use isinstance() to check for ++ # the six meta path importer, since the other six instance will have ++ # inserted an importer with different class. ++ if (type(importer).__name__ == "_SixMetaPathImporter" and ++ importer.name == __name__): ++ del sys.meta_path[i] ++ break ++ del i, importer ++# Finally, add the importer to the meta path import hook. ++sys.meta_path.append(_importer) |