Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(735)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchManager.java

Issue 1304013002: Move functionality for ContentViewCore to ContextualSearchPanel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simple-move-cvc-to-panel
Patch Set: Rebase & revert ContextualSearchRequest Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchManager.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchManager.java b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchManager.java
index f1ec78fa60e76a54ec2f032283be995bf1122539..e5404e006c45d1e9d65897446dd8dc5efa6c26c5 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchManager.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchManager.java
@@ -6,7 +6,6 @@ package org.chromium.chrome.browser.contextualsearch;
import android.app.Activity;
import android.view.View;
-import android.view.View.MeasureSpec;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalFocusChangeListener;
@@ -19,7 +18,6 @@ import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity;
-import org.chromium.chrome.browser.WebContentsFactory;
import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.ContextualSearchControl;
import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.ContextualSearchPanel.PanelState;
import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.ContextualSearchPanel.StateChangeReason;
@@ -43,9 +41,6 @@ import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver;
import org.chromium.components.navigation_interception.InterceptNavigationDelegate;
import org.chromium.components.navigation_interception.NavigationParams;
-import org.chromium.components.web_contents_delegate_android.WebContentsDelegateAndroid;
-import org.chromium.content.browser.ContentView;
-import org.chromium.content.browser.ContentViewClient;
import org.chromium.content.browser.ContentViewCore;
import org.chromium.content.browser.ContextualSearchClient;
import org.chromium.content_public.browser.GestureStateListener;
@@ -94,7 +89,6 @@ public class ContextualSearchManager extends ContextualSearchObservable
private final WindowAndroid mWindowAndroid;
private WebContentsObserver mSearchWebContentsObserver;
- private final WebContentsDelegateAndroid mWebContentsDelegate;
private ContextualSearchContentViewDelegate mSearchContentViewDelegate;
private final ContextualSearchTabPromotionDelegate mTabPromotionDelegate;
private TabModelSelectorTabObserver mTabModelSelectorTabObserver;
@@ -182,26 +176,6 @@ public class ContextualSearchManager extends ContextualSearchObservable
mSelectionController = new ContextualSearchSelectionController(activity, this);
- mWebContentsDelegate = new WebContentsDelegateAndroid() {
- @Override
- public void onLoadStarted() {
- super.onLoadStarted();
- mSearchPanelDelegate.onLoadStarted();
- }
-
- @Override
- public void onLoadStopped() {
- super.onLoadStopped();
- mSearchPanelDelegate.onLoadStopped();
- }
-
- @Override
- public void onLoadProgressChanged(int progress) {
- super.onLoadProgressChanged(progress);
- mSearchPanelDelegate.onLoadProgressChanged(progress);
- }
- };
-
final View controlContainer = mActivity.findViewById(R.id.control_container);
mOnFocusChangeListener = new OnGlobalFocusChangeListener() {
@Override
@@ -268,6 +242,8 @@ public class ContextualSearchManager extends ContextualSearchObservable
@Override
public void setContextualSearchPanelDelegate(ContextualSearchPanelDelegate delegate) {
mSearchPanelDelegate = delegate;
+
+ mSearchPanelDelegate.setChromeActivity(mActivity);
}
@Override
@@ -307,7 +283,8 @@ public class ContextualSearchManager extends ContextualSearchObservable
/**
* @return The Base Page's {@link ContentViewCore}.
*/
- @Nullable private ContentViewCore getBaseContentView() {
+ @Override
+ @Nullable public ContentViewCore getBaseContentView() {
return mSelectionController.getBaseContentView();
}
@@ -383,7 +360,6 @@ public class ContextualSearchManager extends ContextualSearchObservable
mLoadedSearchUrlTimeMs = 0L;
mWereSearchResultsSeen = false;
- mNetworkCommunicator.destroySearchContentView();
mSearchRequest = null;
if (mIsShowingPromo && !mDidLogPromoOutcome) {
@@ -458,9 +434,6 @@ public class ContextualSearchManager extends ContextualSearchObservable
removeLastSearchVisit();
}
- // Make sure we'll create a new Content View when needed.
- mNetworkCommunicator.destroySearchContentView();
-
boolean isTap = mSelectionController.getSelectionType() == SelectionType.TAP;
boolean didRequestSurroundings = false;
if (isTap && mPolicy.shouldPreviousTapResolve(
@@ -714,10 +687,10 @@ public class ContextualSearchManager extends ContextualSearchObservable
boolean shouldPreload = !doPreventPreload && mPolicy.shouldPrefetchSearchResult(true);
mSearchRequest = new ContextualSearchRequest(searchTerm, alternateTerm, shouldPreload);
mDidLoadResolvedSearchRequest = false;
- if (mIsSearchContentViewShowing) {
+ if (mSearchPanelDelegate.isContentViewShowing()) {
mSearchRequest.setNormalPriority();
}
- if (mIsSearchContentViewShowing || shouldPreload) {
+ if (mSearchPanelDelegate.isContentViewShowing() || shouldPreload) {
loadSearchUrl();
}
mPolicy.logSearchTermResolutionDetails(searchTerm,
@@ -734,7 +707,7 @@ public class ContextualSearchManager extends ContextualSearchObservable
*/
private void loadSearchUrl() {
mLoadedSearchUrlTimeMs = System.currentTimeMillis();
- mNetworkCommunicator.loadUrl(mSearchRequest.getSearchUrl());
+ mSearchPanelDelegate.loadUrlInPanel(mSearchRequest.getSearchUrl());
mDidLoadResolvedSearchRequest = true;
// TODO(pedrosimonetti): If the user taps on a word and quickly after that taps on the
@@ -743,7 +716,8 @@ public class ContextualSearchManager extends ContextualSearchObservable
// to coordinate with Chrome-Android folks to come up with a proper fix for this.
// For now, we force the ContentView to be displayed by calling onShow() again
// when a URL is being loaded. See: crbug.com/398206
- if (mIsSearchContentViewShowing && mSearchPanelDelegate.getContentViewCore() != null) {
+ if (mSearchPanelDelegate.isContentViewShowing()
+ && mSearchPanelDelegate.getContentViewCore() != null) {
mSearchPanelDelegate.getContentViewCore().onShow();
}
}
@@ -795,7 +769,8 @@ public class ContextualSearchManager extends ContextualSearchObservable
* a load of a user-visible search result.
* @param isFailure Whether the navigation failed.
*/
- private void onContextualSearchRequestNavigation(boolean isFailure) {
+ @Override
+ public void onContextualSearchRequestNavigation(boolean isFailure) {
if (mSearchRequest == null) return;
if (mSearchRequest.isUsingLowPriority()) {
@@ -817,7 +792,7 @@ public class ContextualSearchManager extends ContextualSearchObservable
mSearchRequest.setHasFailed();
mSearchRequest.setNormalPriority();
// If the content view is showing, load at normal priority now.
- if (mIsSearchContentViewShowing) {
+ if (mSearchPanelDelegate.isContentViewShowing()) {
loadSearchUrl();
} else {
mDidLoadResolvedSearchRequest = false;
@@ -835,125 +810,25 @@ public class ContextualSearchManager extends ContextualSearchObservable
* Called when the Search Content view has finished loading to record how long it takes the SERP
* to load after opening the panel.
*/
- private void onSearchResultsLoaded() {
+ @Override
+ public void onSearchResultsLoaded() {
if (mSearchRequest == null) return;
mSearchPanelDelegate.onSearchResultsLoaded(mSearchRequest.wasPrefetch());
- }
-
- /**
- * Creates a new Content View Core to display search results, if needed.
- */
- private void createNewSearchContentViewCoreIfNeeded() {
- if (mSearchPanelDelegate.getContentViewCore() == null) {
- mNetworkCommunicator.createNewSearchContentView();
- }
- }
-
- @Override
- public void loadUrl(String url) {
- createNewSearchContentViewCoreIfNeeded();
- if (mSearchPanelDelegate.getContentViewCore() != null
- && mSearchPanelDelegate.getContentViewCore().getWebContents() != null) {
- mDidLoadAnyUrl = true;
- mSearchPanelDelegate.getContentViewCore().getWebContents()
- .getNavigationController().loadUrl(new LoadUrlParams(url));
- }
- }
-
- @Override
- public void createNewSearchContentView() {
- if (mSearchPanelDelegate.getContentViewCore() != null) {
- mNetworkCommunicator.destroySearchContentView();
- }
- final ContentViewCore cvc = new ContentViewCore(mActivity);
-
- // Adds a ContentViewClient to override the default fullscreen size.
- if (!mSearchPanelDelegate.isFullscreenSizePanel()) {
- cvc.setContentViewClient(new ContentViewClient() {
- @Override
- public int getDesiredWidthMeasureSpec() {
- return MeasureSpec.makeMeasureSpec(
- mSearchPanelDelegate.getSearchContentViewWidthPx(),
- MeasureSpec.EXACTLY);
- }
-
- @Override
- public int getDesiredHeightMeasureSpec() {
- return MeasureSpec.makeMeasureSpec(
- mSearchPanelDelegate.getSearchContentViewHeightPx(),
- MeasureSpec.EXACTLY);
- }
- });
+ // Any time we place a page in a ContentViewCore, clear history if needed.
+ // This prevents error URLs from appearing in the Tab's history stack.
+ // Also please note that clearHistory() will not
+ // clear the current entry (search results page in this case),
+ // and it will not work properly if there are pending navigations.
+ // That's why we need to clear the history here, after the navigation
+ // is completed.
+ boolean shouldClearHistory =
+ mSearchRequest != null && mSearchRequest.getHasFailed();
+ if (shouldClearHistory && mSearchPanelDelegate.getContentViewCore() != null) {
+ mSearchPanelDelegate.getContentViewCore().getWebContents().getNavigationController()
+ .clearHistory();
}
-
- ContentView cv = new ContentView(mActivity, cvc);
- // Creates an initially hidden WebContents which gets shown when the panel is opened.
- cvc.initialize(cv, cv,
- WebContentsFactory.createWebContents(false, true), mWindowAndroid);
-
- // Transfers the ownership of the WebContents to the native ContextualSearchPanel.
- mSearchPanelDelegate.setWebContents(cvc, mWebContentsDelegate);
-
- mSearchWebContentsObserver =
- new WebContentsObserver(cvc.getWebContents()) {
- @Override
- public void didStartLoading(String url) {
- mDidPromoteSearchNavigation = false;
- }
-
- @Override
- public void didStartProvisionalLoadForFrame(long frameId, long parentFrameId,
- boolean isMainFrame, String validatedUrl, boolean isErrorPage,
- boolean isIframeSrcdoc) {
- if (isMainFrame) onExternalNavigation(validatedUrl);
- }
-
- @Override
- public void didNavigateMainFrame(String url, String baseUrl,
- boolean isNavigationToDifferentPage, boolean isNavigationInPage,
- int httpResultCode) {
- mNetworkCommunicator.handleDidNavigateMainFrame(url, httpResultCode);
- }
-
- @Override
- public void didFinishLoad(long frameId, String validatedUrl,
- boolean isMainFrame) {
- onSearchResultsLoaded();
-
- // Any time we place a page in a ContentViewCore, clear history if needed.
- // This prevents error URLs from appearing in the Tab's history stack.
- // Also please note that clearHistory() will not
- // clear the current entry (search results page in this case),
- // and it will not work properly if there are pending navigations.
- // That's why we need to clear the history here, after the navigation
- // is completed.
- boolean shouldClearHistory =
- mSearchRequest != null && mSearchRequest.getHasFailed();
- if (shouldClearHistory && cvc != null) {
- cvc.getWebContents().getNavigationController()
- .clearHistory();
- }
- }
- };
-
- mSearchContentViewDelegate.setContextualSearchContentViewCore(cvc);
- mInterceptNavigationDelegate = new InterceptNavigationDelegateImpl();
- mSearchPanelDelegate.setInterceptNavigationDelegate(mInterceptNavigationDelegate,
- cvc.getWebContents());
- }
-
- @Override
- public void handleDidNavigateMainFrame(String url, int httpResultCode) {
- if (shouldPromoteSearchNavigation()) {
- onExternalNavigation(url);
- } else {
- // Could be just prefetching, check if that failed.
- boolean isFailure = isHttpFailureCode(httpResultCode);
- onContextualSearchRequestNavigation(isFailure);
- }
- mDidLoadAnyUrl = false;
}
/**
@@ -973,63 +848,16 @@ public class ContextualSearchManager extends ContextualSearchObservable
return mSearchPanelDelegate.didTouchSearchContentView() && !mDidLoadAnyUrl;
}
- /**
- * Called to check if an external navigation is being done and take the appropriate action:
- * Auto-promotes the panel into a separate tab if that's not already being done.
- * @param url The URL we are navigating to.
- */
- private void onExternalNavigation(String url) {
- if (mSearchPanelDelegate.isFullscreenSizePanel()) {
- // Consider the ContentView height to be fullscreen, and inform the system that
- // the Toolbar is always visible (from the Compositor's perspective), even though
- // the Toolbar and Base Page might be offset outside the screen. This means the
- // renderer will consider the ContentView height to be the fullscreen height
- // minus the Toolbar height.
- //
- // This is necessary to fix the bugs: crbug.com/510205 and crbug.com/510206
- mSearchPanelDelegate.getContentViewCore().getWebContents()
- .updateTopControlsState(false, true, false);
- } else {
- mSearchPanelDelegate.getContentViewCore().getWebContents()
- .updateTopControlsState(true, false, false);
- }
-
- if (!mDidPromoteSearchNavigation
- && !BLACKLISTED_URL.equals(url)
- && !url.startsWith(INTENT_URL_PREFIX)
- && shouldPromoteSearchNavigation()) {
- // Do not promote to a regular tab if we're loading our Resolved Search
- // URL, otherwise we'll promote it when prefetching the Serp.
- // Don't promote URLs when they are navigating to an intent - this is
- // handled by the InterceptNavigationDelegate which uses a faster
- // maximizing animation.
- mDidPromoteSearchNavigation = true;
- mSearchPanelDelegate.maximizePanelThenPromoteToTab(StateChangeReason.SERP_NAVIGATION);
- }
+ @Override
+ public void onContentViewCreated(ContentViewCore contentView) {
+ mSearchContentViewDelegate.setContextualSearchContentViewCore(contentView);
}
@Override
- public void destroySearchContentView() {
- if (mSearchPanelDelegate.getContentViewCore() != null
- && mSearchContentViewDelegate != null) {
- mSearchPanelDelegate.destroyWebContents();
+ public void onContentViewDestroyed() {
+ if (mSearchContentViewDelegate != null) {
mSearchContentViewDelegate.releaseContextualSearchContentViewCore();
- mSearchPanelDelegate.getContentViewCore().getWebContents().destroy();
- mSearchPanelDelegate.getContentViewCore().destroy();
- mSearchPanelDelegate.resetContentViewCore();
- if (mSearchWebContentsObserver != null) {
- mSearchWebContentsObserver.destroy();
- mSearchWebContentsObserver = null;
- }
}
-
- // This should be called last here. The setSearchContentViewVisibility method
- // will change the visibility the SearchContentView but also set the value of the
- // internal property mIsSearchContentViewShowing. If we call this after deleting
- // the SearchContentView, it will be faster, because only the internal property
- // will be changed, since there will be no need to change the visibility of the
- // SearchContentView.
- setSearchContentViewVisibility(false);
}
@Override
@@ -1102,23 +930,13 @@ public class ContextualSearchManager extends ContextualSearchObservable
}
@Override
- public void resetSearchContentViewScroll() {
- if (mSearchPanelDelegate.getContentViewCore() != null) {
- mSearchPanelDelegate.getContentViewCore().scrollTo(0, 0);
- }
- }
-
- @Override
public float getSearchContentViewVerticalScroll() {
return mSearchPanelDelegate.getContentViewCore() != null
? mSearchPanelDelegate.getContentViewCore().computeVerticalScrollOffset() : -1.f;
}
@Override
- public void setSearchContentViewVisibility(boolean isVisible) {
- if (mIsSearchContentViewShowing == isVisible) return;
-
- mIsSearchContentViewShowing = isVisible;
+ public void onContentViewVisibilityChanged(boolean isVisible) {
if (isVisible) {
mWereSearchResultsSeen = true;
// If there's no current request, then either a search term resolution
@@ -1134,18 +952,7 @@ public class ContextualSearchManager extends ContextualSearchObservable
mSearchRequest.setNormalPriority();
loadSearchUrl();
}
- // The CVC is created with the search request, but if none was made we'll need
- // one in order to display an empty panel.
- createNewSearchContentViewCoreIfNeeded();
- if (mSearchPanelDelegate.getContentViewCore() != null) {
- mSearchPanelDelegate.getContentViewCore().onShow();
- }
- mSearchPanelDelegate.setWasSearchContentViewSeen();
mPolicy.updateCountersForOpen();
- } else {
- if (mSearchPanelDelegate.getContentViewCore() != null) {
- mSearchPanelDelegate.getContentViewCore().onHide();
- }
}
}

Powered by Google App Engine
This is Rietveld 408576698