/*
   * This function is used by the handleHTTPLoad to setup the cache headers
   * correctly.
   * Returns true if the response was handled from the cache
   */
  private boolean handleCache() {
    switch (mCacheMode) {
        // This mode is normally used for a reload, it instructs the http
        // loader to not use the cached content.
      case WebSettings.LOAD_NO_CACHE:
        break;

        // This mode is used when the content should only be loaded from
        // the cache. If it is not there, then fail the load. This is used
        // to load POST content in a history navigation.
      case WebSettings.LOAD_CACHE_ONLY:
        {
          CacheResult result = CacheManager.getCacheFile(mListener.url(), null);
          if (result != null) {
            startCacheLoad(result);
          } else {
            // This happens if WebCore was first told that the POST
            // response was in the cache, then when we try to use it
            // it has gone.
            // Generate a file not found error
            int err = EventHandler.FILE_NOT_FOUND_ERROR;
            mListener.error(
                err,
                mListener
                    .getContext()
                    .getText(EventHandler.errorStringResources[Math.abs(err)])
                    .toString());
          }
          return true;
        }

        // This mode is for when the user is doing a history navigation
        // in the browser and should returned cached content regardless
        // of it's state. If it is not in the cache, then go to the
        // network.
      case WebSettings.LOAD_CACHE_ELSE_NETWORK:
        {
          if (WebView.LOGV_ENABLED) {
            Log.v(LOGTAG, "FrameLoader: checking cache: " + mListener.url());
          }
          // Get the cache file name for the current URL, passing null for
          // the validation headers causes no validation to occur
          CacheResult result = CacheManager.getCacheFile(mListener.url(), null);
          if (result != null) {
            startCacheLoad(result);
            return true;
          }
          break;
        }

        // This is the default case, which is to check to see if the
        // content in the cache can be used. If it can be used, then
        // use it. If it needs revalidation then the relevant headers
        // are added to the request.
      default:
      case WebSettings.LOAD_NORMAL:
        return mListener.checkCache(mHeaders);
    } // end of switch

    return false;
  }