Search in sources :

Example 1 with InfoBarContainer

use of org.chromium.chrome.browser.infobar.InfoBarContainer in project AndroidChromium by JackyAndroid.

the class ReaderModeManager method restoreInfobars.

/**
     * Restore any infobars that may have been hidden by Reader Mode.
     */
private void restoreInfobars() {
    if (!mIsInfoBarContainerShown)
        return;
    Tab curTab = mTabModelSelector.getCurrentTab();
    if (curTab == null)
        return;
    InfoBarContainer container = curTab.getInfoBarContainer();
    if (container == null)
        return;
    container.setIsObscuredByOtherView(false);
    // Temporarily hides the reader mode button while the infobars are shown.
    closeReaderPanel(StateChangeReason.INFOBAR_SHOWN, false);
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) InfoBarContainer(org.chromium.chrome.browser.infobar.InfoBarContainer)

Example 2 with InfoBarContainer

use of org.chromium.chrome.browser.infobar.InfoBarContainer in project AndroidChromium by JackyAndroid.

the class Tab method setContentViewCore.

/**
     * Completes the {@link ContentViewCore} specific initialization around a native WebContents
     * pointer. {@link #getNativePage()} will still return the {@link NativePage} if there is one.
     * All initialization that needs to reoccur after a web contents swap should be added here.
     * <p />
     * NOTE: If you attempt to pass a native WebContents that does not have the same incognito
     * state as this tab this call will fail.
     *
     * @param cvc The content view core that needs to be set as active view for the tab.
     */
private void setContentViewCore(ContentViewCore cvc) {
    try {
        TraceEvent.begin("ChromeTab.setContentViewCore");
        NativePage previousNativePage = mNativePage;
        mNativePage = null;
        destroyNativePageInternal(previousNativePage);
        if (mContentViewCore != null) {
            mContentViewCore.setObscuredByAnotherView(false);
        }
        mContentViewCore = cvc;
        cvc.getContainerView().setOnHierarchyChangeListener(this);
        cvc.getContainerView().setOnSystemUiVisibilityChangeListener(this);
        // accessibility. http://crbug.com/416663
        if (mContentViewParent != null) {
            assert false;
            mContentViewParent.removeAllViews();
        }
        mContentViewParent = new TabContentViewParent(mThemedApplicationContext, this);
        mContentViewParent.addView(cvc.getContainerView(), 0, new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        mWebContentsDelegate = mDelegateFactory.createWebContentsDelegate(this);
        mWebContentsObserver = new TabWebContentsObserver(mContentViewCore.getWebContents(), this);
        if (mContentViewClient != null) {
            mContentViewCore.setContentViewClient(mContentViewClient);
        }
        mDownloadDelegate = new ChromeDownloadDelegate(mThemedApplicationContext, this);
        assert mNativeTabAndroid != 0;
        nativeInitWebContents(mNativeTabAndroid, mIncognito, mContentViewCore.getWebContents(), mWebContentsDelegate, new TabContextMenuPopulator(mDelegateFactory.createContextMenuPopulator(this), this));
        // valid infobar container, no need to recreate one.
        if (mInfoBarContainer == null) {
            // The InfoBarContainer needs to be created after the ContentView has been natively
            // initialized.
            mInfoBarContainer = new InfoBarContainer(mThemedApplicationContext, getId(), mContentViewParent, this);
        } else {
            mInfoBarContainer.onParentViewChanged(getId(), mContentViewParent);
        }
        mInfoBarContainer.setContentViewCore(mContentViewCore);
        mSwipeRefreshHandler = new SwipeRefreshHandler(mThemedApplicationContext, this);
        updateThemeColorIfNeeded(false);
        notifyContentChanged();
        // For browser tabs, we want to set accessibility focus to the page
        // when it loads. This is not the default behavior for embedded
        // web views.
        mContentViewCore.setShouldSetAccessibilityFocusOnPageLoad(true);
        setInterceptNavigationDelegate(mDelegateFactory.createInterceptNavigationDelegate(this));
        if (mGestureStateListener == null) {
            mGestureStateListener = createGestureStateListener();
        }
        cvc.addGestureStateListener(mGestureStateListener);
    } finally {
        TraceEvent.end("ChromeTab.setContentViewCore");
    }
}
Also used : NativePage(org.chromium.chrome.browser.NativePage) FrozenNativePage(org.chromium.chrome.browser.FrozenNativePage) LayoutParams(android.widget.FrameLayout.LayoutParams) SwipeRefreshHandler(org.chromium.chrome.browser.SwipeRefreshHandler) InfoBarContainer(org.chromium.chrome.browser.infobar.InfoBarContainer) FrameLayout(android.widget.FrameLayout) ChromeDownloadDelegate(org.chromium.chrome.browser.download.ChromeDownloadDelegate)

Example 3 with InfoBarContainer

use of org.chromium.chrome.browser.infobar.InfoBarContainer in project AndroidChromium by JackyAndroid.

the class ContextualSearchManager method showContextualSearch.

/**
     * Shows the Contextual Search UX.
     * Calls back into onGetContextualSearchQueryResponse.
     * @param stateChangeReason The reason explaining the change of state.
     */
private void showContextualSearch(StateChangeReason stateChangeReason) {
    if (mFindToolbarManager != null) {
        mFindToolbarManager.hideToolbar(false);
    }
    // Dismiss the undo SnackBar if present by committing all tab closures.
    mActivity.getTabModelSelector().commitAllTabClosures();
    if (!mSearchPanel.isShowing()) {
        // If visible, hide the infobar container before showing the Contextual Search panel.
        InfoBarContainer container = getInfoBarContainer();
        if (container != null && container.getVisibility() == View.VISIBLE) {
            mWereInfoBarsHidden = true;
            container.setIsObscuredByOtherView(true);
        }
    }
    // If the user is jumping from one unseen search to another search, remove the last search
    // from history.
    PanelState state = mSearchPanel.getPanelState();
    if (!mWereSearchResultsSeen && mLoadedSearchUrlTimeMs != 0L && state != PanelState.UNDEFINED && state != PanelState.CLOSED) {
        removeLastSearchVisit();
    }
    // TODO(pedrosimonetti): Fix for M47. Replace this with a better delayed load approach.
    mSearchPanel.destroyContent();
    boolean isTap = mSelectionController.getSelectionType() == SelectionType.TAP;
    boolean didRequestSurroundings = false;
    if (isTap) {
        // If the user action was not a long-press, immediately start loading content.
        mShouldLoadDelayedSearch = false;
    }
    if (isTap && mPolicy.shouldPreviousTapResolve()) {
        mNetworkCommunicator.startSearchTermResolutionRequest(mSelectionController.getSelectedText());
        didRequestSurroundings = true;
        // Cache the native translate data, so JNI calls won't be made when time-critical.
        mTranslateController.cacheNativeTranslateData();
    } else {
        boolean shouldPrefetch = mPolicy.shouldPrefetchSearchResult();
        mSearchRequest = createContextualSearchRequest(mSelectionController.getSelectedText(), null, null, shouldPrefetch);
        mTranslateController.forceAutoDetectTranslateUnlessDisabled(mSearchRequest);
        mDidStartLoadingResolvedSearchRequest = false;
        mSearchPanel.setSearchTerm(mSelectionController.getSelectedText());
        if (shouldPrefetch)
            loadSearchUrl();
        // TODO(donnd): remove this section once metrics have been analyzed.
        if (mSelectionController.getSelectionType() == SelectionType.LONG_PRESS && mSearchPanel.isPeeking()) {
            boolean isSingleWord = !CONTAINS_WHITESPACE_PATTERN.matcher(mSelectionController.getSelectedText().trim()).find();
            RecordUserAction.record(isSingleWord ? "ContextualSearch.ManualRefineSingleWord" : "ContextualSearch.ManualRefineMultiWord");
        }
    }
    if (!didRequestSurroundings) {
        // Gather surrounding text for Icing integration, which will make the selection and
        // a shorter version of the surroundings available for Conversational Search.
        // Although the surroundings are extracted, they will not be sent to the server as
        // part of search term resolution, just sent to Icing which keeps them local until
        // the user activates a Voice Search.
        nativeGatherSurroundingText(mNativeContextualSearchManagerPtr, mSelectionController.getSelectedText(), NEVER_USE_RESOLVED_SEARCH_TERM, getBaseContentView().getWebContents(), mPolicy.maySendBasePageUrl());
    }
    mWereSearchResultsSeen = false;
    // the policy allows it.
    if (!mSearchPanel.isShowing()) {
        mWouldShowPeekPromo = mPolicy.isPeekPromoConditionSatisfied();
        mIsShowingPeekPromo = mPolicy.isPeekPromoAvailable();
        if (mIsShowingPeekPromo) {
            mSearchPanel.showPeekPromo();
            mPolicy.registerPeekPromoSeen();
        }
    }
    // Note: whether the sprite should be animated or not needs to be set before the call to
    // peekPanel(). If the sprite should be animated, the animation will begin after the panel
    // finishes peeking. If it should not be animated, the icon will be drawn right away.
    mSearchPanel.getImageControl().setShouldAnimateIconSprite(mPolicy.shouldAnimateSearchProviderIcon());
    // Note: now that the contextual search has properly started, set the promo involvement.
    if (mPolicy.isPromoAvailable()) {
        mIsShowingPromo = true;
        mIsMandatoryPromo = mPolicy.isMandatoryPromoAvailable();
        mDidLogPromoOutcome = false;
        mSearchPanel.setIsPromoActive(true, mIsMandatoryPromo);
        mSearchPanel.setDidSearchInvolvePromo();
    }
    // TODO(donnd): although we are showing the bar here, we have not yet set the text!
    // Refactor to show the bar and set the text at the same time!
    // TODO(donnd): If there was a previously ongoing contextual search, we should ensure
    // it's registered as closed.
    mSearchPanel.requestPanelShow(stateChangeReason);
    assert mSelectionController.getSelectionType() != SelectionType.UNDETERMINED;
    mWasActivatedByTap = mSelectionController.getSelectionType() == SelectionType.TAP;
}
Also used : InfoBarContainer(org.chromium.chrome.browser.infobar.InfoBarContainer) PanelState(org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.PanelState)

Example 4 with InfoBarContainer

use of org.chromium.chrome.browser.infobar.InfoBarContainer in project AndroidChromium by JackyAndroid.

the class ContextualSearchManager method onCloseContextualSearch.

@Override
public void onCloseContextualSearch(StateChangeReason reason) {
    if (mSearchPanel == null)
        return;
    mSelectionController.onSearchEnded(reason);
    // Show the infobar container if it was visible before Contextual Search was shown.
    if (mWereInfoBarsHidden) {
        mWereInfoBarsHidden = false;
        InfoBarContainer container = getInfoBarContainer();
        if (container != null) {
            container.setIsObscuredByOtherView(false);
        }
    }
    if (!mWereSearchResultsSeen && mLoadedSearchUrlTimeMs != 0L) {
        removeLastSearchVisit();
    }
    // Clear the timestamp. This is to avoid future calls to hideContextualSearch clearing
    // the current URL.
    mLoadedSearchUrlTimeMs = 0L;
    mWereSearchResultsSeen = false;
    mSearchRequest = null;
    if (mIsShowingPeekPromo || mWouldShowPeekPromo) {
        mPolicy.logPeekPromoMetrics(mIsShowingPeekPromo, mWouldShowPeekPromo);
    }
    if (mIsShowingPromo && !mDidLogPromoOutcome && mSearchPanel.wasPromoInteractive()) {
        ContextualSearchUma.logPromoOutcome(mWasActivatedByTap, mIsMandatoryPromo);
        mDidLogPromoOutcome = true;
    }
    mIsShowingPromo = false;
    mSearchPanel.setIsPromoActive(false, false);
    notifyHideContextualSearch();
}
Also used : InfoBarContainer(org.chromium.chrome.browser.infobar.InfoBarContainer)

Aggregations

InfoBarContainer (org.chromium.chrome.browser.infobar.InfoBarContainer)4 FrameLayout (android.widget.FrameLayout)1 LayoutParams (android.widget.FrameLayout.LayoutParams)1 FrozenNativePage (org.chromium.chrome.browser.FrozenNativePage)1 NativePage (org.chromium.chrome.browser.NativePage)1 SwipeRefreshHandler (org.chromium.chrome.browser.SwipeRefreshHandler)1 PanelState (org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.PanelState)1 ChromeDownloadDelegate (org.chromium.chrome.browser.download.ChromeDownloadDelegate)1 Tab (org.chromium.chrome.browser.tab.Tab)1