| <!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="/core/trace_model/trace_model.html"> |
| <script> |
| 'use strict'; |
| tv.exportTo('tv', function() { |
| /** |
| * Creates a trace viewer and, if given, loads the provided URL. |
| * |
| * For more advanced usage, consider using TimelineView and TraceModel |
| * directly. |
| * |
| * Returns an HTMLElement that is the trace-viwer. |
| */ |
| var TraceViewer = tv.b.ui.define('trace-viewer', tv.c.TimelineView); |
| |
| TraceViewer.prototype = { |
| __proto__: tv.c.TimelineView.prototype, |
| |
| decorate: function(opt_url) { |
| tv.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 tv.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 tv.c.TraceModel(); |
| 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 tv.b.ui.Overlay(); |
| overlay.textContent = tv.b.normalizeException(err).message; |
| overlay.title = 'Import error'; |
| overlay.visible = true; |
| } |
| } |
| }; |
| |
| return { |
| TraceViewer: TraceViewer |
| }; |
| }); |
| </script> |