2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) IBM Corp. 2009 All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 WebInspector.ResourceView = function(resource)
32 WebInspector.View.call(this);
33 this.element.addStyleClass("resource-view");
34 this.resource = resource;
37 WebInspector.ResourceView.prototype = {
38 hasContent: function()
44 WebInspector.ResourceView.prototype.__proto__ = WebInspector.View.prototype;
46 WebInspector.ResourceView.hasTextContent = function(resource)
48 switch (resource.category) {
49 case WebInspector.resourceCategories.documents:
50 case WebInspector.resourceCategories.scripts:
51 case WebInspector.resourceCategories.xhr:
52 case WebInspector.resourceCategories.stylesheets:
54 case WebInspector.resourceCategories.other:
55 return resource.content && !resource.contentEncoded;
61 WebInspector.ResourceView.nonSourceViewForResource = function(resource)
63 switch (resource.category) {
64 case WebInspector.resourceCategories.images:
65 return new WebInspector.ImageView(resource);
66 case WebInspector.resourceCategories.fonts:
67 return new WebInspector.FontView(resource);
69 return new WebInspector.ResourceView(resource);
73 WebInspector.ResourceSourceFrame = function(resource)
75 WebInspector.SourceFrame.call(this, new WebInspector.SourceFrameDelegate(resource), resource.url);
76 this._resource = resource;
79 //This is a map from resource.type to mime types
80 //found in WebInspector.SourceTokenizer.Registry.
81 WebInspector.ResourceSourceFrame.DefaultMIMETypeForResourceType = {
87 WebInspector.ResourceSourceFrame.mimeTypeForResource = function(resource) {
88 return WebInspector.ResourceSourceFrame.DefaultMIMETypeForResourceType[resource.type] || resource.mimeType;
91 WebInspector.ResourceSourceFrame.prototype = {
94 return this._resource;
97 requestContent: function(callback)
99 function contentLoaded(text)
101 var mimeType = WebInspector.ResourceSourceFrame.mimeTypeForResource(this.resource);
102 callback(mimeType, text);
105 this.resource.requestContent(contentLoaded.bind(this));
108 suggestedFileName: function()
110 return this.resource.displayName;
114 WebInspector.ResourceSourceFrame.prototype.__proto__ = WebInspector.SourceFrame.prototype;
116 WebInspector.EditableResourceSourceFrame = function(resource)
118 WebInspector.ResourceSourceFrame.call(this, resource);
121 WebInspector.EditableResourceSourceFrame.prototype = {
122 canEditSource: function()
124 return this.resource.isEditable() && !this._commitEditingInProgress;
127 editContent: function(newText, callback)
129 this._clearIncrementalUpdateTimer();
130 var majorChange = true;
131 this.resource.setContent(newText, majorChange, callback);
134 cancelEditing: function()
136 this._clearIncrementalUpdateTimer();
137 const majorChange = false;
138 if (this._viewerState)
139 this.resource.setContent(this._viewerState.textModelContent, majorChange);
140 WebInspector.SourceFrame.prototype.cancelEditing.call(this);
143 afterTextChanged: function(oldRange, newRange)
145 function commitIncrementalEdit()
147 var majorChange = false;
148 this.resource.setContent(this._textModel.text, majorChange, function() {});
150 const updateTimeout = 200;
151 this._incrementalUpdateTimer = setTimeout(commitIncrementalEdit.bind(this), updateTimeout);
154 _clearIncrementalUpdateTimer: function()
156 if (this._incrementalUpdateTimer)
157 clearTimeout(this._incrementalUpdateTimer);
158 delete this._incrementalUpdateTimer;
162 WebInspector.EditableResourceSourceFrame.prototype.__proto__ = WebInspector.ResourceSourceFrame.prototype;
164 WebInspector.ResourceRevisionSourceFrame = function(revision)
166 WebInspector.ResourceSourceFrame.call(this, revision.resource);
167 this._revision = revision;
170 WebInspector.ResourceRevisionSourceFrame.prototype = {
173 return this._revision.resource;
176 requestContent: function(callback)
178 function contentLoaded(text)
180 var mimeType = WebInspector.ResourceSourceFrame.mimeTypeForResource(this.resource);
181 callback(mimeType, text);
184 this._revision.requestContent(contentLoaded.bind(this));
188 WebInspector.ResourceRevisionSourceFrame.prototype.__proto__ = WebInspector.ResourceSourceFrame.prototype;