@Override
 public void endData() {
   Xlog.d(XLOGTAG, "endData::mStatusCode is: " + mStatusCode + this);
   if (mStatusCode == 200) {
     if (mPosterBytes.size() > 0) {
       Bitmap poster =
           BitmapFactory.decodeByteArray(mPosterBytes.toByteArray(), 0, mPosterBytes.size());
       mProxy.doSetPoster(poster);
     }
     cleanup();
   } else if (mStatusCode >= 300 && mStatusCode < 400) {
     // We have a redirect.
     try {
       mUrl = new URL(mHeaders.getLocation());
     } catch (MalformedURLException e) {
       mUrl = null;
     }
     if (mUrl != null) {
       mHandler.post(
           new Runnable() {
             @Override
             public void run() {
               if (mRequestHandle != null) {
                 mRequestHandle.setupRedirect(
                     mUrl.toString(), mStatusCode, new HashMap<String, String>());
               }
             }
           });
     }
   }
 }
  /*
   * 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);
    }
  }