Changeset 96215 in webkit
- Timestamp:
- Sep 28, 2011 4:56:36 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 10 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r96212 r96215 1 2011-09-28 Vsevolod Vlasov <vsevik@chromium.org> 2 3 Web Inspector: Refactor searching in inspector, add test (fixed non regex search). 4 https://bugs.webkit.org/show_bug.cgi?id=68930 5 6 Reviewed by Yury Semikhatsky. 7 8 * http/tests/inspector/search/resources/search.css: Added. 9 (div.searchTestUniqueString): 10 (div.searchTestUniqueString:hover): 11 * http/tests/inspector/search/resources/search.html: Added. 12 * http/tests/inspector/search/resources/search.js: Added. 13 (searchTestUniqueString): 14 (doSomething): 15 * http/tests/inspector/search/search-in-resources-expected.txt: Added. 16 * http/tests/inspector/search/search-in-resources.html: Added. 17 * http/tests/inspector/search/search-test.js: Added. 18 (initialize_SearchTest.InspectorTest.dumpSearchResults): 19 (initialize_SearchTest): 20 1 21 2011-09-28 Kentaro Hara <haraken@chromium.org> 2 22 -
trunk/Source/WebCore/CMakeLists.txt
r96142 r96215 854 854 855 855 inspector/ConsoleMessage.cpp 856 inspector/ContentSearchUtils.cpp 856 857 inspector/DOMNodeHighlighter.cpp 857 858 inspector/IdentifiersFactory.cpp -
trunk/Source/WebCore/ChangeLog
r96212 r96215 1 2011-09-28 Vsevolod Vlasov <vsevik@chromium.org> 2 3 Web Inspector: Refactor searching in inspector, add test (fixed non regex search). 4 https://bugs.webkit.org/show_bug.cgi?id=68930 5 6 Reviewed by Yury Semikhatsky. 7 8 Search moved out from page agent. 9 Fixed search for non regex case which is not yet used. 10 11 Test: http/tests/inspector/search/search-in-resources.html 12 13 * CMakeLists.txt: 14 * GNUmakefile.list.am: 15 * WebCore.gypi: 16 * WebCore.pro: 17 * WebCore.vcproj/WebCore.vcproj: 18 * WebCore.xcodeproj/project.pbxproj: 19 * inspector/ContentSearchUtils.cpp: Added. 20 (WebCore::ContentSearchUtils::createSearchRegexSource): 21 (WebCore::ContentSearchUtils::createSearchRegex): 22 (WebCore::ContentSearchUtils::countRegularExpressionMatches): 23 * inspector/ContentSearchUtils.h: Added. 24 * inspector/InspectorPageAgent.cpp: 25 (WebCore::hasTextContent): 26 (WebCore::InspectorPageAgent::cachedResourceContent): 27 (WebCore::textContentForCachedResource): 28 (WebCore::buildObjectForSearchResult): 29 (WebCore::InspectorPageAgent::searchInResources): 30 * inspector/front-end/utilities.js: 31 (): 32 1 33 2011-09-28 Kentaro Hara <haraken@chromium.org> 2 34 -
trunk/Source/WebCore/GNUmakefile.list.am
r96142 r96215 1976 1976 Source/WebCore/inspector/ConsoleMessage.cpp \ 1977 1977 Source/WebCore/inspector/ConsoleMessage.h \ 1978 Source/WebCore/inspector/ContentSearchUtils.cpp \ 1979 Source/WebCore/inspector/ContentSearchUtils.h \ 1978 1980 Source/WebCore/inspector/DOMNodeHighlighter.cpp \ 1979 1981 Source/WebCore/inspector/DOMNodeHighlighter.h \ -
trunk/Source/WebCore/WebCore.gypi
r96186 r96215 2661 2661 'inspector/ConsoleMessage.cpp', 2662 2662 'inspector/ConsoleMessage.h', 2663 'inspector/ContentSearchUtils.cpp', 2664 'inspector/ContentSearchUtils.h', 2663 2665 'inspector/DOMNodeHighlighter.cpp', 2664 2666 'inspector/DOMNodeHighlighter.h', -
trunk/Source/WebCore/WebCore.pro
r96142 r96215 813 813 html/shadow/TextControlInnerElements.cpp \ 814 814 inspector/ConsoleMessage.cpp \ 815 inspector/ContentSearchUtils.cpp \ 815 816 inspector/DOMNodeHighlighter.cpp \ 816 817 inspector/IdentifiersFactory.cpp \ … … 1805 1806 html/track/WebVTTTokenizer.h \ 1806 1807 inspector/ConsoleMessage.h \ 1808 inspector/ContentSearchUtils.h \ 1807 1809 inspector/DOMNodeHighlighter.h \ 1808 1810 inspector/IdentifiersFactory.h \ -
trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj
r96142 r96215 68679 68679 </File> 68680 68680 <File 68681 RelativePath="..\inspector\ContentSearchUtils.cpp" 68682 > 68683 </File> 68684 <File 68685 RelativePath="..\inspector\ContentSearchUtils.h" 68686 > 68687 </File> 68688 <File 68681 68689 RelativePath="..\inspector\DOMNodeHighlighter.cpp" 68682 68690 > -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r96163 r96215 1505 1505 590E1B4911E4EF4B0069F784 /* DeviceOrientation.h in Headers */ = {isa = PBXBuildFile; fileRef = 590E1B4811E4EF4B0069F784 /* DeviceOrientation.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1506 1506 590E1B4B11E4EF700069F784 /* JSDeviceOrientationEventCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 590E1B4A11E4EF700069F784 /* JSDeviceOrientationEventCustom.cpp */; }; 1507 59102FBB14327D3B003C9D04 /* ContentSearchUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 59102FB914327D3B003C9D04 /* ContentSearchUtils.cpp */; }; 1508 59102FBC14327D3B003C9D04 /* ContentSearchUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 59102FBA14327D3B003C9D04 /* ContentSearchUtils.h */; }; 1507 1509 5913A24113D49EBA00F5B05C /* IdentifiersFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5913A23F13D49EBA00F5B05C /* IdentifiersFactory.cpp */; }; 1508 1510 5913A24213D49EBA00F5B05C /* IdentifiersFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = 5913A24013D49EBA00F5B05C /* IdentifiersFactory.h */; }; … … 8172 8174 590E1B4811E4EF4B0069F784 /* DeviceOrientation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeviceOrientation.h; sourceTree = "<group>"; }; 8173 8175 590E1B4A11E4EF700069F784 /* JSDeviceOrientationEventCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDeviceOrientationEventCustom.cpp; sourceTree = "<group>"; }; 8176 59102FB914327D3B003C9D04 /* ContentSearchUtils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ContentSearchUtils.cpp; sourceTree = "<group>"; }; 8177 59102FBA14327D3B003C9D04 /* ContentSearchUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContentSearchUtils.h; sourceTree = "<group>"; }; 8174 8178 5913A23F13D49EBA00F5B05C /* IdentifiersFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IdentifiersFactory.cpp; sourceTree = "<group>"; }; 8175 8179 5913A24013D49EBA00F5B05C /* IdentifiersFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IdentifiersFactory.h; sourceTree = "<group>"; }; … … 13619 13623 41F0618D0F5F069800A07EAC /* ConsoleMessage.cpp */, 13620 13624 41F0618C0F5F069800A07EAC /* ConsoleMessage.h */, 13625 59102FB914327D3B003C9D04 /* ContentSearchUtils.cpp */, 13626 59102FBA14327D3B003C9D04 /* ContentSearchUtils.h */, 13621 13627 4F1442261339FD6200E0D6F8 /* DOMNodeHighlighter.cpp */, 13622 13628 4F1442271339FD6200E0D6F8 /* DOMNodeHighlighter.h */, … … 23538 23544 CECCFC3B141973D5002A0AC1 /* DecodeEscapeSequences.h in Headers */, 23539 23545 0FE71406142170B800DB33BA /* ScrollbarThemeMock.h in Headers */, 23546 59102FBC14327D3B003C9D04 /* ContentSearchUtils.h in Headers */, 23540 23547 ); 23541 23548 runOnlyForDeploymentPostprocessing = 0; … … 26377 26384 319AE063142D6B24006563A1 /* StyleFilterData.cpp in Sources */, 26378 26385 319AE069142D78DD006563A1 /* FilterOperations.cpp in Sources */, 26386 59102FBB14327D3B003C9D04 /* ContentSearchUtils.cpp in Sources */, 26379 26387 ); 26380 26388 runOnlyForDeploymentPostprocessing = 0; -
trunk/Source/WebCore/inspector/InspectorPageAgent.cpp
r95901 r96215 40 40 #include "CachedResourceLoader.h" 41 41 #include "CachedScript.h" 42 #include "ContentSearchUtils.h" 42 43 #include "Cookie.h" 43 44 #include "CookieJar.h" … … 69 70 namespace WebCore { 70 71 71 namespace {72 // This should be kept the same as the one in front-end/utilities.js73 static const char regexSpecialCharacters[] = "[](){}+-*.,?\\^$|";74 }75 76 72 namespace PageAgentState { 77 73 static const char pageAgentEnabled[] = "resourceAgentEnabled"; … … 116 112 } 117 113 114 static bool hasTextContent(CachedResource* cachedResource) 115 { 116 InspectorPageAgent::ResourceType type = InspectorPageAgent::cachedResourceType(*cachedResource); 117 return type == InspectorPageAgent::StylesheetResource || type == InspectorPageAgent::ScriptResource; 118 } 119 118 120 bool InspectorPageAgent::cachedResourceContent(CachedResource* cachedResource, String* result, bool* base64Encoded) 119 121 { … … 123 125 return false; 124 126 125 ResourceType type = cachedResourceType(*cachedResource); 126 *base64Encoded = type != StylesheetResource && type != ScriptResource; 127 127 *base64Encoded = !hasTextContent(cachedResource); 128 128 if (*base64Encoded) { 129 129 RefPtr<SharedBuffer> buffer = hasZeroSize ? SharedBuffer::create() : cachedResource->data(); … … 470 470 } 471 471 472 static String createSearchRegexSource(const String& text) 473 { 474 String result; 475 const UChar* characters = text.characters(); 476 String specials(regexSpecialCharacters); 477 478 for (unsigned i = 0; i < text.length(); i++) { 479 if (specials.find(characters[i])) 480 result.append("\\"); 481 result.append(characters[i]); 482 } 483 484 return result; 485 } 486 487 static int countRegularExpressionMatches(const RegularExpression& regex, const String& content) 488 { 489 int result = 0; 490 int position; 491 unsigned start = 0; 492 int matchLength; 493 while ((position = regex.match(content, start, &matchLength)) != -1) { 494 if (start >= content.length()) 495 break; 496 if (matchLength > 0) 497 ++result; 498 start = position + 1; 499 } 500 return result; 501 } 502 503 static PassRefPtr<InspectorObject> buildObjectForSearchMatch(const String& frameId, const String& url, int matchesCount) 472 static bool textContentForCachedResource(CachedResource* cachedResource, String* result) 473 { 474 if (hasTextContent(cachedResource)) { 475 String content; 476 bool base64Encoded; 477 if (InspectorPageAgent::cachedResourceContent(cachedResource, result, &base64Encoded)) { 478 ASSERT(!base64Encoded); 479 return true; 480 } 481 } 482 return false; 483 } 484 485 static PassRefPtr<InspectorObject> buildObjectForSearchResult(const String& frameId, const String& url, int matchesCount) 504 486 { 505 487 RefPtr<InspectorObject> result = InspectorObject::create(); … … 516 498 517 499 bool isRegex = optionalIsRegex ? *optionalIsRegex : false; 518 String regexSource = isRegex ? text : createSearchRegexSource(text);519 520 500 bool caseSensitive = optionalCaseSensitive ? *optionalCaseSensitive : false; 521 RegularExpression regex (regexSource, caseSensitive ? TextCaseSensitive : TextCaseInsensitive);501 RegularExpression regex = ContentSearchUtils::createSearchRegex(text, caseSensitive, isRegex); 522 502 523 503 for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext(m_page->mainFrame())) { 524 504 String content; 525 bool base64Encoded;526 505 Vector<CachedResource*> allResources = cachedResourcesForFrame(frame); 527 506 for (Vector<CachedResource*>::const_iterator it = allResources.begin(); it != allResources.end(); ++it) { 528 507 CachedResource* cachedResource = *it; 529 switch (InspectorPageAgent::cachedResourceType(*cachedResource)) { 530 case InspectorPageAgent::StylesheetResource: 531 case InspectorPageAgent::ScriptResource: 532 if (cachedResourceContent(cachedResource, &content, &base64Encoded)) { 533 ASSERT(!base64Encoded); 534 int matchesCount = countRegularExpressionMatches(regex, content); 535 if (matchesCount) 536 result->pushValue(buildObjectForSearchMatch(frameId(frame), cachedResource->url(), matchesCount)); 537 } 538 break; 539 default: 540 break; 508 if (textContentForCachedResource(cachedResource, &content)) { 509 int matchesCount = ContentSearchUtils::countRegularExpressionMatches(regex, content); 510 if (matchesCount) 511 result->pushValue(buildObjectForSearchResult(frameId(frame), cachedResource->url(), matchesCount)); 541 512 } 542 513 } 543 514 if (mainResourceContent(frame, false, &content)) { 544 int matchesCount = countRegularExpressionMatches(regex, content);515 int matchesCount = ContentSearchUtils::countRegularExpressionMatches(regex, content); 545 516 if (matchesCount) 546 result->pushValue(buildObjectForSearch Match(frameId(frame), frame->document()->url(), matchesCount));517 result->pushValue(buildObjectForSearchResult(frameId(frame), frame->document()->url(), matchesCount)); 547 518 } 548 519 } -
trunk/Source/WebCore/inspector/front-end/utilities.js
r95401 r96215 962 962 function createSearchRegex(query, extraFlags) 963 963 { 964 // This should be kept the same as the one in InspectorPageAgent.cpp.964 // This should be kept the same as the one in ContentSearchUtils.cpp. 965 965 var regexSpecialCharacters = "[](){}+-*.,?\\^$|"; 966 966 var regex = "";
Note: See TracChangeset
for help on using the changeset viewer.