blob: e64f832bed8b9924c78ee1ef222fbf3c65d8c8c0 [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright (c) 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<link rel="stylesheet" href="/base/ui/common.css">
<link rel="import" href="/base/ui.html">
<link rel="import" href="/core/timeline_view.html">
<link rel="import" href="/model/model.html">
<script>
'use strict';
tr.exportTo('tr', function() {
/**
* Creates a trace viewer and, if given, loads the provided URL.
*
* For more advanced usage, consider using TimelineView and Model
* directly.
*
* Returns an HTMLElement that is the trace-viwer.
*/
var TraceViewer = tr.b.ui.define('trace-viewer', tr.c.TimelineView);
TraceViewer.prototype = {
__proto__: tr.c.TimelineView.prototype,
decorate: function(opt_url) {
tr.c.TimelineView.prototype.decorate.call(this);
if (opt_url === undefined)
return;
var url = opt_url;
var that = this;
var req = new XMLHttpRequest();
var is_binary = /[.]gz$/.test(url) || /[.]zip$/.test(url);
req.overrideMimeType('text/plain; charset=x-user-defined');
req.open('GET', url, true);
if (is_binary)
req.responseType = 'arraybuffer';
req.onreadystatechange = function(aEvt) {
if (req.readyState == 4) {
window.setTimeout(function() {
if (req.status == 200) {
onResult(is_binary ? req.response : req.responseText);
} else {
onResultFail(req.status);
}
}, 0);
}
};
req.send(null);
function onResultFail(err) {
var overlay = new tr.b.ui.Overlay();
overlay.textContent = err + ': ' + url + ' could not be loaded';
overlay.title = 'Failed to fetch data';
overlay.visible = true;
}
var model;
function onResult(result) {
model = new tr.Model();
var p = model.importTracesWithProgressDialog([result], true);
p.then(onModelLoaded, onImportFail);
}
function onModelLoaded() {
that.model = model;
that.viewTitle = url;
if (that.timeline)
that.timeline.focusElement = that;
}
function onImportFail() {
var overlay = new tr.b.ui.Overlay();
overlay.textContent = tr.b.normalizeException(err).message;
overlay.title = 'Import error';
overlay.visible = true;
}
}
};
return {
TraceViewer: TraceViewer
};
});
</script>