B2G/gecko/browser/devtools/debugger/debugger-controller.js
/**
   * Trims as much as possible from a url, while keeping the result unique
   * in the Debugger View scripts container.
   *
   * @param string | nsIURL aUrl
   *        The script URL.
   * @param string aLabel [optional]
   *        The resulting label at each step.
   * @param number aSeq [optional]
   *        The current iteration step.
   * @return string
   *         The resulting label at the final step.
   */
Trims as much as possible from a url, while keeping the result unique
in the Debugger View scripts container.

@param string | nsIURL aUrl
The script URL.
@param string aLabel [optional]
The resulting label at each step.
@param number aSeq [optional]
The current iteration step.
@return string
The resulting label at the final step.
Trims as much as possible from a url while keeping the result unique in the Debugger View scripts container . @param string | nsIURL aUrl The script URL . @param string aLabel [ optional ] The resulting label at each step . @param number aSeq [ optional ] The current iteration step . @return string The resulting label at the final step .
function SS__trimUrl(aUrl, aLabel, aSeq) {
    if (!(aUrl instanceof Ci.nsIURL)) {
      try {
        aUrl = Services.io.newURI(aUrl, null, null).QueryInterface(Ci.nsIURL);
      } catch (e) {
        return aUrl;
      }
    }
    if (!aSeq) {
      let name = aUrl.fileName;
      if (name) {
        aLabel = aUrl.fileName.replace(/\&.*/, "");
      } else {
        aLabel = "";
      }
      aSeq = 1;
    }
    if (aLabel && aLabel.indexOf("?") !== 0) {
      if (DebuggerView.Scripts.containsIgnoringQuery(aUrl.spec)) {
        return aLabel;
      }
      if (!DebuggerView.Scripts.containsLabel(aLabel)) {
        return aLabel;
      }
    }
    if (aSeq === 1) {
      let query = aUrl.query;
      if (query) {
        return this._trimUrl(aUrl, aLabel + "?" + query, aSeq + 1);
      }
      aSeq++;
    }
    if (aSeq === 2) {
      let ref = aUrl.ref;
      if (ref) {
        return this._trimUrl(aUrl, aLabel + "#" + aUrl.ref, aSeq + 1);
      }
      aSeq++;
    }
    if (aSeq === 3) {
      let dir = aUrl.directory;
      if (dir) {
        return this._trimUrl(aUrl, dir.replace(/^\//, "") + aLabel, aSeq + 1);
      }
      aSeq++;
    }
    if (aSeq === 4) {
      let host = aUrl.hostPort;
      if (host) {
        return this._trimUrl(aUrl, host + "/" + aLabel, aSeq + 1);
      }
      aSeq++;
    }
    if (aSeq === 5) {
      return this._trimUrl(aUrl, aUrl.specIgnoringRef, aSeq + 1);
    }
    return aUrl.spec;
  }
function SS__trimUrl ( aUrl , aLabel , aSeq ) { if ( ! ( aUrl instanceof Ci . nsIURL ) ) { try { aUrl = Services . io . newURI ( aUrl , null , null ) . QueryInterface ( Ci . nsIURL ) ; } catch ( e ) { return aUrl ; } } if ( ! aSeq ) { let name = aUrl . fileName ; if ( name ) { aLabel = aUrl . fileName . replace ( / \&.* / , "" ) ; } else { aLabel = "" ; } aSeq = 1 ; } if ( aLabel && aLabel . indexOf ( "?" ) !== 0 ) { if ( DebuggerView . Scripts . containsIgnoringQuery ( aUrl . spec ) ) { return aLabel ; } if ( ! DebuggerView . Scripts . containsLabel ( aLabel ) ) { return aLabel ; } } if ( aSeq === 1 ) { let query = aUrl . query ; if ( query ) { return this . _trimUrl ( aUrl , aLabel + "?" + query , aSeq + 1 ) ; } aSeq ++ ; } if ( aSeq === 2 ) { let ref = aUrl . ref ; if ( ref ) { return this . _trimUrl ( aUrl , aLabel + "#" + aUrl . ref , aSeq + 1 ) ; } aSeq ++ ; } if ( aSeq === 3 ) { let dir = aUrl . directory ; if ( dir ) { return this . _trimUrl ( aUrl , dir . replace ( / ^\/ / , "" ) + aLabel , aSeq + 1 ) ; } aSeq ++ ; } if ( aSeq === 4 ) { let host = aUrl . hostPort ; if ( host ) { return this . _trimUrl ( aUrl , host + "/" + aLabel , aSeq + 1 ) ; } aSeq ++ ; } if ( aSeq === 5 ) { return this . _trimUrl ( aUrl , aUrl . specIgnoringRef , aSeq + 1 ) ; } return aUrl . spec ; }
Trims as much as possible from a url, while keeping the result unique
 in the Debugger View scripts container.
Trims as much as possible from a url while keeping the result unique in the Debugger View scripts container .
// Use an nsIURL to parse all the url path parts. // This doesn't look like a url, or nsIURL can't handle it. // This is a regular file url, get only the file name (contains the // base name and extension if available). // If this url contains an invalid query, unfortunately nsIURL thinks // it's part of the file extension. It must be removed. // This is not a file url, hence there is no base name, nor extension. // Proceed using other available information. // If we have a label and it doesn't start with a query... // A page may contain multiple requests to the same url but with different // queries. It would be redundant to show each one. // We found the shortest unique label for the url. // Append the url query. // Append the url reference. // Prepend the url directory. // Prepend the hostname and port number. // Use the whole url spec but ignoring the reference. // Give up.