Commit fb932d15 authored by Theresa Wellington's avatar Theresa Wellington Committed by Commit Bot

[Home] Show zero suggestions on the NTP

Allow zero-query omnibox suggestions to show on the Chrome Home NTP.
This allows the "Link you copied" feature to work in Chrome Home.

BUG=762038

Change-Id: I4c6cc0c1305dea95e7dd3c5c6ba5cc36abd48a36
Reviewed-on: https://chromium-review.googlesource.com/820096Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: Theresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523271}
parent cf1fe8f6
...@@ -1125,10 +1125,12 @@ public class LocationBarLayout extends FrameLayout ...@@ -1125,10 +1125,12 @@ public class LocationBarLayout extends FrameLayout
// now count as a new session. // now count as a new session.
mHasStartedNewOmniboxEditSession = false; mHasStartedNewOmniboxEditSession = false;
mNewOmniboxEditSessionTimestamp = -1; mNewOmniboxEditSessionTimestamp = -1;
if (mNativeInitialized && mUrlHasFocus && mToolbarDataProvider.hasTab()) { if (mNativeInitialized && mUrlHasFocus
&& (mToolbarDataProvider.hasTab()
|| (mBottomSheet != null && mBottomSheet.isShowingNewTab()))) {
mAutocomplete.startZeroSuggest(mToolbarDataProvider.getProfile(), mAutocomplete.startZeroSuggest(mToolbarDataProvider.getProfile(),
mUrlBar.getTextWithAutocomplete(), mToolbarDataProvider.getCurrentUrl(), mUrlBar.getTextWithAutocomplete(), mToolbarDataProvider.getCurrentUrl(),
getCurrentTab().getTitle(), mUrlFocusedFromFakebox); mToolbarDataProvider.getTitle(), mUrlFocusedFromFakebox);
} }
} }
...@@ -2368,12 +2370,9 @@ public class LocationBarLayout extends FrameLayout ...@@ -2368,12 +2370,9 @@ public class LocationBarLayout extends FrameLayout
// If the bottom sheet is managing the display of the suggestions, view visibility does not // If the bottom sheet is managing the display of the suggestions, view visibility does not
// need to be set here. // need to be set here.
if (mBottomSheet != null && mUrlBar != null) { if (mBottomSheet != null && mUrlBar != null) {
// If the NTP is shown, only show the suggestions if there is content in the URL bar.
boolean blockForNTP =
mBottomSheet.isShowingNewTab() && TextUtils.isEmpty(mUrlBar.getText());
boolean showingOmniboxSuggestions = boolean showingOmniboxSuggestions =
mBottomSheet.getCurrentSheetContent() == mOmniboxSuggestionsSheetContent; mBottomSheet.getCurrentSheetContent() == mOmniboxSuggestionsSheetContent;
if (visible && !showingOmniboxSuggestions && !blockForNTP) { if (visible && !showingOmniboxSuggestions) {
mBottomSheet.showContent(mOmniboxSuggestionsSheetContent); mBottomSheet.showContent(mOmniboxSuggestionsSheetContent);
} }
} else { } else {
......
...@@ -45,6 +45,11 @@ class SearchBoxDataProvider implements ToolbarDataProvider { ...@@ -45,6 +45,11 @@ class SearchBoxDataProvider implements ToolbarDataProvider {
return null; return null;
} }
@Override
public String getTitle() {
return "";
}
@Override @Override
public Tab getTab() { public Tab getTab() {
return mTab; return mTab;
......
...@@ -304,17 +304,17 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar, ...@@ -304,17 +304,17 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
@Override @Override
public void setTitleToPageTitle() { public void setTitleToPageTitle() {
Tab currentTab = getToolbarDataProvider().getTab(); String title = getToolbarDataProvider().getTitle();
if (currentTab == null || TextUtils.isEmpty(currentTab.getTitle())) { if (!getToolbarDataProvider().hasTab() || TextUtils.isEmpty(title)) {
mTitleBar.setText(""); mTitleBar.setText("");
return; return;
} }
String title = currentTab.getTitle();
// It takes some time to parse the title of the webcontent, and before that Tab#getTitle // It takes some time to parse the title of the webcontent, and before that
// always return the url. We postpone the title animation until the title is authentic. // ToolbarDataProvider#getTitle always returns the url. We postpone the title animation
// until the title is authentic.
if ((mState == STATE_DOMAIN_AND_TITLE || mState == STATE_TITLE_ONLY) if ((mState == STATE_DOMAIN_AND_TITLE || mState == STATE_TITLE_ONLY)
&& !title.equals(currentTab.getUrl()) && !title.equals(getToolbarDataProvider().getCurrentUrl())
&& !title.equals(ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL)) { && !title.equals(ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL)) {
// Delay the title animation until security icon animation finishes. // Delay the title animation until security icon animation finishes.
ThreadUtils.postOnUiThreadDelayed(mTitleAnimationStarter, TITLE_ANIM_DELAY_MS); ThreadUtils.postOnUiThreadDelayed(mTitleAnimationStarter, TITLE_ANIM_DELAY_MS);
...@@ -347,7 +347,7 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar, ...@@ -347,7 +347,7 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
String url = getCurrentTab().getUrl().trim(); String url = getCurrentTab().getUrl().trim();
if (mState == STATE_TITLE_ONLY) { if (mState == STATE_TITLE_ONLY) {
if (!TextUtils.isEmpty(getCurrentTab().getTitle())) setTitleToPageTitle(); if (!TextUtils.isEmpty(getToolbarDataProvider().getTitle())) setTitleToPageTitle();
} }
// Don't show anything for Chrome URLs and "about:blank". // Don't show anything for Chrome URLs and "about:blank".
......
...@@ -54,6 +54,11 @@ public interface ToolbarDataProvider { ...@@ -54,6 +54,11 @@ public interface ToolbarDataProvider {
*/ */
String getText(); String getText();
/**
* @return The title of the current tab, or the empty string if there is currently no tab.
*/
String getTitle();
/** /**
* @return The primary color to use for the background drawable. * @return The primary color to use for the background drawable.
*/ */
......
...@@ -179,6 +179,11 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar { ...@@ -179,6 +179,11 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
return null; return null;
} }
@Override
public String getTitle() {
return "";
}
@Override @Override
public NewTabPage getNewTabPageForCurrentTab() { public NewTabPage getNewTabPageForCurrentTab() {
return null; return null;
......
...@@ -16,6 +16,7 @@ import org.chromium.base.ContextUtils; ...@@ -16,6 +16,7 @@ import org.chromium.base.ContextUtils;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList; import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.UrlConstants;
import org.chromium.chrome.browser.dom_distiller.DomDistillerServiceFactory; import org.chromium.chrome.browser.dom_distiller.DomDistillerServiceFactory;
import org.chromium.chrome.browser.dom_distiller.DomDistillerTabUtils; import org.chromium.chrome.browser.dom_distiller.DomDistillerTabUtils;
import org.chromium.chrome.browser.locale.LocaleManager; import org.chromium.chrome.browser.locale.LocaleManager;
...@@ -96,7 +97,13 @@ class ToolbarModelImpl extends ToolbarModel implements ToolbarDataProvider, Tool ...@@ -96,7 +97,13 @@ class ToolbarModelImpl extends ToolbarModel implements ToolbarDataProvider, Tool
@Override @Override
public String getCurrentUrl() { public String getCurrentUrl() {
// TODO(yusufo) : Consider using this for all calls from getTab() for accessing url. // TODO(yusufo) : Consider using this for all calls from getTab() for accessing url.
if (!hasTab()) return ""; if (!hasTab()) {
if (mBottomSheet != null && mBottomSheet.isShowingNewTab()) {
return UrlConstants.NTP_URL;
} else {
return "";
}
}
// Tab.getUrl() returns empty string if it does not have a URL. // Tab.getUrl() returns empty string if it does not have a URL.
return getTab().getUrl().trim(); return getTab().getUrl().trim();
} }
...@@ -148,6 +155,14 @@ class ToolbarModelImpl extends ToolbarModel implements ToolbarDataProvider, Tool ...@@ -148,6 +155,14 @@ class ToolbarModelImpl extends ToolbarModel implements ToolbarDataProvider, Tool
return domDistillerService.hasEntry(entryIdFromUrl); return domDistillerService.hasEntry(entryIdFromUrl);
} }
@Override
public String getTitle() {
if (!hasTab()) return "";
String title = getTab().getTitle();
return TextUtils.isEmpty(title) ? title : title.trim();
}
@Override @Override
public boolean isIncognito() { public boolean isIncognito() {
return mIsIncognito; return mIsIncognito;
......
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