Changeset 91252 in webkit


Ignore:
Timestamp:
Jul 19, 2011 6:45:04 AM (13 years ago)
Author:
loislo@chromium.org
Message:

Web Inspector: implement import/export for timeline data.
https://bugs.webkit.org/show_bug.cgi?id=64601

Reviewed by Yury Semikhatsky.

Source/WebCore:

Test: inspector/timeline/timeline-load.html

  • English.lproj/localizedStrings.js:
  • inspector/InspectorFrontendHost.cpp:

(WebCore::FrontendMenuProvider::contextMenuItemSelected):

  • inspector/front-end/TimelinePanel.js:

(WebInspector.TimelinePanel):
(WebInspector.TimelinePanel.prototype._createFileSelector):
(WebInspector.TimelinePanel.prototype._contextMenu):
(WebInspector.TimelinePanel.prototype._exportToFile):
(WebInspector.TimelinePanel.prototype._importFromFile):
(WebInspector.TimelinePanel.prototype._addRecordToTimeline):
(WebInspector.TimelinePanel.prototype._clearPanel):
(WebInspector.TimelineModel):
(WebInspector.TimelineModel.prototype._addRecord):
(WebInspector.TimelineModel.prototype._importNextChunk):
(WebInspector.TimelineModel.prototype._importFromFile):
(WebInspector.TimelineModel.prototype._importFromFile.onError):
(WebInspector.TimelineModel.prototype._exportToFile):
(WebInspector.TimelineModel.prototype._reset):

  • inspector/front-end/utilities.js:

():

LayoutTests:

  • inspector/timeline/timeline-load-expected.txt: Added.
  • inspector/timeline/timeline-load.html: Added.
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r91251 r91252  
     12011-07-19  Ilya Tikhonovsky  <loislo@chromium.org>
     2
     3        Web Inspector: implement import/export for timeline data.
     4        https://bugs.webkit.org/show_bug.cgi?id=64601
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        * inspector/timeline/timeline-load-expected.txt: Added.
     9        * inspector/timeline/timeline-load.html: Added.
     10
    1112011-07-19  Gabor Loki  <loki@webkit.org>
    212
  • trunk/Source/WebCore/ChangeLog

    r91250 r91252  
     12011-07-19  Ilya Tikhonovsky  <loislo@chromium.org>
     2
     3        Web Inspector: implement import/export for timeline data.
     4        https://bugs.webkit.org/show_bug.cgi?id=64601
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        Test: inspector/timeline/timeline-load.html
     9
     10        * English.lproj/localizedStrings.js:
     11        * inspector/InspectorFrontendHost.cpp:
     12        (WebCore::FrontendMenuProvider::contextMenuItemSelected):
     13        * inspector/front-end/TimelinePanel.js:
     14        (WebInspector.TimelinePanel):
     15        (WebInspector.TimelinePanel.prototype._createFileSelector):
     16        (WebInspector.TimelinePanel.prototype._contextMenu):
     17        (WebInspector.TimelinePanel.prototype._exportToFile):
     18        (WebInspector.TimelinePanel.prototype._importFromFile):
     19        (WebInspector.TimelinePanel.prototype._addRecordToTimeline):
     20        (WebInspector.TimelinePanel.prototype._clearPanel):
     21        (WebInspector.TimelineModel):
     22        (WebInspector.TimelineModel.prototype._addRecord):
     23        (WebInspector.TimelineModel.prototype._importNextChunk):
     24        (WebInspector.TimelineModel.prototype._importFromFile):
     25        (WebInspector.TimelineModel.prototype._importFromFile.onError):
     26        (WebInspector.TimelineModel.prototype._exportToFile):
     27        (WebInspector.TimelineModel.prototype._reset):
     28        * inspector/front-end/utilities.js:
     29        ():
     30
    1312011-07-19  Vsevolod Vlasov  <vsevik@chromium.org>
    232
  • trunk/Source/WebCore/inspector/InspectorFrontendHost.cpp

    r86551 r91252  
    4848#include "Pasteboard.h"
    4949#include "ScriptFunctionCall.h"
     50#include "UserGestureIndicator.h"
    5051
    5152#include <wtf/RefPtr.h>
     
    9293    {
    9394        if (m_frontendHost) {
     95            UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture);
    9496            int itemNumber = item->action() - ContextMenuItemBaseCustomTag;
    9597
  • trunk/Source/WebCore/inspector/front-end/TimelinePanel.js

    r91061 r91252  
    3434
    3535    this.element.appendChild(this._createTopPane());
     36    this.element.addEventListener("contextmenu", this._contextMenu.bind(this), true);
    3637    this.element.tabIndex = 0;
    3738
     
    100101    this._timeStampRecords = [];
    101102    this._expandOffset = 15;
     103
     104    this._createFileSelector();
     105    this._model = new WebInspector.TimelineModel(this);
    102106
    103107    WebInspector.timelineManager.addEventListener(WebInspector.TimelineManager.EventTypes.TimelineEventRecorded, this._onTimelineEventRecorded, this);
     
    218222    },
    219223
     224    _createFileSelector: function()
     225    {
     226        if (this._fileSelectorElement)
     227            this.element.removeChild(this._fileSelectorElement);
     228
     229        var fileSelectorElement = document.createElement("input");
     230        fileSelectorElement.type = "file";
     231        fileSelectorElement.style.opacity = 0;
     232        fileSelectorElement.onchange = this._importFromFile.bind(this);
     233        this.element.appendChild(fileSelectorElement);
     234        this._fileSelectorElement = fileSelectorElement;
     235    },
     236
     237    _contextMenu: function(event)
     238    {
     239        var contextMenu = new WebInspector.ContextMenu();
     240        contextMenu.appendItem(WebInspector.UIString("&Export Timeline data\u2026"), this._exportToFile.bind(this));
     241        contextMenu.appendItem(WebInspector.UIString("&Import Timeline data\u2026"), this._fileSelectorElement.click.bind(this._fileSelectorElement));
     242        contextMenu.show(event);
     243    },
     244
     245    _exportToFile: function()
     246    {
     247        this._model._exportToFile();
     248    },
     249
     250    _importFromFile: function()
     251    {
     252        if (this.toggleTimelineButton.toggled)
     253            WebInspector.timelineManager.stop();
     254
     255        this._clearPanel();
     256
     257        this._model._importFromFile(this._fileSelectorElement.files[0]);
     258        this._createFileSelector();
     259    },
     260
    220261    _updateRecordsCounter: function()
    221262    {
     
    315356            }
    316357        }
     358        this._model._addRecord(record);
    317359        this._innerAddRecordToTimeline(record, this._rootRecord);
    318360        this._scheduleRefresh();
     
    445487        this._refresh();
    446488        this._closeRecordDetails();
     489        this._model._reset();
    447490    },
    448491
     
    11731216    }
    11741217}
     1218
     1219WebInspector.TimelineModel = function(timelinePanel)
     1220{
     1221    this._panel = timelinePanel;
     1222    this._records = [];
     1223}
     1224
     1225WebInspector.TimelineModel.prototype = {
     1226    _addRecord: function(record)
     1227    {
     1228        this._records.push(record);
     1229    },
     1230
     1231    _importNextChunk: function(data, index)
     1232    {
     1233        for (var i = 0; i < 20 && index < data.length; ++i, ++index)
     1234            this._panel._addRecordToTimeline(data[index]);
     1235
     1236        if (index !== data.length)
     1237            setTimeout(this._importNextChunk.bind(this, data, index), 0);
     1238    },
     1239
     1240    _importFromFile: function(file)
     1241    {
     1242        function onLoad(e)
     1243        {
     1244            var data = JSON.parse(e.target.result);
     1245            var version = data[0];
     1246            this._importNextChunk(data, 1);
     1247        }
     1248
     1249        function onError(e)
     1250        {
     1251            switch(e.target.error.code) {
     1252            case e.target.error.NOT_FOUND_ERR:
     1253                WebInspector.log(WebInspector.UIString('Timeline.importFromFile: File "%s" not found.', file.name));
     1254            break;
     1255            case e.target.error.NOT_READABLE_ERR:
     1256                WebInspector.log(WebInspector.UIString('Timeline.importFromFile: File "%s" is not readable', file.name));
     1257            break;
     1258            case e.target.error.ABORT_ERR:
     1259                break;
     1260            default:
     1261                WebInspector.log(WebInspector.UIString('Timeline.importFromFile: An error occurred while reading the file "%s"', file.name));
     1262            }
     1263        }
     1264
     1265        var reader = new FileReader();
     1266        reader.onload = onLoad.bind(this);
     1267        reader.onerror = onError;
     1268        reader.readAsText(file);
     1269    },
     1270
     1271    _exportToFile: function()
     1272    {
     1273        var records = ['[' + JSON.stringify(window.navigator.appVersion)];
     1274        for (var i = 0; i < this._records.length - 1; ++i)
     1275            records.push(JSON.stringify(this._records[i]));
     1276        records.push(JSON.stringify(this._records[this._records.length - 1]) + "]");
     1277
     1278        var now= new Date();
     1279        InspectorFrontendHost.saveAs("TimelineRawData-" + now.toRFC3339() + ".json", records.join(",\n"));
     1280    },
     1281
     1282    _reset: function()
     1283    {
     1284        this._records = [];
     1285    }
     1286}
  • trunk/Source/WebCore/inspector/front-end/utilities.js

    r90556 r91252  
    689689}
    690690
     691Date.prototype.toRFC3339 = function()
     692{
     693    function leadZero(x)
     694    {
     695        return x > 9 ? x : '0' + x
     696    }
     697    var offset = Math.abs(this.getTimezoneOffset());
     698    var offsetString = Math.floor(offset / 60) + ':' + leadZero(offset % 60);
     699    return this.getFullYear() + '-' +
     700           leadZero(this.getMonth() + 1) + '-' +
     701           leadZero(this.getDate()) + 'T' +
     702           leadZero(this.getHours()) + ':' +
     703           leadZero(this.getMinutes()) + ':' +
     704           leadZero(this.getSeconds()) +
     705           (!offset ? "Z" : (this.getTimezoneOffset() > 0 ? '-' : '+') + offsetString);
     706}
     707
    691708HTMLTextAreaElement.prototype.moveCursorToEnd = function()
    692709{
Note: See TracChangeset for help on using the changeset viewer.