2ac4953ce3067cdf20b4284174070a8bac03d25f
[WebKit-https.git] / Source / WebCore / inspector / front-end / JavaScriptSource.js
1 /*
2  * Copyright (C) 2012 Google 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 are
6  * met:
7  *
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
13  * distribution.
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.
17  *
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.
29  */
30
31 /**
32  * @constructor
33  * @extends {WebInspector.UISourceCode}
34  * @param {string} url
35  * @param {WebInspector.Resource} resource
36  * @param {WebInspector.ContentProvider} contentProvider
37  * @param {WebInspector.SourceMapping} sourceMapping
38  */
39 WebInspector.JavaScriptSource = function(url, resource, contentProvider, sourceMapping, isEditable)
40 {
41     WebInspector.UISourceCode.call(this, url, resource, contentProvider, sourceMapping);
42     this._isEditable = isEditable;
43 }
44
45 WebInspector.JavaScriptSource.prototype = {
46     /**
47      * @param {number} lineNumber
48      * @param {number} columnNumber
49      * @return {WebInspector.DebuggerModel.Location}
50      */
51     uiLocationToRawLocation: function(lineNumber, columnNumber)
52     {
53         var rawLocation = WebInspector.UISourceCode.prototype.uiLocationToRawLocation.call(this, lineNumber, columnNumber);
54         var debuggerModelLocation = /** @type {WebInspector.DebuggerModel.Location} */ rawLocation;
55         return debuggerModelLocation;
56     },
57
58     /**
59      * @return {boolean}
60      */
61     supportsEnabledBreakpointsWhileEditing: function()
62     {
63         return false;
64     },
65
66     /**
67      * @return {string}
68      */
69     breakpointStorageId: function()
70     {
71         return this.formatted() ? "deobfuscated:" + this.url : this.url;
72     },
73
74     /**
75      * @return {boolean}
76      */
77     isEditable: function()
78     {
79         return this._isEditable && WebInspector.debuggerModel.canSetScriptSource();
80     },
81
82     /**
83      * @return {boolean}
84      */
85     isDivergedFromVM: function()
86     {
87         // FIXME: We should return true if this._isDivergedFromVM is set as well once we provide a way to set breakpoints after LiveEdit failure.
88         return this.isDirty();
89     },
90
91     /**
92      * @param {function(?string)} callback
93      */
94     workingCopyCommitted: function(callback)
95     {
96         /**
97          * @param {?string} error
98          */
99         function innerCallback(error)
100         {
101             this._isDivergedFromVM = !!error;
102             callback(error);
103         }
104
105         var rawLocation = this.uiLocationToRawLocation(0, 0);
106         var script = WebInspector.debuggerModel.scriptForId(rawLocation.scriptId);
107         WebInspector.debuggerModel.setScriptSource(script.scriptId, this.workingCopy(), innerCallback.bind(this));
108     },
109
110     /**
111      * @param {string} query
112      * @param {boolean} caseSensitive
113      * @param {boolean} isRegex
114      * @param {function(Array.<WebInspector.ContentProvider.SearchMatch>)} callback
115      */
116     searchInContent: function(query, caseSensitive, isRegex, callback)
117     {
118         var content = this.content();
119         var provider = content ? new WebInspector.StaticContentProvider(this._contentProvider.contentType(), content) : this._contentProvider;
120         provider.searchInContent(query, caseSensitive, isRegex, callback);
121     },
122
123     formattedChanged: function()
124     {
125         WebInspector.breakpointManager.restoreBreakpoints(this);
126     }
127 }
128
129 WebInspector.JavaScriptSource.prototype.__proto__ = WebInspector.UISourceCode.prototype;