Commit e712abd4 authored by Shakti Sahu's avatar Shakti Sahu Committed by Commit Bot

Added security icon for ephemeral tab

This CL adds :
1 - Security icon and URL for the preview page
2 - Updates title of the page when navigated to another page

Bug: 1007499
Change-Id: I069e57e545907b2000eaebe996392d72da40d6b9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1844341Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarDonn Denman <donnd@chromium.org>
Reviewed-by: default avatarJinsuk Kim <jinsukkim@chromium.org>
Reviewed-by: default avatarChristopher Thompson <cthomp@chromium.org>
Commit-Queue: Shakti Sahu <shaktisahu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705130}
parent 63990472
...@@ -7,14 +7,14 @@ ...@@ -7,14 +7,14 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:paddingBottom="30dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="86dp"> android:layout_height="100dp"
android:paddingBottom="30dp">
<LinearLayout <LinearLayout
android:id="@+id/toolbar" android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height_no_shadow" android:layout_height="@dimen/preview_tab_toolbar_height"
android:orientation="vertical"> android:orientation="vertical">
<View <View
...@@ -23,16 +23,16 @@ ...@@ -23,16 +23,16 @@
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="48dp" android:layout_height="62dp"
android:orientation="horizontal"> android:orientation="horizontal">
<org.chromium.ui.widget.ChromeImageView <org.chromium.ui.widget.ChromeImageView
android:id="@+id/favicon" android:id="@+id/favicon"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_centerVertical="true"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:layout_marginTop="12dp"
android:padding="12dp" android:padding="12dp"
android:src="@drawable/ic_chrome" android:src="@drawable/ic_chrome"
app:tint="@color/default_icon_color_blue" app:tint="@color/default_icon_color_blue"
...@@ -57,19 +57,41 @@ ...@@ -57,19 +57,41 @@
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:padding="12dp" android:padding="12dp"
android:src="@drawable/open_in_new_tab" android:src="@drawable/open_in_new_tab"
app:tint="@color/default_icon_color" android:contentDescription="@string/contextmenu_open_in_new_tab"
tools:ignore="ContentDescription" /> app:tint="@color/default_icon_color" />
<TextView <TextView
android:id="@+id/ephemeral_tab_text" android:id="@+id/ephemeral_tab_text"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="12dp" android:layout_marginTop="16dp"
android:layout_toStartOf="@id/open_in_new_tab" android:layout_toStartOf="@id/open_in_new_tab"
android:layout_toEndOf="@id/favicon" android:layout_toEndOf="@id/favicon"
android:ellipsize="end" android:ellipsize="end"
android:singleLine="true" android:singleLine="true"
android:textAppearance="@style/TextAppearance.BlackTitle1" /> android:textAppearance="@style/TextAppearance.BlackBodyDefault" />
<org.chromium.ui.widget.ChromeImageView
android:id="@+id/security_icon"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_below="@id/ephemeral_tab_text"
android:layout_toEndOf="@id/favicon"
android:layout_marginTop="4dp"
app:tint="@color/default_icon_color" />
<TextView
android:id="@+id/ephemeral_tab_caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toStartOf="@id/open_in_new_tab"
android:layout_toEndOf="@id/security_icon"
android:layout_below="@id/ephemeral_tab_text"
android:layout_marginLeft="4dp"
android:ellipsize="start"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.BlackHint2" />
</RelativeLayout> </RelativeLayout>
<View <View
...@@ -90,6 +112,6 @@ ...@@ -90,6 +112,6 @@
android:id="@+id/shadow" android:id="@+id/shadow"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/action_bar_shadow_height" android:layout_height="@dimen/action_bar_shadow_height"
android:layout_marginTop="@dimen/toolbar_height_no_shadow"/> android:layout_marginTop="@dimen/preview_tab_toolbar_height"/>
</FrameLayout> </FrameLayout>
...@@ -136,6 +136,9 @@ ...@@ -136,6 +136,9 @@
<!-- Overlay panel dimensions --> <!-- Overlay panel dimensions -->
<dimen name="overlay_panel_bar_height_legacy">56dp</dimen> <dimen name="overlay_panel_bar_height_legacy">56dp</dimen>
<dimen name="overlay_panel_bar_height">70dp</dimen> <dimen name="overlay_panel_bar_height">70dp</dimen>
<!-- Preview tab dimensions -->
<dimen name="preview_tab_toolbar_height">70dp</dimen>
<dimen name="preview_tab_favicon_size">24dp</dimen> <dimen name="preview_tab_favicon_size">24dp</dimen>
<!-- Autofill keyboard accessory dimensions --> <!-- Autofill keyboard accessory dimensions -->
......
...@@ -59,6 +59,12 @@ public class OverlayContentDelegate { ...@@ -59,6 +59,12 @@ public class OverlayContentDelegate {
*/ */
public void onVisibilityChanged(boolean isVisible) {} public void onVisibilityChanged(boolean isVisible) {}
/**
* Called when the SSL state changes.
*/
public void onSSLStateUpdated() {}
/** /**
* Called once the WebContents has been seen. * Called once the WebContents has been seen.
*/ */
......
...@@ -196,6 +196,11 @@ public class OverlayPanelContent { ...@@ -196,6 +196,11 @@ public class OverlayPanelContent {
mProgressObserver.onProgressBarUpdated(progress); mProgressObserver.onProgressBarUpdated(progress);
} }
@Override
public void visibleSSLStateChanged() {
mContentDelegate.onSSLStateUpdated();
}
@Override @Override
public void enterFullscreenModeForTab(boolean prefersNavigationBar) { public void enterFullscreenModeForTab(boolean prefersNavigationBar) {
mIsFullscreen = true; mIsFullscreen = true;
......
...@@ -7,6 +7,8 @@ package org.chromium.chrome.browser.compositor.bottombar.ephemeraltab; ...@@ -7,6 +7,8 @@ package org.chromium.chrome.browser.compositor.bottombar.ephemeraltab;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Handler; import android.os.Handler;
import android.support.annotation.DrawableRes;
import android.text.TextUtils;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.chrome.R; import org.chromium.chrome.R;
...@@ -17,18 +19,19 @@ import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelContent; ...@@ -17,18 +19,19 @@ import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelContent;
import org.chromium.chrome.browser.favicon.FaviconHelper; import org.chromium.chrome.browser.favicon.FaviconHelper;
import org.chromium.chrome.browser.favicon.FaviconUtils; import org.chromium.chrome.browser.favicon.FaviconUtils;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.ssl.SecurityStateModel;
import org.chromium.chrome.browser.tabmodel.TabLaunchType; import org.chromium.chrome.browser.tabmodel.TabLaunchType;
import org.chromium.chrome.browser.ui.widget.RoundedIconGenerator; import org.chromium.chrome.browser.ui.widget.RoundedIconGenerator;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet; import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController; import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver; import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver;
import org.chromium.components.embedder_support.view.ContentView; import org.chromium.components.embedder_support.view.ContentView;
import org.chromium.components.security_state.ConnectionSecurityLevel;
import org.chromium.content_public.browser.LoadUrlParams; import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.browser.NavigationHandle;
import org.chromium.content_public.browser.WebContentsObserver;
import org.chromium.ui.base.PageTransition; import org.chromium.ui.base.PageTransition;
import java.net.MalformedURLException;
import java.net.URL;
/** /**
* Central class for ephemeral tab, responsible for spinning off other classes necessary to display * Central class for ephemeral tab, responsible for spinning off other classes necessary to display
* the preview tab UI. * the preview tab UI.
...@@ -42,6 +45,7 @@ public class EphemeralTabCoordinator { ...@@ -42,6 +45,7 @@ public class EphemeralTabCoordinator {
private final BottomSheetController mBottomSheetController; private final BottomSheetController mBottomSheetController;
private final FaviconLoader mFaviconLoader; private final FaviconLoader mFaviconLoader;
private OverlayPanelContent mPanelContent; private OverlayPanelContent mPanelContent;
private WebContentsObserver mWebContentsObserver;
private EphemeralTabSheetContent mSheetContent; private EphemeralTabSheetContent mSheetContent;
private boolean mIsIncognito; private boolean mIsIncognito;
private String mUrl; private String mUrl;
...@@ -81,9 +85,10 @@ public class EphemeralTabCoordinator { ...@@ -81,9 +85,10 @@ public class EphemeralTabCoordinator {
getContent().loadUrl(url, true); getContent().loadUrl(url, true);
getContent().updateBrowserControlsState(true); getContent().updateBrowserControlsState(true);
if (mWebContentsObserver == null) mWebContentsObserver = createWebContentsObserver();
mSheetContent.attachWebContents( mSheetContent.attachWebContents(
getContent().getWebContents(), (ContentView) getContent().getContainerView()); getContent().getWebContents(), (ContentView) getContent().getContainerView());
mSheetContent.setTitleText(title); mSheetContent.updateTitle(title);
mBottomSheetController.requestShowContent(mSheetContent, true); mBottomSheetController.requestShowContent(mSheetContent, true);
// TODO(donnd): Collect UMA with OverlayPanel.StateChangeReason.CLICK. // TODO(donnd): Collect UMA with OverlayPanel.StateChangeReason.CLICK.
...@@ -109,6 +114,11 @@ public class EphemeralTabCoordinator { ...@@ -109,6 +114,11 @@ public class EphemeralTabCoordinator {
mPanelContent.destroy(); mPanelContent.destroy();
mPanelContent = null; mPanelContent = null;
} }
if (mWebContentsObserver != null) {
mWebContentsObserver.destroy();
mWebContentsObserver = null;
}
} }
private void openInNewTab() { private void openInNewTab() {
...@@ -136,6 +146,40 @@ public class EphemeralTabCoordinator { ...@@ -136,6 +146,40 @@ public class EphemeralTabCoordinator {
mSheetContent.startFaviconAnimation(drawable); mSheetContent.startFaviconAnimation(drawable);
} }
private WebContentsObserver createWebContentsObserver() {
return new WebContentsObserver(mPanelContent.getWebContents()) {
@Override
public void titleWasSet(String title) {
mSheetContent.updateTitle(title);
}
@Override
public void didFinishNavigation(NavigationHandle navigation) {
if (navigation.hasCommitted() && navigation.isInMainFrame()) {
mSheetContent.updateURL(mPanelContent.getWebContents().getVisibleUrl());
}
}
};
}
@DrawableRes
private static int getSecurityIconResource(@ConnectionSecurityLevel int securityLevel) {
switch (securityLevel) {
case ConnectionSecurityLevel.NONE:
case ConnectionSecurityLevel.WARNING:
return R.drawable.omnibox_info;
case ConnectionSecurityLevel.DANGEROUS:
return R.drawable.omnibox_https_invalid;
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;
}
/** /**
* Observes the ephemeral tab web contents and loads the associated favicon. * Observes the ephemeral tab web contents and loads the associated favicon.
*/ */
...@@ -144,16 +188,18 @@ public class EphemeralTabCoordinator { ...@@ -144,16 +188,18 @@ public class EphemeralTabCoordinator {
@Override @Override
public void onMainFrameLoadStarted(String url, boolean isExternalUrl) { public void onMainFrameLoadStarted(String url, boolean isExternalUrl) {
try { if (TextUtils.equals(mCurrentUrl, url)) return;
String newHost = new URL(url).getHost();
String curHost = mCurrentUrl == null ? null : new URL(mCurrentUrl).getHost();
if (!newHost.equals(curHost)) {
mCurrentUrl = url; mCurrentUrl = url;
mFaviconLoader.loadFavicon(url, (drawable) -> onFaviconAvailable(drawable)); mFaviconLoader.loadFavicon(url, (drawable) -> onFaviconAvailable(drawable));
} }
} catch (MalformedURLException e) {
assert false : "Malformed URL should not be passed."; @Override
} public void onSSLStateUpdated() {
int securityLevel = SecurityStateModel.getSecurityLevelForWebContents(
mPanelContent.getWebContents());
mSheetContent.setSecurityIcon(getSecurityIconResource(securityLevel));
mSheetContent.updateURL(mPanelContent.getWebContents().getVisibleUrl());
} }
} }
......
...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.compositor.bottombar.ephemeraltab; ...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.compositor.bottombar.ephemeraltab;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable; import android.graphics.drawable.TransitionDrawable;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
...@@ -24,6 +25,7 @@ import org.chromium.chrome.browser.ui.widget.FadingShadow; ...@@ -24,6 +25,7 @@ import org.chromium.chrome.browser.ui.widget.FadingShadow;
import org.chromium.chrome.browser.ui.widget.FadingShadowView; import org.chromium.chrome.browser.ui.widget.FadingShadowView;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet; import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet;
import org.chromium.components.embedder_support.view.ContentView; import org.chromium.components.embedder_support.view.ContentView;
import org.chromium.components.url_formatter.UrlFormatter;
import org.chromium.content_public.browser.RenderCoordinates; import org.chromium.content_public.browser.RenderCoordinates;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.ActivityWindowAndroid; import org.chromium.ui.base.ActivityWindowAndroid;
...@@ -87,7 +89,7 @@ public class EphemeralTabSheetContent implements BottomSheet.BottomSheetContent ...@@ -87,7 +89,7 @@ public class EphemeralTabSheetContent implements BottomSheet.BottomSheetContent
mSheetContentView.addView(mThinWebView.getView()); mSheetContentView.addView(mThinWebView.getView());
int topPadding = int topPadding =
mContext.getResources().getDimensionPixelSize(R.dimen.toolbar_height_no_shadow); mContext.getResources().getDimensionPixelSize(R.dimen.preview_tab_toolbar_height);
mSheetContentView.setPadding(0, topPadding, 0, 0); mSheetContentView.setPadding(0, topPadding, 0, 0);
} }
...@@ -127,9 +129,21 @@ public class EphemeralTabSheetContent implements BottomSheet.BottomSheetContent ...@@ -127,9 +129,21 @@ public class EphemeralTabSheetContent implements BottomSheet.BottomSheetContent
} }
/** Sets the ephemeral tab title text. */ /** Sets the ephemeral tab title text. */
public void setTitleText(String text) { public void updateTitle(String title) {
TextView toolbarText = mToolbarView.findViewById(R.id.ephemeral_tab_text); TextView toolbarText = mToolbarView.findViewById(R.id.ephemeral_tab_text);
toolbarText.setText(text); toolbarText.setText(title);
}
/** Sets the ephemeral tab URL. */
public void updateURL(String url) {
TextView caption = mToolbarView.findViewById(R.id.ephemeral_tab_caption);
caption.setText(UrlFormatter.formatUrlForSecurityDisplayOmitScheme(url));
}
/** Sets the security icon. */
public void setSecurityIcon(@DrawableRes int resId) {
ImageView securityIcon = mToolbarView.findViewById(R.id.security_icon);
securityIcon.setImageResource(resId);
} }
/** Sets the progress percentage on the progress bar. */ /** Sets the progress percentage on the progress bar. */
......
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