Commit 28e39abf authored by dbeam's avatar dbeam Committed by Commit bot

Revert of [Template Expressions] changing ${ leader to $i18n{ (patchset #4...

Revert of [Template Expressions] changing ${ leader to $i18n{ (patchset #4 id:60001 of https://codereview.chromium.org/1585923011/ )

Reason for revert:
broke incognito NTP and chrome://apps
https://code.google.com/p/chromium/issues/detail?id=581621

Original issue's description:
> [Template Expressions] changing ${ leader to $i18n{
>
> This CL changes the Template Expressions from using
> a ${ to identify the start of an expression, to using
> $i18n{.  The intention is to reduce (eliminate) false
> positives when searching for expressions that need
> replacement.  This CL also prepares for the replacement
> work to be done in a background thread and used on a
> broader set of files.
>
> BUG=506009
>
> Committed: https://crrev.com/5aa7fd5f14e49c65ebba87e4248424d622b92930
> Cr-Commit-Position: refs/heads/master@{#371537}

TBR=thakis@chromium.org,dschuyler@chromium.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=506009

Review URL: https://codereview.chromium.org/1647583003

Cr-Commit-Position: refs/heads/master@{#371888}
parent d680edc4
...@@ -5,21 +5,21 @@ ...@@ -5,21 +5,21 @@
html { html {
background-attachment: fixed; background-attachment: fixed;
background-color: $i18n{colorBackground}; background-color: ${colorBackground};
background-position: $i18n{backgroundBarDetached}; background-position: ${backgroundBarDetached};
background-repeat: $i18n{backgroundTiling}; background-repeat: ${backgroundTiling};
height: 100%; height: 100%;
overflow: auto; overflow: auto;
} }
html[hascustombackground='true'] { html[hascustombackground='true'] {
background-image: url(chrome://theme/IDR_THEME_NTP_BACKGROUND?$i18n{themeId}); background-image: url(chrome://theme/IDR_THEME_NTP_BACKGROUND?${themeId});
} }
html[bookmarkbarattached='true'] { html[bookmarkbarattached='true'] {
background-position: $i18n{backgroundBarAttached}; background-position: ${backgroundBarAttached};
} }
#attribution-img { #attribution-img {
content: url(chrome://theme/IDR_THEME_NTP_ATTRIBUTION?$i18n{themeId}); content: url(chrome://theme/IDR_THEME_NTP_ATTRIBUTION?${themeId});
} }
/* Copyright 2012 The Chromium Authors. All rights reserved. /* Copyright (c) 2012 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be * Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. */ * found in the LICENSE file. */
html { html {
background-attachment: fixed; background-attachment: fixed;
background-color: $i18n{colorBackground}; background-color: ${colorBackground};
background-image: url(chrome://theme/IDR_THEME_NTP_BACKGROUND?$i18n{themeId}); background-image: url(chrome://theme/IDR_THEME_NTP_BACKGROUND?${themeId});
background-position: $i18n{backgroundBarDetached}; background-position: ${backgroundBarDetached};
background-repeat: $i18n{backgroundTiling}; background-repeat: ${backgroundTiling};
} }
#attribution { #attribution {
left: $i18n{leftAlignAttribution}; left: ${leftAlignAttribution};
right: $i18n{rightAlignAttribution}; right: ${rightAlignAttribution};
text-align: $i18n{textAlignAttribution}; text-align: ${textAlignAttribution};
display: $i18n{displayAttribution}; display: ${displayAttribution};
} }
#attribution-img { #attribution-img {
content: url(chrome://theme/IDR_THEME_NTP_ATTRIBUTION?$i18n{themeId}); content: url(chrome://theme/IDR_THEME_NTP_ATTRIBUTION?${themeId});
} }
html[bookmarkbarattached='true'] { html[bookmarkbarattached='true'] {
background-position: $i18n{backgroundBarAttached}; background-position: ${backgroundBarAttached};
} }
body { body {
color: $i18n{colorTextRgba}; color: ${colorTextRgba};
height: 100%; height: 100%;
overflow: auto; overflow: auto;
} }
#attribution, #attribution,
[is='action-link'] { [is='action-link'] {
color: $i18n{colorTextLight}; color: ${colorTextLight};
} }
[is='action-link']:active { [is='action-link']:active {
color: $i18n{colorTextRgba}; color: ${colorTextRgba};
} }
.page-switcher { .page-switcher {
color: rgba($i18n{colorText}, 0.5); color: rgba(${colorText}, 0.5);
} }
.page-switcher:hover, .page-switcher:hover,
.page-switcher:focus, .page-switcher:focus,
.page-switcher.drag-target { .page-switcher.drag-target {
background-color: rgba($i18n{colorText}, 0.06); background-color: rgba(${colorText}, 0.06);
} }
/* Only change the background to a gradient when a promo is showing. */ /* Only change the background to a gradient when a promo is showing. */
...@@ -55,34 +55,34 @@ body { ...@@ -55,34 +55,34 @@ body {
.showing-login-area #page-switcher-end:focus, .showing-login-area #page-switcher-end:focus,
.showing-login-area #page-switcher-end.drag-target { .showing-login-area #page-switcher-end.drag-target {
background: linear-gradient(top, background: linear-gradient(top,
rgba($i18n{colorText}, 0) 0, rgba(${colorText}, 0) 0,
rgba($i18n{colorText}, .01) 60px, rgba(${colorText}, .01) 60px,
rgba($i18n{colorText}, .06) 183px); rgba(${colorText}, .06) 183px);
} }
.tile-page-scrollbar { .tile-page-scrollbar {
background-color: $i18n{colorTextLight}; background-color: ${colorTextLight};
} }
/* Footer *********************************************************************/ /* Footer *********************************************************************/
#footer-border { #footer-border {
background: linear-gradient(left, background: linear-gradient(left,
rgba($i18n{colorSectionBorder}, 0.2), rgba(${colorSectionBorder}, 0.2),
rgba($i18n{colorSectionBorder}, 0.3) 20%, rgba(${colorSectionBorder}, 0.3) 20%,
rgba($i18n{colorSectionBorder}, 0.3) 80%, rgba(${colorSectionBorder}, 0.3) 80%,
rgba($i18n{colorSectionBorder}, 0.2)); rgba(${colorSectionBorder}, 0.2));
} }
.dot input:focus { .dot input:focus {
background-color: $i18n{colorBackground}; background-color: ${colorBackground};
} }
.thumbnail-wrapper { .thumbnail-wrapper {
/* This shows through at the (rounded) thumbnail's corners. */ /* This shows through at the (rounded) thumbnail's corners. */
background-color: $i18n{colorSectionBorder}; background-color: ${colorSectionBorder};
} }
.filler .thumbnail { .filler .thumbnail {
border-color: $i18n{colorBackground}; border-color: ${colorBackground};
} }
// Copyright 2012 The Chromium Authors. All rights reserved. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -553,7 +553,7 @@ void NTPResourceCache::CreateNewTabIncognitoCSS() { ...@@ -553,7 +553,7 @@ void NTPResourceCache::CreateNewTabIncognitoCSS() {
: SkColorSetRGB(0x32, 0x32, 0x32); : SkColorSetRGB(0x32, 0x32, 0x32);
// Generate the replacements. // Generate the replacements.
ui::TemplateReplacements substitutions; std::map<base::StringPiece, std::string> substitutions;
// Cache-buster for background. // Cache-buster for background.
substitutions["themeId"] = substitutions["themeId"] =
...@@ -605,7 +605,7 @@ void NTPResourceCache::CreateNewTabCSS() { ...@@ -605,7 +605,7 @@ void NTPResourceCache::CreateNewTabCSS() {
SkColorGetB(color_header)); SkColorGetB(color_header));
// Generate the replacements. // Generate the replacements.
ui::TemplateReplacements substitutions; std::map<base::StringPiece, std::string> substitutions;
// Cache-buster for background. // Cache-buster for background.
substitutions["themeId"] = substitutions["themeId"] =
......
# Copyright 2012 The Chromium Authors. All rights reserved. # Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
...@@ -55,7 +55,7 @@ class CSSChecker(object): ...@@ -55,7 +55,7 @@ class CSSChecker(object):
return re.sub(re.compile(r'--[\d\w-]+: {.*?};', re.DOTALL), '', s) return re.sub(re.compile(r'--[\d\w-]+: {.*?};', re.DOTALL), '', s)
def _remove_template_expressions(s): def _remove_template_expressions(s):
return re.sub(re.compile(r'\$i18n{[^}]*}', re.DOTALL), '', s) return re.sub(re.compile(r'\${[^}]*}', re.DOTALL), '', s)
def _remove_grit(s): def _remove_grit(s):
grit_reg = re.compile(r""" grit_reg = re.compile(r"""
......
...@@ -8,36 +8,29 @@ ...@@ -8,36 +8,29 @@
#include "base/logging.h" #include "base/logging.h"
namespace {
const char kLeader[] = "$i18n{";
const size_t kLeaderSize = arraysize(kLeader) - 1;
const char kTail[] = "}";
const size_t kTailSize = arraysize(kTail) - 1;
} // namespace
namespace ui { namespace ui {
std::string ReplaceTemplateExpressions( std::string ReplaceTemplateExpressions(
base::StringPiece format_string, base::StringPiece format_string,
const TemplateReplacements& substitutions) { const std::map<base::StringPiece, std::string>& substitutions) {
std::string formatted; std::string formatted;
const size_t kValueLengthGuess = 16; const size_t kValueLengthGuess = 16;
formatted.reserve(format_string.length() + formatted.reserve(format_string.length() +
substitutions.size() * kValueLengthGuess); substitutions.size() * kValueLengthGuess);
base::StringPiece::const_iterator i = format_string.begin(); base::StringPiece::const_iterator i = format_string.begin();
while (i < format_string.end()) { while (i < format_string.end()) {
if (base::StringPiece(i).starts_with(kLeader)) { if (*i == '$' && i + 2 < format_string.end() && i[1] == '{' &&
size_t key_start = i + kLeaderSize - format_string.begin(); i[2] != '}') {
size_t key_length = format_string.find(kTail, key_start); size_t key_start = i + strlen("${") - format_string.begin();
size_t key_length = format_string.find('}', key_start);
if (key_length == base::StringPiece::npos) if (key_length == base::StringPiece::npos)
NOTREACHED() << "TemplateExpression missing ending tag"; NOTREACHED() << "TemplateExpression missing ending brace '}'";
key_length -= key_start; key_length -= key_start;
std::string key(format_string.begin() + key_start, key_length); base::StringPiece key(format_string.begin() + key_start, key_length);
DCHECK(!key.empty());
const auto& replacement = substitutions.find(key); const auto& replacement = substitutions.find(key);
if (replacement != substitutions.end()) { if (replacement != substitutions.end()) {
formatted.append(replacement->second); formatted.append(replacement->second);
i += kLeaderSize + key_length + kTailSize; i += strlen("${") + key_length + strlen("}");
continue; continue;
} else { } else {
NOTREACHED() << "TemplateExpression key not found: " << key; NOTREACHED() << "TemplateExpression key not found: " << key;
......
...@@ -16,15 +16,12 @@ ...@@ -16,15 +16,12 @@
namespace ui { namespace ui {
// Map of strings for template replacement in |ReplaceTemplateExpressions|.
typedef std::map<const std::string, std::string> TemplateReplacements;
// Replace ${foo} in the format string with the value for the foo key in // Replace ${foo} in the format string with the value for the foo key in
// |subst|. If the key is not found in the |substitutions| that item will // |subst|. If the key is not found in the |substitutions| that item will
// be unaltered. // be unaltered.
UI_BASE_EXPORT std::string ReplaceTemplateExpressions( UI_BASE_EXPORT std::string ReplaceTemplateExpressions(
base::StringPiece format_string, base::StringPiece format_string,
const TemplateReplacements& substitutions); const std::map<base::StringPiece, std::string>& substitutions);
} // namespace ui } // namespace ui
......
...@@ -9,26 +9,27 @@ ...@@ -9,26 +9,27 @@
namespace ui { namespace ui {
TEST(TemplateExpressionsTest, ReplaceTemplateExpressionsPieces) { TEST(TemplateExpressionsTest, ReplaceTemplateExpressionsPieces) {
TemplateReplacements substitutions; std::map<base::StringPiece, std::string> substitutions;
substitutions["test"] = "word"; substitutions["test"] = "word";
substitutions["5"] = "number"; substitutions["5"] = "number";
EXPECT_EQ("${}", ReplaceTemplateExpressions("${}", substitutions));
EXPECT_EQ("", ReplaceTemplateExpressions("", substitutions)); EXPECT_EQ("", ReplaceTemplateExpressions("", substitutions));
EXPECT_EQ("word", ReplaceTemplateExpressions("$i18n{test}", substitutions)); EXPECT_EQ("word", ReplaceTemplateExpressions("${test}", substitutions));
EXPECT_EQ("number ", ReplaceTemplateExpressions("$i18n{5} ", substitutions)); EXPECT_EQ("number ", ReplaceTemplateExpressions("${5} ", substitutions));
EXPECT_EQ("multiple: word, number.", EXPECT_EQ(
ReplaceTemplateExpressions("multiple: $i18n{test}, $i18n{5}.", "multiple: word, number.",
substitutions)); ReplaceTemplateExpressions("multiple: ${test}, ${5}.", substitutions));
} }
TEST(TemplateExpressionsTest, TEST(TemplateExpressionsTest,
ReplaceTemplateExpressionsConsecutiveDollarSignsPieces) { ReplaceTemplateExpressionsConsecutiveDollarSignsPieces) {
TemplateReplacements substitutions; std::map<base::StringPiece, std::string> substitutions;
substitutions["a"] = "x"; substitutions["a"] = "x";
EXPECT_EQ("$ $$ $$$", ReplaceTemplateExpressions("$ $$ $$$", substitutions)); EXPECT_EQ("$ $$ $$$", ReplaceTemplateExpressions("$ $$ $$$", substitutions));
EXPECT_EQ("$x", ReplaceTemplateExpressions("$$i18n{a}", substitutions)); EXPECT_EQ("$x", ReplaceTemplateExpressions("$${a}", substitutions));
EXPECT_EQ("$$x", ReplaceTemplateExpressions("$$$i18n{a}", substitutions)); EXPECT_EQ("$$x", ReplaceTemplateExpressions("$$${a}", substitutions));
EXPECT_EQ("$i18n12", ReplaceTemplateExpressions("$i18n12", substitutions)); EXPECT_EQ("$12", ReplaceTemplateExpressions("$12", substitutions));
} }
} // namespace ui } // namespace ui
...@@ -123,7 +123,7 @@ void SetLoadTimeDataDefaults(const std::string& app_locale, ...@@ -123,7 +123,7 @@ void SetLoadTimeDataDefaults(const std::string& app_locale,
} }
std::string GetWebUiCssTextDefaults(const std::string& css_template) { std::string GetWebUiCssTextDefaults(const std::string& css_template) {
ui::TemplateReplacements placeholders; std::map<base::StringPiece, std::string> placeholders;
placeholders["textDirection"] = GetTextDirection(); placeholders["textDirection"] = GetTextDirection();
placeholders["fontFamily"] = GetFontFamily(); placeholders["fontFamily"] = GetFontFamily();
placeholders["fontSize"] = GetFontSize(); placeholders["fontSize"] = GetFontSize();
......
...@@ -16,14 +16,14 @@ ...@@ -16,14 +16,14 @@
* Otherwise its $placeholders won't be expanded. */ * Otherwise its $placeholders won't be expanded. */
html { html {
direction: $i18n{textDirection}; direction: ${textDirection};
} }
body { body {
font-family: $i18n{fontFamily}; font-family: ${fontFamily};
font-size: $i18n{fontSize}; font-size: ${fontSize};
} }
button { button {
font-family: $i18n{fontFamily}; font-family: ${fontFamily};
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment