Search in sources :

Example 26 with LoadUrlParams

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

the class DownloadUtils method showDownloadManager.

/**
     * Displays the download manager UI. Note the UI is different on tablets and on phones.
     * @return Whether the UI was shown.
     */
public static boolean showDownloadManager(@Nullable Activity activity, @Nullable Tab tab) {
    if (!isDownloadHomeEnabled())
        return false;
    // Figure out what tab was last being viewed by the user.
    if (activity == null)
        activity = ApplicationStatus.getLastTrackedFocusedActivity();
    if (tab == null && activity instanceof ChromeTabbedActivity) {
        tab = ((ChromeTabbedActivity) activity).getActivityTab();
    }
    Context appContext = ContextUtils.getApplicationContext();
    if (DeviceFormFactor.isTablet(appContext)) {
        // Download Home shows up as a tab on tablets.
        LoadUrlParams params = new LoadUrlParams(UrlConstants.DOWNLOADS_URL);
        if (tab == null || !tab.isInitialized()) {
            // Open a new tab, which pops Chrome into the foreground.
            TabDelegate delegate = new TabDelegate(false);
            delegate.createNewTab(params, TabLaunchType.FROM_CHROME_UI, null);
        } else {
            // Download Home shows up inside an existing tab, but only if the last Activity was
            // the ChromeTabbedActivity.
            tab.loadUrl(params);
            // Bring Chrome to the foreground, if possible.
            Intent intent = Tab.createBringTabToFrontIntent(tab.getId());
            if (intent != null) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                IntentUtils.safeStartActivity(appContext, intent);
            }
        }
    } else {
        // Download Home shows up as a new Activity on phones.
        Intent intent = new Intent();
        intent.setClass(appContext, DownloadActivity.class);
        if (tab != null)
            intent.putExtra(EXTRA_IS_OFF_THE_RECORD, tab.isIncognito());
        if (activity == null) {
            // Stands alone in its own task.
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            appContext.startActivity(intent);
        } else {
            // Sits on top of another Activity.
            intent.putExtra(IntentHandler.EXTRA_PARENT_COMPONENT, activity.getComponentName());
            activity.startActivity(intent);
        }
    }
    return true;
}
Also used : Context(android.content.Context) ChromeTabbedActivity(org.chromium.chrome.browser.ChromeTabbedActivity) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams) TabDelegate(org.chromium.chrome.browser.tabmodel.document.TabDelegate)

Example 27 with LoadUrlParams

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

the class ReaderModeManager method createNewTab.

/**
     * Open a link from the panel in a new tab.
     * @param url The URL to load.
     */
public void createNewTab(String url) {
    if (mChromeActivity == null)
        return;
    Tab currentTab = mTabModelSelector.getCurrentTab();
    if (currentTab == null)
        return;
    TabCreatorManager.TabCreator tabCreator = mChromeActivity.getTabCreator(currentTab.isIncognito());
    if (tabCreator == null)
        return;
    tabCreator.createNewTab(new LoadUrlParams(url, PageTransition.LINK), TabModel.TabLaunchType.FROM_LINK, mChromeActivity.getActivityTab());
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab) TabCreatorManager(org.chromium.chrome.browser.tabmodel.TabCreatorManager) LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams)

Example 28 with LoadUrlParams

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

the class OfflinePageDownloadBridge method openItem.

/**
     * 'Opens' the offline page identified by the GUID.
     * This is done by creating a new tab and navigating it to the saved local snapshot.
     * No automatic redirection is happening based on the connection status.
     * If the item with specified GUID is not found or can't be opened, nothing happens.
     * @param guid          GUID of the item to open.
     * @param componentName If specified, targets a specific Activity to open the offline page in.
     */
@Override
public void openItem(String guid, @Nullable ComponentName componentName) {
    OfflinePageDownloadItem item = getItem(guid);
    if (item == null)
        return;
    LoadUrlParams params = new LoadUrlParams(item.getUrl());
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("X-Chrome-offline", "persist=1 reason=download id=" + Long.toString(nativeGetOfflineIdByGuid(mNativeOfflinePageDownloadBridge, guid)));
    params.setExtraHeaders(headers);
    AsyncTabCreationParams asyncParams = componentName == null ? new AsyncTabCreationParams(params) : new AsyncTabCreationParams(params, componentName);
    final TabDelegate tabDelegate = new TabDelegate(false);
    tabDelegate.createNewTab(asyncParams, TabLaunchType.FROM_CHROME_UI, Tab.INVALID_TAB_ID);
}
Also used : HashMap(java.util.HashMap) LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams) AsyncTabCreationParams(org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams) TabDelegate(org.chromium.chrome.browser.tabmodel.document.TabDelegate)

Example 29 with LoadUrlParams

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

the class Tab method openNewTab.

@CalledByNative
protected void openNewTab(String url, String extraHeaders, ResourceRequestBody postData, int disposition, boolean hasParent, boolean isRendererInitiated) {
    if (isClosing())
        return;
    boolean incognito = isIncognito();
    TabLaunchType tabLaunchType = TabLaunchType.FROM_LONGPRESS_FOREGROUND;
    Tab parentTab = hasParent ? this : null;
    switch(disposition) {
        // fall through
        case WindowOpenDisposition.NEW_WINDOW:
        case WindowOpenDisposition.NEW_FOREGROUND_TAB:
            break;
        // fall through
        case WindowOpenDisposition.NEW_POPUP:
        case WindowOpenDisposition.NEW_BACKGROUND_TAB:
            tabLaunchType = TabLaunchType.FROM_LONGPRESS_BACKGROUND;
            break;
        case WindowOpenDisposition.OFF_THE_RECORD:
            assert incognito;
            incognito = true;
            break;
        default:
            assert false;
    }
    // is not accessible, then we can't open a new tab.
    if (shouldIgnoreNewTab(url, incognito) || getTabModelSelector() == null)
        return;
    LoadUrlParams loadUrlParams = new LoadUrlParams(url);
    loadUrlParams.setVerbatimHeaders(extraHeaders);
    loadUrlParams.setPostData(postData);
    loadUrlParams.setIsRendererInitiated(isRendererInitiated);
    getTabModelSelector().openNewTab(loadUrlParams, tabLaunchType, parentTab, incognito);
}
Also used : LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams) TabLaunchType(org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType) CalledByNative(org.chromium.base.annotations.CalledByNative)

Example 30 with LoadUrlParams

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

the class Tab method unfreezeContents.

/**
     * Restores the WebContents from its saved state.  This should only be called if the tab is
     * frozen with a saved TabState, and NOT if it was frozen for a lazy load.
     * @return Whether or not the restoration was successful.
     */
protected boolean unfreezeContents() {
    try {
        TraceEvent.begin("Tab.unfreezeContents");
        assert mFrozenContentsState != null;
        assert getContentViewCore() == null;
        WebContents webContents = mFrozenContentsState.restoreContentsFromByteBuffer(isHidden());
        if (webContents == null) {
            // State restore failed, just create a new empty web contents as that is the best
            // that can be done at this point. TODO(jcivelli) http://b/5910521 - we should show
            // an error page instead of a blank page in that case (and the last loaded URL).
            webContents = WebContentsFactory.createWebContents(isIncognito(), isHidden());
            mTabUma = new TabUma(TabCreationState.FROZEN_ON_RESTORE_FAILED);
            mFailedToRestore = true;
        }
        mFrozenContentsState = null;
        initContentViewCore(webContents);
        if (mFailedToRestore) {
            String url = TextUtils.isEmpty(mUrl) ? UrlConstants.NTP_URL : mUrl;
            loadUrl(new LoadUrlParams(url, PageTransition.GENERATED));
        }
        return !mFailedToRestore;
    } finally {
        TraceEvent.end("Tab.unfreezeContents");
    }
}
Also used : WebContents(org.chromium.content_public.browser.WebContents) LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams)

Aggregations

LoadUrlParams (org.chromium.content_public.browser.LoadUrlParams)35 Tab (org.chromium.chrome.browser.tab.Tab)9 Intent (android.content.Intent)6 Referrer (org.chromium.content_public.common.Referrer)5 TabDelegate (org.chromium.chrome.browser.tabmodel.document.TabDelegate)4 PendingIntent (android.app.PendingIntent)3 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)3 Context (android.content.Context)2 CustomTabsSessionToken (android.support.customtabs.CustomTabsSessionToken)2 AlertDialog (android.support.v7.app.AlertDialog)2 View (android.view.View)2 CalledByNative (org.chromium.base.annotations.CalledByNative)2 TabLaunchType (org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType)2 AsyncTabCreationParams (org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams)2 DialogInterface (android.content.DialogInterface)1 OnClickListener (android.content.DialogInterface.OnClickListener)1 SharedPreferences (android.content.SharedPreferences)1 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 SparseIntArray (android.util.SparseIntArray)1