Visualizzazione dei risultati da 1 a 10 su 10
  1. #1

    problemi nell'analizzare il codice sorgente di Firebug

    Salve a tutti, premetto che sono un neofita per quanto riguarda javascript e le tecnologie web in generale e che ho cercato di documentarmi il più possibile, ma essendo abbastanza inesperto ho qualche difficoltà a comprendere il codice che leggo.
    Veniamo al dunque, mi è stato "assegnato" il compito di analizzare il codice sorgente di Firebug
    (estensione di firefox : http://ww.w.getfirebug.com/) e di estenderlo in modo da far esportare in un database le informazioni che vengono generate su schermo in un pannello chiamato NET.

    Ho individuato nel file net.js quello su cui lavorare tuttavia, sono in difficoltà nel capire la sintassi utilizzata in esso e anche i collegamenti con gli altri file dell'applicazione.
    Incollo quotando il codice dell'intero file net.js sperando che qualcuno possa illuminarmi sul significato del codice utilizzato.

    Per esempio non riesco a capire a cosa fa riferimento la prima riga:
    FBL.ns(function() { with (FBL) {

    o meglio credo di aver capito che si riferisca al namespace ma non capisco a quali altri file si collega nè mi è chiaro l'uso della sintassi.
    Ringrazio chiunque possa cominciare ad aiutarmi.



    /* See license.txt for terms of usage */
    FBL.ns(function() { with (FBL) {

    // ************************************************** **********************************************
    // Constants

    const nsIWebProgressListener = CI("nsIWebProgressListener")
    const nsIWebProgress = CI("nsIWebProgress")
    const nsIRequest = CI("nsIRequest")
    const nsIChannel = CI("nsIChannel")
    const nsIHttpChannel = CI("nsIHttpChannel")
    const nsICacheService = CI("nsICacheService")
    const nsICache = CI("nsICache")
    const nsIObserverService = CI("nsIObserverService")
    const nsISupportsWeakReference = CI("nsISupportsWeakReference")
    const nsISupports = CI("nsISupports")
    const nsIIOService = CI("nsIIOService")
    const imgIRequest = CI("imgIRequest");

    const CacheService = CC("@mozilla.org/network/cache-service;1");
    const ImgCache = CC("@mozilla.org/image/cache;1");
    const IOService = CC("@mozilla.org/network/io-service;1");

    const NOTIFY_ALL = nsIWebProgress.NOTIFY_ALL;

    const STATE_IS_WINDOW = nsIWebProgressListener.STATE_IS_WINDOW;
    const STATE_IS_DOCUMENT = nsIWebProgressListener.STATE_IS_DOCUMENT;
    const STATE_IS_NETWORK = nsIWebProgressListener.STATE_IS_NETWORK;
    const STATE_IS_REQUEST = nsIWebProgressListener.STATE_IS_REQUEST;

    const STATE_START = nsIWebProgressListener.STATE_START;
    const STATE_STOP = nsIWebProgressListener.STATE_STOP;
    const STATE_TRANSFERRING = nsIWebProgressListener.STATE_TRANSFERRING;

    const LOAD_BACKGROUND = nsIRequest.LOAD_BACKGROUND;
    const LOAD_FROM_CACHE = nsIRequest.LOAD_FROM_CACHE;
    const LOAD_DOCUMENT_URI = nsIChannel.LOAD_DOCUMENT_URI;

    const ACCESS_READ = nsICache.ACCESS_READ;

    const observerService = CCSV("@mozilla.org/observer-service;1", "nsIObserverService");

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    const maxPendingCheck = 200;

    const mimeExtensionMap =
    {
    "txt": "text/plain",
    "html": "text/html",
    "htm": "text/html",
    "xhtml": "text/html",
    "xml": "text/xml",
    "css": "text/css",
    "js": "application/x-javascript",
    "jss": "application/x-javascript",
    "jpg": "image/jpeg",
    "jpeg": "image/jpeg",
    "gif": "image/gif",
    "png": "image/png",
    "bmp": "image/bmp",
    "swf": "application/x-shockwave-flash"
    };

    const fileCategories =
    {
    "undefined": 1,
    "html": 1,
    "css": 1,
    "js": 1,
    "xhr": 1,
    "image": 1,
    "flash": 1,
    "txt": 1,
    "bin": 1
    };

    const textFileCategories =
    {
    "txt": 1,
    "html": 1,
    "xhr": 1,
    "css": 1,
    "js": 1
    };

    const binaryFileCategories =
    {
    "bin": 1,
    "flash": 1
    };

    const mimeCategoryMap =
    {
    "text/plain": "txt",
    "application/octet-stream": "bin",
    "text/html": "html",
    "text/xml": "html",
    "text/css": "css",
    "application/x-javascript": "js",
    "text/javascript": "js",
    "image/jpeg": "image",
    "image/gif": "image",
    "image/png": "image",
    "image/bmp": "image",
    "application/x-shockwave-flash": "flash"
    };

    const binaryCategoryMap =
    {
    "image": 1,
    "flash" : 1
    };

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    const reIgnore = /about:|javascript:|resource:|chrome:|jar:/;

    const layoutInterval = 300;
    const phaseInterval = 1000;
    const indentWidth = 18;

    // ************************************************** **********************************************

    Firebug.NetMonitor = extend(Firebug.Module,
    {
    clear: function(context)
    {
    var panel = context.getPanel("net", true);
    if (panel)
    panel.clear();

    if (context.netProgress)
    context.netProgress.clear();
    },

    onToggleFilter: function(context, filterCategory)
    {
    Firebug.setPref("netFilterCategory", filterCategory);

    var panel = context.getPanel("net", true);
    if (panel)
    {
    panel.setFilter(filterCategory);
    panel.updateSummaries(now(), true);
    }
    },

    syncFilterButtons: function(chrome)
    {
    var button = chrome.$("fbNetFilter-"+Firebug.netFilterCategory);
    button.checked = true;
    },

    ...continua

  2. #2
    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    // extends Module

    initialize: function()
    {
    this.syncFilterButtons(FirebugChrome);
    },

    initContext: function(context)
    {
    if (!Firebug.disableNetMonitor)
    monitorContext(context);
    },

    reattachContext: function(context)
    {
    var chrome = context ? context.chrome : FirebugChrome;
    this.syncFilterButtons(chrome);
    },

    destroyContext: function(context)
    {
    if (context.netProgress)
    unmonitorContext(context);
    },

    showContext: function(browser, context)
    {
    /*if (context)
    {
    var panel = context.chrome.getSelectedPanel();
    if (panel && panel.name == "net")
    context.netProgress.panel = panel;
    }*/
    },

    loadedContext: function(context)
    {
    if (context.netProgress)
    context.netProgress.loaded = true;
    },

    showPanel: function(browser, panel)
    {
    var netButtons = browser.chrome.$("fbNetButtons");
    collapse(netButtons, !panel || panel.name != "net");

    if (panel && panel.context.netProgress)
    {
    if (panel.name == "net")
    panel.context.netProgress.activate(panel);
    else
    panel.context.netProgress.activate(null);
    }
    }
    });

    // ************************************************** **********************************************

    function NetPanel() {}

    NetPanel.prototype = domplate(Firebug.Panel,
    {
    tableTag:
    TABLE({class: "netTable", cellpadding: 0, cellspacing: 0, onclick: "$onClick"},
    TBODY(
    TR(
    TD({width: "15%"}),
    TD({width: "12%"}),
    TD({width: "4%"}),
    TD({width: "65%"})
    )
    )
    ),

    fileTag:
    FOR("file", "$files",
    TR({class: "netRow $file.file|getCategory",
    $hasHeaders: "$file.file|hasResponseHeaders",
    $loaded: "$file.file.loaded", $responseError: "$file.file|isError",
    $fromCache: "$file.file.fromCache", $inFrame: "$file.file|getInFrame"},
    TD({class: "netHrefCol netCol"},
    DIV({class: "netHrefLabel netLabel",
    style: "margin-left: $file.file|getIndent\\px"},
    "$file.file|getHref"
    ),
    DIV({class: "netFullHrefLabel netHrefLabel netLabel",
    style: "margin-left: $file.file|getIndent\\px"},
    "$file.file.href"
    )
    ),
    TD({class: "netDomainCol netCol"},
    DIV({class: "netDomainLabel netLabel"}, "$file.file|getDomain")
    ),
    TD({class: "netSizeCol netCol"},
    DIV({class: "netSizeLabel netLabel"}, "$file.file|getSize")
    ),
    TD({class: "netTimeCol netCol"},
    DIV({class: "netBar"},
    "",
    DIV({class: "netTotalBar", style: "left: $file.offset"}),
    DIV({class: "netTimeBar", style: "left: $file.offset; width: $file.width"},
    SPAN({class: "netTimeLabel"}, "$file.elapsed|formatTime")
    )
    )
    )
    )
    ),

    headTag:
    TR({class: "netHeadRow"},
    TD({class: "netHeadCol", colspan: 4},
    DIV({class: "netHeadLabel"}, "$doc.rootFile.href")
    )
    ),

    netInfoTag:
    TR({class: "netInfoRow"},
    TD({class: "netInfoCol", colspan: 4})
    ),

    phaseTag:
    TR({class: "netRow netPhaseRow"},
    TD({class: "netPhaseCol", colspan: 4})
    ),

    summaryTag:
    TR({class: "netRow netSummaryRow"},
    TD({class: "netCol"},
    DIV({class: "netCountLabel netSummaryLabel"}, "-")
    ),
    TD({class: "netCol"}),
    TD({class: "netTotalSizeCol netCol"},
    DIV({class: "netTotalSizeLabel netSummaryLabel"}, "0KB")
    ),
    TD({class: "netTotalTimeCol netCol"},
    DIV({class: "netBar"},
    DIV({class: "netCacheSizeLabel netSummaryLabel"},
    "(",
    SPAN("0KB"),
    SPAN(" " + $STR("FromCache")),
    ")"
    ),
    DIV({class: "netTotalBar"}),
    DIV({class: "netTimeBar", style: "width: 100%"},
    SPAN({class: "netTotalTimeLabel netSummaryLabel"}, "0ms")
    )
    )
    )
    ),

    getCategory: function(file)
    {
    return "category-"+getFileCategory(file);
    },

    getInFrame: function(file)
    {
    return !!file.document.parent;
    },

    getIndent: function(file)
    {
    // XXXjoe Turn off indenting for now, it's confusing since we don't
    // actually place nested files directly below their parent
    //return file.document.level * indentWidth;
    return 0;
    },

    isError: function(file)
    {
    var errorRange = Math.floor(file.status/100);
    return errorRange == 4 || errorRange == 5;
    },

    summarizePhase: function(phase, rightNow)
    {
    var cachedSize = 0, totalSize = 0;

    var category = Firebug.netFilterCategory;
    if (category == "all")
    category = null;

    var fileCount = 0;
    var minTime = 0, maxTime = 0;
    for (var file = phase.phaseLastStart; file; file = file.previousFile)
    {
    if (!category || file.category == category)
    {
    ++fileCount;

    if (file.size > 0)
    {
    totalSize += file.size;
    if (file.fromCache)
    cachedSize += file.size;
    }

    if (!minTime || file.startTime < minTime)
    minTime = file.startTime;
    if (file.endTime > maxTime)
    maxTime = file.endTime;
    }

    if (file == phase)
    break;
    }

    var totalTime = maxTime - minTime;
    return {cachedSize: cachedSize, totalSize: totalSize, totalTime: totalTime,
    fileCount: fileCount}
    },

    getHref: function(file)
    {
    if (file.status && file.status != 200 && file.status != 304)
    return getFileName(file.href) + " (" + file.status + ")";
    else
    return getFileName(file.href);
    },

    getDomain: function(file)
    {
    return getPrettyDomain(file.href);
    },

    getSize: function(file)
    {
    return this.formatSize(file.size);
    },

    hasResponseHeaders: function(file)
    {
    return !!file.responseHeaders;
    },

    formatSize: function(bytes)
    {
    if (bytes == -1 || bytes == undefined)
    return "?";
    else if (bytes < 1000)
    return bytes + " b";
    else if (bytes < 1000000)
    return Math.ceil(bytes/1000) + " KB";
    else
    return (Math.ceil(bytes/10000)/100) + " MB";
    },

    formatTime: function(elapsed)
    {
    if (elapsed == -1)
    return "";
    else if (elapsed < 1000)
    return elapsed + "ms";
    else if (elapsed < 60000)
    return (Math.ceil(elapsed/10) / 100) + "s";
    else
    return (Math.ceil((elapsed/60000)*100)/100) + "m";
    },

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    onClick: function(event)
    {
    if (isLeftClick(event))
    {
    var row = getAncestorByClass(event.target, "netRow");
    if (row)
    {
    this.toggleHeadersRow(row);
    cancelEvent(event);
    }
    }
    },

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    clear: function()
    {
    this.panelNode.innerHTML = "";
    this.table = null;
    this.summaryRow = null;

    this.queue = [];
    this.invalidPhases = false;
    },

    setFilter: function(filterCategory)
    {
    this.filterCategory = filterCategory;

    var panelNode = this.panelNode;
    for (var category in fileCategories)
    {
    if (filterCategory != "all" && category != filterCategory)
    setClass(panelNode, "hideCategory-"+category);
    else
    removeClass(panelNode, "hideCategory-"+category);
    }
    },

    toggleHeadersRow: function(row)
    {
    if (!hasClass(row, "hasHeaders"))
    return;

    toggleClass(row, "opened");

    if (hasClass(row, "opened"))
    {
    var template = Firebug.NetMonitor.NetInfoBody;

    var netInfoRow = this.netInfoTag.insertRows({}, row)[0];
    var netInfo = template.tag.replace({file: row.repObject}, netInfoRow.firstChild);
    template.selectTabByName(netInfo, "Headers");

    setClass(netInfo, "category-"+getFileCategory(row.repObject));
    }
    else
    {
    row.parentNode.removeChild(row.nextSibling);
    }
    },

    copyParams: function(file)
    {
    var text = getPostText(file, this.context);

    var lines = text.split("\n");
    var params = parseURLEncodedText(lines[lines.length-1]);

    var args = [];
    for (var i = 0; i < params.length; ++i)
    args.push(escape(params[i].name)+"="+escape(params[i].value));

    var url = file.href;
    url += (url.indexOf("?") == -1 ? "?" : "&") + args.join("&");

    copyToClipboard(url);
    },

    copyHeaders: function(headers)
    {
    var lines = [];
    if (headers)
    {
    for (var i = 0; i < headers.length; ++i)
    {
    var header = headers[i];
    lines.push(header.name + ": " + header.value);
    }
    }

    var text = lines.join("\r\n");
    copyToClipboard(text);
    },

    copyResponse: function(file)
    {
    var text = file.responseText
    ? file.responseText
    : this.context.sourceCache.loadText(file.href);

    copyToClipboard(text);
    },

    stopLoading: function(file)
    {
    const NS_BINDING_ABORTED = 0x804b0002;

    file.request.cancel(NS_BINDING_ABORTED);
    },

    ...continua

  3. #3
    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    // extends Panel

    name: "net",
    searchable: true,
    editable: false,

    initialize: function()
    {
    this.queue = [];

    Firebug.Panel.initialize.apply(this, arguments);
    },

    destroy: function(state)
    {
    if (this.pendingInterval)
    {
    this.context.clearInterval(this.pendingInterval);
    delete this.pendingInterval;
    }

    Firebug.Panel.destroy.apply(this, arguments);
    },

    show: function(state)
    {
    if (!this.filterCategory)
    this.setFilter(Firebug.netFilterCategory);

    this.layout();
    this.layoutInterval = setInterval(bindFixed(this.updateLayout, this), layoutInterval);

    if (this.wasScrolledToBottom)
    scrollToBottom(this.panelNode);
    },

    hide: function()
    {
    this.wasScrolledToBottom = isScrolledToBottom(this.panelNode);

    clearInterval(this.layoutInterval);
    delete this.layoutInterval;
    },

    updateOption: function(name, value)
    {
    if (name == "disableNetMonitor")
    TabWatcher.iterateContexts(value ? monitorContext : unmonitorContext);
    else if (name == "netFilterCategory")
    {
    Firebug.NetMonitor.syncFilterButtons(this.context. chrome);
    for (var i = 0; i < TabWatcher.contexts.length; ++i)
    {
    var context = TabWatcher.contexts[i];
    Firebug.NetMonitor.onToggleFilter(context, value);
    }
    }
    },

    getOptionsMenuItems: function()
    {
    return [
    optionMenu("DisableNetMonitor", "disableNetMonitor")
    ];
    },

    getContextMenuItems: function(nada, target)
    {
    var items = [];

    var file = Firebug.getRepObject(target);
    if (!file)
    return items;

    var object = Firebug.getObjectByURL(this.context, file.href);
    var isPost = isURLEncodedFile(file, getPostText(file, this.context));

    items.push(
    {label: "CopyLocation", command: bindFixed(copyToClipboard, FBL, file.href) }
    );

    if (isPost)
    {
    items.push(
    {label: "CopyLocationParameters", command: bindFixed(this.copyParams, this, file) }
    );
    }

    items.push(
    {label: "CopyRequestHeaders",
    command: bindFixed(this.copyHeaders, this, file.requestHeaders) },
    {label: "CopyResponseHeaders",
    command: bindFixed(this.copyHeaders, this, file.responseHeaders) }
    );

    if (file.category in textFileCategories)
    {
    items.push(
    {label: "CopyResponse", command: bindFixed(this.copyResponse, this, file) }
    );
    }

    items.push(
    "-",
    {label: "OpenInTab", command: bindFixed(openNewTab, FBL, file.href) }
    );

    if (!file.loaded)
    {
    items.push(
    "-",
    {label: "StopLoading", command: bindFixed(this.stopLoading, this, file) }
    );
    }

    if (object)
    {
    var subItems = FirebugChrome.getInspectMenuItems(object);
    if (subItems.length)
    {
    items.push("-");
    items.push.apply(items, subItems);
    }
    }

    return items;
    },

    showInfoTip: function(infoTip, target, x, y)
    {
    var row = getAncestorByClass(target, "netRow");
    if (row)
    {
    if (hasClass(row, "category-image"))
    {
    var url = row.repObject.href;
    if (url == this.infoTipURL)
    return true;

    this.infoTipURL = url;
    return Firebug.InfoTip.populateImageInfoTip(infoTip, url);
    }
    }
    },

    search: function(text)
    {
    if (!text)
    {
    delete this.currentSearch;
    return false;
    }

    var row;
    if (this.currentSearch && text == this.currentSearch.text)
    row = this.currentSearch.findNext(true);
    else
    {
    function findRow(node) { return getAncestorByClass(node, "netRow"); }
    this.currentSearch = new TextSearch(this.panelNode, findRow);
    row = this.currentSearch.find(text);
    }

    if (row)
    {
    var sel = this.document.defaultView.getSelection();
    sel.removeAllRanges();
    sel.addRange(this.currentSearch.range);

    scrollIntoCenterView(row, this.panelNode);
    return true;
    }
    else
    return false;
    },

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    updateFile: function(file)
    {
    if (!file.invalid)
    {
    file.invalid = true;
    this.queue.push(file);
    }
    },

    invalidatePhase: function(phase)
    {
    if (!phase.invalidPhase)
    {
    phase.invalidPhase = true;
    this.invalidPhases = true;
    }
    },

    updateLayout: function()
    {
    if (!this.queue.length)
    return;

    var scrolledToBottom = isScrolledToBottom(this.panelNode);

    this.layout();

    if (scrolledToBottom)
    scrollToBottom(this.panelNode);
    },

    continua...

  4. #4
    nessuno può darmi una dritta?
    grazie

  5. #5
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    Tu sei sicurissimo che il linguaggio postato sia javascript e non java, se cosi fosse spera in una risposta da parte dei mod (di sezione) anche se a me sembra più java (ma è solo un supposizione visto che un linguaggio che non conosco) spero che in entrambi i casi tu possa risolvere.
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  6. #6
    Utente di HTML.it L'avatar di Xinod
    Registrato dal
    Sep 2000
    Messaggi
    13,649
    e' javascript, non ecmascript, ma un' interpretazione esclusiva di mozilla e affini,
    dove si possono permettere licenze poetiche tipo "const",
    che forse verranno inserite in javascript 2

    inutile dire che il codice e' molto complesso e dubito qualcuno, anche con le conoscenze adeguate, abbia tempo e voglia di arrovellarsi nel cercare di seguirlo

    quindi, appurata l' impresa, per avere speranze di risposta poni domande specifiche

  7. #7
    Originariamente inviato da Xinod
    e' javascript, non ecmascript, ma un' interpretazione esclusiva di mozilla e affini,
    dove si possono permettere licenze poetiche tipo "const",
    che forse verranno inserite in javascript 2

    inutile dire che il codice e' molto complesso e dubito qualcuno, anche con le conoscenze adeguate, abbia tempo e voglia di arrovellarsi nel cercare di seguirlo

    quindi, appurata l' impresa, per avere speranze di risposta poni domande specifiche
    Mi associo.

  8. #8
    ok vi ringrazio, quanto alle domande specifiche, comincio da questA:

    1)che cosa significa la prima riga di codice: FBL.ns(function() { with (FBL) {

  9. #9
    ragazzi possibile che non ci sia nessuno in grado di darmi delle indicazioni di massima?

  10. #10
    L'unica cosa che ti posso dire con certezza è che FBL è il namespace della libreria...
    Comunque se devo essere sincero dubito che arriverai alla soluzione, soprattutto se come hai detto tu è vero che sei un neofita.
    L'unica speranza è quella di trovare qualcosa su internet, io purtroppo sono riuscito a trovare solo questo: http://developer.mozilla.org/en/docs/FirebugInternals

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.