Title: [105288] trunk/Source/WebCore
Revision
105288
Author
pfeld...@chromium.org
Date
2012-01-18 09:56:42 -0800 (Wed, 18 Jan 2012)

Log Message

Web Inspector: there should be a way to set HTML for given frame.
https://bugs.webkit.org/show_bug.cgi?id=76548

Reviewed by Yury Semikhatsky.

* inspector/Inspector.json:
* inspector/InspectorPageAgent.cpp:
(WebCore::InspectorPageAgent::setDocumentContent):
* inspector/InspectorPageAgent.h:
* inspector/front-end/DOMAgent.js:
(WebInspector.DOMModelResourceBinding.prototype.setContent.callbackWrapper):
(WebInspector.DOMModelResourceBinding.prototype.setContent):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (105287 => 105288)


--- trunk/Source/WebCore/ChangeLog	2012-01-18 17:41:51 UTC (rev 105287)
+++ trunk/Source/WebCore/ChangeLog	2012-01-18 17:56:42 UTC (rev 105288)
@@ -1,3 +1,18 @@
+2012-01-18  Pavel Feldman  <pfeld...@google.com>
+
+        Web Inspector: there should be a way to set HTML for given frame.
+        https://bugs.webkit.org/show_bug.cgi?id=76548
+
+        Reviewed by Yury Semikhatsky.
+
+        * inspector/Inspector.json:
+        * inspector/InspectorPageAgent.cpp:
+        (WebCore::InspectorPageAgent::setDocumentContent):
+        * inspector/InspectorPageAgent.h:
+        * inspector/front-end/DOMAgent.js:
+        (WebInspector.DOMModelResourceBinding.prototype.setContent.callbackWrapper):
+        (WebInspector.DOMModelResourceBinding.prototype.setContent):
+
 2012-01-18  Sergio Villar Senin  <svil...@igalia.com>
 
         [GTK] [regression] A couple of tests failing after r105253

Modified: trunk/Source/WebCore/inspector/Inspector.json (105287 => 105288)


--- trunk/Source/WebCore/inspector/Inspector.json	2012-01-18 17:41:51 UTC (rev 105287)
+++ trunk/Source/WebCore/inspector/Inspector.json	2012-01-18 17:56:42 UTC (rev 105288)
@@ -299,6 +299,15 @@
                     { "name": "result", "type": "array", "items": { "$ref": "SearchResult" }, "description": "List of search results." }
                 ],
                 "hidden": true
+            },
+            {
+                "name": "setDocumentContent",
+                "description": "Sets given markup as the document's HTML.",
+                "parameters": [
+                    { "name": "frameId", "$ref": "Network.FrameId", "description": "Frame id to set HTML for." },
+                    { "name": "html", "type": "string", "description": "HTML content to set."  }
+                ],
+                "hidden": true
             }
         ],
         "events": [

Modified: trunk/Source/WebCore/inspector/InspectorPageAgent.cpp (105287 => 105288)


--- trunk/Source/WebCore/inspector/InspectorPageAgent.cpp	2012-01-18 17:41:51 UTC (rev 105287)
+++ trunk/Source/WebCore/inspector/InspectorPageAgent.cpp	2012-01-18 17:56:42 UTC (rev 105288)
@@ -42,6 +42,7 @@
 #include "ContentSearchUtils.h"
 #include "Cookie.h"
 #include "CookieJar.h"
+#include "DOMEditor.h"
 #include "Document.h"
 #include "DocumentLoader.h"
 #include "Frame.h"
@@ -562,6 +563,21 @@
     results = searchResults;
 }
 
+void InspectorPageAgent::setDocumentContent(ErrorString* errorString, const String& frameId, const String& html)
+{
+    Frame* frame = assertFrame(errorString, frameId);
+    if (!frame)
+        return;
+
+    Document* document = frame->document();
+    if (!document) {
+        *errorString = "No Document instance to set HTML for";
+        return;
+    }
+    DOMEditor editor(document);
+    editor.patchDocument(html);
+}
+
 void InspectorPageAgent::didClearWindowObjectInWorld(Frame* frame, DOMWrapperWorld* world)
 {
     if (world != mainThreadNormalWorld())

Modified: trunk/Source/WebCore/inspector/InspectorPageAgent.h (105287 => 105288)


--- trunk/Source/WebCore/inspector/InspectorPageAgent.h	2012-01-18 17:41:51 UTC (rev 105287)
+++ trunk/Source/WebCore/inspector/InspectorPageAgent.h	2012-01-18 17:56:42 UTC (rev 105288)
@@ -99,6 +99,7 @@
     void getResourceContent(ErrorString*, const String& frameId, const String& url, String* content, bool* base64Encoded);
     void searchInResource(ErrorString*, const String& frameId, const String& url, const String& query, const bool* const optionalCaseSensitive, const bool* const optionalIsRegex, RefPtr<InspectorArray>&);
     void searchInResources(ErrorString*, const String&, const bool* const caseSensitive, const bool* const isRegex, RefPtr<InspectorArray>&);
+    void setDocumentContent(ErrorString*, const String& frameId, const String& html);
 
     // InspectorInstrumentation API
     void didClearWindowObjectInWorld(Frame*, DOMWrapperWorld*);

Modified: trunk/Source/WebCore/inspector/front-end/DOMAgent.js (105287 => 105288)


--- trunk/Source/WebCore/inspector/front-end/DOMAgent.js	2012-01-18 17:41:51 UTC (rev 105287)
+++ trunk/Source/WebCore/inspector/front-end/DOMAgent.js	2012-01-18 17:56:42 UTC (rev 105288)
@@ -64,11 +64,6 @@
 
     if (payload.contentDocument) {
         this._contentDocument = new WebInspector.DOMDocument(domAgent, payload.contentDocument);
-        for (var i = 0; i < this._attributes.length; ++i) {
-            // Only bind document to URL when src attribute is set.
-            if (this._attributes[i].name.toLowerCase() === "src")
-                this._domAgent._documentURLToDocument[this._contentDocument.documentURL] = this._contentDocument;
-        }
         this.children = [this._contentDocument];
         this._renumber();
     }
@@ -515,7 +510,6 @@
 WebInspector.DOMAgent = function() {
     /** @type {Object|undefined} */
     this._idToDOMNode = {};
-    this._documentURLToDocument = {};
     this._document = null;
     this._attributeLoadNodeIds = {};
     InspectorBackend.registerDOMDispatcher(new WebInspector.DOMDispatcher(this));
@@ -731,10 +725,8 @@
     _setDocument: function(payload)
     {
         this._idToDOMNode = {};
-        this._documentURLToDocument = {};
         if (payload && "nodeId" in payload) {
             this._document = new WebInspector.DOMDocument(this, payload);
-            this._documentURLToDocument[this._document.documentURL] = this._document;
             if (this._document.children)
                 this._bindNodes(this._document.children);
         } else
@@ -1131,6 +1123,12 @@
 WebInspector.DOMModelResourceBinding.prototype = {
     setContent: function(resource, content, majorChange, userCallback)
     {
+        var frameId = resource.frameId;
+        if (!frameId)
+            return;
+
+        PageAgent.setDocumentContent(frameId, content, callbackWrapper);
+
         function callbackWrapper(error)
         {
             if (majorChange)
@@ -1138,30 +1136,6 @@
             if (userCallback)
                 userCallback(error);
         }
-
-        function setOuterHTML(reportError)
-        {
-            var doc = this._domAgent._documentURLToDocument[resource.url];
-            if (doc) {
-                DOMAgent.setOuterHTML(doc.id, content, callbackWrapper.bind(this));
-                return true;
-            }
-            if (reportError)
-                userCallback("No document with given URL found");
-            return false;
-        }
-    
-        this._domAgent.requestDocument(withDocument.bind(this));
-
-        function withDocument(doc)
-        {
-            if (setOuterHTML.call(this, false))
-                return;
-
-            // We are editing one of the iframes, but it has not yet been loaded in the DOM tree.
-            // Load all iframe nodes here.
-            DOMAgent.querySelectorAll(doc.id, "iframe[src]", setOuterHTML.bind(this, true));
-        }
     },
 
     canSetContent: function()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to