Commit 666fbc65 authored by fgorski's avatar fgorski Committed by Commit bot

[Offline pages] Reinstating the offline icon on tablet and fixing verbose state/URL emphasis

This patch addresses the following problems:
* Offline icon is not shown in omnibox on tablets
* Offline verbose status is sometimes shown with green padlock
* URL emphasis lags behind security icon update.

This fix does the following:
* Moves the offline icon from the navigation button to security button
* Ensures that navigation button is never shown on phones
* Calculates when to show: navigation/security/no button, to properly
  show or hide icon container.
* Moves verbose status visibility control to security button related
  code (as that is where we show offline stuff and would show verbose
  security states)

BUG=656088,648129
R=tedchoc@chromium.org

Review-Url: https://codereview.chromium.org/2438413002
Cr-Commit-Position: refs/heads/master@{#427209}
parent 9154331c
...@@ -497,22 +497,16 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar, ...@@ -497,22 +497,16 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
mSecurityIconType = securityLevel; mSecurityIconType = securityLevel;
boolean isSmallDevice = !DeviceFormFactor.isTablet(getContext());
boolean isOfflinePage = getCurrentTab() != null && getCurrentTab().isOfflinePage(); boolean isOfflinePage = getCurrentTab() != null && getCurrentTab().isOfflinePage();
boolean showSecurityButton = securityLevel != ConnectionSecurityLevel.NONE || isOfflinePage;
if (securityLevel == ConnectionSecurityLevel.NONE) { int id = LocationBarLayout.getSecurityIconResource(
if (isOfflinePage && mShowsOfflinePage != isOfflinePage) { securityLevel, isSmallDevice, isOfflinePage);
TintedDrawable bolt = TintedDrawable.constructTintedDrawable( boolean showSecurityButton = true;
getResources(), R.drawable.offline_pin);
bolt.setTint(mUseDarkColors ? mDarkModeTint : mLightModeTint);
mSecurityButton.setImageDrawable(bolt);
}
} else {
boolean isSmallDevice = !DeviceFormFactor.isTablet(getContext());
int id = LocationBarLayout.getSecurityIconResource(securityLevel, isSmallDevice);
if (id == 0) { if (id == 0) {
// Hide the button if we don't have an actual icon to display. // Hide the button if we don't have an actual icon to display.
showSecurityButton = false; showSecurityButton = false;
mSecurityButton.setImageDrawable(null);
} else { } else {
// ImageView#setImageResource is no-op if given resource is the current one. // ImageView#setImageResource is no-op if given resource is the current one.
mSecurityButton.setImageResource(id); mSecurityButton.setImageResource(id);
...@@ -520,7 +514,6 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar, ...@@ -520,7 +514,6 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
LocationBarLayout.getColorStateList(securityLevel, getToolbarDataProvider(), LocationBarLayout.getColorStateList(securityLevel, getToolbarDataProvider(),
getResources(), false /* omnibox is not opaque */)); getResources(), false /* omnibox is not opaque */));
} }
}
mShowsOfflinePage = isOfflinePage; mShowsOfflinePage = isOfflinePage;
......
...@@ -18,6 +18,7 @@ import org.chromium.chrome.browser.tab.Tab; ...@@ -18,6 +18,7 @@ import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.toolbar.ToolbarModel.ToolbarModelDelegate; import org.chromium.chrome.browser.toolbar.ToolbarModel.ToolbarModelDelegate;
import org.chromium.components.dom_distiller.core.DomDistillerService; import org.chromium.components.dom_distiller.core.DomDistillerService;
import org.chromium.components.dom_distiller.core.DomDistillerUrlUtils; import org.chromium.components.dom_distiller.core.DomDistillerUrlUtils;
import org.chromium.components.security_state.ConnectionSecurityLevel;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
/** /**
...@@ -107,7 +108,8 @@ class ToolbarModelImpl extends ToolbarModel implements ToolbarDataProvider, Tool ...@@ -107,7 +108,8 @@ class ToolbarModelImpl extends ToolbarModel implements ToolbarDataProvider, Tool
displayText = displayText =
DomDistillerTabUtils.getFormattedUrlFromOriginalDistillerUrl(originalUrl); DomDistillerTabUtils.getFormattedUrlFromOriginalDistillerUrl(originalUrl);
} }
} else if (mTab.isOfflinePage()) { } else if (mTab.isOfflinePage()
&& mTab.getSecurityLevel() == ConnectionSecurityLevel.NONE) {
String originalUrl = mTab.getOriginalUrl(); String originalUrl = mTab.getOriginalUrl();
displayText = OfflinePageUtils.stripSchemeFromOnlineUrl( displayText = OfflinePageUtils.stripSchemeFromOnlineUrl(
DomDistillerTabUtils.getFormattedUrlFromOriginalDistillerUrl(originalUrl)); DomDistillerTabUtils.getFormattedUrlFromOriginalDistillerUrl(originalUrl));
......
...@@ -150,7 +150,7 @@ public class WebappUrlBar extends FrameLayout implements View.OnLayoutChangeList ...@@ -150,7 +150,7 @@ public class WebappUrlBar extends FrameLayout implements View.OnLayoutChangeList
private void updateSecurityIcon(int securityLevel) { private void updateSecurityIcon(int securityLevel) {
boolean isSmallDevice = !DeviceFormFactor.isTablet(getContext()); boolean isSmallDevice = !DeviceFormFactor.isTablet(getContext());
mCurrentIconResource = mCurrentIconResource =
LocationBarLayout.getSecurityIconResource(securityLevel, isSmallDevice); LocationBarLayout.getSecurityIconResource(securityLevel, isSmallDevice, false);
if (mCurrentIconResource != 0 && mIconResourceWidths.get(mCurrentIconResource, -1) == -1) { if (mCurrentIconResource != 0 && mIconResourceWidths.get(mCurrentIconResource, -1) == -1) {
Drawable icon = ApiCompatibilityUtils.getDrawable(getResources(), mCurrentIconResource); Drawable icon = ApiCompatibilityUtils.getDrawable(getResources(), mCurrentIconResource);
......
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