Search in sources :

Example 6 with WebContents

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

the class CustomTabActivity method createMainTab.

private Tab createMainTab() {
    CustomTabsConnection customTabsConnection = CustomTabsConnection.getInstance(getApplication());
    String url = getUrlToLoad();
    // Get any referrer that has been explicitly set by the app.
    String referrerUrl = IntentHandler.getReferrerUrlIncludingExtraHeaders(getIntent(), this);
    if (referrerUrl == null) {
        Referrer referrer = customTabsConnection.getReferrerForSession(mSession);
        if (referrer != null)
            referrerUrl = referrer.getUrl();
    }
    Tab tab = new Tab(TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID), Tab.INVALID_TAB_ID, false, this, getWindowAndroid(), TabLaunchType.FROM_EXTERNAL_APP, null, null);
    tab.setAppAssociatedWith(customTabsConnection.getClientPackageNameForSession(mSession));
    mPrerenderedUrl = customTabsConnection.getPrerenderedUrl(mSession);
    WebContents webContents = customTabsConnection.takePrerenderedUrl(mSession, url, referrerUrl);
    mHasPrerendered = webContents != null;
    if (!mHasPrerendered) {
        webContents = WarmupManager.getInstance().takeSpareWebContents(false, false);
    }
    if (webContents == null)
        webContents = WebContentsFactory.createWebContents(false, false);
    tab.initialize(webContents, getTabContentManager(), new CustomTabDelegateFactory(mIntentDataProvider.shouldEnableUrlBarHiding(), mIntentDataProvider.isOpenedByChrome()), false, false);
    initializeMainTab(tab);
    return tab;
}
Also used : WebContents(org.chromium.content_public.browser.WebContents) Tab(org.chromium.chrome.browser.tab.Tab) Referrer(org.chromium.content_public.common.Referrer)

Example 7 with WebContents

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

the class ChromeDownloadDelegate method closeBlankTab.

/**
     * Close a blank tab just opened for the download purpose.
     * @return true iff the tab was (already) closed.
     */
private boolean closeBlankTab() {
    if (mTab == null) {
        // We do not want caller to dismiss infobar.
        return true;
    }
    WebContents contents = mTab.getWebContents();
    boolean isInitialNavigation = contents == null || contents.getNavigationController().isInitialNavigation();
    if (isInitialNavigation) {
        // Tab is created just for download, close it.
        Activity activity = mTab.getWindowAndroid().getActivity().get();
        if (!(activity instanceof ChromeActivity))
            return true;
        TabModelSelector selector = ((ChromeActivity) activity).getTabModelSelector();
        return selector == null ? true : selector.closeTab(mTab);
    }
    return false;
}
Also used : WebContents(org.chromium.content_public.browser.WebContents) TabModelSelector(org.chromium.chrome.browser.tabmodel.TabModelSelector) ChromeActivity(org.chromium.chrome.browser.ChromeActivity) Activity(android.app.Activity) ChromeActivity(org.chromium.chrome.browser.ChromeActivity)

Example 8 with WebContents

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

the class CustomTabsConnection method prerenderUrl.

/**
     * Tries to request a prerender for a given URL.
     *
     * @param session Session the request comes from.
     * @param url URL to prerender.
     * @param extras extra parameters.
     * @param uid UID of the caller.
     * @return true if a prerender has been initiated.
     */
private boolean prerenderUrl(CustomTabsSessionToken session, String url, Bundle extras, int uid) {
    ThreadUtils.assertOnUiThread();
    // Ignores mayPrerender() for an empty URL, since it cancels an existing prerender.
    if (!mayPrerender(session) && !TextUtils.isEmpty(url))
        return false;
    if (!mWarmupHasBeenCalled.get())
        return false;
    // Last one wins and cancels the previous prerender.
    cancelPrerender(null);
    if (TextUtils.isEmpty(url))
        return false;
    boolean throttle = !shouldPrerenderOnCellularForSession(session);
    if (throttle && !mClientManager.isPrerenderingAllowed(uid))
        return false;
    // A prerender will be requested. Time to destroy the spare WebContents.
    WarmupManager.getInstance().destroySpareWebContents();
    Intent extrasIntent = new Intent();
    if (extras != null)
        extrasIntent.putExtras(extras);
    if (IntentHandler.getExtraHeadersFromIntent(extrasIntent) != null)
        return false;
    if (mExternalPrerenderHandler == null) {
        mExternalPrerenderHandler = new ExternalPrerenderHandler();
    }
    Rect contentBounds = ExternalPrerenderHandler.estimateContentSize(mApplication, true);
    Context context = mApplication.getApplicationContext();
    String referrer = IntentHandler.getReferrerUrlIncludingExtraHeaders(extrasIntent, context);
    if (referrer == null && getReferrerForSession(session) != null) {
        referrer = getReferrerForSession(session).getUrl();
    }
    if (referrer == null)
        referrer = "";
    WebContents webContents = mExternalPrerenderHandler.addPrerender(Profile.getLastUsedProfile(), url, referrer, contentBounds, shouldPrerenderOnCellularForSession(session));
    if (webContents == null)
        return false;
    if (throttle)
        mClientManager.registerPrerenderRequest(uid, url);
    mPrerender = new PrerenderedUrlParams(session, webContents, url, referrer, extras);
    RecordHistogram.recordBooleanHistogram("CustomTabs.PrerenderSessionUsesDefaultParameters", mClientManager.usesDefaultSessionParameters(session));
    return true;
}
Also used : Context(android.content.Context) WebContents(org.chromium.content_public.browser.WebContents) ExternalPrerenderHandler(org.chromium.chrome.browser.prerender.ExternalPrerenderHandler) Rect(android.graphics.Rect) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Example 9 with WebContents

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

the class InterceptNavigationDelegateImpl method maybeUpdateNavigationHistory.

/**
     * Updates navigation history if navigation is canceled due to intent handler. We go back to the
     * last committed entry index which was saved before the navigation, and remove the empty
     * entries from the navigation history. See crbug.com/426679
     */
public void maybeUpdateNavigationHistory() {
    WebContents webContents = mTab.getWebContents();
    if (mClearAllForwardHistoryRequired && webContents != null) {
        NavigationController navigationController = webContents.getNavigationController();
        int lastCommittedEntryIndex = getLastCommittedEntryIndex();
        while (navigationController.canGoForward()) {
            boolean ret = navigationController.removeEntryAtIndex(lastCommittedEntryIndex + 1);
            assert ret;
        }
    } else if (mShouldClearRedirectHistoryForTabClobbering && webContents != null) {
        // http://crbug/479056: Even if we clobber the current tab, we want to remove
        // redirect history to be consistent.
        NavigationController navigationController = webContents.getNavigationController();
        int indexBeforeRedirection = mTab.getTabRedirectHandler().getLastCommittedEntryIndexBeforeStartingNavigation();
        int lastCommittedEntryIndex = getLastCommittedEntryIndex();
        for (int i = lastCommittedEntryIndex - 1; i > indexBeforeRedirection; --i) {
            boolean ret = navigationController.removeEntryAtIndex(i);
            assert ret;
        }
    }
    mClearAllForwardHistoryRequired = false;
    mShouldClearRedirectHistoryForTabClobbering = false;
}
Also used : WebContents(org.chromium.content_public.browser.WebContents) NavigationController(org.chromium.content_public.browser.NavigationController)

Example 10 with WebContents

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

the class ChromeTabCreator method createNewTab.

/**
     * Creates a new tab and posts to UI.
     * @param loadUrlParams parameters of the url load.
     * @param type Information about how the tab was launched.
     * @param parent the parent tab, if present.
     * @param position the requested position (index in the tab model)
     * @param intent the source of the url if it isn't null.
     * @return The new tab.
     */
private Tab createNewTab(LoadUrlParams loadUrlParams, TabModel.TabLaunchType type, Tab parent, int position, Intent intent) {
    try {
        TraceEvent.begin("ChromeTabCreator.createNewTab");
        int parentId = parent != null ? parent.getId() : Tab.INVALID_TAB_ID;
        // Sanitize the url.
        loadUrlParams.setUrl(UrlFormatter.fixupUrl(loadUrlParams.getUrl()));
        loadUrlParams.setTransitionType(getTransitionType(type, intent));
        // Check if the tab is being created asynchronously.
        int assignedTabId = intent == null ? Tab.INVALID_TAB_ID : IntentUtils.safeGetIntExtra(intent, IntentHandler.EXTRA_TAB_ID, Tab.INVALID_TAB_ID);
        AsyncTabParams asyncParams = AsyncTabParamsManager.remove(assignedTabId);
        boolean openInForeground = mOrderController.willOpenInForeground(type, mIncognito);
        TabDelegateFactory delegateFactory = parent == null ? createDefaultTabDelegateFactory() : parent.getDelegateFactory();
        Tab tab;
        if (asyncParams != null && asyncParams.getTabToReparent() != null) {
            type = TabLaunchType.FROM_REPARENTING;
            openInForeground = true;
            TabReparentingParams params = (TabReparentingParams) asyncParams;
            tab = params.getTabToReparent();
            tab.attachAndFinishReparenting(mActivity, createDefaultTabDelegateFactory(), params);
        } else if (asyncParams != null && asyncParams.getWebContents() != null) {
            openInForeground = true;
            WebContents webContents = asyncParams.getWebContents();
            // A WebContents was passed through the Intent.  Create a new Tab to hold it.
            Intent parentIntent = IntentUtils.safeGetParcelableExtra(intent, IntentHandler.EXTRA_PARENT_INTENT);
            parentId = IntentUtils.safeGetIntExtra(intent, IntentHandler.EXTRA_PARENT_TAB_ID, parentId);
            assert TabModelUtils.getTabIndexById(mTabModel, assignedTabId) == TabModel.INVALID_TAB_INDEX;
            tab = Tab.createLiveTab(assignedTabId, mActivity, mIncognito, mNativeWindow, type, parentId, !openInForeground);
            tab.initialize(webContents, mTabContentManager, delegateFactory, !openInForeground, false);
            tab.setParentIntent(parentIntent);
            webContents.resumeLoadingCreatedWebContents();
        } else if (!openInForeground && SysUtils.isLowEndDevice()) {
            // On low memory devices the tabs opened in background are not loaded automatically
            // to preserve resources (cpu, memory, strong renderer binding) for the foreground
            // tab.
            tab = Tab.createTabForLazyLoad(mActivity, mIncognito, mNativeWindow, type, parentId, loadUrlParams);
            tab.initialize(null, mTabContentManager, delegateFactory, !openInForeground, false);
        } else {
            tab = Tab.createLiveTab(Tab.INVALID_TAB_ID, mActivity, mIncognito, mNativeWindow, type, parentId, !openInForeground);
            tab.initialize(null, mTabContentManager, delegateFactory, !openInForeground, false);
            tab.loadUrl(loadUrlParams);
        }
        tab.getTabRedirectHandler().updateIntent(intent);
        if (intent != null && intent.hasExtra(ServiceTabLauncher.LAUNCH_REQUEST_ID_EXTRA)) {
            ServiceTabLauncher.onWebContentsForRequestAvailable(intent.getIntExtra(ServiceTabLauncher.LAUNCH_REQUEST_ID_EXTRA, 0), tab.getWebContents());
        }
        mTabModel.addTab(tab, position, type);
        return tab;
    } finally {
        TraceEvent.end("ChromeTabCreator.createNewTab");
    }
}
Also used : WebContents(org.chromium.content_public.browser.WebContents) Tab(org.chromium.chrome.browser.tab.Tab) Intent(android.content.Intent) TabDelegateFactory(org.chromium.chrome.browser.tab.TabDelegateFactory)

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