Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 904 var options = []; | 904 var options = []; |
| 905 for (var index = 0; index < this._states.length; index++) { | 905 for (var index = 0; index < this._states.length; index++) { |
| 906 if (this._states[index] !== this.state() && this._states[index] !== this._currentState) | 906 if (this._states[index] !== this.state() && this._states[index] !== this._currentState) |
| 907 options.push(this._buttons[index]); | 907 options.push(this._buttons[index]); |
| 908 } | 908 } |
| 909 return options; | 909 return options; |
| 910 }, | 910 }, |
| 911 | 911 |
| 912 __proto__: WebInspector.ToolbarButton.prototype | 912 __proto__: WebInspector.ToolbarButton.prototype |
| 913 } | 913 } |
| 914 | |
| 915 /** | |
| 916 * @constructor | |
| 917 * @extends {WebInspector.Toolbar} | |
| 918 * @param {string} location | |
| 919 * @param {!Element=} parentElement | |
| 920 */ | |
| 921 WebInspector.ExtensibleToolbar = function(location, parentElement) | |
| 922 { | |
| 923 WebInspector.Toolbar.call(this, parentElement); | |
| 924 this._loadItems(location); | |
| 925 } | |
| 926 | |
| 927 WebInspector.ExtensibleToolbar.prototype = { | |
| 928 | |
|
dgozman
2015/04/23 14:09:36
nit: extra blank line
sergeyv
2015/04/23 17:42:12
Done.
| |
| 929 /** | |
| 930 * @param {string} location | |
| 931 */ | |
| 932 _loadItems: function(location) | |
| 933 { | |
| 934 var extensions = self.runtime.extensions(WebInspector.ToolbarItem.Provid er); | |
| 935 var promises = []; | |
| 936 for (var i = 0; i < extensions.length; ++i) { | |
| 937 if (extensions[i].descriptor()["location"] === location) | |
| 938 promises.push(resolveItem(extensions[i])); | |
| 939 } | |
| 940 Promise.all(promises).then(appendItemsInOrder.bind(this)); | |
| 941 | |
| 942 /** | |
| 943 * @param {!Runtime.Extension} extension | |
| 944 * @return {!Promise.<?WebInspector.ToolbarItem>} | |
| 945 */ | |
| 946 function resolveItem(extension) | |
| 947 { | |
| 948 var descriptor = extension.descriptor(); | |
| 949 if (!descriptor.className) | |
| 950 return Promise.resolve(new WebInspector.ToolbarButton(WebInspect or.UIString(descriptor["title"]), descriptor["elementClass"])).then(attachHandle r); | |
| 951 return extension.instancePromise().then(fetchItemFromProvider).then( attachHandler); | |
| 952 | |
| 953 /** | |
| 954 * @param {!Object} provider | |
| 955 */ | |
| 956 function fetchItemFromProvider(provider) | |
| 957 { | |
| 958 return /** @type {!WebInspector.ToolbarItem.Provider} */ (provid er).item(); | |
| 959 } | |
| 960 | |
| 961 /** | |
| 962 * @param {?WebInspector.ToolbarItem} item | |
| 963 * @return {?WebInspector.ToolbarItem} item | |
| 964 */ | |
| 965 function attachHandler(item) | |
| 966 { | |
| 967 if (extension.descriptor()["actionId"] && item) | |
| 968 item.addEventListener("click", handler); | |
| 969 return item; | |
| 970 } | |
| 971 | |
| 972 function handler() | |
| 973 { | |
| 974 WebInspector.actionRegistry.execute(extension.descriptor()["acti onId"]); | |
| 975 } | |
| 976 } | |
| 977 | |
| 978 /** | |
| 979 * @param {!Array.<?WebInspector.ToolbarItem>} items | |
| 980 * @this {WebInspector.ExtensibleToolbar} | |
| 981 */ | |
| 982 function appendItemsInOrder(items) | |
| 983 { | |
| 984 for (var i = 0; i < items.length; ++i) { | |
| 985 var item = items[i]; | |
| 986 if (item) | |
| 987 this.appendToolbarItem(item); | |
| 988 } | |
| 989 } | |
| 990 }, | |
| 991 | |
| 992 __proto__: WebInspector.Toolbar.prototype | |
| 993 } | |
| OLD | NEW |