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.RequestContentView}
34 * @param {!WebInspector.NetworkRequest} request
36 WebInspector.RequestPreviewView = function(request, responseView)
38 WebInspector.RequestContentView.call(this, request);
39 this._responseView = responseView;
42 WebInspector.RequestPreviewView.prototype = {
43 contentLoaded: function()
45 if (!this.request.content && !this.request.contentError()) {
46 if (!this._emptyView) {
47 this._emptyView = this._createEmptyView();
48 this._emptyView.show(this.element);
49 this.innerView = this._emptyView;
52 if (this._emptyView) {
53 this._emptyView.detach();
54 delete this._emptyView;
57 if (!this._previewView)
58 this._previewView = this._createPreviewView();
59 this._previewView.show(this.element);
60 this.innerView = this._previewView;
64 _createEmptyView: function()
66 return this._createMessageView(WebInspector.UIString("This request has no preview available."));
70 * @param {string} message
71 * @return {!WebInspector.EmptyView}
73 _createMessageView: function(message)
75 return new WebInspector.EmptyView(message);
80 var parsedJSON = WebInspector.RequestJSONView.parseJSON(this.request.content);
82 return new WebInspector.RequestJSONView(this.request, parsedJSON);
86 * @return {?WebInspector.RequestHTMLView}
88 _htmlErrorPreview: function()
90 var whitelist = ["text/html", "text/plain", "application/xhtml+xml"];
91 if (whitelist.indexOf(this.request.mimeType) === -1)
94 var dataURL = this.request.asDataURL();
98 return new WebInspector.RequestHTMLView(this.request, dataURL);
101 _createPreviewView: function()
103 if (this.request.contentError())
104 return this._createMessageView(WebInspector.UIString("Failed to load response data"));
106 var mimeType = this.request.mimeType || "";
107 if (mimeType === "application/json" || mimeType.endsWith("+json")) {
108 var jsonView = this._jsonView();
113 if (this.request.hasErrorStatusCode()) {
114 var htmlErrorPreview = this._htmlErrorPreview();
115 if (htmlErrorPreview)
116 return htmlErrorPreview;
119 if (this.request.type === WebInspector.resourceTypes.XHR) {
120 var jsonView = this._jsonView();
123 var htmlErrorPreview = this._htmlErrorPreview();
124 if (htmlErrorPreview)
125 return htmlErrorPreview;
128 if (this._responseView.sourceView)
129 return this._responseView.sourceView;
131 if (this.request.type === WebInspector.resourceTypes.Other)
132 return this._createEmptyView();
134 return WebInspector.RequestView.nonSourceViewForRequest(this.request);
137 __proto__: WebInspector.RequestContentView.prototype