/**
  * Implementation of error handler for EventHandler. Subclasses should call this method to have
  * error fields set.
  *
  * @param id The error id described by EventHandler.
  * @param description A string description of the error. IMPORTANT: as this is called from network
  *     thread, can't call native directly
  */
 public void error(int id, String description) {
   mErrorID = id;
   mErrorDescription = description;
   sendMessageInternal(obtainMessage(MSG_CONTENT_ERROR));
   if (Config.LOGV) {
     Log.v(
         LOGTAG, "LoadListener.error url:" + url() + " id:" + id + " description:" + description);
   }
   detachRequestHandle();
 }
  /**
   * Event handler's endData call. Send a message to the handler notifying them that the data has
   * finished. IMPORTANT: as this is called from network thread, can't call native directly
   */
  public void endData() {
    if (Config.LOGV) {
      Log.v(LOGTAG, "LoadListener.endData(): url: " + url());
    }

    if (mCancelled) return;

    switch (mStatusCode) {
      case HTTP_MOVED_PERMANENTLY:
        // 301 - permanent redirect
        mPermanent = true;
      case HTTP_FOUND:
      case HTTP_SEE_OTHER:
      case HTTP_TEMPORARY_REDIRECT:
        if (mMethod == null && mRequestHandle == null) {
          Log.e(LOGTAG, "LoadListener.endData(): method is null!");
          Log.e(LOGTAG, "LoadListener.endData(): url = " + url());
        }
        // 301, 302, 303, and 307 - redirect
        if (mStatusCode == HTTP_TEMPORARY_REDIRECT) {
          if (mRequestHandle != null && mRequestHandle.getMethod().equals("POST")) {
            sendMessageInternal(obtainMessage(MSG_LOCATION_CHANGED_REQUEST));
          } else if (mMethod != null && mMethod.equals("POST")) {
            sendMessageInternal(obtainMessage(MSG_LOCATION_CHANGED_REQUEST));
          } else {
            sendMessageInternal(obtainMessage(MSG_LOCATION_CHANGED));
          }
        } else {
          sendMessageInternal(obtainMessage(MSG_LOCATION_CHANGED));
        }
        return;

      case HTTP_AUTH:
      case HTTP_PROXY_AUTH:
        // According to rfc2616, the response for HTTP_AUTH must include
        // WWW-Authenticate header field and the response for
        // HTTP_PROXY_AUTH must include Proxy-Authenticate header field.
        if (mAuthHeader != null
            && (Network.getInstance(mContext).isValidProxySet() || !mAuthHeader.isProxy())) {
          Network.getInstance(mContext).handleAuthRequest(this);
          return;
        }
        break; // use default

      case HTTP_NOT_MODIFIED:
        // Server could send back NOT_MODIFIED even if we didn't
        // ask for it, so make sure we have a valid CacheLoader
        // before calling it.
        if (mCacheLoader != null) {
          detachRequestHandle();
          mCacheLoader.load();
          if (Config.LOGV) {
            Log.v(LOGTAG, "LoadListener cache load url=" + url());
          }
          return;
        }
        break; // use default

      case HTTP_NOT_FOUND:
        // Not an error, the server can send back content.
      default:
        break;
    }

    sendMessageInternal(obtainMessage(MSG_CONTENT_FINISHED));
    detachRequestHandle();
  }