B2G/gecko/toolkit/devtools/webconsole/NetworkHelper.jsm
/**
   * Loads the content of aUrl from the cache.
   *
   * @param string aUrl
   *        URL to load the cached content for.
   * @param string aCharset
   *        Assumed charset of the cached content. Used if there is no charset
   *        on the channel directly.
   * @param function aCallback
   *        Callback that is called with the loaded cached content if available
   *        or null if something failed while getting the cached content.
   */
Loads the content of aUrl from the cache.
@param string aUrl
URL to load the cached content for.
@param string aCharset
Assumed charset of the cached content. Used if there is no charset
on the channel directly.
@param function aCallback
Callback that is called with the loaded cached content if available
or null if something failed while getting the cached content.
Loads the content of aUrl from the cache . @param string aUrl URL to load the cached content for . @param string aCharset Assumed charset of the cached content . Used if there is no charset on the channel directly . @param function aCallback Callback that is called with the loaded cached content if available or null if something failed while getting the cached content .
function NH_loadFromCache(aUrl, aCharset, aCallback)
  {
    let channel = NetUtil.newChannel(aUrl);
    channel.loadFlags = Ci.nsIRequest.LOAD_FROM_CACHE |
      Ci.nsICachingChannel.LOAD_ONLY_FROM_CACHE |
      Ci.nsICachingChannel.LOAD_BYPASS_LOCAL_CACHE_IF_BUSY;
    NetUtil.asyncFetch(channel, function (aInputStream, aStatusCode, aRequest) {
      if (!Components.isSuccessCode(aStatusCode)) {
        aCallback(null);
        return;
      }
      let aChannel = aRequest.QueryInterface(Ci.nsIChannel);
      let contentCharset = aChannel.contentCharset || aCharset;
      aCallback(NetworkHelper.readAndConvertFromStream(aInputStream,
                                                       contentCharset));
    });
  }
function NH_loadFromCache ( aUrl , aCharset , aCallback ) { let channel = NetUtil . newChannel ( aUrl ) ; channel . loadFlags = Ci . nsIRequest . LOAD_FROM_CACHE | Ci . nsICachingChannel . LOAD_ONLY_FROM_CACHE | Ci . nsICachingChannel . LOAD_BYPASS_LOCAL_CACHE_IF_BUSY ; NetUtil . asyncFetch ( channel , function ( aInputStream , aStatusCode , aRequest ) { if ( ! Components . isSuccessCode ( aStatusCode ) ) { aCallback ( null ) ; return ; } let aChannel = aRequest . QueryInterface ( Ci . nsIChannel ) ; let contentCharset = aChannel . contentCharset || aCharset ; aCallback ( NetworkHelper . readAndConvertFromStream ( aInputStream , contentCharset ) ) ; } ) ; }
Loads the content of aUrl from the cache.
Loads the content of aUrl from the cache .
// Ensure that we only read from the cache and not the server. // Try to get the encoding from the channel. If there is none, then use // the passed assumed aCharset. // Read the content of the stream using contentCharset as encoding.