Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @param {!WebInspector.RemoteObject} object | 7 * @param {!WebInspector.RemoteObject} object |
| 8 */ | 8 */ |
| 9 WebInspector.CustomPreviewSection = function(object) | 9 WebInspector.CustomPreviewSection = function(object) |
| 10 { | 10 { |
| 11 this._sectionElement = createElementWithClass("span", "custom-expandable-sec tion"); | 11 this._sectionElement = createElementWithClass("span", "custom-expandable-sec tion"); |
| 12 this._object = object; | 12 this._object = object; |
| 13 this._expanded = false; | 13 this._expanded = false; |
| 14 this._cachedContent = null; | 14 this._cachedContent = null; |
| 15 var customPreview = object.customPreview(); | 15 var customPreview = object.customPreview(); |
| 16 | 16 |
| 17 try { | 17 try { |
| 18 var headerJSON = JSON.parse(customPreview.header); | 18 var headerJSON = JSON.parse(customPreview.header); |
| 19 } catch (e) { | 19 } catch (e) { |
| 20 WebInspector.console.error("Broken formatter: header is invalid json " + e); | 20 WebInspector.console.error("Broken formatter: header is invalid json " + e); |
| 21 return; | 21 return; |
| 22 } | 22 } |
| 23 this._header = this._renderJSONMLTag(headerJSON); | 23 this._header = this._renderJSONMLTag(headerJSON); |
| 24 if (this._header.nodeType === Node.TEXT_NODE) { | |
| 25 WebInspector.console.error("Broken formatter: header should be tag. Text node aren't allowed as header!"); | |
|
pfeldman
2015/04/23 09:50:52
Header should be an element node.
sergeyv
2015/04/23 10:09:10
Done.
| |
| 26 return; | |
| 27 } | |
| 28 | |
| 24 if (customPreview.hasBody) { | 29 if (customPreview.hasBody) { |
| 25 this._header.classList.add("custom-expandable-section-header"); | 30 this._header.classList.add("custom-expandable-section-header"); |
| 26 this._header.addEventListener("click", this._onClick.bind(this), false); | 31 this._header.addEventListener("click", this._onClick.bind(this), false); |
| 27 } | 32 } |
| 28 | 33 |
| 29 this._sectionElement.appendChild(this._header); | 34 this._sectionElement.appendChild(this._header); |
| 30 } | 35 } |
| 31 | 36 |
| 32 /** | 37 /** |
| 33 * @constructor | 38 * @constructor |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 /** | 150 /** |
| 146 * @param {!Node} parentElement | 151 * @param {!Node} parentElement |
| 147 * @param {!Array.<*>} jsonMLTags | 152 * @param {!Array.<*>} jsonMLTags |
| 148 */ | 153 */ |
| 149 _appendJsonMLTags: function(parentElement, jsonMLTags) | 154 _appendJsonMLTags: function(parentElement, jsonMLTags) |
| 150 { | 155 { |
| 151 for (var i = 0; i < jsonMLTags.length; ++i) | 156 for (var i = 0; i < jsonMLTags.length; ++i) |
| 152 parentElement.appendChild(this._renderJSONMLTag(jsonMLTags[i])); | 157 parentElement.appendChild(this._renderJSONMLTag(jsonMLTags[i])); |
| 153 }, | 158 }, |
| 154 | 159 |
| 155 _onClick: function() | 160 /** |
| 161 * @param {!Event} event | |
| 162 */ | |
| 163 _onClick: function(event) | |
| 156 { | 164 { |
| 165 event.consume(true); | |
| 157 if (this._cachedContent) | 166 if (this._cachedContent) |
| 158 this._toggleExpand(); | 167 this._toggleExpand(); |
| 159 else | 168 else |
| 160 this._loadBody(); | 169 this._loadBody(); |
| 161 }, | 170 }, |
| 162 | 171 |
| 163 _toggleExpand: function() | 172 _toggleExpand: function() |
| 164 { | 173 { |
| 165 this._expanded = !this._expanded; | 174 this._expanded = !this._expanded; |
| 166 this._header.classList.toggle("expanded", this._expanded); | 175 this._header.classList.toggle("expanded", this._expanded); |
| 167 this._cachedContent.classList.toggle("hidden", !this._expanded); | 176 this._cachedContent.classList.toggle("hidden", !this._expanded); |
| 168 }, | 177 }, |
| 169 | 178 |
| 170 _loadBody: function() | 179 _loadBody: function() |
| 171 { | 180 { |
| 172 /** | 181 /** |
| 173 * @suppressReceiverCheck | 182 * @suppressReceiverCheck |
| 174 * @suppressGlobalPropertiesCheck | 183 * @suppressGlobalPropertiesCheck |
| 175 * @suppress {undefinedVars} | 184 * @suppress {undefinedVars} |
| 176 * @this {Object} | 185 * @this {Object} |
| 177 * @param {*=} formatter | 186 * @param {*=} formatter |
| 187 * @param {*=} config | |
| 178 */ | 188 */ |
| 179 function load(formatter) | 189 function load(formatter, config) |
| 180 { | 190 { |
| 181 /** | 191 /** |
| 182 * @param {*} jsonMLObject | 192 * @param {*} jsonMLObject |
| 183 * @throws {string} error message | 193 * @throws {string} error message |
| 184 */ | 194 */ |
| 185 function substituteObjectTagsInCustomPreview(jsonMLObject) | 195 function substituteObjectTagsInCustomPreview(jsonMLObject) |
| 186 { | 196 { |
| 187 if (!jsonMLObject || (typeof jsonMLObject !== "object") || (type of jsonMLObject.splice !== "function")) | 197 if (!jsonMLObject || (typeof jsonMLObject !== "object") || (type of jsonMLObject.splice !== "function")) |
| 188 return; | 198 return; |
| 189 | 199 |
| 190 var obj = jsonMLObject.length; | 200 var obj = jsonMLObject.length; |
| 191 if (!(typeof obj === "number" && obj >>> 0 === obj && (obj > 0 | | 1 / obj > 0))) | 201 if (!(typeof obj === "number" && obj >>> 0 === obj && (obj > 0 | | 1 / obj > 0))) |
| 192 return; | 202 return; |
| 193 | 203 |
| 194 var startIndex = 1; | 204 var startIndex = 1; |
| 195 if (jsonMLObject[0] === "object") { | 205 if (jsonMLObject[0] === "object") { |
| 196 var attributes = jsonMLObject[1]; | 206 var attributes = jsonMLObject[1]; |
| 197 var originObject = attributes["object"]; | 207 var originObject = attributes["object"]; |
| 208 var config = attributes["config"]; | |
| 198 if (typeof originObject === "undefined") | 209 if (typeof originObject === "undefined") |
| 199 throw "Illegal format: obligatory attribute \"object\" i sn't specified"; | 210 throw "Illegal format: obligatory attribute \"object\" i sn't specified"; |
| 200 | 211 |
| 201 jsonMLObject[1] = bindRemoteObject(originObject, false, fals e, null, false); | 212 jsonMLObject[1] = bindRemoteObject(originObject, false, fals e, null, false, config); |
| 202 startIndex = 2; | 213 startIndex = 2; |
| 203 } | 214 } |
| 204 for (var i = startIndex; i < jsonMLObject.length; ++i) | 215 for (var i = startIndex; i < jsonMLObject.length; ++i) |
| 205 substituteObjectTagsInCustomPreview(jsonMLObject[i]); | 216 substituteObjectTagsInCustomPreview(jsonMLObject[i]); |
| 206 } | 217 } |
| 207 | 218 |
| 208 try { | 219 try { |
| 209 var body = formatter.body(this); | 220 var body = formatter.body(this, config); |
| 210 substituteObjectTagsInCustomPreview(body); | 221 substituteObjectTagsInCustomPreview(body); |
| 211 return body; | 222 return body; |
| 212 } catch (e) { | 223 } catch (e) { |
| 213 console.error("Custom Formatter Failed: " + e); | 224 console.error("Custom Formatter Failed: " + e); |
| 214 return null; | 225 return null; |
| 215 } | 226 } |
| 216 } | 227 } |
| 217 | 228 |
| 218 var customPreview = this._object.customPreview(); | 229 var customPreview = this._object.customPreview(); |
| 219 this._object.callFunctionJSON(load, [{objectId: customPreview.formatterO bjectId}], onBodyLoaded.bind(this)); | 230 var args = [{objectId: customPreview.formatterObjectId}]; |
| 231 if (customPreview.configObjectId) | |
| 232 args.push({objectId: customPreview.configObjectId}); | |
| 233 this._object.callFunctionJSON(load, args, onBodyLoaded.bind(this)); | |
| 220 | 234 |
| 221 /** | 235 /** |
| 222 * @param {*} bodyJsonML | 236 * @param {*} bodyJsonML |
| 223 * @this {WebInspector.CustomPreviewSection} | 237 * @this {WebInspector.CustomPreviewSection} |
| 224 */ | 238 */ |
| 225 function onBodyLoaded(bodyJsonML) | 239 function onBodyLoaded(bodyJsonML) |
| 226 { | 240 { |
| 227 if (!bodyJsonML) | 241 if (!bodyJsonML) |
| 228 return; | 242 return; |
| 229 | 243 |
| 230 this._cachedContent = this._renderJSONMLTag(bodyJsonML); | 244 this._cachedContent = this._renderJSONMLTag(bodyJsonML); |
| 231 this._sectionElement.appendChild(this._cachedContent); | 245 this._sectionElement.appendChild(this._cachedContent); |
| 232 this._toggleExpand(); | 246 this._toggleExpand(); |
| 233 } | 247 } |
| 234 } | 248 } |
| 235 } | 249 } |
| OLD | NEW |