コード例 #1
0
  /**
   * Tear down the load. Subclasses should clean up any mess because of cancellation or errors
   * during the load.
   */
  void tearDown() {
    if (mCacheResult != null) {
      if (getErrorID() == OK) {
        CacheManager.saveCacheFile(mUrl, mCacheResult);
      }

      // we need to reset mCacheResult to be null
      // resource loader's tearDown will call into WebCore's
      // nativeFinish, which in turn calls loader.cancel().
      // If we don't reset mCacheFile, the file will be deleted.
      mCacheResult = null;
    }
    if (mNativeLoader != 0) {
      PerfChecker checker = new PerfChecker();
      nativeFinished();
      checker.responseAlert("res nativeFinished");
      clearNativeLoader();
    }
  }
コード例 #2
0
  /*
   * Perform the actual redirection. This involves setting up the new URL,
   * informing WebCore and then telling the Network to start loading again.
   */
  private void doRedirect() {
    // as cancel() can cancel the load before doRedirect() is
    // called through handleMessage, needs to check to see if we
    // are canceled before proceed
    if (mCancelled) {
      return;
    }

    String redirectTo = mHeaders.getLocation();
    if (redirectTo != null) {
      int nativeResponse = createNativeResponse();
      redirectTo = nativeRedirectedToUrl(mUrl, redirectTo, nativeResponse);
      // nativeRedirectedToUrl() may call cancel(), e.g. when redirect
      // from a https site to a http site, check mCancelled again
      if (mCancelled) {
        return;
      }
      if (redirectTo == null) {
        Log.d(LOGTAG, "Redirection failed for " + mHeaders.getLocation());
        cancel();
        return;
      } else if (!URLUtil.isNetworkUrl(redirectTo)) {
        final String text =
            mContext.getString(com.android.internal.R.string.open_permission_deny)
                + "\n"
                + redirectTo;
        nativeAddData(text.getBytes(), text.length());
        nativeFinished();
        clearNativeLoader();
        return;
      }

      if (mOriginalUrl == null) {
        mOriginalUrl = mUrl;
      }

      // Cache the redirect response
      if (mCacheResult != null) {
        if (getErrorID() == OK) {
          CacheManager.saveCacheFile(mUrl, mCacheResult);
        }
        mCacheResult = null;
      }

      setUrl(redirectTo);

      // Redirect may be in the cache
      if (mRequestHeaders == null) {
        mRequestHeaders = new HashMap<String, String>();
      }
      if (!checkCache(mRequestHeaders)) {
        // mRequestHandle can be null when the request was satisfied
        // by the cache, and the cache returned a redirect
        if (mRequestHandle != null) {
          mRequestHandle.setupRedirect(redirectTo, mStatusCode, mRequestHeaders);
        } else {
          String method = mMethod;

          if (method == null) {
            return;
          }

          Network network = Network.getInstance(getContext());
          network.requestURL(method, mRequestHeaders, mPostData, this, mIsHighPriority);
        }
      }
    } else {
      cancel();
    }

    if (Config.LOGV) {
      Log.v(LOGTAG, "LoadListener.onRedirect(): redirect to: " + redirectTo);
    }
  }