Changeset 96223 in webkit
- Timestamp:
- Sep 28, 2011 8:01:41 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r96221 r96223 1 2011-09-28 Vsevolod Vlasov <vsevik@chromium.org> 2 3 Web Inspector: Add support for search in single resource to page agent. 4 https://bugs.webkit.org/show_bug.cgi?id=68998 5 6 Reviewed by Pavel Feldman. 7 8 * http/tests/inspector/search/search-in-resource-expected.txt: Added. 9 * http/tests/inspector/search/search-in-resource.html: Added. 10 * http/tests/inspector/search/search-in-resources.html: 11 * http/tests/inspector/search/search-test.js: 12 (initialize_SearchTest.InspectorTest.dumpSearchResults): 13 (initialize_SearchTest.InspectorTest.dumpSearchMatches): 14 (initialize_SearchTest): 15 1 16 2011-09-28 Oliver Varga <voliver@inf.u-szeged.hu> 2 17 -
trunk/LayoutTests/http/tests/inspector/search/search-in-resources.html
r96215 r96223 9 9 // This file should not match search query. 10 10 var text = "searchTest" + "UniqueString"; 11 InspectorTest.runAfterResourcesAreFinished(["search.js", "search.css", "search.html"], step2);12 11 13 function step2() 12 InspectorTest.addResult("Case insensitive, non regex:"); 13 PageAgent.searchInResources(text, false, false, step2); 14 15 function step2(error, searchResults) 14 16 { 15 InspectorTest.addResult("Case insensitive, non regex:"); 16 PageAgent.searchInResources(text, false, false, step3); 17 InspectorTest.dumpSearchResults(searchResults); 18 InspectorTest.addResult("Case sensitive, non regex:"); 19 PageAgent.searchInResources(text, true, false, step3); 17 20 } 18 21 … … 20 23 { 21 24 InspectorTest.dumpSearchResults(searchResults); 22 InspectorTest.addResult("Case sensitive, nonregex:");23 PageAgent.searchInResources(text, true, false, step4);25 InspectorTest.addResult("Case insensitive, regex:"); 26 PageAgent.searchInResources(text, false, true, step4); 24 27 } 25 28 … … 27 30 { 28 31 InspectorTest.dumpSearchResults(searchResults); 29 InspectorTest.addResult("Case insensitive, regex:");30 PageAgent.searchInResources(text, false, true, step5);32 InspectorTest.addResult("Case sensitive, regex:"); 33 PageAgent.searchInResources(text, true, true, step5); 31 34 } 32 35 33 36 function step5(error, searchResults) 34 {35 InspectorTest.dumpSearchResults(searchResults);36 InspectorTest.addResult("Case sensitive, regex:");37 PageAgent.searchInResources(text, true, true, step6);38 }39 40 function step6(error, searchResults)41 37 { 42 38 InspectorTest.dumpSearchResults(searchResults); -
trunk/LayoutTests/http/tests/inspector/search/search-test.js
r96215 r96223 7 7 InspectorTest.addResult("url: " + searchResults[i].url + ", matchesCount: " + searchResults[i].matchesCount); 8 8 InspectorTest.addResult(""); 9 } 9 }; 10 11 InspectorTest.dumpSearchMatches = function(searchMatches) 12 { 13 InspectorTest.addResult("Search matches: "); 14 for (var i = 0; i < searchMatches.length; i++) 15 InspectorTest.addResult("lineNumber: " + searchMatches[i].lineNumber + ", line: '" + searchMatches[i].lineContent + "'"); 16 InspectorTest.addResult(""); 17 }; 10 18 11 19 }; -
trunk/Source/WebCore/ChangeLog
r96222 r96223 1 2011-09-28 Vsevolod Vlasov <vsevik@chromium.org> 2 3 Web Inspector: Add support for search in single resource to page agent. 4 https://bugs.webkit.org/show_bug.cgi?id=68998 5 6 Reviewed by Pavel Feldman. 7 8 Test: http/tests/inspector/search/search-in-resource.html 9 10 * inspector/ContentSearchUtils.cpp: 11 (WebCore::ContentSearchUtils::getRegularExpressionMatchesByLines): 12 * inspector/ContentSearchUtils.h: 13 * inspector/Inspector.json: 14 * inspector/InspectorPageAgent.cpp: 15 (WebCore::buildObjectForSearchMatch): 16 (WebCore::InspectorPageAgent::searchInResource): 17 * inspector/InspectorPageAgent.h: 18 * inspector/front-end/Resource.js: 19 (WebInspector.Resource.prototype.searchInContent): 20 * inspector/front-end/SourceFile.js: 21 (WebInspector.ResourceContentProvider.prototype.requestContent): 22 (WebInspector.ResourceContentProvider.prototype.searchInContent): 23 * inspector/front-end/UISourceCode.js: 24 (WebInspector.ContentProvider.prototype.requestContent): 25 (WebInspector.ContentProvider.prototype.searchInContent): 26 1 27 2011-09-28 Ilya Tikhonovsky <loislo@chromium.org> 2 28 -
trunk/Source/WebCore/inspector/ContentSearchUtils.cpp
r96215 r96223 32 32 #if ENABLE(INSPECTOR) 33 33 34 #include "InspectorValues.h" 34 35 #include "RegularExpression.h" 36 37 using namespace std; 35 38 36 39 namespace WebCore { … … 53 56 result.append(characters[i]); 54 57 } 58 59 return result; 60 } 61 62 static Vector<pair<int, String> > getRegularExpressionMatchesByLines(const RegularExpression& regex, const String& text) 63 { 64 Vector<pair<int, String> > result; 65 66 int lineNumber = 0; 67 unsigned start = 0; 68 while (start < text.length()) { 69 size_t lineEnd = text.find('\n', start); 70 if (lineEnd == notFound) 71 lineEnd = text.length(); 72 else 73 lineEnd++; 74 75 String line = text.substring(start, lineEnd - start); 76 if (line.endsWith("\r\n")) 77 line = line.left(line.length() - 2); 78 if (line.endsWith("\n")) 79 line = line.left(line.length() - 1); 80 81 int matchLength; 82 if (regex.match(line, 0, &matchLength) != -1) 83 result.append(pair<int, String>(lineNumber, line)); 84 85 start = lineEnd; 86 lineNumber++; 87 } 88 return result; 89 } 90 91 static PassRefPtr<InspectorObject> buildObjectForSearchMatch(int lineNumber, String lineContent) 92 { 93 RefPtr<InspectorObject> result = InspectorObject::create(); 94 result->setNumber("lineNumber", lineNumber); 95 result->setString("lineContent", lineContent); 55 96 56 97 return result; … … 79 120 } 80 121 122 PassRefPtr<InspectorArray> searchInTextByLines(const String& query, const String& text) 123 { 124 RefPtr<InspectorArray> result = InspectorArray::create(); 125 126 RegularExpression regex = ContentSearchUtils::createSearchRegex(query, false, false); 127 Vector<pair<int, String> > matches = getRegularExpressionMatchesByLines(regex, text); 128 129 for (Vector<pair<int, String> >::const_iterator it = matches.begin(); it != matches.end(); ++it) 130 result->pushValue(buildObjectForSearchMatch(it->first, it->second)); 131 132 return result; 133 } 134 81 135 } // namespace ContentSearchUtils 82 136 } // namespace WebCore -
trunk/Source/WebCore/inspector/ContentSearchUtils.h
r96215 r96223 32 32 #include "PlatformString.h" 33 33 34 #include <wtf/Vector.h> 35 34 36 namespace WebCore { 35 37 38 class InspectorArray; 36 39 class RegularExpression; 37 40 … … 40 43 RegularExpression createSearchRegex(const String& text, bool caseSensitive, bool isRegex); 41 44 int countRegularExpressionMatches(const RegularExpression&, const String&); 45 PassRefPtr<InspectorArray> searchInTextByLines(const String& query, const String& text); 42 46 43 47 } // namespace ContentSearchUtils -
trunk/Source/WebCore/inspector/Inspector.json
r96106 r96223 103 103 }, 104 104 { 105 "id": "SearchMatch", 106 "type": "object", 107 "description": "Search match for resource.", 108 "properties": [ 109 { "name": "lineNumber", "type": "number", "description": "Line number in resource content." }, 110 { "name": "lineContent", "type": "string", "description": "Line with match content." } 111 ], 112 "hidden": true 113 }, 114 { 105 115 "id": "SearchResult", 106 116 "type": "object", … … 186 196 { "name": "content", "type": "string", "description": "Resource content." }, 187 197 { "name": "base64Encoded", "type": "boolean", "description": "True, if content was served as base64." } 198 ], 199 "hidden": true 200 }, 201 { 202 "name": "searchInResource", 203 "description": "Searches for given string in resource content.", 204 "parameters": [ 205 { "name": "frameId", "type": "string", "description": "Frame id for resource to search in." }, 206 { "name": "url", "type": "string", "description": "URL of the resource to search in." }, 207 { "name": "query", "type": "string", "description": "String to search for." } 208 ], 209 "returns": [ 210 { "name": "result", "type": "array", "items": { "$ref": "SearchMatch" }, "description": "List of search matches." } 188 211 ], 189 212 "hidden": true -
trunk/Source/WebCore/inspector/InspectorPageAgent.cpp
r96215 r96223 68 68 #include <wtf/Vector.h> 69 69 70 using namespace std; 71 70 72 namespace WebCore { 71 73 … … 483 485 } 484 486 487 void InspectorPageAgent::searchInResource(ErrorString*, const String& frameId, const String& url, const String& query, RefPtr<InspectorArray>* object) 488 { 489 RefPtr<InspectorArray> result = InspectorArray::create(); 490 491 Frame* frame = frameForId(frameId); 492 KURL kurl(ParsedURLString, url); 493 494 FrameLoader* frameLoader = frame ? frame->loader() : 0; 495 DocumentLoader* loader = frameLoader ? frameLoader->documentLoader() : 0; 496 if (!loader) { 497 *object = result; 498 return; 499 } 500 501 String content; 502 bool success = false; 503 if (equalIgnoringFragmentIdentifier(kurl, loader->url())) 504 success = mainResourceContent(frame, false, &content); 505 506 if (!success) { 507 CachedResource* resource = cachedResource(frame, kurl); 508 success = textContentForCachedResource(resource, &content); 509 } 510 511 if (!success) { 512 *object = result; 513 return; 514 } 515 516 result = ContentSearchUtils::searchInTextByLines(query, content); 517 *object = result; 518 } 519 485 520 static PassRefPtr<InspectorObject> buildObjectForSearchResult(const String& frameId, const String& url, int matchesCount) 486 521 { -
trunk/Source/WebCore/inspector/InspectorPageAgent.h
r95901 r96223 98 98 void getResourceTree(ErrorString*, RefPtr<InspectorObject>*); 99 99 void getResourceContent(ErrorString*, const String& frameId, const String& url, String* content, bool* base64Encoded); 100 void searchInResource(ErrorString*, const String& frameId, const String& url, const String&, RefPtr<InspectorArray>*); 100 101 void searchInResources(ErrorString*, const String&, const bool* const caseSensitive, const bool* const isRegex, RefPtr<InspectorArray>*); 101 102 -
trunk/Source/WebCore/inspector/front-end/Resource.js
r94754 r96223 868 868 }, 869 869 870 searchInContent: function(query, callback) 871 { 872 PageAgent.searchInResource(query, callback); 873 }, 874 870 875 populateImageSource: function(image) 871 876 { -
trunk/Source/WebCore/inspector/front-end/SourceFile.js
r96097 r96223 359 359 } 360 360 this._resource.requestContent(didRequestContent.bind(this)); 361 } 361 }, 362 363 searchInContent: function(query, callback) 364 { 365 this._resource.searchInContent(query, callback); 366 } 362 367 } 363 368 -
trunk/Source/WebCore/inspector/front-end/UISourceCode.js
r93969 r96223 91 91 WebInspector.ContentProvider = function() { } 92 92 WebInspector.ContentProvider.prototype = { 93 requestContent: function(callback) { } 93 requestContent: function(callback) { }, 94 searchInContent: function(query, callback) { } 94 95 }
Note: See TracChangeset
for help on using the changeset viewer.