| <!DOCTYPE html> |
| <!-- |
| gCopyright (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="/base/iteration_helpers.html"> |
| <link rel="import" href="/base/event_target.html"> |
| <link rel="import" href="/base/extension_registry_basic.html"> |
| <link rel="import" href="/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. |
| * |
| * If you want to enforce that a registry only manages types of a given subtype, |
| * then set mandatoryBaseType field on the registry. |
| * |
| */ |
| tv.exportTo('tv.b', function() { |
| |
| function decorateExtensionRegistry(registry, registryOptions) { |
| if (registry.register) |
| throw new Error('Already has registry'); |
| |
| registryOptions.freeze(); |
| if (registryOptions.mode == tv.b.BASIC_REGISTRY_MODE) { |
| tv.b._decorateBasicExtensionRegistry(registry, registryOptions); |
| } else if (registryOptions.mode == tv.b.TYPE_BASED_REGISTRY_MODE) { |
| tv.b._decorateTypeBasedExtensionRegistry(registry, registryOptions); |
| } else { |
| throw new Error('Unrecognized mode'); |
| } |
| |
| // Make it an event target. |
| if (registry.addEventListener === undefined) |
| tv.b.EventTarget.decorate(registry); |
| } |
| |
| return { |
| decorateExtensionRegistry: decorateExtensionRegistry |
| }; |
| }); |
| </script> |