Changeset 96215 in webkit


Ignore:
Timestamp:
Sep 28, 2011 4:56:36 AM (13 years ago)
Author:
vsevik@chromium.org
Message:

Web Inspector: Refactor searching in inspector, add test (fixed non regex search).
https://bugs.webkit.org/show_bug.cgi?id=68930

Reviewed by Yury Semikhatsky.

Source/WebCore:

Search moved out from page agent.
Fixed search for non regex case which is not yet used.

Test: http/tests/inspector/search/search-in-resources.html

  • CMakeLists.txt:
  • GNUmakefile.list.am:
  • WebCore.gypi:
  • WebCore.pro:
  • WebCore.vcproj/WebCore.vcproj:
  • WebCore.xcodeproj/project.pbxproj:
  • inspector/ContentSearchUtils.cpp: Added.

(WebCore::ContentSearchUtils::createSearchRegexSource):
(WebCore::ContentSearchUtils::createSearchRegex):
(WebCore::ContentSearchUtils::countRegularExpressionMatches):

  • inspector/ContentSearchUtils.h: Added.
  • inspector/InspectorPageAgent.cpp:

(WebCore::hasTextContent):
(WebCore::InspectorPageAgent::cachedResourceContent):
(WebCore::textContentForCachedResource):
(WebCore::buildObjectForSearchResult):
(WebCore::InspectorPageAgent::searchInResources):

  • inspector/front-end/utilities.js:

():

LayoutTests:

  • http/tests/inspector/search/resources/search.css: Added.

(div.searchTestUniqueString):
(div.searchTestUniqueString:hover):

  • http/tests/inspector/search/resources/search.html: Added.
  • http/tests/inspector/search/resources/search.js: Added.

(searchTestUniqueString):
(doSomething):

  • http/tests/inspector/search/search-in-resources-expected.txt: Added.
  • http/tests/inspector/search/search-in-resources.html: Added.
  • http/tests/inspector/search/search-test.js: Added.

(initialize_SearchTest.InspectorTest.dumpSearchResults):
(initialize_SearchTest):

Location:
trunk
Files:
10 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r96212 r96215  
     12011-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
    1212011-09-28  Kentaro Hara  <haraken@chromium.org>
    222
  • trunk/Source/WebCore/CMakeLists.txt

    r96142 r96215  
    854854
    855855    inspector/ConsoleMessage.cpp
     856    inspector/ContentSearchUtils.cpp
    856857    inspector/DOMNodeHighlighter.cpp
    857858    inspector/IdentifiersFactory.cpp
  • trunk/Source/WebCore/ChangeLog

    r96212 r96215  
     12011-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
    1332011-09-28  Kentaro Hara  <haraken@chromium.org>
    234
  • trunk/Source/WebCore/GNUmakefile.list.am

    r96142 r96215  
    19761976        Source/WebCore/inspector/ConsoleMessage.cpp \
    19771977        Source/WebCore/inspector/ConsoleMessage.h \
     1978        Source/WebCore/inspector/ContentSearchUtils.cpp \
     1979        Source/WebCore/inspector/ContentSearchUtils.h \
    19781980        Source/WebCore/inspector/DOMNodeHighlighter.cpp \
    19791981        Source/WebCore/inspector/DOMNodeHighlighter.h \
  • trunk/Source/WebCore/WebCore.gypi

    r96186 r96215  
    26612661            'inspector/ConsoleMessage.cpp',
    26622662            'inspector/ConsoleMessage.h',
     2663            'inspector/ContentSearchUtils.cpp',
     2664            'inspector/ContentSearchUtils.h',
    26632665            'inspector/DOMNodeHighlighter.cpp',
    26642666            'inspector/DOMNodeHighlighter.h',
  • trunk/Source/WebCore/WebCore.pro

    r96142 r96215  
    813813    html/shadow/TextControlInnerElements.cpp \
    814814    inspector/ConsoleMessage.cpp \
     815    inspector/ContentSearchUtils.cpp \
    815816    inspector/DOMNodeHighlighter.cpp \
    816817    inspector/IdentifiersFactory.cpp \
     
    18051806    html/track/WebVTTTokenizer.h \
    18061807    inspector/ConsoleMessage.h \
     1808    inspector/ContentSearchUtils.h \
    18071809    inspector/DOMNodeHighlighter.h \
    18081810    inspector/IdentifiersFactory.h \
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r96142 r96215  
    6867968679                        </File>
    6868068680                        <File
     68681                                RelativePath="..\inspector\ContentSearchUtils.cpp"
     68682                                >
     68683                        </File>
     68684                        <File
     68685                                RelativePath="..\inspector\ContentSearchUtils.h"
     68686                                >
     68687                        </File>
     68688                        <File
    6868168689                                RelativePath="..\inspector\DOMNodeHighlighter.cpp"
    6868268690                                >
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r96163 r96215  
    15051505                590E1B4911E4EF4B0069F784 /* DeviceOrientation.h in Headers */ = {isa = PBXBuildFile; fileRef = 590E1B4811E4EF4B0069F784 /* DeviceOrientation.h */; settings = {ATTRIBUTES = (Private, ); }; };
    15061506                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 */; };
    15071509                5913A24113D49EBA00F5B05C /* IdentifiersFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5913A23F13D49EBA00F5B05C /* IdentifiersFactory.cpp */; };
    15081510                5913A24213D49EBA00F5B05C /* IdentifiersFactory.h in Headers */ = {isa = PBXBuildFile; fileRef = 5913A24013D49EBA00F5B05C /* IdentifiersFactory.h */; };
     
    81728174                590E1B4811E4EF4B0069F784 /* DeviceOrientation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeviceOrientation.h; sourceTree = "<group>"; };
    81738175                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>"; };
    81748178                5913A23F13D49EBA00F5B05C /* IdentifiersFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IdentifiersFactory.cpp; sourceTree = "<group>"; };
    81758179                5913A24013D49EBA00F5B05C /* IdentifiersFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IdentifiersFactory.h; sourceTree = "<group>"; };
     
    1361913623                                41F0618D0F5F069800A07EAC /* ConsoleMessage.cpp */,
    1362013624                                41F0618C0F5F069800A07EAC /* ConsoleMessage.h */,
     13625                                59102FB914327D3B003C9D04 /* ContentSearchUtils.cpp */,
     13626                                59102FBA14327D3B003C9D04 /* ContentSearchUtils.h */,
    1362113627                                4F1442261339FD6200E0D6F8 /* DOMNodeHighlighter.cpp */,
    1362213628                                4F1442271339FD6200E0D6F8 /* DOMNodeHighlighter.h */,
     
    2353823544                                CECCFC3B141973D5002A0AC1 /* DecodeEscapeSequences.h in Headers */,
    2353923545                                0FE71406142170B800DB33BA /* ScrollbarThemeMock.h in Headers */,
     23546                                59102FBC14327D3B003C9D04 /* ContentSearchUtils.h in Headers */,
    2354023547                        );
    2354123548                        runOnlyForDeploymentPostprocessing = 0;
     
    2637726384                                319AE063142D6B24006563A1 /* StyleFilterData.cpp in Sources */,
    2637826385                                319AE069142D78DD006563A1 /* FilterOperations.cpp in Sources */,
     26386                                59102FBB14327D3B003C9D04 /* ContentSearchUtils.cpp in Sources */,
    2637926387                        );
    2638026388                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/WebCore/inspector/InspectorPageAgent.cpp

    r95901 r96215  
    4040#include "CachedResourceLoader.h"
    4141#include "CachedScript.h"
     42#include "ContentSearchUtils.h"
    4243#include "Cookie.h"
    4344#include "CookieJar.h"
     
    6970namespace WebCore {
    7071
    71 namespace {
    72 // This should be kept the same as the one in front-end/utilities.js
    73 static const char regexSpecialCharacters[] = "[](){}+-*.,?\\^$|";
    74 }
    75 
    7672namespace PageAgentState {
    7773static const char pageAgentEnabled[] = "resourceAgentEnabled";
     
    116112}
    117113
     114static bool hasTextContent(CachedResource* cachedResource)
     115{
     116    InspectorPageAgent::ResourceType type = InspectorPageAgent::cachedResourceType(*cachedResource);
     117    return type == InspectorPageAgent::StylesheetResource || type == InspectorPageAgent::ScriptResource;
     118}
     119
    118120bool InspectorPageAgent::cachedResourceContent(CachedResource* cachedResource, String* result, bool* base64Encoded)
    119121{
     
    123125        return false;
    124126
    125     ResourceType type = cachedResourceType(*cachedResource);
    126     *base64Encoded = type != StylesheetResource && type != ScriptResource;
    127 
     127    *base64Encoded = !hasTextContent(cachedResource);
    128128    if (*base64Encoded) {
    129129        RefPtr<SharedBuffer> buffer = hasZeroSize ? SharedBuffer::create() : cachedResource->data();
     
    470470}
    471471
    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)
     472static 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
     485static PassRefPtr<InspectorObject> buildObjectForSearchResult(const String& frameId, const String& url, int matchesCount)
    504486{
    505487    RefPtr<InspectorObject> result = InspectorObject::create();
     
    516498
    517499    bool isRegex = optionalIsRegex ? *optionalIsRegex : false;
    518     String regexSource = isRegex ? text : createSearchRegexSource(text);
    519 
    520500    bool caseSensitive = optionalCaseSensitive ? *optionalCaseSensitive : false;
    521     RegularExpression regex(regexSource, caseSensitive ? TextCaseSensitive : TextCaseInsensitive);
     501    RegularExpression regex = ContentSearchUtils::createSearchRegex(text, caseSensitive, isRegex);
    522502
    523503    for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext(m_page->mainFrame())) {
    524504        String content;
    525         bool base64Encoded;
    526505        Vector<CachedResource*> allResources = cachedResourcesForFrame(frame);
    527506        for (Vector<CachedResource*>::const_iterator it = allResources.begin(); it != allResources.end(); ++it) {
    528507            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));
    541512            }
    542513        }
    543514        if (mainResourceContent(frame, false, &content)) {
    544             int matchesCount = countRegularExpressionMatches(regex, content);
     515            int matchesCount = ContentSearchUtils::countRegularExpressionMatches(regex, content);
    545516            if (matchesCount)
    546                 result->pushValue(buildObjectForSearchMatch(frameId(frame), frame->document()->url(), matchesCount));
     517                result->pushValue(buildObjectForSearchResult(frameId(frame), frame->document()->url(), matchesCount));
    547518        }
    548519    }
  • trunk/Source/WebCore/inspector/front-end/utilities.js

    r95401 r96215  
    962962function createSearchRegex(query, extraFlags)
    963963{
    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.
    965965    var regexSpecialCharacters = "[](){}+-*.,?\\^$|";
    966966    var regex = "";
Note: See TracChangeset for help on using the changeset viewer.