Title: [96703] trunk
Revision
96703
Author
[email protected]
Date
2011-10-05 07:30:29 -0700 (Wed, 05 Oct 2011)

Log Message

Web Inspector: Add support for 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.searchInContent):
(WebInspector.ConcatenatedScriptsContentProvider.prototype._sortedScripts.var):
(WebInspector.ConcatenatedScriptsContentProvider.prototype._sortedScripts):
(WebInspector.ConcatenatedScriptsContentProvider.prototype.requestContent):
(WebInspector.ConcatenatedScriptsContentProvider.prototype.searchInContent.maybeCallback):
(WebInspector.ConcatenatedScriptsContentProvider.prototype.searchInContent.searchCallback):
(WebInspector.ConcatenatedScriptsContentProvider.prototype.searchInContent):
(WebInspector.ConcatenatedScriptsContentProvider.prototype._concatenateScriptsContent):
* inspector/front-end/Script.js:
(WebInspector.Script.prototype.requestSource.didGetScriptSource):
(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):
* inspector/debugger/content-providers.html:
* platform/qt/Skipped:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (96702 => 96703)


--- trunk/LayoutTests/ChangeLog	2011-10-05 14:20:22 UTC (rev 96702)
+++ trunk/LayoutTests/ChangeLog	2011-10-05 14:30:29 UTC (rev 96703)
@@ -1,3 +1,31 @@
+2011-10-05  Vsevolod Vlasov  <[email protected]>
+
+        Web Inspector: Add support for search in script content.
+        https://bugs.webkit.org/show_bug.cgi?id=69015
+
+        Reviewed by Pavel Feldman.
+
+        * 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):
+        * inspector/debugger/content-providers.html:
+        * platform/qt/Skipped:
+
 2011-10-05  Balazs Kelemen  <[email protected]>
 
         [Qt][WK2] Try to paint the bot green.

Modified: trunk/LayoutTests/http/tests/inspector/resource-tree/resource-tree-test.js (96702 => 96703)


--- trunk/LayoutTests/http/tests/inspector/resource-tree/resource-tree-test.js	2011-10-05 14:20:22 UTC (rev 96702)
+++ trunk/LayoutTests/http/tests/inspector/resource-tree/resource-tree-test.js	2011-10-05 14:30:29 UTC (rev 96703)
@@ -86,32 +86,4 @@
     InspectorTest.dumpResourcesTree();
 }
 
-InspectorTest.runAfterResourcesAreFinished = function(resourceURLs, callback)
-{
-    InspectorTest._runAfterResourcesAreFinished(resourceURLs.keySet(), callback);
-}
-
-InspectorTest._runAfterResourcesAreFinished = function(resourceURLs, callback)
-{
-    function visit(resource)
-    {
-        if (!resource.finished)
-            return true;
-
-        for (var url in resourceURLs) {
-            if (resource.url.indexOf(url) !== -1)
-                delete resourceURLs[url];
-        }
-
-        if (!Object.keys(resourceURLs).length) {
-            callback();
-            return true;
-        }
-    }
-
-    var succeeded = WebInspector.resourceTreeModel.forAllResources(visit);
-    if (!succeeded)
-        setTimeout(InspectorTest._runAfterResourcesAreFinished.bind(InspectorTest, resourceURLs, callback), 0);
-}
-
 };

Modified: trunk/LayoutTests/http/tests/inspector/resources-test.js (96702 => 96703)


--- trunk/LayoutTests/http/tests/inspector/resources-test.js	2011-10-05 14:20:22 UTC (rev 96702)
+++ trunk/LayoutTests/http/tests/inspector/resources-test.js	2011-10-05 14:30:29 UTC (rev 96703)
@@ -27,4 +27,50 @@
     return r1.request.url.localeCompare(r2.request.url);
 }
 
+InspectorTest.runAfterResourcesAreFinished = function(resourceURLs, callback)
+{
+    InspectorTest._runAfterResourcesAreFinished(resourceURLs.keySet(), callback);
 }
+
+InspectorTest._runAfterResourcesAreFinished = function(resourceURLs, callback)
+{
+    function checkResource(resource)
+    {
+        for (var url in resourceURLs) {
+            if (resource.url.indexOf(url) !== -1)
+                delete resourceURLs[url];
+        }
+    }
+
+    function maybeCallback()
+    {
+        if (!Object.keys(resourceURLs).length) {
+            callback();
+            return true;
+        }
+    }
+
+    function addSniffer(resource)
+    {
+        InspectorTest.addSniffer(WebInspector.ResourceTreeModel.prototype, "_addResourceToFrame", resourceAddedToFrame.bind(this));
+    }
+
+    function resourceAddedToFrame(resource)
+    {
+        checkResource(resource);
+        if (!maybeCallback())
+            addSniffer();
+    }
+
+    function visit(resource)
+    {
+        checkResource(resource);
+        return maybeCallback();
+    }
+
+    var succeeded = WebInspector.resourceTreeModel.forAllResources(visit);
+    if (!succeeded)
+        addSniffer();
+}
+
+}

Added: trunk/LayoutTests/http/tests/inspector/search/resources/search-concatenated.html (0 => 96703)


--- trunk/LayoutTests/http/tests/inspector/search/resources/search-concatenated.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/search/resources/search-concatenated.html	2011-10-05 14:30:29 UTC (rev 96703)
@@ -0,0 +1,30 @@
+<html>
+<head>
+<script>
+function searchTestUniqueString()
+{
+    var variable = 0;
+    // searchTestUniqueString two occurences on the same line searchTestUniqueString
+    var variable2 = 0;
+}
+</script><script>
+function doSomething()
+{
+    searchTestUniqueString();
+    // SEARCHTestUniqueString();
+}
+</script>
+<link href="" rel="stylesheet" type="text/css">
+<script>
+function searchTestUniqueString2()
+{
+    var variable = 0;
+    /* searchTestUniqueString two occurences on the same line searchTestUniqueString */ } </script><script> function doSomething2() { searchTestUniqueString();
+    // SEARCHTestUniqueString();
+}
+</script>
+</script>
+<body>
+</body>
+</html>
+
Property changes on: trunk/LayoutTests/http/tests/inspector/search/resources/search-concatenated.html
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/http/tests/inspector/search/search-in-concatenated-script-expected.txt (0 => 96703)


--- trunk/LayoutTests/http/tests/inspector/search/search-in-concatenated-script-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/search/search-in-concatenated-script-expected.txt	2011-10-05 14:30:29 UTC (rev 96703)
@@ -0,0 +1,17 @@
+Tests concatenated script search in inspector debugger agent.
+
+Bug 69015  
+Debugger was enabled.
+http://127.0.0.1:8000/inspector/search/resources/search-concatenated.html
+Search matches: 
+lineNumber: 3, line: 'function searchTestUniqueString()'
+lineNumber: 6, line: '    // searchTestUniqueString two occurences on the same line searchTestUniqueString'
+lineNumber: 12, line: '    searchTestUniqueString();'
+lineNumber: 13, line: '    // SEARCHTestUniqueString();'
+lineNumber: 18, line: 'function searchTestUniqueString2()'
+lineNumber: 21, line: '    /* searchTestUniqueString two occurences on the same line searchTestUniqueString */ } '
+lineNumber: 21, line: ' function doSomething2() { searchTestUniqueString();'
+lineNumber: 22, line: '    // SEARCHTestUniqueString();'
+
+Debugger was disabled.
+
Property changes on: trunk/LayoutTests/http/tests/inspector/search/search-in-concatenated-script-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/http/tests/inspector/search/search-in-concatenated-script.html (0 => 96703)


--- trunk/LayoutTests/http/tests/inspector/search/search-in-concatenated-script.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/search/search-in-concatenated-script.html	2011-10-05 14:30:29 UTC (rev 96703)
@@ -0,0 +1,47 @@
+<html>
+<head>
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+<script>
+function test()
+{
+    // This file should not match search query.
+    var text = "searchTest" + "UniqueString";
+    InspectorTest.startDebuggerTest(step1);
+
+    function step1()
+    {
+        InspectorTest.runAfterResourcesAreFinished(["search-concatenated.html"], step2);
+    }
+
+    function step2()
+    {
+        InspectorTest.showScriptSource("search-concatenated.html", step3);
+    }
+
+    function step3()
+    {
+        var url = ""
+        var scripts = WebInspector.debuggerModel.scriptsForURL(url);
+        var contentProvider = new WebInspector.ConcatenatedScriptsContentProvider(scripts);
+        InspectorTest.addResult(url);
+        contentProvider.searchInContent(text, step4);
+    }
+
+    function step4(searchMatches)
+    {
+        InspectorTest.dumpSearchMatches(searchMatches);
+        InspectorTest.completeDebuggerTest();
+    }
+}
+</script>
+</head>
+<body>
+<p>Tests concatenated script search in inspector debugger agent.</p>
+<a href="" 69015</a>
+
+<iframe src="" _onload_="runTest()">
+</body>
+</html>
Property changes on: trunk/LayoutTests/http/tests/inspector/search/search-in-concatenated-script.html
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/LayoutTests/http/tests/inspector/search/search-in-resource.html (96702 => 96703)


--- trunk/LayoutTests/http/tests/inspector/search/search-in-resource.html	2011-10-05 14:20:22 UTC (rev 96702)
+++ trunk/LayoutTests/http/tests/inspector/search/search-in-resource.html	2011-10-05 14:30:29 UTC (rev 96703)
@@ -1,13 +1,14 @@
 <html>
 <head>
 <script src=""
+<script src=""
 <script src=""
 <script>
 function test()
 {
     // This file should not match search query.
     var text = "searchTest" + "UniqueString";
-    InspectorTest.runAfterResourcesAreCreated(["search.js"], step2);
+    InspectorTest.runAfterResourcesAreFinished(["search.js"], step2);
 
     function step2()
     {

Added: trunk/LayoutTests/http/tests/inspector/search/search-in-script-expected.txt (0 => 96703)


--- trunk/LayoutTests/http/tests/inspector/search/search-in-script-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/search/search-in-script-expected.txt	2011-10-05 14:30:29 UTC (rev 96703)
@@ -0,0 +1,13 @@
+Tests script search in inspector debugger agent.
+
+Bug 69015  
+Debugger was enabled.
+http://127.0.0.1:8000/inspector/search/resources/search.js
+Search matches: 
+lineNumber: 0, line: 'function searchTestUniqueString()'
+lineNumber: 3, line: '    // searchTestUniqueString two occurences on the same line searchTestUniqueString'
+lineNumber: 9, line: '    searchTestUniqueString();'
+lineNumber: 10, line: '    // SEARCHTestUniqueString();'
+
+Debugger was disabled.
+
Property changes on: trunk/LayoutTests/http/tests/inspector/search/search-in-script-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/http/tests/inspector/search/search-in-script.html (0 => 96703)


--- trunk/LayoutTests/http/tests/inspector/search/search-in-script.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/search/search-in-script.html	2011-10-05 14:30:29 UTC (rev 96703)
@@ -0,0 +1,46 @@
+<html>
+<head>
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+<script>
+function test()
+{
+    // This file should not match search query.
+    var text = "searchTest" + "UniqueString";
+    InspectorTest.startDebuggerTest(step1);
+
+    function step1()
+    {
+        InspectorTest.runAfterResourcesAreFinished(["search.js"], step2);
+    }
+
+    function step2()
+    {
+        InspectorTest.showScriptSource("search.js", step3);
+    }
+
+    function step3()
+    {
+        var scripts = WebInspector.debuggerModel.scriptsForURL("http://127.0.0.1:8000/inspector/search/resources/search.js");
+        var script = scripts[0];
+        InspectorTest.addResult(script.sourceURL);
+        script.searchInContent(text, step4);
+    }
+
+    function step4(searchMatches)
+    {
+        InspectorTest.dumpSearchMatches(searchMatches);
+        InspectorTest.completeDebuggerTest();
+    }
+}
+</script>
+</head>
+<body>
+<p>Tests script search in inspector debugger agent.</p>
+<a href="" 69015</a>
+
+<iframe src="" _onload_="runTest()">
+</body>
+</html>
Property changes on: trunk/LayoutTests/http/tests/inspector/search/search-in-script.html
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/LayoutTests/http/tests/inspector/search/search-test.js (96702 => 96703)


--- trunk/LayoutTests/http/tests/inspector/search/search-test.js	2011-10-05 14:20:22 UTC (rev 96702)
+++ trunk/LayoutTests/http/tests/inspector/search/search-test.js	2011-10-05 14:30:29 UTC (rev 96703)
@@ -16,50 +16,4 @@
     InspectorTest.addResult("");
 };
 
-InspectorTest.runAfterResourcesAreCreated = function(resourceURLs, callback)
-{
-    InspectorTest._runAfterResourcesAreCreated(resourceURLs.keySet(), callback);
-}
-
-InspectorTest._runAfterResourcesAreCreated = function(resourceURLs, callback)
-{
-    function checkResource(resource)
-    {
-        for (var url in resourceURLs) {
-            if (resource.url.indexOf(url) !== -1)
-                delete resourceURLs[url];
-        }
-    }
-
-    function maybeCallback()
-    {
-        if (!Object.keys(resourceURLs).length) {
-            callback();
-            return true;
-        }
-    }
-
-    function addSniffer(resource)
-    {
-        InspectorTest.addSniffer(WebInspector.ResourceTreeModel.prototype, "_bindResourceURL", onResourceBind.bind(this));
-    }
-
-    function onResourceBind(resource)
-    {
-        checkResource(resource);
-        if (!maybeCallback())
-            addSniffer();
-    }
-
-    function visit(resource)
-    {
-        checkResource(resource);
-        return maybeCallback();
-    }
-
-    var succeeded = WebInspector.resourceTreeModel.forAllResources(visit);
-    if (!succeeded)
-        addSniffer();
-}
-
 };

Modified: trunk/LayoutTests/inspector/debugger/content-providers.html (96702 => 96703)


--- trunk/LayoutTests/inspector/debugger/content-providers.html	2011-10-05 14:20:22 UTC (rev 96702)
+++ trunk/LayoutTests/inspector/debugger/content-providers.html	2011-10-05 14:30:29 UTC (rev 96703)
@@ -15,7 +15,9 @@
                 callback(source);
             },
             get lineOffset() { return range[0]; },
-            get columnOffset() { return range[1]; }
+            get columnOffset() { return range[1]; },
+            get endLine() { return range[2]; },
+            get endColumn() { return range[3]; }
         };
     }
 
@@ -37,10 +39,10 @@
         function testConcatenatedScriptsContentProvider(next)
         {
             var scripts = [];
-            scripts.push(createMockScript("1", "\nfunction baz()\n{\n  return 0;\n}\n", [3, 20]));
-            scripts.push(createMockScript("2", "function foo() { return 0; }", [0, 10]));
-            scripts.push(createMockScript("3", "function bar() { return 0; }", [1, 70]));
-            scripts.push(createMockScript("4", "this should not appear in displayed content", [0, 20]));
+            scripts.push(createMockScript("1", "\nfunction baz()\n{\n  return 0;\n}\n", [3, 20, 7, 0]));
+            scripts.push(createMockScript("2", "function foo() { return 0; }", [0, 10, 0, 38]));
+            scripts.push(createMockScript("3", "function bar() { return 0; }", [1, 70, 1, 98]));
+            scripts.push(createMockScript("4", "this should not appear in displayed content", [0, 20, 0, 63]));
             var contentProvider = new WebInspector.ConcatenatedScriptsContentProvider(scripts);
             function didRequestContent(mimeType, content)
             {

Modified: trunk/LayoutTests/platform/qt/Skipped (96702 => 96703)


--- trunk/LayoutTests/platform/qt/Skipped	2011-10-05 14:20:22 UTC (rev 96702)
+++ trunk/LayoutTests/platform/qt/Skipped	2011-10-05 14:30:29 UTC (rev 96703)
@@ -2397,9 +2397,3 @@
 # One test failed after r96260
 # https://bugs.webkit.org/show_bug.cgi?id=69257
 inspector/styles/styles-disable-then-change.html
-
-# [Qt] REGRESSION(r95526): It made 3 inspector tests fail
-# https://bugs.webkit.org/show_bug.cgi?id=69265
-http/tests/inspector/search/search-in-concatenated-script.html
-http/tests/inspector/search/search-in-script.html
-inspector/debugger/script-formatter.html

Modified: trunk/Source/WebCore/ChangeLog (96702 => 96703)


--- trunk/Source/WebCore/ChangeLog	2011-10-05 14:20:22 UTC (rev 96702)
+++ trunk/Source/WebCore/ChangeLog	2011-10-05 14:30:29 UTC (rev 96703)
@@ -1,3 +1,32 @@
+2011-10-05  Vsevolod Vlasov  <[email protected]>
+
+        Web Inspector: Add support for search in script content.
+        https://bugs.webkit.org/show_bug.cgi?id=69015
+
+        Reviewed by Pavel Feldman.
+
+        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.searchInContent):
+        (WebInspector.ConcatenatedScriptsContentProvider.prototype._sortedScripts.var):
+        (WebInspector.ConcatenatedScriptsContentProvider.prototype._sortedScripts):
+        (WebInspector.ConcatenatedScriptsContentProvider.prototype.requestContent):
+        (WebInspector.ConcatenatedScriptsContentProvider.prototype.searchInContent.maybeCallback):
+        (WebInspector.ConcatenatedScriptsContentProvider.prototype.searchInContent.searchCallback):
+        (WebInspector.ConcatenatedScriptsContentProvider.prototype.searchInContent):
+        (WebInspector.ConcatenatedScriptsContentProvider.prototype._concatenateScriptsContent):
+        * inspector/front-end/Script.js:
+        (WebInspector.Script.prototype.requestSource.didGetScriptSource):
+        (WebInspector.Script.prototype.requestSource):
+        (WebInspector.Script.prototype.searchInContent):
+
 2011-10-05  Alexis Menard  <[email protected]>
 
         [Qt][WK2] Default directories and paths are missing for LocalStorage, Database and IconDatabase.

Modified: trunk/Source/WebCore/inspector/Inspector.json (96702 => 96703)


--- trunk/Source/WebCore/inspector/Inspector.json	2011-10-05 14:20:22 UTC (rev 96702)
+++ trunk/Source/WebCore/inspector/Inspector.json	2011-10-05 14:30:29 UTC (rev 96703)
@@ -1772,6 +1772,17 @@
                 "description": "Resumes _javascript_ execution."
             },
             {
+                "name": "searchInContent",
+                "parameters": [
+                    { "name": "scriptId", "$ref": "ScriptId", "description": "Id of the script to search in." },
+                    { "name": "query", "type": "string", "description": "String to search for."  }
+                ],
+                "returns": [
+                    { "name": "result", "type": "array", "items": { "$ref": "Page.SearchMatch" }, "description": "List of search matches." }
+                ],
+                "description": "Searches for given string in script content."
+            },
+            {
                 "name": "setScriptSource",
                 "parameters": [
                     { "name": "scriptId", "$ref": "ScriptId", "description": "Id of the script to edit." },

Modified: trunk/Source/WebCore/inspector/InspectorDebuggerAgent.cpp (96702 => 96703)


--- trunk/Source/WebCore/inspector/InspectorDebuggerAgent.cpp	2011-10-05 14:20:22 UTC (rev 96702)
+++ trunk/Source/WebCore/inspector/InspectorDebuggerAgent.cpp	2011-10-05 14:30:29 UTC (rev 96703)
@@ -31,6 +31,7 @@
 #include "InspectorDebuggerAgent.h"
 
 #if ENABLE(_javascript__DEBUGGER) && ENABLE(INSPECTOR)
+#include "ContentSearchUtils.h"
 #include "InjectedScript.h"
 #include "InjectedScriptManager.h"
 #include "InspectorFrontend.h"
@@ -320,6 +321,15 @@
     return value->asObject();
 }
 
+void InspectorDebuggerAgent::searchInContent(ErrorString* error, const String& scriptId, const String& query, RefPtr<InspectorArray>* results)
+{
+    ScriptsMap::iterator it = m_scripts.find(scriptId);
+    if (it != m_scripts.end())
+        *results = ContentSearchUtils::searchInTextByLines(query, it->second.source);
+    else
+        *error = "No script for id: " + scriptId;
+}
+
 void InspectorDebuggerAgent::setScriptSource(ErrorString* error, const String& scriptId, const String& newContent, const bool* const preview, RefPtr<InspectorArray>* newCallFrames, RefPtr<InspectorObject>* result)
 {
     bool previewOnly = preview && *preview;
@@ -332,9 +342,13 @@
         *result = object;
 }
 
-void InspectorDebuggerAgent::getScriptSource(ErrorString*, const String& scriptId, String* scriptSource)
+void InspectorDebuggerAgent::getScriptSource(ErrorString* error, const String& scriptId, String* scriptSource)
 {
-    *scriptSource = m_scripts.get(scriptId).source;
+    ScriptsMap::iterator it = m_scripts.find(scriptId);
+    if (it != m_scripts.end())
+        *scriptSource = it->second.source;
+    else
+        *error = "No script for id: " + scriptId;
 }
 
 void InspectorDebuggerAgent::schedulePauseOnNextStatement(const String& breakReason, PassRefPtr<InspectorObject> data)

Modified: trunk/Source/WebCore/inspector/InspectorDebuggerAgent.h (96702 => 96703)


--- trunk/Source/WebCore/inspector/InspectorDebuggerAgent.h	2011-10-05 14:20:22 UTC (rev 96702)
+++ trunk/Source/WebCore/inspector/InspectorDebuggerAgent.h	2011-10-05 14:30:29 UTC (rev 96703)
@@ -81,6 +81,7 @@
     void removeBreakpoint(ErrorString*, const String& breakpointId);
     void continueToLocation(ErrorString*, PassRefPtr<InspectorObject> location);
 
+    void searchInContent(ErrorString*, const String& scriptId, const String& query, RefPtr<InspectorArray>*);
     void setScriptSource(ErrorString*, const String& scriptId, const String& newContent, const bool* const preview, RefPtr<InspectorArray>* newCallFrames, RefPtr<InspectorObject>* result);
     void getScriptSource(ErrorString*, const String& scriptId, String* scriptSource);
     void schedulePauseOnNextStatement(const String& breakReason, PassRefPtr<InspectorObject> data);

Modified: trunk/Source/WebCore/inspector/front-end/ContentProviders.js (96702 => 96703)


--- trunk/Source/WebCore/inspector/front-end/ContentProviders.js	2011-10-05 14:20:22 UTC (rev 96702)
+++ trunk/Source/WebCore/inspector/front-end/ContentProviders.js	2011-10-05 14:30:29 UTC (rev 96703)
@@ -50,7 +50,7 @@
 
     searchInContent: function(query, callback)
     {
-        callback([]);
+        this._script.searchInContent(query, callback);
     }
 }
 
@@ -66,66 +66,112 @@
     this._scripts = scripts;
 };
 
+WebInspector.ConcatenatedScriptsContentProvider.scriptOpenTag = "<script>";
+WebInspector.ConcatenatedScriptsContentProvider.scriptCloseTag = "</script>";
+
 WebInspector.ConcatenatedScriptsContentProvider.prototype = {
-   requestContent: function(callback)
-   {
-       var scripts = this._scripts.slice();
-       scripts.sort(function(x, y) { return x.lineOffset - y.lineOffset || x.columnOffset - y.columnOffset; });
-       var sources = [];
-       function didRequestSource(source)
-       {
-           sources.push(source);
-           if (sources.length == scripts.length)
-               callback(this._mimeType, this._concatenateScriptsContent(scripts, sources));
-       }
-       for (var i = 0; i < scripts.length; ++i)
-           scripts[i].requestSource(didRequestSource.bind(this));
-   },
+    _sortedScripts: function()
+    {
+        if (this._sortedScriptsArray)
+            return this._sortedScriptsArray;
 
-    searchInContent: function(query, callback)
+        this._sortedScriptsArray = [];
+        
+        var scripts = this._scripts.slice();
+        scripts.sort(function(x, y) { return x.lineOffset - y.lineOffset || x.columnOffset - y.columnOffset; });
+        
+        var scriptOpenTagLength = WebInspector.ConcatenatedScriptsContentProvider.scriptOpenTag.length;
+        var scriptCloseTagLength = WebInspector.ConcatenatedScriptsContentProvider.scriptCloseTag.length;
+        
+        this._sortedScriptsArray.push(scripts[0]);
+        for (var i = 1; i < scripts.length; ++i) {
+            var previousScript = this._sortedScriptsArray[this._sortedScriptsArray.length - 1];
+            
+            var lineNumber = previousScript.endLine;
+            var columnNumber = previousScript.endColumn + scriptCloseTagLength + scriptOpenTagLength;
+            
+            if (lineNumber < scripts[i].lineOffset || (lineNumber === scripts[i].lineOffset && columnNumber <= scripts[i].columnOffset))
+                this._sortedScriptsArray.push(scripts[i]);
+        }
+        return this._sortedScriptsArray;
+    },
+
+    requestContent: function(callback)
     {
-        callback([]);
+        var scripts = this._sortedScripts();
+        var sources = [];
+        function didRequestSource(source)
+        {
+            sources.push(source);
+            if (sources.length == scripts.length)
+                callback(this._mimeType, this._concatenateScriptsContent(scripts, sources));
+        }
+        for (var i = 0; i < scripts.length; ++i)
+            scripts[i].requestSource(didRequestSource.bind(this));
     },
 
-   _concatenateScriptsContent: function(scripts, sources)
-   {
-       var content = "";
-       var lineNumber = 0;
-       var columnNumber = 0;
+    searchInContent: function(query, callback)
+    {
+        var results = {};
+        var scripts = this._sortedScripts();
+        var scriptsLeft = scripts.length;
 
-       function appendChunk(chunk)
-       {
-           content += chunk;
-           var lineEndings = chunk.lineEndings();
-           var lineCount = lineEndings.length;
-           if (lineCount === 1)
-               columnNumber += chunk.length;
-           else {
-               lineNumber += lineCount - 1;
-               columnNumber = lineEndings[lineCount - 1] - lineEndings[lineCount - 2] - 1;
-           }
-       }
+        function maybeCallback()
+        {
+            if (scriptsLeft)
+                return;
 
-       var scriptOpenTag = "<script>";
-       var scriptCloseTag = "</script>";
-       for (var i = 0; i < scripts.length; ++i) {
-           if (lineNumber > scripts[i].lineOffset || (lineNumber === scripts[i].lineOffset && columnNumber > scripts[i].columnOffset - scriptOpenTag.length))
-               continue;
+            var result = [];
+            for (var i = 0; i < scripts.length; ++i)
+                result = result.concat(results[scripts[i].scriptId]);
+            callback(result);
+        }
 
-           // Fill the gap with whitespace characters.
-           while (lineNumber < scripts[i].lineOffset)
-               appendChunk("\n");
-           while (columnNumber < scripts[i].columnOffset - scriptOpenTag.length)
-               appendChunk(" ");
+        function searchCallback(script, searchMatches)
+        {
+            results[script.scriptId] = [];
+            for (var i = 0; i < searchMatches.length; ++i) {
+                var searchMatch = {};
+                searchMatch.lineNumber = searchMatches[i].lineNumber + script.lineOffset;
+                searchMatch.lineContent = searchMatches[i].lineContent;
+                results[script.scriptId].push(searchMatch);
+            }
+            scriptsLeft--;
+            maybeCallback.call(this);
+        }
 
-           // Add script tag.
-           appendChunk(scriptOpenTag);
-           appendChunk(sources[i]);
-           appendChunk(scriptCloseTag);
-       }
+        maybeCallback();
+        for (var i = 0; i < scripts.length; ++i)
+            scripts[i].searchInContent(query, searchCallback.bind(this, scripts[i]));
+    },
 
-       return content;
-   }
+    _concatenateScriptsContent: function(scripts, sources)
+    {
+        var content = "";
+        var lineNumber = 0;
+        var columnNumber = 0;
+
+        var scriptOpenTag = WebInspector.ConcatenatedScriptsContentProvider.scriptOpenTag;
+        var scriptCloseTag = WebInspector.ConcatenatedScriptsContentProvider.scriptCloseTag;
+        for (var i = 0; i < scripts.length; ++i) {
+            // Fill the gap with whitespace characters.
+            for (var newLinesCount = scripts[i].lineOffset - lineNumber; newLinesCount > 0; --newLinesCount) {
+                columnNumber = 0;
+                content += "\n";
+            }
+            for (var spacesCount = scripts[i].columnOffset - columnNumber - scriptOpenTag.length; spacesCount > 0; --spacesCount)
+                content += " ";
+
+            // Add script tag.
+            content += scriptOpenTag;
+            content += sources[i];
+            content += scriptCloseTag;
+            lineNumber = scripts[i].endLine;
+            columnNumber = scripts[i].endColumn + scriptCloseTag.length;
+        }
+
+        return content;
+    }
 }
 
 WebInspector.ConcatenatedScriptsContentProvider.prototype.__proto__ = WebInspector.ContentProvider.prototype;

Modified: trunk/Source/WebCore/inspector/front-end/Script.js (96702 => 96703)


--- trunk/Source/WebCore/inspector/front-end/Script.js	2011-10-05 14:20:22 UTC (rev 96702)
+++ trunk/Source/WebCore/inspector/front-end/Script.js	2011-10-05 14:30:29 UTC (rev 96703)
@@ -49,12 +49,24 @@
 
         function didGetScriptSource(error, source)
         {
-            this._source = source;
+            this._source = error ? "" : source;
             callback(this._source);
         }
         DebuggerAgent.getScriptSource(this.scriptId, didGetScriptSource.bind(this));
     },
 
+    searchInContent: function(query, callback)
+    {
+        function innerCallback(error, searchMatches)
+        {
+            if (error)
+                console.error(error);
+            callback(searchMatches || []);
+        }
+        
+        DebuggerAgent.searchInContent(this.scriptId, query, innerCallback.bind(this));
+    },
+    
     editSource: function(newSource, callback)
     {
         function didEditScriptSource(error, callFrames)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to