Java Code Examples for org.chromium.chrome.browser.util.IntentUtils#safeGetBooleanExtra()
The following examples show how to use
org.chromium.chrome.browser.util.IntentUtils#safeGetBooleanExtra() .
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: WebApkInfo.java From 365browser with Apache License 2.0 | 6 votes |
/** * Constructs a WebApkInfo from the passed in Intent and <meta-data> in the WebAPK's Android * manifest. * @param intent Intent containing info about the app. */ public static WebApkInfo create(Intent intent) { String webApkPackageName = IntentUtils.safeGetStringExtra(intent, WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME); if (TextUtils.isEmpty(webApkPackageName)) { return null; } String url = urlFromIntent(intent); int source = sourceFromIntent(intent); // Force navigation if the extra is not specified to avoid breaking deep linking for old // WebAPKs which don't specify the {@link WebApkConstants#EXTRA_WEBAPK_FORCE_NAVIGATION} // intent extra. boolean forceNavigation = IntentUtils.safeGetBooleanExtra( intent, WebApkConstants.EXTRA_WEBAPK_FORCE_NAVIGATION, true); return create(webApkPackageName, url, source, forceNavigation); }
Example 2
Source File: ChromeLauncherActivity.java From AndroidChromium with Apache License 2.0 | 6 votes |
/** * @return Whether or not a Custom Tab will be forcefully used for the incoming Intent. */ private boolean isHerbIntent() { if (!canBeHijackedByHerb(getIntent())) return false; // Different Herb flavors handle incoming intents differently. String flavor = FeatureUtilities.getHerbFlavor(); if (TextUtils.isEmpty(flavor) || TextUtils.equals(ChromeSwitches.HERB_FLAVOR_DISABLED, flavor)) { return false; } else if (TextUtils.equals(flavor, ChromeSwitches.HERB_FLAVOR_ELDERBERRY)) { return IntentUtils.safeGetBooleanExtra(getIntent(), ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PARENT, true); } else { // Legacy Herb Flavors might hit this path before the caching logic corrects it, so // treat this as disabled. return false; } }
Example 3
Source File: DataReductionPreferences.java From AndroidChromium with Apache License 2.0 | 6 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.data_reduction_preferences); getActivity().setTitle(R.string.data_reduction_title); boolean isEnabled = DataReductionProxySettings.getInstance().isDataReductionProxyEnabled(); mIsEnabled = !isEnabled; mWasEnabledAtCreation = isEnabled; updatePreferences(isEnabled); setHasOptionsMenu(true); if (getActivity() != null) { mFromPromo = IntentUtils.safeGetBooleanExtra(getActivity().getIntent(), DataReductionPromoSnackbarController.FROM_PROMO, false); } }
Example 4
Source File: WebappInfo.java From 365browser with Apache License 2.0 | 6 votes |
/** * Construct a WebappInfo. * @param intent Intent containing info about the app. */ public static WebappInfo create(Intent intent) { String id = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTRA_ID); String icon = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTRA_ICON); String url = urlFromIntent(intent); String scope = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTRA_SCOPE); int displayMode = IntentUtils.safeGetIntExtra( intent, ShortcutHelper.EXTRA_DISPLAY_MODE, WebDisplayMode.STANDALONE); int orientation = IntentUtils.safeGetIntExtra( intent, ShortcutHelper.EXTRA_ORIENTATION, ScreenOrientationValues.DEFAULT); int source = sourceFromIntent(intent); long themeColor = IntentUtils.safeGetLongExtra(intent, ShortcutHelper.EXTRA_THEME_COLOR, ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING); long backgroundColor = IntentUtils.safeGetLongExtra(intent, ShortcutHelper.EXTRA_BACKGROUND_COLOR, ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING); boolean isIconGenerated = IntentUtils.safeGetBooleanExtra(intent, ShortcutHelper.EXTRA_IS_ICON_GENERATED, false); String name = nameFromIntent(intent); String shortName = shortNameFromIntent(intent); return create(id, url, scope, new Icon(icon), name, shortName, displayMode, orientation, source, themeColor, backgroundColor, isIconGenerated); }
Example 5
Source File: DownloadNotificationService.java From 365browser with Apache License 2.0 | 6 votes |
/** * Handles operations for downloads that the DownloadNotificationService is unaware of. * * This can happen because the DownloadNotificationService learn about downloads later than * Download Home does, and may not yet have a DownloadSharedPreferenceEntry for the item. * * TODO(qinmin): Figure out how to fix the SharedPreferences so that it properly tracks entries. */ private void handleDownloadOperationForMissingNotification(Intent intent) { // This function should only be called via Download Home, but catch this case to be safe. if (!DownloadManagerService.hasDownloadManagerService()) return; String action = intent.getAction(); ContentId id = getContentIdFromIntent(intent); boolean isOffTheRecord = IntentUtils.safeGetBooleanExtra(intent, EXTRA_IS_OFF_THE_RECORD, false); if (!LegacyHelpers.isLegacyDownload(id)) return; // Pass information directly to the DownloadManagerService. if (TextUtils.equals(action, ACTION_DOWNLOAD_CANCEL)) { getServiceDelegate(id).cancelDownload(id, isOffTheRecord); } else if (TextUtils.equals(action, ACTION_DOWNLOAD_PAUSE)) { getServiceDelegate(id).pauseDownload(id, isOffTheRecord); } else if (TextUtils.equals(action, ACTION_DOWNLOAD_RESUME)) { DownloadInfo info = new DownloadInfo.Builder() .setDownloadGuid(id.id) .setIsOffTheRecord(isOffTheRecord) .build(); getServiceDelegate(id).resumeDownload(id, new DownloadItem(false, info), true); } }
Example 6
Source File: ChromeLauncherActivity.java From 365browser with Apache License 2.0 | 6 votes |
/** * @return Whether or not a Custom Tab will be forcefully used for the incoming Intent. */ private boolean isHerbIntent() { if (!canBeHijackedByHerb(getIntent())) return false; // Different Herb flavors handle incoming intents differently. String flavor = FeatureUtilities.getHerbFlavor(); if (TextUtils.isEmpty(flavor) || TextUtils.equals(ChromeSwitches.HERB_FLAVOR_DISABLED, flavor)) { return false; } else if (TextUtils.equals(flavor, ChromeSwitches.HERB_FLAVOR_ELDERBERRY)) { return IntentUtils.safeGetBooleanExtra(getIntent(), ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PARENT, true); } else { // Legacy Herb Flavors might hit this path before the caching logic corrects it, so // treat this as disabled. return false; } }
Example 7
Source File: CustomButtonParams.java From delion with Apache License 2.0 | 5 votes |
/** * 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 8
Source File: IntentHandler.java From AndroidChromium with Apache License 2.0 | 5 votes |
private TabOpenType getTabOpenType(Intent intent) { if (IntentUtils.safeGetBooleanExtra( intent, ShortcutHelper.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, false)) { return TabOpenType.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB; } if (IntentUtils.safeGetBooleanExtra(intent, EXTRA_OPEN_NEW_INCOGNITO_TAB, false)) { return TabOpenType.OPEN_NEW_INCOGNITO_TAB; } if (IntentUtils.safeGetIntExtra(intent, TabOpenType.BRING_TAB_TO_FRONT.name(), Tab.INVALID_TAB_ID) != Tab.INVALID_TAB_ID) { return TabOpenType.BRING_TAB_TO_FRONT; } String appId = IntentUtils.safeGetStringExtra(intent, Browser.EXTRA_APPLICATION_ID); // Due to users complaints, we are NOT reusing tabs for apps that do not specify an appId. if (appId == null || IntentUtils.safeGetBooleanExtra(intent, Browser.EXTRA_CREATE_NEW_TAB, false)) { return TabOpenType.OPEN_NEW_TAB; } // Intents from chrome open in the same tab by default, all others only clobber // tabs created by the same app. return mPackageName.equals(appId) ? TabOpenType.CLOBBER_CURRENT_TAB : TabOpenType.REUSE_APP_ID_MATCHING_TAB_ELSE_NEW_TAB; }
Example 9
Source File: TabRedirectHandler.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Updates |mIntentHistory| and |mLastIntentUpdatedTime|. If |intent| comes from chrome and * currently |mIsOnEffectiveIntentRedirectChain| is true, that means |intent| was sent from * this tab because only the front tab or a new tab can receive an intent from chrome. In that * case, |intent| is added to |mIntentHistory|. * Otherwise, |mIntentHistory| and |mPreviousResolvers| are cleared, and then |intent| is put * into |mIntentHistory|. */ public void updateIntent(Intent intent) { clear(); if (mContext == null || intent == null || !Intent.ACTION_VIEW.equals(intent.getAction())) { return; } mIsCustomTabIntent = ChromeLauncherActivity.isCustomTabIntent(intent); boolean checkIsToChrome = true; // All custom tabs VIEW intents are by design explicit intents, so the presence of package // name doesn't imply they have to be handled by Chrome explicitly. Check if external apps // should be checked for handling the initial redirect chain. if (mIsCustomTabIntent) { boolean sendToExternalApps = IntentUtils.safeGetBooleanExtra(intent, CustomTabIntentDataProvider.EXTRA_SEND_TO_EXTERNAL_DEFAULT_HANDLER, false); checkIsToChrome = !(sendToExternalApps && ChromeFeatureList.isEnabled(ChromeFeatureList.CCT_EXTERNAL_LINK_HANDLING)); } if (checkIsToChrome) mIsInitialIntentHeadingToChrome = isIntentToChrome(mContext, intent); // A copy of the intent with component cleared to find resolvers. mInitialIntent = new Intent(intent).setComponent(null); Intent selector = mInitialIntent.getSelector(); if (selector != null) selector.setComponent(null); }
Example 10
Source File: ChromeTabbedActivity.java From 365browser with Apache License 2.0 | 5 votes |
/** * Launch a URL from an intent. * * @param url The url from the intent. * @param referer Optional referer URL to be used. * @param headers Optional headers to be sent when opening the URL. * @param externalAppId External app id. * @param forceNewTab Whether to force the URL to be launched in a new tab or to fall * back to the default behavior for making that determination. * @param intent The original intent. */ private Tab launchIntent(String url, String referer, String headers, String externalAppId, boolean forceNewTab, Intent intent) { if (mUIInitialized) { mLayoutManager.hideOverview(false); getToolbarManager().finishAnimations(); } if (TextUtils.equals(externalAppId, getPackageName())) { // If the intent was launched by chrome, open the new tab in the appropriate model. // Using FROM_LINK ensures the tab is parented to the current tab, which allows // the back button to close these tabs and restore selection to the previous tab. boolean isIncognito = IntentUtils.safeGetBooleanExtra(intent, IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, false); boolean fromLauncherShortcut = IntentUtils.safeGetBooleanExtra( intent, IntentHandler.EXTRA_INVOKED_FROM_SHORTCUT, false); LoadUrlParams loadUrlParams = new LoadUrlParams(url); loadUrlParams.setIntentReceivedTimestamp(mIntentHandlingTimeMs); loadUrlParams.setVerbatimHeaders(headers); return getTabCreator(isIncognito).createNewTab( loadUrlParams, fromLauncherShortcut ? TabLaunchType.FROM_LAUNCHER_SHORTCUT : TabLaunchType.FROM_LINK, null, intent); } else { return getTabCreator(false).launchUrlFromExternalApp(url, referer, headers, externalAppId, forceNewTab, intent, mIntentHandlingTimeMs); } }
Example 11
Source File: CustomButtonParams.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * 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 12
Source File: TabRedirectHandler.java From 365browser with Apache License 2.0 | 5 votes |
/** * Updates |mIntentHistory| and |mLastIntentUpdatedTime|. If |intent| comes from chrome and * currently |mIsOnEffectiveIntentRedirectChain| is true, that means |intent| was sent from * this tab because only the front tab or a new tab can receive an intent from chrome. In that * case, |intent| is added to |mIntentHistory|. * Otherwise, |mIntentHistory| and |mPreviousResolvers| are cleared, and then |intent| is put * into |mIntentHistory|. */ public void updateIntent(Intent intent) { clear(); if (mContext == null || intent == null || !Intent.ACTION_VIEW.equals(intent.getAction())) { return; } mIsCustomTabIntent = ChromeLauncherActivity.isCustomTabIntent(intent); boolean checkIsToChrome = true; // All custom tabs VIEW intents are by design explicit intents, so the presence of package // name doesn't imply they have to be handled by Chrome explicitly. Check if external apps // should be checked for handling the initial redirect chain. if (mIsCustomTabIntent) { boolean sendToExternalApps = IntentUtils.safeGetBooleanExtra(intent, CustomTabIntentDataProvider.EXTRA_SEND_TO_EXTERNAL_DEFAULT_HANDLER, false); checkIsToChrome = !(sendToExternalApps && ChromeFeatureList.isEnabled(ChromeFeatureList.CCT_EXTERNAL_LINK_HANDLING)); } if (checkIsToChrome) mIsInitialIntentHeadingToChrome = isIntentToChrome(mContext, intent); // A copy of the intent with component cleared to find resolvers. mInitialIntent = new Intent(intent).setComponent(null); Intent selector = mInitialIntent.getSelector(); if (selector != null) selector.setComponent(null); }
Example 13
Source File: ChromeTabbedActivity.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Launch a URL from an intent. * * @param url The url from the intent. * @param referer Optional referer URL to be used. * @param headers Optional headers to be sent when opening the URL. * @param externalAppId External app id. * @param forceNewTab Whether to force the URL to be launched in a new tab or to fall * back to the default behavior for making that determination. * @param intent The original intent. */ private Tab launchIntent(String url, String referer, String headers, String externalAppId, boolean forceNewTab, Intent intent) { if (mUIInitialized) { mLayoutManager.hideOverview(false); getToolbarManager().finishAnimations(); } if (TextUtils.equals(externalAppId, getPackageName())) { // If the intent was launched by chrome, open the new tab in the appropriate model. // Using FROM_LINK ensures the tab is parented to the current tab, which allows // the back button to close these tabs and restore selection to the previous tab. boolean isIncognito = IntentUtils.safeGetBooleanExtra(intent, IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, false); boolean fromLauncherShortcut = IntentUtils.safeGetBooleanExtra( intent, IntentHandler.EXTRA_INVOKED_FROM_SHORTCUT, false); LoadUrlParams loadUrlParams = new LoadUrlParams(url); loadUrlParams.setIntentReceivedTimestamp(mIntentHandlingTimeMs); loadUrlParams.setVerbatimHeaders(headers); return getTabCreator(isIncognito).createNewTab( loadUrlParams, fromLauncherShortcut ? TabLaunchType.FROM_EXTERNAL_APP : TabLaunchType.FROM_LINK, null, intent); } else { return getTabCreator(false).launchUrlFromExternalApp(url, referer, headers, externalAppId, forceNewTab, intent, mIntentHandlingTimeMs); } }
Example 14
Source File: IntentHandler.java From delion with Apache License 2.0 | 5 votes |
private TabOpenType getTabOpenType(Intent intent) { if (IntentUtils.safeGetBooleanExtra( intent, ShortcutHelper.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, false)) { return TabOpenType.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB; } if (IntentUtils.safeGetBooleanExtra(intent, EXTRA_OPEN_NEW_INCOGNITO_TAB, false)) { return TabOpenType.OPEN_NEW_INCOGNITO_TAB; } if (IntentUtils.safeGetIntExtra(intent, TabOpenType.BRING_TAB_TO_FRONT.name(), Tab.INVALID_TAB_ID) != Tab.INVALID_TAB_ID) { return TabOpenType.BRING_TAB_TO_FRONT; } String appId = IntentUtils.safeGetStringExtra(intent, Browser.EXTRA_APPLICATION_ID); // Due to users complaints, we are NOT reusing tabs for apps that do not specify an appId. if (appId == null || IntentUtils.safeGetBooleanExtra(intent, Browser.EXTRA_CREATE_NEW_TAB, false)) { return TabOpenType.OPEN_NEW_TAB; } // Intents from chrome open in the same tab by default, all others only clobber // tabs created by the same app. return mPackageName.equals(appId) ? TabOpenType.CLOBBER_CURRENT_TAB : TabOpenType.REUSE_APP_ID_MATCHING_TAB_ELSE_NEW_TAB; }
Example 15
Source File: DownloadBroadcastReceiver.java From 365browser with Apache License 2.0 | 5 votes |
/** * Called to open a particular download item. Falls back to opening Download Home. * @param context Context of the receiver. * @param intent Intent from the android DownloadManager. */ private void openDownload(final Context context, Intent intent) { int notificationId = IntentUtils.safeGetIntExtra( intent, NotificationConstants.EXTRA_NOTIFICATION_ID, -1); DownloadNotificationService.hideDanglingSummaryNotification(context, notificationId); long ids[] = intent.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS); if (ids == null || ids.length == 0) { DownloadManagerService.openDownloadsPage(context); return; } long id = ids[0]; Uri uri = DownloadManagerDelegate.getContentUriFromDownloadManager(context, id); if (uri == null) { DownloadManagerService.openDownloadsPage(context); return; } String downloadFilename = IntentUtils.safeGetStringExtra( intent, DownloadNotificationService.EXTRA_DOWNLOAD_FILE_PATH); boolean isSupportedMimeType = IntentUtils.safeGetBooleanExtra( intent, DownloadNotificationService.EXTRA_IS_SUPPORTED_MIME_TYPE, false); boolean isOffTheRecord = IntentUtils.safeGetBooleanExtra( intent, DownloadNotificationService.EXTRA_IS_OFF_THE_RECORD, false); ContentId contentId = DownloadNotificationService.getContentIdFromIntent(intent); DownloadManagerService.openDownloadedContent( context, downloadFilename, isSupportedMimeType, isOffTheRecord, contentId.id, id); }
Example 16
Source File: CustomTabIntentDataProvider.java From delion with Apache License 2.0 | 5 votes |
/** * Parses out extras specifically added for Herb. * * @param intent Intent fired to open the CustomTabActivity. * @param context Context for the package. */ private void parseHerbExtras(Intent intent, Context context) { String herbFlavor = FeatureUtilities.getHerbFlavor(); if (TextUtils.isEmpty(herbFlavor) || TextUtils.equals(ChromeSwitches.HERB_FLAVOR_DISABLED, herbFlavor)) { return; } if (!IntentHandler.isIntentChromeOrFirstParty(intent, context)) return; mIsOpenedByChrome = IntentUtils.safeGetBooleanExtra( intent, EXTRA_IS_OPENED_BY_CHROME, false); mShowBookmarkItem = IntentUtils.safeGetBooleanExtra( intent, EXTRA_SHOW_STAR_ICON, false); }
Example 17
Source File: FirstRunFlowSequencer.java From 365browser with Apache License 2.0 | 4 votes |
/** * Tries to launch the First Run Experience. If the Activity was launched with the wrong Intent * flags, we first relaunch it to make sure it runs in its own task, then trigger First Run. * * @param caller Activity instance that is checking if first run is necessary. * @param intent Intent used to launch the caller. * @param requiresBroadcast Whether or not the Intent triggers a BroadcastReceiver. * @return Whether startup must be blocked (e.g. via Activity#finish or dropping the Intent). */ public static boolean launch(Context caller, Intent intent, boolean requiresBroadcast) { // Check if the user just came back from the FRE. boolean firstRunActivityResult = IntentUtils.safeGetBooleanExtra( intent, FirstRunActivity.EXTRA_FIRST_RUN_ACTIVITY_RESULT, false); boolean firstRunComplete = IntentUtils.safeGetBooleanExtra( intent, FirstRunActivity.EXTRA_FIRST_RUN_COMPLETE, false); if (firstRunActivityResult && !firstRunComplete) { Log.d(TAG, "User failed to complete the FRE. Aborting"); return true; } // Tries to launch the Generic First Run Experience for intent from GSA. boolean showLightweightFre = IntentHandler.determineExternalIntentSource(caller.getPackageName(), intent) != ExternalAppId.GSA; // Check if the user needs to go through First Run at all. Intent freIntent = checkIfFirstRunIsNecessary(caller, intent, showLightweightFre); if (freIntent == null) return false; Log.d(TAG, "Redirecting user through FRE."); if ((intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) { if (CommandLine.getInstance().hasSwitch( ChromeSwitches.ENABLE_LIGHTWEIGHT_FIRST_RUN_EXPERIENCE)) { boolean isGenericFreActive = false; List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities(); for (WeakReference<Activity> weakActivity : activities) { Activity activity = weakActivity.get(); if (activity == null) { continue; } else if (activity instanceof LightweightFirstRunActivity) { // A Generic or a new Lightweight First Run Experience will be launched // below, so finish the old Lightweight First Run Experience. activity.setResult(Activity.RESULT_CANCELED); activity.finish(); continue; } else if (activity instanceof FirstRunActivity) { isGenericFreActive = true; continue; } } if (isGenericFreActive) { // Launch the Generic First Run Experience if it was previously active. freIntent = createGenericFirstRunIntent( caller, TextUtils.equals(intent.getAction(), Intent.ACTION_MAIN)); } } // Add a PendingIntent so that the intent used to launch Chrome will be resent when // First Run is completed or canceled. addPendingIntent(caller, freIntent, intent, requiresBroadcast); freIntent.putExtra(FirstRunActivity.EXTRA_FINISH_ON_TOUCH_OUTSIDE, true); if (!(caller instanceof Activity)) freIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); IntentUtils.safeStartActivity(caller, freIntent); } else { // First Run requires that the Intent contains NEW_TASK so that it doesn't sit on top // of something else. Intent newIntent = new Intent(intent); newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); IntentUtils.safeStartActivity(caller, newIntent); } return true; }
Example 18
Source File: IntentHandler.java From AndroidChromium with Apache License 2.0 | 4 votes |
/** * Returns true if the app should ignore a given intent. * * @param context Android Context. * @param intent Intent to check. * @return true if the intent should be ignored. */ public boolean shouldIgnoreIntent(Context context, Intent intent) { // Although not documented to, many/most methods that retrieve values from an Intent may // throw. Because we can't control what packages might send to us, we should catch any // Throwable and then fail closed (safe). This is ugly, but resolves top crashers in the // wild. try { // Ignore all invalid URLs, regardless of what the intent was. if (!intentHasValidUrl(intent)) { return true; } // Determine if this intent came from a trustworthy source (either Chrome or Google // first party applications). boolean isInternal = isIntentChromeOrFirstParty(intent, context); // "Open new incognito tab" is currently limited to Chrome or first parties. if (!isInternal && IntentUtils.safeGetBooleanExtra( intent, EXTRA_OPEN_NEW_INCOGNITO_TAB, false) && (getPendingIncognitoUrl() == null || !getPendingIncognitoUrl().equals(intent.getDataString()))) { return true; } // Now if we have an empty URL and the intent was ACTION_MAIN, // we are pretty sure it is the launcher calling us to show up. // We can safely ignore the screen state. String url = getUrlFromIntent(intent); if (url == null && Intent.ACTION_MAIN.equals(intent.getAction())) { return false; } // Ignore all intents that specify a Chrome internal scheme if they did not come from // a trustworthy source. String scheme = getSanitizedUrlScheme(url); if (!isInternal && scheme != null && (intent.hasCategory(Intent.CATEGORY_BROWSABLE) || intent.hasCategory(Intent.CATEGORY_DEFAULT) || intent.getCategories() == null)) { String lowerCaseScheme = scheme.toLowerCase(Locale.US); if ("chrome".equals(lowerCaseScheme) || "chrome-native".equals(lowerCaseScheme) || "about".equals(lowerCaseScheme)) { // Allow certain "safe" internal URLs to be launched by external // applications. String lowerCaseUrl = url.toLowerCase(Locale.US); if ("about:blank".equals(lowerCaseUrl) || "about://blank".equals(lowerCaseUrl)) { return false; } Log.w(TAG, "Ignoring internal Chrome URL from untrustworthy source."); return true; } } // We must check for screen state at this point. // These might be slow. boolean internalOrVisible = isInternal || isIntentUserVisible(context); return !internalOrVisible; } catch (Throwable t) { return true; } }
Example 19
Source File: SearchActivity.java From 365browser with Apache License 2.0 | 4 votes |
private boolean isVoiceSearchIntent() { return IntentUtils.safeGetBooleanExtra( getIntent(), SearchWidgetProvider.EXTRA_START_VOICE_SEARCH, false); }
Example 20
Source File: DownloadUtils.java From 365browser with Apache License 2.0 | 2 votes |
/** * @return Whether or not the Intent corresponds to a DownloadActivity that should show off the * record downloads. */ public static boolean shouldShowOffTheRecordDownloads(Intent intent) { return IntentUtils.safeGetBooleanExtra(intent, EXTRA_IS_OFF_THE_RECORD, false); }