Changeset 96491 in webkit


Ignore:
Timestamp:
Oct 3, 2011 5:56:52 AM (13 years ago)
Author:
vsevik@chromium.org
Message:

Web Inspector: Add support for backend search in script content.
https://bugs.webkit.org/show_bug.cgi?id=69015

Reviewed by Pavel Feldman.

Source/WebCore:

Tests: http/tests/inspector/search/search-in-concatenated-script.html

http/tests/inspector/search/search-in-script.html

  • inspector/Inspector.json:
  • inspector/InspectorDebuggerAgent.cpp:

(WebCore::InspectorDebuggerAgent::searchInContent):
(WebCore::InspectorDebuggerAgent::getScriptSource):

  • inspector/InspectorDebuggerAgent.h:
  • inspector/front-end/ContentProviders.js:

(WebInspector.ScriptContentProvider.prototype.requestContent):
(WebInspector.ScriptContentProvider.prototype.searchInContent):
(WebInspector.ConcatenatedScriptsContentProvider.prototype.searchInContent.maybeCallback):
(WebInspector.ConcatenatedScriptsContentProvider.prototype.searchInContent.searchCallback):
(WebInspector.ConcatenatedScriptsContentProvider.prototype.searchInContent):

  • inspector/front-end/Script.js:

(WebInspector.Script.prototype.requestSource):
(WebInspector.Script.prototype.searchInContent):

LayoutTests:

  • http/tests/inspector/resource-tree/resource-tree-test.js:

(initialize_ResourceTreeTest):

  • http/tests/inspector/resources-test.js:

(initialize_ResourceTest.InspectorTest.runAfterResourcesAreFinished):
(initialize_ResourceTest.InspectorTest._runAfterResourcesAreFinished):
(initialize_ResourceTest.InspectorTest._runAfterResourcesAreFinished.maybeCallback):
(initialize_ResourceTest.InspectorTest._runAfterResourcesAreFinished.addSniffer):
(initialize_ResourceTest.InspectorTest._runAfterResourcesAreFinished.resourceAddedToFrame):
(initialize_ResourceTest.InspectorTest._runAfterResourcesAreFinished.visit):
(initialize_ResourceTest):

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

(initialize_SearchTest):

Location:
trunk
Files:
5 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r96486 r96491  
     12011-10-03  Vsevolod Vlasov  <vsevik@chromium.org>
     2
     3        Web Inspector: Add support for backend search in script content.
     4        https://bugs.webkit.org/show_bug.cgi?id=69015
     5
     6        Reviewed by Pavel Feldman.
     7
     8        * http/tests/inspector/resource-tree/resource-tree-test.js:
     9        (initialize_ResourceTreeTest):
     10        * http/tests/inspector/resources-test.js:
     11        (initialize_ResourceTest.InspectorTest.runAfterResourcesAreFinished):
     12        (initialize_ResourceTest.InspectorTest._runAfterResourcesAreFinished):
     13        (initialize_ResourceTest.InspectorTest._runAfterResourcesAreFinished.maybeCallback):
     14        (initialize_ResourceTest.InspectorTest._runAfterResourcesAreFinished.addSniffer):
     15        (initialize_ResourceTest.InspectorTest._runAfterResourcesAreFinished.resourceAddedToFrame):
     16        (initialize_ResourceTest.InspectorTest._runAfterResourcesAreFinished.visit):
     17        (initialize_ResourceTest):
     18        * http/tests/inspector/search/resources/search-concatenated.html: Added.
     19        * http/tests/inspector/search/search-in-concatenated-script-expected.txt: Added.
     20        * http/tests/inspector/search/search-in-concatenated-script.html: Added.
     21        * http/tests/inspector/search/search-in-resource.html:
     22        * http/tests/inspector/search/search-in-script-expected.txt: Added.
     23        * http/tests/inspector/search/search-in-script.html: Added.
     24        * http/tests/inspector/search/search-test.js:
     25        (initialize_SearchTest):
     26
    1272011-10-03  Kristóf Kosztyó  <kkristof@inf.u-szeged.hu>
    228
  • trunk/LayoutTests/http/tests/inspector/resource-tree/resource-tree-test.js

    r95287 r96491  
    8787}
    8888
    89 InspectorTest.runAfterResourcesAreFinished = function(resourceURLs, callback)
    90 {
    91     InspectorTest._runAfterResourcesAreFinished(resourceURLs.keySet(), callback);
    92 }
    93 
    94 InspectorTest._runAfterResourcesAreFinished = function(resourceURLs, callback)
    95 {
    96     function visit(resource)
    97     {
    98         if (!resource.finished)
    99             return true;
    100 
    101         for (var url in resourceURLs) {
    102             if (resource.url.indexOf(url) !== -1)
    103                 delete resourceURLs[url];
    104         }
    105 
    106         if (!Object.keys(resourceURLs).length) {
    107             callback();
    108             return true;
    109         }
    110     }
    111 
    112     var succeeded = WebInspector.resourceTreeModel.forAllResources(visit);
    113     if (!succeeded)
    114         setTimeout(InspectorTest._runAfterResourcesAreFinished.bind(InspectorTest, resourceURLs, callback), 0);
    115 }
    116 
    11789};
  • trunk/LayoutTests/http/tests/inspector/resources-test.js

    r90010 r96491  
    2828}
    2929
     30InspectorTest.runAfterResourcesAreFinished = function(resourceURLs, callback)
     31{
     32    InspectorTest._runAfterResourcesAreFinished(resourceURLs.keySet(), callback);
    3033}
     34
     35InspectorTest._runAfterResourcesAreFinished = function(resourceURLs, callback)
     36{
     37    function checkResource(resource)
     38    {
     39        for (var url in resourceURLs) {
     40            if (resource.url.indexOf(url) !== -1)
     41                delete resourceURLs[url];
     42        }
     43    }
     44
     45    function maybeCallback()
     46    {
     47        if (!Object.keys(resourceURLs).length) {
     48            callback();
     49            return true;
     50        }
     51    }
     52
     53    function addSniffer(resource)
     54    {
     55        InspectorTest.addSniffer(WebInspector.ResourceTreeModel.prototype, "_addResourceToFrame", resourceAddedToFrame.bind(this));
     56    }
     57
     58    function resourceAddedToFrame(resource)
     59    {
     60        checkResource(resource);
     61        if (!maybeCallback())
     62            addSniffer();
     63    }
     64
     65    function visit(resource)
     66    {
     67        checkResource(resource);
     68        return maybeCallback();
     69    }
     70
     71    var succeeded = WebInspector.resourceTreeModel.forAllResources(visit);
     72    if (!succeeded)
     73        addSniffer();
     74}
     75
     76}
  • trunk/LayoutTests/http/tests/inspector/search/search-in-resource.html

    r96323 r96491  
    22<head>
    33<script src="../inspector-test.js"></script>
     4<script src="../resources-test.js"></script>
    45<script src="search-test.js"></script>
    56<script>
     
    89    // This file should not match search query.
    910    var text = "searchTest" + "UniqueString";
    10     InspectorTest.runAfterResourcesAreCreated(["search.js"], step2);
     11    InspectorTest.runAfterResourcesAreFinished(["search.js"], step2);
    1112
    1213    function step2()
  • trunk/LayoutTests/http/tests/inspector/search/search-test.js

    r96323 r96491  
    1717};
    1818
    19 InspectorTest.runAfterResourcesAreCreated = function(resourceURLs, callback)
    20 {
    21     InspectorTest._runAfterResourcesAreCreated(resourceURLs.keySet(), callback);
    22 }
    23 
    24 InspectorTest._runAfterResourcesAreCreated = function(resourceURLs, callback)
    25 {
    26     function checkResource(resource)
    27     {
    28         for (var url in resourceURLs) {
    29             if (resource.url.indexOf(url) !== -1)
    30                 delete resourceURLs[url];
    31         }
    32     }
    33 
    34     function maybeCallback()
    35     {
    36         if (!Object.keys(resourceURLs).length) {
    37             callback();
    38             return true;
    39         }
    40     }
    41 
    42     function addSniffer(resource)
    43     {
    44         InspectorTest.addSniffer(WebInspector.ResourceTreeModel.prototype, "_bindResourceURL", onResourceBind.bind(this));
    45     }
    46 
    47     function onResourceBind(resource)
    48     {
    49         checkResource(resource);
    50         if (!maybeCallback())
    51             addSniffer();
    52     }
    53 
    54     function visit(resource)
    55     {
    56         checkResource(resource);
    57         return maybeCallback();
    58     }
    59 
    60     var succeeded = WebInspector.resourceTreeModel.forAllResources(visit);
    61     if (!succeeded)
    62         addSniffer();
    63 }
    64 
    6519};
  • trunk/Source/WebCore/ChangeLog

    r96487 r96491  
     12011-10-03  Vsevolod Vlasov  <vsevik@chromium.org>
     2
     3        Web Inspector: Add support for backend search in script content.
     4        https://bugs.webkit.org/show_bug.cgi?id=69015
     5
     6        Reviewed by Pavel Feldman.
     7
     8        Tests: http/tests/inspector/search/search-in-concatenated-script.html
     9               http/tests/inspector/search/search-in-script.html
     10
     11        * inspector/Inspector.json:
     12        * inspector/InspectorDebuggerAgent.cpp:
     13        (WebCore::InspectorDebuggerAgent::searchInContent):
     14        (WebCore::InspectorDebuggerAgent::getScriptSource):
     15        * inspector/InspectorDebuggerAgent.h:
     16        * inspector/front-end/ContentProviders.js:
     17        (WebInspector.ScriptContentProvider.prototype.requestContent):
     18        (WebInspector.ScriptContentProvider.prototype.searchInContent):
     19        (WebInspector.ConcatenatedScriptsContentProvider.prototype.searchInContent.maybeCallback):
     20        (WebInspector.ConcatenatedScriptsContentProvider.prototype.searchInContent.searchCallback):
     21        (WebInspector.ConcatenatedScriptsContentProvider.prototype.searchInContent):
     22        * inspector/front-end/Script.js:
     23        (WebInspector.Script.prototype.requestSource):
     24        (WebInspector.Script.prototype.searchInContent):
     25
    1262011-10-03  Pavel Feldman  <pfeldman@google.com>
    227
  • trunk/Source/WebCore/inspector/Inspector.json

    r96485 r96491  
    17431743            },
    17441744            {
     1745                "name": "searchInContent",
     1746                "parameters": [
     1747                    { "name": "scriptId", "$ref": "ScriptId", "description": "Id of the script to search in." },
     1748                    { "name": "query", "type": "string", "description": "String to search for."  }
     1749                ],
     1750                "returns": [
     1751                    { "name": "result", "type": "array", "items": { "$ref": "Page.SearchMatch" }, "description": "List of search matches." }
     1752                ],
     1753                "description": "Searches for given string in script content."
     1754            },
     1755            {
    17451756                "name": "setScriptSource",
    17461757                "parameters": [
  • trunk/Source/WebCore/inspector/InspectorDebuggerAgent.cpp

    r96227 r96491  
    3232
    3333#if ENABLE(JAVASCRIPT_DEBUGGER) && ENABLE(INSPECTOR)
     34#include "ContentSearchUtils.h"
    3435#include "InjectedScript.h"
    3536#include "InjectedScriptManager.h"
     
    321322}
    322323
     324void InspectorDebuggerAgent::searchInContent(ErrorString* error, const String& scriptId, const String& query, RefPtr<InspectorArray>* results)
     325{
     326    ScriptsMap::iterator it = m_scripts.find(scriptId);
     327    if (it != m_scripts.end())
     328        *results = ContentSearchUtils::searchInTextByLines(query, it->second.source);
     329    else
     330        *error = "No script for id: " + scriptId;
     331}
     332
    323333void InspectorDebuggerAgent::setScriptSource(ErrorString* error, const String& scriptId, const String& newContent, const bool* const preview, RefPtr<InspectorArray>* newCallFrames, RefPtr<InspectorObject>* result)
    324334{
     
    333343}
    334344
    335 void InspectorDebuggerAgent::getScriptSource(ErrorString*, const String& scriptId, String* scriptSource)
    336 {
    337     *scriptSource = m_scripts.get(scriptId).source;
     345void InspectorDebuggerAgent::getScriptSource(ErrorString* error, const String& scriptId, String* scriptSource)
     346{
     347    ScriptsMap::iterator it = m_scripts.find(scriptId);
     348    if (it != m_scripts.end())
     349        *scriptSource = it->second.source;
     350    else
     351        *error = "No script for id: " + scriptId;
    338352}
    339353
  • trunk/Source/WebCore/inspector/InspectorDebuggerAgent.h

    r95901 r96491  
    8282    void continueToLocation(ErrorString*, PassRefPtr<InspectorObject> location);
    8383
     84    void searchInContent(ErrorString*, const String& scriptId, const String& query, RefPtr<InspectorArray>*);
    8485    void setScriptSource(ErrorString*, const String& scriptId, const String& newContent, const bool* const preview, RefPtr<InspectorArray>* newCallFrames, RefPtr<InspectorObject>* result);
    8586    void getScriptSource(ErrorString*, const String& scriptId, String* scriptSource);
  • trunk/Source/WebCore/inspector/front-end/ContentProviders.js

    r96313 r96491  
    4747        }
    4848        this._script.requestSource(didRequestSource.bind(this));
     49    },
     50
     51    searchInContent: function(query, callback)
     52    {
     53        this._script.searchInContent(query, callback);
    4954    }
    5055}
     
    7681       for (var i = 0; i < scripts.length; ++i)
    7782           scripts[i].requestSource(didRequestSource.bind(this));
     83   },
     84
     85   searchInContent: function(query, callback)
     86   {
     87       var results = {};
     88       var scriptsLeft = this._scripts.length;
     89
     90       function maybeCallback()
     91       {
     92           if (!scriptsLeft) {
     93               var result = [];
     94               for (var i = 0; i < this._scripts.length; ++i)
     95                   result = result.concat(results[this._scripts[i].scriptId]);
     96               callback(result);
     97           }
     98       }
     99
     100       function searchCallback(script, searchMatches)
     101       {
     102           results[script.scriptId] = [];
     103           for (var i = 0; i < searchMatches.length; ++i) {
     104               var searchMatch = {};
     105               searchMatch.lineNumber = searchMatches[i].lineNumber + script.lineOffset;
     106               searchMatch.lineContent = searchMatches[i].lineContent;
     107               results[script.scriptId].push(searchMatch);
     108           }
     109           scriptsLeft--;
     110           maybeCallback.call(this);
     111       }
     112
     113       maybeCallback();
     114       for (var i = 0; i < this._scripts.length; ++i)
     115           this._scripts[i].searchInContent(query, searchCallback.bind(this, this._scripts[i]));
    78116   },
    79117
  • trunk/Source/WebCore/inspector/front-end/Script.js

    r93701 r96491  
    5050        function didGetScriptSource(error, source)
    5151        {
     52            if (error)
     53                console.error(error);
    5254            this._source = source;
    5355            callback(this._source);
     
    5658    },
    5759
     60    searchInContent: function(query, callback)
     61    {
     62        function innerCallback(error, searchMatches)
     63        {
     64            if (error)
     65                console.error(error);
     66            callback(searchMatches);
     67        }
     68       
     69        DebuggerAgent.searchInContent(this.scriptId, query, innerCallback.bind(this));
     70    },
     71   
    5872    editSource: function(newSource, callback)
    5973    {
Note: See TracChangeset for help on using the changeset viewer.