| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * | |
| 8 * 1. Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | |
| 11 * notice, this list of conditions and the following disclaimer in the | |
| 12 * documentation and/or other materials provided with the distribution. | |
| 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | |
| 14 * its contributors may be used to endorse or promote products derived | |
| 15 * from this software without specific prior written permission. | |
| 16 * | |
| 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
| 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
| 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 27 */ | |
| 28 | |
| 29 WebInspector.ResourceView = function(resource) | |
| 30 { | |
| 31 WebInspector.View.call(this); | |
| 32 | |
| 33 this.element.addStyleClass("resource-view"); | |
| 34 | |
| 35 this.resource = resource; | |
| 36 | |
| 37 this.headersElement = document.createElement("div"); | |
| 38 this.headersElement.className = "resource-view-headers"; | |
| 39 this.element.appendChild(this.headersElement); | |
| 40 | |
| 41 this.contentElement = document.createElement("div"); | |
| 42 this.contentElement.className = "resource-view-content"; | |
| 43 this.element.appendChild(this.contentElement); | |
| 44 | |
| 45 this.headersListElement = document.createElement("ol"); | |
| 46 this.headersListElement.className = "outline-disclosure"; | |
| 47 this.headersElement.appendChild(this.headersListElement); | |
| 48 | |
| 49 this.headersTreeOutline = new TreeOutline(this.headersListElement); | |
| 50 this.headersTreeOutline.expandTreeElementsWhenArrowing = true; | |
| 51 | |
| 52 this.urlTreeElement = new TreeElement("", null, false); | |
| 53 this.urlTreeElement.selectable = false; | |
| 54 this.headersTreeOutline.appendChild(this.urlTreeElement); | |
| 55 | |
| 56 this.requestHeadersTreeElement = new TreeElement("", null, true); | |
| 57 this.requestHeadersTreeElement.expanded = false; | |
| 58 this.requestHeadersTreeElement.selectable = false; | |
| 59 this.headersTreeOutline.appendChild(this.requestHeadersTreeElement); | |
| 60 | |
| 61 this.responseHeadersTreeElement = new TreeElement("", null, true); | |
| 62 this.responseHeadersTreeElement.expanded = false; | |
| 63 this.responseHeadersTreeElement.selectable = false; | |
| 64 this.headersTreeOutline.appendChild(this.responseHeadersTreeElement); | |
| 65 | |
| 66 this.headersVisible = true; | |
| 67 | |
| 68 resource.addEventListener("url changed", this._refreshURL, this); | |
| 69 resource.addEventListener("requestHeaders changed", this._refreshRequestHead
ers, this); | |
| 70 resource.addEventListener("responseHeaders changed", this._refreshResponseHe
aders, this); | |
| 71 | |
| 72 this._refreshURL(); | |
| 73 this._refreshRequestHeaders(); | |
| 74 this._refreshResponseHeaders(); | |
| 75 } | |
| 76 | |
| 77 WebInspector.ResourceView.prototype = { | |
| 78 get headersVisible() | |
| 79 { | |
| 80 return this._headersVisible; | |
| 81 }, | |
| 82 | |
| 83 set headersVisible(x) | |
| 84 { | |
| 85 if (x === this._headersVisible) | |
| 86 return; | |
| 87 | |
| 88 this._headersVisible = x; | |
| 89 | |
| 90 if (x) | |
| 91 this.element.addStyleClass("headers-visible"); | |
| 92 else | |
| 93 this.element.removeStyleClass("headers-visible"); | |
| 94 }, | |
| 95 | |
| 96 attach: function() | |
| 97 { | |
| 98 if (!this.element.parentNode) { | |
| 99 var parentElement = (document.getElementById("resource-views") || do
cument.getElementById("script-resource-views")); | |
| 100 if (parentElement) | |
| 101 parentElement.appendChild(this.element); | |
| 102 } | |
| 103 }, | |
| 104 | |
| 105 _refreshURL: function() | |
| 106 { | |
| 107 this.urlTreeElement.title = this.resource.url.escapeHTML(); | |
| 108 }, | |
| 109 | |
| 110 _refreshRequestHeaders: function() | |
| 111 { | |
| 112 this._refreshHeaders(WebInspector.UIString("Request Headers"), this.reso
urce.sortedRequestHeaders, this.requestHeadersTreeElement); | |
| 113 }, | |
| 114 | |
| 115 _refreshResponseHeaders: function() | |
| 116 { | |
| 117 this._refreshHeaders(WebInspector.UIString("Response Headers"), this.res
ource.sortedResponseHeaders, this.responseHeadersTreeElement); | |
| 118 }, | |
| 119 | |
| 120 _refreshHeaders: function(title, headers, headersTreeElement) | |
| 121 { | |
| 122 headersTreeElement.removeChildren(); | |
| 123 | |
| 124 var length = headers.length; | |
| 125 headersTreeElement.title = title.escapeHTML() + "<span class=\"header-co
unt\">" + WebInspector.UIString(" (%d)", length) + "</span>"; | |
| 126 headersTreeElement.hidden = !length; | |
| 127 | |
| 128 var length = headers.length; | |
| 129 for (var i = 0; i < length; ++i) { | |
| 130 var title = "<div class=\"header-name\">" + headers[i].header.escape
HTML() + ":</div>"; | |
| 131 title += "<div class=\"header-value\">" + headers[i].value.escapeHTM
L() + "</div>" | |
| 132 | |
| 133 var headerTreeElement = new TreeElement(title, null, false); | |
| 134 headerTreeElement.selectable = false; | |
| 135 headersTreeElement.appendChild(headerTreeElement); | |
| 136 } | |
| 137 } | |
| 138 } | |
| 139 | |
| 140 WebInspector.ResourceView.prototype.__proto__ = WebInspector.View.prototype; | |
| OLD | NEW |