org.chromium.chrome.browser.util.IntentUtils Java Examples

The following examples show how to use org.chromium.chrome.browser.util.IntentUtils. 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: WebappInfo.java    From delion with Apache License 2.0 7 votes vote down vote up
public static int displayModeFromIntent(Intent intent) {
    String displayMode =
            IntentUtils.safeGetStringExtra(intent, WebApkConstants.EXTRA_WEBAPK_DISPLAY_MODE);
    if (displayMode == null) {
        return IntentUtils.safeGetIntExtra(
                intent, ShortcutHelper.EXTRA_DISPLAY_MODE, WebDisplayMode.Standalone);
    }

    // {@link displayMode} should be one of
    // https://w3c.github.io/manifest/#dfn-display-modes-values
    if (displayMode.equals("fullscreen")) {
        return WebDisplayMode.Fullscreen;
    } else if (displayMode.equals("minimal-ui")) {
        return WebDisplayMode.MinimalUi;
    } else if (displayMode.equals("browser")) {
        return WebDisplayMode.Browser;
    } else {
        return WebDisplayMode.Standalone;
    }
}
 
Example #2
Source File: PhysicalWebBroadcastService.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
        int state = IntentUtils.safeGetIntExtra(
                intent, BluetoothAdapter.EXTRA_STATE, BLUETOOTH_ADAPTER_DEFAULT_STATE);
        if (state == BluetoothAdapter.STATE_OFF) {
            stopSelf();
        }
    } else if (STOP_SERVICE.equals(action)) {
        stopSelf();
    } else {
        Log.e(TAG, "Unrecognized Broadcast Received");
    }
}
 
Example #3
Source File: ContextualSearchQuickActionControl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Sends the intent associated with the quick action if one is available.
 * @param tab The current tab, used to load a URL if the quick action should open inside
 *            Chrome.
 */
public void sendIntent(Tab tab) {
    if (mOpenQuickActionInChrome) {
        tab.loadUrl(new LoadUrlParams(mQuickActionUri));
        return;
    }

    if (mIntent == null) return;

    // Set the Browser application ID to us in case the user chooses Chrome
    // as the app from the intent picker.
    Context context = getContext();
    mIntent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());

    mIntent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
    mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (context instanceof ChromeTabbedActivity2) {
        // Set the window ID so the new tab opens in the correct window.
        mIntent.putExtra(IntentHandler.EXTRA_WINDOW_ID, 2);
    }

    IntentUtils.safeStartActivity(mContext, mIntent);
}
 
Example #4
Source File: BrowserActionActivity.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Gets custom item list for browser action menu.
 * @param bundles Data for custom items from {@link BrowserActionsIntent}.
 */
private void parseBrowserActionItems(ArrayList<Bundle> bundles) {
    for (int i = 0; i < bundles.size(); i++) {
        Bundle bundle = bundles.get(i);
        String title = IntentUtils.safeGetString(bundle, BrowserActionsIntent.KEY_TITLE);
        PendingIntent action =
                IntentUtils.safeGetParcelable(bundle, BrowserActionsIntent.KEY_ACTION);
        Bitmap icon = IntentUtils.safeGetParcelable(bundle, BrowserActionsIntent.KEY_ICON);
        if (title != null && action != null) {
            BrowserActionItem item = new BrowserActionItem(title, action);
            if (icon != null) {
                item.setIcon(icon);
            }
            mActions.add(item);
        } else if (title != null) {
            Log.e(TAG, "Missing action for item: " + i);
        } else if (action != null) {
            Log.e(TAG, "Missing title for item: " + i);
        } else {
            Log.e(TAG, "Missing title and action for item: " + i);
        }
    }
}
 
Example #5
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 #6
Source File: WebappInfo.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * 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, icon, name, shortName, displayMode, orientation, source,
            themeColor, backgroundColor, isIconGenerated);
}
 
Example #7
Source File: ShareActivity.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the ChromeActivity that called the share intent picker.
 */
private ChromeActivity getTriggeringActivity() {
    int triggeringTaskId =
            IntentUtils.safeGetIntExtra(getIntent(), ShareHelper.EXTRA_TASK_ID, 0);
    List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities();
    ChromeActivity triggeringActivity = null;
    for (int i = 0; i < activities.size(); i++) {
        Activity activity = activities.get(i).get();
        if (activity == null) continue;

        if (activity.getTaskId() == triggeringTaskId && activity instanceof ChromeActivity) {
            return (ChromeActivity) activity;
        }
    }
    return null;
}
 
Example #8
Source File: ActivityDelegate.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Check whether or not the Intent contains an ID for document mode.
 * @param intent Intent to check.
 * @return ID for the document that has the given intent as base intent, or
 *         {@link Tab.INVALID_TAB_ID} if it couldn't be retrieved.
 */
public static int getTabIdFromIntent(Intent intent) {
    if (intent == null || intent.getData() == null) return Tab.INVALID_TAB_ID;

    // Avoid AsyncTabCreationParams related flows early returning here.
    if (AsyncTabParamsManager.hasParamsWithTabToReparent()) {
        return IntentUtils.safeGetIntExtra(
                intent, IntentHandler.EXTRA_TAB_ID, Tab.INVALID_TAB_ID);
    }

    Uri data = intent.getData();
    if (!TextUtils.equals(data.getScheme(), UrlConstants.DOCUMENT_SCHEME)) {
        return Tab.INVALID_TAB_ID;
    }

    try {
        return Integer.parseInt(data.getHost());
    } catch (NumberFormatException e) {
        return Tab.INVALID_TAB_ID;
    }
}
 
Example #9
Source File: DownloadNotificationService.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #10
Source File: WebApkInfo.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * 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, ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME);
    if (TextUtils.isEmpty(webApkPackageName)) {
        return null;
    }

    String url = urlFromIntent(intent);
    int source = sourceFromIntent(intent);

    // Unlike non-WebAPK web apps, WebAPK ids are predictable. A malicious actor may send an
    // intent with a valid start URL and arbitrary other data. Only use the start URL, the
    // package name and the ShortcutSource from the launch intent and extract the remaining data
    // from the <meta-data> in the WebAPK's Android manifest.
    return WebApkMetaDataUtils.extractWebappInfoFromWebApk(webApkPackageName, url, source);
}
 
Example #11
Source File: CustomTabsConnection.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private boolean preconnectUrls(List<Bundle> likelyBundles) {
    boolean atLeastOneUrl = false;
    if (likelyBundles == null) return false;
    WarmupManager warmupManager = WarmupManager.getInstance();
    Profile profile = Profile.getLastUsedProfile();
    for (Bundle bundle : likelyBundles) {
        Uri uri;
        try {
            uri = IntentUtils.safeGetParcelable(bundle, CustomTabsService.KEY_URL);
        } catch (ClassCastException e) {
            continue;
        }
        String url = checkAndConvertUri(uri);
        if (url != null) {
            warmupManager.maybePreconnectUrlAndSubResources(profile, url);
            atLeastOneUrl = true;
        }
    }
    return atLeastOneUrl;
}
 
Example #12
Source File: ChromeLauncherActivity.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * @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 #13
Source File: WebappInfo.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * 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 = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTRA_URL);
    int displayMode = displayModeFromIntent(intent);
    int orientation = orientationFromIntent(intent);
    int source = IntentUtils.safeGetIntExtra(intent,
            ShortcutHelper.EXTRA_SOURCE, ShortcutSource.UNKNOWN);
    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);
    String webApkPackageName = IntentUtils.safeGetStringExtra(intent,
            ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME);

    return create(id, url, icon, name, shortName, displayMode, orientation, source,
            themeColor, backgroundColor, isIconGenerated, webApkPackageName);
}
 
Example #14
Source File: PassphraseTypeDialogFragment.java    From delion with Apache License 2.0 6 votes vote down vote up
private SpannableString getResetText() {
    final Context context = getActivity();
    return SpanApplier.applySpans(
            context.getString(R.string.sync_passphrase_encryption_reset_instructions),
            new SpanInfo("<resetlink>", "</resetlink>", new ClickableSpan() {
                @Override
                public void onClick(View view) {
                    Uri syncDashboardUrl = Uri.parse(
                            context.getText(R.string.sync_dashboard_url).toString());
                    Intent intent = new Intent(Intent.ACTION_VIEW, syncDashboardUrl);
                    intent.setPackage(BuildInfo.getPackageName(context));
                    IntentUtils.safePutBinderExtra(
                            intent, CustomTabsIntent.EXTRA_SESSION, null);
                    context.startActivity(intent);
                }
            }));
}
 
Example #15
Source File: WebappInfo.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #16
Source File: ExternalNavigationDelegateImpl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void startActivity(Intent intent, boolean proxy) {
    try {
        forcePdfViewerAsIntentHandlerIfNeeded(intent);
        if (proxy) {
            dispatchAuthenticatedIntent(intent);
        } else {
            Context context = getAvailableContext();
            if (!(context instanceof Activity)) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
        }
        recordExternalNavigationDispatched(intent);
    } catch (RuntimeException e) {
        IntentUtils.logTransactionTooLargeOrRethrow(e, intent);
    }
}
 
Example #17
Source File: DownloadBroadcastReceiver.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Called to open a given download item that is downloaded by the android DownloadManager.
 * @param context Context of the receiver.
 * @param intent Intent from the android DownloadManager.
 */
private void openDownload(final Context context, Intent intent) {
    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) {
        // Open the downloads page
        DownloadManagerService.openDownloadsPage(context);
    } else {
        String downloadFilename = IntentUtils.safeGetStringExtra(
                intent, DownloadNotificationService.EXTRA_DOWNLOAD_FILE_PATH);
        boolean isSupportedMimeType =  IntentUtils.safeGetBooleanExtra(
                intent, DownloadNotificationService.EXTRA_IS_SUPPORTED_MIME_TYPE, false);
        Intent launchIntent = DownloadManagerService.getLaunchIntentFromDownloadId(
                context, downloadFilename, id, isSupportedMimeType);
        if (!DownloadUtils.fireOpenIntentForDownload(context, launchIntent)) {
            DownloadManagerService.openDownloadsPage(context);
        }
    }
}
 
Example #18
Source File: ActivityDelegate.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Check whether or not the Intent contains an ID for document mode.
 * @param intent Intent to check.
 * @return ID for the document that has the given intent as base intent, or
 *         {@link Tab.INVALID_TAB_ID} if it couldn't be retrieved.
 */
public static int getTabIdFromIntent(Intent intent) {
    if (intent == null || intent.getData() == null) return Tab.INVALID_TAB_ID;

    // Avoid AsyncTabCreationParams related flows early returning here.
    if (AsyncTabParamsManager.hasParamsWithTabToReparent()) {
        return IntentUtils.safeGetIntExtra(
                intent, IntentHandler.EXTRA_TAB_ID, Tab.INVALID_TAB_ID);
    }

    Uri data = intent.getData();
    if (!TextUtils.equals(data.getScheme(), UrlConstants.DOCUMENT_SCHEME)) {
        return Tab.INVALID_TAB_ID;
    }

    try {
        return Integer.parseInt(data.getHost());
    } catch (NumberFormatException e) {
        return Tab.INVALID_TAB_ID;
    }
}
 
Example #19
Source File: BookmarkWidgetProvider.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    // Handle bookmark-specific updates ourselves because they might be
    // coming in without extras, which AppWidgetProvider then blocks.
    final String action = intent.getAction();
    if (getBookmarkAppWidgetUpdateAction(context).equals(action)) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        if (intent.hasExtra(AppWidgetManager.EXTRA_APPWIDGET_ID)) {
            performUpdate(context, appWidgetManager,
                    new int[] {IntentUtils.safeGetIntExtra(intent,
                            AppWidgetManager.EXTRA_APPWIDGET_ID, -1)});
        } else {
            performUpdate(context, appWidgetManager,
                    appWidgetManager.getAppWidgetIds(getComponentName(context)));
        }
    } else {
        super.onReceive(context, intent);
    }
}
 
Example #20
Source File: ContextualSearchQuickActionControl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Sends the intent associated with the quick action if one is available.
 */
public void sendIntent() {
    if (mIntent == null) return;
    mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    // Set the Browser application ID to us in case the user chooses Chrome
    // as the app from the intent picker.
    Context context = getContext();
    mIntent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
    mIntent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
    if (context instanceof ChromeTabbedActivity2) {
        // Set the window ID so the new tab opens in the correct window.
        mIntent.putExtra(IntentHandler.EXTRA_WINDOW_ID, 2);
    }

    IntentUtils.safeStartActivity(mContext, mIntent);
}
 
Example #21
Source File: BookmarkUtils.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Opens a bookmark and reports UMA.
 * @param model Bookmarks model to manage the bookmark.
 * @param activity Activity requesting to open the bookmark.
 * @param bookmarkId ID of the bookmark to be opened.
 * @param launchLocation Location from which the bookmark is being opened.
 * @return Whether the bookmark was successfully opened.
 */
public static boolean openBookmark(BookmarkModel model, Activity activity,
        BookmarkId bookmarkId, int launchLocation) {
    if (model.getBookmarkById(bookmarkId) == null) return false;

    String url = model.getBookmarkById(bookmarkId).getUrl();

    NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_BOOKMARK);
    RecordHistogram.recordEnumeratedHistogram(
            "Stars.LaunchLocation", launchLocation, BookmarkLaunchLocation.COUNT);

    if (DeviceFormFactor.isTablet(activity)) {
        // For tablets, the bookmark manager is open in a tab in the ChromeActivity. Use
        // the ComponentName of the ChromeActivity passed into this method.
        openUrl(activity, url, activity.getComponentName());
    } else {
        // For phones, the bookmark manager is a separate activity. When the activity is
        // launched, an intent extra is set specifying the parent component.
        ComponentName parentComponent = IntentUtils.safeGetParcelableExtra(
                activity.getIntent(), IntentHandler.EXTRA_PARENT_COMPONENT);
        openUrl(activity, url, parentComponent);
    }

    return true;
}
 
Example #22
Source File: CustomTabIntentDataProvider.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the color to initialize the background of the Custom Tab with.
 * If no valid color is set, Color.TRANSPARENT is returned.
 */
private int retrieveInitialBackgroundColor(Intent intent) {
    int defaultColor = Color.TRANSPARENT;
    int color = IntentUtils.safeGetIntExtra(
            intent, EXTRA_INITIAL_BACKGROUND_COLOR, defaultColor);
    return color == Color.TRANSPARENT ? color : removeTransparencyFromColor(color);
}
 
Example #23
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 #24
Source File: TabContextMenuItemDelegate.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onSendEmailMessage(String url) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setData(Uri.parse(url));
    IntentUtils.safeStartActivity(mTab.getActivity(), intent);
}
 
Example #25
Source File: BookmarkWidgetService.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@UiThread
@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
    int widgetId = IntentUtils.safeGetIntExtra(intent, AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
    if (widgetId < 0) {
        Log.w(TAG, "Missing EXTRA_APPWIDGET_ID!");
        return null;
    }
    return new BookmarkAdapter(this, widgetId);
}
 
Example #26
Source File: InstantAppsHandler.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether the intent was fired from Chrome. This happens when the user gets a
 *         disambiguation dialog and chooses to stay in Chrome.
 */
private boolean isIntentFromChrome(Context context, Intent intent) {
    return context.getPackageName().equals(IntentUtils.safeGetStringExtra(
            intent, Browser.EXTRA_APPLICATION_ID))
            // We shouldn't leak internal intents with authentication tokens
            || IntentHandler.wasIntentSenderChrome(intent);
}
 
Example #27
Source File: ChromeTabbedActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #28
Source File: ExternalNavigationHandler.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Determines whether the URL needs to be sent as an intent to the system,
 * and sends it, if appropriate.
 * @return Whether the URL generated an intent, caused a navigation in
 *         current tab, or wasn't handled at all.
 */
public OverrideUrlLoadingResult shouldOverrideUrlLoading(ExternalNavigationParams params) {
    Intent intent;
    // Perform generic parsing of the URI to turn it into an Intent.
    try {
        intent = Intent.parseUri(params.getUrl(), Intent.URI_INTENT_SCHEME);
    } catch (Exception ex) {
        Log.w(TAG, "Bad URI %s", params.getUrl(), ex);
        return OverrideUrlLoadingResult.NO_OVERRIDE;
    }

    boolean hasBrowserFallbackUrl = false;
    String browserFallbackUrl =
            IntentUtils.safeGetStringExtra(intent, EXTRA_BROWSER_FALLBACK_URL);
    if (browserFallbackUrl != null
            && UrlUtilities.isValidForIntentFallbackNavigation(browserFallbackUrl)) {
        hasBrowserFallbackUrl = true;
    } else {
        browserFallbackUrl = null;
    }

    long time = SystemClock.elapsedRealtime();
    OverrideUrlLoadingResult result = shouldOverrideUrlLoadingInternal(
            params, intent, hasBrowserFallbackUrl, browserFallbackUrl);
    RecordHistogram.recordTimesHistogram("Android.StrictMode.OverrideUrlLoadingTime",
            SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS);

    if (result == OverrideUrlLoadingResult.NO_OVERRIDE && hasBrowserFallbackUrl
            && (params.getRedirectHandler() == null
                    // For instance, if this is a chained fallback URL, we ignore it.
                    || !params.getRedirectHandler().shouldNotOverrideUrlLoading())) {
        return clobberCurrentTabWithFallbackUrl(browserFallbackUrl, params);
    }
    return result;
}
 
Example #29
Source File: PrintShareActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
        Intent intent = getIntent();
        if (intent == null) return;
        if (!Intent.ACTION_SEND.equals(intent.getAction())) return;
        if (!IntentUtils.safeHasExtra(getIntent(), ShareHelper.EXTRA_TASK_ID)) return;
        handlePrintAction();
    } finally {
        finish();
    }
}
 
Example #30
Source File: IntentHandler.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void recordExternalIntentSourceUMA(Intent intent) {
    ExternalAppId externalId = determineExternalIntentSource(mPackageName, intent);
    RecordHistogram.recordEnumeratedHistogram("MobileIntent.PageLoadDueToExternalApp",
            externalId.ordinal(), ExternalAppId.INDEX_BOUNDARY.ordinal());
    if (externalId == ExternalAppId.OTHER) {
        String appId = IntentUtils.safeGetStringExtra(intent, Browser.EXTRA_APPLICATION_ID);
        if (!TextUtils.isEmpty(appId)) {
            RapporServiceBridge.sampleString("Android.PageLoadDueToExternalApp", appId);
        }
    }
}