Bug 179283 - Web Inspector: support undo/redo of insertAdjacentHTML
Summary: Web Inspector: support undo/redo of insertAdjacentHTML
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Devin Rousso
URL:
Keywords: InRadar
Depends on: 179042
Blocks:
  Show dependency treegraph
 
Reported: 2017-11-04 00:24 PDT by Devin Rousso
Modified: 2017-11-15 09:42 PST (History)
15 users (show)

See Also:


Attachments
Patch (20.16 KB, patch)
2017-11-05 02:45 PST, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (27.03 KB, patch)
2017-11-09 03:59 PST, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (22.10 KB, patch)
2017-11-09 14:10 PST, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (27.05 KB, patch)
2017-11-09 14:13 PST, Devin Rousso
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Devin Rousso 2017-11-04 00:24:58 PDT
.
Comment 1 Devin Rousso 2017-11-05 02:45:34 PST
Created attachment 326060 [details]
Patch
Comment 2 Joseph Pecoraro 2017-11-08 18:47:52 PST
Comment on attachment 326060 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=326060&action=review

Nice test! This looks good to me, but I will want to see a version that shares the Element algorithm. We should never duplicate core algorithms (even if this seems relative simple).

> Source/JavaScriptCore/inspector/protocol/DOM.json:225
> +            "name": "insertAdjacentHTML",

I think this would go better down by "setOuterHTML".

> Source/WebCore/dom/Element.cpp:3669
> +ExceptionOr<NodeVector> Element::nodesForInsertedAdjacentHTML(const String& position, const String& html)

I feel like the algorithm should really be one place. That could be done with something like:

    ExceptionOr<void> Element::insertAdjacentHTML(const String& where, const String& markup, std::optional<NodeVector>& nodes)
    {
        ... /* this will only collect nodes if (nodes) */
    }

    ExceptionOr<void> Element::insertAdjacentHTML(const String& where, const String& markup)
    {
        return insertAdjacentHTML(where, markup, std::nullopt);
    }

> Source/WebCore/inspector/DOMEditor.cpp:280
> +        : Action("InsertAdjacentHTML")

Is the name actually used for anything? I wonder if we should just remove it. Or we can move to ASCIILiteral("...") to save a copy.

> Source/WebCore/inspector/DOMEditor.h:75
>      class ReplaceWholeTextAction;
> +    class InsertAdjacentHTMLAction;

Nit: `sort` these

> Source/WebCore/inspector/agents/InspectorDOMAgent.h:125
> +    void insertAdjacentHTML(ErrorString&, int nodeId, const String& position, const String& html) override;

Nit: The order of these should match the JSON, so preferably after setOuterHTML.

> Source/WebInspectorUI/UserInterface/Models/DOMNode.js:508
> +        // COMPATIBILITY (iOS 11.1): DOM.insertAdjacentHTML did not exist.

Nit: Just say "COMPATIBILITY (iOS 11.0)", since `11.0` is the last versioned protocol that was different.

> LayoutTests/inspector/dom/insertAdjacentHTML-expected.txt:1
> +Test for DOM.setOuterHTML on a page without a documentElement.

Fix this title.
Comment 3 Devin Rousso 2017-11-09 03:59:17 PST
Created attachment 326439 [details]
Patch

It took way too long to figure out that I needed to put & after NodeVector in order to not copy a Ref...
Comment 4 Joseph Pecoraro 2017-11-09 11:23:18 PST
Comment on attachment 326439 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=326439&action=review

r=me

> Source/WebCore/dom/Element.h:315
> +    ExceptionOr<void> insertAdjacentHTML(const String& where, const String& html, std::optional<NodeVector&> nodes);

I think the name `nodes` could be `addedNodes` and it would be clearer.
Comment 5 Devin Rousso 2017-11-09 14:10:19 PST
Created attachment 326485 [details]
Patch
Comment 6 Devin Rousso 2017-11-09 14:13:35 PST
Created attachment 326486 [details]
Patch

Whoops.  Forgot tests.
Comment 7 WebKit Commit Bot 2017-11-09 15:12:05 PST
Comment on attachment 326486 [details]
Patch

Clearing flags on attachment: 326486

Committed r224648: <https://trac.webkit.org/changeset/224648>
Comment 8 WebKit Commit Bot 2017-11-09 15:12:07 PST
All reviewed patches have been landed.  Closing bug.
Comment 9 Radar WebKit Bug Importer 2017-11-15 09:42:34 PST
<rdar://problem/35562282>