Guest User

Untitled

a guest
Oct 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.08 KB | None | 0 0
  1. ====in AdvanceSearchController.js====
  2.  
  3. WebInspector.SearchConfig = function(query, ignoreCase, isRegex)
  4. {
  5. this.query = query;
  6. this.ignoreCase = ignoreCase;
  7. this.isRegex = isRegex;
  8. this._queryConfig = this._parseSearchQuery();
  9. }
  10.  
  11.  
  12. WebInspector.SearchConfig.prototype = {
  13.  
  14. _parseSearchQuery: function()
  15. {
  16. if (this.query === "")
  17. return;
  18.  
  19. var queryConfig = {};
  20.  
  21. function isSoureCodeSelectorToken(token)
  22. {
  23. var matches = /^file:(.*)/gi.exec(token);
  24. return matches && matches[1];
  25. }
  26.  
  27. function isQuotedToken(query)
  28. {
  29. return query[0] === "\"" ? true : false;
  30. }
  31.  
  32.  
  33. function buildQueryTokens(queryString)
  34. {
  35. var tokens = queryString.match(/([^\s]*\"([^\\"]|\\\\|\\")*\"[^\s]*)|([^\s]+)/gi);
  36.  
  37. /*
  38. taking it as an array as we need to check each query string's presence in all qualified source code.
  39. I am not very sure of how to properly apply "and" within regex.
  40. */
  41. var simpleStringPattern = [];
  42. var quotedStringPattern = [];
  43. var sourceCodeSelectorPattern = [];
  44.  
  45.  
  46. for(var i=0; i < tokens.length ; ++i) {
  47. if (isQuotedToken(tokens[i]))
  48. quotedStringPattern.push(tokens[i].replace(/^"|"$/g, ""));
  49. else if (isSoureCodeSelectorToken(tokens[i]))
  50. sourceCodeSelectorPattern.push(tokens[i].split(":")[1]);
  51. else
  52. simpleStringPattern.push(tokens[i]);
  53. }
  54.  
  55. if (sourceCodeSelectorPattern.length) {
  56. queryConfig.sourceCodeSelectors = sourceCodeSelectorPattern;
  57. queryConfig.searchQueryStrings = quotedStringPattern.concat(simpleStringPattern);
  58. /* having a state to check if source code selector(file:xx) is mentioned */
  59. queryConfig.sourceCodeSelectorQueryState = true;
  60. } else
  61. queryConfig.sourceCodeSelectorQueryState = false;
  62.  
  63. }
  64.  
  65. buildQueryTokens(this.query);
  66.  
  67. return queryConfig;
  68. },
  69.  
  70. get queries()token file:js
  71. {
  72. return this._queryConfig.searchQueryStrings;
  73. },
  74.  
  75. get sourceCodeSelectors()
  76. {
  77. return this._queryConfig.sourceCodeSelectors;
  78. },
  79.  
  80. get isSourceCodeSelectorEnabled()
  81. {
  82. return this._queryConfig.sourceCodeSelectorQueryState;
  83. },
  84.  
  85. isSourceCodeSelectorScript : function(url)
  86. {
  87. for (var i = 0; i < this.sourceCodeSelectors.length ; ++i ) {
  88. var regex = new RegExp(this.sourceCodeSelectors[i],"gi");
  89. if (!regex.test(url))
  90. return false;
  91. }
  92. return true;
  93. }
  94.  
  95. }
  96.  
  97.  
  98.  
  99. ====in ScriptSearchScope.js====
  100.  
  101. performSearch: function(searchConfig, searchResultCallback, searchFinishedCallback)
  102. {
  103. this.stopSearch();
  104.  
  105. var uiSourceCodes = this._sortedUISourceCodes();
  106. var uiSourceCodeIndex = 0;
  107. var searchQueryIndex = 0;
  108. var searchResultsConfig = {searchMatches:[], queryCount:0};
  109.  
  110. function filterOutContentScripts(uiSourceCode)
  111. {
  112. return !uiSourceCode.isContentScript;
  113. }
  114.  
  115. function filterOutSourceCodeSelectorScripts(uiSourceCode)
  116. {
  117. return searchConfig.isSourceCodeSelectorScript(uiSourceCode.contentURL());
  118. }
  119.  
  120. if (!WebInspector.settings.searchInContentScripts.get())
  121. uiSourceCodes = uiSourceCodes.filter(filterOutContentScripts);
  122.  
  123. if (searchConfig.isSourceCodeSelectorEnabled)
  124. uiSourceCodes = uiSourceCodes.filter(filterOutSourceCodeSelectorScripts);
  125.  
  126.  
  127. function continueSearch()
  128. {
  129. // FIXME: Enable support for counting matches for incremental search.
  130. // FIXME: Enable support for bounding search results/matches number to keep inspector responsive.
  131. function updateIndexes()
  132. {
  133. uiSourceCodeIndex++;
  134. searchQueryIndex = 0;
  135. searchResultsConfig = {searchMatches:[], queryCount:0};
  136. }
  137.  
  138. /*
  139. I tried combining all as a string. ex for "file:js foo bar abc"
  140. regex = "(?=.*foo)(?=.*bar)(?=.*abc)"
  141. but searchInContect was not returning proper results.
  142. Am not very sure of applying "and" within regex.
  143. */
  144. function searchQueryInSelectorSourceCode(uiSourceCode)
  145. {
  146. if (searchQueryIndex < searchConfig.queries.length) {
  147. uiSourceCode.searchInContent(searchConfig.queries[searchQueryIndex], !searchConfig.ignoreCase, true,
  148. searchCallbackWrapper.bind(this, this._searchId, uiSourceCode));
  149. } else {
  150. if (searchResultsConfig.queryCount == searchConfig.queries.length) {
  151. var searchResult = new WebInspector.FileBasedSearchResultsPane.SearchResult(uiSourceCode, searchResultsConfig.searchMatches);
  152. searchResultCallback(searchResult);
  153. }
  154. updateIndexes();
  155. continueSearch.call(this);
  156. }
  157. }
  158.  
  159. if (uiSourceCodeIndex < uiSourceCodes.length) {
  160. var uiSourceCode = uiSourceCodes[uiSourceCodeIndex];
  161. if (searchConfig.isSourceCodeSelectorEnabled)
  162. searchQueryInSelectorSourceCode(uiSourceCode);
  163. else
  164. uiSourceCode.searchInContent(searchConfig.query, !searchConfig.ignoreCase, searchConfig.isRegex,
  165. searchCallbackWrapper.bind(this, this._searchId, uiSourceCode));
  166. } else
  167. searchFinishedCallback(true);
  168. }
  169.  
  170. function searchCallbackWrapper(searchId, uiSourceCode, searchMatches)
  171. {
  172. if (searchId !== this._searchId) {
  173. searchFinishedCallback(false);
  174. return;
  175. }
  176.  
  177. if (searchConfig.isSourceCodeSelectorEnabled) {
  178. searchQueryIndex++;
  179. if (searchMatches.length) {
  180. searchResultsConfig.searchMatches = searchResultsConfig.searchMatches.concat(searchMatches);
  181. searchResultsConfig.queryCount++;
  182. }
  183. }
  184. else if (!searchConfig.isSourceCodeSelectorEnabled){
  185. var searchResult = new WebInspector.FileBasedSearchResultsPane.SearchResult(uiSourceCode, searchMatches);
  186. searchResultCallback(searchResult);
  187. uiSourceCodeIndex++;
  188. }
  189.  
  190.  
  191. continueSearch.call(this);
  192. }
  193.  
  194. continueSearch.call(this);
  195. return uiSourceCodes.length;
  196. },
Add Comment
Please, Sign In to add comment