Commit 1a0e2b69 authored by cjgrant's avatar cjgrant Committed by Commit Bot

Toolbar: Report offline state through icon and verbose text

On Android, pages may be shown from a downloaded offline cache. In this
case, the security chip text and icon change. Reflect this in
ToolbarModel.

With this new ability, render the Offline security information in VR.

BUG=735770

Review-Url: https://codereview.chromium.org/2968143003
Cr-Commit-Position: refs/heads/master@{#485520}
parent b08b2bd5
...@@ -58,6 +58,13 @@ SkColor GetSchemeColor(SecurityLevel level, const ColorScheme& color_scheme) { ...@@ -58,6 +58,13 @@ SkColor GetSchemeColor(SecurityLevel level, const ColorScheme& color_scheme) {
} }
} }
SkColor GetSecurityChipColor(SecurityLevel level,
bool offline_page,
const ColorScheme& color_scheme) {
return offline_page ? color_scheme.url_emphasized
: GetSchemeColor(level, color_scheme);
}
void setEmphasis(vr_shell::RenderTextWrapper* render_text, void setEmphasis(vr_shell::RenderTextWrapper* render_text,
bool emphasis, bool emphasis,
const gfx::Range& range, const gfx::Range& range,
...@@ -81,7 +88,6 @@ UrlBarTexture::UrlBarTexture( ...@@ -81,7 +88,6 @@ UrlBarTexture::UrlBarTexture(
bool web_vr, bool web_vr,
const base::Callback<void(UiUnsupportedMode)>& failure_callback) const base::Callback<void(UiUnsupportedMode)>& failure_callback)
: has_back_button_(!web_vr), : has_back_button_(!web_vr),
has_security_chip_(false),
failure_callback_(failure_callback) {} failure_callback_(failure_callback) {}
UrlBarTexture::~UrlBarTexture() = default; UrlBarTexture::~UrlBarTexture() = default;
...@@ -220,8 +226,8 @@ void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) { ...@@ -220,8 +226,8 @@ void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) {
// Site security state icon. // Site security state icon.
left_edge += kFieldSpacing; left_edge += kFieldSpacing;
if (state_.security_level != security_state::NONE && if ((state_.security_level != security_state::NONE || state_.offline_page) &&
state_.vector_icon != nullptr) { state_.vector_icon != nullptr && state_.should_display_url) {
gfx::RectF icon_region(left_edge, kHeight / 2 - kSecurityIconSize / 2, gfx::RectF icon_region(left_edge, kHeight / 2 - kSecurityIconSize / 2,
kSecurityIconSize, kSecurityIconSize); kSecurityIconSize, kSecurityIconSize);
canvas->save(); canvas->save();
...@@ -230,7 +236,8 @@ void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) { ...@@ -230,7 +236,8 @@ void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) {
float icon_scale = kSecurityIconSize / GetDefaultSizeOfVectorIcon(icon); float icon_scale = kSecurityIconSize / GetDefaultSizeOfVectorIcon(icon);
canvas->scale(icon_scale, icon_scale); canvas->scale(icon_scale, icon_scale);
PaintVectorIcon(&gfx_canvas, icon, PaintVectorIcon(&gfx_canvas, icon,
GetSchemeColor(state_.security_level, color_scheme())); GetSecurityChipColor(state_.security_level,
state_.offline_page, color_scheme()));
canvas->restore(); canvas->restore();
security_hit_region_ = icon_region; security_hit_region_ = icon_region;
...@@ -239,14 +246,21 @@ void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) { ...@@ -239,14 +246,21 @@ void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) {
canvas->restore(); canvas->restore();
// Draw security chip text (eg. "Not secure") next to the security icon. // The security chip text consumes a significant percentage of URL bar text
if (has_security_chip_ && state_.should_display_url) { // space, so they are currently disabled (see crbug.com/734206). The offline
// chip is an exception, and must be shown (see crbug.com/735770).
bool draw_security_chip = state_.offline_page;
// Possibly draw security chip text (eg. "Not secure") next to the security
// icon.
if (draw_security_chip && state_.should_display_url) {
float chip_max_width = kWidth - left_edge - kUrlRightMargin; float chip_max_width = kWidth - left_edge - kUrlRightMargin;
gfx::Rect text_bounds(ToPixels(left_edge), 0, ToPixels(chip_max_width), gfx::Rect text_bounds(ToPixels(left_edge), 0, ToPixels(chip_max_width),
ToPixels(kHeight)); ToPixels(kHeight));
int pixel_font_height = texture_size.height() * kFontHeight / kHeight; int pixel_font_height = texture_size.height() * kFontHeight / kHeight;
SkColor chip_color = GetSchemeColor(state_.security_level, color_scheme()); SkColor chip_color = GetSecurityChipColor(
state_.security_level, state_.offline_page, color_scheme());
const base::string16& chip_text = state_.secure_verbose_text; const base::string16& chip_text = state_.secure_verbose_text;
DCHECK(!chip_text.empty()); DCHECK(!chip_text.empty());
...@@ -300,6 +314,7 @@ void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) { ...@@ -300,6 +314,7 @@ void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) {
void UrlBarTexture::RenderUrl(const gfx::Size& texture_size, void UrlBarTexture::RenderUrl(const gfx::Size& texture_size,
const gfx::Rect& bounds) { const gfx::Rect& bounds) {
url::Parsed parsed; url::Parsed parsed;
const base::string16 text = url_formatter::FormatUrl( const base::string16 text = url_formatter::FormatUrl(
state_.gurl, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::NORMAL, state_.gurl, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::NORMAL,
&parsed, nullptr, nullptr); &parsed, nullptr, nullptr);
......
...@@ -81,7 +81,6 @@ class UrlBarTexture : public UiTexture { ...@@ -81,7 +81,6 @@ class UrlBarTexture : public UiTexture {
GURL last_drawn_gurl_; GURL last_drawn_gurl_;
bool has_back_button_ = true; bool has_back_button_ = true;
bool has_security_chip_ = true;
security_state::SecurityLevel last_drawn_security_level_; security_state::SecurityLevel last_drawn_security_level_;
base::Callback<void(UiUnsupportedMode)> failure_callback_; base::Callback<void(UiUnsupportedMode)> failure_callback_;
gfx::RectF security_hit_region_ = gfx::RectF(0, 0, 0, 0); gfx::RectF security_hit_region_ = gfx::RectF(0, 0, 0, 0);
......
...@@ -32,6 +32,9 @@ ...@@ -32,6 +32,9 @@
<message name="IDS_DANGEROUS_VERBOSE_STATE" desc="Text for the Dangerous Omnibox Verbose State. Displayed when the current page fails the malware check."> <message name="IDS_DANGEROUS_VERBOSE_STATE" desc="Text for the Dangerous Omnibox Verbose State. Displayed when the current page fails the malware check.">
Dangerous Dangerous
</message> </message>
<message name="IDS_OFFLINE_VERBOSE_STATE" desc="Text for the Offline Omnibox Verbose state. Displayed when the current page is loaded from a previously-downloaded cache.">
Offline
</message>
<if expr="is_ios"> <if expr="is_ios">
<message name="IDS_OMNIBOX_EMPTY_HINT" desc="The text displayed in the omnibox when it is empty."> <message name="IDS_OMNIBOX_EMPTY_HINT" desc="The text displayed in the omnibox when it is empty.">
Search or type URL Search or type URL
......
...@@ -24,6 +24,7 @@ aggregate_vector_icons("toolbar_vector_icons") { ...@@ -24,6 +24,7 @@ aggregate_vector_icons("toolbar_vector_icons") {
"https_valid.icon", "https_valid.icon",
"https_valid_in_chip.1x.icon", "https_valid_in_chip.1x.icon",
"https_valid_in_chip.icon", "https_valid_in_chip.icon",
"offline_pin.icon",
"product.1x.icon", "product.1x.icon",
"product.icon", "product.icon",
"star_active.icon", "star_active.icon",
......
...@@ -79,6 +79,9 @@ const gfx::VectorIcon& ToolbarModelImpl::GetVectorIcon() const { ...@@ -79,6 +79,9 @@ const gfx::VectorIcon& ToolbarModelImpl::GetVectorIcon() const {
if (icon_override) if (icon_override)
return *icon_override; return *icon_override;
if (IsOfflinePage())
return toolbar::kOfflinePinIcon;
switch (GetSecurityLevel(false)) { switch (GetSecurityLevel(false)) {
case security_state::NONE: case security_state::NONE:
case security_state::HTTP_SHOW_WARNING: case security_state::HTTP_SHOW_WARNING:
...@@ -121,6 +124,9 @@ base::string16 ToolbarModelImpl::GetEVCertName() const { ...@@ -121,6 +124,9 @@ base::string16 ToolbarModelImpl::GetEVCertName() const {
} }
base::string16 ToolbarModelImpl::GetSecureVerboseText() const { base::string16 ToolbarModelImpl::GetSecureVerboseText() const {
if (IsOfflinePage())
return l10n_util::GetStringUTF16(IDS_OFFLINE_VERBOSE_STATE);
switch (GetSecurityLevel(false)) { switch (GetSecurityLevel(false)) {
case security_state::HTTP_SHOW_WARNING: case security_state::HTTP_SHOW_WARNING:
return l10n_util::GetStringUTF16(IDS_NOT_SECURE_VERBOSE_STATE); return l10n_util::GetStringUTF16(IDS_NOT_SECURE_VERBOSE_STATE);
......
// 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.
CANVAS_DIMENSIONS, 24,
MOVE_TO, 12, 2,
CUBIC_TO, 6.5f, 2, 2, 6.5f, 2, 12,
R_CUBIC_TO, 0, 5.5f, 4.5f, 10, 10, 10,
R_CUBIC_TO, 5.5f, 0, 10, -4.5f, 10, -10,
R_CUBIC_TO, 0, -5.5f, -4.5f, -10, -10, -10,
CLOSE,
R_MOVE_TO, 5, 16,
H_LINE_TO, 7,
R_V_LINE_TO, -2,
R_H_LINE_TO, 10,
R_V_LINE_TO, 2,
CLOSE,
R_MOVE_TO, -6.7f, -4,
LINE_TO, 7, 10.7f,
R_LINE_TO, 1.4f, -1.4f,
R_LINE_TO, 1.9f, 1.9f,
R_LINE_TO, 5.3f, -5.3f,
LINE_TO, 17, 7.3f,
LINE_TO, 10.3f, 14,
CLOSE,
END
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