tizen beta release
[profile/ivi/webkit-efl.git] / debian / tmp / usr / share / ewebkit-0 / webinspector / ScriptsSearchScope.js
1 /*
2  * Copyright (C) 2011 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  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following disclaimer
13  * in the documentation and/or other materials provided with the
14  * distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC.
20  * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 /**
30  * @constructor
31  * @implements {WebInspector.SearchScope}
32  */
33 WebInspector.ScriptsSearchScope = function()
34 {
35     // FIXME: Add title once it is used by search controller.
36     WebInspector.SearchScope.call(this)
37     this._searchId = 0;
38 }
39
40 WebInspector.ScriptsSearchScope.prototype = {
41     /**
42      * @param {WebInspector.SearchConfig} searchConfig
43      * @param {function(Object)} searchResultCallback
44      * @param {function(boolean)} searchFinishedCallback
45      */
46     performSearch: function(searchConfig, searchResultCallback, searchFinishedCallback)
47     {
48         this.stopSearch();
49         
50         var uiSourceCodes = this._sortedUISourceCodes();
51         var uiSourceCodeIndex = 0;
52         
53         function filterOutContentScripts(uiSourceCode)
54         {
55             return !uiSourceCode.isContentScript;
56         }
57         
58         if (!WebInspector.settings.searchInContentScripts.get())
59             uiSourceCodes = uiSourceCodes.filter(filterOutContentScripts);
60
61         function continueSearch()
62         {
63             // FIXME: Enable support for counting matches for incremental search.
64             // FIXME: Enable support for bounding search results/matches number to keep inspector responsive.
65             if (uiSourceCodeIndex < uiSourceCodes.length) {
66                 var uiSourceCode = uiSourceCodes[uiSourceCodeIndex++];
67                 uiSourceCode.searchInContent(searchConfig.query, !searchConfig.ignoreCase, searchConfig.isRegex, searchCallbackWrapper.bind(this, this._searchId, uiSourceCode));
68             } else 
69                 searchFinishedCallback(true);
70         }
71
72         function searchCallbackWrapper(searchId, uiSourceCode, searchMatches)
73         {
74             if (searchId !== this._searchId) {
75                 searchFinishedCallback(false);
76                 return;
77             }
78                 
79             var searchResult = new WebInspector.FileBasedSearchResultsPane.SearchResult(uiSourceCode, searchMatches);
80             searchResultCallback(searchResult);
81             continueSearch.call(this);
82         }
83         
84         continueSearch.call(this);
85         return uiSourceCodes.length;
86     },
87
88     stopSearch: function()
89     {
90         ++this._searchId;
91     },
92
93     /**
94      * @param {WebInspector.SearchConfig} searchConfig
95      */
96     createSearchResultsPane: function(searchConfig)
97     {
98         return new WebInspector.ScriptsSearchResultsPane(searchConfig);
99     },
100
101     /**
102      * @return {Array.<WebInspector.UISourceCode>}
103      */
104     _sortedUISourceCodes: function()
105     {
106         function filterOutAnonymous(uiSourceCode)
107         {
108             return !!uiSourceCode.url;
109         }
110         
111         function comparator(a, b)
112         {
113             return a.url.localeCompare(b.url);   
114         }
115         
116         var uiSourceCodes = WebInspector.debuggerPresentationModel.uiSourceCodes();
117         
118         uiSourceCodes = uiSourceCodes.filter(filterOutAnonymous);
119         uiSourceCodes.sort(comparator);
120         
121         return uiSourceCodes;
122     }
123 }
124
125 WebInspector.ScriptsSearchScope.prototype.__proto__ = WebInspector.SearchScope.prototype;
126
127 /**
128  * @constructor
129  * @extends {WebInspector.FileBasedSearchResultsPane}
130  * @param {WebInspector.SearchConfig} searchConfig
131  */
132 WebInspector.ScriptsSearchResultsPane = function(searchConfig)
133 {
134     WebInspector.FileBasedSearchResultsPane.call(this, searchConfig)
135
136     this._linkifier = WebInspector.debuggerPresentationModel.createLinkifier(new WebInspector.ScriptsSearchResultsPane.LinkifierFormatter());
137 }
138
139 WebInspector.ScriptsSearchResultsPane.prototype = {
140     /**
141      * @param {Object} file
142      * @param {number} lineNumber
143      * @param {number} columnNumber
144      */
145     createAnchor: function(file, lineNumber, columnNumber)
146     {
147         
148         var uiSourceCode = file;
149         var rawSourceCode = uiSourceCode.rawSourceCode;
150         var rawLocation = rawSourceCode.sourceMapping.uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber);
151         var anchor = this._linkifier.linkifyRawSourceCode(uiSourceCode.rawSourceCode, rawLocation.lineNumber, rawLocation.columnNumber);
152         anchor.removeChildren();
153         return anchor;
154     },
155     
156     /**
157      * @param {Object} file
158      * @return {string}
159      */
160     fileName: function(file)
161     {
162         var uiSourceCode = file;
163         return uiSourceCode.url;
164     },
165 }
166
167 WebInspector.ScriptsSearchResultsPane.prototype.__proto__ = WebInspector.FileBasedSearchResultsPane.prototype;
168
169 /**
170  * @constructor
171  * @implements {WebInspector.DebuggerPresentationModel.LinkifierFormatter}
172  */
173 WebInspector.ScriptsSearchResultsPane.LinkifierFormatter = function()
174 {
175 }
176
177 WebInspector.ScriptsSearchResultsPane.LinkifierFormatter.prototype = {
178     /**
179      * @param {WebInspector.RawSourceCode} rawSourceCode
180      * @param {Element} anchor
181      */
182     formatRawSourceCodeAnchor: function(rawSourceCode, anchor)
183     {
184         // Empty because we don't want to ever update anchor contents after creation.
185     }
186 }
187
188 WebInspector.ScriptsSearchResultsPane.LinkifierFormatter.prototype.__proto__ = WebInspector.DebuggerPresentationModel.LinkifierFormatter.prototype;
189
190 WebInspector.settings.searchInContentScripts = WebInspector.settings.createSetting("searchInContentScripts", false);