org.chromium.chrome.browser.prerender.ExternalPrerenderHandler Java Examples

The following examples show how to use org.chromium.chrome.browser.prerender.ExternalPrerenderHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomTabObserver.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
public CustomTabObserver(
        Application application, CustomTabsSessionToken session, boolean openedByChrome) {
    if (openedByChrome) {
        mCustomTabsConnection = null;
    } else {
        mCustomTabsConnection = CustomTabsConnection.getInstance(application);
    }
    mSession = session;
    if (!openedByChrome && mCustomTabsConnection.shouldSendNavigationInfoForSession(mSession)) {
        float desiredWidth = application.getResources().getDimensionPixelSize(
                R.dimen.custom_tabs_screenshot_width);
        float desiredHeight = application.getResources().getDimensionPixelSize(
                R.dimen.custom_tabs_screenshot_height);
        Rect bounds = ExternalPrerenderHandler.estimateContentSize(application, false);
        mScaleForNavigationInfo = (bounds.width() == 0 || bounds.height() == 0) ? 1f :
                Math.min(desiredWidth / bounds.width(), desiredHeight / bounds.height());
    }
    mOpenedByChrome = openedByChrome;
    resetPageLoadTracking();
}
 
Example #2
Source File: Tab.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an instance of a {@link Tab} that is fully detached from any activity.
 * Also performs general tab initialization as well as detached specifics.
 *
 * The current application context must allow the creation of a WindowAndroid.
 *
 * @return The newly created and initialized tab.
 */
public static Tab createDetached(TabDelegateFactory delegateFactory) {
    Context context = ContextUtils.getApplicationContext();
    WindowAndroid windowAndroid = new WindowAndroid(context);
    Tab tab = new Tab(INVALID_TAB_ID, INVALID_TAB_ID, false, context, windowAndroid,
            TabLaunchType.FROM_DETACHED, null, null);
    tab.initialize(null, null, delegateFactory, true, false);

    // Resize the webContent to avoid expensive post load resize when attaching the tab.
    Rect bounds = ExternalPrerenderHandler.estimateContentSize((Application) context, false);
    int width = bounds.right - bounds.left;
    int height = bounds.bottom - bounds.top;
    tab.getContentViewCore().onSizeChanged(width, height, 0, 0);

    tab.detach(null, null);
    return tab;
}
 
Example #3
Source File: CustomTabObserver.java    From 365browser with Apache License 2.0 5 votes vote down vote up
public CustomTabObserver(
        Application application, CustomTabsSessionToken session, boolean openedByChrome) {
    if (openedByChrome) {
        mCustomTabsConnection = null;
    } else {
        mCustomTabsConnection = CustomTabsConnection.getInstance(application);
    }
    mSession = session;
    if (!openedByChrome && mCustomTabsConnection.shouldSendNavigationInfoForSession(mSession)) {
        float desiredWidth = application.getResources().getDimensionPixelSize(
                R.dimen.custom_tabs_screenshot_width);
        float desiredHeight = application.getResources().getDimensionPixelSize(
                R.dimen.custom_tabs_screenshot_height);
        Rect bounds = ExternalPrerenderHandler.estimateContentSize(application, false);
        if (bounds.width() == 0 || bounds.height() == 0) {
            mContentBitmapWidth = (int) Math.round(desiredWidth);
            mContentBitmapHeight = (int) Math.round(desiredHeight);
        } else {
            // Compute a size that scales the content bitmap to fit one (or both) dimensions,
            // but also preserves aspect ratio.
            float scale =
                    Math.min(desiredWidth / bounds.width(), desiredHeight / bounds.height());
            mContentBitmapWidth = (int) Math.round(bounds.width() * scale);
            mContentBitmapHeight = (int) Math.round(bounds.height() * scale);
        }
    }
    mOpenedByChrome = openedByChrome;
    resetPageLoadTracking();
}
 
Example #4
Source File: Tab.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Called to swap out the current view with the one passed in.
 *
 * @param newContentViewCore The content view that should be swapped into the tab.
 * @param deleteOldNativeWebContents Whether to delete the native web
 *         contents of old view.
 * @param didStartLoad Whether
 *         WebContentsObserver::DidStartProvisionalLoadForFrame() has
 *         already been called.
 * @param didFinishLoad Whether WebContentsObserver::DidFinishLoad() has
 *         already been called.
 */
public void swapContentViewCore(ContentViewCore newContentViewCore,
        boolean deleteOldNativeWebContents, boolean didStartLoad, boolean didFinishLoad) {
    int originalWidth = 0;
    int originalHeight = 0;
    if (mContentViewCore != null) {
        originalWidth = mContentViewCore.getViewportWidthPix();
        originalHeight = mContentViewCore.getViewportHeightPix();
        mContentViewCore.onHide();
    }

    Rect bounds = new Rect();
    if (originalWidth == 0 && originalHeight == 0) {
        bounds = ExternalPrerenderHandler.estimateContentSize(
                (Application) getApplicationContext(), false);
        originalWidth = bounds.right - bounds.left;
        originalHeight = bounds.bottom - bounds.top;
    }

    destroyContentViewCore(deleteOldNativeWebContents);
    NativePage previousNativePage = mNativePage;
    mNativePage = null;
    // Size of the new ContentViewCore is zero at this point. If we don't call onSizeChanged(),
    // next onShow() call would send a resize message with the current ContentViewCore size
    // (zero) to the renderer process, although the new size will be set soon.
    // However, this size fluttering may confuse Blink and rendered result can be broken
    // (see http://crbug.com/340987).
    newContentViewCore.onSizeChanged(originalWidth, originalHeight, 0, 0);
    if (!bounds.isEmpty()) {
        nativeOnPhysicalBackingSizeChanged(mNativeTabAndroid,
                newContentViewCore.getWebContents(), bounds.right, bounds.bottom);
    }
    newContentViewCore.onShow();
    setContentViewCore(newContentViewCore);

    destroyNativePageInternal(previousNativePage);
    for (TabObserver observer : mObservers) {
        observer.onWebContentsSwapped(this, didStartLoad, didFinishLoad);
    }
}
 
Example #5
Source File: Tab.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Called to swap out the current view with the one passed in.
 *
 * @param newContentViewCore The content view that should be swapped into the tab.
 * @param deleteOldNativeWebContents Whether to delete the native web
 *         contents of old view.
 * @param didStartLoad Whether
 *         WebContentsObserver::DidStartProvisionalLoadForFrame() has
 *         already been called.
 * @param didFinishLoad Whether WebContentsObserver::DidFinishLoad() has
 *         already been called.
 */
public void swapContentViewCore(ContentViewCore newContentViewCore,
        boolean deleteOldNativeWebContents, boolean didStartLoad, boolean didFinishLoad) {
    int originalWidth = 0;
    int originalHeight = 0;
    if (mContentViewCore != null) {
        originalWidth = mContentViewCore.getViewportWidthPix();
        originalHeight = mContentViewCore.getViewportHeightPix();
        mContentViewCore.onHide();
    }

    Rect bounds = new Rect();
    if (originalWidth == 0 && originalHeight == 0) {
        bounds = ExternalPrerenderHandler.estimateContentSize(
                (Application) getApplicationContext(), false);
        originalWidth = bounds.right - bounds.left;
        originalHeight = bounds.bottom - bounds.top;
    }

    destroyContentViewCore(deleteOldNativeWebContents);
    NativePage previousNativePage = mNativePage;
    mNativePage = null;
    // Size of the new ContentViewCore is zero at this point. If we don't call onSizeChanged(),
    // next onShow() call would send a resize message with the current ContentViewCore size
    // (zero) to the renderer process, although the new size will be set soon.
    // However, this size fluttering may confuse Blink and rendered result can be broken
    // (see http://crbug.com/340987).
    newContentViewCore.onSizeChanged(originalWidth, originalHeight, 0, 0);
    if (!bounds.isEmpty()) {
        newContentViewCore.onPhysicalBackingSizeChanged(bounds.right, bounds.bottom);
    }
    newContentViewCore.onShow();
    setContentViewCore(newContentViewCore);

    mContentViewCore.attachImeAdapter();

    // If the URL has already committed (e.g. prerendering), tell process management logic that
    // it can rely on the process visibility signal for binding management.
    // TODO: Call ChildProcessLauncher#determinedVisibility() at a more intuitive time.
    // See crbug.com/537671
    if (!mContentViewCore.getWebContents().getLastCommittedUrl().equals("")) {
        ChildProcessLauncher.determinedVisibility(mContentViewCore.getCurrentRenderProcessId());
    }

    destroyNativePageInternal(previousNativePage);
    for (TabObserver observer : mObservers) {
        observer.onWebContentsSwapped(this, didStartLoad, didFinishLoad);
    }
}