Exemplo n.º 1
0
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   if (!GeckoAppShell.getGeckoInterface().hasTabsSideBar()) {
     int heightSpec =
         MeasureSpec.makeMeasureSpec(
             getTabContainerHeight(TabsListContainer.this), MeasureSpec.EXACTLY);
     super.onMeasure(widthMeasureSpec, heightSpec);
   } else {
     super.onMeasure(widthMeasureSpec, heightMeasureSpec);
   }
 }
Exemplo n.º 2
0
  /**
   * If applicable, download and select the distribution specified in the referrer intent.
   *
   * @return true if a referrer-supplied distribution was selected.
   */
  private boolean checkIntentDistribution(final ReferrerDescriptor referrer) {
    if (referrer == null) {
      return false;
    }

    URI uri = getReferredDistribution(referrer);
    if (uri == null) {
      return false;
    }

    long start = SystemClock.uptimeMillis();
    Log.v(LOGTAG, "Downloading referred distribution: " + uri);

    try {
      final HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection();

      // If the Search Activity starts, and we handle the referrer intent, this'll return
      // null. Recover gracefully in this case.
      final GeckoAppShell.GeckoInterface geckoInterface = GeckoAppShell.getGeckoInterface();
      final String ua;
      if (geckoInterface == null) {
        // Fall back to GeckoApp's default implementation.
        ua =
            HardwareUtils.isTablet()
                ? AppConstants.USER_AGENT_FENNEC_TABLET
                : AppConstants.USER_AGENT_FENNEC_MOBILE;
      } else {
        ua = geckoInterface.getDefaultUAString();
      }

      connection.setRequestProperty(HTTP.USER_AGENT, ua);
      connection.setRequestProperty("Accept", EXPECTED_CONTENT_TYPE);

      try {
        final JarInputStream distro;
        try {
          distro = fetchDistribution(uri, connection);
        } catch (Exception e) {
          Log.e(LOGTAG, "Error fetching distribution from network.", e);
          recordFetchTelemetry(e);
          return false;
        }

        long end = SystemClock.uptimeMillis();
        final long duration = end - start;
        Log.d(LOGTAG, "Distro fetch took " + duration + "ms; result? " + (distro != null));
        Telemetry.addToHistogram(
            HISTOGRAM_DOWNLOAD_TIME_MS, clamp(MAX_DOWNLOAD_TIME_MSEC, duration));

        if (distro == null) {
          // Nothing to do.
          return false;
        }

        // Try to copy distribution files from the fetched stream.
        try {
          Log.d(LOGTAG, "Copying files from fetched zip.");
          if (copyFilesFromStream(distro)) {
            // We always copy to the data dir, and we only copy files from
            // a 'distribution' subdirectory. Now determine our actual distribution directory.
            return checkDataDistribution();
          }
        } catch (SecurityException e) {
          Log.e(LOGTAG, "Security exception copying files. Corrupt or malicious?", e);
          Telemetry.addToHistogram(
              HISTOGRAM_CODE_CATEGORY, CODE_CATEGORY_POST_FETCH_SECURITY_EXCEPTION);
        } catch (Exception e) {
          Log.e(LOGTAG, "Error copying files from distribution.", e);
          Telemetry.addToHistogram(HISTOGRAM_CODE_CATEGORY, CODE_CATEGORY_POST_FETCH_EXCEPTION);
        } finally {
          distro.close();
        }
      } finally {
        connection.disconnect();
      }
    } catch (IOException e) {
      Log.e(LOGTAG, "Error copying distribution files from network.", e);
      recordFetchTelemetry(e);
    }

    return false;
  }