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);
87 var dataURL = this.request.asDataURL();
89 return new WebInspector.RequestHTMLView(this.request, dataURL);
92 _createPreviewView: function()
94 if (this.request.contentError())
95 return this._createMessageView(WebInspector.UIString("Failed to load response data"));
97 var jsonMediaTypeRE = /^application\/[^;]*\+json/;
98 if (this.request.mimeType === "application/json" || jsonMediaTypeRE.test(this.request.mimeType)) {
99 var jsonView = this._jsonView();
104 if (this.request.hasErrorStatusCode()) {
105 var htmlView = this._htmlView();
110 if (this.request.type === WebInspector.resourceTypes.XHR) {
111 var jsonView = this._jsonView();
116 if (this.request.type === WebInspector.resourceTypes.XHR && this.request.mimeType === "text/html") {
117 var htmlView = this._htmlView();
122 if (this._responseView.sourceView)
123 return this._responseView.sourceView;
125 if (this.request.type === WebInspector.resourceTypes.Other)
126 return this._createEmptyView();
128 return WebInspector.RequestView.nonSourceViewForRequest(this.request);
131 __proto__: WebInspector.RequestContentView.prototype