Java Code Examples for org.chromium.chrome.browser.IntentHandler#startChromeLauncherActivityForTrustedIntent()

The following examples show how to use org.chromium.chrome.browser.IntentHandler#startChromeLauncherActivityForTrustedIntent() . 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: TabContextMenuItemDelegate.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void onOpenInChrome(String linkUrl, String pageUrl) {
    Intent chromeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl));
    chromeIntent.setPackage(mTab.getApplicationContext().getPackageName());
    chromeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    boolean activityStarted = false;
    if (pageUrl != null) {
        try {
            URI pageUri = URI.create(pageUrl);
            if (UrlUtilities.isInternalScheme(pageUri)) {
                IntentHandler.startChromeLauncherActivityForTrustedIntent(
                        chromeIntent, mTab.getApplicationContext());
                activityStarted = true;
            }
        } catch (IllegalArgumentException ex) {
            // Ignore the exception for creating the URI and launch the intent
            // without the trusted intent extras.
        }
    }

    if (!activityStarted) {
        Context context = mTab.getActivity();
        if (context == null) context = mTab.getApplicationContext();
        context.startActivity(chromeIntent);
        activityStarted = true;
    }
}
 
Example 2
Source File: TabContextMenuItemDelegate.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onOpenInChrome(String linkUrl, String pageUrl) {
    Intent chromeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl));
    chromeIntent.setPackage(mTab.getApplicationContext().getPackageName());
    chromeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    boolean activityStarted = false;
    if (pageUrl != null) {
        try {
            URI pageUri = URI.create(pageUrl);
            if (UrlUtilities.isInternalScheme(pageUri)) {
                IntentHandler.startChromeLauncherActivityForTrustedIntent(
                        chromeIntent, mTab.getApplicationContext());
                activityStarted = true;
            }
        } catch (IllegalArgumentException ex) {
            // Ignore the exception for creating the URI and launch the intent
            // without the trusted intent extras.
        }
    }

    if (!activityStarted) {
        Context context = mTab.getActivity();
        if (context == null) context = mTab.getApplicationContext();
        context.startActivity(chromeIntent);
        activityStarted = true;
    }
}
 
Example 3
Source File: TabContextMenuItemDelegate.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onOpenInChrome(String linkUrl, String pageUrl) {
    Intent chromeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl));
    chromeIntent.setPackage(mTab.getApplicationContext().getPackageName());
    chromeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    boolean activityStarted = false;
    if (pageUrl != null) {
        try {
            URI pageUri = URI.create(pageUrl);
            if (UrlUtilities.isInternalScheme(pageUri)) {
                IntentHandler.startChromeLauncherActivityForTrustedIntent(chromeIntent);
                activityStarted = true;
            }
        } catch (IllegalArgumentException ex) {
            // Ignore the exception for creating the URI and launch the intent
            // without the trusted intent extras.
        }
    }

    if (!activityStarted) {
        Context context = mTab.getActivity();
        if (context == null) context = mTab.getApplicationContext();
        context.startActivity(chromeIntent);
        activityStarted = true;
    }
}
 
Example 4
Source File: PhysicalWeb.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Starts the Activity that shows the list of Physical Web URLs.
 */
public static void showUrlList() {
    IntentHandler.startChromeLauncherActivityForTrustedIntent(
            new Intent(Intent.ACTION_VIEW, Uri.parse(UrlConstants.PHYSICAL_WEB_URL))
                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
 
Example 5
Source File: CustomTabActivity.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Opens the URL currently being displayed in the Custom Tab in the regular browser.
 * @param forceReparenting Whether tab reparenting should be forced for testing.
 *
 * @return Whether or not the tab was sent over successfully.
 */
boolean openCurrentUrlInBrowser(boolean forceReparenting) {
    Tab tab = getActivityTab();
    if (tab == null) return false;

    String url = tab.getUrl();
    if (DomDistillerUrlUtils.isDistilledPage(url)) {
        url = DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(url);
    }
    if (TextUtils.isEmpty(url)) url = getUrlToLoad();
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PARENT, false);

    boolean willChromeHandleIntent = getIntentDataProvider().isOpenedByChrome();
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
    try {
        willChromeHandleIntent |= ExternalNavigationDelegateImpl
                .willChromeHandleIntent(intent, true);
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }

    Bundle startActivityOptions = ActivityOptionsCompat.makeCustomAnimation(
            this, R.anim.abc_fade_in, R.anim.abc_fade_out).toBundle();
    if (willChromeHandleIntent || forceReparenting) {
        Runnable finalizeCallback = new Runnable() {
            @Override
            public void run() {
                finishAndClose(true);
            }
        };

        mMainTab = null;
        // mHasCreatedTabEarly == true => mMainTab != null in the rest of the code.
        mHasCreatedTabEarly = false;
        CustomTabsConnection.getInstance(getApplication()).resetPostMessageHandlerForSession(
                mSession, null);
        tab.detachAndStartReparenting(intent, startActivityOptions, finalizeCallback);
    } else {
        // Temporarily allowing disk access while fixing. TODO: http://crbug.com/581860
        StrictMode.allowThreadDiskWrites();
        try {
            if (mIntentDataProvider.isInfoPage()) {
                IntentHandler.startChromeLauncherActivityForTrustedIntent(intent);
            } else {
                startActivity(intent, startActivityOptions);
            }
        } finally {
            StrictMode.setThreadPolicy(oldPolicy);
        }
    }
    return true;
}