blob: 59beadaaf0064a76f0ebf900649e736dd26adee0 [file] [log] [blame]
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/title_origin_label.h"
#include "ui/base/ui_base_features.h"
std::unique_ptr<views::Label> CreateTitleOriginLabel(
const std::u16string& text) {
auto label =
std::make_unique<views::Label>(text, views::style::CONTEXT_DIALOG_TITLE);
label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
label->SetCollapseWhenHidden(true);
// Elide from head in order to keep the most significant part of the origin
// and avoid spoofing. Note that in English, GetWindowTitle() returns a
// string
// "$ORIGIN wants to", so the "wants to" will not be elided. In other
// languages, the non-origin part may appear fully or partly before the
// origin (e.g., in Filipino, "Gusto ng $ORIGIN na"), which means it may be
// elided. This is not optimal, but it is necessary to avoid origin
// spoofing. See crbug.com/774438.
label->SetElideBehavior(gfx::ELIDE_HEAD);
// Multiline breaks elision, which would mean a very long origin gets
// truncated from the least significant side. Explicitly disable multiline.
label->SetMultiLine(false);
if (features::IsChromeRefresh2023()) {
label->SetTextStyle(views::style::STYLE_HEADLINE_4);
}
return label;
}