1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
<!DOCTYPE html>
<!--
Copyright (c) 2013 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="import" href="/tracing/base/iteration_helpers.html">
<link rel="import" href="/tracing/base/event_target.html">
<link rel="import" href="/tracing/base/extension_registry_basic.html">
<link rel="import" href="/tracing/base/extension_registry_type_based.html">
<script>
'use strict';
/**
* @fileoverview Helper code for defining extension registries, which can be
* used to make a part of trace-viewer extensible.
*
* This file provides two basic types of extension registries:
* - Generic: register a type with metadata, query for those types based on
* a predicate
*
* - TypeName-based: register a type that handles some combination
* of tracing categories or typeNames, then query
* for it based on a category, typeName or both.
*
* Use these for pure-JS classes or ui.define'd classes. For polymer element
* related registries, consult base/polymer_utils.html.
*
* When you register subtypes, you pass the constructor for the
* subtype, and any metadata you want associated with the subtype. Use metadata
* instead of stuffing fields onto the constructor. E.g.:
* registry.register(MySubclass, {titleWhenShownInTabStrip: 'MySub'})
*
* Some registries want a default object that is returned when a more precise
* subtype has been registered. To provide one, set the defaultConstructor
* option on the registry options.
*
* TODO: Extension registry used to make reference to mandatoryBaseType but it
* was never enforced. We may want to add it back in the future in order to
* enforce the types that can be put into a given registry.
*/
tr.exportTo('tr.b', function() {
function decorateExtensionRegistry(registry, registryOptions) {
if (registry.register)
throw new Error('Already has registry');
registryOptions.freeze();
if (registryOptions.mode == tr.b.BASIC_REGISTRY_MODE) {
tr.b._decorateBasicExtensionRegistry(registry, registryOptions);
} else if (registryOptions.mode == tr.b.TYPE_BASED_REGISTRY_MODE) {
tr.b._decorateTypeBasedExtensionRegistry(registry, registryOptions);
} else {
throw new Error('Unrecognized mode');
}
// Make it an event target.
if (registry.addEventListener === undefined)
tr.b.EventTarget.decorate(registry);
}
return {
decorateExtensionRegistry: decorateExtensionRegistry
};
});
</script>
|