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

The following examples show how to use org.chromium.chrome.browser.IntentHandler#getUrlFromIntent() . 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: CustomTabActivity.java    From 365browser with Apache License 2.0 7 votes vote down vote up
/**
 * Used to check whether an incoming intent can be handled by the
 * current {@link CustomTabContentHandler}.
 * @return Whether the active {@link CustomTabContentHandler} has handled the intent.
 */
public static boolean handleInActiveContentIfNeeded(Intent intent) {
    if (sActiveContentHandler == null) return false;

    if (sActiveContentHandler.shouldIgnoreIntent(intent)) {
        Log.w(TAG, "Incoming intent to Custom Tab was ignored.");
        return false;
    }

    CustomTabsSessionToken session = CustomTabsSessionToken.getSessionTokenFromIntent(intent);
    if (session == null || !session.equals(sActiveContentHandler.getSession())) return false;

    String url = IntentHandler.getUrlFromIntent(intent);
    if (TextUtils.isEmpty(url)) return false;
    sActiveContentHandler.loadUrlAndTrackFromTimestamp(new LoadUrlParams(url),
            IntentHandler.getTimestampFromIntent(intent));
    return true;
}
 
Example 2
Source File: IntentWithGesturesHandler.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Generate a new token for the intent that has user gesture. This will
 * invalidate the token on the previously launched intent with user gesture.
 *
 * @param intent Intent with user gesture.
 */
public void onNewIntentWithGesture(Intent intent) {
    if (mSecureRandomInitializer != null) {
        try {
            mSecureRandom = mSecureRandomInitializer.get();
        } catch (InterruptedException | ExecutionException e) {
            Log.e(TAG, "Error fetching SecureRandom", e);
        }
        mSecureRandomInitializer = null;
    }
    if (mSecureRandom == null) return;
    mIntentToken = new byte[32];
    mSecureRandom.nextBytes(mIntentToken);
    intent.putExtra(EXTRA_USER_GESTURE_TOKEN, mIntentToken);
    mUri = IntentHandler.getUrlFromIntent(intent);
}
 
Example 3
Source File: IntentWithGesturesHandler.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Generate a new token for the intent that has user gesture. This will
 * invalidate the token on the previously launched intent with user gesture.
 *
 * @param intent Intent with user gesture.
 */
public void onNewIntentWithGesture(Intent intent) {
    if (mSecureRandomInitializer != null) {
        try {
            mSecureRandom = mSecureRandomInitializer.get();
        } catch (InterruptedException | ExecutionException e) {
            Log.e(TAG, "Error fetching SecureRandom", e);
        }
        mSecureRandomInitializer = null;
    }
    if (mSecureRandom == null) return;
    mIntentToken = new byte[32];
    mSecureRandom.nextBytes(mIntentToken);
    intent.putExtra(EXTRA_USER_GESTURE_TOKEN, mIntentToken);
    mUri = IntentHandler.getUrlFromIntent(intent);
}
 
Example 4
Source File: CustomTabActivity.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Used to check whether an incoming intent can be handled by the
 * current {@link CustomTabContentHandler}.
 * @return Whether the active {@link CustomTabContentHandler} has handled the intent.
 */
public static boolean handleInActiveContentIfNeeded(Intent intent) {
    if (sActiveContentHandler == null) return false;

    if (sActiveContentHandler.shouldIgnoreIntent(intent)) {
        Log.w(TAG, "Incoming intent to Custom Tab was ignored.");
        return false;
    }

    CustomTabsSessionToken session = CustomTabsSessionToken.getSessionTokenFromIntent(intent);
    if (session == null || !session.equals(sActiveContentHandler.getSession())) return false;

    String url = IntentHandler.getUrlFromIntent(intent);
    if (TextUtils.isEmpty(url)) return false;
    sActiveContentHandler.loadUrlAndTrackFromTimestamp(new LoadUrlParams(url),
            IntentHandler.getTimestampFromIntent(intent));
    return true;
}
 
Example 5
Source File: CustomTabActivity.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * @return The URL that should be used from this intent. If it is a WebLite url, it may be
 *         overridden if the Data Reduction Proxy is using Lo-Fi previews.
 */
private String getUrlToLoad() {
    String url = IntentHandler.getUrlFromIntent(getIntent());

    // Intents fired for media viewers have an additional file:// URI passed along so that the
    // tab can display the actual filename to the user when it is loaded.
    if (mIntentDataProvider.isMediaViewer()) {
        String mediaViewerUrl = mIntentDataProvider.getMediaViewerUrl();
        if (!TextUtils.isEmpty(mediaViewerUrl)) {
            Uri mediaViewerUri = Uri.parse(mediaViewerUrl);
            if (UrlConstants.FILE_SCHEME.equals(mediaViewerUri.getScheme())) {
                url = mediaViewerUrl;
            }
        }
    }

    if (!TextUtils.isEmpty(url)) {
        url = DataReductionProxySettings.getInstance().maybeRewriteWebliteUrl(url);
    }

    return url;
}
 
Example 6
Source File: IntentWithGesturesHandler.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Generate a new token for the intent that has user gesture. This will
 * invalidate the token on the previously launched intent with user gesture.
 *
 * @param intent Intent with user gesture.
 */
public void onNewIntentWithGesture(Intent intent) {
    if (mSecureRandomInitializer != null) {
        try {
            mSecureRandom = mSecureRandomInitializer.get();
        } catch (InterruptedException | ExecutionException e) {
            Log.e(TAG, "Error fetching SecureRandom", e);
        }
        mSecureRandomInitializer = null;
    }
    if (mSecureRandom == null) return;
    mIntentToken = new byte[32];
    mSecureRandom.nextBytes(mIntentToken);
    intent.putExtra(EXTRA_USER_GESTURE_TOKEN, mIntentToken);
    mUri = IntentHandler.getUrlFromIntent(intent);
}
 
Example 7
Source File: CustomTabActivity.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Used to check whether an incoming intent can be handled by the
 * current {@link CustomTabContentHandler}.
 * @return Whether the active {@link CustomTabContentHandler} has handled the intent.
 */
public static boolean handleInActiveContentIfNeeded(Intent intent) {
    if (sActiveContentHandler == null) return false;

    if (sActiveContentHandler.shouldIgnoreIntent(intent)) {
        Log.w(TAG, "Incoming intent to Custom Tab was ignored.");
        return false;
    }

    CustomTabsSessionToken session = CustomTabsSessionToken.getSessionTokenFromIntent(intent);
    if (session == null || !session.equals(sActiveContentHandler.getSession())) return false;

    String url = IntentHandler.getUrlFromIntent(intent);
    if (TextUtils.isEmpty(url)) return false;
    sActiveContentHandler.loadUrlAndTrackFromTimestamp(new LoadUrlParams(url),
            IntentHandler.getTimestampFromIntent(intent));
    return true;
}
 
Example 8
Source File: ChromeLauncherActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether or not an Herb prototype may hijack an Intent.
 */
public static boolean canBeHijackedByHerb(Intent intent) {
    String url = IntentHandler.getUrlFromIntent(intent);

    // Only VIEW Intents with URLs are rerouted to Custom Tabs.
    if (intent == null || !TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())
            || TextUtils.isEmpty(url)) {
        return false;
    }

    // Don't open explicitly opted out intents in custom tabs.
    if (CustomTabsIntent.shouldAlwaysUseBrowserUI(intent)) {
        return false;
    }

    // Don't reroute Chrome Intents.
    Context context = ContextUtils.getApplicationContext();
    if (TextUtils.equals(context.getPackageName(),
            IntentUtils.safeGetStringExtra(intent, Browser.EXTRA_APPLICATION_ID))
            || IntentHandler.wasIntentSenderChrome(intent, context)) {
        return false;
    }

    // Don't reroute internal chrome URLs.
    try {
        URI uri = URI.create(url);
        if (UrlUtilities.isInternalScheme(uri)) return false;
    } catch (IllegalArgumentException e) {
        return false;
    }

    // Don't reroute Home screen shortcuts.
    if (IntentUtils.safeHasExtra(intent, ShortcutHelper.EXTRA_SOURCE)) {
        return false;
    }

    return true;
}
 
Example 9
Source File: ChromeLauncherActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether the intent is for launching a Custom Tab.
 */
public static boolean isCustomTabIntent(Intent intent) {
    if (intent == null
            || CustomTabsIntent.shouldAlwaysUseBrowserUI(intent)
            || !intent.hasExtra(CustomTabsIntent.EXTRA_SESSION)) {
        return false;
    }
    return IntentHandler.getUrlFromIntent(intent) != null;
}
 
Example 10
Source File: ChromeLauncherActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether or not an Herb prototype may hijack an Intent.
 */
public static boolean canBeHijackedByHerb(Intent intent) {
    String url = IntentHandler.getUrlFromIntent(intent);

    // Only VIEW Intents with URLs are rerouted to Custom Tabs.
    if (intent == null || !TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())
            || TextUtils.isEmpty(url)) {
        return false;
    }

    // Don't open explicitly opted out intents in custom tabs.
    if (CustomTabsIntent.shouldAlwaysUseBrowserUI(intent)) {
        return false;
    }

    // Don't reroute Chrome Intents.
    Context context = ContextUtils.getApplicationContext();
    if (TextUtils.equals(context.getPackageName(),
            IntentUtils.safeGetStringExtra(intent, Browser.EXTRA_APPLICATION_ID))
            || IntentHandler.wasIntentSenderChrome(intent)) {
        return false;
    }

    // Don't reroute internal chrome URLs.
    try {
        URI uri = URI.create(url);
        if (UrlUtilities.isInternalScheme(uri)) return false;
    } catch (IllegalArgumentException e) {
        return false;
    }

    // Don't reroute Home screen shortcuts.
    if (IntentUtils.safeHasExtra(intent, ShortcutHelper.EXTRA_SOURCE)) {
        return false;
    }

    return true;
}
 
Example 11
Source File: ChromeLauncherActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** When started with an intent, maybe pre-resolve the domain. */
private void maybePrefetchDnsInBackground() {
    if (getIntent() != null && Intent.ACTION_VIEW.equals(getIntent().getAction())) {
        String maybeUrl = IntentHandler.getUrlFromIntent(getIntent());
        if (maybeUrl != null) {
            WarmupManager.getInstance().maybePrefetchDnsForUrlInBackground(this, maybeUrl);
        }
    }
}
 
Example 12
Source File: ChromeLauncherActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether the intent is for launching a Custom Tab.
 */
public static boolean isCustomTabIntent(Intent intent) {
    if (intent == null
            || CustomTabsIntent.shouldAlwaysUseBrowserUI(intent)
            || !intent.hasExtra(CustomTabsIntent.EXTRA_SESSION)) {
        return false;
    }
    return IntentHandler.getUrlFromIntent(intent) != null;
}
 
Example 13
Source File: ChromeLauncherActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/** When started with an intent, maybe pre-resolve the domain. */
private void maybePrefetchDnsInBackground() {
    if (getIntent() != null && Intent.ACTION_VIEW.equals(getIntent().getAction())) {
        String maybeUrl = IntentHandler.getUrlFromIntent(getIntent());
        if (maybeUrl != null) {
            WarmupManager.getInstance().maybePrefetchDnsForUrlInBackground(this, maybeUrl);
        }
    }
}
 
Example 14
Source File: CustomTabActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @return The URL that should be used from this intent. If it is a WebLite url, it may be
 *         overridden if the Data Reduction Proxy is using Lo-Fi previews.
 */
private String getUrlToLoad() {
    String url = IntentHandler.getUrlFromIntent(getIntent());
    if (!TextUtils.isEmpty(url)) {
        url = DataReductionProxySettings.getInstance().maybeRewriteWebliteUrl(url);
    }
    return url;
}
 
Example 15
Source File: ChromeLauncherActivity.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether the intent is for launching a Custom Tab.
 */
public static boolean isCustomTabIntent(Intent intent) {
    if (intent == null || !intent.hasExtra(CustomTabsIntent.EXTRA_SESSION)) {
        return false;
    }
    return IntentHandler.getUrlFromIntent(intent) != null;
}
 
Example 16
Source File: ChromeLauncherActivity.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether or not an Herb prototype may hijack an Intent.
 */
public static boolean canBeHijackedByHerb(Intent intent) {
    String url = IntentHandler.getUrlFromIntent(intent);

    // Only VIEW Intents with URLs are rerouted to Custom Tabs.
    if (intent == null || !TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())
            || TextUtils.isEmpty(url)) {
        return false;
    }

    // Don't reroute Chrome Intents.
    Context context = ContextUtils.getApplicationContext();
    if (TextUtils.equals(context.getPackageName(),
            IntentUtils.safeGetStringExtra(intent, Browser.EXTRA_APPLICATION_ID))) {
        return false;
    }

    // Don't reroute internal chrome URLs.
    try {
        URI uri = URI.create(url);
        if (UrlUtilities.isInternalScheme(uri)) return false;
    } catch (IllegalArgumentException e) {
        return false;
    }

    return true;
}
 
Example 17
Source File: ChromeLauncherActivity.java    From delion with Apache License 2.0 5 votes vote down vote up
/** When started with an intent, maybe pre-resolve the domain. */
private void maybePrefetchDnsInBackground() {
    if (getIntent() != null && Intent.ACTION_VIEW.equals(getIntent().getAction())) {
        String maybeUrl = IntentHandler.getUrlFromIntent(getIntent());
        if (maybeUrl != null) {
            WarmupManager.getInstance().maybePrefetchDnsForUrlInBackground(this, maybeUrl);
        }
    }
}
 
Example 18
Source File: CustomTabActivity.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * @return The URL that should be used from this intent. If it is a WebLite url, it may be
 *         overridden if the Data Reduction Proxy is using Lo-Fi previews.
 */
private String getUrlToLoad() {
    String url = IntentHandler.getUrlFromIntent(getIntent());
    if (!TextUtils.isEmpty(url)) {
        url = DataReductionProxySettings.getInstance().maybeRewriteWebliteUrl(url);
    }
    return url;
}
 
Example 19
Source File: InstantAppsHandler.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private boolean handleIncomingIntentInternal(
        Context context, Intent intent, boolean isCustomTabsIntent, long startTime) {
    boolean isEnabled = isEnabled(context);
    if (!isEnabled || (isCustomTabsIntent && !IntentUtils.safeGetBooleanExtra(
            intent, CUSTOM_APPS_INSTANT_APP_EXTRA, false))) {
        Log.i(TAG, "Not handling with Instant Apps. Enabled? " + isEnabled);
        return false;
    }

    if (IntentUtils.safeGetBooleanExtra(intent, DO_NOT_LAUNCH_EXTRA, false)) {
        maybeRecordFallbackStats(intent);
        Log.i(TAG, "Not handling with Instant Apps (DO_NOT_LAUNCH_EXTRA)");
        return false;
    }

    if (IntentUtils.safeGetBooleanExtra(
            intent, IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, false)
            || IntentUtils.safeHasExtra(intent, ShortcutHelper.EXTRA_SOURCE)
            || isIntentFromChrome(context, intent)
            || (IntentHandler.getUrlFromIntent(intent) == null)) {
        Log.i(TAG, "Not handling with Instant Apps (other)");
        return false;
    }

    // Used to search for the intent handlers. Needs null component to return correct results.
    Intent intentCopy = new Intent(intent);
    intentCopy.setComponent(null);
    Intent selector = intentCopy.getSelector();
    if (selector != null) selector.setComponent(null);

    if (!(isCustomTabsIntent || isChromeDefaultHandler(context))
            || ExternalNavigationDelegateImpl.isPackageSpecializedHandler(
                    context, null, intentCopy)) {
        // Chrome is not the default browser or a specialized handler exists.
        Log.i(TAG, "Not handling with Instant Apps because Chrome is not default or "
                + "there's a specialized handler");
        return false;
    }

    Intent callbackIntent = new Intent(intent);
    callbackIntent.putExtra(DO_NOT_LAUNCH_EXTRA, true);
    callbackIntent.putExtra(INSTANT_APP_START_TIME_EXTRA, startTime);

    return tryLaunchingInstantApp(context, intent, isCustomTabsIntent, callbackIntent);
}
 
Example 20
Source File: InstantAppsHandler.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private boolean handleIncomingIntentInternal(
        Context context, Intent intent, boolean isCustomTabsIntent, long startTime,
        boolean isRedirect) {
    if (!isRedirect && !isCustomTabsIntent && BuildInfo.isAtLeastO()) {
        Log.i(TAG, "Disabled for Android O+");
        return false;
    }

    if (isCustomTabsIntent && !IntentUtils.safeGetBooleanExtra(
            intent, CUSTOM_APPS_INSTANT_APP_EXTRA, false)) {
        Log.i(TAG, "Not handling with Instant Apps (missing CUSTOM_APPS_INSTANT_APP_EXTRA)");
        return false;
    }

    if (IntentUtils.safeGetBooleanExtra(intent, DO_NOT_LAUNCH_EXTRA, false)
            || (BuildInfo.isAtLeastO() && (intent.getFlags() & FLAG_DO_NOT_LAUNCH) != 0)) {
        maybeRecordFallbackStats(intent);
        Log.i(TAG, "Not handling with Instant Apps (DO_NOT_LAUNCH_EXTRA)");
        return false;
    }

    if (IntentUtils.safeGetBooleanExtra(
            intent, IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, false)
            || IntentUtils.safeHasExtra(intent, ShortcutHelper.EXTRA_SOURCE)
            || isIntentFromChrome(context, intent)
            || (IntentHandler.getUrlFromIntent(intent) == null)) {
        Log.i(TAG, "Not handling with Instant Apps (other)");
        return false;
    }

    // Used to search for the intent handlers. Needs null component to return correct results.
    Intent intentCopy = new Intent(intent);
    intentCopy.setComponent(null);
    Intent selector = intentCopy.getSelector();
    if (selector != null) selector.setComponent(null);

    if (!(isCustomTabsIntent || isChromeDefaultHandler(context))
            || ExternalNavigationDelegateImpl.isPackageSpecializedHandler(null, intentCopy)) {
        // Chrome is not the default browser or a specialized handler exists.
        Log.i(TAG, "Not handling with Instant Apps because Chrome is not default or "
                + "there's a specialized handler");
        return false;
    }

    Intent callbackIntent = new Intent(intent);
    callbackIntent.putExtra(DO_NOT_LAUNCH_EXTRA, true);
    callbackIntent.putExtra(INSTANT_APP_START_TIME_EXTRA, startTime);

    return tryLaunchingInstantApp(context, intent, isCustomTabsIntent, callbackIntent);
}