Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / tracing / importer / zip_importer.html
1 <!DOCTYPE html>
2 <!--
3 Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
6 -->
7
8 <link rel="import" href="/tracing/importer/jszip.html">
9 <link rel="import" href="/tracing/importer/importer.html">
10 <link rel="import" href="/tracing/importer/gzip_importer.html">
11 <link rel="import" href="/tracing/trace_model.html">
12
13 <script>
14 'use strict';
15
16 /**
17  * @fileoverview ZipImporter inflates zip compressed data and passes it along
18  * to an actual importer.
19  */
20 tvcm.exportTo('tracing.importer', function() {
21   var Importer = tracing.importer.Importer;
22
23   function ZipImporter(model, eventData) {
24     if (eventData instanceof ArrayBuffer)
25       eventData = new Uint8Array(eventData);
26     this.model_ = model;
27     this.eventData_ = eventData;
28   }
29
30   /**
31    * @param {eventData} string Possibly zip compressed data.
32    * @return {boolean} Whether eventData looks like zip compressed data.
33    */
34   ZipImporter.canImport = function(eventData) {
35     var header;
36     if (eventData instanceof ArrayBuffer)
37       header = new Uint8Array(eventData.slice(0, 2));
38     else if (typeof(eventData) === 'string' || eventData instanceof String)
39       header = [eventData.charCodeAt(0), eventData.charCodeAt(1)];
40     else
41       return false;
42     return header[0] === 'P'.charCodeAt(0) && header[1] === 'K'.charCodeAt(0);
43   };
44
45   ZipImporter.prototype = {
46     __proto__: Importer.prototype,
47
48     extractSubtraces: function() {
49       var zip = new JSZip(this.eventData_);
50       var subtraces = [];
51       for (var idx in zip.files)
52         subtraces.push(zip.files[idx].asText());
53       return subtraces;
54     }
55   };
56
57   tracing.TraceModel.registerImporter(ZipImporter);
58
59   return {
60     ZipImporter: ZipImporter
61   };
62 });
63 </script>