Search in sources :

Example 16 with WebContents

use of org.chromium.content_public.browser.WebContents in project AndroidChromium by JackyAndroid.

the class TopControlsVisibilityDelegate method isHidingTopControlsEnabled.

/**
     * @return Whether hiding top controls is enabled or not.
     */
public boolean isHidingTopControlsEnabled() {
    WebContents webContents = mTab.getWebContents();
    if (webContents == null || webContents.isDestroyed())
        return false;
    String url = mTab.getUrl();
    boolean enableHidingTopControls = url != null;
    enableHidingTopControls &= !url.startsWith(UrlConstants.CHROME_SCHEME);
    enableHidingTopControls &= !url.startsWith(UrlConstants.CHROME_NATIVE_SCHEME);
    int securityState = mTab.getSecurityLevel();
    enableHidingTopControls &= (securityState != ConnectionSecurityLevel.DANGEROUS && securityState != ConnectionSecurityLevel.SECURITY_WARNING);
    enableHidingTopControls &= !AccessibilityUtil.isAccessibilityEnabled(mTab.getApplicationContext());
    ContentViewCore cvc = mTab.getContentViewCore();
    enableHidingTopControls &= cvc == null || !cvc.isFocusedNodeEditable();
    enableHidingTopControls &= !mTab.isShowingErrorPage();
    enableHidingTopControls &= !webContents.isShowingInterstitialPage();
    enableHidingTopControls &= (mTab.getFullscreenManager() != null);
    enableHidingTopControls &= DeviceClassManager.enableFullscreen();
    enableHidingTopControls &= !mTab.isFullscreenWaitingForLoad();
    return enableHidingTopControls;
}
Also used : WebContents(org.chromium.content_public.browser.WebContents) ContentViewCore(org.chromium.content.browser.ContentViewCore)

Example 17 with WebContents

use of org.chromium.content_public.browser.WebContents in project AndroidChromium by JackyAndroid.

the class ChromeActivity method triggerShare.

private void triggerShare(final Tab currentTab, final boolean shareDirectly, boolean isIncognito) {
    final Activity mainActivity = this;
    WebContents webContents = currentTab.getWebContents();
    RecordHistogram.recordBooleanHistogram("OfflinePages.SharedPageWasOffline", currentTab.isOfflinePage());
    boolean canShareOfflinePage = OfflinePageBridge.isPageSharingEnabled();
    // Share an empty blockingUri in place of screenshot file. The file ready notification is
    // sent by onScreenshotReady call below when the file is written.
    final Uri blockingUri = (isIncognito || webContents == null) ? null : ChromeFileProvider.generateUriAndBlockAccess(mainActivity);
    if (canShareOfflinePage) {
        OfflinePageUtils.shareOfflinePage(shareDirectly, true, mainActivity, null, blockingUri, null, currentTab);
    } else {
        ShareHelper.share(shareDirectly, true, mainActivity, currentTab.getTitle(), null, currentTab.getUrl(), null, blockingUri, null);
        if (shareDirectly) {
            RecordUserAction.record("MobileMenuDirectShare");
        } else {
            RecordUserAction.record("MobileMenuShare");
        }
    }
    if (blockingUri == null)
        return;
    // Start screenshot capture and notify the provider when it is ready.
    ContentBitmapCallback callback = new ContentBitmapCallback() {

        @Override
        public void onFinishGetBitmap(Bitmap bitmap, int response) {
            ShareHelper.saveScreenshotToDisk(bitmap, mainActivity, new Callback<Uri>() {

                @Override
                public void onResult(Uri result) {
                    // Unblock the file once it is saved to disk.
                    ChromeFileProvider.notifyFileReady(blockingUri, result);
                }
            });
        }
    };
    if (!mScreenshotCaptureSkippedForTesting) {
        webContents.getContentBitmapAsync(Bitmap.Config.ARGB_8888, 1.f, EMPTY_RECT, callback);
    } else {
        callback.onFinishGetBitmap(null, ReadbackResponse.SURFACE_UNAVAILABLE);
    }
}
Also used : WebContents(org.chromium.content_public.browser.WebContents) Bitmap(android.graphics.Bitmap) ContentBitmapCallback(org.chromium.content_public.browser.ContentBitmapCallback) AsyncInitializationActivity(org.chromium.chrome.browser.init.AsyncInitializationActivity) PrintShareActivity(org.chromium.chrome.browser.printing.PrintShareActivity) Activity(android.app.Activity) Uri(android.net.Uri)

Example 18 with WebContents

use of org.chromium.content_public.browser.WebContents in project AndroidChromium by JackyAndroid.

the class ContextualSearchSceneLayer method update.

/**
     * Update the scene layer to draw an OverlayPanel.
     * @param resourceManager Manager to get view and image resources.
     * @param panel The OverlayPanel to render.
     * @param searchBarControl The Search Bar control.
     * @param peekPromoControl The peeking promotion for Contextual Search.
     * @param imageControl The object controlling the image displayed in the Bar.
     */
public void update(ResourceManager resourceManager, ContextualSearchPanel panel, ContextualSearchBarControl searchBarControl, ContextualSearchPeekPromoControl peekPromoControl, ContextualSearchPromoControl promoControl, ContextualSearchImageControl imageControl) {
    // Don't try to update the layer if not initialized or showing.
    if (resourceManager == null || !panel.isShowing())
        return;
    if (!mIsInitialized) {
        nativeCreateContextualSearchLayer(mNativePtr, resourceManager);
        mIsInitialized = true;
    }
    mImageControl = imageControl;
    int searchContextViewId = searchBarControl.getSearchContextViewId();
    int searchTermViewId = searchBarControl.getSearchTermViewId();
    int searchCaptionViewId = searchBarControl.getCaptionViewId();
    int searchPromoViewId = promoControl.getViewId();
    boolean searchPromoVisible = promoControl.isVisible();
    float searchPromoHeightPx = promoControl.getHeightPx();
    float searchPromoOpacity = promoControl.getOpacity();
    int searchPeekPromoTextViewId = peekPromoControl.getViewId();
    boolean searchPeekPromoVisible = peekPromoControl.isVisible();
    float searchPeekPromoHeightPx = peekPromoControl.getHeightPx();
    float searchPeekPromoPaddingPx = peekPromoControl.getPaddingPx();
    float searchPeekPromoRippleWidthPx = peekPromoControl.getRippleWidthPx();
    float searchPeekPromoRippleOpacity = peekPromoControl.getRippleOpacity();
    float searchPeekPromoTextOpacity = peekPromoControl.getTextOpacity();
    boolean thumbnailVisible = imageControl.getThumbnailVisible();
    String thumbnailUrl = imageControl.getThumbnailUrl();
    float thumbnailVisibilityPercentage = imageControl.getThumbnailVisibilityPercentage();
    int thumbnailSize = imageControl.getThumbnailSize();
    ContextualSearchIconSpriteControl spriteControl = imageControl.getIconSpriteControl();
    boolean searchProviderIconSpriteVisible = spriteControl.isVisible();
    float searchProviderIconCompletionPercentage = spriteControl.getCompletionPercentage();
    float searchPanelX = panel.getOffsetX();
    float searchPanelY = panel.getOffsetY();
    float searchPanelWidth = panel.getWidth();
    float searchPanelHeight = panel.getHeight();
    float searchBarMarginSide = panel.getBarMarginSide();
    float searchBarHeight = panel.getBarHeight();
    float searchContextOpacity = searchBarControl.getSearchBarContextOpacity();
    float searchTermOpacity = searchBarControl.getSearchBarTermOpacity();
    float searchCaptionAnimationPercentage = searchBarControl.getCaptionAnimationPercentage();
    boolean searchCaptionVisible = searchBarControl.getCaptionVisible();
    boolean searchBarBorderVisible = panel.isBarBorderVisible();
    float searchBarBorderHeight = panel.getBarBorderHeight();
    boolean searchBarShadowVisible = panel.getBarShadowVisible();
    float searchBarShadowOpacity = panel.getBarShadowOpacity();
    float arrowIconOpacity = panel.getArrowIconOpacity();
    float arrowIconRotation = panel.getArrowIconRotation();
    float closeIconOpacity = panel.getCloseIconOpacity();
    boolean isProgressBarVisible = panel.isProgressBarVisible();
    float progressBarHeight = panel.getProgressBarHeight();
    float progressBarOpacity = panel.getProgressBarOpacity();
    int progressBarCompletion = panel.getProgressBarCompletion();
    WebContents panelWebContents = panel.getContentViewCore() != null ? panel.getContentViewCore().getWebContents() : null;
    nativeUpdateContextualSearchLayer(mNativePtr, R.drawable.contextual_search_bar_background, searchContextViewId, searchTermViewId, searchCaptionViewId, R.drawable.contextual_search_bar_shadow, R.drawable.google_icon_sprite, R.raw.google_icon_sprite, R.drawable.breadcrumb_arrow, ContextualSearchPanel.CLOSE_ICON_DRAWABLE_ID, R.drawable.progress_bar_background, R.drawable.progress_bar_foreground, searchPromoViewId, R.drawable.contextual_search_promo_ripple, searchPeekPromoTextViewId, mDpToPx, panel.getBasePageBrightness(), panel.getBasePageY() * mDpToPx, panelWebContents, searchPromoVisible, searchPromoHeightPx, searchPromoOpacity, searchPeekPromoVisible, searchPeekPromoHeightPx, searchPeekPromoPaddingPx, searchPeekPromoRippleWidthPx, searchPeekPromoRippleOpacity, searchPeekPromoTextOpacity, searchPanelX * mDpToPx, searchPanelY * mDpToPx, searchPanelWidth * mDpToPx, searchPanelHeight * mDpToPx, searchBarMarginSide * mDpToPx, searchBarHeight * mDpToPx, searchContextOpacity, searchTermOpacity, searchCaptionAnimationPercentage, searchCaptionVisible, searchBarBorderVisible, searchBarBorderHeight * mDpToPx, searchBarShadowVisible, searchBarShadowOpacity, searchProviderIconSpriteVisible, searchProviderIconCompletionPercentage, thumbnailVisible, thumbnailVisibilityPercentage, thumbnailSize, thumbnailUrl, arrowIconOpacity, arrowIconRotation, closeIconOpacity, isProgressBarVisible, progressBarHeight * mDpToPx, progressBarOpacity, progressBarCompletion, Profile.getLastUsedProfile());
}
Also used : WebContents(org.chromium.content_public.browser.WebContents) ContextualSearchIconSpriteControl(org.chromium.chrome.browser.compositor.bottombar.contextualsearch.ContextualSearchIconSpriteControl)

Example 19 with WebContents

use of org.chromium.content_public.browser.WebContents in project AndroidChromium by JackyAndroid.

the class ReaderModePanel method createNewOverlayPanelContent.

@Override
public OverlayPanelContent createNewOverlayPanelContent() {
    OverlayContentDelegate delegate = new OverlayContentDelegate() {

        /**
             * Track if a navigation/load is the first one for this content.
             */
        private boolean mIsInitialLoad = true;

        @Override
        public void onContentViewCreated(ContentViewCore contentView) {
            mContentViewDelegate.setOverlayPanelContentViewCore(contentView);
            WebContents distilledWebContents = contentView.getWebContents();
            if (distilledWebContents == null)
                return;
            WebContents sourceWebContents = mManagerDelegate.getBasePageWebContents();
            if (sourceWebContents == null)
                return;
            DomDistillerTabUtils.distillAndView(sourceWebContents, distilledWebContents);
        }

        @Override
        public void onContentViewDestroyed() {
            mContentViewDelegate.releaseOverlayPanelContentViewCore();
            mIsInitialLoad = true;
        }

        @Override
        public boolean shouldInterceptNavigation(ExternalNavigationHandler externalNavHandler, NavigationParams navigationParams) {
            // clicks.
            if (mIsInitialLoad) {
                mIsInitialLoad = false;
                return true;
            }
            if (!navigationParams.isExternalProtocol) {
                mManagerDelegate.createNewTab(navigationParams.url);
                return false;
            }
            return true;
        }
    };
    return new OverlayPanelContent(delegate, new OverlayContentProgressObserver(), mActivity);
}
Also used : WebContents(org.chromium.content_public.browser.WebContents) OverlayContentProgressObserver(org.chromium.chrome.browser.compositor.bottombar.OverlayContentProgressObserver) ExternalNavigationHandler(org.chromium.chrome.browser.externalnav.ExternalNavigationHandler) ContentViewCore(org.chromium.content.browser.ContentViewCore) OverlayContentDelegate(org.chromium.chrome.browser.compositor.bottombar.OverlayContentDelegate) OverlayPanelContent(org.chromium.chrome.browser.compositor.bottombar.OverlayPanelContent) NavigationParams(org.chromium.components.navigation_interception.NavigationParams)

Example 20 with WebContents

use of org.chromium.content_public.browser.WebContents in project AndroidChromium by JackyAndroid.

the class CustomTabsConnection method takePrerenderedUrl.

/**
     * Transfers a prerendered WebContents if one exists.
     *
     * This resets the internal WebContents; a subsequent call to this method
     * returns null. Must be called from the UI thread.
     * If a prerender exists for a different URL with the same sessionId or with
     * a different referrer, then this is treated as a mispredict from the
     * client application, and cancels the previous prerender. This is done to
     * avoid keeping resources laying around for too long, but is subject to a
     * race condition, as the following scenario is possible:
     * The application calls:
     * 1. mayLaunchUrl(url1) <- IPC
     * 2. loadUrl(url2) <- Intent
     * 3. mayLaunchUrl(url3) <- IPC
     * If the IPC for url3 arrives before the intent for url2, then this methods
     * cancels the prerender for url3, which is unexpected. On the other
     * hand, not cancelling the previous prerender leads to wasted resources, as
     * a WebContents is lingering. This can be solved by requiring applications
     * to call mayLaunchUrl(null) to cancel a current prerender before 2, that
     * is for a mispredict.
     *
     * Note that this methods accepts URLs that don't exactly match the initially
     * prerendered URL. More precisely, the #fragment is ignored. In this case,
     * the client needs to navigate to the correct URL after the WebContents
     * swap. This can be tested using {@link UrlUtilities#urlsFragmentsDiffer()}.
     *
     * @param session The Binder object identifying a session.
     * @param url The URL the WebContents is for.
     * @param referrer The referrer to use for |url|.
     * @return The prerendered WebContents, or null.
     */
WebContents takePrerenderedUrl(CustomTabsSessionToken session, String url, String referrer) {
    ThreadUtils.assertOnUiThread();
    if (mPrerender == null || session == null || !session.equals(mPrerender.mSession)) {
        return null;
    }
    WebContents webContents = mPrerender.mWebContents;
    String prerenderedUrl = mPrerender.mUrl;
    String prerenderReferrer = mPrerender.mReferrer;
    if (referrer == null)
        referrer = "";
    boolean ignoreFragments = mClientManager.getIgnoreFragmentsForSession(session);
    boolean urlsMatch = TextUtils.equals(prerenderedUrl, url) || (ignoreFragments && UrlUtilities.urlsMatchIgnoringFragments(prerenderedUrl, url));
    WebContents result = null;
    if (urlsMatch && TextUtils.equals(prerenderReferrer, referrer)) {
        result = webContents;
        mPrerender = null;
    } else {
        cancelPrerender(session);
    }
    if (!mClientManager.usesDefaultSessionParameters(session) && webContents != null) {
        RecordHistogram.recordBooleanHistogram("CustomTabs.NonDefaultSessionPrerenderMatched", result != null);
    }
    return result;
}
Also used : WebContents(org.chromium.content_public.browser.WebContents)

Aggregations

WebContents (org.chromium.content_public.browser.WebContents)21 Tab (org.chromium.chrome.browser.tab.Tab)5 Activity (android.app.Activity)2 Intent (android.content.Intent)2 View (android.view.View)2 ContentViewCore (org.chromium.content.browser.ContentViewCore)2 PendingIntent (android.app.PendingIntent)1 Context (android.content.Context)1 Bitmap (android.graphics.Bitmap)1 Rect (android.graphics.Rect)1 Uri (android.net.Uri)1 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)1 ViewGroup (android.view.ViewGroup)1 ListView (android.widget.ListView)1 CalledByNative (org.chromium.base.annotations.CalledByNative)1 ChromeActivity (org.chromium.chrome.browser.ChromeActivity)1 OverlayContentDelegate (org.chromium.chrome.browser.compositor.bottombar.OverlayContentDelegate)1 OverlayContentProgressObserver (org.chromium.chrome.browser.compositor.bottombar.OverlayContentProgressObserver)1 OverlayPanelContent (org.chromium.chrome.browser.compositor.bottombar.OverlayPanelContent)1 ContextualSearchIconSpriteControl (org.chromium.chrome.browser.compositor.bottombar.contextualsearch.ContextualSearchIconSpriteControl)1