d03991846b9510bb6b3453aa053e292a0aeabc07 - chromium/src

1,797 views
Skip to first unread message

bau...@chromium.org

unread,
Jan 26, 2015, 5:23:26 AM1/26/15
to chromium...@chromium.org
commit d03991846b9510bb6b3453aa053e292a0aeabc07
Author: bauerb <bau...@chromium.org>
AuthorDate: Mon Jan 26 10:20:45 2015
Commit: Commit bot <commi...@chromium.org>
CommitDate: Mon Jan 26 10:22:14 2015

Directly inline shared WebUI CSS declarations into the security and supervised user interstitials.

BUG=446599,443203

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

Cr-Commit-Position: refs/heads/master@{#313058}

diff --git a/chrome/browser/interstitials/security_interstitial_page.cc b/chrome/browser/interstitials/security_interstitial_page.cc
index 5132196..dbc248a 100644
--- a/chrome/browser/interstitials/security_interstitial_page.cc
+++ b/chrome/browser/interstitials/security_interstitial_page.cc
@@ -64,8 +64,9 @@
base::DictionaryValue load_time_data;
PopulateInterstitialStrings(&load_time_data);
webui::SetFontAndTextDirection(&load_time_data);
- base::StringPiece html(
- ResourceBundle::GetSharedInstance().GetRawDataResource(
- IDR_SECURITY_INTERSTITIAL_HTML));
+ std::string html = ResourceBundle::GetSharedInstance()
+ .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_HTML)
+ .as_string();
+ webui::AppendWebUiCssTextDefaults(&html);
return webui::GetI18nTemplateHtml(html, &load_time_data);
}
diff --git a/chrome/browser/resources/security_warnings/interstitial_v2.html b/chrome/browser/resources/security_warnings/interstitial_v2.html
index 245bf0d..0b384dc 100644
--- a/chrome/browser/resources/security_warnings/interstitial_v2.html
+++ b/chrome/browser/resources/security_warnings/interstitial_v2.html
@@ -12,9 +12,7 @@
<script src="safe_browsing.js"></script>
<script src="interstitial_v2.js"></script>
</head>
-<!-- TODO(jshin): Get rid of i18n-values and import default_text.css instead
- once interstitial page loading does not use data url any more. -->
-<body id="body" i18n-values=".style.fontFamily:fontfamily;.style.fontSize:fontsize">
+<body id="body">
<div class="interstitial-wrapper">
<div class="icon" id="icon"></div>
<div id="main-message">
diff --git a/chrome/browser/resources/supervised_user_block_interstitial.html b/chrome/browser/resources/supervised_user_block_interstitial.html
index a242583..18a9059 100644
--- a/chrome/browser/resources/supervised_user_block_interstitial.html
+++ b/chrome/browser/resources/supervised_user_block_interstitial.html
@@ -11,9 +11,7 @@
<script src="supervised_user_block_interstitial.js"></script>
</head>

-<!-- TODO(jshin): Get rid of i18n-values and import default_text.css instead
- once interstitial page loading does not use data url any more. -->
-<body i18n-values=".style.fontFamily:fontfamily">
+<body>
<div id="main-frame-blocked">
<div id="box">
<div id="content-top">
diff --git a/chrome/browser/supervised_user/supervised_user_interstitial.cc b/chrome/browser/supervised_user/supervised_user_interstitial.cc
index 5572eba..96d022d 100644
--- a/chrome/browser/supervised_user/supervised_user_interstitial.cc
+++ b/chrome/browser/supervised_user/supervised_user_interstitial.cc
@@ -269,8 +269,11 @@

webui::SetFontAndTextDirection(&strings);

- base::StringPiece html(ResourceBundle::GetSharedInstance().GetRawDataResource(
- IDR_SUPERVISED_USER_BLOCK_INTERSTITIAL_HTML));
+ std::string html =
+ ResourceBundle::GetSharedInstance()
+ .GetRawDataResource(IDR_SUPERVISED_USER_BLOCK_INTERSTITIAL_HTML)
+ .as_string();
+ webui::AppendWebUiCssTextDefaults(&html);

return webui::GetI18nTemplateHtml(html, &strings);
}
diff --git a/content/browser/webui/shared_resources_data_source.cc b/content/browser/webui/shared_resources_data_source.cc
index 66fe0f1..e11c6b1 100644
--- a/content/browser/webui/shared_resources_data_source.cc
+++ b/content/browser/webui/shared_resources_data_source.cc
@@ -85,17 +85,8 @@
scoped_refptr<base::RefCountedMemory> bytes;

if (idr == IDR_WEBUI_CSS_TEXT_DEFAULTS) {
- std::vector<std::string> placeholders;
- placeholders.push_back(webui::GetTextDirection()); // $1
- placeholders.push_back(webui::GetFontFamily()); // $2
- placeholders.push_back(webui::GetFontSize()); // $3
-
- ContentClient* content_client = GetContentClient();
- const std::string& chrome_shared =
- content_client->GetDataResource(idr, ui::SCALE_FACTOR_NONE).as_string();
- std::string replaced =
- ReplaceStringPlaceholders(chrome_shared, placeholders, nullptr);
- bytes = base::RefCountedString::TakeString(&replaced);
+ std::string css = webui::GetWebUiCssTextDefaults();
+ bytes = base::RefCountedString::TakeString(&css);
} else {
bytes = GetContentClient()->GetDataResourceBytes(idr);
}
diff --git a/ui/base/webui/web_ui_util.cc b/ui/base/webui/web_ui_util.cc
index 0c5b9f0..3382a30 100644
--- a/ui/base/webui/web_ui_util.cc
+++ b/ui/base/webui/web_ui_util.cc
@@ -12,6 +12,7 @@
#include "base/logging.h"
#include "base/memory/ref_counted_memory.h"
#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_util.h"
#include "net/base/escape.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
@@ -19,6 +20,7 @@
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/font.h"
#include "ui/gfx/image/image_skia.h"
+#include "ui/resources/grit/webui_resources.h"
#include "ui/strings/grit/app_locale_settings.h"
#include "url/gurl.h"

@@ -129,6 +131,33 @@
}
}

+void SetFontAndTextDirection(base::DictionaryValue* localized_strings) {
+ localized_strings->SetString("fontfamily", GetFontFamily());
+ localized_strings->SetString("fontsize", GetFontSize());
+ localized_strings->SetString("textdirection", GetTextDirection());
+}
+
+std::string GetWebUiCssTextDefaults() {
+ std::vector<std::string> placeholders;
+ placeholders.push_back(GetTextDirection()); // $1
+ placeholders.push_back(GetFontFamily()); // $2
+ placeholders.push_back(GetFontSize()); // $3
+
+ const ui::ResourceBundle& resource_bundle =
+ ui::ResourceBundle::GetSharedInstance();
+ const std::string& css_template =
+ resource_bundle.GetRawDataResource(IDR_WEBUI_CSS_TEXT_DEFAULTS)
+ .as_string();
+
+ return ReplaceStringPlaceholders(css_template, placeholders, nullptr);
+}
+
+void AppendWebUiCssTextDefaults(std::string* html) {
+ html->append("<style>");
+ html->append(GetWebUiCssTextDefaults());
+ html->append("</style>");
+}
+
std::string GetFontFamily() {
std::string font_family = l10n_util::GetStringUTF8(
#if defined(OS_WIN)
@@ -162,12 +191,6 @@

std::string GetTextDirection() {
return base::i18n::IsRTL() ? "rtl" : "ltr";
-}
-
-void SetFontAndTextDirection(base::DictionaryValue* localized_strings) {
- localized_strings->SetString("fontfamily", GetFontFamily());
- localized_strings->SetString("fontsize", GetFontSize());
- localized_strings->SetString("textdirection", GetTextDirection());
}

} // namespace webui
diff --git a/ui/base/webui/web_ui_util.h b/ui/base/webui/web_ui_util.h
index 84e06f3..2dbcfc7 100644
--- a/ui/base/webui/web_ui_util.h
+++ b/ui/base/webui/web_ui_util.h
@@ -47,9 +47,20 @@

// Helper function to set the font family, size, and text direction into the
// given dictionary.
+// Note that using font family and size in JS templates is deprecated, because
+// it might lead to flicker. Instead, use AppendWebUICSSTextDefaults() below.
+// TODO(bauerb): Remove uses of font-family and font-size in JS templates, then
+// rename this method to SetTextDirection().
UI_BASE_EXPORT void SetFontAndTextDirection(
base::DictionaryValue* localized_strings);

+// Get a CSS declaration for common text styles for all of Web UI.
+UI_BASE_EXPORT std::string GetWebUiCssTextDefaults();
+
+// Appends the CSS declaration returned by GetWebUiCssTextDefaults() as an
+// inline stylesheet.
+UI_BASE_EXPORT void AppendWebUiCssTextDefaults(std::string* html);
+
// Get some common font styles for all of WebUI.
UI_BASE_EXPORT std::string GetFontFamily();
UI_BASE_EXPORT std::string GetFontSize();
diff --git a/ui/webui/resources/css/text_defaults.css b/ui/webui/resources/css/text_defaults.css
index 3e9007a..682a858 100644
--- a/ui/webui/resources/css/text_defaults.css
+++ b/ui/webui/resources/css/text_defaults.css
@@ -6,11 +6,14 @@
* some per-platform/locale styles that dramatically alter the page. This is
* done to reduce flicker, as JS may not run before the page is rendered.
*
- * Include this stylesheet via its chrome://resources/ URL, i.e.:
+ * There are two ways to include this stylesheet:
+ * 1. via its chrome://resources/ URL in HTML, i.e.:
*
- * <link rel="stylesheet" href="chrome://resources/css/font_defaults.css">
+ * <link rel="stylesheet" href="chrome://resources/css/text_defaults.css">
*
- * otherwise its $placeholders wont be expanded. */
+ * 2. via the webui::AppendWebUICSSTextDefaults() method to directly append it
+ * to an HTML string.
+ * Otherwise its $placeholders won't be expanded. */

html {
direction: $1;
Message has been deleted
Message has been deleted

Taydan Tull

unread,
Nov 3, 2021, 2:06:36 PM11/3/21
to Chromium-checkins, bau...@chromium.org
hay bitch, whats up do a thing on ixl for me
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Josiah McDuffie

unread,
Feb 3, 2022, 3:22:33 PM2/3/22
to Chromium-checkins, Taydan Tull, bau...@chromium.org
shut it plz thx
Reply all
Reply to author
Forward
Message has been deleted
0 new messages