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

The following examples show how to use org.chromium.chrome.browser.IntentHandler#addTrustedIntentExtras() . 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: SearchActivity.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void loadUrl(String url) {
    // Wait until native has loaded.
    if (!mIsActivityUsable) {
        mQueuedUrl = url;
        return;
    }

    // Don't do anything if the input was empty. This is done after the native check to prevent
    // resending a queued query after the user deleted it.
    if (TextUtils.isEmpty(url)) return;

    // Fix up the URL and send it to the full browser.
    String fixedUrl = UrlFormatter.fixupUrl(url);
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(fixedUrl));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
    intent.setClass(this, ChromeLauncherActivity.class);
    IntentHandler.addTrustedIntentExtras(intent);
    IntentUtils.safeStartActivity(this, intent,
            ActivityOptionsCompat
                    .makeCustomAnimation(this, android.R.anim.fade_in, android.R.anim.fade_out)
                    .toBundle());
    RecordUserAction.record("SearchWidget.SearchMade");
    finish();
}
 
Example 2
Source File: TabDelegate.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a tab in the "other" window in multi-window mode. This will only work if
 * {@link MultiWindowUtils#isOpenInOtherWindowSupported} is true for the given activity.
 *
 * @param loadUrlParams Parameters specifying the URL to load and other navigation details.
 * @param activity      The current {@link Activity}
 * @param parentId      The ID of the parent tab, or {@link Tab#INVALID_TAB_ID}.
 */
public void createTabInOtherWindow(LoadUrlParams loadUrlParams, Activity activity,
        int parentId) {
    Intent intent = createNewTabIntent(new AsyncTabCreationParams(loadUrlParams), parentId);

    Class<? extends Activity> targetActivity =
            MultiWindowUtils.getInstance().getOpenInOtherWindowActivity(activity);
    if (targetActivity == null) return;
    MultiWindowUtils.setOpenInOtherWindowIntentExtras(intent, activity, targetActivity);
    IntentHandler.addTrustedIntentExtras(intent, activity);
    activity.startActivity(intent);
}
 
Example 3
Source File: TabDelegate.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a tab in the "other" window in multi-window mode. This will only work if
 * {@link MultiWindowUtils#isOpenInOtherWindowSupported} is true for the given activity.
 *
 * @param loadUrlParams Parameters specifying the URL to load and other navigation details.
 * @param activity      The current {@link Activity}
 * @param parentId      The ID of the parent tab, or {@link Tab#INVALID_TAB_ID}.
 */
public void createTabInOtherWindow(LoadUrlParams loadUrlParams, Activity activity,
        int parentId) {
    Intent intent = createNewTabIntent(
            new AsyncTabCreationParams(loadUrlParams), parentId, false);

    Class<? extends Activity> targetActivity =
            MultiWindowUtils.getInstance().getOpenInOtherWindowActivity(activity);
    if (targetActivity == null) return;

    MultiWindowUtils.setOpenInOtherWindowIntentExtras(intent, activity, targetActivity);
    IntentHandler.addTrustedIntentExtras(intent, activity);
    MultiWindowUtils.onMultiInstanceModeStarted();
    activity.startActivity(intent);
}
 
Example 4
Source File: SearchWidgetProvider.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** Creates a trusted Intent that lets the user begin performing queries. */
private static Intent createStartQueryIntent(Context context, String action, int widgetId) {
    Intent intent = new Intent(action, Uri.parse(String.valueOf(widgetId)));
    intent.setClass(context, SearchWidgetProvider.class);
    IntentHandler.addTrustedIntentExtras(intent);
    return intent;
}
 
Example 5
Source File: TabDelegate.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a tab in the "other" window in multi-window mode. This will only work if
 * {@link MultiWindowUtils#isOpenInOtherWindowSupported} is true for the given activity.
 *
 * @param loadUrlParams Parameters specifying the URL to load and other navigation details.
 * @param activity      The current {@link Activity}
 * @param parentId      The ID of the parent tab, or {@link Tab#INVALID_TAB_ID}.
 */
public void createTabInOtherWindow(LoadUrlParams loadUrlParams, Activity activity,
        int parentId) {
    Intent intent = createNewTabIntent(
            new AsyncTabCreationParams(loadUrlParams), parentId, false);

    Class<? extends Activity> targetActivity =
            MultiWindowUtils.getInstance().getOpenInOtherWindowActivity(activity);
    if (targetActivity == null) return;

    MultiWindowUtils.setOpenInOtherWindowIntentExtras(intent, activity, targetActivity);
    IntentHandler.addTrustedIntentExtras(intent);
    MultiWindowUtils.onMultiInstanceModeStarted();
    activity.startActivity(intent);
}
 
Example 6
Source File: ContentSuggestionsNotificationHelper.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private static void openUrl(Uri uri) {
    Context context = ContextUtils.getApplicationContext();
    Intent intent = new Intent()
                            .setAction(Intent.ACTION_VIEW)
                            .setData(uri)
                            .setClass(context, ChromeLauncherActivity.class)
                            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                            .putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName())
                            .putExtra(ShortcutHelper.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true);
    IntentHandler.addTrustedIntentExtras(intent);
    context.startActivity(intent);
}
 
Example 7
Source File: TabContextMenuItemDelegate.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onOpenInNewChromeTabFromCCT(String linkUrl, boolean isIncognito) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setClass(mTab.getApplicationContext(), ChromeLauncherActivity.class);
    intent.putExtra(ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PARENT, false);
    if (isIncognito) {
        intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true);
        intent.putExtra(
                Browser.EXTRA_APPLICATION_ID, mTab.getApplicationContext().getPackageName());
        IntentHandler.addTrustedIntentExtras(intent);
        IntentHandler.setTabLaunchType(intent, TabLaunchType.FROM_EXTERNAL_APP);
    }
    IntentUtils.safeStartActivity(mTab.getActivity(), intent);
}
 
Example 8
Source File: BrowserActionsContextMenuItemDelegate.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Called when the {@code linkUrl} should be opened in Chrome incognito tab.
 * @param linkUrl The url to open.
 */
public void onOpenInIncognitoTab(String linkUrl) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setPackage(mContext.getPackageName());
    intent.putExtra(ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PARENT, false);
    intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, mContext.getPackageName());
    IntentHandler.addTrustedIntentExtras(intent);
    IntentHandler.setTabLaunchType(intent, TabLaunchType.FROM_EXTERNAL_APP);
    IntentUtils.safeStartActivity(mContext, intent);
}
 
Example 9
Source File: DownloadUtils.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Creates an Intent that allows viewing the given file in an internal media viewer.
 * @param fileUri  URI pointing at the file, ideally in file:// form.
 * @param shareUri URI pointing at the file, ideally in content:// form.
 * @param mimeType MIME type of the file.
 * @return Intent that can be fired to open the file.
 */
public static Intent getMediaViewerIntentForDownloadItem(
        Uri fileUri, Uri shareUri, String mimeType) {
    Context context = ContextUtils.getApplicationContext();
    Intent viewIntent = createViewIntentForDownloadItem(fileUri, mimeType);

    Bitmap closeIcon = BitmapFactory.decodeResource(
            context.getResources(), R.drawable.ic_arrow_back_white_24dp);
    Bitmap shareIcon = BitmapFactory.decodeResource(
            context.getResources(), R.drawable.ic_share_white_24dp);

    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    builder.setToolbarColor(Color.BLACK);
    builder.setCloseButtonIcon(closeIcon);
    builder.setShowTitle(true);

    // Create a PendingIntent that can be used to view the file externally.
    // TODO(dfalcantara): Check if this is problematic in multi-window mode, where two
    //                    different viewers could be visible at the same time.
    Intent chooserIntent = Intent.createChooser(viewIntent, null);
    chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    String openWithStr = context.getString(R.string.download_manager_open_with);
    PendingIntent pendingViewIntent = PendingIntent.getActivity(
            context, 0, chooserIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    builder.addMenuItem(openWithStr, pendingViewIntent);

    // Create a PendingIntent that shares the file with external apps.
    PendingIntent pendingShareIntent = PendingIntent.getActivity(
            context, 0, createShareIntent(shareUri, mimeType), 0);
    builder.setActionButton(
            shareIcon, context.getString(R.string.share), pendingShareIntent, true);

    // The color of the media viewer is dependent on the file type.
    int backgroundRes;
    if (DownloadFilter.fromMimeType(mimeType) == DownloadFilter.FILTER_IMAGE) {
        backgroundRes = R.color.image_viewer_bg;
    } else {
        backgroundRes = R.color.media_viewer_bg;
    }
    int mediaColor = ApiCompatibilityUtils.getColor(context.getResources(), backgroundRes);

    // Build up the Intent further.
    Intent intent = builder.build().intent;
    intent.setPackage(context.getPackageName());
    intent.setData(fileUri);
    intent.putExtra(CustomTabIntentDataProvider.EXTRA_IS_MEDIA_VIEWER, true);
    intent.putExtra(
            CustomTabIntentDataProvider.EXTRA_INITIAL_BACKGROUND_COLOR, mediaColor);
    intent.putExtra(
            CustomTabsIntent.EXTRA_TOOLBAR_COLOR, mediaColor);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
    IntentHandler.addTrustedIntentExtras(intent, context);

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setClass(context, CustomTabActivity.class);
    return intent;
}
 
Example 10
Source File: DownloadUtils.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Creates an Intent that allows viewing the given file in an internal media viewer.
 * @param fileUri    URI pointing at the file, ideally in file:// form.  Used only when
 *                   the media viewer is trying to locate the file on disk.
 * @param contentUri content:// URI pointing at the file.
 * @param mimeType   MIME type of the file.
 * @return Intent that can be fired to open the file.
 */
public static Intent getMediaViewerIntentForDownloadItem(
        Uri fileUri, Uri contentUri, String mimeType) {
    Context context = ContextUtils.getApplicationContext();
    Intent viewIntent = createViewIntentForDownloadItem(contentUri, mimeType);

    Bitmap closeIcon = BitmapFactory.decodeResource(
            context.getResources(), R.drawable.ic_arrow_back_white_24dp);
    Bitmap shareIcon = BitmapFactory.decodeResource(
            context.getResources(), R.drawable.ic_share_white_24dp);

    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    builder.setToolbarColor(Color.BLACK);
    builder.setCloseButtonIcon(closeIcon);
    builder.setShowTitle(true);

    // Create a PendingIntent that can be used to view the file externally.
    // TODO(dfalcantara): Check if this is problematic in multi-window mode, where two
    //                    different viewers could be visible at the same time.
    Intent chooserIntent = Intent.createChooser(viewIntent, null);
    chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    String openWithStr = context.getString(R.string.download_manager_open_with);
    PendingIntent pendingViewIntent = PendingIntent.getActivity(
            context, 0, chooserIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    builder.addMenuItem(openWithStr, pendingViewIntent);

    // Create a PendingIntent that shares the file with external apps.
    PendingIntent pendingShareIntent = PendingIntent.getActivity(
            context, 0, createShareIntent(contentUri, mimeType), 0);
    builder.setActionButton(
            shareIcon, context.getString(R.string.share), pendingShareIntent, true);

    // The color of the media viewer is dependent on the file type.
    int backgroundRes;
    if (DownloadFilter.fromMimeType(mimeType) == DownloadFilter.FILTER_IMAGE) {
        backgroundRes = R.color.image_viewer_bg;
    } else {
        backgroundRes = R.color.media_viewer_bg;
    }
    int mediaColor = ApiCompatibilityUtils.getColor(context.getResources(), backgroundRes);

    // Build up the Intent further.
    Intent intent = builder.build().intent;
    intent.setPackage(context.getPackageName());
    intent.setData(contentUri);
    intent.putExtra(CustomTabIntentDataProvider.EXTRA_IS_MEDIA_VIEWER, true);
    intent.putExtra(CustomTabIntentDataProvider.EXTRA_MEDIA_VIEWER_URL, fileUri.toString());
    intent.putExtra(CustomTabIntentDataProvider.EXTRA_ENABLE_EMBEDDED_MEDIA_EXPERIENCE, true);
    intent.putExtra(
            CustomTabIntentDataProvider.EXTRA_INITIAL_BACKGROUND_COLOR, mediaColor);
    intent.putExtra(
            CustomTabsIntent.EXTRA_TOOLBAR_COLOR, mediaColor);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
    IntentHandler.addTrustedIntentExtras(intent);

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setClass(context, ChromeLauncherActivity.class);
    return intent;
}