2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * @extends {WebInspector.Object}
35 WebInspector.HandlerRegistry = function(setting)
37 WebInspector.Object.call(this);
39 this._setting = setting;
40 this._activeHandler = this._setting.get();
43 WebInspector.HandlerRegistry.prototype = {
46 return Object.getOwnPropertyNames(this._handlers);
51 return this._activeHandler;
54 set activeHandler(value)
56 this._activeHandler = value;
57 this._setting.set(value);
61 * @param {Object} data
63 dispatch: function(data)
65 this.dispatchToHandler(this._activeHandler, data);
69 * @param {string} name
70 * @param {Object} data
72 dispatchToHandler: function(name, data)
74 var handler = this._handlers[name];
75 var result = handler && handler(data);
79 registerHandler: function(name, handler)
81 this._handlers[name] = handler;
82 this.dispatchEventToListeners(WebInspector.HandlerRegistry.EventTypes.HandlersUpdated);
85 unregisterHandler: function(name)
87 delete this._handlers[name];
88 this.dispatchEventToListeners(WebInspector.HandlerRegistry.EventTypes.HandlersUpdated);
92 WebInspector.HandlerRegistry.EventTypes = {
93 HandlersUpdated: "HandlersUpdated"
96 WebInspector.HandlerRegistry.prototype.__proto__ = WebInspector.Object.prototype;
101 WebInspector.HandlerSelector = function(handlerRegistry)
103 this._handlerRegistry = handlerRegistry;
104 this.element = document.createElement("select");
105 this.element.addEventListener("change", this._onChange.bind(this), false);
107 this._handlerRegistry.addEventListener(WebInspector.HandlerRegistry.EventTypes.HandlersUpdated, this._update.bind(this));
110 WebInspector.HandlerSelector.prototype =
114 this.element.removeChildren();
115 var names = this._handlerRegistry.handlerNames;
116 var activeHandler = this._handlerRegistry.activeHandler;
118 for (var i = 0; i < names.length; ++i) {
119 var option = document.createElement("option");
120 option.textContent = names[i];
121 option.selected = activeHandler === names[i];
122 this.element.appendChild(option);
124 this.element.disabled = names.length <= 1;
127 _onChange: function(event)
129 var value = event.target.value;
130 this._handlerRegistry.activeHandler = value;