Commit e07342bd authored by Mugdha Lakhani's avatar Mugdha Lakhani Committed by Commit Bot

[WebLayer] Reland: Show security icon.

There was a naming conflict with url_bar.xml from chrome:// which caused some
chrome smoke tests to fail. This CL fixes that and tries to reland the
original change.

Descrption from the original commit:
UrlBarView is now a LinearLayout with its own resource XML. It contains
a security icon (currently always the lock icon) and a TextView
containing current display URL.

Here's a recording of the UI after this change:
https://drive.google.com/a/google.com/file/d/1q8IzYALoPYd8KLcln4cMEnRjIT6ox_so/view?usp=sharing

TBR=dtrainor@chromium.org,tommycli@chromium.org

Bug: 1025607
Change-Id: I47f94905de9a220f02a589814a7eada550e1b303
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2049980
Commit-Queue: Mugdha Lakhani <nator@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741444}
parent 26c3e288
......@@ -155,6 +155,7 @@ android_resources("chrome_app_java_resources") {
"//components/browser_ui/widget/android:java_resources",
"//components/find_in_page/android:java_resources",
"//components/javascript_dialogs/android:java_resources",
"//components/omnibox/browser:java_resources",
"//components/policy:app_restrictions_resources",
"//components/strings:components_locale_settings_grd",
"//components/strings:components_strings_grd",
......@@ -431,7 +432,6 @@ android_library("chrome_java") {
"//components/payments/content/android:error_strings_generated_srcjar",
"//components/payments/content/android:method_strings_generated_srcjar",
"//components/search_engines:search_engine_type_java",
"//components/security_state/core:security_state_enums_java",
"//components/signin/core/browser:signin_enums_javagen",
"//components/ui_metrics:ui_metrics_enums_java",
"//content/public/browser:contacts_picker_properties_requested_javagen",
......@@ -2875,6 +2875,7 @@ android_library("native_java_unittests_java") {
"//chrome/browser/flags:java",
"//chrome/browser/util:java",
"//chrome/test/android:chrome_java_test_support",
"//components/omnibox/browser:browser_java",
"//components/payments/content/android:java",
"//content/public/android:content_java",
"//content/public/test/android:android_test_message_pump_support_java",
......
......@@ -37,6 +37,7 @@ import org.chromium.chrome.browser.util.UrlConstants;
import org.chromium.chrome.browser.util.UrlUtilities;
import org.chromium.components.browser_ui.styles.ChromeColors;
import org.chromium.components.dom_distiller.core.DomDistillerUrlUtils;
import org.chromium.components.omnibox.SecurityStatusIcon;
import org.chromium.components.security_state.ConnectionSecurityLevel;
import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.util.ColorUtils;
......@@ -411,31 +412,20 @@ public class LocationBarModel implements ToolbarDataProvider, ToolbarCommonPrope
return R.drawable.ic_offline_pin_24dp;
}
switch (securityLevel) {
case ConnectionSecurityLevel.NONE:
return isSmallDevice
&& (!SearchEngineLogoUtils.shouldShowSearchEngineLogo(isIncognito())
|| getNewTabPageForCurrentTab() != null)
? 0
: R.drawable.omnibox_info;
case ConnectionSecurityLevel.WARNING:
if (mNativeLocationBarModelAndroid == 0) {
return R.drawable.omnibox_info;
}
if (SecurityStateModel.shouldShowDangerTriangleForWarningLevel()) {
return R.drawable.omnibox_not_secure_warning;
}
return R.drawable.omnibox_info;
case ConnectionSecurityLevel.DANGEROUS:
return R.drawable.omnibox_not_secure_warning;
case ConnectionSecurityLevel.SECURE_WITH_POLICY_INSTALLED_CERT:
case ConnectionSecurityLevel.SECURE:
case ConnectionSecurityLevel.EV_SECURE:
return R.drawable.omnibox_https_valid;
default:
assert false;
// Return early if native initialization hasn't been done yet.
if ((securityLevel == ConnectionSecurityLevel.NONE
|| securityLevel == ConnectionSecurityLevel.WARNING)
&& mNativeLocationBarModelAndroid == 0) {
return R.drawable.omnibox_info;
}
return 0;
boolean skipIconForNeutralState =
!SearchEngineLogoUtils.shouldShowSearchEngineLogo(isIncognito())
|| getNewTabPageForCurrentTab() != null;
return SecurityStatusIcon.getSecurityIconResource(securityLevel,
SecurityStateModel.shouldShowDangerTriangleForWarningLevel(), isSmallDevice,
skipIconForNeutralState);
}
@Override
......
......@@ -269,17 +269,27 @@ jumbo_static_library("browser") {
}
if (is_android) {
android_resources("java_resources") {
resource_dirs = [ "android/java/res" ]
custom_package = "org.chromium.components.omnibox"
}
android_library("browser_java") {
sources = [
"android/java/src/org/chromium/components/omnibox/SecurityStatusIcon.java",
"android/java/src/org/chromium/components/omnibox/SuggestionAnswer.java",
]
deps = [
":java_resources",
"//base:base_java",
"//third_party/android_deps:com_android_support_support_compat_java",
]
srcjar_deps = [ ":browser_java_enums_srcjar" ]
srcjar_deps = [
":browser_java_enums_srcjar",
"//components/security_state/core:security_state_enums_java",
]
}
java_cpp_enum("browser_java_enums_srcjar") {
......
// Copyright 2020 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.
package org.chromium.components.omnibox;
import androidx.annotation.DrawableRes;
import org.chromium.components.security_state.ConnectionSecurityLevel;
/** Utility class to get security state info for the omnibox. */
public class SecurityStatusIcon {
@DrawableRes
public static int getSecurityIconResource(@ConnectionSecurityLevel int securityLevel,
boolean shouldShowDangerTriangleForWarningLevel, boolean isSmallDevice,
boolean skipIconForNeutralState) {
switch (securityLevel) {
case ConnectionSecurityLevel.NONE:
if (isSmallDevice && skipIconForNeutralState) return 0;
return R.drawable.omnibox_info;
case ConnectionSecurityLevel.WARNING:
if (shouldShowDangerTriangleForWarningLevel) {
return R.drawable.omnibox_not_secure_warning;
}
return R.drawable.omnibox_info;
case ConnectionSecurityLevel.DANGEROUS:
return R.drawable.omnibox_not_secure_warning;
case ConnectionSecurityLevel.SECURE_WITH_POLICY_INSTALLED_CERT:
case ConnectionSecurityLevel.SECURE:
case ConnectionSecurityLevel.EV_SECURE:
return R.drawable.omnibox_https_valid;
default:
assert false;
}
return 0;
}
}
......@@ -244,6 +244,7 @@ jumbo_static_library("weblayer_lib") {
"//components/security_interstitials/content:security_interstitial_page",
"//components/security_interstitials/content/renderer:security_interstitial_page_controller",
"//components/security_interstitials/core",
"//components/security_state/content",
"//components/sessions",
"//components/spellcheck:buildflags",
"//components/ssl_errors",
......
include_rules = [
"+components/omnibox/browser",
"+components/security_state/core/security_state.h",
"+third_party/metrics_proto/omnibox_input_type.pb.h",
]
\ No newline at end of file
......@@ -21,6 +21,8 @@ include_rules = [
"+components/safe_browsing/core/common",
"+components/safe_browsing/core/features.h",
"+components/security_interstitials",
"+components/security_state/content/content_utils.h",
"+components/security_state/core/security_state.h",
"+components/sessions",
"+components/spellcheck/browser",
"+components/ssl_errors",
......
......@@ -7,7 +7,7 @@ import("//build/config/android/rules.gni")
import("//weblayer/variables.gni")
android_resources("weblayer_resources") {
resource_dirs = []
resource_dirs = [ "res" ]
custom_package = "org.chromium.weblayer_private"
}
......@@ -80,6 +80,7 @@ android_library("java") {
"//components/javascript_dialogs/android:java",
"//components/metrics:metrics_java",
"//components/minidump_uploader:minidump_uploader_java",
"//components/omnibox/browser:browser_java",
"//components/security_interstitials/content/android:java",
"//components/spellcheck/browser/android:java",
"//components/variations/android:variations_java",
......@@ -87,6 +88,7 @@ android_library("java") {
"//content/public/android:content_java",
"//net/android:net_java",
"//third_party/android_deps:com_android_support_support_compat_java",
"//ui/android:ui_full_java",
"//ui/android:ui_java",
]
srcjar_deps = [
......
......@@ -16,6 +16,7 @@ import org.chromium.base.ObserverList;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.ui.base.DeviceFormFactor;
import org.chromium.ui.base.WindowAndroid;
import org.chromium.weblayer_private.interfaces.APICallException;
import org.chromium.weblayer_private.interfaces.IBrowser;
......@@ -206,6 +207,11 @@ public class BrowserImpl extends IBrowser.Stub {
return mWindowAndroid.getContext().get();
}
public boolean isWindowOnSmallDevice() {
assert mWindowAndroid != null;
return !DeviceFormFactor.isWindowOnTablet(mWindowAndroid);
}
@Override
public IProfile getProfile() {
StrictModeWorkaround.apply();
......
......@@ -8,11 +8,17 @@ import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.DrawableRes;
import org.chromium.base.LifetimeAssert;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.components.omnibox.SecurityStatusIcon;
import org.chromium.weblayer_private.interfaces.IObjectWrapper;
import org.chromium.weblayer_private.interfaces.IUrlBarController;
import org.chromium.weblayer_private.interfaces.ObjectWrapper;
......@@ -66,15 +72,19 @@ public class UrlBarControllerImpl extends IUrlBarController.Stub {
}
protected class UrlBarView
extends TextView implements BrowserImpl.VisibleSecurityStateObserver {
extends LinearLayout implements BrowserImpl.VisibleSecurityStateObserver {
private float mTextSize;
private TextView mUrlTextView;
private ImageButton mSecurityButton;
public UrlBarView(@NonNull Context context, Bundle options) {
super(context);
mTextSize = options.getFloat(URL_TEXT_SIZE, DEFAULT_TEXT_SIZE);
View.inflate(getContext(), R.layout.weblayer_url_bar, this);
mUrlTextView = findViewById(R.id.url_text);
mSecurityButton = (ImageButton) findViewById(R.id.security_button);
updateView();
mTextSize = options.getFloat(URL_TEXT_SIZE, DEFAULT_TEXT_SIZE);
setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.max(MINIMUM_TEXT_SIZE, mTextSize));
}
// BrowserImpl.VisibleSecurityStateObserver
......@@ -100,12 +110,28 @@ public class UrlBarControllerImpl extends IUrlBarController.Stub {
}
private void updateView() {
// TODO(crbug.com/1025607): Add a way to get a formatted URL based
// on mOptions.
if (mBrowserImpl == null) return;
String displayUrl =
UrlBarControllerImplJni.get().getUrlForDisplay(mNativeUrlBarController);
setText(displayUrl);
mUrlTextView.setText(displayUrl);
mUrlTextView.setTextSize(
TypedValue.COMPLEX_UNIT_SP, Math.max(MINIMUM_TEXT_SIZE, mTextSize));
mSecurityButton.setImageResource(getSecurityIcon());
// TODO(crbug.com/1025607): Set content description for accessibility, and a click
// listener.
}
@DrawableRes
private int getSecurityIcon() {
return SecurityStatusIcon.getSecurityIconResource(
UrlBarControllerImplJni.get().getConnectionSecurityLevel(
mNativeUrlBarController),
UrlBarControllerImplJni.get().shouldShowDangerTriangleForWarningLevel(
mNativeUrlBarController),
mBrowserImpl.isWindowOnSmallDevice(),
/* skipIconForNeutralState= */ true);
}
}
......@@ -114,5 +140,7 @@ public class UrlBarControllerImpl extends IUrlBarController.Stub {
long createUrlBarController(long browserPtr);
void deleteUrlBarController(long urlBarControllerImplPtr);
String getUrlForDisplay(long nativeUrlBarControllerImpl);
int getConnectionSecurityLevel(long nativeUrlBarControllerImpl);
boolean shouldShowDangerTriangleForWarningLevel(long nativeUrlBarControllerImpl);
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2020 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. -->
<!-- The background of the top-view must be opaque, otherwise it bleeds through to the
cc::Layer that mirrors the contents of the top-view. -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFc9c9c9"
android:orientation="horizontal">
<ImageButton
tools:ignore="ContentDescription"
android:id="@+id/security_button"
android:layout_width="15dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" />
<TextView
android:id="@+id/url_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:gravity="center_vertical"/>
</LinearLayout>
......@@ -8,6 +8,8 @@
#include "base/strings/utf_string_conversions.h"
#include "components/omnibox/browser/autocomplete_input.h"
#include "components/omnibox/browser/location_bar_model_impl.h"
#include "components/security_state/content/content_utils.h"
#include "components/security_state/core/security_state.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_constants.h"
#include "weblayer/browser/browser_impl.h"
......@@ -59,18 +61,39 @@ UrlBarControllerImpl::GetUrlForDisplay(JNIEnv* env) {
return base::android::ScopedJavaLocalRef<jstring>(
base::android::ConvertUTF16ToJavaString(env, GetUrlForDisplay()));
}
jint UrlBarControllerImpl::GetConnectionSecurityLevel(JNIEnv* env) {
return GetConnectionSecurityLevel();
}
jboolean UrlBarControllerImpl::ShouldShowDangerTriangleForWarningLevel(
JNIEnv* env) {
return ShouldShowDangerTriangleForWarningLevel();
}
#endif
base::string16 UrlBarControllerImpl::GetUrlForDisplay() {
return location_bar_model_->GetURLForDisplay();
}
bool UrlBarControllerImpl::GetURL(GURL* url) const {
auto* active_tab = static_cast<TabImpl*>(browser_->GetActiveTab());
if (!active_tab)
return false;
security_state::SecurityLevel
UrlBarControllerImpl::GetConnectionSecurityLevel() {
auto* active_web_contents = GetActiveWebContents();
if (!active_web_contents)
return security_state::SecurityLevel::NONE;
auto* active_web_contents = active_tab->web_contents();
auto state = security_state::GetVisibleSecurityState(active_web_contents);
DCHECK(state);
return security_state::GetSecurityLevel(
*state, /* used_policy_installed_certificate= */ false);
}
bool UrlBarControllerImpl::ShouldShowDangerTriangleForWarningLevel() {
return security_state::ShouldShowDangerTriangleForWarningLevel();
}
bool UrlBarControllerImpl::GetURL(GURL* url) const {
auto* active_web_contents = GetActiveWebContents();
if (!active_web_contents)
return false;
......@@ -90,4 +113,12 @@ base::string16 UrlBarControllerImpl::FormattedStringWithEquivalentMeaning(
url, formatted_url, AutocompleteSchemeClassifierImpl(), nullptr);
}
content::WebContents* UrlBarControllerImpl::GetActiveWebContents() const {
auto* active_tab = static_cast<TabImpl*>(browser_->GetActiveTab());
if (!active_tab)
return nullptr;
return active_tab->web_contents();
}
} // namespace weblayer
......@@ -15,6 +15,10 @@
#include "base/android/scoped_java_ref.h"
#endif
namespace content {
class WebContents;
}
namespace weblayer {
class BrowserImpl;
......@@ -28,10 +32,14 @@ class UrlBarControllerImpl : public UrlBarController,
#if defined(OS_ANDROID)
base::android::ScopedJavaLocalRef<jstring> GetUrlForDisplay(JNIEnv* env);
jint GetConnectionSecurityLevel(JNIEnv* env);
jboolean ShouldShowDangerTriangleForWarningLevel(JNIEnv* env);
#endif
// UrlBarController:
base::string16 GetUrlForDisplay() override;
security_state::SecurityLevel GetConnectionSecurityLevel() override;
bool ShouldShowDangerTriangleForWarningLevel() override;
// LocationBarModelDelegate:
bool GetURL(GURL* url) const override;
......@@ -41,6 +49,7 @@ class UrlBarControllerImpl : public UrlBarController,
const base::string16& formatted_url) const override;
private:
content::WebContents* GetActiveWebContents() const;
BrowserImpl* const browser_;
std::unique_ptr<LocationBarModelImpl> location_bar_model_;
};
......
......@@ -6,6 +6,7 @@
#define WEBLAYER_PUBLIC_URL_BAR_CONTROLLER_H_
#include "base/strings/string16.h"
#include "components/security_state/core/security_state.h"
namespace weblayer {
......@@ -17,6 +18,8 @@ class UrlBarController {
virtual ~UrlBarController() {}
virtual base::string16 GetUrlForDisplay() = 0;
virtual security_state::SecurityLevel GetConnectionSecurityLevel() = 0;
virtual bool ShouldShowDangerTriangleForWarningLevel() = 0;
};
} // namespace weblayer
......
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