Changeset 67615 in webkit


Ignore:
Timestamp:
Sep 16, 2010 6:56:43 AM (14 years ago)
Author:
caseq@chromium.org
Message:

2010-09-16 Andrey Kosyakov <caseq@chromium.org>

Reviewed by Pavel Feldman.

Web Inspector: [Resources panel] [HAR] Need a way to save timing data.
Added support to export HAR to file from Resources panel (conditional on Preferences)
Added support for HARLog (a higher-level aggregate than HAREntry)
https://bugs.webkit.org/show_bug.cgi?id=45663

Location:
trunk/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r67614 r67615  
     12010-09-16  Andrey Kosyakov  <caseq@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: [Resources panel] [HAR] Need a way to save timing data.
     6        Added support to export HAR to file from Resources panel (conditional on Preferences)
     7        Added support for HARLog (a higher-level aggregate than HAREntry)
     8        https://bugs.webkit.org/show_bug.cgi?id=45663
     9
     10        * English.lproj/localizedStrings.js:
     11        * inspector/front-end/HAREntry.js:
     12        (WebInspector.HAREntry.prototype.build):
     13        (WebInspector.HAREntry.prototype._buildTimings):
     14        (WebInspector.HAREntry._toMilliseconds):
     15        (WebInspector.HARLog):
     16        (WebInspector.HARLog.prototype.build):
     17        (WebInspector.HARLog.prototype._buildPages):
     18        (WebInspector.HARLog.prototype._buildMainResourceTimings):
     19        (WebInspector.HARLog.prototype._convertResource):
     20        * inspector/front-end/ResourcesPanel.js:
     21        (WebInspector.ResourcesPanel):
     22        (WebInspector.ResourcesPanel.prototype.hide):
     23        (WebInspector.ResourcesPanel.prototype._contextMenu):
     24        (WebInspector.ResourcesPanel.prototype._exportAll):
     25        (WebInspector.ResourcesPanel.prototype._exportResource):
     26        * inspector/front-end/Settings.js:
     27        * inspector/front-end/utilities.js:
     28        ():
     29
    1302010-09-16  Eric Uhrhane  <ericu@chromium.org>
    231
  • trunk/WebCore/inspector/front-end/HAREntry.js

    r67474 r67615  
    4343            pageref: this._resource.documentURL,
    4444            startedDateTime: new Date(this._resource.startTime * 1000),
    45             time: this._toMilliseconds(this._resource.duration),
     45            time: WebInspector.HAREntry._toMilliseconds(this._resource.duration),
    4646            request: this._buildRequest(),
    4747            response: this._buildResponse(),
     
    122122            send: send,
    123123            wait: this._interval("sendEnd", "receiveHeadersEnd"),
    124             receive: this._toMilliseconds(this._resource.receiveDuration),
     124            receive: WebInspector.HAREntry._toMilliseconds(this._resource.receiveDuration),
    125125            ssl: ssl
    126126        };
     
    149149    {
    150150        return parameters.slice();
    151     },
    152 
    153     _toMilliseconds: function(time)
    154     {
    155         return time === -1 ? -1 : Math.round(time * 1000);
    156151    },
    157152
     
    165160    }
    166161};
     162
     163WebInspector.HAREntry._toMilliseconds = function(time)
     164{
     165    return time === -1 ? -1 : Math.round(time * 1000);
     166}
     167
     168WebInspector.HARLog = function()
     169{
     170}
     171
     172WebInspector.HARLog.prototype = {
     173    build: function()
     174    {
     175        var webKitVersion = /AppleWebKit\/([^ ]+)/.exec(window.navigator.userAgent);
     176       
     177        return {
     178            version: "1.2",
     179            creator: {
     180                name: "WebInspector",
     181                version: webKitVersion ? webKitVersion[1] : "n/a"
     182            },
     183            pages: this._buildPages(),
     184            entries: Object.properties(WebInspector.resources).map(this._convertResource)
     185        }
     186    },
     187
     188    _buildPages: function()
     189    {
     190        return [
     191            {
     192                startedDateTime: new Date(WebInspector.mainResource.startTime * 1000),
     193                id: WebInspector.mainResource.documentURL,
     194                title: "",
     195                pageTimings: this._buildMainResourceTimings()
     196            }
     197        ];
     198    },
     199
     200    _buildMainResourceTimings: function()
     201    {
     202        var resourcesPanel = WebInspector.panels.resources;
     203        var startTime = WebInspector.mainResource.startTime;
     204        return {
     205             onContentLoad: WebInspector.HAREntry._toMilliseconds(resourcesPanel.mainResourceDOMContentTime - startTime),
     206             onLoad: WebInspector.HAREntry._toMilliseconds(resourcesPanel.mainResourceLoadTime - startTime),
     207        }
     208    },
     209
     210    _convertResource: function(id)
     211    {
     212        return (new WebInspector.HAREntry(WebInspector.resources[id])).build();
     213    }
     214};
  • trunk/WebCore/inspector/front-end/ResourcesPanel.js

    r66087 r67615  
    4848    this.graphsTreeElement.children[0].select();
    4949    this._resourceTrackingEnabled = false;
     50
     51    this.sidebarElement.addEventListener("contextmenu", this._contextMenu.bind(this), true);
    5052}
    5153
     
    877879        WebInspector.Panel.prototype.hide.call(this);
    878880        this._popoverHelper.hidePopup();
     881    },
     882
     883    _contextMenu: function(event)
     884    {
     885        // createBlobURL is enabled conditionally, do not expose resource export if it's not available.
     886        if (typeof window.createBlobURL !== "function" || !Preferences.resourceExportEnabled)
     887            return;
     888
     889        var contextMenu = new WebInspector.ContextMenu();
     890        var resourceTreeItem = event.target.enclosingNodeOrSelfWithClass("resource-sidebar-tree-item");
     891        if (resourceTreeItem && resourceTreeItem.treeElement) {
     892            var resource = resourceTreeItem.treeElement.representedObject;
     893            contextMenu.appendItem(WebInspector.UIString("Export to HAR"), this._exportResource.bind(this, resource));
     894        }
     895        contextMenu.appendItem(WebInspector.UIString("Export all to HAR"), this._exportAll.bind(this));
     896        contextMenu.show(event);
     897    },
     898
     899    _exportAll: function()
     900    {
     901        var harArchive = {
     902            log: (new WebInspector.HARLog()).build()
     903        }
     904        offerFileForDownload(JSON.stringify(harArchive));
     905    },
     906
     907    _exportResource: function(resource)
     908    {
     909        var har = (new WebInspector.HAREntry(resource)).build();
     910        offerFileForDownload(JSON.stringify(har));
    879911    }
    880912}
  • trunk/WebCore/inspector/front-end/Settings.js

    r67547 r67615  
    4545    auditsPanelEnabled: true,
    4646    onlineDetectionEnabled: true,
    47     domBreakpointsEnabled: false
     47    domBreakpointsEnabled: false,
     48    resourceExportEnabled: false
    4849}
    4950
  • trunk/WebCore/inspector/front-end/utilities.js

    r66477 r67615  
    985985    return new RegExp(regex, "i");
    986986}
     987
     988function offerFileForDownload(contents)
     989{
     990    var builder = new BlobBuilder();
     991    builder.append(contents);
     992    var blob = builder.getBlob("application/octet-stream");
     993    var url = window.createBlobURL(blob);
     994    window.open(url);
     995}
Note: See TracChangeset for help on using the changeset viewer.