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 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
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
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.
31 * @implements {WebInspector.SearchScope}
33 WebInspector.ScriptsSearchScope = function()
35 // FIXME: Add title once it is used by search controller.
36 WebInspector.SearchScope.call(this)
40 WebInspector.ScriptsSearchScope.prototype = {
42 * @param {WebInspector.SearchConfig} searchConfig
43 * @param {function(Object)} searchResultCallback
44 * @param {function(boolean)} searchFinishedCallback
46 performSearch: function(searchConfig, searchResultCallback, searchFinishedCallback)
50 var uiSourceCodes = this._sortedUISourceCodes();
51 var uiSourceCodeIndex = 0;
53 function filterOutContentScripts(uiSourceCode)
55 return !uiSourceCode.isContentScript;
58 if (!WebInspector.settings.searchInContentScripts.get())
59 uiSourceCodes = uiSourceCodes.filter(filterOutContentScripts);
61 function continueSearch()
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));
69 searchFinishedCallback(true);
72 function searchCallbackWrapper(searchId, uiSourceCode, searchMatches)
74 if (searchId !== this._searchId) {
75 searchFinishedCallback(false);
79 var searchResult = new WebInspector.FileBasedSearchResultsPane.SearchResult(uiSourceCode, searchMatches);
80 searchResultCallback(searchResult);
81 continueSearch.call(this);
84 continueSearch.call(this);
85 return uiSourceCodes.length;
88 stopSearch: function()
94 * @param {WebInspector.SearchConfig} searchConfig
96 createSearchResultsPane: function(searchConfig)
98 return new WebInspector.ScriptsSearchResultsPane(searchConfig);
102 * @return {Array.<WebInspector.UISourceCode>}
104 _sortedUISourceCodes: function()
106 function filterOutAnonymous(uiSourceCode)
108 return !!uiSourceCode.url;
111 function comparator(a, b)
113 return a.url.localeCompare(b.url);
116 var uiSourceCodes = WebInspector.debuggerPresentationModel.uiSourceCodes();
118 uiSourceCodes = uiSourceCodes.filter(filterOutAnonymous);
119 uiSourceCodes.sort(comparator);
121 return uiSourceCodes;
125 WebInspector.ScriptsSearchScope.prototype.__proto__ = WebInspector.SearchScope.prototype;
129 * @extends {WebInspector.FileBasedSearchResultsPane}
130 * @param {WebInspector.SearchConfig} searchConfig
132 WebInspector.ScriptsSearchResultsPane = function(searchConfig)
134 WebInspector.FileBasedSearchResultsPane.call(this, searchConfig)
136 this._linkifier = WebInspector.debuggerPresentationModel.createLinkifier(new WebInspector.ScriptsSearchResultsPane.LinkifierFormatter());
139 WebInspector.ScriptsSearchResultsPane.prototype = {
141 * @param {Object} file
142 * @param {number} lineNumber
143 * @param {number} columnNumber
145 createAnchor: function(file, lineNumber, columnNumber)
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();
157 * @param {Object} file
160 fileName: function(file)
162 var uiSourceCode = file;
163 return uiSourceCode.url;
167 WebInspector.ScriptsSearchResultsPane.prototype.__proto__ = WebInspector.FileBasedSearchResultsPane.prototype;
171 * @implements {WebInspector.DebuggerPresentationModel.LinkifierFormatter}
173 WebInspector.ScriptsSearchResultsPane.LinkifierFormatter = function()
177 WebInspector.ScriptsSearchResultsPane.LinkifierFormatter.prototype = {
179 * @param {WebInspector.RawSourceCode} rawSourceCode
180 * @param {Element} anchor
182 formatRawSourceCodeAnchor: function(rawSourceCode, anchor)
184 // Empty because we don't want to ever update anchor contents after creation.
188 WebInspector.ScriptsSearchResultsPane.LinkifierFormatter.prototype.__proto__ = WebInspector.DebuggerPresentationModel.LinkifierFormatter.prototype;
190 WebInspector.settings.searchInContentScripts = WebInspector.settings.createSetting("searchInContentScripts", false);