@Override
 public Tab openNewTab(
     LoadUrlParams loadUrlParams, TabLaunchType type, Tab parent, boolean incognito) {
   TabDelegate delegate = getTabCreator(incognito);
   delegate.createNewTab(loadUrlParams, type, parent);
   return null;
 }
 @Override
 public void onOpenInOtherWindow(String url, Referrer referrer) {
   TabDelegate tabDelegate = new TabDelegate(mTab.isIncognito());
   LoadUrlParams loadUrlParams = new LoadUrlParams(url);
   loadUrlParams.setReferrer(referrer);
   tabDelegate.createTabInOtherWindow(loadUrlParams, mTab.getActivity(), mTab.getParentId());
 }
Esempio n. 3
0
  /**
   * Displays the download manager UI. Note the UI is different on tablets and on phones.
   *
   * @return Whether the UI was shown.
   */
  public static boolean showDownloadManager(@Nullable Activity activity, @Nullable Tab tab) {
    if (!isDownloadHomeEnabled()) return false;

    // Figure out what tab was last being viewed by the user.
    if (activity == null) activity = ApplicationStatus.getLastTrackedFocusedActivity();
    if (tab == null && activity instanceof ChromeTabbedActivity) {
      tab = ((ChromeTabbedActivity) activity).getActivityTab();
    }

    Context appContext = ContextUtils.getApplicationContext();
    if (DeviceFormFactor.isTablet(appContext)) {
      // Download Home shows up as a tab on tablets.
      LoadUrlParams params = new LoadUrlParams(UrlConstants.DOWNLOADS_URL);
      if (tab == null || !tab.isInitialized()) {
        // Open a new tab, which pops Chrome into the foreground.
        TabDelegate delegate = new TabDelegate(false);
        delegate.createNewTab(params, TabLaunchType.FROM_CHROME_UI, null);
      } else {
        // Download Home shows up inside an existing tab, but only if the last Activity was
        // the ChromeTabbedActivity.
        tab.loadUrl(params);

        // Bring Chrome to the foreground, if possible.
        Intent intent = Tab.createBringTabToFrontIntent(tab.getId());
        if (intent != null) {
          intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          IntentUtils.safeStartActivity(appContext, intent);
        }
      }
    } else {
      // Download Home shows up as a new Activity on phones.
      Intent intent = new Intent();
      intent.setClass(appContext, DownloadActivity.class);
      if (tab != null) intent.putExtra(EXTRA_IS_OFF_THE_RECORD, tab.isIncognito());
      if (activity == null) {
        // Stands alone in its own task.
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        appContext.startActivity(intent);
      } else {
        // Sits on top of another Activity.
        intent.putExtra(IntentHandler.EXTRA_PARENT_COMPONENT, activity.getComponentName());
        activity.startActivity(intent);
      }
    }

    return true;
  }