static void changeFolder(Context context, Intent intent) {
   int widgetId = IntentUtils.safeGetIntExtra(intent, AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
   long folderId =
       IntentUtils.safeGetLongExtra(
           intent, BookmarkColumns._ID, ChromeBrowserProviderClient.INVALID_BOOKMARK_ID);
   if (widgetId >= 0 && folderId >= 0) {
     SharedPreferences prefs = getWidgetState(context, widgetId);
     prefs.edit().putLong(STATE_CURRENT_FOLDER, folderId).commit();
     AppWidgetManager.getInstance(context)
         .notifyAppWidgetViewDataChanged(widgetId, R.id.bookmarks_list);
   }
 }
 @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 BookmarkFactory(this, widgetId);
 }
Exemplo n.º 3
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();
    WebappInfo webappInfo = WebappInfo.create(intent);
    String webappId = webappInfo.id();
    String webappUrl = webappInfo.uri().toString();
    int webappSource = webappInfo.source();

    if (webappId != null && webappUrl != null) {
      String webappMacString = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTRA_MAC);
      byte[] webappMac =
          webappMacString == null ? null : Base64.decode(webappMacString, Base64.DEFAULT);

      Intent launchIntent = null;
      if (webappMac != null && WebappAuthenticator.isUrlValid(this, webappUrl, webappMac)) {
        LaunchMetrics.recordHomeScreenLaunchIntoStandaloneActivity(webappUrl, webappSource);

        String activityName = WebappActivity.class.getName();
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
          // Specifically assign the app to a particular WebappActivity instance.
          int activityIndex = ActivityAssigner.instance(this).assign(webappId);
          activityName += String.valueOf(activityIndex);
        }

        // Create an intent to launch the Webapp in an unmapped WebappActivity.
        launchIntent = new Intent();
        launchIntent.setClassName(this, activityName);
        webappInfo.setWebappIntentExtras(launchIntent);

        // On L+, firing intents with the exact same data should relaunch a particular
        // Activity.
        launchIntent.setAction(Intent.ACTION_VIEW);
        launchIntent.setData(Uri.parse(WebappActivity.WEBAPP_SCHEME + "://" + webappId));
      } else {
        Log.e(TAG, "Shortcut (" + webappUrl + ") opened in Chrome.");

        // The shortcut data doesn't match the current encoding.  Change the intent action
        // launch the URL with a VIEW Intent in the regular browser.
        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);
    }

    ApiCompatibilityUtils.finishAndRemoveTask(this);
  }
Exemplo n.º 4
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;
  }
Exemplo n.º 5
0
 /**
  * @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);
 }
Exemplo n.º 6
0
  /**
   * Creates a new tab and posts to UI.
   *
   * @param loadUrlParams parameters of the url load.
   * @param type Information about how the tab was launched.
   * @param parent the parent tab, if present.
   * @param position the requested position (index in the tab model)
   * @param intent the source of the url if it isn't null.
   * @return The new tab.
   */
  public ChromeTab createNewTab(
      LoadUrlParams loadUrlParams,
      TabModel.TabLaunchType type,
      Tab parent,
      int position,
      Intent intent) {
    try {
      TraceEvent.begin("ChromeTabCreator.createNewTab");
      int parentId = parent != null ? parent.getId() : Tab.INVALID_TAB_ID;
      WebContents webContents = IntentHandler.getWebContentsFromIntent(intent);
      boolean isWebContentsPaused = false;
      if (webContents != null) {
        // The WebContents comes with additional data, but it shouldn't be used if the
        // WebContents itself couldn't be parsed out.
        parentId =
            IntentUtils.safeGetIntExtra(
                intent, IntentHandler.EXTRA_PARENT_TAB_ID, Tab.INVALID_TAB_ID);
        isWebContentsPaused =
            IntentUtils.safeGetBooleanExtra(intent, IntentHandler.EXTRA_WEB_CONTENTS_PAUSED, false);
      }

      // Sanitize the url.
      loadUrlParams.setUrl(UrlUtilities.fixupUrl(loadUrlParams.getUrl()));
      loadUrlParams.setTransitionType(getTransitionType(type));

      boolean openInForeground =
          mOrderController.willOpenInForeground(type, mIncognito) || webContents != null;
      ChromeTab tab;
      if (webContents != null) {
        tab =
            ChromeTab.createLiveTab(
                Tab.INVALID_TAB_ID,
                mActivity,
                mIncognito,
                mNativeWindow,
                type,
                parentId,
                !openInForeground);
        tab.initialize(webContents, mTabContentManager, !openInForeground);
        tab.getTabRedirectHandler().updateIntent(intent);

        if (isWebContentsPaused) webContents.resumeLoadingCreatedWebContents();
      } else if (!openInForeground && SysUtils.isLowEndDevice()) {
        // On low memory devices the tabs opened in background are not loaded automatically
        // to preserve resources (cpu, memory, strong renderer binding) for the foreground
        // tab.
        tab =
            ChromeTab.createTabForLazyLoad(
                mActivity, mIncognito, mNativeWindow, type, parentId, loadUrlParams);
        tab.initialize(null, mTabContentManager, !openInForeground);
        mTabSaver.addTabToSaveQueue(tab);
        tab.getTabRedirectHandler().updateIntent(intent);
      } else {
        tab =
            ChromeTab.createLiveTab(
                Tab.INVALID_TAB_ID,
                mActivity,
                mIncognito,
                mNativeWindow,
                type,
                parentId,
                !openInForeground);

        webContents =
            WarmupManager.getInstance().hasPrerenderedUrl(loadUrlParams.getUrl())
                ? WarmupManager.getInstance().takePrerenderedWebContents()
                : null;
        tab.initialize(webContents, mTabContentManager, !openInForeground);
        tab.getTabRedirectHandler().updateIntent(intent);
        tab.loadUrl(loadUrlParams);
      }

      if (intent != null && intent.hasExtra(ServiceTabLauncher.LAUNCH_REQUEST_ID_EXTRA)) {
        ServiceTabLauncher.onWebContentsForRequestAvailable(
            intent.getIntExtra(ServiceTabLauncher.LAUNCH_REQUEST_ID_EXTRA, 0),
            tab.getWebContents());
      }

      mTabModel.addTab(tab, position, type);

      return tab;
    } finally {
      TraceEvent.end("ChromeTabCreator.createNewTab");
    }
  }
 @Override
 public List<ComponentName> queryIntentActivities(Intent intent) {
   return IntentUtils.getIntentHandlers(mActivity, intent);
 }