Commit 8c135aaa authored by Joel Hockey's avatar Joel Hockey Committed by Commit Bot

Refactor terminal settings access into crostini_terminal

Move background-color lookup into crostini_terminal
since we are also adding pass-ctrl-w and it is
better to colocate them.

Bug: 1060861
Change-Id: Id55c9672007cabcb635fce7022d64544b1158f62
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2121115
Auto-Submit: Joel Hockey <joelhockey@chromium.org>
Commit-Queue: Jason Lin <lxj@google.com>
Reviewed-by: default avatarJason Lin <lxj@google.com>
Cr-Commit-Position: refs/heads/master@{#753783}
parent 104cef17
......@@ -33,6 +33,10 @@
namespace {
constexpr char kSettingPrefix[] = "/hterm/profiles/default/";
const size_t kSettingPrefixSize = base::size(kSettingPrefix) - 1;
constexpr char kSettingBackgroundColor[] =
"/hterm/profiles/default/background-color";
constexpr char kDefaultBackgroundColor[] = "#101010";
} // namespace
namespace crostini {
......@@ -236,4 +240,11 @@ void RecordTerminalSettingsChangesUMAs(Profile* profile) {
}
}
std::string GetTerminalSettingBackgroundColor(Profile* profile) {
const base::DictionaryValue* value = profile->GetPrefs()->GetDictionary(
crostini::prefs::kCrostiniTerminalSettings);
const std::string* result = value->FindStringKey(kSettingBackgroundColor);
return result ? *result : kDefaultBackgroundColor;
}
} // namespace crostini
......@@ -130,6 +130,8 @@ void LaunchTerminalSettings(Profile* profile);
// Record which terminal settings have been changed by users.
void RecordTerminalSettingsChangesUMAs(Profile* profile);
// Returns terminal setting 'background-color'.
std::string GetTerminalSettingBackgroundColor(Profile* profile);
} // namespace crostini
#endif // CHROME_BROWSER_CHROMEOS_CROSTINI_CROSTINI_TERMINAL_H_
......@@ -13,7 +13,7 @@
#include "base/task/post_task.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "chrome/browser/chromeos/crostini/crostini_pref_names.h"
#include "chrome/browser/chromeos/crostini/crostini_terminal.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/url_constants.h"
#include "chrome/common/webui_url_constants.h"
......@@ -30,8 +30,6 @@ constexpr base::FilePath::CharType kTerminalRoot[] =
constexpr base::FilePath::CharType kDefaultFile[] =
FILE_PATH_LITERAL("html/crosh.html");
constexpr char kDefaultMime[] = "text/html";
constexpr char kDefaultTheme[] = "#101010";
constexpr char kPrefKeyTheme[] = "/hterm/profiles/default/background-color";
void ReadFile(const std::string& relative_path,
content::URLDataSource::GotDataCallback callback) {
......@@ -105,8 +103,10 @@ void TerminalSource::StartDataRequest(
path = kDefaultFile;
// Replace $i8n{themeColor} in *.html.
if (base::EndsWith(path, ".html", base::CompareCase::INSENSITIVE_ASCII))
replacements_["themeColor"] = GetThemeColorFromPrefs();
if (base::EndsWith(path, ".html", base::CompareCase::INSENSITIVE_ASCII)) {
replacements_["themeColor"] = net::EscapeForHTML(
crostini::GetTerminalSettingBackgroundColor(profile_));
}
base::ThreadPool::PostTask(
FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_BLOCKING},
......@@ -129,10 +129,3 @@ bool TerminalSource::ShouldServeMimeTypeAsContentTypeHeader() {
const ui::TemplateReplacements* TerminalSource::GetReplacements() {
return &replacements_;
}
std::string TerminalSource::GetThemeColorFromPrefs() {
const base::DictionaryValue* value = profile_->GetPrefs()->GetDictionary(
crostini::prefs::kCrostiniTerminalSettings);
const std::string* theme = value->FindStringKey(kPrefKeyTheme);
return theme ? net::EscapeForHTML(*theme) : kDefaultTheme;
}
......@@ -37,10 +37,6 @@ class TerminalSource : public content::URLDataSource {
bool ShouldServeMimeTypeAsContentTypeHeader() override;
const ui::TemplateReplacements* GetReplacements() override;
// Get theme color from terminal settings in prefs (with HTML escaping).
// Returns default theme '#101010' if no prefs set.
std::string GetThemeColorFromPrefs();
Profile* profile_;
ui::TemplateReplacements replacements_;
......
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