org.chromium.chrome.browser.document.ChromeLauncherActivity Java Examples

The following examples show how to use org.chromium.chrome.browser.document.ChromeLauncherActivity. 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: BookmarkUtils.java    From delion with Apache License 2.0 6 votes vote down vote up
private static void openUrl(Activity activity, String url, ComponentName componentName) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.putExtra(Browser.EXTRA_APPLICATION_ID,
            activity.getApplicationContext().getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (componentName != null) {
        intent.setComponent(componentName);
    } else {
        // If the bookmark manager is shown in a tab on a phone (rather than in a separate
        // activity) the component name may be null. Send the intent through
        // ChromeLauncherActivity instead to avoid crashing. See crbug.com/615012.
        intent.setClass(activity, ChromeLauncherActivity.class);
    }

    IntentHandler.startActivityForTrustedIntent(intent, activity);
}
 
Example #2
Source File: BookmarkUtils.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private static void openUrl(Activity activity, String url, ComponentName componentName) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.putExtra(Browser.EXTRA_APPLICATION_ID,
            activity.getApplicationContext().getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(IntentHandler.EXTRA_PAGE_TRANSITION_TYPE, PageTransition.AUTO_BOOKMARK);

    if (componentName != null) {
        intent.setComponent(componentName);
    } else {
        // If the bookmark manager is shown in a tab on a phone (rather than in a separate
        // activity) the component name may be null. Send the intent through
        // ChromeLauncherActivity instead to avoid crashing. See crbug.com/615012.
        intent.setClass(activity, ChromeLauncherActivity.class);
    }

    IntentHandler.startActivityForTrustedIntent(intent);
}
 
Example #3
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 #4
Source File: ExternalNavigationDelegateImpl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public boolean maybeLaunchInstantApp(Tab tab, String url, String referrerUrl,
        boolean isIncomingRedirect) {
    if (tab == null || tab.getWebContents() == null) return false;

    InstantAppsHandler handler = InstantAppsHandler.getInstance();
    Intent intent = tab.getTabRedirectHandler() != null
            ? tab.getTabRedirectHandler().getInitialIntent() : null;
    // TODO(mariakhomenko): consider also handling NDEF_DISCOVER action redirects.
    if (isIncomingRedirect && intent != null && intent.getAction() == Intent.ACTION_VIEW) {
        // Set the URL the redirect was resolved to for checking the existence of the
        // instant app inside handleIncomingIntent().
        Intent resolvedIntent = new Intent(intent);
        resolvedIntent.setData(Uri.parse(url));
        return handler.handleIncomingIntent(getAvailableContext(), resolvedIntent,
                ChromeLauncherActivity.isCustomTabIntent(resolvedIntent));
    } else if (!isIncomingRedirect) {
        // Check if the navigation is coming from SERP and skip instant app handling.
        if (isSerpReferrer(referrerUrl, tab)) return false;
        return handler.handleNavigation(
                getAvailableContext(), url,
                TextUtils.isEmpty(referrerUrl) ? null : Uri.parse(referrerUrl),
                tab.getWebContents());
    }
    return false;
}
 
Example #5
Source File: IncognitoNotificationService.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void removeNonVisibleChromeTabbedRecentEntries() {
    Set<Integer> visibleTaskIds = getTaskIdsForVisibleActivities();

    Context context = ContextUtils.getApplicationContext();
    ActivityManager manager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    PackageManager pm = getPackageManager();

    for (AppTask task : manager.getAppTasks()) {
        RecentTaskInfo info = DocumentUtils.getTaskInfoFromTask(task);
        if (info == null) continue;
        String className = DocumentUtils.getTaskClassName(task, pm);

        // It is not easily possible to distinguish between tasks sitting on top of
        // ChromeLauncherActivity, so we treat them all as likely ChromeTabbedActivities and
        // close them to be on the cautious side of things.
        if ((ChromeTabbedActivity.isTabbedModeClassName(className)
                || TextUtils.equals(className, ChromeLauncherActivity.class.getName()))
                && !visibleTaskIds.contains(info.id)) {
            task.finishAndRemoveTask();
        }
    }
}
 
Example #6
Source File: IncognitoNotificationService.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void removeNonVisibleChromeTabbedRecentEntries() {
    Set<Integer> visibleTaskIds = getTaskIdsForVisibleActivities();

    Context context = ContextUtils.getApplicationContext();
    ActivityManager manager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    PackageManager pm = getPackageManager();

    for (AppTask task : manager.getAppTasks()) {
        RecentTaskInfo info = DocumentUtils.getTaskInfoFromTask(task);
        if (info == null) continue;
        String className = DocumentUtils.getTaskClassName(task, pm);

        // It is not easily possible to distinguish between tasks sitting on top of
        // ChromeLauncherActivity, so we treat them all as likely ChromeTabbedActivities and
        // close them to be on the cautious side of things.
        if ((TextUtils.equals(className, ChromeTabbedActivity.class.getName())
                || TextUtils.equals(className, ChromeLauncherActivity.class.getName()))
                && !visibleTaskIds.contains(info.id)) {
            task.finishAndRemoveTask();
        }
    }
}
 
Example #7
Source File: BookmarkUtils.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private static void openUrl(Activity activity, String url, ComponentName componentName) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.putExtra(Browser.EXTRA_APPLICATION_ID,
            activity.getApplicationContext().getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(IntentHandler.EXTRA_PAGE_TRANSITION_TYPE, PageTransition.AUTO_BOOKMARK);

    if (componentName != null) {
        intent.setComponent(componentName);
    } else {
        // If the bookmark manager is shown in a tab on a phone (rather than in a separate
        // activity) the component name may be null. Send the intent through
        // ChromeLauncherActivity instead to avoid crashing. See crbug.com/615012.
        intent.setClass(activity, ChromeLauncherActivity.class);
    }

    IntentHandler.startActivityForTrustedIntent(intent, activity);
}
 
Example #8
Source File: TabRedirectHandler.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
    }

    String chromePackageName = mContext.getPackageName();
    // If an intent is heading explicitly to Chrome, we should stay in Chrome.
    if (TextUtils.equals(chromePackageName, intent.getPackage())
            || TextUtils.equals(chromePackageName, IntentUtils.safeGetStringExtra(intent,
                    Browser.EXTRA_APPLICATION_ID))) {
        mIsInitialIntentHeadingToChrome = true;
    }
    mIsCustomTabIntent = ChromeLauncherActivity.isCustomTabIntent(intent);

    // Copies minimum information to retrieve resolvers.
    mInitialIntent = new Intent(Intent.ACTION_VIEW);
    mInitialIntent.setData(intent.getData());
    if (intent.getCategories() != null) {
        for (String category : intent.getCategories()) {
            mInitialIntent.addCategory(category);
        }
    }
}
 
Example #9
Source File: ExternalNavigationDelegateImpl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public boolean maybeLaunchInstantApp(Tab tab, String url, String referrerUrl,
        boolean isIncomingRedirect) {
    if (tab == null || tab.getWebContents() == null) return false;

    InstantAppsHandler handler = InstantAppsHandler.getInstance();
    Intent intent = tab.getTabRedirectHandler() != null
            ? tab.getTabRedirectHandler().getInitialIntent() : null;
    // TODO(mariakhomenko): consider also handling NDEF_DISCOVER action redirects.
    if (isIncomingRedirect && intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) {
        // Set the URL the redirect was resolved to for checking the existence of the
        // instant app inside handleIncomingIntent().
        Intent resolvedIntent = new Intent(intent);
        resolvedIntent.setData(Uri.parse(url));
        return handler.handleIncomingIntent(getAvailableContext(), resolvedIntent,
                ChromeLauncherActivity.isCustomTabIntent(resolvedIntent), true);
    } else if (!isIncomingRedirect) {
        // Check if the navigation is coming from SERP and skip instant app handling.
        if (isSerpReferrer(tab)) return false;
        return handler.handleNavigation(getAvailableContext(), url,
                TextUtils.isEmpty(referrerUrl) ? null : Uri.parse(referrerUrl), tab);
    }
    return false;
}
 
Example #10
Source File: IncognitoNotificationService.java    From delion with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void removeNonVisibleChromeTabbedRecentEntries() {
    Set<Integer> visibleTaskIds = getTaskIdsForVisibleActivities();

    Context context = ContextUtils.getApplicationContext();
    ActivityManager manager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    PackageManager pm = getPackageManager();

    for (AppTask task : manager.getAppTasks()) {
        RecentTaskInfo info = DocumentUtils.getTaskInfoFromTask(task);
        if (info == null) continue;
        String className = DocumentUtils.getTaskClassName(task, pm);

        // It is not easily possible to distinguish between tasks sitting on top of
        // ChromeLauncherActivity, so we treat them all as likely ChromeTabbedActivities and
        // close them to be on the cautious side of things.
        if ((TextUtils.equals(className, ChromeTabbedActivity.class.getName())
                || TextUtils.equals(className, ChromeLauncherActivity.class.getName()))
                && !visibleTaskIds.contains(info.id)) {
            task.finishAndRemoveTask();
        }
    }
}
 
Example #11
Source File: TabDelegate.java    From delion with Apache License 2.0 6 votes vote down vote up
private Intent createNewTabIntent(AsyncTabCreationParams asyncParams, int parentId) {
    int assignedTabId = TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID);
    AsyncTabParamsManager.add(assignedTabId, asyncParams);

    Intent intent = new Intent(
            Intent.ACTION_VIEW, Uri.parse(asyncParams.getLoadUrlParams().getUrl()));
    intent.setClass(ContextUtils.getApplicationContext(), ChromeLauncherActivity.class);
    intent.putExtra(IntentHandler.EXTRA_TAB_ID, assignedTabId);
    intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, mIsIncognito);
    intent.putExtra(IntentHandler.EXTRA_PARENT_TAB_ID, parentId);

    Activity parentActivity = ActivityDelegate.getActivityForTabId(parentId);
    if (parentActivity != null && parentActivity.getIntent() != null) {
        intent.putExtra(IntentHandler.EXTRA_PARENT_INTENT, parentActivity.getIntent());
    }

    if (asyncParams.getRequestId() != null) {
        intent.putExtra(ServiceTabLauncher.LAUNCH_REQUEST_ID_EXTRA,
                asyncParams.getRequestId().intValue());
    }

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    return intent;
}
 
Example #12
Source File: WebappLauncherActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void launchInTab(String webappUrl, int webappSource) {
    if (TextUtils.isEmpty(webappUrl)) return;

    Intent launchIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(webappUrl));
    launchIntent.setClassName(getPackageName(), ChromeLauncherActivity.class.getName());
    launchIntent.putExtra(ShortcutHelper.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true);
    launchIntent.putExtra(ShortcutHelper.EXTRA_SOURCE, webappSource);
    launchIntent.setFlags(
            Intent.FLAG_ACTIVITY_NEW_TASK | ApiCompatibilityUtils.getActivityNewDocumentFlag());
    startActivity(launchIntent);
}
 
Example #13
Source File: TabRedirectHandler.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #14
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 #15
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 #16
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 #17
Source File: MultiWindowUtils.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Makes |intent| able to support multi-instance in pre-N Samsung multi-window mode.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void makeLegacyMultiInstanceIntent(ChromeLauncherActivity activity, Intent intent) {
    if (isLegacyMultiWindow(activity)) {
        if (TextUtils.equals(ChromeTabbedActivity.class.getName(),
                intent.getComponent().getClassName())) {
            intent.setClassName(activity, MultiInstanceChromeTabbedActivity.class.getName());
        }
        intent.setFlags(intent.getFlags()
                & ~(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT));
    }
}
 
Example #18
Source File: MultiWindowUtils.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @param activity The {@link Activity} to check.
 * @return Whether or not {@code activity} should run in pre-N Samsung multi-instance mode.
 */
public boolean shouldRunInLegacyMultiInstanceMode(ChromeLauncherActivity activity) {
    return Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP
            && TextUtils.equals(activity.getIntent().getAction(), Intent.ACTION_MAIN)
            && isLegacyMultiWindow(activity)
            && activity.isChromeBrowserActivityRunning();
}
 
Example #19
Source File: LauncherShortcutActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String intentAction = getIntent().getAction();

    // Exit early if the original intent action isn't for opening a new tab.
    if (!intentAction.equals(ACTION_OPEN_NEW_TAB)
            && !intentAction.equals(ACTION_OPEN_NEW_INCOGNITO_TAB)) {
        finish();
        return;
    }

    Intent newIntent = new Intent();
    newIntent.setAction(Intent.ACTION_VIEW);
    newIntent.setData(Uri.parse(UrlConstants.NTP_URL));
    newIntent.setClass(this, ChromeLauncherActivity.class);
    newIntent.putExtra(IntentHandler.EXTRA_INVOKED_FROM_SHORTCUT, true);
    newIntent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
    newIntent.putExtra(Browser.EXTRA_APPLICATION_ID, getPackageName());
    IntentHandler.addTrustedIntentExtras(newIntent);

    if (intentAction.equals(ACTION_OPEN_NEW_INCOGNITO_TAB)) {
        newIntent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true);
    }

    // This system call is often modified by OEMs and not actionable. http://crbug.com/619646.
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
    try {
        startActivity(newIntent);
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }

    finish();
}
 
Example #20
Source File: BookmarkWidgetProxy.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (BookmarkWidgetService.getChangeFolderAction(context)
            .equals(intent.getAction())) {
        BookmarkWidgetService.changeFolder(context, intent);
    } else {
        Intent view = new Intent(intent);
        view.setClass(context, ChromeLauncherActivity.class);
        view.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.BOOKMARK_NAVIGATOR_WIDGET);
        view.putExtra(ShortcutHelper.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true);
        startActivity(context, view);
    }
}
 
Example #21
Source File: ChromeTabbedActivity.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Opens a new Tab with the possibility of showing it in a Custom Tab, instead.
 *
 * See IntentHandler#processUrlViewIntent() for an explanation most of the parameters.
 * @param forceNewTab If not handled by a Custom Tab, forces the new tab to be created.
 */
private void openNewTab(String url, String referer, String headers,
        String externalAppId, Intent intent, boolean forceNewTab) {
    boolean isAllowedToReturnToExternalApp = IntentUtils.safeGetBooleanExtra(intent,
            ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PARENT, true);

    String herbFlavor = FeatureUtilities.getHerbFlavor();
    if (isAllowedToReturnToExternalApp
            && ChromeLauncherActivity.canBeHijackedByHerb(intent)
            && TextUtils.equals(ChromeSwitches.HERB_FLAVOR_DILL, herbFlavor)) {
        Log.d(TAG, "Sending to CustomTabActivity");
        mActivityStopMetrics.setStopReason(
                ActivityStopMetrics.STOP_REASON_CUSTOM_TAB_STARTED);

        Intent newIntent = ChromeLauncherActivity.createCustomTabActivityIntent(
                ChromeTabbedActivity.this, intent, false);
        newIntent.putExtra(Browser.EXTRA_APPLICATION_ID, getPackageName());
        newIntent.putExtra(
                CustomTabIntentDataProvider.EXTRA_IS_OPENED_BY_CHROME, true);
        ChromeLauncherActivity.updateHerbIntent(ChromeTabbedActivity.this,
                newIntent, Uri.parse(IntentHandler.getUrlFromIntent(newIntent)));

        // Launch the Activity on top of this task.
        int updatedFlags = newIntent.getFlags();
        updatedFlags &= ~Intent.FLAG_ACTIVITY_NEW_TASK;
        updatedFlags &= ~Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
        newIntent.setFlags(updatedFlags);
        startActivityForResult(newIntent, CCT_RESULT);
    } else {
        // Create a new tab.
        Tab newTab =
                launchIntent(url, referer, headers, externalAppId, forceNewTab, intent);
        newTab.setIsAllowedToReturnToExternalApp(isAllowedToReturnToExternalApp);
        RecordUserAction.record("MobileReceivedExternalIntent");
    }
}
 
Example #22
Source File: HistoryManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
Intent getOpenUrlIntent(String url, Boolean isIncognito, boolean createNewTab) {
    // Construct basic intent.
    Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    viewIntent.putExtra(Browser.EXTRA_APPLICATION_ID,
            mActivity.getApplicationContext().getPackageName());
    viewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    // Determine component or class name.
    ComponentName component;
    if (DeviceFormFactor.isTablet()) {
        component = mActivity.getComponentName();
    } else {
        component = IntentUtils.safeGetParcelableExtra(
                mActivity.getIntent(), IntentHandler.EXTRA_PARENT_COMPONENT);
    }
    if (component != null) {
        viewIntent.setComponent(component);
    } else {
        viewIntent.setClass(mActivity, ChromeLauncherActivity.class);
    }

    // Set other intent extras.
    if (isIncognito != null) {
        viewIntent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, isIncognito);
    }
    if (createNewTab) viewIntent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);

    return viewIntent;
}
 
Example #23
Source File: TabRedirectHandler.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #24
Source File: MultiWindowUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Makes |intent| able to support multi-instance in pre-N Samsung multi-window mode.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void makeLegacyMultiInstanceIntent(ChromeLauncherActivity activity, Intent intent) {
    if (isLegacyMultiWindow(activity)) {
        if (TextUtils.equals(ChromeTabbedActivity.class.getName(),
                intent.getComponent().getClassName())) {
            intent.setClassName(activity, MultiInstanceChromeTabbedActivity.class.getName());
        }
        intent.setFlags(intent.getFlags()
                & ~(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT));
    }
}
 
Example #25
Source File: MultiWindowUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @param activity The {@link Activity} to check.
 * @return Whether or not {@code activity} should run in pre-N Samsung multi-instance mode.
 */
public boolean shouldRunInLegacyMultiInstanceMode(ChromeLauncherActivity activity) {
    return Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP
            && TextUtils.equals(activity.getIntent().getAction(), Intent.ACTION_MAIN)
            && isLegacyMultiWindow(activity)
            && activity.isChromeBrowserActivityRunning();
}
 
Example #26
Source File: LauncherShortcutActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String intentAction = getIntent().getAction();

    // Exit early if the original intent action isn't for opening a new tab.
    if (!intentAction.equals(ACTION_OPEN_NEW_TAB)
            && !intentAction.equals(ACTION_OPEN_NEW_INCOGNITO_TAB)) {
        finish();
        return;
    }

    Intent newIntent = new Intent();
    newIntent.setAction(Intent.ACTION_VIEW);
    newIntent.setData(Uri.parse(UrlConstants.NTP_URL));
    newIntent.setClass(this, ChromeLauncherActivity.class);
    newIntent.putExtra(IntentHandler.EXTRA_INVOKED_FROM_SHORTCUT, true);
    newIntent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
    newIntent.putExtra(Browser.EXTRA_APPLICATION_ID, getPackageName());
    IntentHandler.addTrustedIntentExtras(newIntent, this);

    if (intentAction.equals(ACTION_OPEN_NEW_INCOGNITO_TAB)) {
        newIntent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true);
    }

    // This system call is often modified by OEMs and not actionable. http://crbug.com/619646.
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    StrictMode.allowThreadDiskWrites();
    try {
        startActivity(newIntent);
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }

    finish();
}
 
Example #27
Source File: BookmarkWidgetProxy.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (BookmarkWidgetService.getChangeFolderAction(context)
            .equals(intent.getAction())) {
        BookmarkWidgetService.changeFolder(context, intent);
    } else {
        Intent view = new Intent(intent);
        view.setClass(context, ChromeLauncherActivity.class);
        view.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.BOOKMARK_NAVIGATOR_WIDGET);
        view.putExtra(ShortcutHelper.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true);
        startActivity(context, view);
    }
}
 
Example #28
Source File: ChromeTabbedActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Opens a new Tab with the possibility of showing it in a Custom Tab, instead.
 *
 * See IntentHandler#processUrlViewIntent() for an explanation most of the parameters.
 * @param forceNewTab If not handled by a Custom Tab, forces the new tab to be created.
 */
private void openNewTab(String url, String referer, String headers,
        String externalAppId, Intent intent, boolean forceNewTab) {
    boolean isAllowedToReturnToExternalApp = IntentUtils.safeGetBooleanExtra(intent,
            ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PARENT, true);

    // Create a new tab.
    Tab newTab =
            launchIntent(url, referer, headers, externalAppId, forceNewTab, intent);
    newTab.setIsAllowedToReturnToExternalApp(isAllowedToReturnToExternalApp);
    logMobileReceivedExternalIntent(externalAppId, intent);
}
 
Example #29
Source File: MultiWindowUtils.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Makes |intent| able to support multi-instance in pre-N Samsung multi-window mode.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void makeLegacyMultiInstanceIntent(ChromeLauncherActivity activity, Intent intent) {
    if (isLegacyMultiWindow(activity)) {
        if (TextUtils.equals(ChromeTabbedActivity.class.getName(),
                intent.getComponent().getClassName())) {
            intent.setClassName(activity, MultiInstanceChromeTabbedActivity.class.getName());
        }
        intent.setFlags(intent.getFlags()
                & ~(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT));
    }
}
 
Example #30
Source File: MultiWindowUtils.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * @param activity The {@link Activity} to check.
 * @return Whether or not {@code activity} should run in pre-N Samsung multi-instance mode.
 */
public boolean shouldRunInLegacyMultiInstanceMode(ChromeLauncherActivity activity) {
    return Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP
            && TextUtils.equals(activity.getIntent().getAction(), Intent.ACTION_MAIN)
            && isLegacyMultiWindow(activity)
            && activity.isChromeBrowserActivityRunning();
}