Java Code Examples for org.chromium.chrome.browser.util.IntentUtils#safeGetBundleExtra()

The following examples show how to use org.chromium.chrome.browser.util.IntentUtils#safeGetBundleExtra() . 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: IntentHandler.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a String (or null) containing the extra headers sent by the intent, if any.
 *
 * This methods skips the referrer header.
 *
 * @param intent The intent containing the bundle extra with the HTTP headers.
 */
public static String getExtraHeadersFromIntent(Intent intent) {
    Bundle bundleExtraHeaders = IntentUtils.safeGetBundleExtra(intent, Browser.EXTRA_HEADERS);
    if (bundleExtraHeaders == null) return null;
    StringBuilder extraHeaders = new StringBuilder();
    Iterator<String> keys = bundleExtraHeaders.keySet().iterator();
    while (keys.hasNext()) {
        String key = keys.next();
        String value = bundleExtraHeaders.getString(key);
        if ("referer".equals(key.toLowerCase(Locale.US))) continue;
        if (extraHeaders.length() != 0) extraHeaders.append("\n");
        extraHeaders.append(key);
        extraHeaders.append(": ");
        extraHeaders.append(value);
    }
    return extraHeaders.length() == 0 ? null : extraHeaders.toString();
}
 
Example 2
Source File: IntentHandler.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a String (or null) containing the extra headers sent by the intent, if any.
 *
 * This methods skips the referrer header.
 *
 * @param intent The intent containing the bundle extra with the HTTP headers.
 */
public static String getExtraHeadersFromIntent(Intent intent) {
    Bundle bundleExtraHeaders = IntentUtils.safeGetBundleExtra(intent, Browser.EXTRA_HEADERS);
    if (bundleExtraHeaders == null) return null;
    StringBuilder extraHeaders = new StringBuilder();
    Iterator<String> keys = bundleExtraHeaders.keySet().iterator();
    while (keys.hasNext()) {
        String key = keys.next();
        String value = bundleExtraHeaders.getString(key);
        if ("referer".equals(key.toLowerCase(Locale.US))) continue;
        if (extraHeaders.length() != 0) extraHeaders.append("\n");
        extraHeaders.append(key);
        extraHeaders.append(": ");
        extraHeaders.append(value);
    }
    return extraHeaders.length() == 0 ? null : extraHeaders.toString();
}
 
Example 3
Source File: IntentHandler.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a String (or null) containing the extra headers sent by the intent, if any.
 *
 * This methods skips the referrer header.
 *
 * @param intent The intent containing the bundle extra with the HTTP headers.
 */
public static String getExtraHeadersFromIntent(Intent intent) {
    Bundle bundleExtraHeaders = IntentUtils.safeGetBundleExtra(intent, Browser.EXTRA_HEADERS);
    if (bundleExtraHeaders == null) return null;
    StringBuilder extraHeaders = new StringBuilder();
    Iterator<String> keys = bundleExtraHeaders.keySet().iterator();
    while (keys.hasNext()) {
        String key = keys.next();
        String value = bundleExtraHeaders.getString(key);
        if ("referer".equals(key.toLowerCase(Locale.US))) continue;
        if (extraHeaders.length() != 0) extraHeaders.append("\n");
        extraHeaders.append(key);
        extraHeaders.append(": ");
        extraHeaders.append(value);
    }
    return extraHeaders.length() == 0 ? null : extraHeaders.toString();
}
 
Example 4
Source File: CustomButtonParams.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a list of {@link CustomButtonParams} from the intent sent by clients.
 * @param intent The intent sent by the client.
 * @return A list of parsed {@link CustomButtonParams}. Return an empty list if input is invalid
 */
static List<CustomButtonParams> fromIntent(Context context, Intent intent) {
    List<CustomButtonParams> paramsList = new ArrayList<>(1);
    if (intent == null) return paramsList;

    Bundle singleBundle = IntentUtils.safeGetBundleExtra(intent,
            CustomTabsIntent.EXTRA_ACTION_BUTTON_BUNDLE);
    ArrayList<Bundle> bundleList = IntentUtils.getParcelableArrayListExtra(intent,
            CustomTabsIntent.EXTRA_TOOLBAR_ITEMS);
    boolean tinted = IntentUtils.safeGetBooleanExtra(intent,
            CustomTabsIntent.EXTRA_TINT_ACTION_BUTTON, false);
    if (singleBundle != null) {
        CustomButtonParams singleParams = fromBundle(context, singleBundle, tinted, false);
        if (singleParams != null) paramsList.add(singleParams);
    }
    if (bundleList != null) {
        Set<Integer> ids = new HashSet<>();
        for (Bundle bundle : bundleList) {
            CustomButtonParams params = fromBundle(context, bundle, tinted, true);
            if (params == null) {
                continue;
            } else if (ids.contains(params.getId())) {
                Log.e(TAG, "Bottom bar items contain duplicate id: " + params.getId());
                continue;
            }
            ids.add(params.getId());
            paramsList.add(params);
        }
    }
    return paramsList;
}
 
Example 5
Source File: IntentHandler.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the referrer, looking in the Intent extra and in the extra headers extra.
 *
 * The referrer extra takes priority over the "extra headers" one.
 *
 * @param intent The Intent containing the extras.
 * @param context The application context.
 * @return The referrer, or null.
 */
public static String getReferrerUrlIncludingExtraHeaders(Intent intent, Context context) {
    String referrerUrl = getReferrerUrl(intent, context);
    if (referrerUrl != null) return referrerUrl;

    Bundle bundleExtraHeaders = IntentUtils.safeGetBundleExtra(intent, Browser.EXTRA_HEADERS);
    if (bundleExtraHeaders == null) return null;
    for (String key : bundleExtraHeaders.keySet()) {
        String value = bundleExtraHeaders.getString(key);
        if ("referer".equals(key.toLowerCase(Locale.US)) && isValidReferrerHeader(value)) {
            return value;
        }
    }
    return null;
}
 
Example 6
Source File: CustomButtonParams.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a list of {@link CustomButtonParams} from the intent sent by clients.
 * @param intent The intent sent by the client.
 * @return A list of parsed {@link CustomButtonParams}. Return an empty list if input is invalid
 */
static List<CustomButtonParams> fromIntent(Context context, Intent intent) {
    List<CustomButtonParams> paramsList = new ArrayList<>(1);
    if (intent == null) return paramsList;

    Bundle singleBundle = IntentUtils.safeGetBundleExtra(intent,
            CustomTabsIntent.EXTRA_ACTION_BUTTON_BUNDLE);
    ArrayList<Bundle> bundleList = IntentUtils.getParcelableArrayListExtra(intent,
            CustomTabsIntent.EXTRA_TOOLBAR_ITEMS);
    boolean tinted = IntentUtils.safeGetBooleanExtra(intent,
            CustomTabsIntent.EXTRA_TINT_ACTION_BUTTON, false);
    if (singleBundle != null) {
        CustomButtonParams singleParams = fromBundle(context, singleBundle, tinted, false);
        if (singleParams != null) paramsList.add(singleParams);
    }
    if (bundleList != null) {
        Set<Integer> ids = new HashSet<>();
        for (Bundle bundle : bundleList) {
            CustomButtonParams params = fromBundle(context, bundle, tinted, true);
            if (params == null) {
                continue;
            } else if (ids.contains(params.getId())) {
                Log.e(TAG, "Bottom bar items contain duplicate id: " + params.getId());
                continue;
            }
            ids.add(params.getId());
            paramsList.add(params);
        }
    }
    return paramsList;
}
 
Example 7
Source File: IntentHandler.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the referrer, looking in the Intent extra and in the extra headers extra.
 *
 * The referrer extra takes priority over the "extra headers" one.
 *
 * @param intent The Intent containing the extras.
 * @param context The application context.
 * @return The referrer, or null.
 */
public static String getReferrerUrlIncludingExtraHeaders(Intent intent, Context context) {
    String referrerUrl = getReferrerUrl(intent, context);
    if (referrerUrl != null) return referrerUrl;

    Bundle bundleExtraHeaders = IntentUtils.safeGetBundleExtra(intent, Browser.EXTRA_HEADERS);
    if (bundleExtraHeaders == null) return null;
    for (String key : bundleExtraHeaders.keySet()) {
        String value = bundleExtraHeaders.getString(key);
        if ("referer".equals(key.toLowerCase(Locale.US)) && isValidReferrerHeader(value)) {
            return value;
        }
    }
    return null;
}
 
Example 8
Source File: CustomButtonParams.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a list of {@link CustomButtonParams} from the intent sent by clients.
 * @param intent The intent sent by the client.
 * @return A list of parsed {@link CustomButtonParams}. Return an empty list if input is invalid
 */
static List<CustomButtonParams> fromIntent(Context context, Intent intent) {
    List<CustomButtonParams> paramsList = new ArrayList<>(1);
    if (intent == null) return paramsList;

    Bundle singleBundle = IntentUtils.safeGetBundleExtra(intent,
            CustomTabsIntent.EXTRA_ACTION_BUTTON_BUNDLE);
    ArrayList<Bundle> bundleList = IntentUtils.getParcelableArrayListExtra(intent,
            CustomTabsIntent.EXTRA_TOOLBAR_ITEMS);
    boolean tinted = IntentUtils.safeGetBooleanExtra(intent,
            CustomTabsIntent.EXTRA_TINT_ACTION_BUTTON, false);
    if (singleBundle != null) {
        CustomButtonParams singleParams = fromBundle(context, singleBundle, tinted, false);
        if (singleParams != null) paramsList.add(singleParams);
    }
    if (bundleList != null) {
        Set<Integer> ids = new HashSet<>();
        for (Bundle bundle : bundleList) {
            CustomButtonParams params = fromBundle(context, bundle, tinted, true);
            if (params == null) {
                continue;
            } else if (ids.contains(params.getId())) {
                Log.e(TAG, "Bottom bar items contain duplicate id: " + params.getId());
                continue;
            }
            ids.add(params.getId());
            paramsList.add(params);
        }
    }
    return paramsList;
}
 
Example 9
Source File: IntentHandler.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the referrer, looking in the Intent extra and in the extra headers extra.
 *
 * The referrer extra takes priority over the "extra headers" one.
 *
 * @param intent The Intent containing the extras.
 * @return The referrer, or null.
 */
public static String getReferrerUrlIncludingExtraHeaders(Intent intent) {
    String referrerUrl = getReferrerUrl(intent);
    if (referrerUrl != null) return referrerUrl;

    Bundle bundleExtraHeaders = IntentUtils.safeGetBundleExtra(intent, Browser.EXTRA_HEADERS);
    if (bundleExtraHeaders == null) return null;
    for (String key : bundleExtraHeaders.keySet()) {
        String value = bundleExtraHeaders.getString(key);
        if ("referer".equals(key.toLowerCase(Locale.US)) && isValidReferrerHeader(value)) {
            return value;
        }
    }
    return null;
}