/*
   * This function is called from native WebCore code to
   * notify this LoadListener that the content it is currently
   * downloading should be saved to a file and not sent to
   * WebCore.
   */
  void downloadFile() {
    // Setting the Cache Result to null ensures that this
    // content is not added to the cache
    mCacheResult = null;

    // Inform the client that they should download a file
    mBrowserFrame
        .getCallbackProxy()
        .onDownloadStart(
            url(),
            mBrowserFrame.getUserAgentString(),
            mHeaders.getContentDisposition(),
            mMimeType,
            mContentLength);

    // Cancel the download. We need to stop the http load.
    // The native loader object will get cleared by the call to
    // cancel() but will also be cleared on the WebCore side
    // when this function returns.
    cancel();
  }
  /*
   * This message handler is to facilitate communication between the network
   * thread and the browser thread.
   */
  public void handleMessage(Message msg) {
    switch (msg.what) {
      case MSG_CONTENT_HEADERS:
        /*
         * This message is sent when the LoadListener has headers
         * available. The headers are sent onto WebCore to see what we
         * should do with them.
         */
        if (mNativeLoader != 0) {
          commitHeaders();
        }
        break;

      case MSG_CONTENT_DATA:
        /*
         * This message is sent when the LoadListener has data available
         * in it's data buffer. This data buffer could be filled from a
         * file (this thread) or from http (Network thread).
         */
        if (mNativeLoader != 0) {
          commitLoad();
        }
        break;

      case MSG_CONTENT_FINISHED:
        /*
         * This message is sent when the LoadListener knows that the
         * load is finished. This message is not sent in the case of an
         * error.
         *
         */
        tearDown();
        break;

      case MSG_CONTENT_ERROR:
        /*
         * This message is sent when a load error has occured. The
         * LoadListener will clean itself up.
         */
        notifyError();
        tearDown();
        break;

      case MSG_LOCATION_CHANGED:
        /*
         * This message is sent from LoadListener.endData to inform the
         * browser activity that the location of the top level page
         * changed.
         */
        doRedirect();
        break;

      case MSG_LOCATION_CHANGED_REQUEST:
        /*
         * This message is sent from endData on receipt of a 307
         * Temporary Redirect in response to a POST -- the user must
         * confirm whether to continue loading. If the user says Yes,
         * we simply call MSG_LOCATION_CHANGED. If the user says No,
         * we call MSG_CONTENT_FINISHED.
         */
        Message contMsg = obtainMessage(MSG_LOCATION_CHANGED);
        Message stopMsg = obtainMessage(MSG_CONTENT_FINISHED);
        mBrowserFrame.getCallbackProxy().onFormResubmission(stopMsg, contMsg);
        break;
    }
  }