2 * Copyright (C) 2012 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.VBox}
34 * @param {!WebInspector.FileSystemModel.File} file
36 WebInspector.FileContentView = function(file)
38 WebInspector.VBox.call(this);
40 this._innerView = /** @type {?WebInspector.Widget} */ (null);
45 WebInspector.FileContentView.prototype = {
48 if (!this._innerView) {
49 if (this._file.isTextFile)
50 this._innerView = new WebInspector.EmptyWidget("");
52 this._innerView = new WebInspector.EmptyWidget(WebInspector.UIString("Binary File"));
56 this._innerView.show(this.element);
60 * @param {number} errorCode
61 * @param {!FileSystemAgent.Metadata} metadata
63 _metadataReceived: function(errorCode, metadata)
65 if (errorCode || !metadata)
69 if (!this._content.updateMetadata(metadata))
71 var sourceFrame = /** @type {!WebInspector.SourceFrame} */ (this._innerView);
72 this._content.requestContent(sourceFrame.setContent.bind(sourceFrame));
74 this._innerView.detach();
75 this._content = new WebInspector.FileContentView.FileContentProvider(this._file, metadata);
76 var sourceFrame = new WebInspector.SourceFrame(this._content);
77 sourceFrame.setHighlighterType(this._file.resourceType.canonicalMimeType());
78 this._innerView = sourceFrame;
79 this._innerView.show(this.element);
88 if (this._file.isTextFile)
89 this._file.requestMetadata(this._metadataReceived.bind(this));
92 __proto__: WebInspector.VBox.prototype
97 * @implements {WebInspector.ContentProvider}
98 * @param {!WebInspector.FileSystemModel.File} file
99 * @param {!FileSystemAgent.Metadata} metadata
101 WebInspector.FileContentView.FileContentProvider = function(file, metadata)
104 this._metadata = metadata;
107 WebInspector.FileContentView.FileContentProvider.prototype = {
112 contentURL: function()
114 return this._file.url;
119 * @return {!WebInspector.ResourceType}
121 contentType: function()
123 return this._file.resourceType;
128 * @param {function(?string)} callback
130 requestContent: function(callback)
132 var size = /** @type {number} */ (this._metadata.size);
133 this._file.requestFileContent(true, 0, size, this._charset || "", this._fileContentReceived.bind(this, callback));
137 * @param {function(?string)} callback
138 * @param {number} errorCode
139 * @param {string=} content
140 * @param {boolean=} base64Encoded
141 * @param {string=} charset
143 _fileContentReceived: function(callback, errorCode, content, base64Encoded, charset)
145 if (errorCode || !content) {
150 this._charset = charset;
156 * @param {string} query
157 * @param {boolean} caseSensitive
158 * @param {boolean} isRegex
159 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} callback
161 searchInContent: function(query, caseSensitive, isRegex, callback)
163 setTimeout(callback.bind(null, []), 0);
167 * @param {!FileSystemAgent.Metadata} metadata
170 updateMetadata: function(metadata)
172 if (this._metadata.modificationTime >= metadata.modificationTime)
174 this._metadata = metadata.modificationTime;