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
// now count as a new session.
mHasStartedNewOmniboxEditSession = false;
mNewOmniboxEditSessionTimestamp = -1;
if (mNativeInitialized && mUrlHasFocus && mToolbarDataProvider.hasTab()) {
if (mNativeInitialized && mUrlHasFocus
&& (mToolbarDataProvider.hasTab()
|| (mBottomSheet != null && mBottomSheet.isShowingNewTab()))) {
mAutocomplete.startZeroSuggest(mToolbarDataProvider.getProfile(),
mUrlBar.getTextWithAutocomplete(), mToolbarDataProvider.getCurrentUrl(),
getCurrentTab().getTitle(), mUrlFocusedFromFakebox);
mToolbarDataProvider.getTitle(), mUrlFocusedFromFakebox);
}
}
......@@ -2368,12 +2370,9 @@ public class LocationBarLayout extends FrameLayout
// If the bottom sheet is managing the display of the suggestions, view visibility does not
// need to be set here.
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 =
mBottomSheet.getCurrentSheetContent() == mOmniboxSuggestionsSheetContent;
if (visible && !showingOmniboxSuggestions && !blockForNTP) {
if (visible && !showingOmniboxSuggestions) {
mBottomSheet.showContent(mOmniboxSuggestionsSheetContent);
}
} else {
......
......@@ -45,6 +45,11 @@ class SearchBoxDataProvider implements ToolbarDataProvider {
return null;
}
@Override
public String getTitle() {
return "";
}
@Override
public Tab getTab() {
return mTab;
......
......@@ -304,17 +304,17 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
@Override
public void setTitleToPageTitle() {
Tab currentTab = getToolbarDataProvider().getTab();
if (currentTab == null || TextUtils.isEmpty(currentTab.getTitle())) {
String title = getToolbarDataProvider().getTitle();
if (!getToolbarDataProvider().hasTab() || TextUtils.isEmpty(title)) {
mTitleBar.setText("");
return;
}
String title = currentTab.getTitle();
// It takes some time to parse the title of the webcontent, and before that Tab#getTitle
// always return the url. We postpone the title animation until the title is authentic.
// It takes some time to parse the title of the webcontent, and before that
// 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)
&& !title.equals(currentTab.getUrl())
&& !title.equals(getToolbarDataProvider().getCurrentUrl())
&& !title.equals(ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL)) {
// Delay the title animation until security icon animation finishes.
ThreadUtils.postOnUiThreadDelayed(mTitleAnimationStarter, TITLE_ANIM_DELAY_MS);
......@@ -347,7 +347,7 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
String url = getCurrentTab().getUrl().trim();
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".
......
......@@ -54,6 +54,11 @@ public interface ToolbarDataProvider {
*/
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.
*/
......
......@@ -179,6 +179,11 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
return null;
}
@Override
public String getTitle() {
return "";
}
@Override
public NewTabPage getNewTabPageForCurrentTab() {
return null;
......
......@@ -16,6 +16,7 @@ import org.chromium.base.ContextUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R;
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.DomDistillerTabUtils;
import org.chromium.chrome.browser.locale.LocaleManager;
......@@ -96,7 +97,13 @@ class ToolbarModelImpl extends ToolbarModel implements ToolbarDataProvider, Tool
@Override
public String getCurrentUrl() {
// 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.
return getTab().getUrl().trim();
}
......@@ -148,6 +155,14 @@ class ToolbarModelImpl extends ToolbarModel implements ToolbarDataProvider, Tool
return domDistillerService.hasEntry(entryIdFromUrl);
}
@Override
public String getTitle() {
if (!hasTab()) return "";
String title = getTab().getTitle();
return TextUtils.isEmpty(title) ? title : title.trim();
}
@Override
public boolean isIncognito() {
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