1<!DOCTYPE html> 2<!-- 3Copyright (c) 2015 The Chromium Authors. All rights reserved. 4Use of this source code is governed by a BSD-style license that can be 5found in the LICENSE file. 6--> 7 8<link rel="import" href="/tracing/base/extension_registry.html"> 9<link rel="import" href="/tracing/base/guid.html"> 10 11<script> 12'use strict'; 13 14tr.exportTo('tr.model', function() { 15 /** 16 * Annotation is a base class that represents all annotation objects that 17 * can be drawn on the timeline. 18 * 19 * @constructor 20 */ 21 function Annotation() { 22 this.guid_ = tr.b.GUID.allocate(); 23 this.view_ = undefined; 24 }; 25 26 Annotation.fromDictIfPossible = function(args) { 27 if (args.typeName === undefined) 28 throw new Error('Missing typeName argument'); 29 30 var typeInfo = Annotation.findTypeInfoMatching(function(typeInfo) { 31 return typeInfo.metadata.typeName === args.typeName; 32 }); 33 34 if (typeInfo === undefined) 35 return undefined; 36 37 return typeInfo.constructor.fromDict(args); 38 }; 39 40 Annotation.fromDict = function() { 41 throw new Error('Not implemented'); 42 } 43 44 Annotation.prototype = { 45 get guid() { 46 return this.guid_; 47 }, 48 49 // Invoked by trace model when this annotation is removed. 50 onRemove: function() { 51 }, 52 53 toDict: function() { 54 throw new Error('Not implemented'); 55 }, 56 57 getOrCreateView: function(viewport) { 58 if (!this.view_) 59 this.view_ = this.createView_(viewport); 60 return this.view_; 61 }, 62 63 createView_: function() { 64 throw new Error('Not implemented'); 65 } 66 }; 67 68 var options = new tr.b.ExtensionRegistryOptions(tr.b. BASIC_REGISTRY_MODE); 69 tr.b.decorateExtensionRegistry(Annotation, options); 70 71 Annotation.addEventListener('will-register', function(e) { 72 if (!e.typeInfo.constructor.hasOwnProperty('fromDict')) 73 throw new Error('Must have fromDict method'); 74 75 if (!e.typeInfo.metadata.typeName) 76 throw new Error('Registered Annotations must provide typeName'); 77 }); 78 79 return { 80 Annotation: Annotation 81 }; 82}); 83</script> 84