Search in sources :

Example 1 with AsyncTabCreationParams

use of org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams 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 = OfflinePageUtils.getLoadUrlParamsForOpeningOfflineVersion(item.getUrl(), nativeGetOfflineIdByGuid(mNativeOfflinePageDownloadBridge, guid));
    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 : LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams) AsyncTabCreationParams(org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams) TabDelegate(org.chromium.chrome.browser.tabmodel.document.TabDelegate)

Example 2 with AsyncTabCreationParams

use of org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams in project AndroidChromium by JackyAndroid.

the class ServiceTabLauncher method launchTab.

/**
 * Launches the browser activity and launches a tab for |url|.
 *
 * @param context The context using which the URL is being loaded.
 * @param requestId Id of the request for launching this tab.
 * @param incognito Whether the tab should be launched in incognito mode.
 * @param url The URL which should be launched in a tab.
 * @param disposition The disposition requested by the navigation source.
 * @param referrerUrl URL of the referrer which is opening the page.
 * @param referrerPolicy The referrer policy to consider when applying the referrer.
 * @param extraHeaders Extra headers to apply when requesting the tab's URL.
 * @param postData Post-data to include in the tab URL's request body.
 */
@CalledByNative
public static void launchTab(final Context context, final int requestId, final boolean incognito, final String url, final int disposition, final String referrerUrl, final int referrerPolicy, final String extraHeaders, final ResourceRequestBody postData) {
    final TabDelegate tabDelegate = new TabDelegate(incognito);
    // 1. Launch WebAPK if one matches the target URL.
    if (ChromeWebApkHost.isEnabled()) {
        String webApkPackageName = WebApkValidator.queryWebApkPackage(context, url);
        if (webApkPackageName != null) {
            Intent intent = WebApkNavigationClient.createLaunchWebApkIntent(webApkPackageName, url);
            if (intent != null) {
                intent.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.NOTIFICATION);
                context.startActivity(intent);
                return;
            }
        }
    }
    // 2. Launch WebappActivity if one matches the target URL and was opened recently.
    // Otherwise, open the URL in a tab.
    final WebappDataStorage storage = WebappRegistry.getInstance().getWebappDataStorageForUrl(url);
    // been opened recently enough, open the URL in a tab.
    if (storage == null || !storage.wasLaunchedRecently()) {
        LoadUrlParams loadUrlParams = new LoadUrlParams(url, PageTransition.LINK);
        loadUrlParams.setPostData(postData);
        loadUrlParams.setVerbatimHeaders(extraHeaders);
        loadUrlParams.setReferrer(new Referrer(referrerUrl, referrerPolicy));
        AsyncTabCreationParams asyncParams = new AsyncTabCreationParams(loadUrlParams, requestId);
        tabDelegate.createNewTab(asyncParams, TabLaunchType.FROM_CHROME_UI, Tab.INVALID_TAB_ID);
    } else {
        // The URL is within the scope of a recently launched standalone-capable web app
        // on the home screen, so open it a standalone web app frame. An AsyncTask is
        // used because WebappDataStorage.createWebappLaunchIntent contains a Bitmap
        // decode operation and should not be run on the UI thread.
        // 
        // This currently assumes that the only source is notifications; any future use
        // which adds a different source will need to change this.
        new AsyncTask<Void, Void, Intent>() {

            @Override
            protected final Intent doInBackground(Void... nothing) {
                return storage.createWebappLaunchIntent();
            }

            @Override
            protected final void onPostExecute(Intent intent) {
                // Replace the web app URL with the URL from the notification. This is
                // within the webapp's scope, so it is valid.
                intent.putExtra(ShortcutHelper.EXTRA_URL, url);
                intent.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.NOTIFICATION);
                tabDelegate.createNewStandaloneFrame(intent);
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
}
Also used : Referrer(org.chromium.content_public.common.Referrer) Intent(android.content.Intent) TabDelegate(org.chromium.chrome.browser.tabmodel.document.TabDelegate) LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams) AsyncTabCreationParams(org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams) WebappDataStorage(org.chromium.chrome.browser.webapps.WebappDataStorage) CalledByNative(org.chromium.base.annotations.CalledByNative)

Aggregations

AsyncTabCreationParams (org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams)2 TabDelegate (org.chromium.chrome.browser.tabmodel.document.TabDelegate)2 LoadUrlParams (org.chromium.content_public.browser.LoadUrlParams)2 Intent (android.content.Intent)1 CalledByNative (org.chromium.base.annotations.CalledByNative)1 WebappDataStorage (org.chromium.chrome.browser.webapps.WebappDataStorage)1 Referrer (org.chromium.content_public.common.Referrer)1